mirror of
https://codeberg.org/keyoxide/keyoxide-web.git
synced 2024-12-22 23:09:29 -07:00
Add WKD Local Part utility
This commit is contained in:
parent
c32c847204
commit
32b8d58bd6
3 changed files with 113 additions and 2 deletions
|
@ -504,12 +504,50 @@ async function fetchKeys(opts) {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function encodeZBase32(data) {
|
||||||
|
// Source: https://github.com/openpgpjs/openpgpjs/blob/master/src/util.js
|
||||||
|
if (data.length === 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
const ALPHABET = "ybndrfg8ejkmcpqxot1uwisza345h769";
|
||||||
|
const SHIFT = 5;
|
||||||
|
const MASK = 31;
|
||||||
|
let buffer = data[0];
|
||||||
|
let index = 1;
|
||||||
|
let bitsLeft = 8;
|
||||||
|
let result = '';
|
||||||
|
while (bitsLeft > 0 || index < data.length) {
|
||||||
|
if (bitsLeft < SHIFT) {
|
||||||
|
if (index < data.length) {
|
||||||
|
buffer <<= 8;
|
||||||
|
buffer |= data[index++] & 0xff;
|
||||||
|
bitsLeft += 8;
|
||||||
|
} else {
|
||||||
|
const pad = SHIFT - bitsLeft;
|
||||||
|
buffer <<= pad;
|
||||||
|
bitsLeft += pad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bitsLeft -= SHIFT;
|
||||||
|
result += ALPHABET[MASK & (buffer >> bitsLeft)];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function computeWKDLocalPart(message) {
|
||||||
|
const encoder = new TextEncoder();
|
||||||
|
const data = encoder.encode(message);
|
||||||
|
const hash = await crypto.subtle.digest('SHA-1', data);
|
||||||
|
return encodeZBase32(new Uint8Array(hash));
|
||||||
|
}
|
||||||
|
|
||||||
// General purpose
|
// General purpose
|
||||||
let elFormVerify = document.body.querySelector("#form-verify"),
|
let elFormVerify = document.body.querySelector("#form-verify"),
|
||||||
elFormEncrypt = document.body.querySelector("#form-encrypt"),
|
elFormEncrypt = document.body.querySelector("#form-encrypt"),
|
||||||
elFormProofs = document.body.querySelector("#form-proofs"),
|
elFormProofs = document.body.querySelector("#form-proofs"),
|
||||||
elProfileUid = document.body.querySelector("#profileUid"),
|
elProfileUid = document.body.querySelector("#profileUid"),
|
||||||
elProfileMode = document.body.querySelector("#profileMode");
|
elProfileMode = document.body.querySelector("#profileMode"),
|
||||||
|
elUtilWKD = document.body.querySelector("#form-util-wkd");
|
||||||
|
|
||||||
if (elFormVerify) {
|
if (elFormVerify) {
|
||||||
elFormVerify.onsubmit = function (evt) {
|
elFormVerify.onsubmit = function (evt) {
|
||||||
|
@ -628,3 +666,20 @@ if (elProfileUid) {
|
||||||
}
|
}
|
||||||
displayProfile(opts);
|
displayProfile(opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (elUtilWKD) {
|
||||||
|
elUtilWKD.onsubmit = function (evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
const elInput = document.body.querySelector("#input");
|
||||||
|
const elOutput = document.body.querySelector("#output");
|
||||||
|
|
||||||
|
elInput.addEventListener("input", async function(evt) {
|
||||||
|
if (evt.target.value) {
|
||||||
|
elOutput.value = await computeWKDLocalPart(evt.target.value);
|
||||||
|
} else {
|
||||||
|
elOutput.value = "";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ $router->map('GET', '/encrypt/[:uid]', function() {}, 'encryptUid');
|
||||||
$router->map('GET', '/proofs/[:uid]', function() {}, 'proofsUid');
|
$router->map('GET', '/proofs/[:uid]', function() {}, 'proofsUid');
|
||||||
$router->map('GET', '/hkp/[**:uid]', function() {}, 'profileHKP');
|
$router->map('GET', '/hkp/[**:uid]', function() {}, 'profileHKP');
|
||||||
$router->map('GET', '/wkd/[**:uid]', function() {}, 'profileWKD');
|
$router->map('GET', '/wkd/[**:uid]', function() {}, 'profileWKD');
|
||||||
|
$router->map('GET', '/util/[:id]', function() {}, 'util');
|
||||||
$router->map('GET', '/[**:uid]', function() {}, 'profile');
|
$router->map('GET', '/[**:uid]', function() {}, 'profile');
|
||||||
|
|
||||||
// Router matching
|
// Router matching
|
||||||
|
@ -132,8 +133,13 @@ if(is_array($match) && is_callable($match['target'])) {
|
||||||
echo($content);
|
echo($content);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'util':
|
||||||
|
$id = $match['params']['id'];
|
||||||
|
readfile("pages/util/$id.html");
|
||||||
|
break;
|
||||||
|
|
||||||
case 'faq':
|
case 'faq':
|
||||||
readfile('pages/faq.html');
|
readfile("pages/faq.html");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
50
pages/util/wkd.html
Normal file
50
pages/util/wkd.html
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en" dir="ltr">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="shortcut icon" href="/favicon.png">
|
||||||
|
<title>WKD utilities - Keyoxide</title>
|
||||||
|
<link rel="stylesheet" href="/assets/styles.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<div class="container">
|
||||||
|
<a href="/">Keyoxide</a>
|
||||||
|
<div class="spacer"></div>
|
||||||
|
<nav>
|
||||||
|
<a href="/verify">verify</a>
|
||||||
|
<a href="/encrypt">encrypt</a>
|
||||||
|
<a href="/proofs">proofs</a>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<h1>WKD Local Part</h1>
|
||||||
|
<div class="content">
|
||||||
|
<form id="form-util-wkd" method="post">
|
||||||
|
<h3>Name</h3>
|
||||||
|
<input type="text" name="input" id="input" placeholder="Name">
|
||||||
|
<h3>Result</h3>
|
||||||
|
<input type="text" name="output" id="output" readonly>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<p>
|
||||||
|
Sitemap:
|
||||||
|
<a href="/">index</a> -
|
||||||
|
<a href="/encrypt">encrypt</a> -
|
||||||
|
<a href="/verify">verify</a> -
|
||||||
|
<a href="/proofs">proofs</a> -
|
||||||
|
<a href="/guides">guides</a> -
|
||||||
|
<a href="/faq">faq</a>
|
||||||
|
</p>
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
<script type="text/javascript" src="/assets/scripts.js" charset="utf-8"></script>
|
||||||
|
</html>
|
Loading…
Reference in a new issue