Add support for lobste.rs proofs

This commit is contained in:
Yarmo Mackenbach 2020-06-30 12:42:47 +02:00
parent c442a403e8
commit d42b6fee66
2 changed files with 52 additions and 0 deletions

View file

@ -413,6 +413,29 @@ async function verifyProof(url, fingerprint) {
return output;
}
}
// Lobsters
if (/^https:\/\/lobste.rs/.test(url)) {
output.type = "lobsters";
match = url.match(/https:\/\/lobste.rs\/u\/(.*)/);
output.display = match[1];
output.proofUrlFetch = `/server/verifyLobsters.php?user=${match[1]}&fp=${fingerprint}`;
try {
response = await fetch(output.proofUrlFetch, {
headers: {
Accept: 'application/json'
},
credentials: 'omit'
});
if (!response.ok) {
throw new Error('Response failed: ' + response.status);
}
json = await response.json();
output.isVerified = json.verified;
} catch (e) {
} finally {
return output;
}
}
// XMPP
if (/^xmpp:/.test(url)) {
output.type = "xmpp";

29
server/verifyLobsters.php Normal file
View file

@ -0,0 +1,29 @@
<?php
$fingerprint = htmlspecialchars($_GET["fp"]);
$user = htmlspecialchars($_GET["user"]);
$url = "https://lobste.rs/u/$user.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;
if (preg_match("/{$check}/i", $data["about"])) {
$response["verified"] = true;
}
echo json_encode($response);
?>