Bug fix.
- Handle error for incorrect passphrase entry.
This commit is contained in:
parent
f12e69b5df
commit
8c2b659360
@ -13,7 +13,7 @@ const environmentVars = `import {NgxLoggerLevel} from 'ngx-logger';
|
||||
export const environment = {
|
||||
production: ${isProduction},
|
||||
bloxbergChainId: ${process.env.CIC_CHAIN_ID || 8996},
|
||||
level: ${process.env.LOG_LEVEL || 'NgxLoggerLevel.OFF'},
|
||||
level: ${process.env.LOG_LEVEL || 'NgxLoggerLevel.ERROR'},
|
||||
serverLogLevel: ${process.env.SERVER_LOG_LEVEL || 'NgxLoggerLevel.OFF'},
|
||||
loggingUrl: '${process.env.CIC_LOGGING_URL || 'http://localhost:8000'}',
|
||||
cicMetaUrl: '${process.env.CIC_META_URL || 'https://meta.dev.grassrootseconomics.net'}',
|
||||
|
@ -34,12 +34,12 @@ export class ErrorInterceptor implements HttpInterceptor {
|
||||
errorMessage = `Backend returned code ${err.status}, body was: ${JSON.stringify(err.error)}`;
|
||||
this.loggingService.sendErrorLevelMessage(errorMessage, this, {error: err});
|
||||
}
|
||||
if (isDevMode()) {
|
||||
this.errorDialogService.openDialog({
|
||||
message: errorMessage || err.error.message || err.statusText || 'Unknown Error',
|
||||
status: err.status || 0
|
||||
});
|
||||
}
|
||||
// if (isDevMode()) {
|
||||
// this.errorDialogService.openDialog({
|
||||
// message: errorMessage || err.error.message || err.statusText || 'Unknown Error',
|
||||
// status: err.status || 0
|
||||
// });
|
||||
// }
|
||||
switch (err.status) {
|
||||
case 401: // unauthorized
|
||||
this.router.navigateByUrl('/auth').then();
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { KeyStore } from 'cic-client-meta';
|
||||
// const openpgp = require('openpgp'); //TODO should we put this on the mutalble key store object
|
||||
import * as openpgp from 'openpgp';
|
||||
import {throwError} from 'rxjs';
|
||||
const keyring = new openpgp.Keyring();
|
||||
|
||||
interface MutableKeyStore extends KeyStore {
|
||||
@ -83,6 +84,7 @@ class MutablePgpKeyStore implements MutableKeyStore{
|
||||
}
|
||||
|
||||
getFingerprint(): string {
|
||||
// TODO Handle multiple keys
|
||||
return keyring.privateKeys.keys[0].keyPacket.fingerprint;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import {ErrorDialogService} from '@app/_services/error-dialog.service';
|
||||
import {tap} from 'rxjs/operators';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import {Observable } from 'rxjs';
|
||||
import * as openpgp from 'openpgp';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@ -109,8 +110,12 @@ export class AuthService {
|
||||
|
||||
|
||||
async loginResponse(o): Promise<any> {
|
||||
const r = await signChallenge(o.challenge, o.realm, environment.cicMetaUrl, this.mutableKeyStore);
|
||||
this.sendResponse(r);
|
||||
try {
|
||||
const r = await signChallenge(o.challenge, o.realm, environment.cicMetaUrl, this.mutableKeyStore);
|
||||
this.sendResponse(r);
|
||||
} catch (error) {
|
||||
this.errorDialogService.openDialog({message: 'Incorrect key passphrase.'});
|
||||
}
|
||||
}
|
||||
|
||||
loginView(): void {
|
||||
@ -120,8 +125,10 @@ export class AuthService {
|
||||
}
|
||||
|
||||
async setKey(privateKeyArmored): Promise<boolean> {
|
||||
// TODO Check if key is encrypted else warn user.
|
||||
|
||||
try {
|
||||
const isValidKeyCheck = await this.mutableKeyStore.isValidKey(privateKeyArmored)
|
||||
const isValidKeyCheck = await this.mutableKeyStore.isValidKey(privateKeyArmored);
|
||||
if (!isValidKeyCheck) {
|
||||
throw Error('The private key is invalid');
|
||||
}
|
||||
@ -154,7 +161,10 @@ export class AuthService {
|
||||
return this.httpClient.get(`${environment.publicKeysUrl}`, {responseType: 'text'})
|
||||
.pipe(tap(
|
||||
data => { },
|
||||
error => { this.loggingService.sendErrorLevelMessage('Unable to load trusted public keys.', this, {error}); }
|
||||
error => {
|
||||
this.loggingService.sendErrorLevelMessage('Unable to load trusted public keys.', this, {error});
|
||||
this.errorDialogService.openDialog({message: 'Trusted keys endpoint can\'t be reached. Please try again later.'});
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {MatDialog} from '@angular/material/dialog';
|
||||
import {ErrorDialogComponent} from '@app/shared/error-dialog/error-dialog.component';
|
||||
import {LoggingService} from '@app/_services/logging.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@ -11,7 +10,6 @@ export class ErrorDialogService {
|
||||
|
||||
constructor(
|
||||
public dialog: MatDialog,
|
||||
private loggingService: LoggingService
|
||||
) { }
|
||||
|
||||
openDialog(data): any {
|
||||
@ -24,10 +22,6 @@ export class ErrorDialogService {
|
||||
data
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe(result => {
|
||||
this.loggingService.sendInfoLevelMessage('The dialog was closed');
|
||||
this.isDialogOpen = false;
|
||||
const res = result;
|
||||
});
|
||||
dialogRef.afterClosed().subscribe(() => this.isDialogOpen = false);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ export class AppComponent {
|
||||
) {
|
||||
(async () => {
|
||||
await this.authService.mutableKeyStore.loadKeyring();
|
||||
// TODO Handle error from get public keys function.
|
||||
this.authService.getPublicKeys().subscribe(this.authService.mutableKeyStore.importPublicKey);
|
||||
// this.loggingService.sendInfoLevelMessage(await this.tokenService.getTokens());
|
||||
})();
|
||||
|
@ -3,8 +3,8 @@
|
||||
<p>
|
||||
Message: {{ data.message }}
|
||||
</p>
|
||||
<p>
|
||||
Status: {{ data.status }}
|
||||
<p *ngIf="data.status">
|
||||
Status: {{ data?.status }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user