Skip to content

Commit

Permalink
tuftool: install default CryptoProvider for HTTP client
Browse files Browse the repository at this point in the history
when building the tuftool HTTP client, install the aws_lc_rs default
CryptoProvider if none is set yet. This is to ensure that a
CryptoProvider for rustls is set before proceeded with HTTP methods.

Signed-off-by: Gavin Inglis <[email protected]>
  • Loading branch information
ginglis13 committed Sep 27, 2024
1 parent d440259 commit 7fd06e2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tough/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use log::trace;
use reqwest::header::{self, HeaderValue, ACCEPT_RANGES};
use reqwest::{Client, ClientBuilder, Request, Response};
use reqwest::{Error, Method};
use rustls::crypto::{aws_lc_rs, CryptoProvider};
use snafu::ResultExt;
use snafu::Snafu;
use std::cmp::Ordering;
Expand Down Expand Up @@ -322,7 +323,15 @@ impl RetryStream {
&mut self,
cx: &mut std::task::Context<'_>,
) -> Result<Poll<Option<Result<bytes::Bytes, TransportError>>>, HttpError> {
// create a reqwest client
// Set the aws_lc_rs CryptoProvider for rustls. This is to ensure that the reqwest client
// is using a FIPS enabled aws_lc_rs when creating a client. Otherwise, ring is used:
// https://github.com/seanmonstar/reqwest/blob/d85f44b217f36f8bef065fe95877eab98c52c2e5/src/async_impl/client.rs#L577-L587
// This can be called successfully at most once in any process execution: https://docs.rs/rustls/latest/rustls/crypto/struct.CryptoProvider.html#method.install_default
// The return type is Result<(), Arc<Self>>, which can be dropped.
if CryptoProvider::get_default().is_none() {
let _ = aws_lc_rs::default_provider().install_default();
}

let client = ClientBuilder::new()
.timeout(self.settings.timeout)
.connect_timeout(self.settings.connect_timeout)
Expand Down

0 comments on commit 7fd06e2

Please sign in to comment.