Skip to content

Commit ebdff50

Browse files
committed
make MAC check robust against unpadded vs padded base64 differences
1 parent da2ef38 commit ebdff50

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/crypto/SecretStorage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export class SecretStorage extends EventEmitter {
167167
if (info.algorithm === SECRET_STORAGE_ALGORITHM_V1_AES) {
168168
if (info.mac) {
169169
const {mac} = await SecretStorage._calculateKeyCheck(key, info.iv);
170-
return info.mac === mac;
170+
return info.mac.replace(/=+$/g, '') === mac.replace(/=+$/g, '');
171171
} else {
172172
// if we have no information, we have to assume the key is right
173173
return true;

src/crypto/aes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ async function decryptNode(data, key, name) {
8484
const [aesKey, hmacKey] = deriveKeysNode(key, name);
8585

8686
const hmac = crypto.createHmac("sha256", hmacKey)
87-
.update(data.ciphertext, "base64").digest("base64");
87+
.update(data.ciphertext, "base64").digest("base64").replace(/=+$/g, '');
8888

89-
if (hmac !== data.mac) {
89+
if (hmac !== data.mac.replace(/=+$/g, '')) {
9090
throw new Error(`Error decrypting secret ${name}: bad MAC`);
9191
}
9292

0 commit comments

Comments
 (0)