Type:
Class

The X509 certificate store holds trusted CA certificates used to verify peer certificates.

The easiest way to create a useful certificate store is:

1
2
cert_store = OpenSSL::X509::Store.new
cert_store.set_default_paths

This will use your system's built-in certificates.

If your system does not have a default set of certificates you can obtain a set from Mozilla here: curl.haxx.se/docs/caextract.html (Note that this set does not have an HTTPS download option so you may wish to use the firefox-db2pem.sh script to extract the certificates from a local install to avoid man-in-the-middle attacks.)

After downloading or generating a cacert.pem from the above link you can create a certificate store from the pem file like this:

1
2
cert_store = OpenSSL::X509::Store.new
cert_store.add_file 'cacert.pem'

The certificate store can be used with an SSLSocket like this:

1
2
3
4
5
6
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.cert_store = cert_store
 
tcp_socket = TCPSocket.open 'example.com', 443
 
ssl_socket = OpenSSL::SSL::SSLSocket.new tcp_socket, ssl_context
set_default_paths
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::X509/OpenSSL::X509::Store

store.set_default_path Instance Public methods Adds the default certificates

2025-01-10 15:47:30
add_crl
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::X509/OpenSSL::X509::Store

add_crl(p1) Instance Public methods

2025-01-10 15:47:30
verify
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::X509/OpenSSL::X509::Store

verify(p1, p2 = v2) Instance Public methods

2025-01-10 15:47:30
add_file
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::X509/OpenSSL::X509::Store

store.add_file(file) â store Instance Public methods Adds the certificates

2025-01-10 15:47:30
verify_callback=
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::X509/OpenSSL::X509::Store

verify_callback=(p1) Instance Public methods General callback for

2025-01-10 15:47:30
new
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::X509/OpenSSL::X509::Store

X509::Store.new => store Class Public methods

2025-01-10 15:47:30
add_path
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::X509/OpenSSL::X509::Store

add_path(p1) Instance Public methods

2025-01-10 15:47:30
flags=
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::X509/OpenSSL::X509::Store

flags=(p1) Instance Public methods

2025-01-10 15:47:30
add_cert
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::X509/OpenSSL::X509::Store

store.add_cert(cert) Instance Public methods Adds the

2025-01-10 15:47:30
time=
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::X509/OpenSSL::X509::Store

time=(p1) Instance Public methods

2025-01-10 15:47:30