Class: Win32SSLInit::Certs
- Inherits:
-
Object
- Object
- Win32SSLInit::Certs
- Extended by:
- FFI::Library
- Includes:
- Enumerable
- Defined in:
- lib/win32_ssl_init/certs.rb
Defined Under Namespace
Classes: CERT_CONTEXT
Class Method Summary collapse
-
.instance ⇒ RestClient::Windows::RootCerts
Returns a new instance.
-
.load_certs ⇒ Array<[OpenSSL::X509::Certificate]>
private
Returns an array of root certificates.
Instance Method Summary collapse
-
#each {|cert| ... } ⇒ Object
Enumerates each root certificate.
-
#initialize(roots) ⇒ Certs
constructor
A new instance of Certs.
Constructor Details
#initialize(roots) ⇒ Certs
Returns a new instance of Certs.
21 22 23 |
# File 'lib/win32_ssl_init/certs.rb', line 21 def initialize(roots) @roots = roots end |
Class Method Details
.instance ⇒ RestClient::Windows::RootCerts
Returns a new instance.
34 35 36 |
# File 'lib/win32_ssl_init/certs.rb', line 34 def self.instance new(self.load_certs) end |
.load_certs ⇒ Array<[OpenSSL::X509::Certificate]>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns an array of root certificates.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/win32_ssl_init/certs.rb', line 42 def self.load_certs certs = [] # This is based on a patch submitted to openssl: # http://www.mail-archive.com/[email protected]/msg26958.html ptr = FFI::Pointer::NULL store = CertOpenSystemStoreA(nil, "ROOT") begin while (ptr = CertEnumCertificatesInStore(store, ptr)) and not ptr.null? context = CERT_CONTEXT.new(ptr) cert_buf = context[:pbCertEncoded].read_bytes(context[:cbCertEncoded]) begin certs << OpenSSL::X509::Certificate.new(cert_buf) rescue => detail warn("Failed to import root certificate: #{detail.inspect}") end end ensure CertCloseStore(store, 0) end certs end |
Instance Method Details
#each {|cert| ... } ⇒ Object
Enumerates each root certificate.
28 29 30 |
# File 'lib/win32_ssl_init/certs.rb', line 28 def each @roots.each { |cert| yield cert } end |