web-push 3.0.0 → 3.0.2
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/.github/workflows/ci.yml +3 -3
- data/LICENSE +1 -1
- data/README.md +12 -4
- data/lib/web_push/encryption.rb +4 -3
- data/lib/web_push/version.rb +1 -1
- data/lib/web_push.rb +0 -5
- data/spec/spec_helper.rb +5 -2
- data/spec/web_push/encryption_spec.rb +3 -3
- data/spec/web_push_spec.rb +12 -0
- data/web-push.gemspec +1 -2
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a90ad96aa12a10002ba31de9ac2b082abcce714bcb3e7b54e97d702cfd12af0
|
4
|
+
data.tar.gz: c04841ffa17ba33182087413b2b6a266ca08f0370510392df635dc040be6f34c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6d24148fb7b252602028ba38200a3b8d156ece2f5b4fafefdaeae61e8c78718fb8e9d70f58dac356d96e7a455007f0a6d5d422062321fe600ee7783b08d6dde
|
7
|
+
data.tar.gz: 451223df83c431f13ed1da1abb3c074c03e57674180f37bd81abc5156309a8e5582380839bbcb5ba3ec23301ae0b7165083ffa15078b788714f09e6eeea92e6f
|
data/.github/workflows/ci.yml
CHANGED
@@ -9,11 +9,11 @@ jobs:
|
|
9
9
|
strategy:
|
10
10
|
fail-fast: false
|
11
11
|
matrix:
|
12
|
-
os: [ubuntu-
|
13
|
-
ruby-version: ['3.0', '3.1', '3.2']
|
12
|
+
os: [ubuntu-22.04, ubuntu-24.04]
|
13
|
+
ruby-version: ['3.0', '3.1', '3.2', '3.3', '3.4']
|
14
14
|
runs-on: ${{ matrix.os }}
|
15
15
|
steps:
|
16
|
-
- uses: actions/checkout@
|
16
|
+
- uses: actions/checkout@v4
|
17
17
|
- name: Set up Ruby
|
18
18
|
uses: ruby/setup-ruby@v1
|
19
19
|
with:
|
data/LICENSE
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
Copyright (c) 2016 Hiroyuki Sakuraba
|
2
|
-
Copyright (c) 2022 Marco Colli, Pushpad (https://pushpad.xyz)
|
2
|
+
Copyright (c) 2022-2025 Marco Colli, Pushpad (https://pushpad.xyz)
|
3
3
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -5,6 +5,8 @@
|
|
5
5
|
|
6
6
|
This gem makes it possible to send push messages to web browsers from Ruby backends using the [Web Push Protocol](https://datatracker.ietf.org/doc/html/rfc8030). It supports [Message Encryption for Web Push](https://datatracker.ietf.org/doc/html/rfc8291) and [VAPID](https://datatracker.ietf.org/doc/html/rfc8292).
|
7
7
|
|
8
|
+
**Note**: This is an open source gem for Web Push. If you want to send web push notifications from Ruby using Pushpad, you need to use another gem ([pushpad gem](https://github.com/pushpad/pushpad-ruby)).
|
9
|
+
|
8
10
|
## Installation
|
9
11
|
|
10
12
|
Add this line to the Gemfile:
|
@@ -53,10 +55,16 @@ navigator.serviceWorker.register('/service-worker.js')
|
|
53
55
|
|
54
56
|
### Subscribing to push notifications
|
55
57
|
|
56
|
-
The VAPID public key you generated earlier
|
58
|
+
The VAPID public key that you generated earlier needs to be made available to JavaScript, which can be done in many ways, for example with a fetch request or when rendering the HTML template in Ruby:
|
57
59
|
|
58
|
-
```
|
59
|
-
|
60
|
+
```erb
|
61
|
+
<script>
|
62
|
+
// Make the VAPID public key available to the client as a Uint8Array
|
63
|
+
window.vapidPublicKey = new Uint8Array(<%= Base64.urlsafe_decode64(ENV['VAPID_PUBLIC_KEY']).bytes %>)
|
64
|
+
|
65
|
+
// Or you can pass it as a string if you prefer
|
66
|
+
window.vapidPublicKey = "<%= ENV['VAPID_PUBLIC_KEY'].delete('=') %>"
|
67
|
+
</script>
|
60
68
|
```
|
61
69
|
|
62
70
|
Your JavaScript code uses the `pushManager` interface to subscribe to push notifications, passing the VAPID public key to the subscription settings.
|
@@ -178,7 +186,7 @@ WebPush.payload_send(
|
|
178
186
|
p256dh: "BO/aG9nYXNkZmFkc2ZmZHNmYWRzZmFl...",
|
179
187
|
auth: "aW1hcmthcmFpa3V6ZQ==",
|
180
188
|
vapid: {
|
181
|
-
subject: "mailto:sender@example.com"
|
189
|
+
subject: "mailto:sender@example.com",
|
182
190
|
pem: ENV['VAPID_KEYS']
|
183
191
|
}
|
184
192
|
)
|
data/lib/web_push/encryption.rb
CHANGED
@@ -8,6 +8,7 @@ module WebPush
|
|
8
8
|
assert_arguments(message, p256dh, auth)
|
9
9
|
|
10
10
|
group_name = 'prime256v1'
|
11
|
+
hash = 'SHA256'
|
11
12
|
salt = Random.new.bytes(16)
|
12
13
|
|
13
14
|
server = OpenSSL::PKey::EC.generate(group_name)
|
@@ -25,11 +26,11 @@ module WebPush
|
|
25
26
|
content_encryption_key_info = "Content-Encoding: aes128gcm\0"
|
26
27
|
nonce_info = "Content-Encoding: nonce\0"
|
27
28
|
|
28
|
-
prk =
|
29
|
+
prk = OpenSSL::KDF.hkdf(shared_secret, salt: client_auth_token, info: info, hash: hash, length: 32)
|
29
30
|
|
30
|
-
content_encryption_key =
|
31
|
+
content_encryption_key = OpenSSL::KDF.hkdf(prk, salt: salt, info: content_encryption_key_info, hash: hash, length: 16)
|
31
32
|
|
32
|
-
nonce =
|
33
|
+
nonce = OpenSSL::KDF.hkdf(prk, salt: salt, info: nonce_info, hash: hash, length: 12)
|
33
34
|
|
34
35
|
ciphertext = encrypt_payload(message, content_encryption_key, nonce)
|
35
36
|
|
data/lib/web_push/version.rb
CHANGED
data/lib/web_push.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'openssl'
|
4
4
|
require 'base64'
|
5
|
-
require 'hkdf'
|
6
5
|
require 'jwt'
|
7
6
|
require 'uri'
|
8
7
|
require 'net/http'
|
@@ -57,10 +56,6 @@ module WebPush
|
|
57
56
|
end
|
58
57
|
|
59
58
|
def decode64(str)
|
60
|
-
# For Ruby < 2.3, Base64.urlsafe_decode64 strict decodes and will raise errors if encoded value is not properly padded
|
61
|
-
# Implementation: http://ruby-doc.org/stdlib-2.3.0/libdoc/base64/rdoc/Base64.html#method-i-urlsafe_decode64
|
62
|
-
str = str.ljust((str.length + 3) & ~3, '=') if !str.end_with?('=') && str.length % 4 != 0
|
63
|
-
|
64
59
|
Base64.urlsafe_decode64(str)
|
65
60
|
end
|
66
61
|
|
data/spec/spec_helper.rb
CHANGED
@@ -65,10 +65,10 @@ describe WebPush::Encryption do
|
|
65
65
|
content_encryption_key_info = "Content-Encoding: aes128gcm\0"
|
66
66
|
nonce_info = "Content-Encoding: nonce\0"
|
67
67
|
|
68
|
-
prk =
|
68
|
+
prk = OpenSSL::KDF.hkdf(shared_secret, salt: client_auth_token, info: info, hash: 'SHA256', length: 32)
|
69
69
|
|
70
|
-
content_encryption_key =
|
71
|
-
nonce =
|
70
|
+
content_encryption_key = OpenSSL::KDF.hkdf(prk, salt: salt, info: content_encryption_key_info, hash: 'SHA256', length: 16)
|
71
|
+
nonce = OpenSSL::KDF.hkdf(prk, salt: salt, info: nonce_info, hash: 'SHA256', length: 12)
|
72
72
|
|
73
73
|
decrypt_ciphertext(ciphertext, content_encryption_key, nonce)
|
74
74
|
end
|
data/spec/web_push_spec.rb
CHANGED
@@ -5,6 +5,18 @@ describe WebPush do
|
|
5
5
|
expect(WebPush::VERSION).not_to be nil
|
6
6
|
end
|
7
7
|
|
8
|
+
describe '.decode64' do
|
9
|
+
let(:a_padded_key) { "YWJjZGU=" }
|
10
|
+
|
11
|
+
it 'urlsafe decodes padded base64 string' do
|
12
|
+
expect(WebPush.decode64(a_padded_key)).to eq("abcde")
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'urlsafe decodes unpadded base64 string' do
|
16
|
+
expect(WebPush.decode64(a_padded_key.delete("="))).to eq("abcde")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
8
20
|
shared_examples 'web push protocol standard error handling' do
|
9
21
|
it 'raises InvalidSubscription if the API returns a 404 Error' do
|
10
22
|
stub_request(:post, expected_endpoint)
|
data/web-push.gemspec
CHANGED
@@ -14,8 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
|
15
15
|
spec.required_ruby_version = '>= 3.0'
|
16
16
|
|
17
|
-
spec.add_dependency '
|
18
|
-
spec.add_dependency 'jwt', '~> 2.0'
|
17
|
+
spec.add_dependency 'jwt', '~> 3.0'
|
19
18
|
spec.add_dependency 'openssl', '~> 3.0'
|
20
19
|
|
21
20
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web-push
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zaru
|
@@ -9,36 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2025-06-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: hkdf
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '1.0'
|
21
|
-
type: :runtime
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - "~>"
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '1.0'
|
28
14
|
- !ruby/object:Gem::Dependency
|
29
15
|
name: jwt
|
30
16
|
requirement: !ruby/object:Gem::Requirement
|
31
17
|
requirements:
|
32
18
|
- - "~>"
|
33
19
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
20
|
+
version: '3.0'
|
35
21
|
type: :runtime
|
36
22
|
prerelease: false
|
37
23
|
version_requirements: !ruby/object:Gem::Requirement
|
38
24
|
requirements:
|
39
25
|
- - "~>"
|
40
26
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
27
|
+
version: '3.0'
|
42
28
|
- !ruby/object:Gem::Dependency
|
43
29
|
name: openssl
|
44
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
125
|
- !ruby/object:Gem::Version
|
140
126
|
version: '0'
|
141
127
|
requirements: []
|
142
|
-
rubygems_version: 3.
|
128
|
+
rubygems_version: 3.5.22
|
143
129
|
signing_key:
|
144
130
|
specification_version: 4
|
145
131
|
summary: Web Push library for Ruby (RFC8030)
|