Fix registration.

pull/27/head
Mikunj 7 years ago
parent d5154bef73
commit b63844af57

@ -70,12 +70,33 @@
generateKeypair = libsignal.KeyHelper.generateIdentityKeyPair; generateKeypair = libsignal.KeyHelper.generateIdentityKeyPair;
} }
return this.queueTask(() => return this.queueTask(() =>
generateKeypair().then(identityKeyPair => generateKeypair().then(
createAccount(identityKeyPair) async identityKeyPair => {
.then(clearSessionsAndPreKeys) const profileKey = textsecure.crypto.getRandomBytes(32);
.then(generateKeys) const accessKey = await window.Signal.Crypto.deriveAccessKey(
.then(keys => confirmKeys(keys)) profileKey
.then(registrationDone) );
// our key
const pubKeyString = StringView.arrayBufferToHex(
identityKeyPair.pubKey
);
return createAccount(
pubKeyString,
null,
identityKeyPair,
profileKey,
null,
null,
null,
{ accessKey }
)
.then(clearSessionsAndPreKeys)
.then(generateKeys)
.then(confirmKeys)
.then(() => registrationDone(pubKeyString))
}
) )
); );
}, },
@ -394,13 +415,21 @@
}); });
}); });
}, },
createAccount(identityKeyPair, userAgent, readReceipts) { // Original parameters are left so we are still compatible with the other signal code
return Promise.resolve().then(() => { createAccount(
textsecure.storage.remove('identityKey'); number,
textsecure.storage.remove('number_id'); verificationCode,
textsecure.storage.remove('device_name'); identityKeyPair,
textsecure.storage.remove('userAgent'); profileKey,
textsecure.storage.remove('read-receipts-setting'); deviceName,
userAgent,
readReceipts,
options = {}
) {
const signalingKey = libsignal.crypto.getRandomBytes(32 + 20);
let password = btoa(getString(libsignal.crypto.getRandomBytes(16)));
password = password.substring(0, password.length - 2);
const registrationId = libsignal.KeyHelper.generateRegistrationId();
// update our own identity key, which may have changed // update our own identity key, which may have changed
// if we're relinking after a reinstall on the master device // if we're relinking after a reinstall on the master device
@ -408,27 +437,52 @@
identityKeyPair.pubKey identityKeyPair.pubKey
); );
textsecure.storage.protocol.saveIdentityWithAttributes(pubKeyString, { return Promise.resolve().then(() => {
id: pubKeyString, textsecure.storage.remove('identityKey');
publicKey: identityKeyPair.pubKey, textsecure.storage.remove('signaling_key');
firstUse: true, textsecure.storage.remove('password');
timestamp: Date.now(), textsecure.storage.remove('registrationId');
verified: textsecure.storage.protocol.VerifiedStatus.VERIFIED, textsecure.storage.remove('number_id');
nonblockingApproval: true, textsecure.storage.remove('device_name');
}); textsecure.storage.remove('regionCode');
textsecure.storage.remove('userAgent');
textsecure.storage.remove('profileKey');
textsecure.storage.remove('read-receipts-setting');
const identity = number || pubKeyString;
// update our own identity key, which may have changed
// if we're relinking after a reinstall on the master device
textsecure.storage.protocol.saveIdentityWithAttributes(identity, {
id: identity,
publicKey: identityKeyPair.pubKey,
firstUse: true,
timestamp: Date.now(),
verified: textsecure.storage.protocol.VerifiedStatus.VERIFIED,
nonblockingApproval: true,
});
textsecure.storage.put('identityKey', identityKeyPair); textsecure.storage.put('identityKey', identityKeyPair);
if (userAgent) { textsecure.storage.put('signaling_key', signalingKey);
textsecure.storage.put('userAgent', userAgent); textsecure.storage.put('password', password);
} textsecure.storage.put('registrationId', registrationId);
if (readReceipts) { if (profileKey) {
textsecure.storage.put('read-receipt-setting', true); textsecure.storage.put('profileKey', profileKey);
} else { }
textsecure.storage.put('read-receipt-setting', false); if (userAgent) {
} textsecure.storage.put('userAgent', userAgent);
}
if (readReceipts) {
textsecure.storage.put('read-receipt-setting', true);
} else {
textsecure.storage.put('read-receipt-setting', false);
}
textsecure.storage.user.setNumberAndDeviceId(pubKeyString, 1); textsecure.storage.user.setNumberAndDeviceId(
}); pubKeyString,
1,
);
});
}, },
clearSessionsAndPreKeys() { clearSessionsAndPreKeys() {
const store = textsecure.storage.protocol; const store = textsecure.storage.protocol;
@ -441,13 +495,13 @@
]); ]);
}, },
// Takes the same object returned by generateKeys // Takes the same object returned by generateKeys
confirmKeys(keys) { async confirmKeys(keys) {
const store = textsecure.storage.protocol; const store = textsecure.storage.protocol;
const key = keys.signedPreKey; const key = keys.signedPreKey;
const confirmed = true; const confirmed = true;
window.log.info('confirmKeys: confirming key', key.keyId); window.log.info('confirmKeys: confirming key', key.keyId);
return store.storeSignedPreKey( await store.storeSignedPreKey(
key.keyId, key.keyId,
key.keyPair, key.keyPair,
confirmed, confirmed,

Loading…
Cancel
Save