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

Allow PKCS8 EC private keys to be loaded #61

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tsaarni
Copy link
Contributor

@tsaarni tsaarni commented Sep 15, 2022

This change makes it possible to use EC (elliptic curve) private keys as client credentials.

Depends on jruby/jruby-openssl#267. Without that fix being applied, this change has no effect. This is now released.


Part of elastic/logstash#15236

@tsaarni
Copy link
Contributor Author

tsaarni commented Sep 15, 2022

Tests do not work anymore with current logstash version because of #51.

@andsel
Copy link
Contributor

andsel commented Sep 11, 2023

@tsaarni please rebase this to main to align with latest changes 🙏

@tsaarni
Copy link
Contributor Author

tsaarni commented Sep 13, 2023

@tsaarni please rebase this to main to align with latest changes 🙏

Done!

Copy link
Contributor

@andsel andsel left a comment

Choose a reason for hiding this comment

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

Left a comment given that #62 add TLS test harness.

@@ -238,7 +238,7 @@ def setup_ssl
require "openssl"
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.cert = OpenSSL::X509::Certificate.new(File.read(@ssl_cert))
ssl_context.key = OpenSSL::PKey::RSA.new(File.read(@ssl_key),@ssl_key_passphrase)
ssl_context.key = OpenSSL::PKey::read(File.read(@ssl_key),@ssl_key_passphrase)
Copy link
Contributor

Choose a reason for hiding this comment

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

@given that you have added all the TLS test scaffolding in #62 do you think that, after the merge on main branch of that PR and rebase of this, could we add 2 tests here, one for RSA key and the other for Elliptic Cryptography here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes absolutely, let's do that.

Copy link
Contributor Author

@tsaarni tsaarni Sep 14, 2023

Choose a reason for hiding this comment

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

The diff looks bit confusing, but this is what was done:

I added RSA and EC test but at the same time I needed to remove test for invalid client private key, which was previously added in TLS tests. I now realized that OpenSSL::PKey::read() does not raise error when given invalid PEM file, unlike OpenSSL::PKey::RSA.new did. Instead, it returns instance of OpenSSL::PKey::RSA even though invalid.pem clearly is not an RSA key.

When I fixed support for EC pkey to PKey::read() in jruby-openssl, I did not check this. Maybe it lacks negative checks.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that it worthwhile to open an issue in https://github.com/jruby/jruby-openssl repository, accepting silently an improper file is misleading.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my test case I used input that does not even have valid PEM block inside, so I would have expected that even PEM block parsing should fail here https://github.com/jruby/jruby-openssl/blob/19135259f121f9c9e95ee7f0b4c830f9267680e0/src/main/java/org/jruby/ext/openssl/PKey.java#L117 ->
https://github.com/jruby/jruby-openssl/blob/19135259f121f9c9e95ee7f0b4c830f9267680e0/src/main/java/org/jruby/ext/openssl/x509store/PEMInputOutput.java#L317
Requires some additional debugging on jruby-openssl to find out what is going on there...

I've created new issue jruby/jruby-openssl#285. I added also the CA case which I noticed earlier.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oks, let's see what they answer and then I'll merge this.

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.

Contributing to logstash-output-syslog and status of the plugin?
2 participants