Fix Reddit proof

This commit is contained in:
Yarmo Mackenbach 2020-06-28 15:51:26 +02:00
parent d144a6d372
commit 8622953905
2 changed files with 40 additions and 8 deletions

View file

@ -333,7 +333,7 @@ async function verifyProof(url, fingerprint) {
match = url.match(/https:\/\/www.reddit.com\/user\/(.*)\/comments\/(.*)\/(.*)\//); match = url.match(/https:\/\/www.reddit.com\/user\/(.*)\/comments\/(.*)\/(.*)\//);
output.display = match[1]; output.display = match[1];
output.url = `https://www.reddit.com/user/${match[1]}`; output.url = `https://www.reddit.com/user/${match[1]}`;
output.proofUrlFetch = url.replace(/\/[a-zA-Z0-9_]*\/$/, ".json"); output.proofUrlFetch = `/server/verifyReddit.php?user=${match[1]}&comment=${match[2]}&fp=${fingerprint}`;
try { try {
response = await fetch(output.proofUrlFetch, { response = await fetch(output.proofUrlFetch, {
headers: { headers: {
@ -345,13 +345,7 @@ async function verifyProof(url, fingerprint) {
throw new Error('Response failed: ' + response.status); throw new Error('Response failed: ' + response.status);
} }
json = await response.json(); json = await response.json();
console.log(json); output.isVerified = json.verified;
reVerify = new RegExp(`Verifying my OpenPGP key: openpgp4fpr:${fingerprint}`);
json.Answer.forEach((item, i) => {
if (reVerify.test(item.data)) {
output.isVerified = true;
}
});
} catch (e) { } catch (e) {
} finally { } finally {
return output; return output;

38
server/verifyReddit.php Normal file
View file

@ -0,0 +1,38 @@
<?php
include 'secrets.php';
$fingerprint = htmlspecialchars($_GET["fp"]);
$user = htmlspecialchars($_GET["user"]);
$comment = htmlspecialchars($_GET["comment"]);
$url = "https://www.reddit.com/user/$user/comments/$comment.json";
$check = "\[Verifying my OpenPGP key: openpgp4fpr:$fingerprint\\\\\]";
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
$data = json_decode($result, true);
$response = array();
$response["verified"] = false;
$response["fingerprint"] = $fingerprint;
$response["user"] = $user;
$response["comment"] = $comment;
foreach ($data as $entry) {
$entryData = $entry["data"]["children"];
foreach ($entryData as $subEntry) {
if (preg_match("/{$check}/i", $subEntry["data"]["selftext"])) {
$response["verified"] = true;
}
}
}
echo json_encode($response);
?>