-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
feat(common.tls): Add support for passphrase-protected private key #13262
Conversation
The encrypted private key file is in the `testutil/pki` dir is `clientenckey.pem`. However the `tls-certs.sh` script and `pki.ClientEncKeyPath()` refered to it as `clientkeyenc.pem`. This patch makes the filename consistent (`clientenckey.pem`) across all those places.
…ate key This patch adds support for handling an PEM-encoded encrypted private key in the pkcs#1 format and the more general & recommended pkcs#8 (using a pkcs#5 v2.0 encryption standard). Fixes influxdata#12932
This also makes golangci-lint happier! :yay:
… x509.DecryptPEMBlock
fa044be
to
c73c01f
Compare
@powersj This PR is ready for review. Please let me know if there is any feedback or changes you'd like me to make to this pull request. I'm happy to discuss any suggestions you might have. |
Hi Rajiv
|
@allej Thanks for the confirmation! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates - one final comment about a test case, then this should be ready for final review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution @rajiv-k! Just a few minor comments...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rajiv-k can you please switch to the implicit declaration for certBytes
, keyBytes
and err
!? Furthermore, please declare var cert tls.Certificate
immediately before it is assigned in order to avoid unintended read-before-set cases.
@rajiv-k can you please check the implicit declaration?!? |
Download PR build artifacts for linux_amd64.tar.gz, darwin_amd64.tar.gz, and windows_amd64.zip. 🥳 This pull request decreases the Telegraf binary size by -5.62 % for linux amd64 (new size: 175.1 MB, nightly size 185.5 MB) 📦 Click here to get additional PR build artifactsArtifact URLs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adapted the variable declaration, so I'm fine with the code now. Thanks a lot for your work and contribution @rajiv-k!
@srebhan Thanks for taking care of this while I was away on vacation 👍 |
Required for all PRs
I have implemented the feature using https://github.com/youmark/pkcs8 because the go stdlib lacks support for parsing encrypted PKCS8 private keys (golang/go#8860).
Note: When storing encrypted Private Keys in PKCS#8 format, a number of PKCS#5 v1.5, PKCS#5 v2.0 and PKCS#12 can be used to generate the encryption key from the provided passphrase.
However, this library can only handle the more modern and recommended PKCS#5 v2.0.
This fix itself seems to be working well. I was able to use this in two different plugins,
influxdb_v2
andamqp_consumer
which were both configured with client certificate authentication and had an encrypted private key.resolves #12932