Update libsignal-protocol / Update prekey format

Integrates change in prekey object formatting, which now matches more
conveniently with the representation rendered by the server.

// FREEBIE
This commit is contained in:
lilia 2016-04-27 15:21:44 -07:00
parent 6589ec544a
commit 9f871db48a
6 changed files with 49 additions and 105 deletions

View File

@ -34627,19 +34627,7 @@ window.libsignal.protocol = function(storage_interface) {
var address = SignalProtocolAddress.fromString(deviceObject.encodedNumber);
var builder = new SessionBuilder(storage_interface, address);
return builder.processPreKey({
identityKey: toArrayBuffer(deviceObject.identityKey),
preKey: {
keyId: deviceObject.preKeyId,
publicKey: toArrayBuffer(deviceObject.preKey),
},
signedPreKey: {
keyId: deviceObject.signedKeyId,
publicKey: toArrayBuffer(deviceObject.signedKey),
signature: toArrayBuffer(deviceObject.signedKeySignature),
},
registrationId: deviceObject.registrationId
});
return builder.processPreKey(deviceObject);
}
}).then(function() {
return getRecord(deviceObject.encodedNumber).then(function(refreshed) {
@ -35458,6 +35446,13 @@ libsignal.SessionBuilder = SessionBuilder;
throw e;
});
});
},
processPreKey: function(preKeyBundle) {
return queueJobForNumber(preKeyBundle.encodedNumber, function() {
var address = libsignal.SignalProtocolAddress.fromString(preKeyBundle.encodedNumber);
var builder = new libsignal.SessionBuilder(textsecure.storage.protocol, address);
return builder.processPreKey(preKeyBundle);
});
}
};
})();
@ -35699,24 +35694,8 @@ libsignal.SessionBuilder = SessionBuilder;
window.textsecure.storage.devices = {
saveKeysToDeviceObject: function(deviceObject) {
var number = textsecure.utils.unencodeNumber(deviceObject.encodedNumber)[0];
return textsecure.storage.protocol.loadIdentityKey(number).then(function(identityKey) {
if (identityKey !== undefined && deviceObject.identityKey !== undefined && getString(identityKey) != getString(deviceObject.identityKey)) {
var error = new Error("Identity key changed");
error.identityKey = deviceObject.identityKey;
throw error;
}
return textsecure.storage.protocol.putIdentityKey(number, deviceObject.identityKey).then(function() {
tempKeys[deviceObject.encodedNumber] = {
preKey: deviceObject.preKey,
preKeyId: deviceObject.preKeyId,
signedKey: deviceObject.signedKey,
signedKeyId: deviceObject.signedKeyId,
signedKeySignature: deviceObject.signedKeySignature,
registrationId: deviceObject.registrationId
};
});
return textsecure.protocol_wrapper.processPreKey(deviceObject).then(function() {
tempKeys[deviceObject.encodedNumber] = deviceObject;
});
},
@ -37480,23 +37459,19 @@ OutgoingMessage.prototype = {
getKeysForNumber: function(number, updateDevices) {
var handleResult = function(response) {
return Promise.all(response.devices.map(function(device) {
if (updateDevices === undefined || updateDevices.indexOf(device.deviceId) > -1)
return textsecure.storage.devices.saveKeysToDeviceObject({
encodedNumber: number + "." + device.deviceId,
identityKey: response.identityKey,
preKey: device.preKey.publicKey,
preKeyId: device.preKey.keyId,
signedKey: device.signedPreKey.publicKey,
signedKeyId: device.signedPreKey.keyId,
signedKeySignature: device.signedPreKey.signature,
registrationId: device.registrationId
}).catch(function(error) {
device.identityKey = response.identityKey;
device.encodedNumber = number + "." + device.deviceId;
if (updateDevices === undefined || updateDevices.indexOf(device.deviceId) > -1) {
return textsecure.storage.devices.saveKeysToDeviceObject(device).catch(function(error) {
if (error.message === "Identity key changed") {
error = new textsecure.OutgoingIdentityKeyError(number, this.message.toArrayBuffer(), this.timestamp, error.identityKey);
error = new textsecure.OutgoingIdentityKeyError(
number, this.message.toArrayBuffer(),
this.timestamp, device.identityKey);
this.registerError(number, "Identity key changed", error);
}
throw error;
}.bind(this));
}
}.bind(this)));
}.bind(this);

View File

@ -34513,19 +34513,7 @@ window.libsignal.protocol = function(storage_interface) {
var address = SignalProtocolAddress.fromString(deviceObject.encodedNumber);
var builder = new SessionBuilder(storage_interface, address);
return builder.processPreKey({
identityKey: toArrayBuffer(deviceObject.identityKey),
preKey: {
keyId: deviceObject.preKeyId,
publicKey: toArrayBuffer(deviceObject.preKey),
},
signedPreKey: {
keyId: deviceObject.signedKeyId,
publicKey: toArrayBuffer(deviceObject.signedKey),
signature: toArrayBuffer(deviceObject.signedKeySignature),
},
registrationId: deviceObject.registrationId
});
return builder.processPreKey(deviceObject);
}
}).then(function() {
return getRecord(deviceObject.encodedNumber).then(function(refreshed) {

View File

@ -52,23 +52,19 @@ OutgoingMessage.prototype = {
getKeysForNumber: function(number, updateDevices) {
var handleResult = function(response) {
return Promise.all(response.devices.map(function(device) {
if (updateDevices === undefined || updateDevices.indexOf(device.deviceId) > -1)
return textsecure.storage.devices.saveKeysToDeviceObject({
encodedNumber: number + "." + device.deviceId,
identityKey: response.identityKey,
preKey: device.preKey.publicKey,
preKeyId: device.preKey.keyId,
signedKey: device.signedPreKey.publicKey,
signedKeyId: device.signedPreKey.keyId,
signedKeySignature: device.signedPreKey.signature,
registrationId: device.registrationId
}).catch(function(error) {
device.identityKey = response.identityKey;
device.encodedNumber = number + "." + device.deviceId;
if (updateDevices === undefined || updateDevices.indexOf(device.deviceId) > -1) {
return textsecure.storage.devices.saveKeysToDeviceObject(device).catch(function(error) {
if (error.message === "Identity key changed") {
error = new textsecure.OutgoingIdentityKeyError(number, this.message.toArrayBuffer(), this.timestamp, error.identityKey);
error = new textsecure.OutgoingIdentityKeyError(
number, this.message.toArrayBuffer(),
this.timestamp, device.identityKey);
this.registerError(number, "Identity key changed", error);
}
throw error;
}.bind(this));
}
}.bind(this)));
}.bind(this);

View File

@ -82,6 +82,13 @@
throw e;
});
});
},
processPreKey: function(preKeyBundle) {
return queueJobForNumber(preKeyBundle.encodedNumber, function() {
var address = libsignal.SignalProtocolAddress.fromString(preKeyBundle.encodedNumber);
var builder = new libsignal.SessionBuilder(textsecure.storage.protocol, address);
return builder.processPreKey(preKeyBundle);
});
}
};
})();

View File

@ -15,24 +15,8 @@
window.textsecure.storage.devices = {
saveKeysToDeviceObject: function(deviceObject) {
var number = textsecure.utils.unencodeNumber(deviceObject.encodedNumber)[0];
return textsecure.storage.protocol.loadIdentityKey(number).then(function(identityKey) {
if (identityKey !== undefined && deviceObject.identityKey !== undefined && getString(identityKey) != getString(deviceObject.identityKey)) {
var error = new Error("Identity key changed");
error.identityKey = deviceObject.identityKey;
throw error;
}
return textsecure.storage.protocol.putIdentityKey(number, deviceObject.identityKey).then(function() {
tempKeys[deviceObject.encodedNumber] = {
preKey: deviceObject.preKey,
preKeyId: deviceObject.preKeyId,
signedKey: deviceObject.signedKey,
signedKeyId: deviceObject.signedKeyId,
signedKeySignature: deviceObject.signedKeySignature,
registrationId: deviceObject.registrationId
};
});
return textsecure.protocol_wrapper.processPreKey(deviceObject).then(function() {
tempKeys[deviceObject.encodedNumber] = deviceObject;
});
},

View File

@ -5,33 +5,27 @@
'use strict';
describe('Device storage', function() {
before(function() { localStorage.clear(); });
var store = textsecure.storage.protocol;
var identifier = '+5558675309';
var another_identifier = '+5555590210';
var identityKey = {
pubKey: textsecure.crypto.getRandomBytes(33),
privKey: textsecure.crypto.getRandomBytes(32),
};
var testKey = {
pubKey: textsecure.crypto.getRandomBytes(33),
privKey: textsecure.crypto.getRandomBytes(32),
};
var prekeys, identityKey, testKey;
this.timeout(5000);
before(function(done) {
localStorage.clear();
libsignal.util.generateIdentityKeyPair().then(function(identityKey) {
return textsecure.storage.protocol.putIdentityKey(identifier, identityKey);
}).then(done);
});
describe('saveKeysToDeviceObject', function() {
it('rejects if the identity key changes', function(done) {
return textsecure.storage.devices.saveKeysToDeviceObject({
identityKey: identityKey.pubKey,
identityKey: textsecure.crypto.getRandomBytes(33),
encodedNumber: identifier + '.1'
}).then(function() {
textsecure.storage.devices.saveKeysToDeviceObject({
identityKey: testKey.pubKey,
encodedNumber: identifier + '.1'
}).then(function() {
done(new Error('Allowed to overwrite identity key'));
}).catch(function(e) {
assert.strictEqual(e.message, 'Identity key changed');
done();
});
done(new Error('Allowed to overwrite identity key'));
}).catch(function(e) {
assert.strictEqual(e.message, 'Identity key changed');
done();
});
});
});