Add consistent and contextual logging around decryption failure (#10404)
* Added more context to logging messages around decryption failure * Added missing period.
This commit is contained in:
parent
7cd6fcf265
commit
e4ed4a3858
|
@ -452,6 +452,9 @@ export default class MainBackground {
|
||||||
return new ForegroundMemoryStorageService();
|
return new ForegroundMemoryStorageService();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For local backed session storage, we expect that the encrypted data on disk will persist longer than the encryption key in memory
|
||||||
|
// and failures to decrypt because of that are completely expected. For this reason, we pass in `false` to the `EncryptServiceImplementation`
|
||||||
|
// so that MAC failures are not logged.
|
||||||
return new LocalBackedSessionStorageService(
|
return new LocalBackedSessionStorageService(
|
||||||
sessionKey,
|
sessionKey,
|
||||||
this.storageService,
|
this.storageService,
|
||||||
|
|
|
@ -71,12 +71,12 @@ export class EncryptServiceImplementation implements EncryptService {
|
||||||
key = this.resolveLegacyKey(key, encString);
|
key = this.resolveLegacyKey(key, encString);
|
||||||
|
|
||||||
if (key.macKey != null && encString?.mac == null) {
|
if (key.macKey != null && encString?.mac == null) {
|
||||||
this.logService.error("mac required.");
|
this.logService.error("MAC required but not provided.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.encType !== encString.encryptionType) {
|
if (key.encType !== encString.encryptionType) {
|
||||||
this.logService.error("encType unavailable.");
|
this.logService.error("Key encryption type does not match payload encryption type.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ export class EncryptServiceImplementation implements EncryptService {
|
||||||
);
|
);
|
||||||
const macsEqual = await this.cryptoFunctionService.compareFast(fastParams.mac, computedMac);
|
const macsEqual = await this.cryptoFunctionService.compareFast(fastParams.mac, computedMac);
|
||||||
if (!macsEqual) {
|
if (!macsEqual) {
|
||||||
this.logMacFailed("mac failed.");
|
this.logMacFailed("MAC comparison failed. Key or payload has changed.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,10 +114,12 @@ export class EncryptServiceImplementation implements EncryptService {
|
||||||
key = this.resolveLegacyKey(key, encThing);
|
key = this.resolveLegacyKey(key, encThing);
|
||||||
|
|
||||||
if (key.macKey != null && encThing.macBytes == null) {
|
if (key.macKey != null && encThing.macBytes == null) {
|
||||||
|
this.logService.error("MAC required but not provided.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.encType !== encThing.encryptionType) {
|
if (key.encType !== encThing.encryptionType) {
|
||||||
|
this.logService.error("Key encryption type does not match payload encryption type.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,12 +129,13 @@ export class EncryptServiceImplementation implements EncryptService {
|
||||||
macData.set(new Uint8Array(encThing.dataBytes), encThing.ivBytes.byteLength);
|
macData.set(new Uint8Array(encThing.dataBytes), encThing.ivBytes.byteLength);
|
||||||
const computedMac = await this.cryptoFunctionService.hmac(macData, key.macKey, "sha256");
|
const computedMac = await this.cryptoFunctionService.hmac(macData, key.macKey, "sha256");
|
||||||
if (computedMac === null) {
|
if (computedMac === null) {
|
||||||
|
this.logMacFailed("Failed to compute MAC.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const macsMatch = await this.cryptoFunctionService.compare(encThing.macBytes, computedMac);
|
const macsMatch = await this.cryptoFunctionService.compare(encThing.macBytes, computedMac);
|
||||||
if (!macsMatch) {
|
if (!macsMatch) {
|
||||||
this.logMacFailed("mac failed.");
|
this.logMacFailed("MAC comparison failed. Key or payload has changed.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue