Class: CertValidator::RealOcspValidator::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/cert_validator/ocsp/extractor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cert) ⇒ Extractor

Returns a new instance of Extractor.



6
7
8
# File 'lib/cert_validator/ocsp/extractor.rb', line 6

def initialize(cert)
  @certificate = cert
end

Instance Attribute Details

#certificateObject (readonly)

Returns the value of attribute certificate.



4
5
6
# File 'lib/cert_validator/ocsp/extractor.rb', line 4

def certificate
  @certificate
end

Instance Method Details

#decoded_extensionObject



24
25
26
# File 'lib/cert_validator/ocsp/extractor.rb', line 24

def decoded_extension
  @decoded_extension ||= Asn1.new(Asn1.new(ocsp_extension).extension_payload).decode
end

#descend_to_string(asn_data) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cert_validator/ocsp/extractor.rb', line 38

def descend_to_string(asn_data)
  return asn_data if asn_data.is_a? String
  seen = Set.new
  current = asn_data
  loop do
    raise RecursiveExtractError.new if seen.include? current
    seen.add current
    current = current.first.value

    return current if current.is_a? String
  end
end

#endpointObject



10
11
12
13
14
# File 'lib/cert_validator/ocsp/extractor.rb', line 10

def endpoint
  return nil unless has_ocsp_extension?

  ocsp_extension_payload
end

#has_ocsp_extension?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/cert_validator/ocsp/extractor.rb', line 16

def has_ocsp_extension?
  !! (ocsp_extension && ocsp_extension_payload)
end

#ocsp_extensionObject



20
21
22
# File 'lib/cert_validator/ocsp/extractor.rb', line 20

def ocsp_extension
  @ocsp_extension ||= certificate.extensions.detect{ |e| e.oid == 'authorityInfoAccess' }
end

#ocsp_extension_payloadObject



28
29
30
31
32
33
34
35
36
# File 'lib/cert_validator/ocsp/extractor.rb', line 28

def ocsp_extension_payload
  return @ocsp_extension_payload if defined? @ocsp_extension_payload

  intermediate = decoded_extension.value.detect do |v|
    v.first.value == 'OCSP'
  end.value[1].value

  @ocsp_extension_payload = descend_to_string(intermediate)
end