Fix pubkey validation

pull/426/head
sachaaaaa 6 years ago
parent c308155f48
commit 713e9a3acf

@ -13,7 +13,8 @@
log, log,
storage, storage,
Event, Event,
ConversationController ConversationController,
Whisper
*/ */
/* eslint-disable more/no-then */ /* eslint-disable more/no-then */
@ -555,22 +556,20 @@
this.dispatchEvent(new Event('registration')); this.dispatchEvent(new Event('registration'));
}, },
async authoriseSecondaryDevice(secondaryDevicePubKey) { async authoriseSecondaryDevice(secondaryDevicePubKey) {
if (secondaryDevicePubKey === textsecure.storage.user.getNumber()) { const ourPubKey = textsecure.storage.user.getNumber();
if (secondaryDevicePubKey === ourPubKey) {
throw new Error( throw new Error(
'Cannot register primary device pubkey as secondary device' 'Cannot register primary device pubkey as secondary device'
); );
} }
// Validate pubKey // throws if invalid
const c = await ConversationController.getOrCreateAndWait( this.validatePubKeyHex(secondaryDevicePubKey);
// we need a conversation for sending a message
await ConversationController.getOrCreateAndWait(
secondaryDevicePubKey, secondaryDevicePubKey,
'private' 'private'
); );
const validationError = c.validateNumber();
if (validationError) {
throw new Error('Invalid secondary device pubkey provided');
}
// Ensure there is a conversation existing
const signature = await libloki.crypto.generateSignatureForPairing( const signature = await libloki.crypto.generateSignatureForPairing(
secondaryDevicePubKey, secondaryDevicePubKey,
textsecure.protobuf.PairingAuthorisationMessage.Type.PAIRING_REQUEST textsecure.protobuf.PairingAuthorisationMessage.Type.PAIRING_REQUEST
@ -580,6 +579,16 @@
signature signature
); );
}, },
validatePubKeyHex(pubKey) {
const c = new Whisper.Conversation({
id: pubKey,
type: 'private',
});
const validationError = c.validateNumber();
if (validationError) {
throw new Error(validationError);
}
},
}); });
textsecure.AccountManager = AccountManager; textsecure.AccountManager = AccountManager;
})(); })();

Loading…
Cancel
Save