Class: RestClient::Windows::RootCerts

### Home Classes Methods

### In Files

- lib/restclient/windows/root_certs.rb

### Parent

Object

### Namespace

- CLASS RestClient::Windows::RootCerts::CERT_CONTEXT

### Methods

- ::instance
- ::load_certs
- ::new
- #each

### Included Modules

- Enumerable

### Class/Module Index

Quicksearch

- RestClient
- RestClient::AbstractResponse
- RestClient::Exception
- RestClient::ExceptionWithResponse
- RestClient::Exceptions
- RestClient::MaxRedirectsReached
- RestClient::Payload
- RestClient::Payload::Base
- RestClient::Payload::Multipart
- RestClient::Payload::Streamed
- RestClient::Payload::UrlEncoded
- RestClient::Platform
- RestClient::RawResponse
- RestClient::Redirect
- RestClient::Request
- RestClient::Request::Redirect
- RestClient::Request::RequestFailed
- RestClient::RequestFailed
- RestClient::Resource
- RestClient::Response
- RestClient::ResponseForException
- RestClient::SSLCertificateNotVerified
- RestClient::ServerBrokeConnection
- RestClient::Windows
- RestClient::Windows::RootCerts
- RestClient::Windows::RootCerts::CERT_CONTEXT

No matching classes.

# 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() 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.