mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
update auth service to use new crypto service
This commit is contained in:
@@ -246,15 +246,15 @@ export class AuthService implements AuthServiceAbstraction {
|
|||||||
// Keys aren't stored for a device that is locked or logged out
|
// Keys aren't stored for a device that is locked or logged out
|
||||||
// Make sure we're logged in before checking this, otherwise we could mix up those states
|
// Make sure we're logged in before checking this, otherwise we could mix up those states
|
||||||
const neverLock =
|
const neverLock =
|
||||||
(await this.cryptoService.hasKeyStored(KeySuffixOptions.Auto, userId)) &&
|
(await this.cryptoService.hasUserKeyStored(KeySuffixOptions.Auto, userId)) &&
|
||||||
!(await this.stateService.getEverBeenUnlocked({ userId: userId }));
|
!(await this.stateService.getEverBeenUnlocked({ userId: userId }));
|
||||||
if (neverLock) {
|
if (neverLock) {
|
||||||
// TODO: This also _sets_ the key so when we check memory in the next line it finds a key.
|
// Get the key from storage and set it in memory
|
||||||
// We should refactor here.
|
const userKey = await this.cryptoService.getUserKeyFromStorage(KeySuffixOptions.Auto, userId);
|
||||||
await this.cryptoService.getKey(KeySuffixOptions.Auto, userId);
|
await this.cryptoService.setUserKey(userKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasKeyInMemory = await this.cryptoService.hasKeyInMemory(userId);
|
const hasKeyInMemory = await this.cryptoService.hasUserKeyInMemory(userId);
|
||||||
if (!hasKeyInMemory) {
|
if (!hasKeyInMemory) {
|
||||||
return AuthenticationStatus.Locked;
|
return AuthenticationStatus.Locked;
|
||||||
}
|
}
|
||||||
@@ -281,7 +281,7 @@ export class AuthService implements AuthServiceAbstraction {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.cryptoService.makeKey(masterPassword, email, kdf, kdfConfig);
|
return await this.cryptoService.makeMasterKey(masterPassword, email, kdf, kdfConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
async authResponsePushNotification(notification: AuthRequestPushNotification): Promise<any> {
|
async authResponsePushNotification(notification: AuthRequestPushNotification): Promise<any> {
|
||||||
@@ -298,19 +298,19 @@ export class AuthService implements AuthServiceAbstraction {
|
|||||||
requestApproved: boolean
|
requestApproved: boolean
|
||||||
): Promise<AuthRequestResponse> {
|
): Promise<AuthRequestResponse> {
|
||||||
const pubKey = Utils.fromB64ToArray(key);
|
const pubKey = Utils.fromB64ToArray(key);
|
||||||
const encryptedKey = await this.cryptoService.rsaEncrypt(
|
// TODO(Jake): Do we need to support old encryption model here?
|
||||||
(
|
const userSymKey = await this.cryptoService.getUserKeyFromMemory();
|
||||||
await this.cryptoService.getKey()
|
if (!userSymKey) {
|
||||||
).encKey,
|
throw new Error("User key not found");
|
||||||
pubKey.buffer
|
}
|
||||||
);
|
const encryptedKey = await this.cryptoService.rsaEncrypt(userSymKey.encKey, pubKey.buffer);
|
||||||
const encryptedMasterPassword = await this.cryptoService.rsaEncrypt(
|
const encryptedMasterPasswordHash = await this.cryptoService.rsaEncrypt(
|
||||||
Utils.fromUtf8ToArray(await this.stateService.getKeyHash()),
|
Utils.fromUtf8ToArray(await this.stateService.getKeyHash()),
|
||||||
pubKey.buffer
|
pubKey.buffer
|
||||||
);
|
);
|
||||||
const request = new PasswordlessAuthRequest(
|
const request = new PasswordlessAuthRequest(
|
||||||
encryptedKey.encryptedString,
|
encryptedKey.encryptedString,
|
||||||
encryptedMasterPassword.encryptedString,
|
encryptedMasterPasswordHash.encryptedString,
|
||||||
await this.appIdService.getAppId(),
|
await this.appIdService.getAppId(),
|
||||||
requestApproved
|
requestApproved
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user