Skip to content

OpenSSL::SSL::SSLContext#add_certificate, then #cert returns nil #303

Closed
@thekuwayama

Description

@thekuwayama

This issue is related to behavior of OpenSSL::SSL::SSLContext#add_certificate(_chain_file).

When the SSLContext object is called add_certificate method, then it would load certificates.
In my opinion, it was expected to return a Certificate object (not nil) when being called cert method. But the object does not return a Certificate object and returns nil.
You can check this if you run the following code.

require 'openssl'

ctx = OpenSSL::SSL::SSLContext.new
crt = OpenSSL::X509::Certificate.new(
  File.read('/path/to/ruby-openssl/test/fixtures/chain/server.crt')
)
key = OpenSSL::PKey::RSA.new(
  File.read('/path/to/ruby-openssl/test/fixtures/chain/server.key')
)

ctx.add_certificate(cert, key)
pp ctx.cert

The object, in a handshake, uses the server certificate object and the private key object that were loaded by add_certificate.
It is tested by test_add_certificate.
add_certificate_chain_file method is the same as this.
The SSLContext object does not return these objects.

As commented, the cert, key and extra_chain_cert attributes are deprecated so it is as intended?
If so, how do you think to add the note that cert (etc) returns nil?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions