feat(crypto): add immutable crypto configuration validation (#1729) - #1839
Open
Paranoa-dev wants to merge 1 commit into
Open
feat(crypto): add immutable crypto configuration validation (#1729)#1839Paranoa-dev wants to merge 1 commit into
Paranoa-dev wants to merge 1 commit into
Conversation
…Mail#1729) Create CryptoConfig for validating suites, limits, key resolvers, clocks, and runtime primitives as one immutable configuration. Invalid combinations now fail before any crypto operation is served. Secret values are never included in validation errors. Production requires Web Crypto; development allows test overrides.
Author
|
Good day Maintainer |
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.
Creates an immutable, validated crypto configuration object (
CryptoConfig) that consolidates algorithm identifiers, size limits, key resolver availability, clock source, and runtime primitive checks into a single validated configuration. Invalid combinations fail before any crypto operation is served.Problem
Algorithm identifiers, limits, and runtime capabilities are currently implicit in code and not validated as one configuration. Misconfigured deployments may fail only when a user attempts to send or open a message.
Solution
src/services/crypto/config.ts� Crypto Configuration ValidationNew types and interfaces:
CryptoConfig� The full, immutable, frozen configuration objectCryptoConfigInput� Builder input with optional overridesCryptoEnvironment�"development" | "production"deployment modeCryptoLimits� Body and attachment size/count limitsCryptoPrimitives� Runtime primitive availability (subtleCrypto,getRandomValues)KeyResolverConfig/ClockConfig� Availability metadata for key resolvers and clocksValidation functions:
validateEnvironment()� Checks environment string is"development"or"production"validateEnvelopeVersion()� Validates version against the suite registryvalidateSuites()� Validates all suite names are registered and supported for the given versionvalidateLimits()� Enforces min/max bounds on all limit fields (finite numbers, integer attachments)validatePrimitives()� Production requirescrypto.subtleandcrypto.getRandomValues; development allows test overridesdetectPrimitives()� Runtime detection of Web Crypto availability (frozen result)Builder and singleton:
buildCryptoConfig(input?)� Builds and validates an immutable config. Returnsvalid: falsewith frozenerrorsarray on failure. No secrets in errors.getCryptoConfig()/resetCryptoConfig()� Cached singleton for the default (production) configKey design decisions:
Object.freeze()d � truly immutable after constructionMIN_LIMITS) and ceiling (MAX_LIMITS) values to prevent misconfigurationtests/unit/crypto/config.test.ts� 72 TestsComprehensive test coverage across:
subtleCrypto/getRandomValues)validateLimits,validateSuites,validateEnvelopeVersion,validatePrimitives,validateEnvironment)detectPrimitives)getCryptoConfig/resetCryptoConfig)Acceptance Criteria
Implementation Scope
src/services/crypto/config.tstests/unit/crypto/config.test.tsTest Results
The pre-existing crypto test failures (
crypto is not defined) are due to the vitest Node.js environment lackingglobalThis.cryptoand are unrelated to this change.Closes #1729