1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

update cli with new crypto service methods

- decrypt user sym key and set when unlocking
This commit is contained in:
Jacob Fink
2023-05-30 10:50:11 -04:00
parent f0438e5dd2
commit f2e7a8ad11
3 changed files with 31 additions and 18 deletions

View File

@@ -406,7 +406,11 @@ export class LoginCommand {
} }
try { try {
const { newPasswordHash, newEncKey, hint } = await this.collectNewMasterPasswordDetails( const {
newPasswordHash,
newUserSymKey: newEncKey,
hint,
} = await this.collectNewMasterPasswordDetails(
"Your master password does not meet one or more of your organization policies. In order to access the vault, you must update your master password now." "Your master password does not meet one or more of your organization policies. In order to access the vault, you must update your master password now."
); );
@@ -444,7 +448,11 @@ export class LoginCommand {
} }
try { try {
const { newPasswordHash, newEncKey, hint } = await this.collectNewMasterPasswordDetails( const {
newPasswordHash,
newUserSymKey: newEncKey,
hint,
} = await this.collectNewMasterPasswordDetails(
"An organization administrator recently changed your master password. In order to access the vault, you must update your master password now." "An organization administrator recently changed your master password. In order to access the vault, you must update your master password now."
); );
@@ -477,7 +485,7 @@ export class LoginCommand {
error?: string error?: string
): Promise<{ ): Promise<{
newPasswordHash: string; newPasswordHash: string;
newEncKey: [SymmetricCryptoKey, EncString]; newUserSymKey: [SymmetricCryptoKey, EncString];
hint?: string; hint?: string;
}> { }> {
if (this.email == null || this.email === "undefined") { if (this.email == null || this.email === "undefined") {
@@ -559,21 +567,24 @@ export class LoginCommand {
const kdfConfig = await this.stateService.getKdfConfig(); const kdfConfig = await this.stateService.getKdfConfig();
// Create new key and hash new password // Create new key and hash new password
const newKey = await this.cryptoService.makeKey( const newMasterKey = await this.cryptoService.makeMasterKey(
masterPassword, masterPassword,
this.email.trim().toLowerCase(), this.email.trim().toLowerCase(),
kdf, kdf,
kdfConfig kdfConfig
); );
const newPasswordHash = await this.cryptoService.hashPassword(masterPassword, newKey); const newPasswordHash = await this.cryptoService.hashPassword(masterPassword, newMasterKey);
// Grab user's current enc key // Grab user's symmetric key
const userEncKey = await this.cryptoService.getEncKey(); const userSymKey = await this.cryptoService.getUserKey();
// Create new encKey for the User // Re-encrypt user's symmetric key with new master key
const newEncKey = await this.cryptoService.remakeEncKey(newKey, userEncKey); const newUserSymKey = await this.cryptoService.encryptUserSymKeyWithMasterKey(
newMasterKey,
userSymKey
);
return { newPasswordHash, newEncKey, hint: masterPasswordHint }; return { newPasswordHash, newUserSymKey, hint: masterPasswordHint };
} }
private async handleCaptchaRequired( private async handleCaptchaRequired(

View File

@@ -44,17 +44,17 @@ export class UnlockCommand {
const email = await this.stateService.getEmail(); const email = await this.stateService.getEmail();
const kdf = await this.stateService.getKdfType(); const kdf = await this.stateService.getKdfType();
const kdfConfig = await this.stateService.getKdfConfig(); const kdfConfig = await this.stateService.getKdfConfig();
const key = await this.cryptoService.makeKey(password, email, kdf, kdfConfig); const masterKey = await this.cryptoService.makeMasterKey(password, email, kdf, kdfConfig);
const storedKeyHash = await this.cryptoService.getKeyHash(); const storedKeyHash = await this.cryptoService.getKeyHash();
let passwordValid = false; let passwordValid = false;
if (key != null) { if (masterKey != null) {
if (storedKeyHash != null) { if (storedKeyHash != null) {
passwordValid = await this.cryptoService.compareAndUpdateKeyHash(password, key); passwordValid = await this.cryptoService.compareAndUpdateKeyHash(password, masterKey);
} else { } else {
const serverKeyHash = await this.cryptoService.hashPassword( const serverKeyHash = await this.cryptoService.hashPassword(
password, password,
key, masterKey,
HashPurpose.ServerAuthorization HashPurpose.ServerAuthorization
); );
const request = new SecretVerificationRequest(); const request = new SecretVerificationRequest();
@@ -64,7 +64,7 @@ export class UnlockCommand {
passwordValid = true; passwordValid = true;
const localKeyHash = await this.cryptoService.hashPassword( const localKeyHash = await this.cryptoService.hashPassword(
password, password,
key, masterKey,
HashPurpose.LocalAuthorization HashPurpose.LocalAuthorization
); );
await this.cryptoService.setKeyHash(localKeyHash); await this.cryptoService.setKeyHash(localKeyHash);
@@ -75,7 +75,9 @@ export class UnlockCommand {
} }
if (passwordValid) { if (passwordValid) {
await this.cryptoService.setKey(key); await this.cryptoService.setMasterKey(masterKey);
const userKey = await this.cryptoService.decryptUserSymKeyWithMasterKey(masterKey);
await this.cryptoService.setUserKey(userKey);
if (await this.keyConnectorService.getConvertAccountRequired()) { if (await this.keyConnectorService.getConvertAccountRequired()) {
const convertToKeyConnectorCommand = new ConvertToKeyConnectorCommand( const convertToKeyConnectorCommand = new ConvertToKeyConnectorCommand(

View File

@@ -126,8 +126,8 @@ export class CreateCommand {
return Response.error("Premium status is required to use this feature."); return Response.error("Premium status is required to use this feature.");
} }
const encKey = await this.cryptoService.getEncKey(); const userSymKey = await this.cryptoService.getUserKey();
if (encKey == null) { if (userSymKey == null) {
return Response.error( return Response.error(
"You must update your encryption key before you can use this feature. " + "You must update your encryption key before you can use this feature. " +
"See https://help.bitwarden.com/article/update-encryption-key/" "See https://help.bitwarden.com/article/update-encryption-key/"