From 46bd4c218d71f5bcf6b7ce207bbba078f32cef7b Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 1 Dec 2023 13:35:56 +1100 Subject: [PATCH] fix: drop support for argon2 based ons --- ts/session/apis/snode_api/onsResolve.ts | 41 +++---------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/ts/session/apis/snode_api/onsResolve.ts b/ts/session/apis/snode_api/onsResolve.ts index 2e5cef200..767b75968 100644 --- a/ts/session/apis/snode_api/onsResolve.ts +++ b/ts/session/apis/snode_api/onsResolve.ts @@ -6,10 +6,10 @@ import { stringToUint8Array, toHex, } from '../../utils/String'; +import { OnsResolveSubRequest } from './SnodeRequestTypes'; import { doSnodeBatchRequest } from './batchRequest'; import { GetNetworkTime } from './getNetworkTime'; import { getRandomSnode } from './snodePool'; -import { OnsResolveSubRequest } from './SnodeRequestTypes'; // ONS name can have [a-zA-Z0-9_-] except that - is not allowed as start or end // do not define a regex but rather create it on the fly to avoid https://stackoverflow.com/questions/3891641/regex-test-only-works-every-other-time @@ -56,48 +56,15 @@ async function getSessionIDForOnsName(onsNameCase: string) { } const hexEncodedCipherText = intermediate?.encrypted_value; - const isArgon2Based = !intermediate?.nonce; const ciphertext = fromHexToArray(hexEncodedCipherText); - let sessionIDAsData: Uint8Array; - let nonce: Uint8Array; let key: Uint8Array; + // we dropped support for argon2 based ons - if (isArgon2Based) { - // Handle old Argon2-based encryption used before HF16 - const salt = new Uint8Array(sodium.crypto_pwhash_SALTBYTES); - nonce = new Uint8Array(sodium.crypto_secretbox_NONCEBYTES); - try { - const keyHex = sodium.crypto_pwhash( - sodium.crypto_secretbox_KEYBYTES, - onsNameLowerCase, - salt, - sodium.crypto_pwhash_OPSLIMIT_MODERATE, - sodium.crypto_pwhash_MEMLIMIT_MODERATE, - sodium.crypto_pwhash_ALG_ARGON2ID13, - 'hex' - ); - if (!keyHex) { - throw new Error('ONSresolve: key invalid argon2'); - } - key = fromHexToArray(keyHex); - } catch (e) { - throw new Error('ONSresolve: Hashing failed'); - } - - sessionIDAsData = sodium.crypto_secretbox_open_easy(ciphertext, nonce, key); - if (!sessionIDAsData) { - throw new Error('ONSresolve: Decryption failed'); - } - - return toHex(sessionIDAsData); - } - - // not argon2Based const hexEncodedNonce = intermediate.nonce as string; if (!hexEncodedNonce) { throw new Error('ONSresolve: No hexEncodedNonce'); } - nonce = fromHexToArray(hexEncodedNonce); + const nonce = fromHexToArray(hexEncodedNonce); try { key = sodium.crypto_generichash(sodium.crypto_generichash_BYTES, nameAsData, nameHash); @@ -109,7 +76,7 @@ async function getSessionIDForOnsName(onsNameCase: string) { throw new Error('ONSresolve: Hashing failed'); } - sessionIDAsData = sodium.crypto_aead_xchacha20poly1305_ietf_decrypt( + const sessionIDAsData = sodium.crypto_aead_xchacha20poly1305_ietf_decrypt( null, ciphertext, null,