Class: R509::Cert::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/r509/cert/validator.rb,
lib/r509/cert/validator/errors.rb,
lib/r509/cert/validator/version.rb,
lib/r509/cert/validator/crl_validator.rb,
lib/r509/cert/validator/ocsp_validator.rb,
lib/r509/cert/validator/basic_validator.rb

Defined Under Namespace

Classes: BasicValidator, CrlError, CrlValidator, Error, OcspError, OcspValidator

Constant Summary collapse

VERSION =
"0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cert, issuer = nil) ⇒ Validator

Returns a new instance of Validator.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/r509/cert/validator.rb', line 12

def initialize(cert, issuer = nil)
  if cert.is_a? OpenSSL::X509::Certificate
    cert = R509::Cert.new cert: cert
  end
  
  if issuer.is_a? OpenSSL::X509::Certificate
    cert = R509::Cert.new cert: cert
  end

  @cert = cert
  @issuer = issuer

  initialize_validators
end

Instance Attribute Details

#certObject (readonly)

The certificate this Validator will validate



10
11
12
# File 'lib/r509/cert/validator.rb', line 10

def cert
  @cert
end

Instance Method Details

#validate(options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/r509/cert/validator.rb', line 43

def validate(options={})
  begin
    validate! options
  rescue OcspError
    return false
  rescue CrlError
    return false
  end

  return true
end

#validate!(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/r509/cert/validator.rb', line 27

def validate!(options={})
  opts = { ocsp: @ocsp.available?, crl: @crl.available? }.merge options

  if opts[:ocsp] && !@ocsp.available?
    raise Error.new "Tried to validate OCSP but cert has no OCSP data" 
  end

  if opts[:crl] && !@crl.available?
    
  end

  @ocsp.validate! if opts[:ocsp]
  @crl.validate! if opts[:crl]
  true
end