Class: SSLyze::X509::Extensions::SubjectAltName

Inherits:
SSLyze::X509::Extension show all
Includes:
Enumerable
Defined in:
lib/sslyze/x509/extensions/subject_alt_name.rb

Overview

Represents the subjectAltName X509v3 extension.

Since:

  • 1.0.0

Constant Summary collapse

TYPES =

Known subject name types.

Since:

  • 1.0.0

{
  'DNS' => :dns,
  'IP'  => :ip,
  'URI' => :uri,
  'RID' => :rid,

  'email'     => :email,
  'dirName'   => :dir_name,
  'otherName' => :other_name
}

Instance Method Summary collapse

Instance Method Details

#dir_nameArray<String>

All dirName: alternative names within the extension's value.

Returns:

  • (Array<String>)

Since:

  • 1.0.0



124
125
126
127
128
# File 'lib/sslyze/x509/extensions/subject_alt_name.rb', line 124

def dir_name
  @dir_name ||= select { |type,value| type == :dir_name }.map do |(type,value)|
    value
  end
end

#dnsArray<String>

All DNS: alternative names within the extension's value.

Returns:

  • (Array<String>)

Since:

  • 1.0.0



69
70
71
72
73
# File 'lib/sslyze/x509/extensions/subject_alt_name.rb', line 69

def dns
  @dns ||= select { |type,value| type == :dns }.map do |(type,value)|
    value
  end
end

#each {|type, name| ... } ⇒ Enumerator

Enumerates over every alternative name within the extension's value.

Yields:

  • (type, name)

    The given block will be passed each

Yield Parameters:

  • type (:dns, :ip, :uri, :rid, :email, :dir_name, :other_name)

    The type of the alternative name being yielded.

  • name (String)

    An alternative name within the extension's value.

Returns:

  • (Enumerator)

    If no block is given, an Enumerator will be returned.

Raises:

  • (NotImplementedError)

    An unknown name type was encountered while parsing the extension's value.

Since:

  • 1.0.0



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sslyze/x509/extensions/subject_alt_name.rb', line 50

def each
  return enum_for unless block_given?

  value.split(', ').each do |type_value|
    type, value = type_value.split(':',2)

    unless TYPES.has_key?(type)
      raise(NotImplementedError,"unsupported subjectAltName type: #{type}")
    end

    yield TYPES[type], value
  end
end

#emailArray<String>

All email: alternative names within the extension's value.

Returns:

  • (Array<String>)

Since:

  • 1.0.0



102
103
104
105
106
# File 'lib/sslyze/x509/extensions/subject_alt_name.rb', line 102

def email
  @email ||= select { |type,value| type == :email }.map do |(type,value)|
    value
  end
end

#ipArray<IPAddr>

All IP: alternative names within the extension's value.

Returns:

  • (Array<IPAddr>)

Since:

  • 1.0.0



80
81
82
83
84
# File 'lib/sslyze/x509/extensions/subject_alt_name.rb', line 80

def ip
  @ip ||= select { |type,value| type == :ip }.map do |(type,value)|
    IPAddr.new(value)
  end
end

#other_nameArray<String>

All otherName: alternative names within the extension's value.

Returns:

  • (Array<String>)

Since:

  • 1.0.0



135
136
137
138
139
# File 'lib/sslyze/x509/extensions/subject_alt_name.rb', line 135

def other_name
  @other_name ||= select { |type,value| type == :other_name }.map do |(type,value)|
    value
  end
end

#ridArray<String>

All RID: alternative names within the extension's value.

Returns:

  • (Array<String>)

Since:

  • 1.0.0



113
114
115
116
117
# File 'lib/sslyze/x509/extensions/subject_alt_name.rb', line 113

def rid
  @rid ||= select { |type,value| type == :rid }.map do |(type,value)|
    value
  end
end

#uriArray<URI::Generic>

All URI: alternative names within the extension's value.

Returns:

  • (Array<URI::Generic>)

Since:

  • 1.0.0



91
92
93
94
95
# File 'lib/sslyze/x509/extensions/subject_alt_name.rb', line 91

def uri
  @uri ||= select { |type,value| type == :uri }.map do |(type,value)|
    URI.parse(value)
  end
end