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, email_address: 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).

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

    The email address for the cert (ex: admin@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



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ronin/support/crypto/cert.rb', line 73

def self.build(common_name: nil, email_address: 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('emailAddress',email_address) if email_address
  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



106
107
108
# File 'lib/ronin/support/crypto/cert.rb', line 106

def [](oid)
  entries[oid]
end

#common_nameString?

The common name (CN) entry.

Returns:

Since:

  • 1.0.0



115
116
117
# File 'lib/ronin/support/crypto/cert.rb', line 115

def common_name
  self['CN']
end

#countryString?

The country (C) entry.

Returns:

Since:

  • 1.0.0



173
174
175
# File 'lib/ronin/support/crypto/cert.rb', line 173

def country
  self['C']
end

#email_addressString?

The email address (emailAddress) entry.

Returns:

Since:

  • 1.1.0



126
127
128
# File 'lib/ronin/support/crypto/cert.rb', line 126

def email_address
  self['emailAddress']
end

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

The parsed entries in the name.

Returns:

Since:

  • 1.0.0



91
92
93
94
95
# File 'lib/ronin/support/crypto/cert.rb', line 91

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



153
154
155
# File 'lib/ronin/support/crypto/cert.rb', line 153

def locality
  self['L']
end

#organizationString?

The organization (O) entry.

Returns:

Since:

  • 1.0.0



135
136
137
# File 'lib/ronin/support/crypto/cert.rb', line 135

def organization
  self['O']
end

#organizational_unitString?

The organizational unit (OU) entry.

Returns:

Since:

  • 1.0.0



144
145
146
# File 'lib/ronin/support/crypto/cert.rb', line 144

def organizational_unit
  self['OU']
end

#stateString? Also known as: province

The state or province (ST) entry.

Returns:

Since:

  • 1.0.0



162
163
164
# File 'lib/ronin/support/crypto/cert.rb', line 162

def state
  self['ST']
end