Skip to content

Commit

Permalink
Support for undefined preKey
Browse files Browse the repository at this point in the history
  • Loading branch information
liliakai committed Feb 9, 2017
1 parent a768b94 commit 819ba8e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
15 changes: 10 additions & 5 deletions js/libtextsecure.js
Expand Up @@ -37792,14 +37792,19 @@ var TextSecureServer = (function() {
}
res.identityKey = StringView.base64ToBytes(res.identityKey);
res.devices.forEach(function(device) {
if ( !validateResponse(device, {signedPreKey: 'object', preKey: 'object'}) ||
!validateResponse(device.signedPreKey, {publicKey: 'string', signature: 'string'}) ||
!validateResponse(device.preKey, {publicKey: 'string'})) {
throw new Error("Invalid response");
if ( !validateResponse(device, {signedPreKey: 'object'}) ||
!validateResponse(device.signedPreKey, {publicKey: 'string', signature: 'string'}) ) {
throw new Error("Invalid signedPreKey");
}
if ( device.preKey ) {
if ( !validateResponse(device, {preKey: 'object'}) ||
!validateResponse(device.preKey, {publicKey: 'string'})) {
throw new Error("Invalid preKey");
}
device.preKey.publicKey = StringView.base64ToBytes(device.preKey.publicKey);
}
device.signedPreKey.publicKey = StringView.base64ToBytes(device.signedPreKey.publicKey);
device.signedPreKey.signature = StringView.base64ToBytes(device.signedPreKey.signature);
device.preKey.publicKey = StringView.base64ToBytes(device.preKey.publicKey);
});
return res;
});
Expand Down
15 changes: 10 additions & 5 deletions libtextsecure/api.js
Expand Up @@ -315,14 +315,19 @@ var TextSecureServer = (function() {
}
res.identityKey = StringView.base64ToBytes(res.identityKey);
res.devices.forEach(function(device) {
if ( !validateResponse(device, {signedPreKey: 'object', preKey: 'object'}) ||
!validateResponse(device.signedPreKey, {publicKey: 'string', signature: 'string'}) ||
!validateResponse(device.preKey, {publicKey: 'string'})) {
throw new Error("Invalid response");
if ( !validateResponse(device, {signedPreKey: 'object'}) ||
!validateResponse(device.signedPreKey, {publicKey: 'string', signature: 'string'}) ) {
throw new Error("Invalid signedPreKey");
}
if ( device.preKey ) {
if ( !validateResponse(device, {preKey: 'object'}) ||
!validateResponse(device.preKey, {publicKey: 'string'})) {
throw new Error("Invalid preKey");
}
device.preKey.publicKey = StringView.base64ToBytes(device.preKey.publicKey);
}
device.signedPreKey.publicKey = StringView.base64ToBytes(device.signedPreKey.publicKey);
device.signedPreKey.signature = StringView.base64ToBytes(device.signedPreKey.signature);
device.preKey.publicKey = StringView.base64ToBytes(device.preKey.publicKey);
});
return res;
});
Expand Down

1 comment on commit 819ba8e

@WhisperBTC
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! BitHub has sent payment of $80.80USD for this commit.

Please sign in to comment.