Comments (6)
👋 Hi there, thanks for opening an issue
I think we're open to adding functionality for this. Previously (rustls/webpki#67) I had started implementing something similar in webpki
but the conclusion at the time was that it'd be a better fit in rustls with a slightly different design. I haven't had time to come back around to that but it's been on my mind because we stubbed out X509_check_private_key
with a TODO in some ongoing OpenSSL compatibility work.
Would you be interested in working on a PR?
from rustls.
Would you be interested in working on a PR?
Yeah! I still have a lot to learn in this space, though. Are you guys are okay with nurturing a newbie?
Naively, the interface I would want is one of:
-
A method on
CertifiedKey
that verifies consistency between theCertifiedKey
's underlyingend_entity_cert
(of typeCertificateDer
) andkey
(Arc<dyn SigningKey>
):/// I think this might not work, though. See the paragraph below. verify_private_key(&self) -> Result<(), Error>
-
Or maybe just a free function, like:
/// Ditto-ish. See below also. verify_private_key(cert: &SomeCertType, key: &SomeKeyType) -> Result<(), Error>
Looking at rustls/webpki#67, it looks like one tricky part of this will be finding certificate and key types (types meaning Rust types) that are abstract, but not so much so that we lose distinctive information like cryptographic key types—which also must be consistent, aside from the actual public key bytes we'd like to compare.
For example, take the CertifiedKey
function I pitched above. CertifiedKey
's end_entity_cert()
is CertificateDer
, not webpki::EndEntityCert
. But even webpki::EndEntityCert
doesn't give us the SubjectPublicKeyInfo
I assume we want—that would mean accessing its private inner cert::Cert
. It also doesn't look like SigningKey
gives us, well, anything here. That would also need to be figured out.
I'll have some contiguous time over the weekend to get started on this, along with a few hours here and there during the week. If you guys have any pointers in the meantime, I'd greatly appreciate it!
from rustls.
The pieces I had in mind for this were:
- add a function to
webpki::EndEntityCert
that exposes the certificate's public key as a SPKI. Note that webpki's internal representation of an SPKI (ieCert::spki
) lacks the length prefix; this would need to be reconstituted for the encoding to be correct. We could possibly add this type topki-types
to give it a name? - add a function to
rustls::sign::SigningKey::public_key
that returns the public key, again in SPKI format. This should be optional, and have a default that opts-out in a distinctive way. Perhaps that isResult<Option<Vec<u8>>, Error>
, or maybe we add a distinctive newError
. Both of those options seem alright. - add a function to
CertifiedKey
, naming TBD, which: a) parsesend_entity_cert()
to extract the certificate SPKI, b) gets the other SPKI from the private key, and c) errors in a distinctive way if they do not match. - call that new function from the various
set_single_cert
functions we have around the place. - see about providing
public_key()
for the variousSigningKey
impls we have (ring, aws-lc-rs, provider-example). A bit of research here to see what is possible in ring/aws-lc-rs's API.
from rustls.
Are you guys are okay with nurturing a newbie?
I would be happy to help you work through the above if you're still interested. You can find us in Discord in the #rustls
room if you want to have a place to ask one-off questions.
Ctz's plan sounds good to me. WDYT about starting with the first bullet point and working up a pki-types
and webpki
branch? I think the last bullet might be the most involved, we can work towards it starting with some of the easier pieces.
from rustls.
Ctz's plan sounds good to me. WDYT about starting with the first bullet point and working up a pki-types and webpki branch? I think the last bullet might be the most involved, we can work towards it starting with some of the easier pieces.
This sounds great, and thank you! I'll drop a few questions in your Discord channel soon.
from rustls.
add a function to CertifiedKey, naming TBD, which: a) parses end_entity_cert() to extract the certificate SPKI, b) gets the other SPKI from the private key, and c) errors in a distinctive way if they do not match.
Perhaps stating the obvious: the crypto library may read in a (private key, public key) pair but never check that the privacy key is consistent with the public key. Then the crypto library might expose the potentially-mismatched public key to others. Many crypto libraries don't check pairwise consistency at all, and/or they offer options or separate APIs that optionally do it. Ideally Rustls would extract the SPKI from the EE certificate and then ask the crypto provider to do a pairwise consistency check as part of the construction of a CertifiedKey.
from rustls.
Related Issues (20)
- Suggest registering for OpenSSF Best Practices badge HOT 7
- Pass ClientHello by reference to ResolvesServerCert HOT 2
- GHSA-6g7w-8wpp-frhj and CVE-2024-32650 don't make it clear that async rustls servers aren't susceptible HOT 2
- AWS LC fails against golang TLS server while ring works fine HOT 6
- Rustls w/ aws-lc-rs on Windows requires NASM HOT 31
- Making impl ClientHelloPayload public ? HOT 21
- Question. Does rustls have something to hide cert (as it is sensitive data ) in binary and memory HOT 3
- Ensuring that a provider based on the one built-in is used HOT 8
- Compile error when target is watchos HOT 6
- Expose ability to customize ClientHello message HOT 4
- How I use CryptoProvider::install_default() ? HOT 3
- Illegal instruction on arm-a72 HOT 3
- Add RustCrypto cryptographic backend HOT 5
- Build rustls v0.23.5 with musl HOT 2
- UnbufferedConnectionState HOT 2
- Unbuffered process_tls_records does not mach usage scenario HOT 2
- Clean up crate feature naming
- build failure due to aws-lc-sys v0.16.0 HOT 1
- `UnknownIssuer` with self-signed certificate HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rustls.