Skip to content

Allow for TLS certificate checks to be skipped#224

Open
19h wants to merge 1 commit into
Luminarys:masterfrom
19h:master
Open

Allow for TLS certificate checks to be skipped#224
19h wants to merge 1 commit into
Luminarys:masterfrom
19h:master

Conversation

@19h
Copy link
Copy Markdown

@19h 19h commented Oct 24, 2021

Allows user to skip TLS certificate checks when connecting to trackers.

Rationale:

When seeding exclusively to private trackers, trust is generally higher than with public trackers. LetsEncrypt certificates expire every three months and require operators to intervene. This disrupts the torrent infrastructure unnecessarily.

Proposal:

Add new verify_certificates switch to the tracker-specific configuration, which defaults to true, but if set to false, configures SStream to use a rustls verifier that skips the server authentication.

Copy link
Copy Markdown
Contributor

@evanrichter evanrichter left a comment

Choose a reason for hiding this comment

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

I personally like this PR, but I think it needs a few changes before merging (just my opinion, I'm not a maintainer)

I like having the option to skip TLS cert checking, but the option needs to be safe by default, and variable naming should be consistent and straight forward.

Comment thread sstream/src/lib.rs Outdated
impl Default for SStreamConfig {
fn default() -> Self {
SStreamConfig {
tls_check_certificates: false,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The default should definitely be to enforce certificate checking...

I think that may be what's happening here, but the wording is super confusing.

I would expect tls_check_certificates to be true if certificates are going to be checked...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch, I originally had this variable called 'skip_certificate_check' and didn't exactly invert the default here.

Comment thread sstream/src/lib.rs Outdated
if let Some(config) = config {
config.tls_check_certificates
} else {
false
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

again, I think the variable wording is opposite what I expect, and a cursory code review would suggest that the service does not check certs by default

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Same as above

Comment thread sstream/src/lib.rs
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);

if !tls_check_certificates {
tls_config.client_auth_cert_resolver = Arc::new(NoVerifyTLS);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm honestly confused again what this variable does and what it's default behavior is. My understanding is that this variable is by default false and therefore NoVerifyTLS is by default the configuration. If that is the case, then I suggest:

  1. leave the variable name as is
  2. make the variable true by default
  3. make all default configurations check the certificate by default

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fully agree that strict checks should be the default.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yes, we definitely want this true by default. Thanks for updating.

Comment thread sycli/src/client.rs
"ws" => {
if addr.is_ipv4() {
SStream::new_v4(None)
SStream::new_v4(None, None)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not always the case that connecting to the server over plaintext means that certificates should not be enforced. I run synapse on my local network, so I use HTTP, but I still want certs enforced by default.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think a nice feature (though doesn't have to be done now) would be adding a flag which enables skipping tls verification in sycli now. This seems like it's going to enforce by default which should be ok.

Comment thread sstream/Cargo.toml

[dependencies]
rustls = "0.18.0"
rustls = { version = "0.19", features = ["default", "dangerous_configuration"] }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you might not need the dangerous_configuration feature since you don't call rustls::client::ClientConfig::dangerous()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Unfortunately ServerCertVerifier is only exported with this feature enabled: https://github.com/rustls/rustls/blame/0f17531c6fb898e564c7d6ffbfec183ce66db508/rustls/src/lib.rs#L377-L381.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah I missed that, agreed!

@19h
Copy link
Copy Markdown
Author

19h commented Oct 24, 2021

@evanrichter thanks for the review!

Copy link
Copy Markdown
Owner

@Luminarys Luminarys left a comment

Choose a reason for hiding this comment

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

Thanks for making this change! And thanks for the review @evanrichter. Just a couple minor things and I think it can be merged.

Comment thread sstream/src/lib.rs
) -> SStreamConfig {
SStreamConfig {
tls_check_certificates: tls_no_verify,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can we remove this empty line?

Comment thread sstream/src/lib.rs
let mut config = rustls::ClientConfig::new();
config
let tls_check_certificates =
if let Some(config) = config {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Let's convert this to an optional mapping, so something like config.map(|config| config.tls_check_certificates).unwrap_or(true);

Comment thread sstream/src/lib.rs
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);

if !tls_check_certificates {
tls_config.client_auth_cert_resolver = Arc::new(NoVerifyTLS);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yes, we definitely want this true by default. Thanks for updating.

Comment thread sycli/src/client.rs
"ws" => {
if addr.is_ipv4() {
SStream::new_v4(None)
SStream::new_v4(None, None)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think a nice feature (though doesn't have to be done now) would be adding a flag which enables skipping tls verification in sycli now. This seems like it's going to enforce by default which should be ok.

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