|
|
|
@ -1048,78 +1048,8 @@ MessageReceiver.prototype.extend({
|
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
|
const valid = await this.validateAuthorisation(pairingRequest);
|
|
|
|
|
const valid = await libloki.crypto.validateAuthorisation(pairingRequest);
|
|
|
|
|
if (valid) {
|
|
|
|
|
// Pairing dialog is open and is listening
|
|
|
|
|
if (Whisper.events.isListenedTo('devicePairingRequestReceived')) {
|
|
|
|
@ -1138,7 +1068,7 @@ MessageReceiver.prototype.extend({
|
|
|
|
|
pairingAuthorisation,
|
|
|
|
|
{ dataMessage, syncMessage }
|
|
|
|
|
) {
|
|
|
|
|
const valid = await this.validateAuthorisation(pairingAuthorisation);
|
|
|
|
|
const valid = await libloki.crypto.validateAuthorisation(pairingAuthorisation);
|
|
|
|
|
const alreadySecondaryDevice = !!window.storage.get('isSecondaryDevice');
|
|
|
|
|
let removedFromCache = false;
|
|
|
|
|
if (alreadySecondaryDevice) {
|
|
|
|
@ -1214,25 +1144,8 @@ MessageReceiver.prototype.extend({
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
async handleAuthorisationForContact(envelope, pairingAuthorisation) {
|
|
|
|
|
const valid = await this.validateAuthorisation(pairingAuthorisation);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
async handleAuthorisationForContact(envelope) {
|
|
|
|
|
window.log.error('Unexpected pairing request/authorisation received, ignoring.');
|
|
|
|
|
return this.removeFromCache(envelope);
|
|
|
|
|
},
|
|
|
|
|
async handlePairingAuthorisationMessage(envelope, content) {
|
|
|
|
@ -1247,7 +1160,7 @@ MessageReceiver.prototype.extend({
|
|
|
|
|
content
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return this.handleAuthorisationForContact(envelope, pairingAuthorisation);
|
|
|
|
|
return this.handleAuthorisationForContact(envelope);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async handleSecondaryDeviceFriendRequest(pubKey, deviceMapping) {
|
|
|
|
|