Skip to content

Commit c382a60

Browse files
authored
host_env: keep rustls off the rustls-free ssl surface (#8727)
* host_env: keep rustls off the rustls-free ssl surface ssl is MemoryBIO, constants, OID, and ALPN. ssl-rustls is the rustls engine. Drop the wasm32 rustls-pki-types web dep; the browser crate already enables that feature. Assisted-by: Claude * host_env: drop rustls-pki-types from the lockfile Assisted-by: Claude * host_env: name the rustls engine feature rustls ssl is the rustls-free surface. rustls is the engine. stdlib's ssl-rustls product feature still selects this. Assisted-by: Claude
1 parent da69430 commit c382a60

6 files changed

Lines changed: 49 additions & 23 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/host_env/Cargo.toml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,20 @@ license.workspace = true
1010

1111
[features]
1212
native-certs = ["dep:rustls-native-certs"]
13-
ssl = ["dep:rustls", "dep:rustls-pemfile", "dep:rustls-webpki", "dep:x509-parser", "dep:der", "dep:pkcs8", "dep:sha2"]
13+
# rustls-free `_ssl` surface: MemoryBIO, constants, OID, ALPN, hostname.
14+
ssl = []
15+
# rustls engine. Implies `ssl`. Browser wasm enables this together with
16+
# rustls-pki-types `web` on that crate; wasm-host enables `ssl` only.
17+
rustls = [
18+
"ssl",
19+
"dep:rustls",
20+
"dep:rustls-pemfile",
21+
"dep:rustls-webpki",
22+
"dep:x509-parser",
23+
"dep:der",
24+
"dep:pkcs8",
25+
"dep:sha2",
26+
]
1427

1528
[dependencies]
1629
rustpython-wtf8 = { workspace = true }
@@ -39,11 +52,6 @@ rustix = { workspace = true }
3952
[target.'cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))'.dependencies]
4053
num_cpus = "1.17.0"
4154

42-
# rustls-pki-types::UnixTime::now is gated off wasm32-unknown-unknown unless
43-
# the `web` feature is on. Browser rustls and Charon/LLBC both need it.
44-
[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dependencies]
45-
rustls-pki-types = { version = "1", default-features = false, features = ["alloc", "std", "web"] }
46-
4755
[target.'cfg(not(any(target_os = "ios", target_os = "android", target_os = "windows", target_arch = "wasm32", target_os = "redox")))'.dependencies]
4856
mac_address = { workspace = true }
4957

@@ -114,7 +122,4 @@ cc = "1"
114122
[lints]
115123
workspace = true
116124

117-
[package.metadata.cargo-shear]
118-
# Feature-unification only: enables rustls-pki-types `web` so UnixTime::now
119-
# exists on wasm32-unknown-unknown. No rust source imports this crate.
120-
ignored = ["rustls-pki-types"]
125+

crates/host_env/src/ssl/mod.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,59 @@
11
//! Shared `_ssl` surface.
22
//!
3-
//! The `ssl` feature compiles this whole module. MemoryBIO, constants, OID,
4-
//! and ALPN do not use rustls. The rustls engine compiles wherever `rustls`
5-
//! is available, including browser wasm via rustls-rustcrypto.
3+
//! `ssl` is the rustls-free surface: MemoryBIO, constants, OID, ALPN, and
4+
//! hostname checks. `rustls` compiles the rustls engine. Browser wasm
5+
//! enables `rustls` together with rustls-pki-types `web` on that crate;
6+
//! wasm-host enables `ssl` only.
67
78
pub mod bio;
9+
pub mod constants;
10+
pub mod oid;
11+
pub mod protocol;
12+
13+
#[cfg(feature = "rustls")]
814
pub mod cert;
15+
#[cfg(feature = "rustls")]
916
pub mod chain;
17+
#[cfg(feature = "rustls")]
1018
pub mod cipher;
19+
#[cfg(feature = "rustls")]
1120
pub mod config;
21+
#[cfg(feature = "rustls")]
1222
pub mod connection;
13-
pub mod constants;
23+
#[cfg(feature = "rustls")]
1424
pub mod error;
25+
#[cfg(feature = "rustls")]
1526
pub mod handshake;
27+
#[cfg(feature = "rustls")]
1628
pub mod keylog;
29+
#[cfg(feature = "rustls")]
1730
pub mod msg;
18-
pub mod oid;
19-
pub mod protocol;
31+
#[cfg(feature = "rustls")]
2032
pub mod providers;
33+
#[cfg(feature = "rustls")]
2134
pub mod session;
35+
#[cfg(feature = "rustls")]
2236
pub mod verify;
37+
#[cfg(feature = "rustls")]
2338
pub mod x509;
2439

2540
pub use bio::{MemoryBio, MemoryBioError};
41+
pub use constants::*;
42+
pub use protocol::{AlpnError, HostnameError, parse_length_prefixed_alpn, validate_hostname};
43+
44+
#[cfg(feature = "rustls")]
2645
pub use cert::{DecodedCertificate, decode_certificate, is_ca_certificate};
46+
#[cfg(feature = "rustls")]
2747
pub use connection::{
2848
RecordCursor, SSL3_RT_MAX_PACKET_SIZE, TLS_RECORD_HEADER_SIZE, TlsConnection,
2949
};
30-
pub use constants::*;
50+
#[cfg(feature = "rustls")]
3151
pub use error::TlsError;
32-
pub use protocol::{
33-
AlpnError, HostnameError, parse_length_prefixed_alpn, rustls_versions, validate_hostname,
34-
};
52+
#[cfg(feature = "rustls")]
53+
pub use protocol::rustls_versions;
54+
#[cfg(feature = "rustls")]
3555
pub use providers::CryptoExt;
56+
#[cfg(feature = "rustls")]
3657
pub use session::{
3758
CapturingClientSessionStore, ClientSessionKind, SESSION_CACHE_SIZE, SessionCache, SessionData,
3859
};

crates/host_env/src/ssl/protocol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn validate_hostname(hostname: &str) -> Result<(), HostnameError> {
3939
}
4040

4141
/// Convert PROTO/OP bits into the rustls version slice.
42+
#[cfg(feature = "rustls")]
4243
#[must_use]
4344
pub fn rustls_versions(
4445
minimum: i32,

crates/stdlib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ssl-openssl-vendor = ["ssl-openssl", "openssl/vendored"]
2424
tkinter = ["dep:tk-sys", "dep:tcl-sys", "dep:widestring"]
2525
flame-it = ["flame"]
2626

27-
__ssl-rustls = ["ssl", "rustpython-host_env/ssl", "rustpython-host_env/native-certs", "rustls", "rustls-pemfile", "x509-parser", "pem-rfc7468", "webpki-roots"]
27+
__ssl-rustls = ["ssl", "rustpython-host_env/ssl", "rustpython-host_env/rustls", "rustpython-host_env/native-certs", "rustls", "rustls-pemfile", "x509-parser", "pem-rfc7468", "webpki-roots"]
2828

2929
[dependencies]
3030
# rustpython crates

crates/wasm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ getrandom_02 = { package = "getrandom", version = "0.2", features = ["js"] }
4848
rustls = { workspace = true, default-features = false, features = ["std", "tls12", "custom-provider"] }
4949
rustls-pki-types = { version = "1", default-features = false, features = ["alloc", "std", "web"] }
5050
rustls-rustcrypto = "0.0.2-alpha"
51-
rustpython-host_env = { workspace = true, features = ["ssl"] }
51+
rustpython-host_env = { workspace = true, features = ["rustls"] }
5252

5353
[package.metadata.wasm-pack.profile.release]
5454
wasm-opt = false#["-O1"]

0 commit comments

Comments
 (0)