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

Search cert file and dir returned by openssl-probe #109

Merged
merged 5 commits into from
Jul 2, 2024
Merged

Conversation

pgerber
Copy link
Contributor

@pgerber pgerber commented Jun 7, 2024

Fixes #28

@pgerber pgerber force-pushed the freebsd branch 4 times, most recently from b8bc610 to 0266775 Compare June 7, 2024 16:47
Copy link
Member

@djc djc 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 your work on improving rustls-native-certs!

Unfortunately in its current form this PR is quite hard to review. When we merge code we like make sure the PR consists of a series of well-defined changes, whereas this PR contains a bunch of changes all squashed together. Please read through https://github.com/rustls/rustls/blob/main/CONTRIBUTING.md for more guidance.

In particular, it would be good to avoid moving existing code around in the same commit as adding a bunch of new code, it would be good to split out addition of documentation for existing code from any other changes (in a separate commit). Then, further commits that change the behavior should update the documentation.

It would also be good to add a PR description that briefly describes which conceptual changes you're trying to make here.

@pgerber
Copy link
Contributor Author

pgerber commented Jun 14, 2024

So, the change should now be in a more reviewable state. I wonder if I'm just too used to people squashing commits and using commit message like "fixes #NNN". I should remind myself more often to work with small, digestible commits, even found I few issues splitting things down into pieces.

Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

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

Much easier to review, thanks! Here's an initial round of feedback.

tests/smoketests.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/unix.rs Outdated Show resolved Hide resolved
Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

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

Nice work! I had a handful of nits but I think the substance of the work is on the right track 👍

src/lib.rs Outdated Show resolved Hide resolved
tests/smoketests.rs Outdated Show resolved Hide resolved
tests/smoketests.rs Outdated Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/unix.rs Outdated Show resolved Hide resolved
tests/smoketests.rs Outdated Show resolved Hide resolved
Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

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

I started reviewing the branch, but it seems like most of the resolved feedback isn't present. Is it possible you pushed the wrong branch?

I will pick up my re-review once that's sorted. Thanks!

src/lib.rs Outdated Show resolved Hide resolved
tests/smoketests.rs Outdated Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@pgerber
Copy link
Contributor Author

pgerber commented Jun 21, 2024

@cpu, updated commits will follow soon. I'm afraid I had to leave before I managed to do a final review before pushing the changes.

@pgerber pgerber force-pushed the freebsd branch 2 times, most recently from 5958180 to e4fa787 Compare June 22, 2024 09:40
tests/smoketests.rs Outdated Show resolved Hide resolved
Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

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

Thanks, looks good to me 🚀

src/lib.rs Show resolved Hide resolved
Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

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

Looking good, some hopefully minor feedback left.

tests/smoketests.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated
@@ -63,7 +63,9 @@ const ENV_CERT_FILE: &str = "SSL_CERT_FILE";
/// Returns None if SSL_CERT_FILE is not defined in the current environment.
///
/// If it is defined, it is always used, so it must be a path to a real
/// file from which certificates can be loaded successfully.
/// file from which certificates can be loaded successfully. However,
Copy link
Member

Choose a reason for hiding this comment

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

I'd skip the "However" here, which doesn't seem entirely appropriate? Maybe rephrase as:

While parsing, [rustls_pemfile::certs()] parser will ignore parts of the file which are not part of a certificate.

Copy link
Contributor Author

@pgerber pgerber Jun 26, 2024

Choose a reason for hiding this comment

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

"However" I chose because I'm trying to say certificate loading needs to be successful but the fact that parts of the file may be ignored (e.g. because the wrong certificate format is used or a certificate is corrupted) can mean that we report success/Ok(_) when really the certificate failed to parse, at least from a user's perspective.

What about this:

While parsing, [rustls_pemfile::certs()] parser will ignore parts of the file which are not considered part of a certificate. Certificates which are not in the right format (PEM) or are otherwise corrupted may get ignored silently.

