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.4"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cert, issuer = nil, options = {}) ⇒ 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, options = {})
  if cert.is_a? OpenSSL::X509::Certificate
    cert = R509::Cert.new cert: cert
  end
  
  if issuer.is_a? OpenSSL::X509::Certificate
    issuer = R509::Cert.new cert: issuer
  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



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/r509/cert/validator.rb', line 47

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
42
43
44
45
# 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

  crl_file = opts[:crl_file]

  crl_available = @crl.available? || (crl_file && File.exist?(crl_file))

  if opts[:crl] && !crl_available
    raise Error.new "Tried to validate CRL but cert has no CRL data"
  end

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