Sha256: e0cdd56be69b2c2df2aa239e6f463ee7fce80ee6abfade8d2b5a59f89c9e8678

Contents?: true

Size: 1.99 KB

Versions: 90

Compression:

Stored size: 1.99 KB

Contents

require 'puppet/ssl'
require 'openssl'
module Puppet
module SSL
  # Puppet::SSL::Configuration is intended to separate out the following concerns:
  # * CA certificates that authenticate peers (ca_auth_file)
  # * CA certificates that build trust but do not authenticate (ca_chain_file)
  # * Who clients trust as distinct from who servers trust.  We should not
  #   assume one single self signed CA cert for everyone.
class Configuration
  def initialize(localcacert, options={})
    if (options[:ca_chain_file] and not options[:ca_auth_file])
      raise ArgumentError, "The CA auth chain is required if the chain file is provided"
    end
    @localcacert = localcacert
    @ca_chain_file = options[:ca_chain_file]
    @ca_auth_file = options[:ca_auth_file]
  end

  # The ca_chain_file method is intended to return the PEM bundle of CA certs
  # establishing trust but not used for peer authentication.
  def ca_chain_file
    @ca_chain_file || ca_auth_file
  end

  # The ca_auth_file method is intended to return the PEM bundle of CA certs
  # used to authenticate peer connections.
  def ca_auth_file
    @ca_auth_file || @localcacert
  end

  ##
  # ca_auth_certificates returns an Array of OpenSSL::X509::Certificate
  # instances intended to be used in the connection verify_callback.  This
  # method loads and parses the {#ca_auth_file} from the filesystem.
  #
  # @api private
  #
  # @return [Array<OpenSSL::X509::Certificate>]
  def ca_auth_certificates
    @ca_auth_certificates ||= decode_cert_bundle(read_file(ca_auth_file))
  end

  ##
  # Decode a string of concatenated certificates
  #
  # @return [Array<OpenSSL::X509::Certificate>]
  def decode_cert_bundle(bundle_str)
    re = /-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----/m
    pem_ary = bundle_str.scan(re)
    pem_ary.map do |pem_str|
      OpenSSL::X509::Certificate.new(pem_str)
    end
  end
  private :decode_cert_bundle

  # read_file makes testing easier.
  def read_file(path)
    File.read(path)
  end
  private :read_file
end
end
end

Version data entries

90 entries across 90 versions & 2 rubygems

Version Path
puppet-3.8.3 lib/puppet/ssl/configuration.rb
puppet-3.8.3-x86-mingw32 lib/puppet/ssl/configuration.rb
puppet-3.8.3-x64-mingw32 lib/puppet/ssl/configuration.rb
puppet-retrospec-0.8.0 vendor/gems/puppet-3.7.3/lib/puppet/ssl/configuration.rb
puppet-3.8.2 lib/puppet/ssl/configuration.rb
puppet-3.8.2-x86-mingw32 lib/puppet/ssl/configuration.rb
puppet-3.8.2-x64-mingw32 lib/puppet/ssl/configuration.rb
puppet-retrospec-0.7.3 vendor/gems/puppet-3.7.3/lib/puppet/ssl/configuration.rb
puppet-retrospec-0.7.2 vendor/gems/puppet-3.7.3/lib/puppet/ssl/configuration.rb
puppet-3.8.1 lib/puppet/ssl/configuration.rb
puppet-3.8.1-x86-mingw32 lib/puppet/ssl/configuration.rb
puppet-3.8.1-x64-mingw32 lib/puppet/ssl/configuration.rb
puppet-3.7.5 lib/puppet/ssl/configuration.rb
puppet-3.7.5-x86-mingw32 lib/puppet/ssl/configuration.rb
puppet-3.7.5-x64-mingw32 lib/puppet/ssl/configuration.rb
puppet-3.7.4 lib/puppet/ssl/configuration.rb
puppet-3.7.4-x86-mingw32 lib/puppet/ssl/configuration.rb
puppet-3.7.4-x64-mingw32 lib/puppet/ssl/configuration.rb
puppet-3.7.3 lib/puppet/ssl/configuration.rb
puppet-3.7.3-x86-mingw32 lib/puppet/ssl/configuration.rb