From 6c7a3004de0f9db1b4e92745b960ed311bc777f2 Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Mon, 24 Jun 2024 14:48:07 +1000 Subject: [PATCH] chore(FFI): Use the cryptographic provider from ring crate --- rust/Cargo.lock | 8 +++----- rust/pact_ffi/Cargo.toml | 2 +- rust/pact_ffi/src/lib.rs | 11 ++++++++++- rust/pact_ffi/src/mock_server/mod.rs | 21 ++++++++++----------- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index fd20b0c49..85e6019b8 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -2184,9 +2184,7 @@ dependencies = [ [[package]] name = "pact_mock_server" -version = "2.0.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "801c47d489dff87c64ff80a93bd9c915a3c5300b2433df1e11d8851f16d6131b" +version = "2.0.0-beta.3" dependencies = [ "anyhow", "bytes", @@ -4093,9 +4091,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" +checksum = "3ea73390fe27785838dcbf75b91b1d84799e28f1ce71e6f372a5dc2200c80de5" dependencies = [ "getrandom", ] diff --git a/rust/pact_ffi/Cargo.toml b/rust/pact_ffi/Cargo.toml index 8d923dcef..67edcae13 100644 --- a/rust/pact_ffi/Cargo.toml +++ b/rust/pact_ffi/Cargo.toml @@ -40,7 +40,7 @@ rand = "0.8.5" rand_regex = "0.15.1" regex = "1.10.2" regex-syntax = "0.6.29" -rustls = "0.23.10" +rustls = { version = "0.23.10", features = ["ring"] } rustls-pemfile = "2.1.2" serde = { version = "1.0.193", features = ["derive"] } serde_json = "1.0.108" diff --git a/rust/pact_ffi/src/lib.rs b/rust/pact_ffi/src/lib.rs index 683e256ba..860ee8773 100644 --- a/rust/pact_ffi/src/lib.rs +++ b/rust/pact_ffi/src/lib.rs @@ -11,6 +11,8 @@ use std::str::FromStr; use lazy_static::lazy_static; use libc::c_char; +use rustls::crypto::CryptoProvider; +use rustls::crypto::ring::default_provider; use tracing::{debug, error, info, trace, warn}; use tracing_core::{Level, LevelFilter}; use tracing_log::AsLog; @@ -80,6 +82,13 @@ pub unsafe extern fn pactffi_init(log_env_var: *const c_char) { if let Err(err) = tracing::subscriber::set_global_default(subscriber) { eprintln!("Failed to initialise global tracing subscriber - {err}"); }; + + if CryptoProvider::get_default().is_none() { + warn!("No TLS cryptographic provided has been configured, defaulting to the standard FIPS provider from ring"); + if let Err(_err) = CryptoProvider::install_default(default_provider()) { + error!("Failed to install the standard FIPS provider, HTTPS requests may not work"); + } + } } /// Initialises logging, and sets the log level explicitly. This function should only be called @@ -337,9 +346,9 @@ mod tests { use expectest::prelude::*; use rstest::rstest; + use tracing_core::LevelFilter; use super::*; - use tracing_core::LevelFilter; #[rstest] #[case("trace", LevelFilter::TRACE)] diff --git a/rust/pact_ffi/src/mock_server/mod.rs b/rust/pact_ffi/src/mock_server/mod.rs index 824cba47c..8783d53d4 100644 --- a/rust/pact_ffi/src/mock_server/mod.rs +++ b/rust/pact_ffi/src/mock_server/mod.rs @@ -50,22 +50,11 @@ use std::ffi::CString; use std::net::ToSocketAddrs; use std::panic::catch_unwind; use std::str::from_utf8; -use anyhow::anyhow; use chrono::Local; use either::Either; use libc::c_char; use onig::Regex; -use pact_models::pact::Pact; -use pact_models::time_utils::{parse_pattern, to_chrono_pattern}; -use rand::prelude::*; -use serde_json::Value; -use tokio_rustls::rustls::ServerConfig; -use tracing::{error, warn}; -use uuid::Uuid; - -use pact_matching::logging::fetch_buffer_contents; -use pact_matching::metrics::{MetricEvent, send_metrics}; use pact_mock_server::{MANAGER, MockServerError, WritePactFileErr}; use pact_mock_server::legacy::{ create_mock_server, @@ -81,8 +70,18 @@ use pact_mock_server::legacy::{ }; use pact_mock_server::mock_server::MockServerConfig; use pact_mock_server::server_manager::ServerManager; +use rand::prelude::*; +use serde_json::Value; +use tokio_rustls::rustls::ServerConfig; +use tracing::{error, warn}; +use uuid::Uuid; + +use pact_matching::logging::fetch_buffer_contents; +use pact_matching::metrics::{MetricEvent, send_metrics}; use pact_models::generators::GeneratorCategory; use pact_models::matchingrules::{Category, MatchingRuleCategory}; +use pact_models::pact::Pact; +use pact_models::time_utils::{parse_pattern, to_chrono_pattern}; use crate::{convert_cstr, ffi_fn, safe_str}; use crate::mock_server::handles::{PactHandle, path_from_dir};