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 --ssl option for forcing a TLS version #168

Merged
merged 6 commits into from
Nov 14, 2021

Conversation

blyxxyz
Copy link
Collaborator

@blyxxyz blyxxyz commented Aug 7, 2021

Resolves #120.

@blyxxyz blyxxyz marked this pull request as draft August 7, 2021 20:23
@blyxxyz
Copy link
Collaborator Author

blyxxyz commented Aug 7, 2021

---- bad_tls_version_nativetls stdout ----
thread 'bad_tls_version_nativetls' panicked at 'Unexpected success
command=`"D:\\a\\xh\\xh\\target\\x86_64-pc-windows-msvc\\debug\\xh.exe" "--ssl=tls1.1" "--native-tls" "https://tls-v1-2.badssl.com:1012/"`
code=0
stdout=```"HTTP/1.1 200 OK [...]

I'm guessing this is a bug in native-tls's max_protocol_version() on Windows. Might end up disabling the test and printing a warning (on Windows).

src/cli.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/cli.rs Outdated Show resolved Hide resolved
src/main.rs Show resolved Hide resolved
@sorairolake
Copy link
Contributor

If possible, I think it's better to add TLS 1.1 or less to possible_values only when native-tls is enabled.

@ducaale
Copy link
Owner

ducaale commented Oct 29, 2021

If possible, I think it's better to add TLS 1.1 or less to possible_values only when native-tls is enabled.

@sorairolake It should be possible via the cfg_attr attribute

    /// Force a particular TLS version.
    ///
    /// "auto" or "ssl2.3" gives the default behavior of negotiating a version
    /// with the server.
    #[cfg_attr(feature = "native-tls", structopt(long, value_name = "VERSION", parse(from_str = parse_tls_version), possible_values = &["auto", "ssl2.3", "tls1", "tls1.1", "tls1.2", "tls1.3"]))]
    #[cfg_attr(not(feature = "native-tls"), structopt(long, value_name = "VERSION", parse(from_str = parse_tls_version), possible_values = &["auto", "ssl2.3", "tls1.2", "tls1.3"]))]
    // An explicit path to Option disables structopt magic we don't want here
    pub ssl: std::option::Option<tls::Version>,

@blyxxyz
Copy link
Collaborator Author

blyxxyz commented Nov 14, 2021

If possible, I think it's better to add TLS 1.1 or less to possible_values only when native-tls is enabled.

You get a more confusing error message that way, so I'd rather not.

@blyxxyz blyxxyz marked this pull request as ready for review November 14, 2021 17:35
src/to_curl.rs Outdated Show resolved Hide resolved
cmd.push("--tls-max");
cmd.push("1.3");
}
_ => unreachable!(),
Copy link
Owner

Choose a reason for hiding this comment

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

I think If we used our own enum for representing TLS versions, we could have avoided the catch-all arm here plus the Option<std::option::Option> hack. What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we do it like that then we need extra effort to ignore TlsVersion::Auto. So I'm not sure it'd end up cleaner overall.

Copy link
Owner

@ducaale ducaale left a comment

Choose a reason for hiding this comment

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

LGTM

@ducaale ducaale merged commit e72e17c into ducaale:develop Nov 14, 2021
@blyxxyz blyxxyz deleted the tls-version branch November 14, 2021 19:07
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.

3 participants