Add discourse identity proof

This commit is contained in:
Yarmo Mackenbach 2020-07-06 11:44:36 +02:00
parent 6fcb48cd6a
commit 603e5a0f35
3 changed files with 66 additions and 3 deletions

View file

@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- Added discourse identity proof
## [0.1.0] - 2020-07-05
### Added

View file

@ -514,6 +514,7 @@ async function verifyProof(url, fingerprint) {
output.display = `${match[1]}@${match[2]}`;
}
// Catchall
// Mastodon
try {
response = await fetch(url, {
headers: {
@ -526,7 +527,6 @@ async function verifyProof(url, fingerprint) {
}
json = await response.json();
if ('attachment' in json) {
// Potentially Mastodon
match = url.match(/https:\/\/(.*)\/@(.*)/);
json.attachment.forEach((item, i) => {
if (item.value.toUpperCase() === fingerprint.toUpperCase()) {
@ -537,10 +537,38 @@ async function verifyProof(url, fingerprint) {
}
});
}
return output;
} catch (e) {
} finally {
console.warn(e);
}
// Discourse
try {
match = url.match(/https:\/\/(.*)\/u\/(.*)/);
output.proofUrlFetch = `/server/verifyDiscourse.php?url=${url}&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();
if (json.isDiscourse) {
output.type = "discourse";
output.display = `${json.user}@${match[1]}`;
output.isVerified = json.verified;
return output;
}
} catch (e) {
console.warn(e);
}
} catch (e) {
console.warn(e);
}
return output;
}
async function fetchKeys(opts) {

View file

@ -0,0 +1,33 @@
<?php
$fingerprint = urlencode($_GET["fp"]);
$url = htmlspecialchars($_GET["url"]);
$urlProof = $url.".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, $urlProof);
$result = curl_exec($ch);
curl_close($ch);
$data = json_decode($result, true);
$response = array();
$response["isDiscourse"] = false;
if (isset($data) && array_key_exists("user", $data) && array_key_exists("bio_raw", $data["user"])) {
$response["isDiscourse"] = true;
$response["fingerprint"] = $fingerprint;
$response["user"] = $data["user"]["username"];
$response["verified"] = false;
}
if (preg_match("/{$check}/i", $data["user"]["bio_raw"])) {
$response["verified"] = true;
}
echo json_encode($response);
?>