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,19 +587,23 @@ window.axolotl.protocol = function() {
preKeyMsg.registrationId = axolotl.api.getMyRegistrationId(); preKeyMsg.registrationId = axolotl.api.getMyRegistrationId();
if (session === undefined) { if (session === undefined) {
return axolotl.crypto.createKeyPair().then(function(baseKey) { var deviceIdentityKey = toArrayBuffer(deviceObject.identityKey);
preKeyMsg.preKeyId = deviceObject.preKeyId; var deviceSignedKey = toArrayBuffer(deviceObject.signedKey);
preKeyMsg.signedPreKeyId = deviceObject.signedKeyId; return axolotl.crypto.Ed25519Verify(deviceIdentityKey, deviceSignedKey, toArrayBuffer(deviceObject.signedKeySignature)).then(function() {
preKeyMsg.baseKey = toArrayBuffer(baseKey.pubKey); return axolotl.crypto.createKeyPair().then(function(baseKey) {
return initSession(true, baseKey, undefined, deviceObject.encodedNumber, preKeyMsg.preKeyId = deviceObject.preKeyId;
toArrayBuffer(deviceObject.identityKey), toArrayBuffer(deviceObject.preKey), toArrayBuffer(deviceObject.signedKey)) preKeyMsg.signedPreKeyId = deviceObject.signedKeyId;
.then(function(new_session) { preKeyMsg.baseKey = toArrayBuffer(baseKey.pubKey);
session = new_session; return initSession(true, baseKey, undefined, deviceObject.encodedNumber,
session.pendingPreKey = { preKeyId: deviceObject.preKeyId, signedKeyId: deviceObject.signedKeyId, baseKey: baseKey.pubKey }; deviceIdentityKey, toArrayBuffer(deviceObject.preKey), deviceSignedKey)
return doEncryptPushMessageContent().then(function(message) { .then(function(new_session) {
preKeyMsg.message = message; session = new_session;
var result = String.fromCharCode((3 << 4) | 3) + getString(preKeyMsg.encode()); session.pendingPreKey = { preKeyId: deviceObject.preKeyId, signedKeyId: deviceObject.signedKeyId, baseKey: baseKey.pubKey };
return {type: 3, body: result}; return doEncryptPushMessageContent().then(function(message) {
preKeyMsg.message = message;
var result = String.fromCharCode((3 << 4) | 3) + getString(preKeyMsg.encode());
return {type: 3, body: result};
});
}); });
}); });
}); });

View file

@ -196,15 +196,12 @@ 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;
});
}); });
}; };

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
}); });
} }