Bug fix.
- Add handling of errors from getPublicKeys function. - Check if added private keys are encrypted.
This commit is contained in:
@@ -5,10 +5,8 @@ import {environment} from '@src/environments/environment';
|
||||
import {LoggingService} from '@app/_services/logging.service';
|
||||
import {MutableKeyStore, MutablePgpKeyStore} from '@app/_pgp';
|
||||
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'
|
||||
@@ -125,18 +123,19 @@ 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);
|
||||
if (!isValidKeyCheck) {
|
||||
throw Error('The private key is invalid');
|
||||
}
|
||||
const isEncryptedKeyCheck = await this.mutableKeyStore.isEncryptedPrivateKey(privateKeyArmored);
|
||||
if (!isEncryptedKeyCheck) {
|
||||
throw Error('The private key doesn\'t have a password!');
|
||||
}
|
||||
const key = await this.mutableKeyStore.importPrivateKey(privateKeyArmored);
|
||||
localStorage.setItem(btoa('CICADA_PRIVATE_KEY'), privateKeyArmored);
|
||||
} catch (err) {
|
||||
this.loggingService.sendErrorLevelMessage('Failed setting key', this, {error: err});
|
||||
// TODO use a global error handler here
|
||||
this.loggingService.sendErrorLevelMessage(`Failed to set key: ${err.message || err.statusText}`, this, {error: err});
|
||||
this.errorDialogService.openDialog({
|
||||
message: `Failed to set key: ${err.message || err.statusText}`,
|
||||
});
|
||||
@@ -158,14 +157,7 @@ export class AuthService {
|
||||
}
|
||||
|
||||
getPublicKeys(): Observable<any> {
|
||||
return this.httpClient.get(`${environment.publicKeysUrl}`, {responseType: 'text'})
|
||||
.pipe(tap(
|
||||
data => { },
|
||||
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.'});
|
||||
}
|
||||
));
|
||||
return this.httpClient.get(`${environment.publicKeysUrl}`, {responseType: 'text'});
|
||||
}
|
||||
|
||||
async getPrivateKeys(): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user