From 349ea1775a7f2a81b86c2f6daffee6b947152b2f Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 22 Nov 2020 16:01:34 +0800 Subject: [PATCH] code refactor --- src/lib/userstate.js | 4 ++-- src/lib/webauthn.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/userstate.js b/src/lib/userstate.js index 5b24af52..35590ec9 100644 --- a/src/lib/userstate.js +++ b/src/lib/userstate.js @@ -3,7 +3,7 @@ import CryptoJS from 'crypto-js'; import settings from './settings.js'; import utils from './utils.js'; -const APP_LOCK_SECRET_BASE_STRING_PREFIX = 'LAB_LOCK_SECRET_'; +const appLockSecretBaseStringPrefix = 'LAB_LOCK_SECRET_'; const tokenLocalStorageKey = 'lab_user_token'; const webauthnConfigLocalStorageKey = 'lab_user_webauthn_config'; @@ -13,7 +13,7 @@ const tokenSessionStorageKey = 'lab_user_session_token'; const appLockSecretSessionStorageKey = 'lab_user_app_lock_secret'; function getAppLockSecret(pinCode) { - const hashedPinCode = CryptoJS.SHA256(APP_LOCK_SECRET_BASE_STRING_PREFIX + pinCode).toString(); + const hashedPinCode = CryptoJS.SHA256(appLockSecretBaseStringPrefix + pinCode).toString(); return hashedPinCode.substr(0, 24); // put secret into user id of webauthn (user id total length must less 64 bytes) } diff --git a/src/lib/webauthn.js b/src/lib/webauthn.js index c2f28f37..501391ff 100644 --- a/src/lib/webauthn.js +++ b/src/lib/webauthn.js @@ -2,7 +2,7 @@ import CBOR from 'cbor-js'; import logger from './logger.js'; import utils from './utils.js'; -const PUBLIC_KEY_CREDENTIAL_CREATION_OPTIONS_TEMPLATE = { +const publicKeyCredentialCreationOptionsBaseTemplate = { attestation: "none", authenticatorSelection: { authenticatorAttachment: 'platform', @@ -17,7 +17,7 @@ const PUBLIC_KEY_CREDENTIAL_CREATION_OPTIONS_TEMPLATE = { timeout: 1800000 }; -const PUBLIC_KEY_CREDENTIAL_REQUEST_OPTIONS_TEMPLATE = { +const publicKeyCredentialRequestOptionsBaseTemplate = { allowCredentials: [{ type: 'public-key' }], @@ -53,7 +53,7 @@ function registerCredential({ username, nickname }, userSecret) { const challenge = utils.generateRandomString(); const userId = `${username}|${userSecret}`; // username 32bytes(max) + userSecret 24bytes = 56bytes(max) - const publicKeyCredentialCreationOptions = Object.assign({}, PUBLIC_KEY_CREDENTIAL_CREATION_OPTIONS_TEMPLATE, { + const publicKeyCredentialCreationOptions = Object.assign({}, publicKeyCredentialCreationOptionsBaseTemplate, { challenge: utils.stringToArrayBuffer(challenge), rp: { name: window.location.hostname, @@ -132,7 +132,7 @@ function verifyCredential({ username }, credentialId) { } const challenge = utils.generateRandomString(); - const publicKeyCredentialRequestOptions = Object.assign({}, PUBLIC_KEY_CREDENTIAL_REQUEST_OPTIONS_TEMPLATE, { + const publicKeyCredentialRequestOptions = Object.assign({}, publicKeyCredentialRequestOptionsBaseTemplate, { challenge: utils.stringToArrayBuffer(challenge), rpId: window.location.hostname });