-
Notifications
You must be signed in to change notification settings - Fork 19
chore: use crypto package everywhere #191
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
Open
debdutdeb
wants to merge
60
commits into
main
Choose a base branch
from
fdr108-use-crypto-everywhere
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
5e9d98c
fix the tests
debdutdeb 8cbcc04
test changes
debdutdeb 453b8ab
mistakenly committed
debdutdeb 71af331
fix import order in test file
debdutdeb fc13a07
update lockfile
debdutdeb 644d4dc
.... playing with it
debdutdeb 6b81995
committing
debdutdeb 3fa2276
show old test working
debdutdeb 9a9e87d
..
debdutdeb e682d4b
committing all
debdutdeb 31c2418
...
debdutdeb 0070e01
biome lint
debdutdeb 0d8ec53
correct event signature validation
debdutdeb 9ed8bc4
reduce lines
debdutdeb b04ff5d
now using in the services, more incoming
debdutdeb c0f71e1
fix tests for request service
debdutdeb 92512b5
...
debdutdeb fd22b03
tests are passing at this point
debdutdeb 1bb49d7
ts all there
debdutdeb df8a8f6
reduce diff 1
debdutdeb 53b0cce
2
debdutdeb c69bb92
remove my bun hack
debdutdeb 9ba45fd
fix races
debdutdeb df62bf7
all lints
debdutdeb ba83208
add mongo to ci? dump later
debdutdeb 1b0cc56
,,
debdutdeb 74d3b4a
fix cachekey
debdutdeb 0885012
better
debdutdeb 6bdda06
Merge remote-tracking branch 'origin/main' into fdr108-use-crypto-eve…
debdutdeb 760e926
fix: all import package names
debdutdeb 265c47c
fix: allow svs to fetch keys as it needs
debdutdeb f77a240
fix: repassing some tests
debdutdeb aa3ea98
fix: passing event service tests
debdutdeb 58d5e7f
fix: signature verification service tests
debdutdeb ae6ea98
chore: sep tests that require mongo
debdutdeb 84f5e49
refactor: better error handling and remove server service
debdutdeb 1f17ab0
refactor: rename own server key mmethod to more accurate one
debdutdeb 9ee83a0
fix: keyservice.getownserverkeyresponse
debdutdeb 33df512
fix: linter complains
debdutdeb 57276c8
fix: broken tests
debdutdeb dca5761
fix: crypto thrown error type
debdutdeb 8c4d820
chore: workflow file formatting
debdutdeb d62c230
update lock file
debdutdeb 87b4e77
Merge remote-tracking branch 'origin/main' into fdr108-use-crypto-eve…
sampaiodiego 54c9c61
restore bun.lock
sampaiodiego 59ac6d6
test: improve config instance
sampaiodiego a0b18a8
fix: delay KeyRepository inject
sampaiodiego def6e7e
test: fix tests
sampaiodiego 8bde57b
fix: config getSigningKey
sampaiodiego 1cb5955
fix: remove database options from config
sampaiodiego 637807c
Merge remote-tracking branch 'origin/main' into fdr108-use-crypto-eve…
sampaiodiego 653eb6d
revert sdk methods changes
sampaiodiego 0ed45f6
sign join event
sampaiodiego dbd133a
fix get server key
sampaiodiego f9f5bc1
revert additional check on getRoomVersion
sampaiodiego b79a356
code cleanup
sampaiodiego fec7759
Merge remote-tracking branch 'origin/main' into fdr108-use-crypto-eve…
sampaiodiego 5531ab7
more cleanup
sampaiodiego 665d272
remove duplicated getRoomVersion
sampaiodiego 76a4314
validate request destination
sampaiodiego 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
Binary file not shown.
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 |
|---|---|---|
|
|
@@ -24,3 +24,35 @@ export type SigningKey = { | |
| publicKey: Uint8Array; | ||
| sign(data: Uint8Array): Promise<Uint8Array>; | ||
| }; | ||
|
|
||
| export type KeyV2ServerResponse = { | ||
| // still valid for signing events | ||
| old_verify_keys: Record< | ||
| string, | ||
| { | ||
| expired_ts: number; | ||
| key: string; | ||
| } | ||
| >; | ||
| server_name: string; | ||
| signatures: Record<string, Record<string, string>>; | ||
| valid_until_ts: number; | ||
| // only federation requests | ||
| verify_keys: Record< | ||
| string, // keyAlgo:algoVersion => KeyId | ||
| { | ||
| key: string; // base64 encoded | ||
| } | ||
| >; | ||
| }; | ||
|
|
||
| export type ServerKey = { | ||
| serverName: string; | ||
| keyId: string; | ||
| key: string; | ||
| pem: string; | ||
|
|
||
| _createdAt: Date; | ||
| _updatedAt: Date; | ||
|
Comment on lines
+55
to
+56
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _ prefixes don't make sense |
||
| expiresAt: Date; | ||
| }; | ||
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 was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export function runIfMongoExists(t: () => void) { | ||
| if (!process.env.RUN_MONGO_TESTS) { | ||
| console.warn('Skipping tests that require a database'); | ||
| return; | ||
| } | ||
|
|
||
| t(); | ||
| } |
50 changes: 50 additions & 0 deletions
50
packages/federation-sdk/src/__mocks__/repositories.spec.ts
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,50 @@ | ||
| import { | ||
| EventStagingStore, | ||
| EventStore, | ||
| ServerKey, | ||
| } from '@rocket.chat/federation-core'; | ||
| import { EventStagingRepository } from '../repositories/event-staging.repository'; | ||
| import { EventRepository } from '../repositories/event.repository'; | ||
| import { KeyRepository } from '../repositories/key.repository'; | ||
| import { Lock, LockRepository } from '../repositories/lock.repository'; | ||
| import { | ||
| StateGraphRepository, | ||
| type StateGraphStore, | ||
| } from '../repositories/state-graph.repository'; | ||
|
|
||
| import { DatabaseConnectionService } from '../services/database-connection.service'; | ||
|
|
||
| const databaseConfig = { | ||
| uri: 'mongodb://localhost:27017/', | ||
| name: 'matrix_test', | ||
| poolSize: 100, | ||
| }; | ||
|
|
||
| const database = new DatabaseConnectionService(databaseConfig); | ||
|
|
||
| const db = await database.getDb(); | ||
|
|
||
| const keysCollection = db.collection<ServerKey>('test_keys'); | ||
| const eventsCollection = db.collection<EventStore>('test_events'); | ||
| const eventStagingCollection = | ||
| db.collection<EventStagingStore>('test_event_staging'); | ||
| const lockCollection = db.collection<Lock>('test_locks'); | ||
| const statesCollection = db.collection<StateGraphStore>('test_states'); | ||
|
|
||
| const keyRepository = new KeyRepository(keysCollection); | ||
|
|
||
| const eventStagingRepository = new EventStagingRepository( | ||
| eventStagingCollection, | ||
| ); | ||
| const lockRepository = new LockRepository(lockCollection); | ||
| const stateRepository = new StateGraphRepository(statesCollection); | ||
|
|
||
| const eventsRepository = new EventRepository(eventsCollection); | ||
|
|
||
| export const repositories = { | ||
| keys: keyRepository, | ||
| locks: lockRepository, | ||
| eventStaging: eventStagingRepository, | ||
| states: stateRepository, | ||
| events: eventsRepository, | ||
| }; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Script executed:
Repository: RocketChat/homeserver
<shell_result>
Repository: RocketChat/homeserver
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: RocketChat/homeserver
<shell_result>
Repository: RocketChat/homeserver
Exit code: 1
</shell_result>
Script executed:
Repository: RocketChat/homeserver
<shell_result>
Repository: RocketChat/homeserver
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: RocketChat/homeserver
<shell_result>
Repository: RocketChat/homeserver
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: RocketChat/homeserver
<shell_result>
Repository: RocketChat/homeserver
Exit code: 0
</shell_result>
Script executed:
Repository: RocketChat/homeserver
<shell_result>
Repository: RocketChat/homeserver
Exit code: 0
stdout:
</shell_result>
Script executed:
# Look at the full block-if-no-mongo implementation to understand the pattern cat packages/federation-sdk/src/__mocks__/block-if-no-mongo.tsRepository: RocketChat/homeserver
<shell_result>
Repository: RocketChat/homeserver
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: RocketChat/homeserver
<shell_result>
Repository: RocketChat/homeserver
Exit code: 0
stdout:
</shell_result>
Script executed:
Repository: RocketChat/homeserver
<shell_result>
Repository: RocketChat/homeserver
Exit code: 0
stdout:
</shell_result>
Improve cross-platform compatibility of the test script.
The
test:withMongoscript has several portability issues:export RUN_MONGO_TESTS=1is bash/zsh-specific and will fail on Windowsgrep,awk,xargs) are not available on Windows by default{}placeholder inxargs bun test {}is unnecessary—xargsappends arguments by defaultCurrently, the script runs only the 4 spec files that import
runIfMongoExists(event, key, signature-verification, and state services).Recommended approach: Use a Node/Bun script instead of shell utilities for cross-platform compatibility. Create a script at
scripts/test-mongo.ts(or.js):Then update
package.json:This approach is cross-platform, easier to maintain, and avoids adding new dependencies like
cross-env.🤖 Prompt for AI Agents