From 2ab91d7659e5b503c1f55a37ad04e52d9bc28257 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Sun, 28 Jun 2020 23:27:37 +0200 Subject: [PATCH] Fix handling of hkp or wkd depending on input --- assets/scripts.js | 3 +-- index.php | 48 +++++++++++++++++++++++++++++++++++++++++--- pages/encrypt.html | 4 ++-- pages/proofs.html | 4 ++-- pages/verify.html | 4 ++-- server/functions.php | 12 +++++++++++ 6 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 server/functions.php diff --git a/assets/scripts.js b/assets/scripts.js index 2790143..e1a4b50 100644 --- a/assets/scripts.js +++ b/assets/scripts.js @@ -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 { diff --git a/index.php b/index.php index 5fb6397..e3e7e23 100644 --- a/index.php +++ b/index.php @@ -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; diff --git a/pages/encrypt.html b/pages/encrypt.html index 0f18715..a50d4e5 100644 --- a/pages/encrypt.html +++ b/pages/encrypt.html @@ -29,10 +29,10 @@

Public Key (1: plaintext)

Public Key (2: web key directory)

- +

Public Key (3: HKP server)

- +

Result

diff --git a/pages/proofs.html b/pages/proofs.html index e444c4f..f98b4ad 100644 --- a/pages/proofs.html +++ b/pages/proofs.html @@ -27,10 +27,10 @@

Public Key (1: plaintext)

Public Key (2: web key directory)

- +

Public Key (3: HKP server)

- +

Result

Click on the button below.

diff --git a/pages/verify.html b/pages/verify.html index dced67a..fca0be8 100644 --- a/pages/verify.html +++ b/pages/verify.html @@ -29,10 +29,10 @@

Public Key (1: plaintext)

Public Key (2: web key directory)

- +

Public Key (3: HKP server)

- +

Result

Click on the button below.

diff --git a/server/functions.php b/server/functions.php new file mode 100644 index 0000000..95b2db4 --- /dev/null +++ b/server/functions.php @@ -0,0 +1,12 @@ +