Centralize public-key material validation in lib/keys.ts (#163)#247
Open
Krishna41357 wants to merge 1 commit into
Open
Centralize public-key material validation in lib/keys.ts (#163)#247Krishna41357 wants to merge 1 commit into
Krishna41357 wants to merge 1 commit into
Conversation
|
@Krishna41357 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #163
What changed
Added
apps/backend/src/lib/keys.tsas the single validator for all public-keymaterial the server accepts: identity keys, signed prekeys, one-time prekeys,
and signatures. Every endpoint that previously validated key material inline
now routes through it.
IdentityPublicKeySchema— 44-byte Ed25519 SPKI DER, base64PreKeyPublicKeySchema— 32-byte raw Ed25519 key, base64SignatureSchema— 64-byte Ed25519 signature, base64PreKeyEntrySchema/SignedPreKeyEntrySchema— composite schemas used bythe prekey upload endpoint
verifyEd25519Signature— shared signature verification, moved out ofroutes/devices.tsMlsKeyPackageSchema— 32–4096 byte validator, ready for use, documented ascurrently unused since no endpoint accepts MLS key packages in this
codebase yet (see scope note below)
Wired in:
apps/backend/src/schemas/auth.schemas.ts—DeviceSchemaandVerifySchemanow validateidentityPublicKeyvia the shared schemainstead of a bare
min(1)checkapps/backend/src/routes/devices.ts—POST /devices/:id/prekeysnow usesSignedPreKeyEntrySchema/PreKeyEntrySchemafor the request body andverifyEd25519Signaturefor signature checks; the local copies of bothwere removed
Updated existing fixtures in
devices.prekeys.test.ts(VALID_BODY,ACTIVE_DEVICE.identityPublicKey) to use correctly-sized base64 placeholders,since the old short placeholders would now fail length validation before
reaching the handler logic those tests exercise.
Scope note: MLS key packages
The issue mentions MLS key packages alongside identity/prekeys. I searched
the backend (
grep -rni 'mls|keyPackage|key_package' apps/backend/src) andconfirmed there is no endpoint, schema, or DB column for MLS key packages
anywhere in this codebase yet.
MlsKeyPackageSchemais implemented and unittested so it's ready the moment such an endpoint exists, but no route was
added here — that would be new functionality outside this issue's stated
scope of centralizing validation, not introducing it for a feature that
doesn't exist.
Acceptance criteria
(auth verify/challenge, device registration, prekey upload)
keys.test.ts)devices.prekeys.test.ts) updated to staygreen under the new strict validation
Testing
pnpm testinapps/backend— all suites pass, including the newkeys.test.tsand the updateddevices.prekeys.test.ts.