Sha256: fb4964a81a91ea8306d1ae96242fff967a8e341b0f7ba14c67ffc58283ed88e0
Contents?: true
Size: 1003 Bytes
Versions: 6
Compression:
Stored size: 1003 Bytes
Contents
# frozen_string_literal: true module Rails module Auth module X509 # Provides convenience methods for subjectAltName extension of X.509 certificates class SubjectAltNameExtension attr_reader :dns_names, :ips, :uris DNS_REGEX = /^DNS:/i.freeze IP_REGEX = /^IP( Address)?:/i.freeze URI_REGEX = /^URI:/i.freeze 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 end end end end
Version data entries
6 entries across 6 versions & 1 rubygems