webpush 0.3.6 → 0.3.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e6318084376fd3bac8eac5d32a4cae9fdcdddecd61970489981d7789045a311
4
- data.tar.gz: 5d855613fdbebddf56563d571969f964da0edd24361f12472dd9f3ee641145d7
3
+ metadata.gz: 1a7dfdadec9ade5140f48e4b7643202630c9e14700e8366011464b0c6d3bfade
4
+ data.tar.gz: 6e8bed89a1abd252c703f1f79e865e23d69a5cd6e973709bd1e86d85977fb893
5
5
  SHA512:
6
- metadata.gz: 7bb6f34b88a6246584e5b004598d044a2a7aa872d8be8889d53d4231262934e9431e293ac1ebb9622c24b483afbb393ff46617c3506b0d19d819cac49ee26677
7
- data.tar.gz: 5b653bbcc07b7e46949387180c67eabcba8c994961c99a76f5979cb332aa0204bf524a87d237c762e507a383b56b291a5770174840561727a471c8b19855d9f6
6
+ metadata.gz: bf031e189b8d2637968605500b14abd1c3941f1ff8229ebf2131e5e6c4343badff7295f308c5a192fcccfeca90ad696873f891f47ead43fd3398057333786ce2
7
+ data.tar.gz: 3b3097ce59cb726d4009cb8dc5e7c5b17a330b4cd8a5f97a9dd424c337f91a1c3570d5ef9459e69be3a5f61cbf42eee8536b110716d373744df78e7ae74da741
@@ -1,5 +1,14 @@
1
1
  # Change Log
2
2
 
3
+ ## [v0.3.6](https://github.com/zaru/webpush/tree/v0.3.6) (2019-01-09)
4
+ [Full Changelog](https://github.com/zaru/webpush/compare/v0.3.5...v0.3.6)
5
+
6
+ **Merged pull requests:**
7
+
8
+ - Added a error class to arguments of raise\_error [\#62](https://github.com/zaru/webpush/pull/62) ([zaru](https://github.com/zaru))
9
+ - Fix TravisCI bundler version [\#61](https://github.com/zaru/webpush/pull/61) ([zaru](https://github.com/zaru))
10
+ - Raise Webpush::Unauthorized on HTTP 403 [\#59](https://github.com/zaru/webpush/pull/59) ([collimarco](https://github.com/collimarco))
11
+
3
12
  ## [v0.3.5](https://github.com/zaru/webpush/tree/v0.3.5) (2019-01-02)
4
13
  [Full Changelog](https://github.com/zaru/webpush/compare/v0.3.4...v0.3.5)
5
14
 
data/README.md CHANGED
@@ -45,6 +45,9 @@ vapid_key = Webpush.generate_key
45
45
  # Save these in your application server settings
46
46
  vapid_key.public_key
47
47
  vapid_key.private_key
48
+
49
+ # Or you can save in PEM format if you prefer
50
+ vapid_key.to_pem
48
51
  ```
49
52
 
50
53
  ### Declaring manifest.json
@@ -281,6 +284,23 @@ Webpush.payload_send(
281
284
  )
282
285
  ```
283
286
 
287
+ ### With VAPID in PEM format
288
+
289
+ This library also supports the PEM format for the VAPID keys:
290
+
291
+ ```ruby
292
+ Webpush.payload_send(
293
+ endpoint: "https://fcm.googleapis.com/gcm/send/eah7hak....",
294
+ message: "A message",
295
+ p256dh: "BO/aG9nYXNkZmFkc2ZmZHNmYWRzZmFl...",
296
+ auth: "aW1hcmthcmFpa3V6ZQ==",
297
+ vapid: {
298
+ subject: "mailto:sender@example.com"
299
+ pem: ENV['VAPID_KEYS']
300
+ }
301
+ )
302
+ ```
303
+
284
304
  ### With GCM api key
285
305
 
286
306
  ```ruby
@@ -70,7 +70,7 @@ module Webpush
70
70
  end
71
71
 
72
72
  def build_vapid_headers
73
- vapid_key = VapidKey.from_keys(vapid_public_key, vapid_private_key)
73
+ vapid_key = vapid_pem ? VapidKey.from_pem(vapid_pem) : VapidKey.from_keys(vapid_public_key, vapid_private_key)
74
74
  jwt = JWT.encode(jwt_payload, vapid_key.curve, 'ES256', jwt_header_fields)
75
75
  p256ecdsa = vapid_key.public_key_for_push_header
76
76
 
@@ -138,6 +138,10 @@ module Webpush
138
138
  @vapid_options.fetch(:private_key, nil)
139
139
  end
140
140
 
141
+ def vapid_pem
142
+ @vapid_options.fetch(:pem, nil)
143
+ end
144
+
141
145
  def default_options
142
146
  {
143
147
  ttl: 60*60*24*7*4, # 4 weeks
@@ -14,6 +14,18 @@ module Webpush
14
14
  key
15
15
  end
16
16
 
17
+ # Create a VapidKey instance from pem encoded elliptic curve public and private keys
18
+ #
19
+ # @return [Webpush::VapidKey] a VapidKey instance for the given public and private keys
20
+ def self.from_pem(pem)
21
+ key = new
22
+ src = OpenSSL::PKey.read pem
23
+ key.curve.public_key = src.public_key
24
+ key.curve.private_key = src.private_key
25
+
26
+ key
27
+ end
28
+
17
29
  attr_reader :curve
18
30
 
19
31
  def initialize
@@ -63,6 +75,13 @@ module Webpush
63
75
  end
64
76
  alias to_hash to_h
65
77
 
78
+ def to_pem
79
+ public_key = OpenSSL::PKey::EC.new curve
80
+ public_key.private_key = nil
81
+
82
+ curve.to_pem + public_key.to_pem
83
+ end
84
+
66
85
  def inspect
67
86
  "#<#{self.class}:#{object_id.to_s(16)} #{to_h.map { |k, v| ":#{k}=#{v}" }.join(" ")}>"
68
87
  end
@@ -1,3 +1,3 @@
1
1
  module Webpush
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpush
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - zaru@sakuraba
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-09 00:00:00.000000000 Z
11
+ date: 2019-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hkdf
@@ -168,7 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  - !ruby/object:Gem::Version
169
169
  version: '0'
170
170
  requirements: []
171
- rubygems_version: 3.0.1
171
+ rubyforge_project:
172
+ rubygems_version: 2.7.6
172
173
  signing_key:
173
174
  specification_version: 4
174
175
  summary: Encryption Utilities for Web Push payload.