From a96c21b209a4ddfea4b1fd75500021ebce68bc75 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 12 Feb 2020 12:10:29 -0500 Subject: [PATCH] added stretched master key. bootstrap 4. --- crypto.html | 117 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 50 deletions(-) diff --git a/crypto.html b/crypto.html index 316be3c4..35d3f0bb 100644 --- a/crypto.html +++ b/crypto.html @@ -8,34 +8,21 @@ Bitwarden Crypto - + - - - - + @@ -80,35 +76,50 @@ -

Master Key

-
{{masterKey.b64}}
+
+

Master Key

+
{{masterKey.b64}}
+
-

Master Password Hash

-
{{masterKeyHash.b64}}
+
+

Master Password Hash

+
{{masterKeyHash.b64}}
+
-

Generated Symmetric Key

-
{{symKey.key.b64}}
-

Encryption Key

-
{{symKey.encKey.b64}}
-

MAC Key

-
{{symKey.macKey.b64}}
-

Protected Symmetric Key

-
{{protectedSymKey.string}}
+
+

Stretched Master Key

+
{{stretchedMasterKey.key.b64}}
+

Encryption Key

+
{{stretchedMasterKey.encKey.b64}}
+

MAC Key

+
{{stretchedMasterKey.macKey.b64}}
+
-

Generated RSA Keypair

-

Public Key

-
{{publicKey.b64}}
-

Private Key

-
{{privateKey.b64}}
-

Protected Private Key

-
{{protectedPrivateKey.string}}
+
+

Generated Symmetric Key

+
{{symKey.key.b64}}
+

Encryption Key

+
{{symKey.encKey.b64}}
+

MAC Key

+
{{symKey.macKey.b64}}
+

Protected Symmetric Key

+
{{protectedSymKey.string}}
+
+ +
+

Generated RSA Key Pair

+

Public Key

+
{{publicKey.b64}}
+

Private Key

+
{{privateKey.b64}}
+

Protected Private Key

+
{{protectedPrivateKey.string}}
+
-
-

Encryption

@@ -368,7 +379,7 @@ return dataForMac; } - async function generateRsaKeypair() { + async function generateRsaKeyPair() { const rsaOptions = { name: 'RSA-OAEP', modulusLength: 2048, @@ -429,6 +440,7 @@ masterKey: new ByteData(), masterKeyHash: new ByteData(), + stretchedMasterKey: new SymmetricCryptoKey(), symKey: new SymmetricCryptoKey(), protectedSymKey: new Cipher(), @@ -462,6 +474,7 @@ return new ByteData(); } + self.stretchedMasterKey = await stretchKey(newValue.arr.buffer); self.masterKeyHash = await pbkdf2(newValue.arr.buffer, self.masterPasswordBuffer, 1, 256); } }, @@ -473,7 +486,7 @@ window.crypto.getRandomValues(symKey); self.symKey = new SymmetricCryptoKey(symKey); - const keyPair = await generateRsaKeypair(); + const keyPair = await generateRsaKeyPair(); self.publicKey = keyPair.publicKey; self.privateKey = keyPair.privateKey; } @@ -514,17 +527,21 @@ vm.$watch(() => { return { - masterKey: vm.masterKey, + stretchedMasterKey: vm.stretchedMasterKey, symKey: vm.symKey }; }, async (newVal, oldVal) => { - if (!newVal.masterKey || !newVal.masterKey.arr || !newVal.symKey || !newVal.symKey.key) { + if (!newVal.stretchedMasterKey || !newVal.stretchedMasterKey.key || + !newVal.stretchedMasterKey.key.arr || !newVal.symKey || !newVal.symKey.key || + !newVal.symKey.key.arr) { vm.protectedSymKey = new Cipher(); return; } - vm.protectedSymKey = await aesEncrypt(newVal.symKey.key.arr, newVal.masterKey, null); - const unprotectedSymKey = await aesDecrypt(vm.protectedSymKey, newVal.masterKey, null); + vm.protectedSymKey = await aesEncrypt(newVal.symKey.key.arr, newVal.stretchedMasterKey.encKey, + newVal.stretchedMasterKey.macKey); + const unprotectedSymKey = await aesDecrypt(vm.protectedSymKey, newVal.stretchedMasterKey.encKey, + newVal.stretchedMasterKey.macKey); vm.unprotectedSymKey = new ByteData(unprotectedSymKey); });