diff --git a/src/app/_pgp/pgp-key-store.ts b/src/app/_pgp/pgp-key-store.ts index 0b27f9f..9c49048 100644 --- a/src/app/_pgp/pgp-key-store.ts +++ b/src/app/_pgp/pgp-key-store.ts @@ -28,7 +28,7 @@ interface MutableKeyStore extends KeyStore { removePublicKeyForId(keyId: string): any; removePublicKey(publicKey: any): any; clearKeysInKeyring(): void; - sign(plainText: string): Promise; + sign(plainText: string, passphrase: string): Promise; } class MutablePgpKeyStore implements MutableKeyStore{ @@ -144,11 +144,10 @@ class MutablePgpKeyStore implements MutableKeyStore{ keyring.clear(); } - async sign(plainText): Promise { + async sign(plainText: string, passphrase: string): Promise { const privateKey = this.getPrivateKey(); if (!privateKey.isDecrypted()) { - const password = window.prompt('password'); - await privateKey.decrypt(password); + await privateKey.decrypt(passphrase); } const opts = { message: openpgp.message.fromText(plainText), diff --git a/src/app/_services/auth.service.ts b/src/app/_services/auth.service.ts index ba4651a..7bf0431 100644 --- a/src/app/_services/auth.service.ts +++ b/src/app/_services/auth.service.ts @@ -73,7 +73,7 @@ export class AuthService { xhr.send(); } - getChallenge(): void { + getChallenge(password: string): void { const xhr = new XMLHttpRequest(); xhr.responseType = 'arraybuffer'; xhr.open('GET', environment.cicMetaUrl + window.location.search.substring(1)); @@ -81,12 +81,21 @@ export class AuthService { if (xhr.status === 401) { const authHeader = xhr.getResponseHeader('WWW-Authenticate'); const o = hobaParseChallengeHeader(authHeader); - await this.loginResponse(o); + await this.loginResponse(o, password); } }; xhr.send(); } + passwordLogin(password: string): boolean { + try { + this.getChallenge(password); + return true; + } catch (e) { + this.loggingService.sendErrorLevelMessage('Login challenge failed', this, {error: e}); + } + return false; + } login(): boolean { if (this.sessionToken !== undefined) { @@ -96,32 +105,20 @@ export class AuthService { } catch (e) { this.loggingService.sendErrorLevelMessage('Login token failed', this, {error: e}); } - } else { - try { - this.getChallenge(); - } catch (e) { - this.loggingService.sendErrorLevelMessage('Login challenge failed', this, {error: e}); - } } return false; } - async loginResponse(o): Promise { + async loginResponse(o: any, password: string): Promise { try { - const r = await signChallenge(o.challenge, o.realm, environment.cicMetaUrl, this.mutableKeyStore); + const r = await signChallenge(o.challenge, o.realm, environment.cicMetaUrl, this.mutableKeyStore, password); this.sendResponse(r); } catch (error) { this.errorDialogService.openDialog({message: 'Incorrect key passphrase.'}); } } - loginView(): void { - document.getElementById('one').style.display = 'none'; - document.getElementById('two').style.display = 'block'; - this.setState('Click button to log in with PGP key ' + this.mutableKeyStore.getPrivateKeyId()); - } - async setKey(privateKeyArmored): Promise { try { const isValidKeyCheck = await this.mutableKeyStore.isValidKey(privateKeyArmored); @@ -141,7 +138,6 @@ export class AuthService { }); return false; } - this.loginView(); return true; } diff --git a/src/app/auth/auth.component.html b/src/app/auth/auth.component.html index 2355239..fdf90e3 100644 --- a/src/app/auth/auth.component.html +++ b/src/app/auth/auth.component.html @@ -7,7 +7,7 @@

CICADA

-
+

Add Private Key

@@ -19,13 +19,13 @@ Private Key -
+
Private Key is required.
- @@ -33,6 +33,41 @@
+