-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CryptoProvider support #366
Comments
(Was this meant to be filed on rustls/rustls-ffi instead of this repo?) |
Yep, thanks! |
@jsha I started working on the "Stage I" plan and have a prototype branch that I think gets us most of the way there: cpu-choose-your-own-crypto-adventure.
The If built with I've been using Some places that I could use feedback:
I'll keep poking at this in the meantime and update here if I get any further along. Thanks! |
Yes, this is good.
Right now the only thing you can do with a To put another way:
Maybe we don't need these at all? If people want the defaults, they can just rely on them being default. We should do some brief spelunking to see if there was more motivation to offer these.
Yeah, this seems like the best way forward, though I don't love it. It means asking users to pick a crypto provider once to build their config, and a second time to build their certified key. |
Thanks for the feedback!
That type is also used for the I'm imagining something like: #[no_mangle]
pub extern "C" fn rustls_crypto_provider_cipher_suites(
provider: *const rustls_crypto_provider,
cipher_suites: *mut *const *const rustls_supported_ciphersuite,
cipher_suites_len: *mut size_t,
) -> rustls_result {
...
} I tried a quick initial implementation without introducing a new |
Oops, you are correct. Okay, an amendment: When calling So for However, for configuring a connection, you would still need to pass So |
Here's a checkpoint branch that's a bit further along (but still missing lots of polish).
I also tried something new and added a unit tests module in Some places for improvement:
What do you think about this general direction for the API? |
Generally looks right.
Yep, this is excellent and the way forward. We discussed this a bit here: #209. One of the benefits of Rust tests is that we get the benefit of Miri, at least in code paths that don't hit FFI (which Miri doesn't like). The reason you don't see a lot of these is just that we don't have a lot of unittest coverage. My initial testing priority was to get a sort of working example and see how the API felt in C. That's of course a downside of writing unittests in Rust; since we're not exercising the code in C we won't see right away if we've made an awkward API. But I think that's an acceptable tradeoff. I haven't found any unittesting frameworks in C that looked great. |
That makes sense. I'll take a look at fixing that up.
Awesome. What you're saying about the trade-offs makes sense to me too. |
I was able to find time to come back around at this. PTAL: #441 |
Rustls' upcoming 0.22 release has support for a
CryptoProvider
trait that can be used to provide alternate crypto backends. We should support it in rustls-ffi. We can think of this as two stages:Stage 1
Allow choosing between rustls' first party supported providers,
ring
, andaws-lc-rs
. Requirements:ring
,aws-lc-rs
, and "bothring
andaws-lc-rs
".ring
oraws-lc-rs
for any given config, including selecting different backends for different configs.Stage 2
Allow implementation of third-party CryptoProviders through rustls-ffi.
The path to do this would be to expose each of the 15 traits I mentioned in rustls/rustls#1603. The pattern to implement traits in FFI is to effectively do the same thing as trait objects in Rust: define a vtable and do dynamic dispatch.
void *userdata
.*userdata
with the vtable.So, there's a path to exposing all the traits of the CryptoProvider API. But I actually think we shouldn't do this. I think the FFI should go the other way. If there's an existing C library that provides crypto implementations (e.g. boringssl), someone should write Rust code that calls out to that library with FFI in order to provide the traits that
CryptoProvider
wants. This is how the demoboring-rustls-provider
does it.That leaves the question: say a rustls-ffi users wants to use neither
ring
noraws-lc-rs
, but some third thing likeboring-rustls-provider
. How do they do that?I think it should work like this:
*rustls_crypto_provider
.&'static &'static dyn CryptoProvider
" (the two statics handle the DSTs problem we were just discussing).CryptoProvider
implementations can either expose an FFI method themselves to get a pointer of the appropriate type, or someone else can provide it.The text was updated successfully, but these errors were encountered: