Class: Ronin::DB::CertOrganization

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Model
Defined in:
lib/ronin/db/cert_organization.rb

Overview

Base class for CertIssuer and CertSubject.

Since:

  • 0.2.0

Direct Known Subclasses

CertIssuer, CertSubject

Constant Summary collapse

X509_ATTRIBUTES =

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

Mapping of X509 names to Symbols.

Since:

  • 0.2.0

{
  'CN'           => :common_name,
  'emailAddress' => :email_address,
  'O'            => :organization,
  'OU'           => :organizational_unit,
  'L'            => :locality,
  'ST'           => :state,
  'C'            => :country
}

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from Model

included

Instance Attribute Details

#countryString

The two letter country code (C).

Returns:

  • (String)


71
# File 'lib/ronin/db/cert_organization.rb', line 71

attribute :country, :string

#created_atTime

When the organization was first created.

Returns:

  • (Time)


79
# File 'lib/ronin/db/cert_organization.rb', line 79

attribute :created_at, :datetime

#idInteger

The primary key of the certificate organization.

Returns:

  • (Integer)


40
# File 'lib/ronin/db/cert_organization.rb', line 40

attribute :id, :integer

#localityString?

The locality (L)..

Returns:

  • (String, nil)


59
# File 'lib/ronin/db/cert_organization.rb', line 59

attribute :locality, :string

#organizationString

The organization name (O).

Returns:

  • (String)


46
# File 'lib/ronin/db/cert_organization.rb', line 46

attribute :organization, :string

#organizational_unitString?

The organizational unit (OU).

Returns:

  • (String, nil)


53
# File 'lib/ronin/db/cert_organization.rb', line 53

attribute :organizational_unit, :string

#stateString?

The state (ST).

Returns:

  • (String, nil)


65
# File 'lib/ronin/db/cert_organization.rb', line 65

attribute :state, :string

Class Method Details

.parse(name) ⇒ Hash{Symbol => String}

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.

Parses an X509 Name into attributes.

Parameters:

  • name (OpenSSL::X509::Name, String)

    The X509 name to parse.

Returns:

  • (Hash{Symbol => String})

    The parsed attributes.

Since:

  • 0.2.0



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/ronin/db/cert_organization.rb', line 105

def self.parse(name)
  x509_name = case name
              when OpenSSL::X509::Name then name
              when String
                OpenSSL::X509::Name.parse(name)
              else
                raise(ArgumentError,"value must be either an OpenSSL::X509::Name or a String: #{name.inspect}")
              end

  attributes = {}

  x509_name.to_a.each do |(oid,value,type)|
    if (key = X509_ATTRIBUTES[oid])
      attributes[key] = value.force_encoding(Encoding::UTF_8)
    end
  end

  return attributes
end