-
Notifications
You must be signed in to change notification settings - Fork 17
Add chained certificate support #20
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,9 +50,31 @@ def initialize(options={}) | |
|
|
||
| if @options[:ssl] | ||
| # load SSL certificate | ||
| @ssl = OpenSSL::SSL::SSLContext.new | ||
| @ssl.cert = OpenSSL::X509::Certificate.new(File.read(@options[:ssl_certificate])) | ||
| @ssl.key = OpenSSL::PKey::RSA.new(File.read(@options[:ssl_key]), | ||
| ssl = OpenSSL::SSL::SSLContext.new | ||
| raw_cert = File.read(@options[:ssl_certificate]) | ||
| ssl.cert = OpenSSL::X509::Certificate.new(raw_cert) | ||
|
|
||
| # Parse chain certificates from @ssl_cert | ||
| certPosition = [0] | ||
| while certPosition[-1] | ||
| certPosition.push(raw_cert.index("-----B", certPosition[-1] + 1)) | ||
| end | ||
|
|
||
| # Gather chain from certificate | ||
| if certPosition.length > 2 | ||
| ssl.extra_chain_cert = Array.new | ||
| for i in 1..(certPosition.length - 2) | ||
| if certPosition[i+1] | ||
| certEnd = certPosition[i+1] - 1 | ||
| else | ||
| certEnd = raw_cert.length - 1 | ||
| end | ||
| certLink = OpenSSL::X509::Certificate.new(raw_cert[certPosition[i]..certEnd]) | ||
| ssl.extra_chain_cert.push(certLink) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like most things in Ruby OpenSSL, the extra_chain_cert setting has practically no documentation available nor are there any decent examples I can find of its usage online (all the examples I see are copy/pasted from Ruby's own source tree, blah). I'll have to read MRI's code to figure out what this really does under the hood.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Notes from reading MRI's code) extra_chain_cert is an accessor (in MRI, anyway) that is used in both the SSLContext initialize and connect(?) methods. It invokes this OpenSSL method: SSL_CTX_add_extra_chain_cert for each item in the Enumerable |
||
| end | ||
| end | ||
|
|
||
| ssl.key = OpenSSL::PKey::RSA.new(File.read(@options[:ssl_key]), | ||
| @options[:ssl_key_passphrase]) | ||
| end | ||
| end # def initialize | ||
|
|
||
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.
I suspect there's a library method for reading certificates from a file that we can reuse instead of crafting our own here. I don't know what that is right now, though.
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.
This new code might be best in a separate file as a function that returns an array of OpenSSL::X509::Certificates.