class RestClient::Windows::RootCerts
Represents a collection of trusted root certificates.
@api public
Public Class Methods
instance()
click to toggle source
Returns a new instance. @return [RestClient::Windows::RootCerts] object constructed from current root certificates
# File lib/restclient/windows/root_certs.rb, line 32 def self.instance new(self.load_certs) end
load_certs()
click to toggle source
Returns an array of root certificates.
@return [Array<>] an array of root certificates @api private
# File lib/restclient/windows/root_certs.rb, line 40 def self.load_certs certs = [] # This is based on a patch submitted to openssl: # http://www.mail-archive.com/openssl-dev@openssl.org/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
new(roots)
click to toggle source
# File lib/restclient/windows/root_certs.rb, line 19 def initialize(roots) @roots = roots end
Public Instance Methods
each() { |cert| ... }
click to toggle source
Enumerates each root certificate. @yieldparam cert [OpenSSL::X509::Certificate] each root certificate @api public
# File lib/restclient/windows/root_certs.rb, line 26 def each @roots.each {|cert| yield cert} end