Skip to content

Cache openssl cert lookup and don't bail on error #324

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

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v2
- uses: sfackler/actions/rustup@master
- uses: sfackler/actions/rustfmt@master

windows:
strategy:
fail-fast: false
Expand All @@ -35,7 +35,7 @@ jobs:
- uses: actions/checkout@v2
- uses: sfackler/actions/rustup@master
with:
version: 1.65.0
version: 1.80.0
- run: echo "::set-output name=version::$(rustc --version)"
id: rust-version
- uses: actions/cache@v1
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
description = "A wrapper over a platform's native TLS implementation"
repository = "https://github.com/sfackler/rust-native-tls"
readme = "README.md"
rust-version = "1.53.0"
rust-version = "1.80.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to avoid bumping the minimal compiler version? 0.2.13 broke GStreamer Rust plug-ins but the stable branch is stuck on 1.71.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it stuck on 1.71?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reply from a GStreamer developer:

For the question on github: because various people consider updating the toolchain requirements a breaking change because it's apparently fine to update all kinds of software but not the toolchain. I don't agree with that but I don't have the energy to deal with these people.


[package.metadata.docs.rs]
features = ["alpn"]
Expand Down
2 changes: 2 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ fn main() {
println!("cargo:rustc-cfg=have_min_max_version");
}
}

println!("cargo::rustc-check-cfg=cfg(have_min_max_version)")
}
17 changes: 15 additions & 2 deletions src/imp/openssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ use self::openssl::ssl::{
SslVerifyMode,
};
use self::openssl::x509::{store::X509StoreBuilder, X509VerifyResult, X509};
use self::openssl_probe::ProbeResult;
use std::error;
use std::fmt;
use std::io;
use std::sync::LazyLock;

use {Protocol, TlsAcceptorBuilder, TlsConnectorBuilder};

static PROBE_RESULT: LazyLock<ProbeResult> = LazyLock::new(openssl_probe::probe);

#[cfg(have_min_max_version)]
fn supported_protocols(
min: Option<Protocol>,
Expand Down Expand Up @@ -268,8 +272,17 @@ impl TlsConnector {
pub fn new(builder: &TlsConnectorBuilder) -> Result<TlsConnector, Error> {
let mut connector = SslConnector::builder(SslMethod::tls())?;

let probe = openssl_probe::probe();
connector.load_verify_locations(probe.cert_file.as_deref(), probe.cert_dir.as_deref())?;
// We need to load these separately so an error on one doesn't prevent the other from loading.
if let Some(cert_file) = &PROBE_RESULT.cert_file {
if let Err(e) = connector.load_verify_locations(Some(cert_file), None) {
debug!("load_verify_locations cert file error: {:?}", e);
}
}
if let Some(cert_dir) = &PROBE_RESULT.cert_dir {
if let Err(e) = connector.load_verify_locations(None, Some(cert_dir)) {
debug!("load_verify_locations cert dir error: {:?}", e);
}
}

if let Some(ref identity) = builder.identity {
connector.set_certificate(&identity.0.cert)?;
Expand Down
Loading