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 => {
const profileKey = textsecure.crypto.getRandomBytes(32);
const accessKey = await window.Signal.Crypto.deriveAccessKey(
profileKey
);
// our key
const pubKeyString = StringView.arrayBufferToHex(
identityKeyPair.pubKey
);
return createAccount(
pubKeyString,
null,
identityKeyPair,
profileKey,
null,
null,
null,
{ accessKey }
)
.then(clearSessionsAndPreKeys) .then(clearSessionsAndPreKeys)
.then(generateKeys) .then(generateKeys)
.then(keys => confirmKeys(keys)) .then(confirmKeys)
.then(registrationDone) .then(() => registrationDone(pubKeyString))
}
) )
); );
}, },
@ -394,22 +415,46 @@
}); });
}); });
}, },
createAccount(identityKeyPair, userAgent, readReceipts) { // Original parameters are left so we are still compatible with the other signal code
createAccount(
number,
verificationCode,
identityKeyPair,
profileKey,
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
// if we're relinking after a reinstall on the master device
const pubKeyString = StringView.arrayBufferToHex(
identityKeyPair.pubKey
);
return Promise.resolve().then(() => { return Promise.resolve().then(() => {
textsecure.storage.remove('identityKey'); textsecure.storage.remove('identityKey');
textsecure.storage.remove('signaling_key');
textsecure.storage.remove('password');
textsecure.storage.remove('registrationId');
textsecure.storage.remove('number_id'); textsecure.storage.remove('number_id');
textsecure.storage.remove('device_name'); textsecure.storage.remove('device_name');
textsecure.storage.remove('regionCode');
textsecure.storage.remove('userAgent'); textsecure.storage.remove('userAgent');
textsecure.storage.remove('profileKey');
textsecure.storage.remove('read-receipts-setting'); textsecure.storage.remove('read-receipts-setting');
const identity = number || pubKeyString;
// 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
const pubKeyString = StringView.arrayBufferToHex( textsecure.storage.protocol.saveIdentityWithAttributes(identity, {
identityKeyPair.pubKey id: identity,
);
textsecure.storage.protocol.saveIdentityWithAttributes(pubKeyString, {
id: pubKeyString,
publicKey: identityKeyPair.pubKey, publicKey: identityKeyPair.pubKey,
firstUse: true, firstUse: true,
timestamp: Date.now(), timestamp: Date.now(),
@ -418,6 +463,12 @@
}); });
textsecure.storage.put('identityKey', identityKeyPair); textsecure.storage.put('identityKey', identityKeyPair);
textsecure.storage.put('signaling_key', signalingKey);
textsecure.storage.put('password', password);
textsecure.storage.put('registrationId', registrationId);
if (profileKey) {
textsecure.storage.put('profileKey', profileKey);
}
if (userAgent) { if (userAgent) {
textsecure.storage.put('userAgent', userAgent); textsecure.storage.put('userAgent', userAgent);
} }
@ -427,7 +478,10 @@
textsecure.storage.put('read-receipt-setting', false); textsecure.storage.put('read-receipt-setting', false);
} }
textsecure.storage.user.setNumberAndDeviceId(pubKeyString, 1); textsecure.storage.user.setNumberAndDeviceId(
pubKeyString,
1,
);
}); });
}, },
clearSessionsAndPreKeys() { clearSessionsAndPreKeys() {
@ -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