Fix critical cryptographic vulnerabilities in key encryption and storage #22
+2,084
−126
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.
Summary
This PR addresses critical security vulnerabilities in the TAP-RS cryptographic implementation, replacing insecure XOR-based key encryption with proper ECDH-ES+A256KW key wrapping per RFC 3394 and RFC 7518. A comprehensive security audit report is included documenting all findings.
Key Changes
Security Fixes (Critical)
tap-agent/src/crypto/key_wrap.rsmodule, replacing trivial XOR operations that provided no semantic securitytap-agent/src/crypto/kdf.rsfor proper ECDH shared secret processingLocalAgentKey::encrypt_to_jwk()andDecryptionKey::unwrap_jwe()to use:aes,aes-kw, andsha2crates to support proper key wrapping and derivationDocumentation & Future Work
key_store.rsmodule: DefinesKeyStoretrait abstraction for future integration with external key management systems (HSMs, cloud KMS, platform keychains)SECURITY_AUDIT.mddocumenting:Implementation Details
p256::EphemeralSecretfor ECDH-ESResult<T>with descriptive errorsSecurity Notes
These are tracked in the audit report for follow-up PRs.
Testing
References
https://claude.ai/code/session_01KP4i4Z5K6feT3t54TAEab2