Method: Lowdown::Mock.ssl_certificate_and_key

Defined in:
lib/lowdown/mock.rb

.ssl_certificate_and_key(app_bundle_id) ⇒ Array<OpenSSL::X509::Certificate, OpenSSL::PKey::RSA>

Generates a self-signed Universal Certificate.

Parameters:

  • app_bundle_id (String)

    the App ID / app Bundle ID to encode into the certificate.

Returns:

  • (Array<OpenSSL::X509::Certificate, OpenSSL::PKey::RSA>)

    the self-signed certificate and private key.


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lowdown/mock.rb', line 21

def self.ssl_certificate_and_key(app_bundle_id)
  key = OpenSSL::PKey::RSA.new(1024)
  name = OpenSSL::X509::Name.parse("/UID=#{app_bundle_id}/CN=Stubbed APNS Certificate: #{app_bundle_id}")
  cert = OpenSSL::X509::Certificate.new
  cert.subject    = name
  cert.not_before = Time.now
  cert.not_after  = cert.not_before + 3600
  cert.public_key = key.public_key
  cert.sign(key, OpenSSL::Digest::SHA1.new)

  # Make it a Universal Certificate
  ext_name = Lowdown::Certificate::UNIVERSAL_CERTIFICATE_EXTENSION
  ext_value = OpenSSL::ASN1::Sequence.new(
    [
      OpenSSL::ASN1::UTF8String.new(app_bundle_id),
      OpenSSL::ASN1::Sequence.new([OpenSSL::ASN1::UTF8String.new("app")]),
    ]
  ).to_der
  cert.extensions = [OpenSSL::X509::Extension.new(ext_name, ext_value)]

  [cert, key]
end