Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Commit 63d2536

Browse files
committed
Support for directional trust
Pass in a direction to isTrusted, based on constants defined by the storage implementation. These values allow the trust store to determine whether a given key is trusted, given the directional context.
1 parent b0ed2e5 commit 63d2536

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

dist/libsignal-protocol.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35813,7 +35813,7 @@ SessionBuilder.prototype = {
3581335813
processPreKey: function(device) {
3581435814
return Internal.SessionLock.queueJobForNumber(this.remoteAddress.toString(), function() {
3581535815
return this.storage.isTrustedIdentity(
35816-
this.remoteAddress.getName(), device.identityKey
35816+
this.remoteAddress.getName(), device.identityKey, this.storage.Direction.SENDING
3581735817
).then(function(trusted) {
3581835818
if (!trusted) {
3581935819
throw new Error('Identity key changed');
@@ -35866,7 +35866,7 @@ SessionBuilder.prototype = {
3586635866
processV3: function(record, message) {
3586735867
var preKeyPair, signedPreKeyPair, session;
3586835868
return this.storage.isTrustedIdentity(
35869-
this.remoteAddress.getName(), message.identityKey.toArrayBuffer()
35869+
this.remoteAddress.getName(), message.identityKey.toArrayBuffer(), this.storage.Direction.RECEIVING
3587035870
).then(function(trusted) {
3587135871
if (!trusted) {
3587235872
var e = new Error('Unknown identity key');

src/SessionBuilder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SessionBuilder.prototype = {
77
processPreKey: function(device) {
88
return Internal.SessionLock.queueJobForNumber(this.remoteAddress.toString(), function() {
99
return this.storage.isTrustedIdentity(
10-
this.remoteAddress.getName(), device.identityKey
10+
this.remoteAddress.getName(), device.identityKey, this.storage.Direction.SENDING
1111
).then(function(trusted) {
1212
if (!trusted) {
1313
throw new Error('Identity key changed');
@@ -60,7 +60,7 @@ SessionBuilder.prototype = {
6060
processV3: function(record, message) {
6161
var preKeyPair, signedPreKeyPair, session;
6262
return this.storage.isTrustedIdentity(
63-
this.remoteAddress.getName(), message.identityKey.toArrayBuffer()
63+
this.remoteAddress.getName(), message.identityKey.toArrayBuffer(), this.storage.Direction.RECEIVING
6464
).then(function(trusted) {
6565
if (!trusted) {
6666
var e = new Error('Unknown identity key');

test/InMemorySignalProtocolStore.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
function SignalProtocolStore() {
1+
function SignalProtocolStore() {
22
this.store = {};
33
}
44

55
SignalProtocolStore.prototype = {
6+
Direction: {
7+
SENDING: 1,
8+
RECEIVING: 2,
9+
},
10+
611
getIdentityKeyPair: function() {
712
return Promise.resolve(this.get('identityKey'));
813
},
@@ -29,7 +34,7 @@ SignalProtocolStore.prototype = {
2934
delete this.store[key];
3035
},
3136

32-
isTrustedIdentity: function(identifier, identityKey) {
37+
isTrustedIdentity: function(identifier, identityKey, direction) {
3338
if (identifier === null || identifier === undefined) {
3439
throw new Error("tried to check identity key for undefined/null key");
3540
}

0 commit comments

Comments
 (0)