Class: PartnerApi::Utils::ReadCert

Inherits:
Object
  • Object
show all
Defined in:
lib/partner_api/utils/read_cert.rb

Constant Summary collapse

CERT_PATTERN =

A workaround for this issue related to OpenSSL github.com/ruby/openssl/issues/254

/-----BEGIN CERTIFICATE-----(?:.|\n)+?-----END CERTIFICATE-----/

Instance Method Summary collapse

Constructor Details

#initialize(public_certs, private_key) ⇒ ReadCert

Returns a new instance of ReadCert.



8
9
10
11
# File 'lib/partner_api/utils/read_cert.rb', line 8

def initialize(public_certs, private_key)
  @certs = public_certs.scan(CERT_PATTERN)
  @private_key = private_key
end

Instance Method Details

#ssl_contextObject



13
14
15
16
17
18
19
20
21
# File 'lib/partner_api/utils/read_cert.rb', line 13

def ssl_context
  OpenSSL::SSL::SSLContext.new(:TLSv1_2).tap do |ctx|
    ctx.set_params(
      cert: cert,
      key: OpenSSL::PKey::RSA.new(private_key),
      extra_chain_cert: extra_chain_cert
    )
  end
end