From 819ba8ee7417a048816885d0a30a41409ca32110 Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 8 Feb 2017 22:23:42 -0800 Subject: [PATCH] Support for undefined preKey --- js/libtextsecure.js | 15 ++++++++++----- libtextsecure/api.js | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 87b1278a0ea6..c754dd488186 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -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; }); diff --git a/libtextsecure/api.js b/libtextsecure/api.js index 2d37d9c209b0..0ee01ed72ff2 100644 --- a/libtextsecure/api.js +++ b/libtextsecure/api.js @@ -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; });