class Ronin::Support::Crypto::Cert::Name

Represents the ‘Subject` and `Issuer` fields in a X509 Certificate.

@api semipublic

Public Class Methods

build(common_name: nil, email_address: nil, organizational_unit: nil, organization: nil, locality: nil, state: nil, province: nil, country: nil) click to toggle source

Builds a X509 ‘Subject` or `Issuer` string.

@param [String, nil] common_name

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

@param [String, nil] email_address

The email address for the cert (ex: `admin@github.com`).

@param [String, nil] organizational_unit

The organizational unit for the cert.

@param [String, nil] organization

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

@param [String, nil] locality

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

@param [String, nil] state

The state for the cert (ex: `Californa`).

@param [String, nil] province

The province for the cert.

@param [String, nil] country

The country for the cert (ex: `US`).

@return [Name]

The populated name.
# 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

Public Instance Methods

[](oid) click to toggle source

Finds the entry with the given OID name.

@param [String] oid

@return [String, nil]

# File lib/ronin/support/crypto/cert.rb, line 106
def [](oid)
  entries[oid]
end
common_name() click to toggle source

The common name (‘CN`) entry.

@return [String, nil]

# File lib/ronin/support/crypto/cert.rb, line 115
def common_name
  self['CN']
end
country() click to toggle source

The country (‘C`) entry.

@return [String, nil]

# File lib/ronin/support/crypto/cert.rb, line 173
def country
  self['C']
end
email_address() click to toggle source

The email address (‘emailAddress`) entry.

@return [String, nil]

@since 1.1.0

# File lib/ronin/support/crypto/cert.rb, line 126
def email_address
  self['emailAddress']
end
entries() click to toggle source

The parsed entries in the name.

@return [Hash{String => String}]

# 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
Also aliased as: to_h
locality() click to toggle source

The locality (‘L`) entry.

@return [String, nil]

# File lib/ronin/support/crypto/cert.rb, line 153
def locality
  self['L']
end
organization() click to toggle source

The organization (‘O`) entry.

@return [String, nil]

# File lib/ronin/support/crypto/cert.rb, line 135
def organization
  self['O']
end
organizational_unit() click to toggle source

The organizational unit (‘OU`) entry.

@return [String, nil]

# File lib/ronin/support/crypto/cert.rb, line 144
def organizational_unit
  self['OU']
end
province()
Alias for: state
state() click to toggle source

The state or province (‘ST`) entry.

@return [String, nil]

# File lib/ronin/support/crypto/cert.rb, line 162
def state
  self['ST']
end
Also aliased as: province
to_h()
Alias for: entries