Class: Ronin::Recon::Values::Cert

Inherits:
Ronin::Recon::Value show all
Defined in:
lib/ronin/recon/values/cert.rb

Overview

Represents a SSL/TLS certificate.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Ronin::Recon::Value

#==, parse, #to_csv, #to_json

Constructor Details

#initialize(cert) ⇒ Cert

Initializes the certificate value.

Parameters:

  • cert (OpenSSL::X509::Certificate)

    The decoded X509 certificate.



45
46
47
# File 'lib/ronin/recon/values/cert.rb', line 45

def initialize(cert)
  @cert = Support::Crypto::Cert(cert)
end

Instance Attribute Details

#certRonin::Support::Crypto::Cert (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The certificate object.

Returns:

  • (Ronin::Support::Crypto::Cert)


37
38
39
# File 'lib/ronin/recon/values/cert.rb', line 37

def cert
  @cert
end

Class Method Details

.value_type:cert

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

This is used internally to map a recon value class to a printable type.

Returns the type or kind of recon value.

Returns:

  • (:cert)


161
162
163
# File 'lib/ronin/recon/values/cert.rb', line 161

def self.value_type
  :cert
end

Instance Method Details

#as_jsonHash{Symbol => Object}

Converts the certificate to a hash of attributes

Returns:

  • (Hash{Symbol => Object})


137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/ronin/recon/values/cert.rb', line 137

def as_json
  {
    serial:            @cert.serial,
    not_before:        @cert.not_before,
    not_after:         @cert.not_after,
    subject:           @cert.subject.to_h,
    issuer:            @cert.issuer.to_h,
    extensions:        @cert.extensions_hash,
    subject_alt_names: @cert.subject_alt_names,
    pem:               @cert.to_pem
  }
end

#eql?(other) ⇒ Boolean

Compares the certificate to another value.

Parameters:

  • other (Object)

Returns:

  • (Boolean)


110
111
112
# File 'lib/ronin/recon/values/cert.rb', line 110

def eql?(other)
  self.class == other.class && serial == other.serial
end

#extensionsArray<OpenSSL::X509::Extensions>

Additional certificate extensions.

Returns:

  • (Array<OpenSSL::X509::Extensions>)


99
100
101
# File 'lib/ronin/recon/values/cert.rb', line 99

def extensions
  @cert.extensions
end

#hashInteger

The "hash" value of the certificate.

Returns:

  • (Integer)


119
120
121
# File 'lib/ronin/recon/values/cert.rb', line 119

def hash
  [self.class, @cert.serial].hash
end

#issuerOpenSSL::X509::Name

The certificate issuer's information.

Returns:

  • (OpenSSL::X509::Name)


81
82
83
# File 'lib/ronin/recon/values/cert.rb', line 81

def issuer
  @cert.issuer
end

#not_afterTime

When the certificate expires.

Returns:

  • (Time)


72
73
74
# File 'lib/ronin/recon/values/cert.rb', line 72

def not_after
  @cert.not_after
end

#not_beforeTime

When the certificate begins being valid.

Returns:

  • (Time)


63
64
65
# File 'lib/ronin/recon/values/cert.rb', line 63

def not_before
  @cert.not_before
end

#serialOpenSSL::BN

The serial number of the SSL/TLS certificate.

Returns:

  • (OpenSSL::BN)


54
55
56
# File 'lib/ronin/recon/values/cert.rb', line 54

def serial
  @cert.serial
end

#subjectOpenSSL::X509::Name

The certificate subject's information.

Returns:

  • (OpenSSL::X509::Name)


90
91
92
# File 'lib/ronin/recon/values/cert.rb', line 90

def subject
  @cert.subject
end

#to_sString

Converts the certificate to a string.

Returns:

  • (String)


128
129
130
# File 'lib/ronin/recon/values/cert.rb', line 128

def to_s
  @cert.to_s
end