apns_simple 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/apns_simple.rb +0 -1
- data/lib/apns_simple/client.rb +14 -10
- data/lib/apns_simple/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 458059ecb443c898d82d6f7bce8f9d6c1cd79386
|
4
|
+
data.tar.gz: e90411dc5d34a7891c2541c37314ebf243f3dbb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdd5ab6692345cd1c317073120775e4d250228d8795b27b7fec998fbb465d3f42fa0496ee8bf19c430a13224f9379edcb73977ed15582c3afb32f2a05798a28d
|
7
|
+
data.tar.gz: 2740ceaf52a4e12934ab9e1e36ab687e2c17967e4047b4e18dfa2c817eadfd5bd199ad09e4d27ef37ef6ba72403c3df273e43e41e609d033d8e6fd82d88f1fa4
|
data/lib/apns_simple.rb
CHANGED
data/lib/apns_simple/client.rb
CHANGED
@@ -4,7 +4,9 @@ require 'socket'
|
|
4
4
|
module ApnsSimple
|
5
5
|
class Client
|
6
6
|
|
7
|
-
|
7
|
+
class CertificateActivenessTimeError < StandardError; end
|
8
|
+
|
9
|
+
attr_reader :ssl_context, :host, :port
|
8
10
|
|
9
11
|
COMMAND = 8
|
10
12
|
CODES = {
|
@@ -22,10 +24,18 @@ module ApnsSimple
|
|
22
24
|
}
|
23
25
|
|
24
26
|
def initialize(options)
|
25
|
-
|
26
|
-
|
27
|
+
certificate = options.fetch(:certificate)
|
28
|
+
current_time = Time.now.utc
|
29
|
+
cert = OpenSSL::X509::Certificate.new(certificate)
|
30
|
+
if current_time < cert.not_before || current_time > cert.not_after
|
31
|
+
raise CertificateActivenessTimeError, "CURRENT_TIME: #{current_time}, NOT_BEFORE: #{cert.not_before}, NOT_AFTER: #{cert.not_after}"
|
32
|
+
end
|
33
|
+
|
27
34
|
@ssl_context = OpenSSL::SSL::SSLContext.new
|
28
|
-
|
35
|
+
ssl_context.cert = cert
|
36
|
+
|
37
|
+
passphrase = options[:passphrase] || ''
|
38
|
+
ssl_context.key = OpenSSL::PKey::RSA.new(certificate, passphrase)
|
29
39
|
|
30
40
|
gateway_uri = options[:gateway_uri] || 'apn://gateway.push.apple.com:2195'
|
31
41
|
@host, @port = parse_gateway_uri(gateway_uri)
|
@@ -33,12 +43,6 @@ module ApnsSimple
|
|
33
43
|
|
34
44
|
def push(notification)
|
35
45
|
begin
|
36
|
-
current_time = Time.now.utc
|
37
|
-
cert = OpenSSL::X509::Certificate.new(certificate)
|
38
|
-
if current_time < cert.not_before || current_time > cert.not_after
|
39
|
-
raise CertificateActivenessTimeError, "CURRENT_TIME: #{current_time}, NOT_BEFORE: #{cert.not_before}, NOT_AFTER: #{cert.not_after}"
|
40
|
-
end
|
41
|
-
ssl_context.cert = cert
|
42
46
|
sock = TCPSocket.new(host, port)
|
43
47
|
ssl = OpenSSL::SSL::SSLSocket.new(sock, ssl_context)
|
44
48
|
ssl.connect
|
data/lib/apns_simple/version.rb
CHANGED