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.



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

def initialize(original_chain, certificate_store)
  @original_chain             = CertificateBundle.new(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
  @recommended_chain     = case \
    when @originally_ordered && @originally_trusted ; @original_chain
    when @originally_trusted                        ; @ordered_chain
    else                                            ; self
    end
end

Instance Method Details

#is_trusted_root?(cert) ⇒ Boolean

Returns:

  • (Boolean)


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

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



64
65
66
# File 'lib/ssltool/chain_resolution.rb', line 64

def to_s
  to_a.join
end