Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

add danger clause for ignoring invalid certificates #2470

Merged
merged 1 commit into from
Apr 17, 2020

Conversation

da-kami
Copy link
Member

@da-kami da-kami commented Apr 16, 2020

fixes #2464

needed to make ether-halight e2e test pass on macOS Catalina.

Questionable if this is a good fix, since it is a security concern.

@mergify
Copy link
Contributor

mergify bot commented Apr 16, 2020

Are you sure the changelog does not need updating?

3 similar comments
@mergify
Copy link
Contributor

mergify bot commented Apr 16, 2020

Are you sure the changelog does not need updating?

@mergify
Copy link
Contributor

mergify bot commented Apr 16, 2020

Are you sure the changelog does not need updating?

@mergify
Copy link
Contributor

mergify bot commented Apr 16, 2020

Are you sure the changelog does not need updating?

@da-kami da-kami requested a review from rishflab April 16, 2020 09:20
Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

As this only happens on MacOS, can we do this under a conditional-compilation flag for macos?

Also a comment in the code would be good to explain the problem and possible link a ticket that we can watch for resolution.

@da-kami da-kami force-pushed the lnd-certificate-mac-fix branch from c9919e6 to 4071fa4 Compare April 16, 2020 09:29
@da-kami
Copy link
Member Author

da-kami commented Apr 16, 2020

As this only happens on MacOS, can we do this under a conditional-compilation flag for macos?

@thomaseizinger I duplicated the function and added conditionals. Is that what you had in mind, or should I rather us https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-macro ?

@thomaseizinger
Copy link
Contributor

As this only happens on MacOS, can we do this under a conditional-compilation flag for macos?

@thomaseizinger I duplicated the function and added conditionals. Is that what you had in mind, or should I rather us doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-macro ?

Yes that is what I meant although I would have probably only applied to the particular line like this:

let mut builder = reqwest::Client::builder().add_root_certificate(cert).default_headers(default_headers);

#[cfg(target_os = "macos")]
{
	// a very long and good comment on what is happening and why we need this
    builder.danger_accept_invalid_certs(true);
}

builder.build()?

@da-kami
Copy link
Member Author

da-kami commented Apr 16, 2020

As this only happens on MacOS, can we do this under a conditional-compilation flag for macos?

@thomaseizinger I duplicated the function and added conditionals. Is that what you had in mind, or should I rather us doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-macro ?

Yes that is what I meant although I would have probably only applied to the particular line like this:

let mut builder = reqwest::Client::builder().add_root_certificate(cert).default_headers(default_headers);

#[cfg(target_os = "macos")]
{
	// a very long and good comment on what is happening and why we need this
    builder.danger_accept_invalid_certs(true);
}

builder.build()?

@thomaseizinger unfortunately that cannot be changed that easy. running into lifetime (use of moved value...) with the builder when doing this.

@da-kami
Copy link
Member Author

da-kami commented Apr 16, 2020

Seems there is an additional problem with the lnd_sanity test.
Not sure how and if this is related. Gonna look into it tomorrow.
Locally lnd_sanity is passing - all e2e tests green 🤷‍♂️

Copy link
Contributor

@D4nte D4nte left a comment

Choose a reason for hiding this comment

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

Please custom block size + add explanatory comment.

cnd/src/swap_protocols/halight/connector.rs Outdated Show resolved Hide resolved
@D4nte
Copy link
Contributor

D4nte commented Apr 17, 2020

Also, what was the result of trying with rustls-tls? Looks like you have to pass .use_rustls_tls() on the client Builder to force its use.

@da-kami
Copy link
Member Author

da-kami commented Apr 17, 2020

Also, what was the result of trying with rustls-tls? Looks like you have to pass .use_rustls_tls() on the client Builder to force its use.

#2464 (comment)

I did try fixing it with rustls-tls first, but was not able to. The fix would have had similar behaviour (ignore validation) as the one on native-tls.

needed to make e2e test pass on macOS Catalina
@da-kami da-kami force-pushed the lnd-certificate-mac-fix branch from 4071fa4 to 9735d3f Compare April 17, 2020 01:29
@da-kami da-kami requested review from D4nte and thomaseizinger April 17, 2020 01:31
Comment on lines +453 to +464
#[cfg(target_os = "macos")]
let client = reqwest::Client::builder()
.danger_accept_invalid_certs(true)
.add_root_certificate(cert)
.default_headers(default_headers)
.build()?)
.build()?;

#[cfg(not(target_os = "macos"))]
let client = reqwest::Client::builder()
.add_root_certificate(cert)
.default_headers(default_headers)
.build()?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I hope it is not too much bike-shedding but I found this: https://doc.rust-lang.org/std/macro.cfg.html

So I think we could do:

// The generated, self-signed lnd certificate is deemed invalid on macOS
// Catalina because of new certificate requirements in macOS Catalina: https://support.apple.com/en-us/HT210176
// By using this conditional compilation step for macOS we accept invalid
// certificates. This is only a minimal security risk because by default the
// certificate that lnd generates is configured to only allow connections
// from localhost. Ticket that will resolve that issue: https://github.com/lightningnetwork/lnd/issues/4201
let accept_invalid_certificates = if cfg!(target_os = "macos") {
	true
} else {
	false
};    

let client = reqwest::Client::builder()
	.danger_accept_invalid_certs(accept_invalid_certificates)
    .add_root_certificate(cert)
    .default_headers(default_headers)
    .build()?;

Copy link
Contributor

Choose a reason for hiding this comment

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

Up to you if you like it better :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Where is the 🚲🏠 comment reaction when we need it?

Copy link
Member Author

Choose a reason for hiding this comment

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

beautiful, but saw it too late. Feel free to push a follow up :)

@mergify
Copy link
Contributor

mergify bot commented Apr 17, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Apr 17, 2020

@bors bors bot merged commit 09b580b into dev Apr 17, 2020
@mergify mergify bot deleted the lnd-certificate-mac-fix branch April 17, 2020 02:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LN problem: certificate invalid
3 participants