Class: Acmesmith::CertificateRetrievingService::CertificateChain
- Inherits:
-
Object
- Object
- Acmesmith::CertificateRetrievingService::CertificateChain
- Defined in:
- lib/acmesmith/certificate_retrieving_service.rb
Instance Attribute Summary collapse
-
#certificates ⇒ Object
readonly
Returns the value of attribute certificates.
-
#pem_chain ⇒ Object
readonly
Returns the value of attribute pem_chain.
Instance Method Summary collapse
-
#initialize(pem_chain) ⇒ CertificateChain
constructor
A new instance of CertificateChain.
- #match?(name: nil, key_id: nil) ⇒ Boolean
- #to_s ⇒ Object
- #top ⇒ Object
Constructor Details
#initialize(pem_chain) ⇒ CertificateChain
Returns a new instance of CertificateChain.
50 51 52 53 54 |
# File 'lib/acmesmith/certificate_retrieving_service.rb', line 50 def initialize(pem_chain) @pem_chain = pem_chain @pems = Certificate.split_pems(pem_chain) @certificates = @pems.map { |_| OpenSSL::X509::Certificate.new(_) } end |
Instance Attribute Details
#certificates ⇒ Object (readonly)
Returns the value of attribute certificates.
57 58 59 |
# File 'lib/acmesmith/certificate_retrieving_service.rb', line 57 def certificates @certificates end |
#pem_chain ⇒ Object (readonly)
Returns the value of attribute pem_chain.
56 57 58 |
# File 'lib/acmesmith/certificate_retrieving_service.rb', line 56 def pem_chain @pem_chain end |
Instance Method Details
#match?(name: nil, key_id: nil) ⇒ Boolean
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/acmesmith/certificate_retrieving_service.rb', line 65 def match?(name: nil, key_id: nil) has_root = top.issuer == top.subject if name return false unless name == (has_root ? top.subject : top.issuer).to_a.assoc('CN')[1] end if key_id top_key_id = if has_root value_der(top.extensions.find { |e| e.oid == 'subjectKeyIdentifier' })&.slice(2..-1) else value_der(top.extensions.find { |e| e.oid == 'authorityKeyIdentifier' })&.slice(4,20) end&.unpack1('H*')&.downcase return false unless key_id.downcase.gsub(/:/,'') == top_key_id end true end |
#to_s ⇒ Object
59 60 61 62 63 |
# File 'lib/acmesmith/certificate_retrieving_service.rb', line 59 def to_s certificates[1..-1].map do |c| "s:#{c.subject},i:#{c.issuer}" end.join(" | ") end |
#top ⇒ Object
84 85 86 |
# File 'lib/acmesmith/certificate_retrieving_service.rb', line 84 def top @top ||= find_top() end |