diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js index 8ba3f419daf1cc65f742947d5992624e86df42a7..a133428b0122a452c14ecefd89161e9451338547 100644 --- a/javascript/src/iframe/viamapi-iframe.js +++ b/javascript/src/iframe/viamapi-iframe.js @@ -47,7 +47,7 @@ import { checkRecoveryKeyCombine, encryptShare } from "../utilities/secrets"; -import {generateNonce, signRSA} from "../utilities/cryptoUtils"; +import { generateNonce, signRSA } from "../utilities/cryptoUtils"; const penpalMethods = require("../../temp/penpal-methods").default; const WopiAPI = require("./wopiapi-iframe"); @@ -139,7 +139,9 @@ async function setCurrentlyLoadedIdentity(identity) { const privateKey = identity.authentication.privateKey; const nonceSignature = await signRSA(privateKey, nonce); window.viamApi.setNonce(Buffer.from(nonce).toString("base64")); - window.viamApi.setNonceSignature(Buffer.from(nonceSignature).toString("base64")); + window.viamApi.setNonceSignature( + Buffer.from(nonceSignature).toString("base64") + ); } } @@ -399,6 +401,7 @@ function loadIdentityInternal(identityKey, pinCode) { return new Penpal.Promise(result => { getIdentityFromLocalStorage(identityKey, pinCode) .then(async loadedIdentity => { + console.log({ loadedIdentity }); if (loadedIdentity == null) { result({ data: "", @@ -407,10 +410,17 @@ function loadIdentityInternal(identityKey, pinCode) { "Please restore or authorize your account via another device." }); } + if (!loadedIdentity.privateKey) { + result({ + data: "", + code: "400", + status: "No privateKey" + }); + } localStorage.removeItem("attempt"); window.loadedIdentities[identityKey] = loadedIdentity; - await setCurrentlyLoadedIdentity(loadedIdentity) + await setCurrentlyLoadedIdentity(loadedIdentity); if (identityKey === localStorage.getItem("authenticatedIdentity")) { window.currentlyAuthenticatedIdentity = loadedIdentity; @@ -499,7 +509,7 @@ function getCertificateForPassport(passportUUID, internal) { .then(async () => { window.currentlyAuthenticatedIdentity = passportIdentity; window.lastTimeGetProfile = 0; - await setCurrentlyLoadedIdentity(passportIdentity) + await setCurrentlyLoadedIdentity(passportIdentity); const copyOfCryptoData = JSON.parse( JSON.stringify(cryptoData) ); @@ -573,16 +583,21 @@ const connection = Penpal.connectToParent({ ? collaboraUrl : collaboraUrl + "/"; - const { code, data: { domains: permittedDomains }} = await penpalMethods.identityGetPermittedDomains(); + const { + code, + data: { domains: permittedDomains } + } = await penpalMethods.identityGetPermittedDomains(); if (code !== "200") { - throw new Error("Unable to retrieve a list of permitted domains.") + throw new Error("Unable to retrieve a list of permitted domains."); } const iframeOrigin = document.referrer; - if (iframeOrigin && // Empty iframe origins are allowed. This is the case for Roundcube plugin - permittedDomains && - permittedDomains.length) { + if ( + iframeOrigin && // Empty iframe origins are allowed. This is the case for Roundcube plugin + permittedDomains && + permittedDomains.length + ) { let iframeOriginIsPermitted = false; for (const domain of permittedDomains) { @@ -593,7 +608,7 @@ const connection = Penpal.connectToParent({ } if (!iframeOriginIsPermitted) { - throw new Error(`Iframe origin "${iframeOrigin}" is not permitted.`) + throw new Error(`Iframe origin "${iframeOrigin}" is not permitted.`); } } }, @@ -609,7 +624,7 @@ const connection = Penpal.connectToParent({ newIdentity.setAuthentication(cryptoData); newIdentity.setPinCode(pinCode); - await setCurrentlyLoadedIdentity(newIdentity) + await setCurrentlyLoadedIdentity(newIdentity); localStorage.setItem( "currentlyLoadedIdentity", JSON.stringify(newIdentity) @@ -832,6 +847,7 @@ const connection = Penpal.connectToParent({ }); }, login: async (loginIdentity, mode, requestCode, requestActionID) => { + const localStorageIdentity = getIdentityFromLocalStorage(); if (!window.loadedIdentities[loginIdentity.authentication.publicKey]) { return { data: "", @@ -2613,7 +2629,8 @@ connection.promise.then(parent => { false ); - !window.currentlyLoadedIdentity && await setCurrentlyLoadedIdentity(identity); + !window.currentlyLoadedIdentity && + (await setCurrentlyLoadedIdentity(identity)); if (!identityAuthenticatedEvent && identity) { const event = createEvent("IdentityAuthenticated", "Authenticated", [