Fix multi device pairing

pull/1216/head
Mikunj 5 years ago
parent a3cb98c46c
commit 8f82e7a442

@ -223,7 +223,7 @@
requestSignature, requestSignature,
grantSignature, grantSignature,
} = authorisation; } = authorisation;
const isGrant = !!grantSignature; const isGrant = !!(grantSignature && grantSignature.length > 0);
if (!primaryDevicePubKey || !secondaryDevicePubKey) { if (!primaryDevicePubKey || !secondaryDevicePubKey) {
window.log.warn( window.log.warn(
'Received a pairing request with missing pubkeys. Ignored.' 'Received a pairing request with missing pubkeys. Ignored.'
@ -277,7 +277,7 @@
} = authorisation; } = authorisation;
const alreadySecondaryDevice = !!window.storage.get('isSecondaryDevice'); const alreadySecondaryDevice = !!window.storage.get('isSecondaryDevice');
const ourPubKey = textsecure.storage.user.getNumber(); const ourPubKey = textsecure.storage.user.getNumber();
const isRequest = !grantSignature; const isRequest = !(grantSignature && grantSignature.length > 0);
if (isRequest && alreadySecondaryDevice) { if (isRequest && alreadySecondaryDevice) {
window.log.warn( window.log.warn(
'Received a pairing request while being a secondary device. Ignored.' 'Received a pairing request while being a secondary device. Ignored.'

@ -22,7 +22,7 @@
"icon-gen": "electron-icon-maker --input=images/icon_1024.png --output=./build", "icon-gen": "electron-icon-maker --input=images/icon_1024.png --output=./build",
"generate": "yarn icon-gen && yarn grunt", "generate": "yarn icon-gen && yarn grunt",
"build-release": "cross-env SIGNAL_ENV=production npm run build -- --config.directories.output=release", "build-release": "cross-env SIGNAL_ENV=production npm run build -- --config.directories.output=release",
"build-module-protobuf": "pbjs --target static-module --wrap commonjs --out ts/protobuf/compiled.js protos/*.proto && pbts --out ts/protobuf/compiled.d.ts ts/protobuf/compiled.js", "build-module-protobuf": "pbjs --target static-module --wrap commonjs --out ts/protobuf/compiled.js protos/*.proto && pbts --out ts/protobuf/compiled.d.ts ts/protobuf/compiled.js --force-long",
"clean-module-protobuf": "rm -f ts/protobuf/compiled.d.ts ts/protobuf/compiled.js", "clean-module-protobuf": "rm -f ts/protobuf/compiled.d.ts ts/protobuf/compiled.js",
"build-protobuf": "yarn build-module-protobuf", "build-protobuf": "yarn build-module-protobuf",
"clean-protobuf": "yarn clean-module-protobuf", "clean-protobuf": "yarn clean-module-protobuf",
@ -95,7 +95,7 @@
"os-locale": "2.1.0", "os-locale": "2.1.0",
"p-retry": "^4.2.0", "p-retry": "^4.2.0",
"pify": "3.0.0", "pify": "3.0.0",
"protobufjs": "6.8.6", "protobufjs": "^6.9.0",
"rc-slider": "^8.7.1", "rc-slider": "^8.7.1",
"react": "16.8.3", "react": "16.8.3",
"react-contextmenu": "2.11.0", "react-contextmenu": "2.11.0",

@ -356,16 +356,10 @@ export async function innerHandleContentMessage(
} }
if (content.pairingAuthorisation) { if (content.pairingAuthorisation) {
if (!content.dataMessage || !content.syncMessage) {
window.log.error('Missing fields in pairingAuthorisation');
return;
}
await handlePairingAuthorisationMessage( await handlePairingAuthorisationMessage(
envelope, envelope,
content.pairingAuthorisation, content.pairingAuthorisation,
content.dataMessage, content.dataMessage
content.syncMessage
); );
return; return;
} }

@ -84,19 +84,18 @@ export async function handleUnpairRequest(
export async function handlePairingAuthorisationMessage( export async function handlePairingAuthorisationMessage(
envelope: EnvelopePlus, envelope: EnvelopePlus,
pairingAuthorisation: SignalService.IPairingAuthorisationMessage, pairingAuthorisation: SignalService.IPairingAuthorisationMessage,
dataMessage: SignalService.IDataMessage, dataMessage: SignalService.IDataMessage | undefined | null
syncMessage: SignalService.ISyncMessage
): Promise<void> { ): Promise<void> {
const { secondaryDevicePubKey, grantSignature } = pairingAuthorisation; const { secondaryDevicePubKey, grantSignature } = pairingAuthorisation;
const isGrant = const isGrant =
grantSignature && grantSignature &&
grantSignature.length > 0 &&
secondaryDevicePubKey === window.textsecure.storage.user.getNumber(); secondaryDevicePubKey === window.textsecure.storage.user.getNumber();
if (isGrant) { if (isGrant) {
await handleAuthorisationForSelf( await handleAuthorisationForSelf(
envelope, envelope,
pairingAuthorisation, pairingAuthorisation,
dataMessage, dataMessage
syncMessage
); );
} else { } else {
await handlePairingRequest(envelope, pairingAuthorisation); await handlePairingRequest(envelope, pairingAuthorisation);
@ -134,8 +133,7 @@ async function handlePairingRequest(
async function handleAuthorisationForSelf( async function handleAuthorisationForSelf(
envelope: EnvelopePlus, envelope: EnvelopePlus,
pairingAuthorisation: SignalService.IPairingAuthorisationMessage, pairingAuthorisation: SignalService.IPairingAuthorisationMessage,
dataMessage: SignalService.IDataMessage, dataMessage: SignalService.IDataMessage | undefined | null
syncMessage: SignalService.ISyncMessage
) { ) {
const { ConversationController, libloki, Whisper } = window; const { ConversationController, libloki, Whisper } = window;
@ -143,7 +141,6 @@ async function handleAuthorisationForSelf(
pairingAuthorisation pairingAuthorisation
); );
const alreadySecondaryDevice = !!window.storage.get('isSecondaryDevice'); const alreadySecondaryDevice = !!window.storage.get('isSecondaryDevice');
let removedFromCache = false;
if (alreadySecondaryDevice) { if (alreadySecondaryDevice) {
window.log.warn( window.log.warn(
'Received an unexpected pairing authorisation (device is already paired as secondary device). Ignoring.' 'Received an unexpected pairing authorisation (device is already paired as secondary device). Ignoring.'
@ -154,7 +151,7 @@ async function handleAuthorisationForSelf(
); );
} else { } else {
const { primaryDevicePubKey, grantSignature } = pairingAuthorisation; const { primaryDevicePubKey, grantSignature } = pairingAuthorisation;
if (grantSignature) { if (grantSignature && grantSignature.length > 0) {
// Authorisation received to become a secondary device // Authorisation received to become a secondary device
window.log.info( window.log.info(
`Received pairing authorisation from ${primaryDevicePubKey}` `Received pairing authorisation from ${primaryDevicePubKey}`
@ -188,22 +185,12 @@ async function handleAuthorisationForSelf(
window.log.warn('profile or profileKey are missing in DataMessage'); window.log.warn('profile or profileKey are missing in DataMessage');
} }
} }
// Update contact list
if (syncMessage && syncMessage.contacts) {
// Note: we do not return here because we don't want to block the next message on
// this attachment download and a lot of processing of that attachment.
// This call already removes the envelope from the cache
void handleContacts(envelope, syncMessage.contacts);
removedFromCache = true;
}
} else { } else {
window.log.warn('Unimplemented pairing authorisation message type'); window.log.warn('Unimplemented pairing authorisation message type');
} }
} }
if (!removedFromCache) {
await removeFromCache(envelope); await removeFromCache(envelope);
} }
}
function parseContacts(arrbuf: ArrayBuffer): Array<any> { function parseContacts(arrbuf: ArrayBuffer): Array<any> {
const buffer = new ByteBuffer(); const buffer = new ByteBuffer();

@ -114,8 +114,6 @@ export async function handleSessionRequestMessage(
timestamp: Date.now(), timestamp: Date.now(),
}); });
await libsession.getMessageQueue().send(user, sessionEstablished); await libsession.getMessageQueue().send(user, sessionEstablished);
libloki.api.sendSessionEstablishedMessage(envelope.source);
} catch (e) { } catch (e) {
log.warn('Failed to process session request', e); log.warn('Failed to process session request', e);
// TODO how to handle a failed session request? // TODO how to handle a failed session request?

@ -321,10 +321,10 @@ async function refreshRandomPoolDetail(seedNodes: Array<any>): Promise<void> {
} }
} }
export async function refreshRandomPool(seedNodes: Array<any>): Promise<void> { export async function refreshRandomPool(seedNodes?: Array<any>): Promise<void> {
const { log } = window; const { log } = window;
if (!seedNodes.length) { if (!seedNodes || !seedNodes.length) {
if (!window.seedNodeList || !window.seedNodeList.length) { if (!window.seedNodeList || !window.seedNodeList.length) {
log.error( log.error(
'LokiSnodeAPI:::refreshRandomPool - seedNodeList has not been loaded yet' 'LokiSnodeAPI:::refreshRandomPool - seedNodeList has not been loaded yet'
@ -335,9 +335,11 @@ export async function refreshRandomPool(seedNodes: Array<any>): Promise<void> {
seedNodes = window.seedNodeList; seedNodes = window.seedNodeList;
} }
return allowOnlyOneAtATime('refreshRandomPool', async () => return allowOnlyOneAtATime('refreshRandomPool', async () => {
refreshRandomPoolDetail(seedNodes) if (seedNodes) {
); await refreshRandomPoolDetail(seedNodes);
}
});
} }
export async function getSnodesFor(pubkey: string): Promise<Array<Snode>> { export async function getSnodesFor(pubkey: string): Promise<Array<Snode>> {

@ -322,16 +322,11 @@
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.106.tgz#6093e9a02aa567ddecfe9afadca89e53e5dce4dd" resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.106.tgz#6093e9a02aa567ddecfe9afadca89e53e5dce4dd"
integrity sha512-tOSvCVrvSqFZ4A/qrqqm6p37GZoawsZtoR0SJhlF7EonNZUgrn8FfT+RNQ11h+NUpMt6QVe36033f3qEKBwfWA== integrity sha512-tOSvCVrvSqFZ4A/qrqqm6p37GZoawsZtoR0SJhlF7EonNZUgrn8FfT+RNQ11h+NUpMt6QVe36033f3qEKBwfWA==
"@types/long@*": "@types/long@*", "@types/long@^4.0.1":
version "4.0.1" version "4.0.1"
resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.1.tgz#459c65fa1867dafe6a8f322c4c51695663cc55e9" resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.1.tgz#459c65fa1867dafe6a8f322c4c51695663cc55e9"
integrity sha512-5tXH6Bx/kNGd3MgffdmP4dy2Z+G4eaXw0SE81Tq3BNadtnMR5/ySMzX4SLEzHJzSmPNn4HIdpQsBvXMUykr58w== integrity sha512-5tXH6Bx/kNGd3MgffdmP4dy2Z+G4eaXw0SE81Tq3BNadtnMR5/ySMzX4SLEzHJzSmPNn4HIdpQsBvXMUykr58w==
"@types/long@^3.0.32":
version "3.0.32"
resolved "https://registry.yarnpkg.com/@types/long/-/long-3.0.32.tgz#f4e5af31e9e9b196d8e5fca8a5e2e20aa3d60b69"
integrity sha512-ZXyOOm83p7X8p3s0IYM3VeueNmHpkk/yMlP8CLeOnEcu6hIwPH7YjZBvhQkR0ZFS2DqZAxKtJ/M5fcuv3OU5BA==
"@types/minimatch@*": "@types/minimatch@*":
version "3.0.3" version "3.0.3"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
@ -367,10 +362,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.31.tgz#d6b4f9645fee17f11319b508fb1001797425da51" resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.31.tgz#d6b4f9645fee17f11319b508fb1001797425da51"
integrity sha512-T+wnJno8uh27G9c+1T+a1/WYCHzLeDqtsGJkoEdSp2X8RTh3oOCZQcUnjAx90CS8cmmADX51O0FI/tu9s0yssg== integrity sha512-T+wnJno8uh27G9c+1T+a1/WYCHzLeDqtsGJkoEdSp2X8RTh3oOCZQcUnjAx90CS8cmmADX51O0FI/tu9s0yssg==
"@types/node@^8.9.4": "@types/node@^13.7.0":
version "8.10.59" version "13.13.12"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.59.tgz#9e34261f30183f9777017a13d185dfac6b899e04" resolved "https://registry.yarnpkg.com/@types/node/-/node-13.13.12.tgz#9c72e865380a7dc99999ea0ef20fc9635b503d20"
integrity sha512-8RkBivJrDCyPpBXhVZcjh7cQxVBSmRk9QM7hOketZzp6Tg79c0N8kkpAIito9bnJ3HCVCHVYz+KHTEbfQNfeVQ== integrity sha512-zWz/8NEPxoXNT9YyF2osqyA9WjssZukYpgI4UYZpOjcyqwIUqWGkcCionaEb9Ki+FULyPyvNFpg/329Kd2/pbw==
"@types/pify@3.0.2": "@types/pify@3.0.2":
version "3.0.2" version "3.0.2"
@ -7870,10 +7865,10 @@ proto-list@~1.2.1:
resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849" resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849"
integrity sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk= integrity sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=
protobufjs@6.8.6: protobufjs@^6.9.0:
version "6.8.6" version "6.9.0"
resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.8.6.tgz#ce3cf4fff9625b62966c455fc4c15e4331a11ca2" resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.9.0.tgz#c08b2bf636682598e6fabbf0edb0b1256ff090bd"
integrity sha512-eH2OTP9s55vojr3b7NBaF9i4WhWPkv/nq55nznWNp/FomKrLViprUcqnBjHph2tFQ+7KciGPTPsVWGz0SOhL0Q== integrity sha512-LlGVfEWDXoI/STstRDdZZKb/qusoAWUnmLg9R8OLSO473mBLWHowx8clbX5/+mKDEI+v7GzjoK9tRPZMMcoTrg==
dependencies: dependencies:
"@protobufjs/aspromise" "^1.1.2" "@protobufjs/aspromise" "^1.1.2"
"@protobufjs/base64" "^1.1.2" "@protobufjs/base64" "^1.1.2"
@ -7885,8 +7880,8 @@ protobufjs@6.8.6:
"@protobufjs/path" "^1.1.2" "@protobufjs/path" "^1.1.2"
"@protobufjs/pool" "^1.1.0" "@protobufjs/pool" "^1.1.0"
"@protobufjs/utf8" "^1.1.0" "@protobufjs/utf8" "^1.1.0"
"@types/long" "^3.0.32" "@types/long" "^4.0.1"
"@types/node" "^8.9.4" "@types/node" "^13.7.0"
long "^4.0.0" long "^4.0.0"
proxy-addr@~2.0.5: proxy-addr@~2.0.5:

Loading…
Cancel
Save