Class: IO::Endpoint::TLS::Configuration
- Inherits:
-
Object
- Object
- IO::Endpoint::TLS::Configuration
- Defined in:
- lib/io/endpoint/tls/configuration.rb
Overview
Represents transport-neutral TLS certificate and verification configuration.
Instance Attribute Summary collapse
-
#certificate_chain ⇒ Object
readonly
Returns the value of attribute certificate_chain.
-
#private_key ⇒ Object
readonly
Returns the value of attribute private_key.
- #The ordered local certificate chain encoded as individual PEM strings, with the leaf certificate followed by any intermediates.(orderedlocalcertificatechainencodedasindividualPEMstrings, withtheleafcertificatefollowedbyanyintermediates.) ⇒ Object readonly
- #The private key encoded as PEM.(privatekeyencodedasPEM.) ⇒ Object readonly
- #The trusted certificate sources.(trustedcertificatesources.) ⇒ Object readonly
-
#trust_store ⇒ Object
readonly
Returns the value of attribute trust_store.
-
#verification ⇒ Object
readonly
Returns the value of attribute verification.
Instance Method Summary collapse
-
#initialize(trust_store: nil, certificate_chain: nil, private_key: nil, verification: nil) ⇒ Configuration
constructor
Initialize a TLS configuration from PEM-encoded certificate and private key material.
-
#inspect ⇒ Object
Get a representation of the configuration without exposing certificate or private key material.
- #The peer verification policy.=(peerverificationpolicy. = (value)) ⇒ Object
-
#verify_peer? ⇒ Boolean
Whether peer certificates should be verified.
Constructor Details
#initialize(trust_store: nil, certificate_chain: nil, private_key: nil, verification: nil) ⇒ Configuration
Initialize a TLS configuration from PEM-encoded certificate and private key material.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/io/endpoint/tls/configuration.rb', line 20 def initialize(trust_store: nil, certificate_chain: nil, private_key: nil, verification: nil) if certificate_chain unless certificate_chain.is_a?(Array) && certificate_chain.all?{|certificate| certificate.is_a?(String)} raise TypeError, "The certificate chain must be provided as an array of strings!" end unless certificate_chain.any? raise ArgumentError, "The certificate chain must contain at least one certificate!" end end unless private_key.nil? || private_key.is_a?(String) raise TypeError, "The private key must be provided as a string!" end if certificate_chain.nil? != private_key.nil? raise ArgumentError, "The certificate chain and private key must be provided together!" end verification = :peer if verification.nil? && trust_store unless [nil, :none, :peer, :required].include?(verification) raise ArgumentError, "Unsupported verification policy: #{verification.inspect}!" end @trust_store = trust_store @certificate_chain = certificate_chain @private_key = private_key @verification = verification end |
Instance Attribute Details
#certificate_chain ⇒ Object (readonly)
Returns the value of attribute certificate_chain.
54 55 56 |
# File 'lib/io/endpoint/tls/configuration.rb', line 54 def certificate_chain @certificate_chain end |
#private_key ⇒ Object (readonly)
Returns the value of attribute private_key.
57 58 59 |
# File 'lib/io/endpoint/tls/configuration.rb', line 57 def private_key @private_key end |
#The ordered local certificate chain encoded as individual PEM strings, with the leaf certificate followed by any intermediates.(orderedlocalcertificatechainencodedasindividualPEMstrings, withtheleafcertificatefollowedbyanyintermediates.) ⇒ Object (readonly)
54 |
# File 'lib/io/endpoint/tls/configuration.rb', line 54 attr :certificate_chain |
#The private key encoded as PEM.(privatekeyencodedasPEM.) ⇒ Object (readonly)
57 |
# File 'lib/io/endpoint/tls/configuration.rb', line 57 attr :private_key |
#The trusted certificate sources.(trustedcertificatesources.) ⇒ Object (readonly)
51 |
# File 'lib/io/endpoint/tls/configuration.rb', line 51 attr :trust_store |
#trust_store ⇒ Object (readonly)
Returns the value of attribute trust_store.
51 52 53 |
# File 'lib/io/endpoint/tls/configuration.rb', line 51 def trust_store @trust_store end |
#verification ⇒ Object (readonly)
Returns the value of attribute verification.
60 61 62 |
# File 'lib/io/endpoint/tls/configuration.rb', line 60 def verification @verification end |
Instance Method Details
#inspect ⇒ Object
Get a representation of the configuration without exposing certificate or private key material.
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/io/endpoint/tls/configuration.rb', line 70 def inspect attributes = { trust_store: !@trust_store.nil?, certificate_chain: !@certificate_chain.nil?, private_key: !@private_key.nil?, verification: @verification, } return "\#<#{self.class} #{attributes.inspect}>" end |
#The peer verification policy.=(peerverificationpolicy. = (value)) ⇒ Object
60 |
# File 'lib/io/endpoint/tls/configuration.rb', line 60 attr :verification |
#verify_peer? ⇒ Boolean
Whether peer certificates should be verified.
64 65 66 |
# File 'lib/io/endpoint/tls/configuration.rb', line 64 def verify_peer? return @verification == :peer || @verification == :required end |