Class: Ronin::Support::Crypto::Cert::Name

Inherits:
OpenSSL::X509::Name
  • Object
show all
Defined in:
lib/ronin/support/crypto/cert.rb

Overview

Represents the Subject and Issuer fields in a X509 Certificate.

Since:

  • 1.0.0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(common_name: nil, organizational_unit: nil, organization: nil, locality: nil, state: nil, province: nil, country: nil) ⇒ Name

Builds a X509 Subject or Issuer string.

Parameters:

  • common_name (String, nil) (defaults to: nil)

    The "common name" for the cert (ex: github.com).

  • organizational_unit (String, nil) (defaults to: nil)

    The organizational unit for the cert.

  • organization (String, nil) (defaults to: nil)

    The organization name for the cert (ex: GitHub, Inc.).

  • locality (String, nil) (defaults to: nil)

    The locality or city for the cert (ex: San Francisco).

  • state (String, nil) (defaults to: nil)

    The state for the cert (ex: Californa).

  • province (String, nil) (defaults to: nil)

    The province for the cert.

  • country (String, nil) (defaults to: nil)

    The country for the cert (ex: US).

Returns:

  • (Name)

    The populated name.

Since:

  • 1.0.0



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ronin/support/crypto/cert.rb', line 69

def self.build(common_name: nil, organizational_unit: nil, organization: nil, locality: nil, state: nil, province: nil, country: nil)
  name = new
  name.add_entry("CN",common_name)         if common_name
  name.add_entry("OU",organizational_unit) if organizational_unit
  name.add_entry("O",organization)         if organization
  name.add_entry("L",locality)             if locality
  name.add_entry("ST",state || province)   if (state || province)
  name.add_entry("C",country)              if country

  return name
end

Instance Method Details

#[](oid) ⇒ String?

Finds the entry with the given OID name.

Parameters:

Returns:

Since:

  • 1.0.0



101
102
103
# File 'lib/ronin/support/crypto/cert.rb', line 101

def [](oid)
  entries[oid]
end

#common_nameString?

The common name (CN) entry.

Returns:

Since:

  • 1.0.0



110
111
112
# File 'lib/ronin/support/crypto/cert.rb', line 110

def common_name
  self['CN']
end

#countryString?

The country (C) entry.

Returns:

Since:

  • 1.0.0



157
158
159
# File 'lib/ronin/support/crypto/cert.rb', line 157

def country
  self['C']
end

#entriesHash{String => String} Also known as: to_h

The parsed entries in the name.

Returns:

Since:

  • 1.0.0



86
87
88
89
90
# File 'lib/ronin/support/crypto/cert.rb', line 86

def entries
  @entries ||= to_a.to_h do |(oid,value,type)|
    [oid, value && value.force_encoding(Encoding::UTF_8)]
  end
end

#localityString?

The locality (L) entry.

Returns:

Since:

  • 1.0.0



137
138
139
# File 'lib/ronin/support/crypto/cert.rb', line 137

def locality
  self['L']
end

#organizationString?

The organization (O) entry.

Returns:

Since:

  • 1.0.0



119
120
121
# File 'lib/ronin/support/crypto/cert.rb', line 119

def organization
  self['O']
end

#organizational_unitString?

The organizational unit (OU) entry.

Returns:

Since:

  • 1.0.0



128
129
130
# File 'lib/ronin/support/crypto/cert.rb', line 128

def organizational_unit
  self['OU']
end

#stateString? Also known as: province

The state or province (ST) entry.

Returns:

Since:

  • 1.0.0



146
147
148
# File 'lib/ronin/support/crypto/cert.rb', line 146

def state
  self['ST']
end