Class: SSLyze::X509::Extensions::CertificatePolicies

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

Overview

Represents the certificatePolicies X509v3 extension.

Since:

  • 1.0.0

Defined Under Namespace

Classes: Policy

Instance Method Summary collapse

Instance Method Details

#each {|policy| ... } ⇒ Enumerator

Enumerates over every certificate policy in the extension.

Yields:

  • (policy)

    The given block will be passed each parsed policy.

Yield Parameters:

  • policy (Policy)

    A parsed certificate policy.

Returns:

  • (Enumerator)

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

Since:

  • 1.0.0



101
102
103
# File 'lib/sslyze/x509/extensions/certificate_policies.rb', line 101

def each(&block)
  policies.each(&block)
end

#lengthInteger

The number of certificate policies.

Returns:

  • (Integer)

Since:

  • 1.0.0



85
86
87
# File 'lib/sslyze/x509/extensions/certificate_policies.rb', line 85

def length
  policies.length
end

#policiesArray<Policy>

Parses the individual policies listed in the extension's value.

Returns:

Since:

  • 1.0.0



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/sslyze/x509/extensions/certificate_policies.rb', line 62

def policies
  # XXX: ugly multiline regexp to parse the certificate policies and
  # their qualifiers.
  @policies ||= value.scan(/^Policy: [^\n]+\n(?:  [^:]+: [^\n]+\n)*/m).map do |text|
    policy = text.match(/^Policy: ([^\n]+)/)[1]

    cps = if (match = text.match(/^  CPS: ([^\n]+)/m))
            URI.parse(match[1])
          end

    user_notice = if (match = text.match(/^  User Notice: ([^\n]+)/m))
                    match[1]
                  end

    Policy.new(policy, cps: cps, user_notice: user_notice)
  end
end