1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

generate keypair on registration

This commit is contained in:
Kyle Spearrin
2018-07-03 11:41:55 -04:00
parent 269b59210c
commit 3454d93fef
10 changed files with 127 additions and 22 deletions

View File

@@ -3,7 +3,10 @@ import { Router } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { RegisterRequest } from '../../models/request/registerRequest';
import {
RegisterKeysRequest,
RegisterRequest,
} from '../../models/request/registerRequest';
import { ApiService } from '../../abstractions/api.service';
import { AuthService } from '../../abstractions/auth.service';
@@ -11,6 +14,7 @@ import { CryptoService } from '../../abstractions/crypto.service';
import { I18nService } from '../../abstractions/i18n.service';
export class RegisterComponent {
name: string = '';
email: string = '';
masterPassword: string = '';
confirmMasterPassword: string = '';
@@ -52,8 +56,18 @@ export class RegisterComponent {
return;
}
this.name = this.name === '' ? null : this.name;
this.email = this.email.toLowerCase();
const key = await this.cryptoService.makeKey(this.masterPassword, this.email);
const encKey = await this.cryptoService.makeEncKey(key);
const hashedPassword = await this.cryptoService.hashPassword(this.masterPassword, key);
const keys = await this.cryptoService.makeKeyPair(encKey[0]);
const request = new RegisterRequest(this.email, this.name, hashedPassword,
this.hint, encKey[1].encryptedString);
request.keys = new RegisterKeysRequest(keys[0], keys[1].encryptedString);
try {
this.formPromise = this.register();
this.formPromise = this.apiService.postRegister(request);
await this.formPromise;
this.analytics.eventTrack.next({ action: 'Registered' });
this.toasterService.popAsync('success', null, this.i18nService.t('newAccountCreated'));
@@ -66,13 +80,4 @@ export class RegisterComponent {
this.showPassword = !this.showPassword;
document.getElementById(confirmField ? 'masterPasswordRetype' : 'masterPassword').focus();
}
private async register() {
this.email = this.email.toLowerCase();
const key = await this.cryptoService.makeKey(this.masterPassword, this.email);
const encKey = await this.cryptoService.makeEncKey(key);
const hashedPassword = await this.cryptoService.hashPassword(this.masterPassword, key);
const request = new RegisterRequest(this.email, hashedPassword, this.hint, encKey.encryptedString);
await this.apiService.postRegister(request);
}
}