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

[DRAFT] Fix #214: Separate user cert-chain from PKCS#8 key #215

Merged
merged 2 commits into from
Feb 5, 2024

Conversation

ljrk0
Copy link
Contributor

@ljrk0 ljrk0 commented Nov 28, 2023

This adds a new config option sasl.external.key which is required to properly support SASL External using PKCS#8. PKCS#8 is a format that's used exclusively for keys and not user-certs. As such, when using from_pkcs8() from native-tls, both a user-cert (in PEM) and the PKCS#8 key must be provided. This was implemented before through one file which contained both the PKCS#8 key and the user-cert, concatenated. Strict implementations will either complain about the key-file containing certificates, vice-versa or duplicate certificates: since "both" the key-file and cert-file contain the same certificates due to being identical.

The code is probably not ideal, e.g.,

  1. the external_cert and external_key functions could possibly be merged, or
  2. the fields client_cert_path and client_key_path in Security be wrapped as a tuple (client_cert_path, client_key_path) with similar changes
  3. there could be support for combined PKCS#8 key files + PEM cert chains, as well as
  4. support for PKCS#12 combined identity files.

Further, the documentation in the Wiki linking to Libera may need to be updated.

@casperstorm
Copy link
Member

casperstorm commented Nov 30, 2023

@tarkah could you take a look at this? 👀
Relevant issue: #214.

@casperstorm casperstorm requested a review from tarkah November 30, 2023 11:44
@ljrk0 ljrk0 marked this pull request as draft December 1, 2023 15:48
Copy link
Member

@tarkah tarkah left a comment

Choose a reason for hiding this comment

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

Sorry for the delay on this, thank you for the PR! After reviewing things further, the change makes sense.

I'd like to see us not break backwards compatibility however. See my other comment.

Comment on lines 135 to 141
fn external_key(&self) -> Option<&PathBuf> {
if let Self::External { key, .. } = self {
Some(key)
} else {
None
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we make key an Option and return cert path here if key is none? This way we preserve backwards compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, sure can do! Just to make sure I understand correctly:

The function external_key is currently already returning an Option, so what you're suggesting is to do another fallback check like this?

- } else {
+ else if let Self::External { cert, .. } = self {
+    return Some(cert) //fallback
+ } else {
      return None
  }

I'm currently mostly worried about odd error cases arising from this, when people use the same config from Linux to macOS/Windows and getting weird error messages -- but I don't have any better idea.

Copy link
Member

Choose a reason for hiding this comment

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

I've implemented this patch on top of your work and confirmed it:

  • Works w/ previous config (only cert defined w/ cert+key combined file)
  • Works w/ separate cert + key files / entries in config

I'm not sure how to advise people on this, other than maybe we update our wiki? At least we don't have breakage for users migrating to this newer patched version and now support separately defined cert / keys for "proper" usage, which ideally people migrate to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, sorry for being MIA for some time! Sounds great!

Yeah, I was wondering whether one could add some more checking, because it'd be a weird error-case to have a config that works on Linux but you use it on macOS and it breaks (with weird TLS errors, too). Ideally, maybe one could issue a warning for combined files, going forward?

@tarkah tarkah marked this pull request as ready for review February 5, 2024 17:55
@tarkah tarkah merged commit 8b3a6b9 into squidowl:main Feb 5, 2024
1 check passed
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