Fix handling of hkp or wkd depending on input

This commit is contained in:
Yarmo Mackenbach 2020-06-28 23:27:37 +02:00
parent 747cec0bb1
commit 2ab91d7659
6 changed files with 64 additions and 11 deletions

View file

@ -585,9 +585,8 @@ if (elProfileUid) {
let match, opts, profileUid = elProfileUid.innerHTML;
if (/.*@.*/.test(profileUid)) {
// Match email for wkd
match = profileUid.match(/(.*)@(.*)_([a-zA-Z0-9]+)$/);
opts = {
input: `${match[1]}@${match[2]}.${match[3]}`,
input: profileUid,
mode: "wkd"
}
} else {

View file

@ -2,6 +2,7 @@
include_once __DIR__ . '/vendor/autoload.php';
use Pagerange\Markdown\MetaParsedown;
include_once 'server/functions.php';
// Init router
$router = new AltoRouter();
@ -14,6 +15,12 @@ $router->map('GET', '/proofs', function() {}, 'proofs');
$router->map('GET', '/verify/[:uid]', function() {}, 'verifyUid');
$router->map('GET', '/encrypt/[:uid]', function() {}, 'encryptUid');
$router->map('GET', '/proofs/[:uid]', function() {}, 'proofsUid');
$router->map('GET', '/verify/hkp/[:uid]', function() {}, 'verifyHKP');
$router->map('GET', '/encrypt/hkp/[:uid]', function() {}, 'encryptHKP');
$router->map('GET', '/proofs/hkp/[:uid]', function() {}, 'proofsHKP');
$router->map('GET', '/verify/wkd/[:uid]', function() {}, 'verifyWKD');
$router->map('GET', '/encrypt/wkd/[:uid]', function() {}, 'encryptWKD');
$router->map('GET', '/proofs/wkd/[:uid]', function() {}, 'proofsWKD');
$router->map('GET', '/guides', function() {}, 'guides');
$router->map('GET', '/guides/[:id]', function() {}, 'guideId');
$router->map('GET', '/faq', function() {}, 'faq');
@ -22,6 +29,11 @@ $router->map('GET', '/[:uid]', function() {}, 'profile');
// Router matching
$match = $router->match();
// Fix "escaped" email address
if (array_key_exists('uid', $match['params'])) {
$match['params']['uid'] = str_lreplace('_', '.', $match['params']['uid']);
}
// Render the appropriate route
if(is_array($match) && is_callable($match['target'])) {
switch ($match['name']) {
@ -31,24 +43,54 @@ if(is_array($match) && is_callable($match['target'])) {
case 'verify':
case 'verifyUid':
case 'verifyHKP':
$content = file_get_contents('pages/verify.html');
$content = str_replace('%UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ""), $content);
$content = str_replace('%HKP_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
$content = str_replace('%WKD_UID%', '', $content);
header('Content-Type: text/html; charset=utf-8');
echo($content);
break;
case 'verifyWKD':
$content = file_get_contents('pages/verify.html');
$content = str_replace('%HKP_UID%', '', $content);
$content = str_replace('%WKD_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
header('Content-Type: text/html; charset=utf-8');
echo($content);
break;
case 'encrypt':
case 'encryptUid':
case 'encryptHKP':
$content = file_get_contents('pages/encrypt.html');
$content = str_replace('%UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ""), $content);
$content = str_replace('%HKP_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
$content = str_replace('%WKD_UID%', '', $content);
header('Content-Type: text/html; charset=utf-8');
echo($content);
break;
case 'encryptWKD':
$content = file_get_contents('pages/encrypt.html');
$content = str_replace('%HKP_UID%', '', $content);
$content = str_replace('%WKD_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
header('Content-Type: text/html; charset=utf-8');
echo($content);
break;
case 'proofs':
case 'proofsUid':
case 'proofsHKP':
$content = file_get_contents('pages/proofs.html');
$content = str_replace('%UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ""), $content);
$content = str_replace('%HKP_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
$content = str_replace('%WKD_UID%', '', $content);
header('Content-Type: text/html; charset=utf-8');
echo($content);
break;
case 'proofsWKD':
$content = file_get_contents('pages/proofs.html');
$content = str_replace('%HKP_UID%', '', $content);
$content = str_replace('%WKD_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
header('Content-Type: text/html; charset=utf-8');
echo($content);
break;

View file

@ -29,10 +29,10 @@
<h3>Public Key (1: plaintext)</h3>
<textarea name="publicKey" id="publicKey"></textarea>
<h3>Public Key (2: web key directory)</h3>
<input type="text" name="wkd" id="wkd" placeholder="name@domain.com">
<input type="text" name="wkd" id="wkd" placeholder="name@domain.com" value="%WKD_UID%">
<h3>Public Key (3: HKP server)</h3>
<input type="text" name="hkp_server" id="hkp_server" placeholder="https://keys.openpgp.org/">
<input type="text" name="hkp_input" id="hkp_input" placeholder="Email / key id / fingerprint" value="%UID%">
<input type="text" name="hkp_input" id="hkp_input" placeholder="Email / key id / fingerprint" value="%HKP_UID%">
<h3>Result</h3>
<textarea name="messageEncrypted" id="messageEncrypted" readonly></textarea>
<p id="result"></p>

View file

@ -27,10 +27,10 @@
<h3>Public Key (1: plaintext)</h3>
<textarea name="publicKey" id="publicKey"></textarea>
<h3>Public Key (2: web key directory)</h3>
<input type="text" name="wkd" id="wkd" placeholder="name@domain.com">
<input type="text" name="wkd" id="wkd" placeholder="name@domain.com" value="%WKD_UID%">
<h3>Public Key (3: HKP server)</h3>
<input type="text" name="hkp_server" id="hkp_server" placeholder="https://keys.openpgp.org/">
<input type="text" name="hkp_input" id="hkp_input" placeholder="Email / key id / fingerprint" value="%UID%">
<input type="text" name="hkp_input" id="hkp_input" placeholder="Email / key id / fingerprint" value="%HKP_UID%">
<h3>Result</h3>
<p id="result">Click on the button below.</p>
<p id="resultContent"></p>

View file

@ -29,10 +29,10 @@
<h3>Public Key (1: plaintext)</h3>
<textarea name="publicKey" id="publicKey"></textarea>
<h3>Public Key (2: web key directory)</h3>
<input type="text" name="wkd" id="wkd" placeholder="name@domain.com">
<input type="text" name="wkd" id="wkd" placeholder="name@domain.com" value="%WKD_UID%">
<h3>Public Key (3: HKP server)</h3>
<input type="text" name="hkp_server" id="hkp_server" placeholder="https://keys.openpgp.org/">
<input type="text" name="hkp_input" id="hkp_input" placeholder="Email / key id / fingerprint" value="%UID%">
<input type="text" name="hkp_input" id="hkp_input" placeholder="Email / key id / fingerprint" value="%HKP_UID%">
<h3>Result</h3>
<p id="result">Click on the button below.</p>
<p id="resultContent"></p>

12
server/functions.php Normal file
View file

@ -0,0 +1,12 @@
<?php
function str_lreplace($search, $replace, $subject) {
$pos = strrpos($subject, $search);
if($pos !== false) {
$subject = substr_replace($subject, $replace, $pos, strlen($search));
}
return $subject;
}
?>