Move prekey sigcheck to libaxolotl

This commit is contained in:
Matt Corallo 2015-01-15 21:52:50 -10:00 committed by lilia
parent cb6cb4ff89
commit 12844590f5
3 changed files with 20 additions and 17 deletions

View file

@ -567,6 +567,7 @@ window.axolotl.protocol = function() {
try { try {
delete deviceObject['signedKey']; delete deviceObject['signedKey'];
delete deviceObject['signedKeyId']; delete deviceObject['signedKeyId'];
delete deviceObject['signedKeySignature'];
delete deviceObject['preKey']; delete deviceObject['preKey'];
delete deviceObject['preKeyId']; delete deviceObject['preKeyId'];
} catch(_) {} } catch(_) {}
@ -586,12 +587,15 @@ window.axolotl.protocol = function() {
preKeyMsg.registrationId = axolotl.api.getMyRegistrationId(); preKeyMsg.registrationId = axolotl.api.getMyRegistrationId();
if (session === undefined) { if (session === undefined) {
var deviceIdentityKey = toArrayBuffer(deviceObject.identityKey);
var deviceSignedKey = toArrayBuffer(deviceObject.signedKey);
return axolotl.crypto.Ed25519Verify(deviceIdentityKey, deviceSignedKey, toArrayBuffer(deviceObject.signedKeySignature)).then(function() {
return axolotl.crypto.createKeyPair().then(function(baseKey) { return axolotl.crypto.createKeyPair().then(function(baseKey) {
preKeyMsg.preKeyId = deviceObject.preKeyId; preKeyMsg.preKeyId = deviceObject.preKeyId;
preKeyMsg.signedPreKeyId = deviceObject.signedKeyId; preKeyMsg.signedPreKeyId = deviceObject.signedKeyId;
preKeyMsg.baseKey = toArrayBuffer(baseKey.pubKey); preKeyMsg.baseKey = toArrayBuffer(baseKey.pubKey);
return initSession(true, baseKey, undefined, deviceObject.encodedNumber, return initSession(true, baseKey, undefined, deviceObject.encodedNumber,
toArrayBuffer(deviceObject.identityKey), toArrayBuffer(deviceObject.preKey), toArrayBuffer(deviceObject.signedKey)) deviceIdentityKey, toArrayBuffer(deviceObject.preKey), deviceSignedKey)
.then(function(new_session) { .then(function(new_session) {
session = new_session; session = new_session;
session.pendingPreKey = { preKeyId: deviceObject.preKeyId, signedKeyId: deviceObject.signedKeyId, baseKey: baseKey.pubKey }; session.pendingPreKey = { preKeyId: deviceObject.preKeyId, signedKeyId: deviceObject.signedKeyId, baseKey: baseKey.pubKey };
@ -602,6 +606,7 @@ window.axolotl.protocol = function() {
}); });
}); });
}); });
});
} else } else
return doEncryptPushMessageContent().then(function(message) { return doEncryptPushMessageContent().then(function(message) {
if (session.pendingPreKey !== undefined) { if (session.pendingPreKey !== undefined) {

View file

@ -196,16 +196,13 @@ window.textsecure.api = function () {
for (var i = 0; i < res.devices.length; i++) { for (var i = 0; i < res.devices.length; i++) {
res.devices[i].signedPreKey.publicKey = StringView.base64ToBytes(res.devices[i].signedPreKey.publicKey); res.devices[i].signedPreKey.publicKey = StringView.base64ToBytes(res.devices[i].signedPreKey.publicKey);
res.devices[i].signedPreKey.signature = StringView.base64ToBytes(res.devices[i].signedPreKey.signature); res.devices[i].signedPreKey.signature = StringView.base64ToBytes(res.devices[i].signedPreKey.signature);
promises[i] = window.axolotl.crypto.Ed25519Verify(res.identityKey, res.devices[i].signedPreKey.publicKey, res.devices[i].signedPreKey.signature);
res.devices[i].preKey.publicKey = StringView.base64ToBytes(res.devices[i].preKey.publicKey); res.devices[i].preKey.publicKey = StringView.base64ToBytes(res.devices[i].preKey.publicKey);
//TODO: Is this still needed? //TODO: Is this still needed?
//if (res.devices[i].keyId === undefined) //if (res.devices[i].keyId === undefined)
// res.devices[i].keyId = 0; // res.devices[i].keyId = 0;
} }
return Promise.all(promises).then(function() {
return res; return res;
}); });
});
}; };
self.sendMessages = function(destination, messageArray) { self.sendMessages = function(destination, messageArray) {

View file

@ -30,6 +30,7 @@ window.textsecure.messaging = function() {
preKeyId: response.devices[i].preKey.keyId, preKeyId: response.devices[i].preKey.keyId,
signedKey: response.devices[i].signedPreKey.publicKey, signedKey: response.devices[i].signedPreKey.publicKey,
signedKeyId: response.devices[i].signedPreKey.keyId, signedKeyId: response.devices[i].signedPreKey.keyId,
signedKeySignature: response.devices[i].signedPreKey.signature,
registrationId: response.devices[i].registrationId registrationId: response.devices[i].registrationId
}); });
} }