s/textsecure.protocol/axolotl.protocol/

This commit is contained in:
Matt Corallo 2015-01-15 19:18:31 -10:00 committed by lilia
parent c1907b14eb
commit bb32a51d66
6 changed files with 21 additions and 20 deletions

View file

@ -135,7 +135,7 @@
$('#multi-device .status').text("Connecting...");
$('#setup-qr').html('');
textsecure.protocol.prepareTempWebsocket().then(function(cryptoInfo) {
axolotl.protocol.createIdentityKeyRecvSocket().then(function(cryptoInfo) {
var qrCode = new QRCode(document.getElementById('setup-qr'));
var socket = textsecure.api.getTempWebsocket();

View file

@ -16,9 +16,9 @@
;(function() {
'use strict';
window.textsecure = window.textsecure || {};
window.axolotl = window.axolotl || {};
window.textsecure.protocol = function() {
window.axolotl.protocol = function() {
var self = {};
/******************************
@ -677,7 +677,7 @@ window.textsecure.protocol = function() {
refreshPreKeys();
}, 60 * 1000);
self.prepareTempWebsocket = function() {
self.createIdentityKeyRecvSocket = function() {
var socketInfo = {};
var keyPair;
@ -697,9 +697,12 @@ window.textsecure.protocol = function() {
return verifyMAC(ivAndCiphertext, keys[1], mac).then(function() {
return window.axolotl.crypto.decrypt(keys[0], ciphertext, iv).then(function(plaintext) {
var identityKeyMsg = textsecure.protobuf.ProvisionMessage.decode(plaintext);
var identityKeyMsg = axolotl.protobuf.ProvisionMessage.decode(plaintext);
return axolotl.crypto.createKeyPair(toArrayBuffer(identityKeyMsg.identityKeyPrivate)).then(function(identityKeyPair) {
if (crypto_storage.getStoredKeyPair("identityKey") !== undefined)
throw new Error("Tried to overwrite identity key");
crypto_storage.putKeyPair("identityKey", identityKeyPair);
identityKeyMsg.identityKeyPrivate = null;

View file

@ -39,7 +39,7 @@
//TODO
/*if ((finalMessage.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
== textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
textsecure.protocol.closeSession(res[1], true);*/
axolotl.protocol.closeSession(res[1], true);*/
return finalMessage;
}
@ -47,31 +47,29 @@
window.textsecure = window.textsecure || {};
window.textsecure.protocol_wrapper = {
handleIncomingPushMessageProto: function(proto) {
switch(proto.type) {
case textsecure.protobuf.IncomingPushMessageSignal.Type.PLAINTEXT:
return Promise.resolve(textsecure.protobuf.PushMessageContent.decode(proto.message));
case textsecure.protobuf.IncomingPushMessageSignal.Type.CIPHERTEXT:
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
return textsecure.protocol.decryptWhisperMessage(from, getString(proto.message)).then(decodeMessageContents);
return axolotl.protocol.decryptWhisperMessage(from, getString(proto.message)).then(decodeMessageContents);
case textsecure.protobuf.IncomingPushMessageSignal.Type.PREKEY_BUNDLE:
if (proto.message.readUint8() != ((3 << 4) | 3))
throw new Error("Bad version byte");
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
return textsecure.protocol.handlePreKeyWhisperMessage(from, getString(proto.message)).then(decodeMessageContents);
return axolotl.protocol.handlePreKeyWhisperMessage(from, getString(proto.message)).then(decodeMessageContents);
case textsecure.protobuf.IncomingPushMessageSignal.Type.RECEIPT:
return Promise.resolve(null);
case textsecure.protobuf.IncomingPushMessageSignal.Type.PREKEY_BUNDLE_DEVICE_CONTROL:
if (proto.message.readUint8() != ((3 << 4) | 3))
throw new Error("Bad version byte");
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
return textsecure.protocol.handlePreKeyWhisperMessage(from, getString(proto.message)).then(function(res) {
return axolotl.protocol.handlePreKeyWhisperMessage(from, getString(proto.message)).then(function(res) {
return textsecure.protobuf.DeviceControl.decode(res[0]);
});
case textsecure.protobuf.IncomingPushMessageSignal.Type.DEVICE_CONTROL:
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
return textsecure.protocol.decryptWhisperMessage(from, getString(proto.message)).then(function(res) {
return axolotl.protocol.decryptWhisperMessage(from, getString(proto.message)).then(function(res) {
return textsecure.protobuf.DeviceControl.decode(res[0]);
});
default:
@ -85,7 +83,7 @@
//TODO: Encapsuate with the rest of textsecure.storage.devices
textsecure.storage.removeEncrypted("devices" + from.split('.')[0]);
//TODO: Probably breaks with a devicecontrol message
return textsecure.protocol.handlePreKeyWhisperMessage(from, encodedMessage).then(decodeMessageContents).then(
return axolotl.protocol.handlePreKeyWhisperMessage(from, encodedMessage).then(decodeMessageContents).then(
function(pushMessageContent) {
extension.trigger('message:decrypted', {
message_id : message_id,

View file

@ -259,7 +259,7 @@ window.textsecure.registerSingleDevice = function(number, verificationCode, step
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(number));
stepDone(1);
return textsecure.protocol.generateKeys().then(function(keys) {
return axolotl.protocol.generateKeys().then(function(keys) {
stepDone(2);
return textsecure.api.registerKeys(keys).then(function() {
stepDone(3);
@ -290,7 +290,7 @@ window.textsecure.registerSecondDevice = function(encodedProvisionEnvelope, cryp
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(identityKey.number));
stepDone(2);
return textsecure.protocol.generateKeys().then(function(keys) {
return axolotl.protocol.generateKeys().then(function(keys) {
stepDone(3);
return textsecure.api.registerKeys(keys).then(function() {
stepDone(4);

View file

@ -65,7 +65,7 @@ window.textsecure.messaging = function() {
return new Promise(function() { throw new Error("Mismatched relays for number " + number); });
}
return textsecure.protocol.encryptMessageFor(deviceObjectList[i], message).then(function(encryptedMsg) {
return axolotl.protocol.encryptMessageFor(deviceObjectList[i], message).then(function(encryptedMsg) {
jsonData[i] = {
type: encryptedMsg.type,
destinationDeviceId: textsecure.utils.unencodeNumber(deviceObjectList[i].encodedNumber)[1],
@ -289,7 +289,7 @@ window.textsecure.messaging = function() {
return sendIndividualProto(number, proto).then(function(res) {
var devices = textsecure.storage.devices.getDeviceObjectsForNumber(number);
for (var i in devices)
textsecure.protocol.closeOpenSessionForDevice(devices[i].encodedNumber);
axolotl.protocol.closeOpenSessionForDevice(devices[i].encodedNumber);
return res;
});

View file

@ -47,14 +47,14 @@ describe('Protocol', function() {
after(function() { localStorage.clear(); });
it ('works', function(done) {
localStorage.clear();
return textsecure.protocol.generateKeys().then(function() {
return axolotl.protocol.generateKeys().then(function() {
assert.isDefined(textsecure.storage.getEncrypted("25519KeyidentityKey"));
assert.isDefined(textsecure.storage.getEncrypted("25519KeysignedKey0"));
for (var i = 0; i < 100; i++) {
assert.isDefined(textsecure.storage.getEncrypted("25519KeypreKey" + i));
}
var origIdentityKey = getString(textsecure.storage.getEncrypted("25519KeyidentityKey").privKey);
return textsecure.protocol.generateKeys().then(function() {
return axolotl.protocol.generateKeys().then(function() {
assert.isDefined(textsecure.storage.getEncrypted("25519KeyidentityKey"));
assert.equal(getString(textsecure.storage.getEncrypted("25519KeyidentityKey").privKey), origIdentityKey);
@ -65,7 +65,7 @@ describe('Protocol', function() {
assert.isDefined(textsecure.storage.getEncrypted("25519KeypreKey" + i));
}
return textsecure.protocol.generateKeys().then(function() {
return axolotl.protocol.generateKeys().then(function() {
assert.isDefined(textsecure.storage.getEncrypted("25519KeyidentityKey"));
assert.equal(getString(textsecure.storage.getEncrypted("25519KeyidentityKey").privKey), origIdentityKey);