Class: R509::Crl::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/r509/crl.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Parser) initialize(crl)

A new instance of Parser

Parameters:

  • crl (String, OpenSSL::X509::CRL)


14
15
16
# File 'lib/r509/crl.rb', line 14

def initialize(crl)
    @crl = OpenSSL::X509::CRL.new(crl)
end

Instance Attribute Details

- (Object) crl (readonly)

Returns the value of attribute crl



11
12
13
# File 'lib/r509/crl.rb', line 11

def crl
  @crl
end

Class Method Details

+ (R509::Crl::Parser) load_from_file(filename)

Helper method to quickly load a CRL from the filesystem

Parameters:

  • filename (String)

    Path to file you want to load

Returns:



22
23
24
# File 'lib/r509/crl.rb', line 22

def self.load_from_file( filename )
    return R509::Crl::Parser.new( IOHelpers.read_data(filename) )
end

Instance Method Details

- (OpenSSL::X509::Name) issuer

Returns:

  • (OpenSSL::X509::Name)


27
28
29
# File 'lib/r509/crl.rb', line 27

def issuer
    @crl.issuer
end

- (String) issuer_cn

The common name (CN) component of the issuer

Returns:

  • (String)

    The common name (CN) component of the issuer



32
33
34
35
36
37
38
39
40
41
# File 'lib/r509/crl.rb', line 32

def issuer_cn
    return nil if self.issuer.nil?

    self.issuer.to_a.each do |part, value, length|
        return value if part.upcase == 'CN'
    end

    # return nil if we didn't find a CN part
    return nil
end

- (Time) last_update

Returns:

  • (Time)


44
45
46
# File 'lib/r509/crl.rb', line 44

def last_update
    @crl.last_update
end

- (Time) next_update

Returns:

  • (Time)


49
50
51
# File 'lib/r509/crl.rb', line 49

def next_update
    @crl.next_update
end

- (Hash) revoked

Hash of serial => { :time, :reason } hashes

Returns:

  • (Hash)

    hash of serial => { :time, :reason } hashes



77
78
79
80
81
82
83
84
85
# File 'lib/r509/crl.rb', line 77

def revoked
    revoked_list = {}
    @crl.revoked.each do |revoked|
        reason = get_reason(revoked)
        revoked_list[revoked.serial.to_i] = { :time => revoked.time, :reason => reason }
    end

    revoked_list
end

- (Boolean) revoked?(serial)

Parameters:

  • serial (Integer)

    number

Returns:

  • (Boolean)


68
69
70
71
72
73
74
# File 'lib/r509/crl.rb', line 68

def revoked?(serial)
    if @crl.revoked.find { |revoked| revoked.serial == serial }
        true
    else
        false
    end
end

- (Hash) revoked_cert(serial)

Hash with :time and :reason

Parameters:

  • serial (Integer)

    number

Returns:

  • (Hash)

    hash with :time and :reason



89
90
91
92
93
94
95
96
97
# File 'lib/r509/crl.rb', line 89

def revoked_cert(serial)
    revoked = @crl.revoked.find { |revoked| revoked.serial == serial }
    if revoked
        reason = get_reason(revoked)
        { :time => revoked.time, :reason => reason }
    else
        nil
    end
end

- (String) signature_algorithm

Returns:

  • (String)


54
55
56
# File 'lib/r509/crl.rb', line 54

def signature_algorithm
    @crl.signature_algorithm
end

- (Boolean) verify(public_key)

Pass a public key to verify that the CRL is signed by a specific certificate (call cert.public_key on that object)

Parameters:

  • public_key (OpenSSL::PKey::PKey)

Returns:

  • (Boolean)


62
63
64
# File 'lib/r509/crl.rb', line 62

def verify(public_key)
    @crl.verify(public_key)
end