push_package 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 993a2f7345ad1bee0c5aa221936e44e322f63b39
4
- data.tar.gz: 09023bbe6ad97d1ebc1e3a97c7b028114aea0ec3
3
+ metadata.gz: ceeed08b5a9b3d2df6e2d0deb154dd29d4802724
4
+ data.tar.gz: 5a8959ed6ad5ea9e6deb348ad90e2e878d1d8e55
5
5
  SHA512:
6
- metadata.gz: e3ee7036717ed8f3ab09912d0fc56ed497c2f13c3472371f6fd3c7cb305ee88a45b898db5a2fa69262693382a94bd3bd891767be1dbc14f0cc10039e18cfb912
7
- data.tar.gz: f479ef6728e2744759ca348d28afc42f730d5e72c40c006835b3324cef2759fe2b0265506737af66d8800a81624fc327f06597f842c27cf928593b2f1204e386
6
+ metadata.gz: 422bf6d6411be5bc2731166c54ef836c7abceffe3a99ac208f02d105f529c2ce2101919e6ef94b05290cb1edd08604706b83009daf89c00b950bfd28ac8c36be
7
+ data.tar.gz: 01688a3ef558699b13f42ed3332608fcd0fc7cccad8189b540df535dc65de350274c07f6d696a29d8c45612cae68130af91a5e6aa48c698c945036a9f68ba52e
data/lib/push_package.rb CHANGED
@@ -13,7 +13,7 @@ class PushPackage
13
13
  REQUIRED_WEBSITE_PARAMS = ["websiteName", "websitePushID", "allowedDomains", "urlFormatString", "authenticationToken", "webServiceURL"]
14
14
  REQUIRED_ICONSET_FILES = ["icon_16x16.png", "icon_16x16@2x.png", "icon_32x32.png", "icon_32x32@2x.png", "icon_128x128.png", "icon_128x128@2x.png" ]
15
15
 
16
- attr_reader :p12
16
+ attr_reader :certificate, :pkey
17
17
 
18
18
  def initialize(website_params, iconset_path, certificate, password = nil, intermediate_cert = nil)
19
19
  raise InvalidParameterError unless valid_website_params?(website_params)
@@ -34,7 +34,14 @@ class PushPackage
34
34
  #ensure binary data for jruby.
35
35
  cert_data.force_encoding(Encoding::ASCII_8BIT)
36
36
  end
37
- @p12 = OpenSSL::PKCS12.new(cert_data, password)
37
+ if pem?(cert_data)
38
+ @certificate = OpenSSL::X509::Certificate.new(cert_data)
39
+ @pkey = OpenSSL::PKey::RSA.new(cert_data)
40
+ else
41
+ p12 = OpenSSL::PKCS12.new(cert_data, password)
42
+ @certificate = p12.certificate
43
+ @pkey = p12.key
44
+ end
38
45
 
39
46
  if intermediate_cert
40
47
  intermediate_cert_data = File.read(intermediate_cert)
@@ -92,7 +99,15 @@ class PushPackage
92
99
 
93
100
  def signature
94
101
  #use the certificate to create a pkcs7 detached signature
95
- OpenSSL::PKCS7::sign(@p12.certificate, @p12.key, manifest_data, @extra_certs, OpenSSL::PKCS7::BINARY | OpenSSL::PKCS7::DETACHED)
102
+ OpenSSL::PKCS7::sign(@certificate, @pkey, manifest_data, @extra_certs, OpenSSL::PKCS7::BINARY | OpenSSL::PKCS7::DETACHED)
103
+ end
104
+
105
+ def pem?(cert_data)
106
+ begin
107
+ cert_data =~ /BEGIN CERTIFICATE/ && cert_data =~ /PRIVATE KEY/
108
+ rescue
109
+ false
110
+ end
96
111
  end
97
112
 
98
113
  def manifest_data
