Lint code.

This commit is contained in:
Spencer Ofwiti 2021-06-07 18:49:15 +03:00
parent 159cedc86e
commit 8e96b070a5
3 changed files with 36 additions and 18 deletions

View File

@ -102,8 +102,11 @@ export class AuthService {
await this.loginResponse(o, password); await this.loginResponse(o, password);
return true; return true;
} catch (error) { } catch (error) {
this.loggingService.sendErrorLevelMessage(`Login challenge failed: Error ${error.status} - ${error.statusText}`, this.loggingService.sendErrorLevelMessage(
this, {error}); `Login challenge failed: Error ${error.status} - ${error.statusText}`,
this,
{ error }
);
} }
return false; return false;
} }
@ -114,8 +117,11 @@ export class AuthService {
this.getWithToken(); this.getWithToken();
return true; return true;
} catch (error) { } catch (error) {
this.loggingService.sendErrorLevelMessage(`Login token failed: Error ${error.status} - ${error.statusText}`, this.loggingService.sendErrorLevelMessage(
this, {error}); `Login token failed: Error ${error.status} - ${error.statusText}`,
this,
{ error }
);
} }
} }
return false; return false;
@ -162,9 +168,11 @@ export class AuthService {
if (!isValidKeyCheck) { if (!isValidKeyCheck) {
throw Error('The private key is invalid'); throw Error('The private key is invalid');
} }
const isEncryptedKeyCheck = await this.mutableKeyStore.isEncryptedPrivateKey(privateKeyArmored); const isEncryptedKeyCheck = await this.mutableKeyStore.isEncryptedPrivateKey(
privateKeyArmored
);
if (!isEncryptedKeyCheck) { if (!isEncryptedKeyCheck) {
throw Error('The private key doesn\'t have a password!'); throw Error('The private key does not have a password!');
} }
const key = await this.mutableKeyStore.importPrivateKey(privateKeyArmored); const key = await this.mutableKeyStore.importPrivateKey(privateKeyArmored);
localStorage.setItem(btoa('CICADA_PRIVATE_KEY'), privateKeyArmored); localStorage.setItem(btoa('CICADA_PRIVATE_KEY'), privateKeyArmored);

View File

@ -23,8 +23,8 @@ export class AuthComponent implements OnInit {
private authService: AuthService, private authService: AuthService,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private router: Router, private router: Router,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef
) { } ) {}
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.keyForm = this.formBuilder.group({ this.keyForm = this.formBuilder.group({
@ -44,8 +44,12 @@ export class AuthComponent implements OnInit {
} }
} }
get keyFormStub(): any { return this.keyForm.controls; } get keyFormStub(): any {
get passwordFormStub(): any { return this.passwordForm.controls; } return this.keyForm.controls;
}
get passwordFormStub(): any {
return this.passwordForm.controls;
}
async onSubmit(): Promise<void> { async onSubmit(): Promise<void> {
this.keyFormSubmitted = true; this.keyFormSubmitted = true;
@ -66,10 +70,14 @@ export class AuthComponent implements OnInit {
async onPasswordInput(): Promise<void> { async onPasswordInput(): Promise<void> {
this.passwordFormSubmitted = true; this.passwordFormSubmitted = true;
if (this.passwordForm.invalid) { return; } if (this.passwordForm.invalid) {
return;
}
this.passwordFormLoading = true; this.passwordFormLoading = true;
const passwordLogin = await this.authService.passwordLogin(this.passwordFormStub.password.value); const passwordLogin = await this.authService.passwordLogin(
this.passwordFormStub.password.value
);
if (passwordLogin) { if (passwordLogin) {
this.loginView(); this.loginView();
} }
@ -95,7 +103,9 @@ export class AuthComponent implements OnInit {
passwordInput(): void { passwordInput(): void {
this.authService.sessionToken = undefined; this.authService.sessionToken = undefined;
this.switchWindows(false, true, false); this.switchWindows(false, true, false);
this.setPasswordState('Enter Password to log in with PGP key ' + this.authService.mutableKeyStore.getPrivateKeyId()); this.setPasswordState(
'Enter Password to log in with PGP key ' + this.authService.mutableKeyStore.getPrivateKeyId()
);
} }
loginView(): void { loginView(): void {

View File

@ -3,9 +3,9 @@ import { hobaResult, hobaToSign } from '@src/assets/js/hoba.js';
const alg = '969'; const alg = '969';
export async function signChallenge(challenge, realm, origin, keyStore, password) { export async function signChallenge(challenge, realm, origin, keyStore, password) {
const fingerprint = keyStore.getFingerprint(); const fingerprint = keyStore.getFingerprint();
const nonce_array = new Uint8Array(32); const nonce_array = new Uint8Array(32);
crypto.getRandomValues(nonce_array); crypto.getRandomValues(nonce_array);
const kid_array = fingerprint; const kid_array = fingerprint;
@ -14,8 +14,8 @@ export async function signChallenge(challenge, realm, origin, keyStore, password
const a_challenge = btoa(challenge); const a_challenge = btoa(challenge);
const message = hobaToSign(a_nonce, a_kid, a_challenge, realm, origin, alg); const message = hobaToSign(a_nonce, a_kid, a_challenge, realm, origin, alg);
const signature = await keyStore.sign(message, password); const signature = await keyStore.sign(message, password);
const a_signature = btoa(signature); const a_signature = btoa(signature);
const result = hobaResult(a_nonce, a_kid, a_challenge, a_signature); const result = hobaResult(a_nonce, a_kid, a_challenge, a_signature);
return result; return result;