Fix up initial ratchet stuff
This commit is contained in:
parent
3c603c72b4
commit
da1b021972
1 changed files with 12 additions and 10 deletions
|
@ -470,10 +470,8 @@ function getRandomBytes(size) {
|
||||||
calculated_mac.update(CryptoJS.enc.Latin1.parse(getString(data)));
|
calculated_mac.update(CryptoJS.enc.Latin1.parse(getString(data)));
|
||||||
calculated_mac = calculated_mac.finalize();
|
calculated_mac = calculated_mac.finalize();
|
||||||
|
|
||||||
if (btoa(calculated_mac.toString(CryptoJS.enc.Base64)).substring(0, mac.length) != mac) {
|
if (btoa(calculated_mac.toString(CryptoJS.enc.Base64)).substring(0, mac.length) != mac)
|
||||||
console.log("Got message with bad MAC");
|
|
||||||
throw "Bad MAC";
|
throw "Bad MAC";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************
|
/******************************
|
||||||
|
@ -521,7 +519,9 @@ function getRandomBytes(size) {
|
||||||
lastRemoteEphemeralKey: message.baseKey },
|
lastRemoteEphemeralKey: message.baseKey },
|
||||||
oldRatchetList: []
|
oldRatchetList: []
|
||||||
};
|
};
|
||||||
session[getString(preKeyPair.pubKey)] = { messageKeys: {}, chainKey: { counter: 0, key: firstRatchet.chainKey } };
|
session[getString(preKeyPair.pubKey)] = { messageKeys: {}, chainKey: { counter: -1, key: firstRatchet.chainKey } };
|
||||||
|
// This isnt an actual ratchet, its just here to make maybeStepRatchet work
|
||||||
|
session[getString(message.baseKey)] = { messageKeys: {}, chainKey: { counter: 0xffffffff, key: '' } };
|
||||||
crypto_storage.saveSession(encodedNumber, session);
|
crypto_storage.saveSession(encodedNumber, session);
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
|
@ -556,17 +556,19 @@ function getRandomBytes(size) {
|
||||||
|
|
||||||
ECDHE(remoteKey, ratchet.ephemeralKeyPair.privKey, function(sharedSecret) {
|
ECDHE(remoteKey, ratchet.ephemeralKeyPair.privKey, function(sharedSecret) {
|
||||||
var masterKey = HKDF(sharedSecret, ratchet.rootKey, "WhisperRatchet");
|
var masterKey = HKDF(sharedSecret, ratchet.rootKey, "WhisperRatchet");
|
||||||
session[getString(remoteKey)] = { messageKeys: {}, chainKey: { counter: 0, key: masterKey.substring(32, 64) } };
|
session[getString(remoteKey)] = { messageKeys: {}, chainKey: { counter: -1, key: masterKey[1] } };
|
||||||
|
|
||||||
createNewKeyPair(function(keyPair) {
|
createNewKeyPair(function(keyPair) {
|
||||||
ratchet.ephemeralKeyPair = keyPair;
|
ratchet.ephemeralKeyPair = keyPair;
|
||||||
|
|
||||||
masterKey = HKDF(ECDHE(remoteKey, ratchet.ephemeralKeyPair.privKey), masterKey.substring(0, 32), "WhisperRatchet");
|
ECDHE(remoteKey, ratchet.ephemeralKeyPair.privKey, function(sharedSecret) {
|
||||||
ratchet.rootKey = masterKey.substring(0, 32);
|
masterKey = HKDF(sharedSecret, masterKey[0], "WhisperRatchet");
|
||||||
session[getString(nextRatchet.ephemeralKeyPair.pubKey)] = { messageKeys: {}, chainKey: { counter: 0, key: masterKey.substring(32, 64) } };
|
ratchet.rootKey = masterKey[0];
|
||||||
|
session[getString(ratchet.ephemeralKeyPair.pubKey)] = { messageKeys: {}, chainKey: { counter: -1, key: masterKey[1] } };
|
||||||
|
|
||||||
ratchet.lastRemoteEphemeralKey = remoteKey;
|
ratchet.lastRemoteEphemeralKey = remoteKey;
|
||||||
callback();
|
callback();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue