improve guards on loading keypair

pull/823/head
Ryan Tharp 5 years ago
parent 926a245bf6
commit dbff390035

@ -48,6 +48,12 @@
// Should we use ephemeral key pairs here rather than long term keys on each side? // Should we use ephemeral key pairs here rather than long term keys on each side?
async encrypt(plaintext) { async encrypt(plaintext) {
const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair(); const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair();
if (!myKeyPair) {
window.log.warn("encrypt, Can't load myKeyPair from storage");
// FIXME: not sure what I should give on failure
// just going to stick with the same type of value
return {};
}
const myPrivateKey = myKeyPair.privKey; const myPrivateKey = myKeyPair.privKey;
const symmetricKey = libsignal.Curve.calculateAgreement( const symmetricKey = libsignal.Curve.calculateAgreement(
this.pubKey, this.pubKey,
@ -63,6 +69,12 @@
async decrypt(ivAndCiphertext) { async decrypt(ivAndCiphertext) {
const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair(); const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair();
if (!myKeyPair) {
window.log.warn("decrypt, Can't load myKeyPair from storage");
// FIXME: not sure what I should give on failure
// just going to stick with the same type of value
return {};
}
const myPrivateKey = myKeyPair.privKey; const myPrivateKey = myKeyPair.privKey;
const symmetricKey = libsignal.Curve.calculateAgreement( const symmetricKey = libsignal.Curve.calculateAgreement(
this.pubKey, this.pubKey,
@ -169,6 +181,12 @@
data[len] = type; data[len] = type;
const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair(); const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair();
if (!myKeyPair) {
window.log.warn("generateSignatureForPairing Can't load myKeyPair from storage");
// FIXME: not sure what I should give on failure
// just going to stick with the same type of value
return {};
}
const signature = await libsignal.Curve.async.calculateSignature( const signature = await libsignal.Curve.async.calculateSignature(
myKeyPair.privKey, myKeyPair.privKey,
data.buffer data.buffer
@ -292,6 +310,12 @@
dcodeIO.ByteBuffer.fromBase64(serverPubKey64).toArrayBuffer() dcodeIO.ByteBuffer.fromBase64(serverPubKey64).toArrayBuffer()
); );
const { privKey } = await textsecure.storage.protocol.getIdentityKeyPair(); const { privKey } = await textsecure.storage.protocol.getIdentityKeyPair();
if (!myKeyPair) {
window.log.warn("decryptToken, Can't load myKeyPair from storage");
// FIXME: not sure what I should give on failure
// just going to stick with the same type of value
return {};
}
const symmetricKey = libsignal.Curve.calculateAgreement( const symmetricKey = libsignal.Curve.calculateAgreement(
serverPubKey, serverPubKey,
privKey privKey

Loading…
Cancel
Save