Skip to content

ssl: add ssl_cert option to support pkcs12 self-signed cert#165

Open
lenage wants to merge 1 commit intotoland:masterfrom
lenage:master
Open

ssl: add ssl_cert option to support pkcs12 self-signed cert#165
lenage wants to merge 1 commit intotoland:masterfrom
lenage:master

Conversation

@lenage
Copy link
Copy Markdown

@lenage lenage commented Mar 18, 2018

Added ssl_cert, ssl_cert_type and ssl_key_password to support self-signed PKCS12 cert.

see cURL docs for those options:

https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERT.html
https://curl.haxx.se/libcurl/c/CURLOPT_SSLCERTTYPE.html

I just wrote one spec, and it passed, if i missed something, please let me know.

Comment thread ext/patron/session_ext.c

ssl_key_password = rb_funcall(request, rb_intern("ssl_key_password"), 0);
if(RTEST(ssl_key_password)) {
curl_easy_setopt(curl, CURLOPT_SSLKEYPASSWD, StringValuePtr(ssl_key_password));
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

https://curl.haxx.se/mail/lib-2005-03/0172.html

found CURLOPT_SSLKEYPASSWD in maillist

Copy link
Copy Markdown
Collaborator

@julik julik left a comment

Choose a reason for hiding this comment

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

Looks really impressive, thanks! Good to merge but I am curious what the failure mode is with a non-happy path. Is there a clear exception message propagated via the curl abort?

Comment thread spec/session_ssl_spec.rb
@session.insecure = nil
@session.ssl_cert = 'spec/certs/keystore.p12'
@sessions.ssl_cert_type = "p12"
@session.ssl_key_password = "pkcs12"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If the password is set incorrectly, what is the exception that is going to be raised? Do we need a separate exception type for this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, will add a spec for that case

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

curl -v --cert ./keystore.p12 --pass pkcs13 https://google.com                                                                                                                                           * Rebuilt URL to: https://google.com/
*   Trying 74.125.68.113...
* TCP_NODELAY set
* Connected to google.com (74.125.68.113) port 443 (#0)
* WARNING: SSL: Certificate type not set, assuming PKCS#12 format.
* SSL: Incorrect password for the certificate "./keystore.p12" and its private key.
* Closing connection 0

trying to connect with wrong password, seems like failed at SSL level

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yep, would be useful to check for a proper exception in that case on the Patron end

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

sorry, it's kind of busy in those days, i will catch and update this PR asap

Comment thread spec/session_ssl_spec.rb
it "should work when ssl_cert is supplied" do
@session.insecure = nil
@session.ssl_cert = 'spec/certs/keystore.p12'
@sessions.ssl_cert_type = "p12"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@sessions should probably be @session? And if it isn't does this test pass?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, my bad

@julik
Copy link
Copy Markdown
Collaborator

julik commented May 10, 2018

@lenage Sorry it's been a while - but could you maybe take another look at the feedback?

@joshgoebel
Copy link
Copy Markdown

Is this project pretty much unmaintained now?

@julik
Copy link
Copy Markdown
Collaborator

julik commented Oct 14, 2024

I'm looking at PRs regularly here. On this PR there was feedback which was left unadressed. Also I do think that using a self-signed cert does merit setting up the test Puma with that cert to verify whether connecting works correctly and it is possible to do a GET.

@joshgoebel
Copy link
Copy Markdown

I was also looking at the fact that there hasn't been a release since 2014.

@julik
Copy link
Copy Markdown
Collaborator

julik commented Feb 12, 2025

@joshgoebel I understand your curiosity but this is likely related to how this GH repo does not register releases. Last release was in 2019. I left the job where I was using Patron a lot around 2022 - until that time that last version was doing its duty well for us. At my new spot there was another HTTP client library picked prior to me joining, and there is so much stuff to do that I didn't get to replacing it with Patron - and Patron would need those advanced SSL configuration options for it to be viable for us. Alas, just so many elephants to eat and hills to climb. But I wouldn't say Patron is abandoned.

Screen Shot 2025-02-12 at 12 31 12

@joshgoebel
Copy link
Copy Markdown

but this is likely related to how this GH repo does not register releases.

If you don't wish to use the github releases feature you should turn it off, otherwise it just confuses users who will look there to find the latest release.

@julik julik mentioned this pull request Feb 26, 2025
@julik
Copy link
Copy Markdown
Collaborator

julik commented Feb 27, 2025

@joshgoebel see #197 (comment) I will add a section to the README pointing people at rubygems.org for authoritative version releases. Thank you for your feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants