class HTTPI::Auth::SSL

HTTPI::Auth::SSL

Provides SSL client authentication.

Constants

CERT_TYPES
VERIFY_MODES

Attributes

ca_cert[W]

Sets the OpenSSL ca certificate.

ca_cert_file[RW]

Accessor for the cacert file to validate SSL certificates.

cert[W]

Sets the OpenSSL certificate.

cert_file[RW]

Accessor for the cert file to validate SSL connections.

cert_key[W]

Sets the OpenSSL certificate key.

cert_key_file[RW]

Accessor for the cert key file to validate SSL certificates.

cert_key_password[RW]

Accessor for the cert key password to validate SSL certificates.

Public Instance Methods

ca_cert() click to toggle source

Returns an OpenSSL::X509::Certificate for the ca_cert_file.

# File lib/httpi/auth/ssl.rb, line 64
def ca_cert
  @ca_cert ||= OpenSSL::X509::Certificate.new File.read(ca_cert_file)
end
cert() click to toggle source

Returns an OpenSSL::X509::Certificate for the cert_file.

# File lib/httpi/auth/ssl.rb, line 56
def cert
  @cert ||= (OpenSSL::X509::Certificate.new File.read(cert_file) if cert_file)
end
cert_key() click to toggle source

Returns an OpenSSL::PKey::RSA for the cert_key_file.

# File lib/httpi/auth/ssl.rb, line 72
def cert_key
  @cert_key ||= (OpenSSL::PKey::RSA.new(File.read(cert_key_file), cert_key_password) if cert_key_file)
end
cert_type() click to toggle source

Returns the cert type to validate SSL certificates PEM|DER.

# File lib/httpi/auth/ssl.rb, line 34
def cert_type
  @cert_type ||= :pem
end
cert_type=(type) click to toggle source

Sets the cert type to validate SSL certificates PEM|DER.

# File lib/httpi/auth/ssl.rb, line 39
def cert_type=(type)
  raise ArgumentError, "Invalid SSL cert type: #{type}" unless CERT_TYPES.include? type
  @cert_type = type
end
openssl_verify_mode() click to toggle source

Returns the SSL verify mode as a OpenSSL::SSL::VERIFY_* constant.

# File lib/httpi/auth/ssl.rb, line 80
def openssl_verify_mode
  case verify_mode
    when :none                 then OpenSSL::SSL::VERIFY_NONE
    when :peer                 then OpenSSL::SSL::VERIFY_PEER
    when :fail_if_no_peer_cert then OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
    when :client_once          then OpenSSL::SSL::VERIFY_CLIENT_ONCE
  end
end
present?() click to toggle source

Returns whether SSL configuration is present.

# File lib/httpi/auth/ssl.rb, line 15
def present?
  (verify_mode == :none) || (cert && cert_key) || ca_cert_file
rescue TypeError, Errno::ENOENT
  false
end
verify_mode() click to toggle source

Returns the SSL verify mode. Defaults to :peer.

# File lib/httpi/auth/ssl.rb, line 45
def verify_mode
  @verify_mode ||= :peer
end
verify_mode=(mode) click to toggle source

Sets the SSL verify mode. Expects one of HTTPI::Auth::SSL::VERIFY_MODES.

# File lib/httpi/auth/ssl.rb, line 50
def verify_mode=(mode)
  raise ArgumentError, "Invalid SSL verify mode: #{mode}" unless VERIFY_MODES.include? mode
  @verify_mode = mode
end