Module: R509::ASN1

Defined in:
lib/r509/asn1.rb

Overview

Module for holding various classes related to parsed ASN.1 objects

Defined Under Namespace

Classes: GeneralName, GeneralNames, NoticeReference, PolicyInformation, PolicyQualifiers, UserNotice

Class Method Summary (collapse)

Class Method Details

+ (R509::ASN1::GeneralNames) general_name_parser(names)

Parameters:

  • names (Array)

    An array of strings. Can be dNSName, iPAddress, URI, or rfc822Name. You can also supply a directoryName, but this must be an R509::Subject or array of arrays

Returns:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/r509/asn1.rb', line 25

def self.general_name_parser(names)
  if names.nil?
    return nil
  end
  general_names = R509::ASN1::GeneralNames.new
  names.map do |domain|
    if !(IPAddr.new(domain.strip) rescue nil).nil?
      ip = IPAddr.new(domain.strip)
      general_names.create_item(:tag => 7, :value => ip.to_s)
    else
      case domain
      when R509::Subject, Array
        subject = R509::Subject.new(domain)
        general_names.create_item(:tag => 4, :value => subject)
      when /:\/\// #URI
        general_names.create_item(:tag => 6, :value => domain.strip)
      when /@/ #rfc822Name
        general_names.create_item(:tag => 1, :value => domain.strip)
      else #dNSName
        general_names.create_item(:tag => 2, :value => domain.strip)
      end
    end
  end
  general_names
end

+ (Object) get_extension_payload(ext)

parses the ASN.1 payload and gets the extension data out for further processing by the subclasses



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/r509/asn1.rb', line 8

def self.get_extension_payload(ext)
  asn = OpenSSL::ASN1.decode ext
  # Our extension object. Here's the structure:
  #   Extension  ::=  SEQUENCE  {
  #        extnID      OBJECT IDENTIFIER,
  #        critical    BOOLEAN DEFAULT FALSE,
  #        extnValue   OCTET STRING
  #                    -- contains the DER encoding of an ASN.1 value
  #                    -- corresponding to the extension type identified
  #                    -- by extnID
  #        }
  OpenSSL::ASN1.decode(asn.entries.last.value).value
end