class HTTPI::Auth::SSL
HTTPI::Auth::SSL¶ ↑
Provides SSL client authentication.
Constants
- CERT_TYPES
- VERIFY_MODES
Attributes
Sets the OpenSSL
ca certificate.
Accessor for the cacert file to validate SSL certificates.
Sets the OpenSSL
certificate.
Accessor for the cert file to validate SSL connections.
Sets the OpenSSL
certificate key.
Accessor for the cert key file to validate SSL certificates.
Accessor for the cert key password to validate SSL certificates.
Public Instance Methods
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
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
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
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
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
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
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
Returns the SSL verify mode. Defaults to
:peer
.
# File lib/httpi/auth/ssl.rb, line 45 def verify_mode @verify_mode ||= :peer end
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