From 09fc0d690b21b7f7c2d625a757310fdceb8580a5 Mon Sep 17 00:00:00 2001 From: Brendan Fattig Date: Thu, 14 Mar 2024 13:53:12 -0500 Subject: [PATCH] Use base64url encoding for encrypted username --- ts/Bytes.ts | 4 ++++ ts/context/Bytes.ts | 4 ++++ ts/state/selectors/items.ts | 2 +- ts/test-mock/pnp/username_test.ts | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ts/Bytes.ts b/ts/Bytes.ts index 1934cc9eac92..6baff3ed2686 100644 --- a/ts/Bytes.ts +++ b/ts/Bytes.ts @@ -26,6 +26,10 @@ export function toBase64(data: Uint8Array): string { return bytes.toBase64(data); } +export function toBase64url(data: Uint8Array): string { + return bytes.toBase64url(data); +} + export function toHex(data: Uint8Array): string { return bytes.toHex(data); } diff --git a/ts/context/Bytes.ts b/ts/context/Bytes.ts index d6bfb95f2bb1..c6177031a106 100644 --- a/ts/context/Bytes.ts +++ b/ts/context/Bytes.ts @@ -25,6 +25,10 @@ export class Bytes { return Buffer.from(data).toString('base64'); } + public toBase64url(data: Uint8Array): string { + return Buffer.from(data).toString('base64url'); + } + public toHex(data: Uint8Array): string { return Buffer.from(data).toString('hex'); } diff --git a/ts/state/selectors/items.ts b/ts/state/selectors/items.ts index 4bd4b2dbe507..d5c1e664e707 100644 --- a/ts/state/selectors/items.ts +++ b/ts/state/selectors/items.ts @@ -115,7 +115,7 @@ export const getUsernameLink = createSelector( const content = Bytes.concatenate([entropy, serverId]); return contactByEncryptedUsernameRoute - .toWebUrl({ encryptedUsername: Bytes.toBase64(content) }) + .toWebUrl({ encryptedUsername: Bytes.toBase64url(content) }) .toString(); } ); diff --git a/ts/test-mock/pnp/username_test.ts b/ts/test-mock/pnp/username_test.ts index 0e4762666f8b..d08f0c89fa51 100644 --- a/ts/test-mock/pnp/username_test.ts +++ b/ts/test-mock/pnp/username_test.ts @@ -345,7 +345,7 @@ describe('pnp/username', function (this: Mocha.Suite) { encryptedUsername: Buffer.concat([ entropy, uuidToBytes(serverId), - ]).toString('base64'), + ]).toString('base64url'), }) .toString();