refactor verifyAuthorisation out of validateAuthorisation

pull/539/head
Ryan Tharp 6 years ago
parent bd17c4b026
commit 66eae90c38

@ -175,16 +175,13 @@
return signature; return signature;
} }
async function validateAuthorisation(authorisation) { async function verifyAuthorisation(authorisation) {
const { const {
primaryDevicePubKey, primaryDevicePubKey,
secondaryDevicePubKey, secondaryDevicePubKey,
requestSignature, requestSignature,
grantSignature, grantSignature,
} = authorisation; } = authorisation;
const alreadySecondaryDevice = !!window.storage.get('isSecondaryDevice');
const ourPubKey = textsecure.storage.user.getNumber();
const isRequest = !grantSignature;
const isGrant = !!grantSignature; const isGrant = !!grantSignature;
if (!primaryDevicePubKey || !secondaryDevicePubKey) { if (!primaryDevicePubKey || !secondaryDevicePubKey) {
window.log.warn( window.log.warn(
@ -196,19 +193,6 @@
'Received a pairing request with missing request signature. Ignored.' 'Received a pairing request with missing request signature. Ignored.'
); );
return false; 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;
} }
const verify = async (signature, signatureType) => { const verify = async (signature, signatureType) => {
const encoding = typeof signature === 'string' ? 'base64' : undefined; const encoding = typeof signature === 'string' ? 'base64' : undefined;
@ -228,6 +212,7 @@
window.log.error(e); window.log.error(e);
return false; return false;
} }
// can't have grant without requestSignature?
if (isGrant) { if (isGrant) {
try { try {
await verify(grantSignature, PairingType.GRANT); await verify(grantSignature, PairingType.GRANT);
@ -242,6 +227,33 @@
return true; return true;
} }
// FIXME: rename to include the fact it's relative to YOUR device
async function validateAuthorisation(authorisation) {
const {
primaryDevicePubKey,
secondaryDevicePubKey,
grantSignature,
} = authorisation;
const alreadySecondaryDevice = !!window.storage.get('isSecondaryDevice');
const ourPubKey = textsecure.storage.user.getNumber();
const isRequest = !grantSignature;
if (isRequest && alreadySecondaryDevice) {
window.log.warn(
'Received a pairing request while being a secondary device. Ignored.'
);
return false;
} else if (isRequest && primaryDevicePubKey !== ourPubKey) {
window.log.warn(
'Received a pairing request addressed to another pubkey. Ignored.'
);
return false;
} else if (isRequest && secondaryDevicePubKey === ourPubKey) {
window.log.warn('Received a pairing request from ourselves. Ignored.');
return false;
}
return this.verifyAuthorisation(authorisation);
}
async function verifyPairingSignature( async function verifyPairingSignature(
primaryDevicePubKey, primaryDevicePubKey,
secondaryPubKey, secondaryPubKey,
@ -307,6 +319,7 @@
decryptToken, decryptToken,
generateSignatureForPairing, generateSignatureForPairing,
verifyPairingSignature, verifyPairingSignature,
verifyAuthorisation,
validateAuthorisation, validateAuthorisation,
PairingType, PairingType,
// for testing // for testing

Loading…
Cancel
Save