Skip to content

Commit 396bcf6

Browse files
authored
fix provider loading take two (#10390) (#10395)
we previously hoisted this into rust, but we used the try_load feature which supposedly retains fallbacks. Something about that doesn't behave the way we expect though and the machinery in providers is sufficiently complex that we are just going to load the default provider explicitly. this matches our behavior pre-rust.
1 parent 0e0e46f commit 396bcf6

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/rust/src/lib.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ mod x509;
2424
#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust")]
2525
struct LoadedProviders {
2626
legacy: Option<provider::Provider>,
27+
_default: provider::Provider,
2728
}
2829

2930
#[pyo3::prelude::pyfunction]
@@ -37,7 +38,7 @@ fn is_fips_enabled() -> bool {
3738
}
3839

3940
#[cfg(CRYPTOGRAPHY_OPENSSL_300_OR_GREATER)]
40-
fn _initialize_legacy_provider() -> CryptographyResult<LoadedProviders> {
41+
fn _initialize_providers() -> CryptographyResult<LoadedProviders> {
4142
// As of OpenSSL 3.0.0 we must register a legacy cipher provider
4243
// to get RC2 (needed for junk asymmetric private key
4344
// serialization), RC4, Blowfish, IDEA, SEED, etc. These things
@@ -47,13 +48,14 @@ fn _initialize_legacy_provider() -> CryptographyResult<LoadedProviders> {
4748
.map(|v| v.is_empty() || v == "0")
4849
.unwrap_or(true);
4950
let legacy = if load_legacy {
50-
let legacy_result = provider::Provider::try_load(None, "legacy", true);
51+
let legacy_result = provider::Provider::load(None, "legacy");
5152
_legacy_provider_error(legacy_result.is_ok())?;
5253
Some(legacy_result?)
5354
} else {
5455
None
5556
};
56-
Ok(LoadedProviders { legacy })
57+
let _default = provider::Provider::load(None, "default")?;
58+
Ok(LoadedProviders { legacy, _default })
5759
}
5860

5961
fn _legacy_provider_error(success: bool) -> pyo3::PyResult<()> {
@@ -94,13 +96,13 @@ fn _rust(py: pyo3::Python<'_>, m: &pyo3::types::PyModule) -> pyo3::PyResult<()>
9496
let openssl_mod = pyo3::prelude::PyModule::new(py, "openssl")?;
9597
cfg_if::cfg_if! {
9698
if #[cfg(CRYPTOGRAPHY_OPENSSL_300_OR_GREATER)] {
97-
let providers = _initialize_legacy_provider()?;
99+
let providers = _initialize_providers()?;
98100
if providers.legacy.is_some() {
99101
openssl_mod.add("_legacy_provider_loaded", true)?;
100-
openssl_mod.add("_providers", providers)?;
101102
} else {
102103
openssl_mod.add("_legacy_provider_loaded", false)?;
103104
}
105+
openssl_mod.add("_providers", providers)?;
104106
} else {
105107
// default value for non-openssl 3+
106108
openssl_mod.add("_legacy_provider_loaded", false)?;

0 commit comments

Comments
 (0)