web-push 2.1.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +3 -2
- data/lib/web_push/encryption.rb +1 -2
- data/lib/web_push/vapid_key.rb +33 -14
- data/lib/web_push/version.rb +1 -1
- data/spec/web_push/encryption_spec.rb +1 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8a683629bc333d1f987fc867dd05b4d0af39179e94cc8dc7c9742dbaddd4c45
|
4
|
+
data.tar.gz: 1c86dcbfcbec2791df28c45c2dff656ca8385b5a3fb75d900fb731e7472887f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e33057f0c869ea54dd952f5b937fe6ca01c49a7d82549a7563fd4b148a315eba627d791f5c39d844834b2418466b21f7c58ae382c310fdc339b1560be508234
|
7
|
+
data.tar.gz: 813fc19fb5939a5318409ac30651d31050d22e006213305e549899b109cde83ddcc3dfac17a7d1c1abc016ebc6dbb3235f17fd049eff96738be4e2832be55917
|
data/.github/workflows/ci.yml
CHANGED
@@ -6,11 +6,12 @@ on:
|
|
6
6
|
branches: [ master ]
|
7
7
|
jobs:
|
8
8
|
test:
|
9
|
-
runs-on: ubuntu-latest
|
10
9
|
strategy:
|
11
10
|
fail-fast: false
|
12
11
|
matrix:
|
13
|
-
|
12
|
+
os: [ubuntu-20.04, ubuntu-22.04]
|
13
|
+
ruby-version: ['3.0', '3.1', '3.2']
|
14
|
+
runs-on: ${{ matrix.os }}
|
14
15
|
steps:
|
15
16
|
- uses: actions/checkout@v3
|
16
17
|
- name: Set up Ruby
|
data/lib/web_push/encryption.rb
CHANGED
@@ -10,8 +10,7 @@ module WebPush
|
|
10
10
|
group_name = 'prime256v1'
|
11
11
|
salt = Random.new.bytes(16)
|
12
12
|
|
13
|
-
server = OpenSSL::PKey::EC.
|
14
|
-
server.generate_key
|
13
|
+
server = OpenSSL::PKey::EC.generate(group_name)
|
15
14
|
server_public_key_bn = server.public_key.to_bn
|
16
15
|
|
17
16
|
group = OpenSSL::PKey::EC::Group.new(group_name)
|
data/lib/web_push/vapid_key.rb
CHANGED
@@ -10,9 +10,7 @@ module WebPush
|
|
10
10
|
# @return [WebPush::VapidKey] a VapidKey instance for the given public and private keys
|
11
11
|
def self.from_keys(public_key, private_key)
|
12
12
|
key = new
|
13
|
-
key.public_key
|
14
|
-
key.private_key = private_key
|
15
|
-
|
13
|
+
key.set_keys! public_key, private_key
|
16
14
|
key
|
17
15
|
end
|
18
16
|
|
@@ -20,19 +18,14 @@ module WebPush
|
|
20
18
|
#
|
21
19
|
# @return [WebPush::VapidKey] a VapidKey instance for the given public and private keys
|
22
20
|
def self.from_pem(pem)
|
23
|
-
|
24
|
-
src = OpenSSL::PKey.read pem
|
25
|
-
key.curve.public_key = src.public_key
|
26
|
-
key.curve.private_key = src.private_key
|
27
|
-
|
28
|
-
key
|
21
|
+
new(OpenSSL::PKey.read(pem))
|
29
22
|
end
|
30
23
|
|
31
24
|
attr_reader :curve
|
32
25
|
|
33
|
-
def initialize
|
34
|
-
@curve =
|
35
|
-
@curve.
|
26
|
+
def initialize(pkey = nil)
|
27
|
+
@curve = pkey
|
28
|
+
@curve = OpenSSL::PKey::EC.generate('prime256v1') if @curve.nil?
|
36
29
|
end
|
37
30
|
|
38
31
|
# Retrieve the encoded elliptic curve public key for VAPID protocol
|
@@ -57,11 +50,37 @@ module WebPush
|
|
57
50
|
end
|
58
51
|
|
59
52
|
def public_key=(key)
|
60
|
-
|
53
|
+
set_keys! key, nil
|
61
54
|
end
|
62
55
|
|
63
56
|
def private_key=(key)
|
64
|
-
|
57
|
+
set_keys! nil, key
|
58
|
+
end
|
59
|
+
|
60
|
+
def set_keys!(public_key = nil, private_key = nil)
|
61
|
+
if public_key.nil?
|
62
|
+
public_key = curve.public_key
|
63
|
+
else
|
64
|
+
public_key = OpenSSL::PKey::EC::Point.new(group, to_big_num(public_key))
|
65
|
+
end
|
66
|
+
|
67
|
+
if private_key.nil?
|
68
|
+
private_key = curve.private_key
|
69
|
+
else
|
70
|
+
private_key = to_big_num(private_key)
|
71
|
+
end
|
72
|
+
|
73
|
+
asn1 = OpenSSL::ASN1::Sequence([
|
74
|
+
OpenSSL::ASN1::Integer.new(1),
|
75
|
+
# Not properly padded but OpenSSL doesn't mind
|
76
|
+
OpenSSL::ASN1::OctetString(private_key.to_s(2)),
|
77
|
+
OpenSSL::ASN1::ObjectId('prime256v1', 0, :EXPLICIT),
|
78
|
+
OpenSSL::ASN1::BitString(public_key.to_octet_string(:uncompressed), 1, :EXPLICIT),
|
79
|
+
])
|
80
|
+
|
81
|
+
der = asn1.to_der
|
82
|
+
|
83
|
+
@curve = OpenSSL::PKey::EC.new(der)
|
65
84
|
end
|
66
85
|
|
67
86
|
def curve_name
|
data/lib/web_push/version.rb
CHANGED
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:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zaru
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hkdf
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '0'
|
141
141
|
requirements: []
|
142
|
-
rubygems_version: 3.
|
142
|
+
rubygems_version: 3.4.1
|
143
143
|
signing_key:
|
144
144
|
specification_version: 4
|
145
145
|
summary: Web Push library for Ruby (RFC8030)
|