-
Notifications
You must be signed in to change notification settings - Fork 12.6k
feat: e2ee security hardening #36942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 250 commits
Commits
Show all changes
383 commits
Select commit
Hold shift + click to select a range
7534a3c
use rest api for getUsersOfRoomWithoutKey
cardoso 328bf15
add some type annotations
cardoso c2befab
add more history
cardoso 13d94cf
fix warnings
cardoso 263bb4a
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 33717df
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 2677e2e
add more history
cardoso cd67e17
bip39
cardoso 6239bd9
add more history
cardoso ec2bdfd
add more history
cardoso 67910bc
add more history
cardoso a096b7d
add more history
cardoso b570045
add more history
cardoso 90cc5da
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 1f0ef12
simplify key agreement
cardoso 970359f
simplify subscription changed
cardoso b7abc67
move subscription changed to room
cardoso 8ab94c3
remove dead code
cardoso 00878c3
fix formatting
cardoso 74be31f
hoist key export
cardoso 83a5870
don't ignore error
cardoso 135a8a4
hoist wait for room
cardoso 91394a1
remove dead code
cardoso 63be7e0
fix flaky test
cardoso f57b0f0
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 84fbf87
remove adapters from notes
cardoso 6ec2a80
simplify persist keys
cardoso ad48037
remove playwright workflow
cardoso 9fadf22
use rest api for requesting subscription keys
cardoso c475e9f
stopClient doesn't need to be async
cardoso a29343b
aes-cbc backwards compat (wip)
cardoso 833d0bb
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso b9a612a
reset own keys api
cardoso 2039982
state READY -> KEYS_RECEIVED
cardoso 4385b4e
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 4e118d5
add more history
cardoso 8efc67d
fix initial handshake
cardoso 33b8445
add more history
cardoso bad7af8
reduce logs
cardoso 1b9539c
comment out duplicate room waiting
cardoso 1818341
make tests run independent of cwd
cardoso af1ba41
remove unneeded shouldConvertReceivedMessages method
cardoso 9d8cab6
update state diagrams
cardoso 8b1e559
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 3651328
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 9bf3345
remove querystring and url imports
cardoso 24f86f4
fix group key id
cardoso a45801d
revert some changes
cardoso 91e9212
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso d9886dd
revert some changes
cardoso 2bf1748
fix unit test
cardoso e37a774
revert some stuff
cardoso c2d9ad1
log error on decoding private key
cardoso cd067c7
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 4567149
improve logging
cardoso 4509612
parse payload
cardoso 8497882
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 6dcca49
e2ee v2 format
cardoso 5ab11a1
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 7d857dc
fix lastMessage decryption
cardoso 483f04e
fix decrypt desktop notifications
cardoso 3558150
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 59246e6
improve logging
cardoso fb68b21
improve tracing
cardoso 7a28884
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 667aee0
upgrade mnemonic word count to 12
cardoso 9736533
remove separate package
cardoso ca0665e
clean up
cardoso 4133051
remove separate package pt 2
cardoso cc75cf1
update readme
cardoso c3e34a7
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 25e890e
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso a4886c9
fix last message decryption
cardoso a515b9c
simplify logger
cardoso 5fe1f6e
simplify decrypt
cardoso c04d3eb
rename key_id -> kid
cardoso d46de6f
fix passphrase entropy
cardoso a64bc5b
revert package.json changes
cardoso 71cfec6
revert more changes
cardoso 1e884a9
revert more changes
cardoso c9721ed
revert yarn.lock
cardoso 10b0214
formatting
cardoso b836b21
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso b2139ef
fix pinned message decryption
cardoso a6f2857
quick fix for old keys
cardoso 8f7ba75
Merge branch 'develop' into e2e-crypto-core
dougfabris c474fc1
add some more logging
cardoso 4ae569b
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 9fbc1cd
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 4ae6ca1
add more history
cardoso a8cf5b4
chore: add more history
cardoso 3bf31df
chore: keep trace inside log group
cardoso ac86fca
chore: add more history
cardoso 94a26a4
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso ad2ea1a
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso cad05df
feat: support any length of prefix
cardoso 9974c98
add encode operation
cardoso a1f6bce
Merge branch 'develop' into e2e-crypto-core
cardoso abd7039
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 3d22cae
chore: use @rocket.chat/base64
cardoso 5bb5759
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso b94a411
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 8ae46f9
backwards compat first pass
cardoso 3114815
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso c231af9
separate pbkdf2 logic
cardoso 25df556
binary codec
cardoso dbfb1ab
Merge branch 'develop' into e2e-crypto-core
cardoso de5d4ea
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 03f7b89
chore: undo test changes
cardoso 128cc91
Merge branch 'develop' into e2e-crypto-core
cardoso 3637374
fix: lint errors
cardoso 3fe56bd
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 532b10c
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso b53e205
chore: improve logging
cardoso 6e22d4e
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso a1e033f
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso ce52cde
restore test file
cardoso 27083c0
chore: remove Meteor.userId from e2ee
cardoso 174285b
Merge branch 'develop' into e2e-crypto-core
cardoso 38e1d83
remove unused cache
cardoso 6b6d756
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso d8b86b6
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 020e8f9
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso ab8868f
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso bab8ed2
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso e4e5109
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 01b11ab
chore: remove unneedded EJSON.parse
cardoso 8089fff
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 761a535
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 9a324d6
fix: native federation merge tweaks
cardoso 6298157
fix: typings
cardoso 74ff78a
Merge branch 'develop' into e2e-crypto-core
cardoso 710ba57
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 88898b5
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 861a532
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso fa4ae9c
fix: support text in content
cardoso 4a6abd4
fix: legacy test
cardoso 74b9606
chore: use pre-baked data for legacy e2ee test
cardoso bc0fabb
test: remove unneeded api call
cardoso d5019b5
test: mobile content compatibility
cardoso f5f8718
chore: move AES logic to dedicated file
cardoso dffbad3
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 85822f6
chore: move RSA logic to separate file
cardoso d602906
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso a1d4318
fix: file upload
cardoso beecd4b
fix: file upload (2)
cardoso 79f17bf
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 40d9587
fix: getInstanceByRoomId
cardoso 38244be
Merge branch 'develop' into e2e-crypto-core
cardoso 1b95d32
Merge branch 'develop' into e2e-crypto-core
cardoso 04416f3
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 453d99a
fix: remove some span attributes
cardoso c668f9a
fix: add more validation
cardoso ce51598
fix: add validation to v2 payload decoding
cardoso e083e96
Merge branch 'develop' into e2e-crypto-core
cardoso 3717119
Merge branch 'develop' into e2e-crypto-core
cardoso db56fbd
Merge branch 'develop' into e2e-crypto-core
cardoso 65fa476
Merge branch 'develop' into e2e-crypto-core
cardoso d069195
Merge branch 'develop' into e2e-crypto-core
cardoso e4e77fd
Merge branch 'develop' into e2e-crypto-core
cardoso d391910
Merge branch 'develop' into e2e-crypto-core
cardoso fe6610e
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 903bb62
Merge branch 'develop' into e2e-crypto-core
cardoso bd0bb72
Merge branch 'develop' into e2e-crypto-core
cardoso c0801bf
fix: support v2 format in chat.update endpoint
cardoso 5929d53
fix: lint errors
cardoso 20bad63
fix: throw error on Binary.toArrayBuffer if character is multi-byte
cardoso 7498580
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso bd20698
Merge branch 'develop' into e2e-crypto-core
cardoso dba9555
Merge branch 'develop' into e2e-crypto-core
cardoso 0cd16e6
Merge branch 'develop' into e2e-crypto-core
cardoso 14eee06
Merge branch 'develop' into e2e-crypto-core
cardoso a364e81
Merge branch 'develop' into e2e-crypto-core
cardoso 72f6909
feat(e2ee): Refactor PBKDF2 utilities into granular functions
cardoso 633e0cb
test(e2ee): Add unit tests for PBKDF2 utility functions
cardoso 40820a4
feat(e2ee): Introduce `Codec` interface and `PrefixedBase64` codec
cardoso d6c467b
feat(e2ee): Implement `Keychain` for E2EE private key management
cardoso 78799db
test(e2ee): Add unit tests for Keychain class
cardoso feed8f0
refactor(e2ee): Integrate `PrefixedBase64` codec into `E2ERoom`
cardoso 6d3134d
refactor(e2ee): Integrate `Keychain` into `E2E` class
cardoso 34aa35b
test(e2e): Update E2E tests and user fixtures for E2EE changes
cardoso fc567d5
Merge branch 'develop' into e2e-crypto-core
cardoso 02f39d1
Merge branch 'e2e-crypto-core' into chore/pbkdf2
cardoso 6f0cebc
Merge branch 'develop' into e2e-crypto-core
cardoso 5f2de11
Merge branch 'e2e-crypto-core' into chore/pbkdf2
cardoso 6010471
fix(e2e): correct E2EE passphrase management test structure
cardoso 96ef239
refactor(e2ee): enhance cryptographic key type definitions
cardoso 08a4d28
refactor(e2ee): narrow key type for `encrypt` function
cardoso f730434
test(e2ee): update `pbkdf2` tests for stricter type assertions
cardoso c427898
Merge branch 'develop' into e2e-crypto-core
cardoso 0789bb3
Merge branch 'e2e-crypto-core' into chore/pbkdf2
cardoso bf8a1a8
docs(e2ee): Clarify IStoredKeyV1 binary format with JSDoc
cardoso b3d273c
refactor(e2ee): Standardize encrypted key storage with EncryptedKey.e…
cardoso da8f9cd
chore(e2e-tests): Enable E2E key reset for passphrase management tests
cardoso 8921927
docs(e2ee): Clarify stored key format comments
cardoso 7447423
refactor(e2ee): Refine `Codec` type to support specific encode return…
cardoso cffa28c
refactor(e2ee): Standardize `EncryptedKey` representation and seriali…
cardoso 7c2f43d
refactor(e2ee): Update keychain encryption for new `IStoredKeyV2` for…
cardoso 19b72aa
test(e2ee): Add `base64Length` utility and update keychain tests
cardoso 86097b0
chore: Apply minor formatting and whitespace consistency
cardoso 1aba286
refactor(e2ee): Mark PBKDF2 algorithm name as readonly
cardoso ca2de37
Merge branch 'develop' into e2e-crypto-core
cardoso 2b637cc
Merge branch 'e2e-crypto-core' into chore/pbkdf2
cardoso 6c8b65b
chore(e2ee): group keychain tests within a describe block
cardoso 119e1f8
refactor(e2e): improve organization of passphrase management E2E tests
cardoso 604aa59
Merge pull request #37243 from RocketChat/chore/pbkdf2
cardoso 1d88713
Merge branch 'develop' into e2e-crypto-core
cardoso d71d344
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 568b979
chore: format
cardoso 80f56cc
Merge branch 'develop' into e2e-crypto-core
cardoso d94b372
refactor: ICodec interface
cardoso 959aa2d
refactor: Keychain codec handling to a class-based implementation
cardoso 5917c21
feat: PrefixedBase64 codec and tests; update imports to use it
cardoso c3c8c9f
refactor: AES CryptoKey types and importKey/encrypt/decrypt signatures
cardoso ee4f885
refactor: update call sites for AES encrypt/decrypt
cardoso 9a381a2
test: binary codec
cardoso f055eec
chore: runtime and typings cleanups
cardoso ac7794b
Merge branch 'develop' into e2e-crypto-core
cardoso abd959f
Merge branch 'develop' into e2e-crypto-core
cardoso 4580b0a
Merge branch 'develop' into e2e-crypto-core
cardoso 67b2a3c
Merge branch 'develop' into e2e-crypto-core
cardoso aa8a325
Merge branch 'develop' into e2e-crypto-core
cardoso 50682f0
Merge branch 'develop' into e2e-crypto-core
cardoso 2c4410f
fix: federation conflict
cardoso ea6bc17
fix: formatting
cardoso e90e176
fix: typings
cardoso d034005
chore: add aes tests
cardoso 6b964a2
Merge branch 'develop' into e2e-crypto-core
cardoso aef5162
Merge branch 'develop' into e2e-crypto-core
cardoso 2afaa65
Merge branch 'develop' into e2e-crypto-core
cardoso 973bf98
Merge branch 'develop' into e2e-crypto-core
cardoso e07ccdb
refactor: use ICodec interface (encode/decode) and update tests
cardoso d985a32
refactor: remove ByteBuffer-based helpers and file-reader helper
cardoso 9b0644b
refactor: use Binary.encode/decode and replace removed helpers
cardoso ec7b32b
refactor: E2EE class behaviors, key handling, and key export/import
cardoso 6e4354e
refactor: RSA module types and JWK import/export, and add RSA tests
cardoso f9753cb
Merge branch 'develop' into e2e-crypto-core
cardoso 44e85a5
chore: move crypto primitives to own folder
cardoso 07f1158
fix: formatting
cardoso 7e68273
refactor: type-safe crypto
cardoso 81801bc
Merge branch 'develop' into e2e-crypto-core
cardoso 5c13a8e
Merge branch 'develop' into e2e-crypto-core
cardoso 65c7a72
fix: remove unneeded async
cardoso bb68cbf
Merge branch 'develop' into e2e-crypto-core
cardoso de56c66
Merge branch 'develop' into e2e-crypto-core
cardoso e38c9fe
Merge branch 'develop' into e2e-crypto-core
cardoso 7de2048
Merge branch 'develop' into e2e-crypto-core
cardoso 62e2ff7
chore: remove dangling comment
cardoso b41a00e
chore: improve pbkdf2 types
cardoso 6c48c94
chore(jest): webcrypto in client setup
cardoso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1 @@ | ||
| export enum E2EEState { | ||
| NOT_STARTED = 'NOT_STARTED', | ||
| DISABLED = 'DISABLED', | ||
| LOADING_KEYS = 'LOADING_KEYS', | ||
| READY = 'READY', | ||
| SAVE_PASSWORD = 'SAVE_PASSWORD', | ||
| ENTER_PASSWORD = 'ENTER_PASSWORD', | ||
| ERROR = 'ERROR', | ||
| } | ||
| export type E2EEState = 'NOT_STARTED' | 'DISABLED' | 'LOADING_KEYS' | 'READY' | 'SAVE_PASSWORD' | 'ENTER_PASSWORD' | 'ERROR'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,9 @@ | ||
| export enum E2ERoomState { | ||
| NO_PASSWORD_SET = 'NO_PASSWORD_SET', | ||
| NOT_STARTED = 'NOT_STARTED', | ||
| DISABLED = 'DISABLED', | ||
| HANDSHAKE = 'HANDSHAKE', | ||
| ESTABLISHING = 'ESTABLISHING', | ||
| CREATING_KEYS = 'CREATING_KEYS', | ||
| WAITING_KEYS = 'WAITING_KEYS', | ||
| KEYS_RECEIVED = 'KEYS_RECEIVED', | ||
| READY = 'READY', | ||
| ERROR = 'ERROR', | ||
| } | ||
| export type E2ERoomState = | ||
cardoso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| | 'NOT_STARTED' | ||
| | 'DISABLED' | ||
| | 'ESTABLISHING' | ||
| | 'CREATING_KEYS' | ||
| | 'WAITING_KEYS' | ||
| | 'KEYS_RECEIVED' | ||
| | 'READY' | ||
| | 'ERROR'; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { Binary } from './binary'; | ||
|
|
||
| describe('Binary', () => { | ||
| describe('toString', () => { | ||
| it('should convert ArrayBuffer to string', () => { | ||
| const array = new Uint8Array([72, 101, 108, 108, 111]); // "Hello" | ||
| const result = Binary.encode(array.buffer); | ||
| expect(result).toBe('Hello'); | ||
| }); | ||
|
|
||
| it('should handle empty ArrayBuffer', () => { | ||
| const buffer = new ArrayBuffer(0); | ||
| const result = Binary.encode(buffer); | ||
| expect(result).toBe(''); | ||
| }); | ||
| }); | ||
|
|
||
| describe('toArrayBuffer', () => { | ||
| it('should convert string to ArrayBuffer', () => { | ||
| const str = 'Hello'; | ||
| const buffer = Binary.decode(str); | ||
| const uint8 = new Uint8Array(buffer); | ||
| expect(Array.from(uint8)).toEqual([72, 101, 108, 108, 111]); | ||
| }); | ||
|
|
||
| it('should handle empty string', () => { | ||
| const str = ''; | ||
| const buffer = Binary.decode(str); | ||
| expect(buffer.byteLength).toBe(0); | ||
| }); | ||
|
|
||
| it('should throw RangeError for illegal char code', () => { | ||
| const str = 'Hello\u0100'; // Character with char code 256 | ||
| expect(() => Binary.decode(str)).toThrowErrorMatchingInlineSnapshot(`"illegal char code: 256"`); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import type { ICodec } from './codec'; | ||
|
|
||
| export const Binary: ICodec<string, ArrayBuffer> = { | ||
| encode(buffer: ArrayBuffer): string { | ||
| const uint8 = new Uint8Array(buffer); | ||
| const CHUNK_SIZE = 8192; // Process in chunks for performance | ||
| let result = ''; | ||
| for (let i = 0; i < uint8.length; i += CHUNK_SIZE) { | ||
| const chunk = uint8.subarray(i, i + CHUNK_SIZE); | ||
| result += String.fromCharCode(...chunk); | ||
| } | ||
| return result; | ||
| }, | ||
| decode(str: string): ArrayBuffer { | ||
| // Create a Uint8Array of the same length as the string. | ||
| // This will be a view on the new ArrayBuffer. | ||
| const buffer = new ArrayBuffer(str.length); | ||
| const uint8 = new Uint8Array(buffer); | ||
|
|
||
| // Iterate through the string, getting the character code for each | ||
| // character and setting it as the value for the corresponding byte. | ||
| for (let i = 0; i < str.length; i++) { | ||
| const charCode = str.charCodeAt(i); | ||
| if (charCode > 0xff) { | ||
| throw new RangeError(`illegal char code: ${charCode}`); | ||
| } | ||
| uint8[i] = charCode; | ||
| } | ||
|
|
||
| return buffer; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export interface ICodec<TIn, TOut, TEnc = TIn> { | ||
| decode: (data: TIn) => TOut; | ||
| encode: (data: TOut) => TEnc; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| import { decodeEncryptedContent } from './content'; | ||
| import { importKey, decrypt, type Key } from './crypto/aes'; | ||
|
|
||
| describe('content', () => { | ||
| const msgv1web = Object.freeze({ | ||
| _id: 'JfAxN6Ncsw2XS9eiY', | ||
| rid: '68dad82a10815056615446aa', | ||
| e2eMentions: { | ||
| e2eUserMentions: [], | ||
| e2eChannelMentions: [], | ||
| }, | ||
| content: Object.freeze({ | ||
| algorithm: 'rc.v1.aes-sha2', | ||
| ciphertext: '32c9e7917b78LHjHfqLMeDn+2UK1PhD/soFe8CVwvFdLkslcfxNHby4=', | ||
| }), | ||
| t: 'e2e', | ||
| ts: { | ||
| $date: '2025-09-29T19:07:07.908Z', | ||
| }, | ||
| u: { | ||
| _id: 'bm4cAAcN92jgXe2jN', | ||
| username: 'alice', | ||
| name: 'alice', | ||
| }, | ||
| msg: '', | ||
| _updatedAt: { | ||
| $date: '2025-09-29T19:07:07.929Z', | ||
| }, | ||
| urls: [], | ||
| mentions: [], | ||
| channels: [], | ||
| }); | ||
|
|
||
| const msgv1mob = Object.freeze({ | ||
| _id: 'AZF8Myj605B3f7ZPL', | ||
| rid: '68dad82a10815056615446aa', | ||
| msg: '32c9e7917b783JpM8aOVludqIRzx+DOqjEU9Mj3NUWb+/GLRl7sdkvTtCMChH1LBjMjJJvVJ6Rlw4dI8BYFftZWiCOiR7TPwriCoSPiZ7dY5C4H2q8MVSdR95ZiyG7eWQ5j5/rxzAYsSWDA9LkumW8JBb+WQ1hD9JMfQd4IXtlFMnaDgEhZhe/s=', | ||
| t: 'e2e', | ||
| e2e: 'pending', | ||
| e2eMentions: { | ||
| e2eUserMentions: [], | ||
| e2eChannelMentions: [], | ||
| }, | ||
| content: Object.freeze({ | ||
| algorithm: 'rc.v1.aes-sha2', | ||
| ciphertext: | ||
| '32c9e7917b783JpM8aOVludqIRzx+DOqjEU9Mj3NUWb+/GLRl7sdkvTtCMChH1LBjMjJJvVJ6Rlw4dI8BYFftZWiCOiR7TPwriCoSPiZ7dY5C4H2q8MVSdR95ZiyG7eWQ5j5/rxzAYsSWDA9LkumW8JBb+WQ1hD9JMfQd4IXtlFMnaDgEhZhe/s=', | ||
| }), | ||
| ts: { | ||
| $date: '2025-09-29T19:28:35.261Z', | ||
| }, | ||
| u: { | ||
| _id: 'RQTYT5RJoDKZFwDhk', | ||
| username: 'bob', | ||
| name: 'bob', | ||
| }, | ||
| _updatedAt: { | ||
| $date: '2025-09-29T19:28:35.274Z', | ||
| }, | ||
| urls: [], | ||
| mentions: [], | ||
| channels: [], | ||
| }); | ||
|
|
||
| describe('v1 messages', () => { | ||
| let key: Key<{ name: 'AES-CBC'; length: 128 }>; | ||
|
|
||
| beforeAll(async () => { | ||
| key = await importKey({ | ||
| alg: 'A128CBC', | ||
| ext: true, | ||
| k: 'qb8In0Rpa9nwSusvxxDcbQ', | ||
| key_ops: ['encrypt', 'decrypt'], | ||
| kty: 'oct', | ||
| }); | ||
| }); | ||
|
|
||
| test('parse v1 web message', async () => { | ||
| const parsed = decodeEncryptedContent(msgv1web.content); | ||
| const decrypted = await decrypt(key, parsed); | ||
| expect(decrypted).toMatchInlineSnapshot(`"{"msg":"hello"}"`); | ||
| }); | ||
|
|
||
| test('parse v1 mobile message', async () => { | ||
| const parsed = decodeEncryptedContent(msgv1mob.content); | ||
| const decrypted = await decrypt(key, parsed); | ||
| expect(decrypted).toMatchInlineSnapshot( | ||
| `"{"_id":"AZF8Myj605B3f7ZPL","text":"world","userId":"RQTYT5RJoDKZFwDhk","ts":{"$date":1759174115076}}"`, | ||
| ); | ||
| }); | ||
|
|
||
| test('parse v1 mobile message from msg field', async () => { | ||
| const parsed = decodeEncryptedContent(msgv1mob.msg); | ||
| const decrypted = await decrypt(key, parsed); | ||
| expect(decrypted).toMatchInlineSnapshot( | ||
| `"{"_id":"AZF8Myj605B3f7ZPL","text":"world","userId":"RQTYT5RJoDKZFwDhk","ts":{"$date":1759174115076}}"`, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| const msgv2web = Object.freeze({ | ||
| _id: 'h6sXWTiKcWfcgkhgo', | ||
| rid: '68c9da1b0427bc33b429207e', | ||
| e2eMentions: { | ||
| e2eUserMentions: [], | ||
| e2eChannelMentions: [], | ||
| }, | ||
| content: Object.freeze({ | ||
| algorithm: 'rc.v2.aes-sha2', | ||
| kid: 'f46d2864-0384-4a87-8815-51fba2cad216', | ||
| iv: 'wXbYQ8q9sYRCHtNp', | ||
| ciphertext: 'cIDO9mXzCCrrl/wORP0Jf6oWeusqzSCXVGGvY7CHrA==', | ||
| }), | ||
| t: 'e2e', | ||
| ts: { | ||
| $date: '2025-09-30T18:05:30.876Z', | ||
| }, | ||
| u: { | ||
| _id: 'Ctk47kkuzJihnmvZE', | ||
| username: 'alice', | ||
| name: 'Alice', | ||
| }, | ||
| msg: '', | ||
| _updatedAt: { | ||
| $date: '2025-09-30T18:05:30.887Z', | ||
| }, | ||
| urls: [], | ||
| mentions: [], | ||
| channels: [], | ||
| }); | ||
|
|
||
| test('parse v2 web message', async () => { | ||
| const parsed = decodeEncryptedContent(msgv2web.content); | ||
| const key = await importKey({ | ||
| alg: 'A256GCM', | ||
| ext: true, | ||
| k: '9o1xoHt4OamRJvnaLna-5akUb5L98S_iWYGGaXPZ1Yg', | ||
| key_ops: ['encrypt', 'decrypt'], | ||
| kty: 'oct', | ||
| }); | ||
| const decrypted = await decrypt(key, parsed); | ||
| expect(decrypted).toMatchInlineSnapshot(`"{"msg":"hello"}"`); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.