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

Add TLS version option #1655

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions lychee-bin/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub(crate) fn create(cfg: &Config, cookie_jar: Option<&Arc<CookieStoreMutex>>) -
.accepted(accepted)
.require_https(cfg.require_https)
.cookie_jar(cookie_jar.cloned())
.min_tls_version(cfg.min_tls.clone().map(Into::into))
.include_fragments(cfg.include_fragments)
.fallback_extensions(cfg.fallback_extensions.clone())
.build()
Expand Down
36 changes: 35 additions & 1 deletion lychee-bin/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use lychee_lib::{
StatusCodeSelector, DEFAULT_MAX_REDIRECTS, DEFAULT_MAX_RETRIES, DEFAULT_RETRY_WAIT_TIME_SECS,
DEFAULT_TIMEOUT_SECS, DEFAULT_USER_AGENT,
};
use reqwest::tls;
use secrecy::{ExposeSecret, SecretString};
use serde::Deserialize;
use std::path::Path;
Expand Down Expand Up @@ -46,6 +47,34 @@ const HELP_MSG_CONFIG_FILE: &str = formatcp!(
const TIMEOUT_STR: &str = concatcp!(DEFAULT_TIMEOUT_SECS);
const RETRY_WAIT_TIME_STR: &str = concatcp!(DEFAULT_RETRY_WAIT_TIME_SECS);

#[derive(Debug, Display, Deserialize, Default, Clone, EnumString)]
#[non_exhaustive]
pub(crate) enum TlsVersion {
#[serde(rename = "TLSv1_0")]
#[strum(serialize = "TLSv1_0")]
V1_0,
#[serde(rename = "TLSv1_1")]
#[strum(serialize = "TLSv1_1")]
V1_1,
#[serde(rename = "TLSv1_2")]
#[strum(serialize = "TLSv1_2")]
#[default]
V1_2,
#[serde(rename = "TLSv1_3")]
#[strum(serialize = "TLSv1_3")]
V1_3,
}
impl From<TlsVersion> for tls::Version {
fn from(ver: TlsVersion) -> Self {
match ver {
TlsVersion::V1_0 => tls::Version::TLS_1_0,
TlsVersion::V1_1 => tls::Version::TLS_1_1,
TlsVersion::V1_2 => tls::Version::TLS_1_2,
TlsVersion::V1_3 => tls::Version::TLS_1_3,
}
}
}

/// The format to use for the final status report
#[derive(Debug, Deserialize, Default, Clone, Display, EnumIter, VariantNames, PartialEq)]
#[non_exhaustive]
Expand Down Expand Up @@ -240,7 +269,7 @@ pub(crate) struct Config {
long,
default_value_t = FileExtensions::default(),
long_help = "Test the specified file extensions for URIs when checking files locally.

Multiple extensions can be separated by commas. Note that if you want to check filetypes,
which have multiple extensions, e.g. HTML files with both .html and .htm extensions, you need to
specify both extensions explicitly."
Expand Down Expand Up @@ -317,6 +346,11 @@ list of excluded status codes. This example will not cache results with a status
#[serde(default = "max_retries")]
pub(crate) max_retries: u64,

// Minimum TLS Version
#[arg(long)]
#[serde(default)]
pub(crate) min_tls: Option<TlsVersion>,

/// Maximum number of concurrent network requests
#[arg(long, default_value = &MAX_CONCURRENCY_STR)]
#[serde(default = "max_concurrency")]
Expand Down
9 changes: 8 additions & 1 deletion lychee-lib/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use http::{
use log::{debug, warn};
use octocrab::Octocrab;
use regex::RegexSet;
use reqwest::{header, redirect};
use reqwest::{header, redirect, tls};
use reqwest_cookie_store::CookieStoreMutex;
use secrecy::{ExposeSecret, SecretString};
use typed_builder::TypedBuilder;
Expand Down Expand Up @@ -192,6 +192,9 @@ pub struct ClientBuilder {
#[builder(default = DEFAULT_MAX_RETRIES)]
max_retries: u64,

/// Minimum accepted TLS version.
min_tls_version: Option<tls::Version>,

/// User-agent used for checking links.
///
/// Defaults to [`DEFAULT_USER_AGENT`].
Expand Down Expand Up @@ -352,6 +355,10 @@ impl ClientBuilder {
builder = builder.cookie_provider(cookie_jar);
}

if let Some(min_tls) = self.min_tls_version {
builder = builder.min_tls_version(min_tls);
}

let reqwest_client = match self.timeout {
Some(t) => builder.timeout(t),
None => builder,
Expand Down
Loading