s/textsecure.protocol/axolotl.protocol/
This commit is contained in:
parent
c1907b14eb
commit
bb32a51d66
6 changed files with 21 additions and 20 deletions
|
@ -135,7 +135,7 @@
|
||||||
|
|
||||||
$('#multi-device .status').text("Connecting...");
|
$('#multi-device .status').text("Connecting...");
|
||||||
$('#setup-qr').html('');
|
$('#setup-qr').html('');
|
||||||
textsecure.protocol.prepareTempWebsocket().then(function(cryptoInfo) {
|
axolotl.protocol.createIdentityKeyRecvSocket().then(function(cryptoInfo) {
|
||||||
var qrCode = new QRCode(document.getElementById('setup-qr'));
|
var qrCode = new QRCode(document.getElementById('setup-qr'));
|
||||||
|
|
||||||
var socket = textsecure.api.getTempWebsocket();
|
var socket = textsecure.api.getTempWebsocket();
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
;(function() {
|
;(function() {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
window.textsecure = window.textsecure || {};
|
window.axolotl = window.axolotl || {};
|
||||||
|
|
||||||
window.textsecure.protocol = function() {
|
window.axolotl.protocol = function() {
|
||||||
var self = {};
|
var self = {};
|
||||||
|
|
||||||
/******************************
|
/******************************
|
||||||
|
@ -677,7 +677,7 @@ window.textsecure.protocol = function() {
|
||||||
refreshPreKeys();
|
refreshPreKeys();
|
||||||
}, 60 * 1000);
|
}, 60 * 1000);
|
||||||
|
|
||||||
self.prepareTempWebsocket = function() {
|
self.createIdentityKeyRecvSocket = function() {
|
||||||
var socketInfo = {};
|
var socketInfo = {};
|
||||||
var keyPair;
|
var keyPair;
|
||||||
|
|
||||||
|
@ -697,9 +697,12 @@ window.textsecure.protocol = function() {
|
||||||
|
|
||||||
return verifyMAC(ivAndCiphertext, keys[1], mac).then(function() {
|
return verifyMAC(ivAndCiphertext, keys[1], mac).then(function() {
|
||||||
return window.axolotl.crypto.decrypt(keys[0], ciphertext, iv).then(function(plaintext) {
|
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) {
|
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);
|
crypto_storage.putKeyPair("identityKey", identityKeyPair);
|
||||||
identityKeyMsg.identityKeyPrivate = null;
|
identityKeyMsg.identityKeyPrivate = null;
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
//TODO
|
//TODO
|
||||||
/*if ((finalMessage.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
/*if ((finalMessage.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
||||||
== 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;
|
return finalMessage;
|
||||||
}
|
}
|
||||||
|
@ -47,31 +47,29 @@
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
window.textsecure.protocol_wrapper = {
|
window.textsecure.protocol_wrapper = {
|
||||||
handleIncomingPushMessageProto: function(proto) {
|
handleIncomingPushMessageProto: function(proto) {
|
||||||
|
|
||||||
|
|
||||||
switch(proto.type) {
|
switch(proto.type) {
|
||||||
case textsecure.protobuf.IncomingPushMessageSignal.Type.PLAINTEXT:
|
case textsecure.protobuf.IncomingPushMessageSignal.Type.PLAINTEXT:
|
||||||
return Promise.resolve(textsecure.protobuf.PushMessageContent.decode(proto.message));
|
return Promise.resolve(textsecure.protobuf.PushMessageContent.decode(proto.message));
|
||||||
case textsecure.protobuf.IncomingPushMessageSignal.Type.CIPHERTEXT:
|
case textsecure.protobuf.IncomingPushMessageSignal.Type.CIPHERTEXT:
|
||||||
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
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:
|
case textsecure.protobuf.IncomingPushMessageSignal.Type.PREKEY_BUNDLE:
|
||||||
if (proto.message.readUint8() != ((3 << 4) | 3))
|
if (proto.message.readUint8() != ((3 << 4) | 3))
|
||||||
throw new Error("Bad version byte");
|
throw new Error("Bad version byte");
|
||||||
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
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:
|
case textsecure.protobuf.IncomingPushMessageSignal.Type.RECEIPT:
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
case textsecure.protobuf.IncomingPushMessageSignal.Type.PREKEY_BUNDLE_DEVICE_CONTROL:
|
case textsecure.protobuf.IncomingPushMessageSignal.Type.PREKEY_BUNDLE_DEVICE_CONTROL:
|
||||||
if (proto.message.readUint8() != ((3 << 4) | 3))
|
if (proto.message.readUint8() != ((3 << 4) | 3))
|
||||||
throw new Error("Bad version byte");
|
throw new Error("Bad version byte");
|
||||||
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
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]);
|
return textsecure.protobuf.DeviceControl.decode(res[0]);
|
||||||
});
|
});
|
||||||
case textsecure.protobuf.IncomingPushMessageSignal.Type.DEVICE_CONTROL:
|
case textsecure.protobuf.IncomingPushMessageSignal.Type.DEVICE_CONTROL:
|
||||||
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
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]);
|
return textsecure.protobuf.DeviceControl.decode(res[0]);
|
||||||
});
|
});
|
||||||
default:
|
default:
|
||||||
|
@ -85,7 +83,7 @@
|
||||||
//TODO: Encapsuate with the rest of textsecure.storage.devices
|
//TODO: Encapsuate with the rest of textsecure.storage.devices
|
||||||
textsecure.storage.removeEncrypted("devices" + from.split('.')[0]);
|
textsecure.storage.removeEncrypted("devices" + from.split('.')[0]);
|
||||||
//TODO: Probably breaks with a devicecontrol message
|
//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) {
|
function(pushMessageContent) {
|
||||||
extension.trigger('message:decrypted', {
|
extension.trigger('message:decrypted', {
|
||||||
message_id : message_id,
|
message_id : message_id,
|
||||||
|
|
|
@ -259,7 +259,7 @@ window.textsecure.registerSingleDevice = function(number, verificationCode, step
|
||||||
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(number));
|
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(number));
|
||||||
stepDone(1);
|
stepDone(1);
|
||||||
|
|
||||||
return textsecure.protocol.generateKeys().then(function(keys) {
|
return axolotl.protocol.generateKeys().then(function(keys) {
|
||||||
stepDone(2);
|
stepDone(2);
|
||||||
return textsecure.api.registerKeys(keys).then(function() {
|
return textsecure.api.registerKeys(keys).then(function() {
|
||||||
stepDone(3);
|
stepDone(3);
|
||||||
|
@ -290,7 +290,7 @@ window.textsecure.registerSecondDevice = function(encodedProvisionEnvelope, cryp
|
||||||
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(identityKey.number));
|
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(identityKey.number));
|
||||||
stepDone(2);
|
stepDone(2);
|
||||||
|
|
||||||
return textsecure.protocol.generateKeys().then(function(keys) {
|
return axolotl.protocol.generateKeys().then(function(keys) {
|
||||||
stepDone(3);
|
stepDone(3);
|
||||||
return textsecure.api.registerKeys(keys).then(function() {
|
return textsecure.api.registerKeys(keys).then(function() {
|
||||||
stepDone(4);
|
stepDone(4);
|
||||||
|
|
|
@ -65,7 +65,7 @@ window.textsecure.messaging = function() {
|
||||||
return new Promise(function() { throw new Error("Mismatched relays for number " + number); });
|
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] = {
|
jsonData[i] = {
|
||||||
type: encryptedMsg.type,
|
type: encryptedMsg.type,
|
||||||
destinationDeviceId: textsecure.utils.unencodeNumber(deviceObjectList[i].encodedNumber)[1],
|
destinationDeviceId: textsecure.utils.unencodeNumber(deviceObjectList[i].encodedNumber)[1],
|
||||||
|
@ -289,7 +289,7 @@ window.textsecure.messaging = function() {
|
||||||
return sendIndividualProto(number, proto).then(function(res) {
|
return sendIndividualProto(number, proto).then(function(res) {
|
||||||
var devices = textsecure.storage.devices.getDeviceObjectsForNumber(number);
|
var devices = textsecure.storage.devices.getDeviceObjectsForNumber(number);
|
||||||
for (var i in devices)
|
for (var i in devices)
|
||||||
textsecure.protocol.closeOpenSessionForDevice(devices[i].encodedNumber);
|
axolotl.protocol.closeOpenSessionForDevice(devices[i].encodedNumber);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
});
|
});
|
||||||
|
|
|
@ -47,14 +47,14 @@ describe('Protocol', function() {
|
||||||
after(function() { localStorage.clear(); });
|
after(function() { localStorage.clear(); });
|
||||||
it ('works', function(done) {
|
it ('works', function(done) {
|
||||||
localStorage.clear();
|
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("25519KeyidentityKey"));
|
||||||
assert.isDefined(textsecure.storage.getEncrypted("25519KeysignedKey0"));
|
assert.isDefined(textsecure.storage.getEncrypted("25519KeysignedKey0"));
|
||||||
for (var i = 0; i < 100; i++) {
|
for (var i = 0; i < 100; i++) {
|
||||||
assert.isDefined(textsecure.storage.getEncrypted("25519KeypreKey" + i));
|
assert.isDefined(textsecure.storage.getEncrypted("25519KeypreKey" + i));
|
||||||
}
|
}
|
||||||
var origIdentityKey = getString(textsecure.storage.getEncrypted("25519KeyidentityKey").privKey);
|
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.isDefined(textsecure.storage.getEncrypted("25519KeyidentityKey"));
|
||||||
assert.equal(getString(textsecure.storage.getEncrypted("25519KeyidentityKey").privKey), origIdentityKey);
|
assert.equal(getString(textsecure.storage.getEncrypted("25519KeyidentityKey").privKey), origIdentityKey);
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ describe('Protocol', function() {
|
||||||
assert.isDefined(textsecure.storage.getEncrypted("25519KeypreKey" + i));
|
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.isDefined(textsecure.storage.getEncrypted("25519KeyidentityKey"));
|
||||||
assert.equal(getString(textsecure.storage.getEncrypted("25519KeyidentityKey").privKey), origIdentityKey);
|
assert.equal(getString(textsecure.storage.getEncrypted("25519KeyidentityKey").privKey), origIdentityKey);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue