Class: SSLTool::ChainResolution

Inherits:
Object
  • Object
show all
Defined in:
lib/ssltool/chain_resolution.rb

Defined Under Namespace

Classes: CertificateBundle, ChainResolutionError, TooManyHeadsChainResolutionError, ZeroCertsChainResolutionError, ZeroHeadsChainResolutionError

Instance Method Summary collapse

Constructor Details

#initialize(original_chain, certificate_store) ⇒ ChainResolution

Returns a new instance of ChainResolution.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ssltool/chain_resolution.rb', line 29

def initialize(original_chain, certificate_store)
  @original_chain             = original_chain.uniq.freeze
  @certificate_store          = certificate_store
  @domain_certs, @other_certs = @original_chain.partition(&:for_domain_name?)
  @original_chain.empty? and raise ZeroCertsChainResolutionError
  case @domain_certs.length
  when 1; # pass
  when 0; raise ZeroHeadsChainResolutionError
  else  ; raise TooManyHeadsChainResolutionError.new(@domain_certs)
  end
  @base_cert             = @domain_certs.first
  @ordered_chain         = CertificateBundle.new(@base_cert.chain_from(@other_certs)).freeze
  @resolved_chain        = CertificateBundle.new(@base_cert.chain_from(@certificate_store.combined_trusted_pool_set))
                             .take_while { |c| ! is_trusted_root? c }
                             .freeze
  @unused_certs          = CertificateBundle.new(@other_certs - @resolved_chain).freeze
  @domain_names          = @base_cert.domain_names.freeze
  @originally_ordered    = @original_chain == @ordered_chain
  @originally_trusted    = @certificate_store.trust? @ordered_chain
  @ordered               = true
  @trusted               = @certificate_store.trust? @resolved_chain
  @self_signed_untrusted = @resolved_chain.last.self_signed? && !@trusted
end

Instance Method Details

#is_trusted_root?(cert) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/ssltool/chain_resolution.rb', line 23

def is_trusted_root? cert
  cert.certificate_authority? &&
  cert.self_signed?           &&
  @certificate_store.trusted_pool.include?(cert)
end

#to_sObject Also known as: join, to_pem



58
59
60
# File 'lib/ssltool/chain_resolution.rb', line 58

def to_s
  to_a.join
end