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

- (GeneralName) initialize(asn)

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



79
80
81
82
83
84
85
86
# File 'lib/r509/asn1.rb', line 79

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

Instance Attribute Details

- (Object) short_type (readonly)

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



72
73
74
# File 'lib/r509/asn1.rb', line 72

def short_type
  @short_type
end

- (Object) tag (readonly)

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



76
77
78
# File 'lib/r509/asn1.rb', line 76

def tag
  @tag
end

- (Object) type (readonly)

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



69
70
71
# File 'lib/r509/asn1.rb', line 69

def type
  @type
end

- (Object) value (readonly)

Value of the GeneralName



74
75
76
# File 'lib/r509/asn1.rb', line 74

def value
  @value
end

Class Method Details

+ (String) map_tag_to_short_type(tag)

Serial prefix

Parameters:

  • tag (Integer)

Returns:

  • (String)

    serial prefix



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/r509/asn1.rb', line 116

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

+ (Symbol) map_tag_to_type(tag)

Symbol type

Parameters:

  • tag (Integer)

Returns:

  • (Symbol)

    symbol type



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

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

+ (Integer) map_type_to_tag(type)

Maps a GeneralName type to the integer tag representation

Parameters:

  • type (String, Symbol)

    of GeneralName

Returns:

  • (Integer)

    tag for the type



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/r509/asn1.rb', line 91

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

- (Hash) serialize_name

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

Returns:

  • (Hash)

    conf section and name serialized for OpenSSL extension creation



169
170
171
172
173
174
175
176
# File 'lib/r509/asn1.rb', line 169

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

- (Hash) to_h

Returns:

  • (Hash)


147
148
149
150
151
# File 'lib/r509/asn1.rb', line 147

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

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