feat(dtls): add CustomSigner trait for external signing providers#94
Draft
twizansk wants to merge 1 commit into
Draft
feat(dtls): add CustomSigner trait for external signing providers#94twizansk wants to merge 1 commit into
twizansk wants to merge 1 commit into
Conversation
Add a CustomSigner trait to CryptoPrivateKeyKind that allows delegating DTLS signing operations to an external provider (HSM, TPM, cloud KMS) instead of requiring raw private key bytes in memory. This enables use cases where the private key cannot be extracted from hardware — for example, TPM-backed device certificates where only a signing API is available. The caller implements CustomSigner with their signing logic and passes it as a CryptoPrivateKeyKind::Custom variant. Changes: - Add CustomSigner trait with sign() and clone_box() methods - Add Custom variant to CryptoPrivateKeyKind enum - Add Custom match arms in generate_key_signature and generate_certificate_verify - Allow Custom keys in config validation and signature scheme compatibility checks
Member
|
please fix fmt and clippy issue |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #94 +/- ##
==========================================
- Coverage 71.30% 71.23% -0.07%
==========================================
Files 442 442
Lines 67361 67362 +1
==========================================
- Hits 48030 47985 -45
- Misses 19331 19377 +46 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Summary
Add a
CustomSignertrait toCryptoPrivateKeyKindthat allows delegating DTLS signing operations to an external provider instead of requiring raw private key bytes in memory.Motivation
Hardware security modules (HSMs), TPMs, and cloud KMS services expose signing APIs but do not allow extracting the raw private key. The current
CryptoPrivateKeyKindenum requires aringkey pair constructed from raw key bytes, making it impossible to use these external signing providers for DTLS.This is a common requirement for IoT devices with TPM-backed device certificates, cloud services using AWS KMS or GCP Cloud HSM, and any environment where private keys must remain in hardware.
Changes
CustomSignertrait inrtc-dtls/src/crypto/mod.rswithsign()andclone_box()methodsCustomvariant inCryptoPrivateKeyKindenumgenerate_key_signatureandgenerate_certificate_verifyto delegate signing to the custom signerCustomkey typetrueforCustom(the signer is responsible for producing the correct format)Usage
```rust
use rtc_dtls::crypto::{CustomSigner, Certificate, CryptoPrivateKey, CryptoPrivateKeyKind};
#[derive(Debug)]
struct MySigner { /* HSM handle, API client, etc. */ }
impl CustomSigner for MySigner {
fn sign(&self, message: &[u8]) -> Result<Vec, String> {
// Call your HSM/TPM/KMS signing API
// Return signature in the format expected by the negotiated algorithm
// (e.g., ASN.1 DER for ECDSA)
todo!()
}
}
let cert = Certificate {
certificate: vec![/* DER-encoded cert chain */],
private_key: CryptoPrivateKey {
kind: CryptoPrivateKeyKind::Custom(Box::new(MySigner {})),
serialized_der: Vec::new(), // No key material needed
},
};
```
Notes
Customsigner must return signatures in the wire format expected by the peer (e.g., ASN.1 DER for ECDSA, PKCS#1 for RSA). The library does not perform format conversion.clone_box()is required because the DTLS listener clones the certificate config for each incoming connection.is_compatible()returnstruefor all signature schemes when using aCustomsigner — the caller is responsible for ensuring their signer supports the negotiated algorithm.