Skip to content
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

Allows configuring TLS backend #386

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

erickguan
Copy link

Fixes #384.

@dbrgn
Copy link
Collaborator

dbrgn commented Oct 27, 2024

Hm, I wonder if we shouldn't just switch to native roots and call it a day... What's your opinion @niklasmohrin?

@erickguan
Copy link
Author

FYI, the default build uses the native roots.

I didn't change the build default in this PR. I can see some adjustments required and your inputs.

@niklasmohrin
Copy link
Collaborator

@dbrgn I have some thoughts written down in the issue, I think that having the functionality is nice and people can still build it without the bloat by disabling features

Copy link
Collaborator

@niklasmohrin niklasmohrin left a comment

Choose a reason for hiding this comment

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

Thanks! I have some requests regarding the code first, once we have this ironed out I will take a closer look at the documentation. Please feel free to reach out if you have any questions or thoughts :)

Cargo.toml Outdated
@@ -25,7 +25,7 @@ app_dirs = { version = "2", package = "app_dirs2" }
clap = { version = "4", features = ["std", "derive", "help", "usage", "cargo", "error-context", "color", "wrap_help"], default-features = false }
env_logger = { version = "0.11", optional = true }
log = "0.4"
reqwest = { version = "0.12.5", features = ["blocking"], default-features = false }
reqwest = { version = "0.12.5", features = ["blocking", "native-tls", "rustls-tls", "rustls-tls-native-roots", "rustls-tls-webpki-roots"], default-features = false }
Copy link
Collaborator

Choose a reason for hiding this comment

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

I had something else in mind: By disabling the native-roots (etc.) features of tealdeer, we would also disable the features for reqwest here, so that the resulting tealdeer binary is as small as possible.

Copy link
Author

Choose a reason for hiding this comment

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

I see. Fixed. I saw the reqwest 0.12.9 supports additional roots. So I also extended it. What do you think about it?

src/cache.rs Outdated
cache_dir: PathBuf,
enable_styles: bool,
tls_backend: &'a str, // for setting up reqwest client
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should use an enum like so:

enum TlsBackend {
    // ...
}

This way we also avoid the lifetime parameter :)

Copy link
Author

Choose a reason for hiding this comment

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

Of course!

src/config.rs Outdated
Comment on lines 271 to 275
/// Allows choosing a TLS backend supported by `reqwest`. Available TLS backends:
/// # - `native-roots`: Rustls with native roots
/// # - `webpki-roots`: Rustls with `WebPK` roots
/// # - `native-tls`: Native TLS (`SChannel` on Windows, Secure Transport on macOS and OpenSSL otherwise)
/// Read more in `Cargo.toml`
Copy link
Collaborator

Choose a reason for hiding this comment

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

This documentation can then probably move to the definition of the TlsBackend enum

src/cache.rs Outdated
Comment on lines 528 to 532
let _ = Cache::build_client(&Cache {
cache_dir: dir.into_path(),
enable_styles: false,
tls_backend: $backend,
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are not checking whether the returned Result of build_client is Ok here - let's do so

Additionally, I think we can make build_client not take the whole Cache but just the TlsBackend parameter. Then we won't need the tempdir and we can then remove the macro too and write out the three tests

Copy link
Author

Choose a reason for hiding this comment

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

True. Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Configure TLS at runtime
3 participants