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:
parent
6589ec544a
commit
9f871db48a
6 changed files with 49 additions and 105 deletions
|
@ -34627,19 +34627,7 @@ window.libsignal.protocol = function(storage_interface) {
|
||||||
var address = SignalProtocolAddress.fromString(deviceObject.encodedNumber);
|
var address = SignalProtocolAddress.fromString(deviceObject.encodedNumber);
|
||||||
var builder = new SessionBuilder(storage_interface, address);
|
var builder = new SessionBuilder(storage_interface, address);
|
||||||
|
|
||||||
return builder.processPreKey({
|
return builder.processPreKey(deviceObject);
|
||||||
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
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
return getRecord(deviceObject.encodedNumber).then(function(refreshed) {
|
return getRecord(deviceObject.encodedNumber).then(function(refreshed) {
|
||||||
|
@ -35458,6 +35446,13 @@ libsignal.SessionBuilder = SessionBuilder;
|
||||||
throw e;
|
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 = {
|
window.textsecure.storage.devices = {
|
||||||
saveKeysToDeviceObject: function(deviceObject) {
|
saveKeysToDeviceObject: function(deviceObject) {
|
||||||
var number = textsecure.utils.unencodeNumber(deviceObject.encodedNumber)[0];
|
return textsecure.protocol_wrapper.processPreKey(deviceObject).then(function() {
|
||||||
return textsecure.storage.protocol.loadIdentityKey(number).then(function(identityKey) {
|
tempKeys[deviceObject.encodedNumber] = deviceObject;
|
||||||
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
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -37480,23 +37459,19 @@ OutgoingMessage.prototype = {
|
||||||
getKeysForNumber: function(number, updateDevices) {
|
getKeysForNumber: function(number, updateDevices) {
|
||||||
var handleResult = function(response) {
|
var handleResult = function(response) {
|
||||||
return Promise.all(response.devices.map(function(device) {
|
return Promise.all(response.devices.map(function(device) {
|
||||||
if (updateDevices === undefined || updateDevices.indexOf(device.deviceId) > -1)
|
device.identityKey = response.identityKey;
|
||||||
return textsecure.storage.devices.saveKeysToDeviceObject({
|
device.encodedNumber = number + "." + device.deviceId;
|
||||||
encodedNumber: number + "." + device.deviceId,
|
if (updateDevices === undefined || updateDevices.indexOf(device.deviceId) > -1) {
|
||||||
identityKey: response.identityKey,
|
return textsecure.storage.devices.saveKeysToDeviceObject(device).catch(function(error) {
|
||||||
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) {
|
|
||||||
if (error.message === "Identity key changed") {
|
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);
|
this.registerError(number, "Identity key changed", error);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
}
|
||||||
}.bind(this)));
|
}.bind(this)));
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
|
|
|
@ -34513,19 +34513,7 @@ window.libsignal.protocol = function(storage_interface) {
|
||||||
var address = SignalProtocolAddress.fromString(deviceObject.encodedNumber);
|
var address = SignalProtocolAddress.fromString(deviceObject.encodedNumber);
|
||||||
var builder = new SessionBuilder(storage_interface, address);
|
var builder = new SessionBuilder(storage_interface, address);
|
||||||
|
|
||||||
return builder.processPreKey({
|
return builder.processPreKey(deviceObject);
|
||||||
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
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
return getRecord(deviceObject.encodedNumber).then(function(refreshed) {
|
return getRecord(deviceObject.encodedNumber).then(function(refreshed) {
|
||||||
|
|
|
@ -52,23 +52,19 @@ OutgoingMessage.prototype = {
|
||||||
getKeysForNumber: function(number, updateDevices) {
|
getKeysForNumber: function(number, updateDevices) {
|
||||||
var handleResult = function(response) {
|
var handleResult = function(response) {
|
||||||
return Promise.all(response.devices.map(function(device) {
|
return Promise.all(response.devices.map(function(device) {
|
||||||
if (updateDevices === undefined || updateDevices.indexOf(device.deviceId) > -1)
|
device.identityKey = response.identityKey;
|
||||||
return textsecure.storage.devices.saveKeysToDeviceObject({
|
device.encodedNumber = number + "." + device.deviceId;
|
||||||
encodedNumber: number + "." + device.deviceId,
|
if (updateDevices === undefined || updateDevices.indexOf(device.deviceId) > -1) {
|
||||||
identityKey: response.identityKey,
|
return textsecure.storage.devices.saveKeysToDeviceObject(device).catch(function(error) {
|
||||||
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) {
|
|
||||||
if (error.message === "Identity key changed") {
|
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);
|
this.registerError(number, "Identity key changed", error);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
}
|
||||||
}.bind(this)));
|
}.bind(this)));
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,13 @@
|
||||||
throw e;
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -15,24 +15,8 @@
|
||||||
|
|
||||||
window.textsecure.storage.devices = {
|
window.textsecure.storage.devices = {
|
||||||
saveKeysToDeviceObject: function(deviceObject) {
|
saveKeysToDeviceObject: function(deviceObject) {
|
||||||
var number = textsecure.utils.unencodeNumber(deviceObject.encodedNumber)[0];
|
return textsecure.protocol_wrapper.processPreKey(deviceObject).then(function() {
|
||||||
return textsecure.storage.protocol.loadIdentityKey(number).then(function(identityKey) {
|
tempKeys[deviceObject.encodedNumber] = deviceObject;
|
||||||
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
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -5,33 +5,27 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
describe('Device storage', function() {
|
describe('Device storage', function() {
|
||||||
before(function() { localStorage.clear(); });
|
|
||||||
var store = textsecure.storage.protocol;
|
var store = textsecure.storage.protocol;
|
||||||
var identifier = '+5558675309';
|
var identifier = '+5558675309';
|
||||||
var another_identifier = '+5555590210';
|
var another_identifier = '+5555590210';
|
||||||
var identityKey = {
|
var prekeys, identityKey, testKey;
|
||||||
pubKey: textsecure.crypto.getRandomBytes(33),
|
this.timeout(5000);
|
||||||
privKey: textsecure.crypto.getRandomBytes(32),
|
before(function(done) {
|
||||||
};
|
localStorage.clear();
|
||||||
var testKey = {
|
libsignal.util.generateIdentityKeyPair().then(function(identityKey) {
|
||||||
pubKey: textsecure.crypto.getRandomBytes(33),
|
return textsecure.storage.protocol.putIdentityKey(identifier, identityKey);
|
||||||
privKey: textsecure.crypto.getRandomBytes(32),
|
}).then(done);
|
||||||
};
|
});
|
||||||
describe('saveKeysToDeviceObject', function() {
|
describe('saveKeysToDeviceObject', function() {
|
||||||
it('rejects if the identity key changes', function(done) {
|
it('rejects if the identity key changes', function(done) {
|
||||||
return textsecure.storage.devices.saveKeysToDeviceObject({
|
return textsecure.storage.devices.saveKeysToDeviceObject({
|
||||||
identityKey: identityKey.pubKey,
|
identityKey: textsecure.crypto.getRandomBytes(33),
|
||||||
encodedNumber: identifier + '.1'
|
encodedNumber: identifier + '.1'
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
textsecure.storage.devices.saveKeysToDeviceObject({
|
done(new Error('Allowed to overwrite identity key'));
|
||||||
identityKey: testKey.pubKey,
|
}).catch(function(e) {
|
||||||
encodedNumber: identifier + '.1'
|
assert.strictEqual(e.message, 'Identity key changed');
|
||||||
}).then(function() {
|
done();
|
||||||
done(new Error('Allowed to overwrite identity key'));
|
|
||||||
}).catch(function(e) {
|
|
||||||
assert.strictEqual(e.message, 'Identity key changed');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue