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