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

Support certificate chains #13

Merged
merged 2 commits into from
Jun 21, 2022
Merged

Support certificate chains #13

merged 2 commits into from
Jun 21, 2022

Conversation

litch
Copy link
Contributor

@litch litch commented Jun 17, 2022

This is a partial solution to #11, but does not address #1 at all.

I'm having a bit of an issue with root certs, but don't think it should be far off.

return Err(TLSError::General(format!("server certificates do not match ours")));
} else {
tracing::trace!("Confirmed certificate match");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't strictly need this message, but I kind of like having it for sanity checking.

Copy link
Owner

@Kixunil Kixunil 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 the PR!

If I understand correctly, this doesn't do normal PKI verification just supports multiple certificates where those must be also in a file. I think the idea is acceptable&useful but there's at least one bug: the lengths of chains are not compared in verify_server_cert, so the comparison can return true even for different lengths - very likely a vulnerability.

if presented_certs[0].0 != self.cert {
return Err(TLSError::General(format!("server certificates doesn't match ours")));

for (c, p) in self.certs.iter().zip(presented_certs.iter()) {
Copy link
Owner

Choose a reason for hiding this comment

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

Lengths should be compared before the loop and return error if they aren't equal. Please mention both lengths in error message.

src/lib.rs Outdated
|error| InternalConnectError::ParseCert { file: path.into(), error });

if certs.len() != 1 {
return Err(InternalConnectError::InvalidCertCount { file: path.into(), count: certs.len(), });
tracing::debug!("Certificate count is not 1 (Actual Count: {})", certs.len());
Copy link
Owner

Choose a reason for hiding this comment

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

Unconditional debug with message "Loaded certificate chain with {} certificates" (or similar) would be better since we don't treat 1 as special.

Could you also remove InvalidCertCount from InternalConnectError? It's not used anymore.

src/lib.rs Outdated
Ok(ServerCertVerified::assertion())
}
}
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

Nit: please don't remove newlines at the end of file.

src/lib.rs Outdated
@@ -129,6 +130,10 @@ async fn load_macaroon(path: impl AsRef<Path> + Into<PathBuf>) -> Result<String,
///
/// If you have a motivating use case for use of direct data feel free to open an issue and
/// explain.
#[tracing::instrument(
name = "Connecting to LND",
skip(address, cert_file, macaroon_file),
Copy link
Owner

Choose a reason for hiding this comment

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

These shouldn't be sensitive if that's the reason why you skip them. (macaroon_file is just a path and on a correctly configured system it's only accessible by authorized users)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was actually skipping them because they did not implement debug as they were coming in, rather than them being sensitive. =)

Cargo.toml Outdated
@@ -22,6 +22,7 @@ webpki = "0.21.3"
rustls-pemfile = "1.0.0"
hex = "0.4.3"
tokio = { version = "1.7.1", features = ["fs"] }
tracing = { version = "0.1", features = ["log"] }
Copy link
Owner

Choose a reason for hiding this comment

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

Do you happen to know how much this prolongs compile times? If yes would it be worth it to make it optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know. And I'm not exactly certain how to make it optional. =/

I'm actually 100% happy to pull the tracing out of here. It seems like something it should have but me just shoving it in to do some small changes is probably not ideal. It would be better if it were done everywhere and consistently.

Copy link
Owner

Choose a reason for hiding this comment

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

Thinking about it, tracing has MSRV 1.49 which could become annoying since I want MSRV 1.48 so yeah, making it optional in a separate PR would be the best appraoch.

Making it optional should be very easy, just set optional = true in Cargo.toml and then use `#[cfg_attr(feature = "tracing", tracing::instrument(...))] for attributes and

#[cfg(feature = "tracing")]
{
    tracing::trace!("message");
}

for logs in the code.

@litch
Copy link
Contributor Author

litch commented Jun 17, 2022

Thanks for the super quick feedback. Here's another pass.

Again - super happy to pull all the tracing stuff if you'd prefer.

@Kixunil
Copy link
Owner

Kixunil commented Jun 18, 2022

Looks good! Could you please squash the commits? Or if you like make it two commits, one adding tracing, the other doing the rest.

@litch
Copy link
Contributor Author

litch commented Jun 20, 2022

Thanks - I added tracing before the actual changes because the logs were kind of intertwined with the cert checks.

Copy link
Owner

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

Please fix the MSRV issue.

src/lib.rs Outdated Show resolved Hide resolved
@Kixunil Kixunil merged commit aad0081 into Kixunil:master Jun 21, 2022
@Kixunil
Copy link
Owner

Kixunil commented Jun 21, 2022

Thanks a lot!

douglaz pushed a commit to orbitalturtle/tonic_lnd that referenced this pull request Dec 14, 2023
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.

2 participants