Skip to content

Commit

Permalink
chore(FFI): Use the cryptographic provider from ring crate
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Jun 24, 2024
1 parent a8b67a5 commit 6c7a300
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
8 changes: 3 additions & 5 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/pact_ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 10 additions & 1 deletion rust/pact_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)]
Expand Down
21 changes: 10 additions & 11 deletions rust/pact_ffi/src/mock_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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};
Expand Down

0 comments on commit 6c7a300

Please sign in to comment.