Merge pull request #446 from BeaudanBrown/auth-crypto

[Public Authentication] Add crypto helpers and public error
pull/448/head
Beaudan Campbell-Brown 6 years ago committed by GitHub
commit 81f7f340bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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