Add crypto helpers and public error

pull/446/head
Beaudan Brown 6 years ago
parent 205f03419f
commit eec4f22b50

@ -158,6 +158,27 @@
}
}
async function decryptToken(ivAndCipherText64, serverPubKey64) {
const ivAndCipherText = new Uint8Array(
dcodeIO.ByteBuffer.fromBase64(ivAndCipherText64).toArrayBuffer()
);
const iv = ivAndCipherText.slice(0, IV_LENGTH);
const cipherText = ivAndCipherText.slice(IV_LENGTH);
const serverPubKey = new Uint8Array(
dcodeIO.ByteBuffer.fromBase64(serverPubKey64).toArrayBuffer()
);
const { privKey } = await textsecure.storage.protocol.getIdentityKeyPair();
const symmetricKey = libsignal.Curve.calculateAgreement(
serverPubKey,
privKey
);
const token = await libsignal.crypto.decrypt(symmetricKey, cipherText, iv);
const tokenString = dcodeIO.ByteBuffer.wrap(token).toString('utf8');
return tokenString;
}
const snodeCipher = new LokiSnodeChannel();
window.libloki.crypto = {
@ -166,6 +187,7 @@
FallBackSessionCipher,
FallBackDecryptionError,
snodeCipher,
decryptToken,
// for testing
_LokiSnodeChannel: LokiSnodeChannel,
_decodeSnodeAddressToPubKey: decodeSnodeAddressToPubKey,

@ -263,6 +263,16 @@
}
}
function PublicTokenError(message) {
this.name = 'PublicTokenError';
ReplayableError.call(this, {
name: 'PublicTokenError',
message,
});
}
inherit(ReplayableError, PublicTokenError);
function TimestampError(message) {
this.name = 'TimeStampError';
@ -305,4 +315,5 @@
window.textsecure.WrongDifficultyError = WrongDifficultyError;
window.textsecure.TimestampError = TimestampError;
window.textsecure.PublicChatError = PublicChatError;
window.textsecure.PublicTokenError = PublicTokenError;
})();

Loading…
Cancel
Save