lowdown 0.0.3 → 0.0.4
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/bin/lowdown +4 -4
- data/lib/lowdown/certificate.rb +7 -7
- data/lib/lowdown/client.rb +5 -2
- data/lib/lowdown/{connection/mock.rb → mock.rb} +38 -4
- data/lib/lowdown/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fa2be0e57306efb793fb262856aa2a1bea16c03
|
4
|
+
data.tar.gz: 151af85c92ff4c4553244f78c70721bf41cc31a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6aab49b75690c5aac492d6d1ffd137bb5b548b2377e7f391e2bb7095b03661a80ba920388e89e24f1f2f24826946b81274e94d12cdf49bf9d737e80db539289
|
7
|
+
data.tar.gz: e0ccfd14e17cbe9b7e96b2401ea493396eab4a0acd72c472b4383dd95c3b20e0aab469ebdba38d663648dd09a26d2cd235ff95cd7d472f026a5e5cd91170ae0e
|
data/bin/lowdown
CHANGED
@@ -45,7 +45,7 @@ OPTION_PARSER = OptionParser.new do |opts|
|
|
45
45
|
options[:topic] = topic
|
46
46
|
end
|
47
47
|
|
48
|
-
opts.on("-e", "--environment ENV", "Environment to send push notification (production or development), defaults to certificate
|
48
|
+
opts.on("-e", "--environment ENV", "Environment to send push notification (production or development), defaults to production if the certificate supports that or otherwise development") do |env|
|
49
49
|
options[:env] = env
|
50
50
|
end
|
51
51
|
|
@@ -81,10 +81,10 @@ if options[:env]
|
|
81
81
|
end
|
82
82
|
production = options[:env] == "production"
|
83
83
|
else
|
84
|
-
if certificate.
|
85
|
-
production = false
|
86
|
-
elsif certificate.production?
|
84
|
+
if certificate.production?
|
87
85
|
production = true
|
86
|
+
elsif certificate.development?
|
87
|
+
production = false
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
data/lib/lowdown/certificate.rb
CHANGED
@@ -18,17 +18,17 @@ module Lowdown
|
|
18
18
|
def self.from_pem_data(data, passphrase = nil)
|
19
19
|
key = OpenSSL::PKey::RSA.new(data, passphrase)
|
20
20
|
certificate = OpenSSL::X509::Certificate.new(data)
|
21
|
-
new(
|
21
|
+
new(certificate, key)
|
22
22
|
end
|
23
23
|
|
24
24
|
attr_reader :key, :certificate
|
25
25
|
|
26
|
-
def initialize(
|
26
|
+
def initialize(certificate, key = nil)
|
27
27
|
@key, @certificate = key, certificate
|
28
28
|
end
|
29
29
|
|
30
30
|
def to_pem
|
31
|
-
|
31
|
+
[@key, @certificate].compact.map(&:to_pem).join("\n")
|
32
32
|
end
|
33
33
|
|
34
34
|
def ssl_context
|
@@ -59,14 +59,14 @@ module Lowdown
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
def app_bundle_id
|
63
|
+
@certificate.subject.to_a.find { |key, *_| key == 'UID' }[1]
|
64
|
+
end
|
65
|
+
|
62
66
|
private
|
63
67
|
|
64
68
|
def extension(oid)
|
65
69
|
@certificate.extensions.find { |ext| ext.oid == oid }
|
66
70
|
end
|
67
|
-
|
68
|
-
def app_bundle_id
|
69
|
-
@certificate.subject.to_a.find { |key, *_| key == 'UID' }[1]
|
70
|
-
end
|
71
71
|
end
|
72
72
|
end
|
data/lib/lowdown/client.rb
CHANGED
@@ -26,8 +26,11 @@ module Lowdown
|
|
26
26
|
|
27
27
|
def self.client(uri, certificate_or_data)
|
28
28
|
certificate = Lowdown.Certificate(certificate_or_data)
|
29
|
-
|
30
|
-
|
29
|
+
client_with_connection(Connection.new(uri, certificate.ssl_context), certificate)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.client_with_connection(connection, certificate)
|
33
|
+
new(connection, certificate.universal? ? certificate.topics.first : nil)
|
31
34
|
end
|
32
35
|
|
33
36
|
attr_reader :connection, :default_topic
|
@@ -1,14 +1,48 @@
|
|
1
|
+
require "lowdown/certificate"
|
2
|
+
require "lowdown/client"
|
1
3
|
require "lowdown/response"
|
2
4
|
|
3
5
|
module Lowdown
|
4
|
-
|
5
|
-
|
6
|
+
module Mock
|
7
|
+
def self.ssl_certificate_and_key(app_bundle_id)
|
8
|
+
key = OpenSSL::PKey::RSA.new(1024)
|
9
|
+
name = OpenSSL::X509::Name.parse("/UID=#{app_bundle_id}/CN=Stubbed APNS Certificate: #{app_bundle_id}")
|
10
|
+
cert = OpenSSL::X509::Certificate.new
|
11
|
+
cert.subject = name
|
12
|
+
cert.not_before = Time.now
|
13
|
+
cert.not_after = cert.not_before + 3600
|
14
|
+
cert.public_key = key.public_key
|
15
|
+
cert.sign(key, OpenSSL::Digest::SHA1.new)
|
16
|
+
|
17
|
+
# Make it a Universal Certificate
|
18
|
+
ext_name = Lowdown::Certificate::UNIVERSAL_CERTIFICATE_EXTENSION
|
19
|
+
cert.extensions = [OpenSSL::X509::Extension.new(ext_name, "0d..#{app_bundle_id}0...app")]
|
20
|
+
|
21
|
+
[cert, key]
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.certificate(app_bundle_id)
|
25
|
+
Certificate.new(*ssl_certificate_and_key(app_bundle_id))
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.client(uri: nil, app_bundle_id: "com.example.MockApp")
|
29
|
+
certificate = certificate(app_bundle_id)
|
30
|
+
connection = Connection.new(uri: uri, ssl_context: certificate.ssl_context)
|
31
|
+
Client.client_with_connection(connection, certificate)
|
32
|
+
end
|
33
|
+
|
34
|
+
class Connection
|
6
35
|
Request = Struct.new(:path, :headers, :body, :response)
|
7
36
|
|
37
|
+
# Mock API
|
8
38
|
attr_reader :requests, :responses
|
9
39
|
|
10
|
-
|
11
|
-
|
40
|
+
# Real API
|
41
|
+
attr_reader :uri, :ssl_context
|
42
|
+
|
43
|
+
def initialize(uri: nil, ssl_context: nil)
|
44
|
+
@uri, @ssl_context = uri, ssl_context
|
45
|
+
@responses = []
|
12
46
|
@requests = []
|
13
47
|
end
|
14
48
|
|
data/lib/lowdown/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lowdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eloy Durán
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http-2
|
@@ -86,7 +86,7 @@ files:
|
|
86
86
|
- lib/lowdown/certificate.rb
|
87
87
|
- lib/lowdown/client.rb
|
88
88
|
- lib/lowdown/connection.rb
|
89
|
-
- lib/lowdown/
|
89
|
+
- lib/lowdown/mock.rb
|
90
90
|
- lib/lowdown/notification.rb
|
91
91
|
- lib/lowdown/response.rb
|
92
92
|
- lib/lowdown/threading.rb
|