Skip to content

[ext]: Seal DEKs with a standard set of ciphers - #173

Open
pseudomuto wants to merge 1 commit into
ext_server_materialfrom
ext-ciphers
Open

pseudomuto wants to merge 1 commit into
ext_server_materialfrom
ext-ciphers

Conversation

@pseudomuto

Copy link
Copy Markdown
Collaborator

KeyMaterial gave extension servers a framing so they stopped hand-rolling binary layouts, but it left the cryptography with them. Writing a provider still meant building an AEAD, generating a nonce, choosing additional data, and re-checking the nonce length on the way back in. Those are the parts where mistakes are silent rather than loud.

Add a key wrapper that takes a lookup for wrapping keys and does the rest. It seals with an AEAD, frames the result as KeyMaterial, and opens it again. AES-256-GCM is the default, but ChaCha20-Poly1305 and XChaCha20-Poly1305 are also available. A caller can register others via ext.WithCipherFunc.

Where key bytes come from stays with the implementor. Owning the derivation would mean owning its migration story too (nope), so the example keeps its HKDF and loses everything else.

KeyMaterial gave extension servers a framing so they stopped
hand-rolling binary layouts, but it left the cryptography with them.
Writing a provider still meant building an AEAD, generating a nonce,
choosing additional data, and re-checking the nonce length on the way
back in. Those are the parts where a mistake is silent rather than
loud.

Add a key wrapper that takes a lookup for wrapping keys and does the
rest. It seals with an AEAD, frames the result as KeyMaterial, and
opens it again. AES-256-GCM is the default, but ChaCha20-Poly1305 and
XChaCha20-Poly1305 are also available. A caller can registers others via
`ext.WithCipherFunc`.

Where key bytes come from stays with the implementor. Owning the
derivation would mean owning its migration story too (nope), so the
example keeps its HKDF and loses everything else.
@pseudomuto
pseudomuto added this pull request to stack #174 September 16, 2026 18:37
@pseudomuto
pseudomuto requested a review from a team as a code owner September 16, 2026 18:37
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.44262% with 8 lines in your changes missing coverage. Please review.

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread examples/kms/README.md
Comment on lines +217 to +218
token, serves TLS, and shuts down on a signal. Start with `keyring.go` if you are writing one of these against a real
key service, because that method is the part you replace:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we qualify this to key services that can return the raw wrapping-key bytes? Some managed key services keep their keys non-exportable and provide only wrap and unwrap APIs. Those implementations would use KeyMaterial for the common framing but continue implementing ext.KMS directly instead of using NewKeyWrapper.

@dipali-bhatt dipali-bhatt left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together. For managed key services such as SF KMS, the wrapping key is non-exportable, so the extension cannot return the raw key bytes required by NewKeyWrapper.
Would you consider adding a companion helper, that defines provider-neutral wrap and unwrap callbacks and implements the surrounding ext.KMS and KeyMaterial construction and parsing? The extension callbacks would continue to own authentication, API calls, algorithm and field validation, integrity protection, error mapping, and backend-specific key semantics.
This would keep the solution provider-neutral while allowing managed-KMS integrations to avoid implementing their own durable record encoding and decoding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants