Class: R509::ASN1::GeneralName

Inherits:
Object
  • Object
show all
Defined in:
lib/r509/asn1.rb

Overview

This class parses ASN.1 GeneralName objects. At the moment it supports rfc822Name, dNSName, directoryName, uniformResourceIdentifier, and iPAddress

GeneralName ::= CHOICE {
     otherName                       [0]     OtherName,
     rfc822Name                      [1]     IA5String,
     dNSName                         [2]     IA5String,
     x400Address                     [3]     ORAddress,
     directoryName                   [4]     Name,
     ediPartyName                    [5]     EDIPartyName,
     uniformResourceIdentifier       [6]     IA5String,
     iPAddress                       [7]     OCTET STRING,
     registeredID                    [8]     OBJECT IDENTIFIER }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(asn) ⇒ GeneralName

Returns a new instance of GeneralName

Parameters:

  • asn (OpenSSL::ASN1::ASN1Data, Hash)

    ASN.1 input data. Can also pass a hash with (:tag or :type) and :value keys



93
94
95
96
97
98
99
100
# File 'lib/r509/asn1.rb', line 93

def initialize(asn)
  if asn.is_a?(Hash)
    # this is added via create_item
    parse_hash(asn)
  else
    parse_asn(asn)
  end
end

Instance Attribute Details

#short_typeObject (readonly)

The prefix OpenSSL needs for this type when encoding it into an extension. Also used by the YAML serialization in the extensions



86
87
88
# File 'lib/r509/asn1.rb', line 86

def short_type
  @short_type
end

#tagObject (readonly)

Integer tag type. See GeneralName description at the top of this class



90
91
92
# File 'lib/r509/asn1.rb', line 90

def tag
  @tag
end

#typeObject (readonly)

The type, represented as a symbolized version of the GeneralName (e.g. :dNSName)



83
84
85
# File 'lib/r509/asn1.rb', line 83

def type
  @type
end

#valueObject (readonly)

Value of the GeneralName



88
89
90
# File 'lib/r509/asn1.rb', line 88

def value
  @value
end

Class Method Details

.map_tag_to_short_type(tag) ⇒ String

Returns serial prefix

Parameters:

  • tag (Integer)

Returns:

  • (String)

    serial prefix



130
131
132
133
134
135
136
137
138
139
140
# File 'lib/r509/asn1.rb', line 130

def self.map_tag_to_short_type(tag)
  case tag
  when 1 then "email"
  when 2 then "DNS"
  when 4 then "dirName"
  when 6 then "URI"
  when 7 then "IP"
  else
    raise R509Error, "Unimplemented GeneralName tag: #{tag}. At this time R509 does not support GeneralName types other than rfc822Name, dNSName, uniformResourceIdentifier, iPAddress, and directoryName"
  end
end

.map_tag_to_type(tag) ⇒ Symbol

Returns symbol type

Parameters:

  • tag (Integer)

Returns:

  • (Symbol)

    symbol type



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/r509/asn1.rb', line 144

def self.map_tag_to_type(tag)
  case tag
  when 0 then :otherName
  when 1 then :rfc822Name
  when 2 then :dNSName
  when 3 then :x400Address
  when 4 then :directoryName
  when 5 then :ediPartyName
  when 6 then :uniformResourceIdentifier
  when 7 then :iPAddress
  when 8 then :registeredID
  else
    raise R509Error, "Invalid tag #{tag}"
  end
end

.map_type_to_tag(type) ⇒ Integer

Maps a GeneralName type to the integer tag representation

Parameters:

  • type (String, Symbol)

    of GeneralName

Returns:

  • (Integer)

    tag for the type



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/r509/asn1.rb', line 105

def self.map_type_to_tag(type)
  #        otherName                       [0]     OtherName,
  #        rfc822Name                      [1]     IA5String,
  #        dNSName                         [2]     IA5String,
  #        x400Address                     [3]     ORAddress,
  #        directoryName                   [4]     Name,
  #        ediPartyName                    [5]     EDIPartyName,
  #        uniformResourceIdentifier       [6]     IA5String,
  #        iPAddress                       [7]     OCTET STRING,
  #        registeredID                    [8]     OBJECT IDENTIFIER }
  case type
  when "otherName", :otherName then 0
  when "rfc822Name", :rfc822Name, "email" then 1
  when "dNSName", :dNSName, "DNS" then 2
  when "x400Address", :x400Address then 3
  when "directoryName", :directoryName, "dirName" then 4
  when "ediPartyName", :ediPartyName  then 5
  when "uniformResourceIdentifier", :uniformResourceIdentifier, "URI" then 6
  when "iPAddress", :iPAddress, "IP" then 7
  when "registeredID", :registeredID  then 8
  end
end

Instance Method Details

#serialize_nameHash

Used to serialize GeneralName objects when issuing new certificates inside R509::CertificateAuthority::Signer

Returns:

  • (Hash)

    conf section and name serialized for OpenSSL extension creation



183
184
185
186
187
188
189
190
# File 'lib/r509/asn1.rb', line 183

def serialize_name
  if self.type == :directoryName
    return serialize_directory_name
  else
    extension_string = self.short_type + ":" + self.value
    return { :conf => nil, :extension_string => extension_string }
  end
end

#to_hHash

Returns:

  • (Hash)


161
162
163
164
165
# File 'lib/r509/asn1.rb', line 161

def to_h
  val = (@value.is_a?(R509::Subject)) ? @value.to_h : @value

  { :type => @short_type, :value => val }
end