Class: ApnsKit::Certificate
- Inherits:
-
Object
- Object
- ApnsKit::Certificate
- Defined in:
- lib/apns_kit/certificate.rb
Class Method Summary collapse
Instance Method Summary collapse
- #app_bundle_id ⇒ Object
- #development? ⇒ Boolean
-
#initialize(key, certificate) ⇒ Certificate
constructor
A new instance of Certificate.
- #production? ⇒ Boolean
- #ssl_context ⇒ Object
- #universal? ⇒ Boolean
Constructor Details
#initialize(key, certificate) ⇒ Certificate
Returns a new instance of Certificate.
19 20 21 22 |
# File 'lib/apns_kit/certificate.rb', line 19 def initialize(key, certificate) @key = key @certificate = certificate end |
Class Method Details
.from_p12_file(data, passphrase = nil) ⇒ Object
6 7 8 9 |
# File 'lib/apns_kit/certificate.rb', line 6 def from_p12_file(data, passphrase = nil) p12 = OpenSSL::PKCS12.new(data, passphrase) ApnsKit::Certificate.new(p12.key, p12.certificate) end |
.from_pem_file(data, passphrase = nil) ⇒ Object
11 12 13 14 15 |
# File 'lib/apns_kit/certificate.rb', line 11 def from_pem_file(data, passphrase = nil) key = OpenSSL::PKey::RSA.new(data, passphrase) certificate = OpenSSL::X509::Certificate.new(data) ApnsKit::Certificate.new(key, certificate) end |
Instance Method Details
#app_bundle_id ⇒ Object
43 44 45 |
# File 'lib/apns_kit/certificate.rb', line 43 def app_bundle_id @app_bundle_id ||= @certificate.subject.to_a.find { |key, *_| key == "UID" }[1] end |
#development? ⇒ Boolean
35 36 37 |
# File 'lib/apns_kit/certificate.rb', line 35 def development? extension(DEVELOPMENT_ENV_EXTENSION).present? end |
#production? ⇒ Boolean
31 32 33 |
# File 'lib/apns_kit/certificate.rb', line 31 def production? extension(PRODUCTION_ENV_EXTENSION).present? end |
#ssl_context ⇒ Object
24 25 26 27 28 29 |
# File 'lib/apns_kit/certificate.rb', line 24 def ssl_context @ssl_context ||= OpenSSL::SSL::SSLContext.new.tap do |context| context.key = @key context.cert = @certificate end end |
#universal? ⇒ Boolean
39 40 41 |
# File 'lib/apns_kit/certificate.rb', line 39 def universal? extension(UNIVERSAL_CERTIFICATE_EXTENSION).present? end |