Skip to content

Conversation

@digizeph
Copy link
Member

Summary

This PR adds automatic rustls crypto provider initialization to prevent the "Could not automatically determine the process-level CryptoProvider" panic when using HTTPS, S3, or FTP features.

Changes

New Module: crypto

  • Added src/oneio/crypto.rs with ensure_default_provider() function
  • Automatically tries AWS-LC first, then falls back to ring
  • Thread-safe and idempotent implementation
  • Exported publicly via oneio::crypto module

Integration Points

The crypto provider initialization is now called automatically from:

  • get_http_reader_raw() - HTTP/HTTPS requests
  • create_client_with_headers() - Custom HTTP clients
  • get_ftp_reader_raw() - FTP connections
  • s3_bucket() - S3 operations
  • get_content_length() - Content length checks
  • get_async_reader_raw() - Async HTTP operations

Public API

Applications and dependent crates can now explicitly initialize the provider:

oneio::crypto::ensure_default_provider()?;

This is particularly useful for:

  • Early error handling during startup
  • Making crypto provider dependency explicit
  • Testing and debugging

Documentation

  • Updated lib.rs with usage examples and feature documentation
  • Added comprehensive module documentation
  • Created examples/test_crypto_provider.rs demonstrating usage
  • Updated README.md with crypto initialization section
  • Updated CHANGELOG.md

Testing

  • Added unit tests for provider initialization
  • Added test for idempotency
  • All existing tests pass with various feature combinations
  • New example verifies end-to-end functionality

Benefits

  • Zero Configuration: Works automatically without manual setup
  • Flexible: Supports both AWS-LC and ring backends
  • Explicit API: Can be called manually for better control
  • Thread-Safe: Handles concurrent initialization correctly
  • Backward Compatible: No breaking changes to existing code

Use Case for Dependent Crates

Other crates in the BGPKIT ecosystem (bgpkit-commons, peeringdb-rs, asninfo) can now simply call:

oneio::crypto::ensure_default_provider()?;

This ensures whichever crypto provider the dependency tree pulled in (AWS-LC or ring) gets installed automatically, eliminating the panic without forcing a specific provider choice.

Testing

# Test with default features
cargo test

# Test with all features
cargo test --all-features

# Test with https and s3
cargo test --features https,s3

# Run the example
cargo run --example test_crypto_provider --features https

All tests pass successfully.

- Add new crypto module with ensure_default_provider() helper
- Automatically initialize crypto provider in all HTTPS/S3/FTP code paths
- Prefer AWS-LC with automatic fallback to ring
- Thread-safe and idempotent implementation
- Export publicly for use by dependent crates
- Add comprehensive documentation and examples
- Add tests for provider initialization

Fixes the 'Could not automatically determine the process-level
CryptoProvider' panic by ensuring a provider is always installed
before rustls operations, without requiring manual setup.
@digizeph digizeph requested a review from Copilot October 29, 2025 23:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds automatic rustls crypto provider initialization to prevent the "Could not automatically determine the process-level CryptoProvider" panic. The implementation creates a new crypto module with an ensure_default_provider() function that automatically tries to install AWS-LC first, then falls back to ring, and integrates it into all HTTPS/S3/FTP code paths.

Key changes:

  • New crypto module with automatic provider initialization logic
  • Integration of automatic initialization across all HTTPS, S3, and FTP operations
  • Updated Cargo.toml to use sync-rustls-tls for rust-s3
  • Comprehensive documentation and example for explicit initialization

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/oneio/crypto.rs New module implementing crypto provider initialization with AWS-LC and ring fallback
src/oneio/remote.rs Added automatic crypto provider initialization to HTTP and FTP operations
src/oneio/s3.rs Added automatic crypto provider initialization to S3 bucket operations
src/oneio/mod.rs Exposed crypto module and added initialization to content length and async operations
src/lib.rs Exposed crypto module publicly and added documentation
examples/test_crypto_provider.rs New example demonstrating explicit crypto provider initialization
README.md Added documentation for crypto provider initialization
Cargo.toml Updated rust-s3 to use sync-rustls-tls and added example configuration
CHANGELOG.md Documented the new feature and changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

oneio/Cargo.toml

Lines 62 to 109 in 76be0da

rustls_sys = { package = "rustls", version = "0.23", optional = true }
tokio-util = { version = "0.7", optional = true }
[features]
# Simple, flat feature structure
default = ["gz", "bz", "https"]
# Backward compatible `lib-core` feature, no longer default.
lib-core = ["http", "ftp", "gz", "bz", "lz", "xz", "zstd", "json"]
# Transport features (TLS handled automatically by libraries)
http = ["reqwest"]
https = ["http", "rustls"] # https needs http
ftp = ["https", "suppaftp"] # ftp needs https
s3 = ["rust-s3"]
gz = ["gz-zlib-rs"]
# internal feature to enable gzip support
any_gz = []
gz-miniz = ["any_gz", "flate2/miniz_oxide"]
gz-zlib-rs = ["any_gz", "flate2/zlib-rs"]
gz-zlib-ng = ["any_gz", "flate2/zlib-ng"]
gz-zlib-cloudflare = ["any_gz", "flate2/cloudflare_zlib"]
bz = ["bzip2"]
lz = ["lz4"]
xz = ["xz2"]
zstd = ["dep:zstd"]
# Other features
json = ["serde", "serde_json"]
digest = ["ring", "hex"]
# CLI tool (includes common features)
cli = ["clap", "tracing", "gz", "bz", "lz", "xz", "http", "s3", "digest"]
# Advanced: TLS selection (only if explicitly needed)
native-tls = [
"reqwest?/native-tls",
"suppaftp?/native-tls",
"rust-s3?/sync-native-tls",
]
rustls = [
"reqwest?/rustls-tls",
"suppaftp?/rustls",
"rust-s3?/sync-rustls-tls"
]

P1 Badge Wire rustls_sys into TLS features

The new crypto::ensure_default_provider only installs a provider inside #[cfg(feature = "rustls_sys")], but none of the TLS-facing features (https, ftp, s3, or even the rustls feature itself) actually enable the optional rustls_sys dependency in Cargo.toml. With the default feature set (https), the rustls_sys code is compiled out and the function immediately returns Ok(()), so HTTP/S3/FTP calls still hit rustls’ runtime panic about a missing CryptoProvider. To make the automatic initialization effective, the TLS features need to include dep:rustls_sys (or the provider should be installed through a dependency already in scope).

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- Separate format job in CI workflow for faster feedback
- Run cargo fmt to fix trailing whitespace
- Format check now runs independently from compilation/test checks
- Add dep:rustls_sys to rustls feature flag in Cargo.toml
- Change crypto.rs to check feature rustls instead of rustls_sys
- Update remote_file_exists to use ensure_default_provider
- Fix clippy warnings (needless return statements)
- Add GitHub Copilot custom instructions for repository
- Instructions include formatting, clippy, README regeneration rules
Since https enables rustls, ftp enables https (which enables rustls),
and s3 uses rustls transitively, checking for multiple feature flags
is redundant. Simplified all checks to just use rustls feature flag.

- Changed all crypto initialization checks to use only rustls feature
- Removed redundant https/s3/ftp checks alongside rustls
- This makes the code cleaner and easier to maintain
- Document all improvements and fixes in CHANGELOG.md
- Add changelog update rules to Copilot instructions
- Emphasize changelog updates in pre-commit checklist
- Include changelog formatting guidelines
@digizeph digizeph merged commit f27bfcd into main Oct 29, 2025
4 checks passed
@digizeph digizeph deleted the feature/crypto-provider-init branch October 29, 2025 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants