mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 06:13:38 +00:00
Add comments to send service to make it easier to follow (#14389)
This commit is contained in:
@@ -50,7 +50,7 @@ export class SendService implements InternalSendServiceAbstraction {
|
|||||||
model: SendView,
|
model: SendView,
|
||||||
file: File | ArrayBuffer,
|
file: File | ArrayBuffer,
|
||||||
password: string,
|
password: string,
|
||||||
key?: SymmetricCryptoKey,
|
userKey?: SymmetricCryptoKey,
|
||||||
): Promise<[Send, EncArrayBuffer]> {
|
): Promise<[Send, EncArrayBuffer]> {
|
||||||
let fileData: EncArrayBuffer = null;
|
let fileData: EncArrayBuffer = null;
|
||||||
const send = new Send();
|
const send = new Send();
|
||||||
@@ -62,15 +62,19 @@ export class SendService implements InternalSendServiceAbstraction {
|
|||||||
send.deletionDate = model.deletionDate;
|
send.deletionDate = model.deletionDate;
|
||||||
send.expirationDate = model.expirationDate;
|
send.expirationDate = model.expirationDate;
|
||||||
if (model.key == null) {
|
if (model.key == null) {
|
||||||
|
// Sends use a seed, stored in the URL fragment. This seed is used to derive the key that is used for encryption.
|
||||||
const key = await this.keyGenerationService.createKeyWithPurpose(
|
const key = await this.keyGenerationService.createKeyWithPurpose(
|
||||||
128,
|
128,
|
||||||
this.sendKeyPurpose,
|
this.sendKeyPurpose,
|
||||||
this.sendKeySalt,
|
this.sendKeySalt,
|
||||||
);
|
);
|
||||||
|
// key.material is the seed that can be used to re-derive the key
|
||||||
model.key = key.material;
|
model.key = key.material;
|
||||||
model.cryptoKey = key.derivedKey;
|
model.cryptoKey = key.derivedKey;
|
||||||
}
|
}
|
||||||
if (password != null) {
|
if (password != null) {
|
||||||
|
// Note: Despite being called key, the passwordKey is not used for encryption.
|
||||||
|
// It is used as a static proof that the client knows the password, and has the encryption key.
|
||||||
const passwordKey = await this.keyGenerationService.deriveKeyFromPassword(
|
const passwordKey = await this.keyGenerationService.deriveKeyFromPassword(
|
||||||
password,
|
password,
|
||||||
model.key,
|
model.key,
|
||||||
@@ -78,11 +82,11 @@ export class SendService implements InternalSendServiceAbstraction {
|
|||||||
);
|
);
|
||||||
send.password = passwordKey.keyB64;
|
send.password = passwordKey.keyB64;
|
||||||
}
|
}
|
||||||
if (key == null) {
|
if (userKey == null) {
|
||||||
key = await this.keyService.getUserKey();
|
userKey = await this.keyService.getUserKey();
|
||||||
}
|
}
|
||||||
// Key is not a SymmetricCryptoKey, but key material used to derive the cryptoKey
|
// Key is not a SymmetricCryptoKey, but key material used to derive the cryptoKey
|
||||||
send.key = await this.encryptService.encrypt(model.key, key);
|
send.key = await this.encryptService.encrypt(model.key, userKey);
|
||||||
send.name = await this.encryptService.encrypt(model.name, model.cryptoKey);
|
send.name = await this.encryptService.encrypt(model.name, model.cryptoKey);
|
||||||
send.notes = await this.encryptService.encrypt(model.notes, model.cryptoKey);
|
send.notes = await this.encryptService.encrypt(model.notes, model.cryptoKey);
|
||||||
if (send.type === SendType.Text) {
|
if (send.type === SendType.Text) {
|
||||||
|
|||||||
Reference in New Issue
Block a user