Add supporting javascript files for pgp and hoba.
This commit is contained in:
parent
6b1e930b2b
commit
414b9eb215
24
src/assets/js/hoba-pgp.js
Normal file
24
src/assets/js/hoba-pgp.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import {hobaResult, hobaToSign} from "./hoba.js";
|
||||||
|
|
||||||
|
const alg = '969';
|
||||||
|
|
||||||
|
export async function signChallenge(challenge, realm, origin, keyStore) {
|
||||||
|
const fingerprint = keyStore.fingerprint();
|
||||||
|
const nonce_array = new Uint8Array(32);
|
||||||
|
crypto.getRandomValues(nonce_array);
|
||||||
|
|
||||||
|
const kid_array = fingerprint;
|
||||||
|
|
||||||
|
const a_kid = btoa(String.fromCharCode.apply(null, kid_array));
|
||||||
|
const a_nonce = btoa(String.fromCharCode.apply(null, nonce_array));
|
||||||
|
const a_challenge = btoa(challenge);
|
||||||
|
const message = hobaToSign(a_nonce, a_kid, a_challenge, realm, origin, alg);
|
||||||
|
console.debug('message to sign', challenge, realm, origin, message);
|
||||||
|
|
||||||
|
const signature = await keyStore.sign(message);
|
||||||
|
const a_signature = btoa(signature);
|
||||||
|
|
||||||
|
const result = hobaResult(a_nonce, a_kid, a_challenge, a_signature);
|
||||||
|
console.debug('result', result);
|
||||||
|
return result;
|
||||||
|
}
|
30
src/assets/js/hoba.js
Normal file
30
src/assets/js/hoba.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
export function hobaResult(nonce, kid, challenge, signature) {
|
||||||
|
return nonce + '.' + kid + '.' + challenge + '.' + signature;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hobaToSign(nonce, kid, challenge, realm, origin, alg) {
|
||||||
|
var s = '';
|
||||||
|
var params = [nonce, alg, origin, realm, kid, challenge];
|
||||||
|
for (var i = 0; i < params.length; i++) {
|
||||||
|
s += params[i].length + ':' + params[i];
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hobaParseChallengeHeader(s) {
|
||||||
|
const auth_parts = s.split(" ");
|
||||||
|
const auth_pairs = auth_parts[1].split(",");
|
||||||
|
let auth_values = {}
|
||||||
|
for (var i = 0; i < auth_pairs.length; i++) {
|
||||||
|
var auth_kv = auth_pairs[i].split(/^([^=]+)="(.+)"/);
|
||||||
|
auth_values[auth_kv[1]] = auth_kv[2];
|
||||||
|
}
|
||||||
|
console.debug('challenge b64', auth_values['challenge']);
|
||||||
|
const challenge_bytes = atob(auth_values['challenge']);
|
||||||
|
console.debug('challenge bytes', challenge_bytes);
|
||||||
|
|
||||||
|
return {
|
||||||
|
challenge: challenge_bytes,
|
||||||
|
realm: auth_values['realm'],
|
||||||
|
};
|
||||||
|
}
|
2
src/assets/js/openpgp.min.js
vendored
Normal file
2
src/assets/js/openpgp.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user