Class: Rails::Auth::X509::SubjectAltNameExtension

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/auth/x509/subject_alt_name_extension.rb

Overview

Provides convenience methods for subjectAltName extension of X.509 certificates

Constant Summary collapse

DNS_REGEX =
/^DNS:/i.freeze
IP_REGEX =
/^IP( Address)?:/i.freeze
URI_REGEX =
/^URI:/i.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(certificate) ⇒ SubjectAltNameExtension

Returns a new instance of SubjectAltNameExtension.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rails/auth/x509/subject_alt_name_extension.rb', line 14

def initialize(certificate)
  unless certificate.is_a?(OpenSSL::X509::Certificate)
    raise TypeError, "expecting OpenSSL::X509::Certificate, got #{certificate.class}"
  end

  extension = certificate.extensions.detect { |ext| ext.oid == "subjectAltName" }
  values = (extension&.value&.split(",") || []).map(&:strip)

  @dns_names = values.grep(DNS_REGEX) { |v| v.sub(DNS_REGEX, "") }.freeze
  @ips = values.grep(IP_REGEX) { |v| v.sub(IP_REGEX, "") }.freeze
  @uris = values.grep(URI_REGEX) { |v| v.sub(URI_REGEX, "") }.freeze
end

Instance Attribute Details

#dns_namesObject (readonly)

Returns the value of attribute dns_names.



8
9
10
# File 'lib/rails/auth/x509/subject_alt_name_extension.rb', line 8

def dns_names
  @dns_names
end

#ipsObject (readonly)

Returns the value of attribute ips.



8
9
10
# File 'lib/rails/auth/x509/subject_alt_name_extension.rb', line 8

def ips
  @ips
end

#urisObject (readonly)

Returns the value of attribute uris.



8
9
10
# File 'lib/rails/auth/x509/subject_alt_name_extension.rb', line 8

def uris
  @uris
end