Skip to content
11 changes: 0 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"swagger-ui-dist": "4.15.5",
"tippy.js": "6.3.7",
"tributejs": "5.1.3",
"uint8-to-base64": "0.2.0",
"vue": "3.2.45",
"vue-bar-graph": "2.0.0",
"vue-loader": "17.0.1",
Expand Down
25 changes: 18 additions & 7 deletions web_src/js/features/user-auth-webauthn.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import $ from 'jquery';
import {encode, decode} from 'uint8-to-base64';

const {appSubUrl, csrfToken} = window.config;

function encodeToBase64(toEncode) {
const output = [];
for (let i = 0; i < toEncode.length; i++) {
output.push(String.fromCharCode(toEncode[i]));
}
return window.btoa(output.join(''));
}

function decodeFromBase64(toDecode) {
return Uint8Array.from(window.atob(toDecode), (c) => c.charCodeAt(0));
}

export function initUserAuthWebAuthn() {
if ($('.user.signin.webauthn-prompt').length === 0) {
return;
Expand All @@ -14,9 +25,9 @@ export function initUserAuthWebAuthn() {

$.getJSON(`${appSubUrl}/user/webauthn/assertion`, {})
.done((makeAssertionOptions) => {
makeAssertionOptions.publicKey.challenge = decode(makeAssertionOptions.publicKey.challenge);
makeAssertionOptions.publicKey.challenge = decodeFromBase64(makeAssertionOptions.publicKey.challenge);
for (let i = 0; i < makeAssertionOptions.publicKey.allowCredentials.length; i++) {
makeAssertionOptions.publicKey.allowCredentials[i].id = decode(makeAssertionOptions.publicKey.allowCredentials[i].id);
makeAssertionOptions.publicKey.allowCredentials[i].id = decodeFromBase64(makeAssertionOptions.publicKey.allowCredentials[i].id);
}
navigator.credentials.get({
publicKey: makeAssertionOptions.publicKey
Expand Down Expand Up @@ -87,7 +98,7 @@ function verifyAssertion(assertedCredential) {

// Encode an ArrayBuffer into a base64 string.
function bufferEncode(value) {
return encode(value)
return encodeToBase64(value)
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=/g, '');
Expand Down Expand Up @@ -184,11 +195,11 @@ function webAuthnRegisterRequest() {
}).done((makeCredentialOptions) => {
$('#nickname').closest('div.field').removeClass('error');

makeCredentialOptions.publicKey.challenge = decode(makeCredentialOptions.publicKey.challenge);
makeCredentialOptions.publicKey.user.id = decode(makeCredentialOptions.publicKey.user.id);
makeCredentialOptions.publicKey.challenge = decodeFromBase64(makeCredentialOptions.publicKey.challenge);
makeCredentialOptions.publicKey.user.id = decodeFromBase64(makeCredentialOptions.publicKey.user.id);
if (makeCredentialOptions.publicKey.excludeCredentials) {
for (let i = 0; i < makeCredentialOptions.publicKey.excludeCredentials.length; i++) {
makeCredentialOptions.publicKey.excludeCredentials[i].id = decode(makeCredentialOptions.publicKey.excludeCredentials[i].id);
makeCredentialOptions.publicKey.excludeCredentials[i].id = decodeFromBase64(makeCredentialOptions.publicKey.excludeCredentials[i].id);
}
}

Expand Down