@@ -1,3 +1,3 @@
1
1
  class PushPackage
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
@@ -0,0 +1,53 @@
1
+ Bag Attributes
2
+ localKeyID: 93 78 7F 99 71 62 1D 88 CD 43 36 22 DA 6B 26 AC 87 B3 AE 9F
3
+ subject=/C=US/ST=MA/L=Cambridge/O=Twitter/CN=localhost
4
+ issuer=/C=US/ST=MA/L=Cambridge/O=Twitter/CN=localhost
5
+ -----BEGIN CERTIFICATE-----
6
+ MIIDJDCCAgwCCQD1K/B5O4YXDzANBgkqhkiG9w0BAQUFADBUMQswCQYDVQQGEwJV
7
+ UzELMAkGA1UECBMCTUExEjAQBgNVBAcTCUNhbWJyaWRnZTEQMA4GA1UEChMHVHdp
8
+ dHRlcjESMBAGA1UEAxMJbG9jYWxob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+Bl48AlVEHvygo8+BepNFEMpW3QuKcDn9z
43
+ HjWYk9+L93pfCAvcg9Dq9GoJV4uSMpVG3UjJCfJve2FDAEO4ydDlrG3J/fGBWvqV
44
+ 1qTfW2DOjy6AtP1BsgaE3M95GwXHVxETBJuVLwE9AoGAK6GchNpgGC9caP2Pa8DC
45
+ u99K5pr93GfOPLLqHQMNKrxzEvtmVjE4XDNpjkhKquRbeUUK8sm2iMgYXYEOtWpW
46
+ upDp4koIE2fS2eyBlgWJlhvBYAM5mwUGx7GZLXk27Ckf8vN9so1DFURlF/UUw0zY
47
+ 9dhddA9zH5ZwJZgRsLOJvr0CgYEAgDaKSrg2IQmgoLTo+rIaz0eF2x4f50r0EZ8s
48
+ 5MWmN0re6ysXn/P6FnSYyKz594hUZnFMsO0EApKAEPsQNcdxW4O6I9TdWyz+AAlK
49
+ o1FYve1H3V6nnvvs7rU3iC1jff4u2ma8zRV2a+9hlK7j6H3Cu+zL7GOaqTOJKGwx
50
+ e2cGoOECgYEA2nG7rX7Xq8xa5WjeN1nnFVzmlj0iPqBEJNAXNQ+o9tsBPFm1rGlg
51
+ VszYIRfrtPFVtacCXOxBqGgIpFYKJr3MF+AEhU3e2ilJgO98HGBLRcX6AM73wfOq
52
+ SnyuQs9m2EyJyxoT17rm5TiSRRfnLxKeSSv/lpPV4kqkxLY3nreI0uY=
53
+ -----END RSA PRIVATE KEY-----
@@ -185,15 +185,33 @@ describe PushPackage do
185
185
  signature = File.read(tmp_path + '/signature')
186
186
  p7 = OpenSSL::PKCS7.new(signature)
187
187
  store = OpenSSL::X509::Store.new
188
- store.add_cert(push_package.p12.certificate)
188
+ store.add_cert(push_package.certificate)
189
189
  p7.verify(
190
- [push_package.p12.certificate],
190
+ [push_package.certificate],
191
191
  store,
192
192
  File.read(tmp_path + '/manifest.json'),
193
193
  OpenSSL::PKCS7::DETACHED
194
194
  ).must_equal true
195
195
  end
196
196
 
197
+ describe 'when using a pem file' do
198
+ let(:certificate) { File.open(fixture_path('self-signed.pem')) }
199
+
200
+ it 'should have a valid signature' do
201
+ extracted_package.must_include('signature')
202
+ signature = File.read(tmp_path + '/signature')
203
+ p7 = OpenSSL::PKCS7.new(signature)
204
+ store = OpenSSL::X509::Store.new
205
+ store.add_cert(push_package.certificate)
206
+ p7.verify(
207
+ [push_package.certificate],
208
+ store,
209
+ File.read(tmp_path + '/manifest.json'),
210
+ OpenSSL::PKCS7::DETACHED
211
+ ).must_equal true
212
+ end
213
+ end
214
+
197
215
  it 'should have no extra certs in signature' do
198
216
  extracted_package.must_include('signature')
199
217
  signature = File.read(tmp_path + '/signature')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: push_package
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Natchev
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-04 00:00:00.000000000 Z
12
+ date: 2016-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubyzip
@@ -116,6 +116,7 @@ files:
116
116
  - spec/fixtures/localhost.key
117
117
  - spec/fixtures/manifest.json
118
118
  - spec/fixtures/self-signed.p12
119
+ - spec/fixtures/self-signed.pem
119
120
  - spec/fixtures/signature
120
121
  - spec/push_package_spec.rb
121
122
  - spec/spec_helper.rb
@@ -156,6 +157,7 @@ test_files:
156
157
  - spec/fixtures/localhost.key
157
158
  - spec/fixtures/manifest.json
158
159
  - spec/fixtures/self-signed.p12
160
+ - spec/fixtures/self-signed.pem
159
161
  - spec/fixtures/signature
160
162
  - spec/push_package_spec.rb
161
163
  - spec/spec_helper.rb