Merge pull request #534 from sachaaaaa/use_file_server_device_mapping

[multi-device] Use file server device mapping
pull/541/head
sachaaaaa 6 years ago committed by GitHub
commit f268fbb552
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,4 +1,11 @@
/* global Whisper, $, getAccountManager, textsecure, i18n, passwordUtil, _ */ /* global Whisper,
$,
getAccountManager,
textsecure,
i18n,
passwordUtil,
_,
lokiFileServerAPI */
/* eslint-disable more/no-then */ /* eslint-disable more/no-then */
@ -137,8 +144,9 @@
const language = this.$('#mnemonic-display-language').val(); const language = this.$('#mnemonic-display-language').val();
this.showProfilePage(mnemonic, language); this.showProfilePage(mnemonic, language);
}, },
onSecondaryDeviceRegistered() { async onSecondaryDeviceRegistered() {
clearInterval(this.pairingInterval); clearInterval(this.pairingInterval);
await lokiFileServerAPI.updateOurDeviceMapping();
// Ensure the left menu is updated // Ensure the left menu is updated
Whisper.events.trigger('userChanged', { isSecondaryDevice: true }); Whisper.events.trigger('userChanged', { isSecondaryDevice: true });
this.$el.trigger('openInbox'); this.$el.trigger('openInbox');

@ -174,7 +174,78 @@
return signature; return signature;
} }
async function verifyPairingAuthorisation( async function validateAuthorisation(authorisation) {
const {
type,
primaryDevicePubKey,
secondaryDevicePubKey,
requestSignature,
grantSignature,
} = authorisation;
const alreadySecondaryDevice = !!window.storage.get('isSecondaryDevice');
const ourPubKey = textsecure.storage.user.getNumber();
const isRequest =
type === textsecure.protobuf.PairingAuthorisationMessage.Type.REQUEST;
const isGrant =
type === textsecure.protobuf.PairingAuthorisationMessage.Type.GRANT;
if (!primaryDevicePubKey || !secondaryDevicePubKey) {
window.log.warn(
'Received a pairing request with missing pubkeys. Ignored.'
);
return false;
} else if (!requestSignature) {
window.log.warn(
'Received a pairing request with missing request signature. Ignored.'
);
return false;
} else if (isRequest && alreadySecondaryDevice) {
window.log.warn(
'Received a pairing request while being a secondary device. Ignored.'
);
return false;
} else if (isRequest && authorisation.primaryDevicePubKey !== ourPubKey) {
window.log.warn(
'Received a pairing request addressed to another pubkey. Ignored.'
);
return false;
} else if (isRequest && authorisation.secondaryDevicePubKey === ourPubKey) {
window.log.warn('Received a pairing request from ourselves. Ignored.');
return false;
}
try {
await this.verifyPairingSignature(
primaryDevicePubKey,
secondaryDevicePubKey,
dcodeIO.ByteBuffer.wrap(requestSignature).toArrayBuffer(),
textsecure.protobuf.PairingAuthorisationMessage.Type.REQUEST
);
} catch (e) {
window.log.warn(
'Could not verify pairing request authorisation signature. Ignoring message.'
);
window.log.error(e);
return false;
}
if (isGrant) {
try {
await this.verifyPairingSignature(
primaryDevicePubKey,
secondaryDevicePubKey,
dcodeIO.ByteBuffer.wrap(grantSignature).toArrayBuffer(),
textsecure.protobuf.PairingAuthorisationMessage.Type.GRANT
);
} catch (e) {
window.log.warn(
'Could not verify pairing grant authorisation signature. Ignoring message.'
);
window.log.error(e);
return false;
}
}
return true;
}
async function verifyPairingSignature(
primaryDevicePubKey, primaryDevicePubKey,
secondaryPubKey, secondaryPubKey,
signature, signature,
@ -233,7 +304,8 @@
snodeCipher, snodeCipher,
decryptToken, decryptToken,
generateSignatureForPairing, generateSignatureForPairing,
verifyPairingAuthorisation, verifyPairingSignature,
validateAuthorisation,
// for testing // for testing
_LokiSnodeChannel: LokiSnodeChannel, _LokiSnodeChannel: LokiSnodeChannel,
_decodeSnodeAddressToPubKey: decodeSnodeAddressToPubKey, _decodeSnodeAddressToPubKey: decodeSnodeAddressToPubKey,

@ -3,6 +3,7 @@
textsecure, textsecure,
libsignal, libsignal,
libloki, libloki,
lokiFileServerAPI,
mnemonic, mnemonic,
btoa, btoa,
Signal, Signal,
@ -622,6 +623,7 @@
}; };
// Update authorisation in database with the new grant signature // Update authorisation in database with the new grant signature
await libloki.storage.savePairingAuthorisation(authorisation); await libloki.storage.savePairingAuthorisation(authorisation);
await lokiFileServerAPI.updateOurDeviceMapping();
await libloki.api.sendPairingAuthorisation( await libloki.api.sendPairingAuthorisation(
authorisation, authorisation,
secondaryDevicePubKey secondaryDevicePubKey

@ -1048,78 +1048,8 @@ MessageReceiver.prototype.extend({
} }
return this.removeFromCache(envelope); return this.removeFromCache(envelope);
}, },
async validateAuthorisation(authorisation) {
const {
type,
primaryDevicePubKey,
secondaryDevicePubKey,
requestSignature,
grantSignature,
} = authorisation;
const alreadySecondaryDevice = !!window.storage.get('isSecondaryDevice');
const ourPubKey = textsecure.storage.user.getNumber();
const isRequest =
type === textsecure.protobuf.PairingAuthorisationMessage.Type.REQUEST;
const isGrant =
type === textsecure.protobuf.PairingAuthorisationMessage.Type.GRANT;
if (!primaryDevicePubKey || !secondaryDevicePubKey) {
window.log.warn(
'Received a pairing request with missing pubkeys. Ignored.'
);
return false;
} else if (!requestSignature) {
window.log.warn(
'Received a pairing request with missing request signature. Ignored.'
);
return false;
} else if (isRequest && alreadySecondaryDevice) {
window.log.warn(
'Received a pairing request while being a secondary device. Ignored.'
);
return false;
} else if (isRequest && authorisation.primaryDevicePubKey !== ourPubKey) {
window.log.warn(
'Received a pairing request addressed to another pubkey. Ignored.'
);
return false;
} else if (isRequest && authorisation.secondaryDevicePubKey === ourPubKey) {
window.log.warn('Received a pairing request from ourselves. Ignored.');
return false;
}
try {
await libloki.crypto.verifyPairingAuthorisation(
primaryDevicePubKey,
secondaryDevicePubKey,
dcodeIO.ByteBuffer.wrap(requestSignature).toArrayBuffer(),
textsecure.protobuf.PairingAuthorisationMessage.Type.REQUEST
);
} catch (e) {
window.log.warn(
'Could not verify pairing request authorisation signature. Ignoring message.'
);
window.log.error(e);
return false;
}
if (isGrant) {
try {
await libloki.crypto.verifyPairingAuthorisation(
primaryDevicePubKey,
secondaryDevicePubKey,
dcodeIO.ByteBuffer.wrap(grantSignature).toArrayBuffer(),
textsecure.protobuf.PairingAuthorisationMessage.Type.GRANT
);
} catch (e) {
window.log.warn(
'Could not verify pairing grant authorisation signature. Ignoring message.'
);
window.log.error(e);
return false;
}
}
return true;
},
async handlePairingRequest(envelope, pairingRequest) { async handlePairingRequest(envelope, pairingRequest) {
const valid = await this.validateAuthorisation(pairingRequest); const valid = await libloki.crypto.validateAuthorisation(pairingRequest);
if (valid) { if (valid) {
// Pairing dialog is open and is listening // Pairing dialog is open and is listening
if (Whisper.events.isListenedTo('devicePairingRequestReceived')) { if (Whisper.events.isListenedTo('devicePairingRequestReceived')) {
@ -1138,7 +1068,7 @@ MessageReceiver.prototype.extend({
pairingAuthorisation, pairingAuthorisation,
{ dataMessage, syncMessage } { dataMessage, syncMessage }
) { ) {
const valid = await this.validateAuthorisation(pairingAuthorisation); const valid = await libloki.crypto.validateAuthorisation(pairingAuthorisation);
const alreadySecondaryDevice = !!window.storage.get('isSecondaryDevice'); const alreadySecondaryDevice = !!window.storage.get('isSecondaryDevice');
let removedFromCache = false; let removedFromCache = false;
if (alreadySecondaryDevice) { if (alreadySecondaryDevice) {
@ -1214,25 +1144,8 @@ MessageReceiver.prototype.extend({
}) })
); );
}, },
async handleAuthorisationForContact(envelope, pairingAuthorisation) { async handleAuthorisationForContact(envelope) {
const valid = await this.validateAuthorisation(pairingAuthorisation); window.log.error('Unexpected pairing request/authorisation received, ignoring.');
if (!valid) {
window.log.warn(
'Received invalid pairing authorisation for self. Could not verify signature. Ignoring.'
);
} else {
const {
primaryDevicePubKey,
secondaryDevicePubKey,
} = pairingAuthorisation;
// ensure the primary device is a friend
const c = window.ConversationController.get(primaryDevicePubKey);
if (c && c.isFriend()) {
await libloki.storage.savePairingAuthorisation(pairingAuthorisation);
// send friend accept?
window.libloki.api.sendBackgroundMessage(secondaryDevicePubKey);
}
}
return this.removeFromCache(envelope); return this.removeFromCache(envelope);
}, },
async handlePairingAuthorisationMessage(envelope, content) { async handlePairingAuthorisationMessage(envelope, content) {
@ -1247,7 +1160,7 @@ MessageReceiver.prototype.extend({
content content
); );
} }
return this.handleAuthorisationForContact(envelope, pairingAuthorisation); return this.handleAuthorisationForContact(envelope);
}, },
async handleSecondaryDeviceFriendRequest(pubKey, deviceMapping) { async handleSecondaryDeviceFriendRequest(pubKey, deviceMapping) {

@ -341,23 +341,6 @@ OutgoingMessage.prototype = {
// Check if we need to attach the preKeys // Check if we need to attach the preKeys
let sessionCipher; let sessionCipher;
const isFriendRequest = this.messageType === 'friend-request'; const isFriendRequest = this.messageType === 'friend-request';
const isSecondaryDevice = !!window.storage.get('isSecondaryDevice');
if (isFriendRequest && isSecondaryDevice) {
// Attach authorisation from primary device ONLY FOR FRIEND REQUEST
const ourPubKeyHex = textsecure.storage.user.getNumber();
const pairingAuthorisation = await libloki.storage.getGrantAuthorisationForSecondaryPubKey(
ourPubKeyHex
);
if (pairingAuthorisation) {
this.message.pairingAuthorisation = libloki.api.createPairingAuthorisationProtoMessage(
pairingAuthorisation
);
} else {
window.log.error(
'Could not find authorisation for our own pubkey while being secondary device.'
);
}
}
this.fallBackEncryption = this.fallBackEncryption || isFriendRequest; this.fallBackEncryption = this.fallBackEncryption || isFriendRequest;
const flags = this.message.dataMessage const flags = this.message.dataMessage
? this.message.dataMessage.get_flags() ? this.message.dataMessage.get_flags()

Loading…
Cancel
Save