I also wonder if this should we document this in the public part of the documentation too. Perhaps we could clarify what format is expected to make it less likely people will use the wrong format. Something like:

Be sure certificates are in PEM format. Example:

<insert example cert in PEM format>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's an error and what's ignored seems a bit arbitrary to me.

This is ignored

----BEGIN CERTIFICATE-----
^ missing '-' at start
<content>
-----END CERTIFICATE-----

This is an error:

-----BEGIN CERTIFICATE-----
<content>
-----END CERTIFICATE----
                        ^ missing '-'

This is ignored:

-----BEGIN CERTIFICATE-----
<content>
-----END CERTIFICATE----
                        ^ missing '-' AND '\n'

This is ignore:

-----BEGIN CERTIFICATE-----
<content>
-----END CERTIFICATE-----
                         ^ missing '\n'

Copy link
Member

Choose a reason for hiding this comment

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

I think we'd probably take PRs to make all of those errors, but the main goal in that crate was to properly ignore things that don't look like PEM objects at all which has been sighted in the wild. I guess these cases really haven't shown up.

All of your documentation suggestions sound good to me!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Still pending)

Copy link
Contributor Author

@pgerber pgerber Jul 2, 2024

Choose a reason for hiding this comment

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

PEM appears to use the encoding defined in RFC7468. Ignoring invalid sections of the file is part of the encoding but, if I read the grammar right, the line feed at the end of -----END CERTIFICATE----- is explicitly optional in "lax mode". So, perhaps it should be made optional in RusTLS parser too. I'm not sure.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for looking into that! Would be good to file a followup issue and/or PR for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added it to my todo list.

Cargo.lock Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
tests/compare_mozilla.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
pgerber added 5 commits July 2, 2024 09:12
Avoid catching panic without truly knowing what kind of error
caused it. There could have been an network error or an error
loading certificates triggering a panic. (Unlikely with the
current test but there is more tests for failure conditions
coming.)
• Add test to make this explicit.
• Update (private) documentation to match status quo.
• Change wording of (private) documentation. I find "real" to be an
  ambiguous description. It could for instance be interpreted to mean
  it needs to be what Unix calls regular file (as opposed to a symlink,
  FIFO, etc.)
• Add tests to show that file must exists but may be a non-regular
  file.
• On Unix, certificates were loaded from the OpenSSL certificate
  store but only the file based-certificate store (known as CAfile)
  in OpenSSL. Load certs from dir-based store too (CAdir).
• On all platforms, accept new SSL_CERT_DIR, which is also accepted
  by OpenSSL.
Cargo sets these env. vars. internally, at least here, on Linux:

$ cargo init --bin env-conflict
$ cd env-conflict
$ cat >src/main.rs <<EOF
fn main() {
    let _ = dbg!(std::env::var("SSL_CERT_FILE"));
    let _ = dbg!(std::env::var("SSL_CERT_DIR"));
}
EOF
$ cargo -q run
[src/main.rs:2:13] std::env::var("SSL_CERT_FILE") = Ok(
    "/usr/lib/ssl/cert.pem",
)
[src/main.rs:3:13] std::env::var("SSL_CERT_DIR") = Ok(
    "/usr/lib/ssl/certs",
)
@djc djc added this pull request to the merge queue Jul 2, 2024
@djc
Copy link
Member

djc commented Jul 2, 2024

Thanks for all your work on this! Will do a follow-up which bumps the version and has some very minor tweaks.

Merged via the queue into rustls:main with commit db8ed40 Jul 2, 2024
14 checks passed
@djc djc mentioned this pull request Jul 2, 2024
@pgerber
Copy link
Contributor Author

pgerber commented Jul 5, 2024

@djc, @cpu, thanks for making this pull request a pleasant experience.

@cpu
Copy link
Member

cpu commented Jul 5, 2024

My pleasure :-) Thanks again for the contribution!

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.

FreeBSD certs not found
3 participants