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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb622817a7125abd49993f92ef3555c51bb695da2f5613fff03ae9b64aff94ff
4
- data.tar.gz: bd014b310ddb76ed652bdf47668bad25251efa07835649702eaea8c595fa7856
3
+ metadata.gz: c8a683629bc333d1f987fc867dd05b4d0af39179e94cc8dc7c9742dbaddd4c45
4
+ data.tar.gz: 1c86dcbfcbec2791df28c45c2dff656ca8385b5a3fb75d900fb731e7472887f9
5
5
  SHA512:
6
- metadata.gz: 923ae3767467c3ceaabf74180c5b27f9297e2b16874f23bd76c557087ed30f05bc2e149034bb8aae5c586c535c03658742cfe6082c64f0e5de8a3265cd18e4f2
7
- data.tar.gz: e5158b056e50178ec282ce6314abe524a7c4954073ba3b70a65b52c9783a78050e96624a46b6f4127a0ac007a3e52fe756018326d4cfae9d2b95cca2c5df2c59
6
+ metadata.gz: 8e33057f0c869ea54dd952f5b937fe6ca01c49a7d82549a7563fd4b148a315eba627d791f5c39d844834b2418466b21f7c58ae382c310fdc339b1560be508234
7
+ data.tar.gz: 813fc19fb5939a5318409ac30651d31050d22e006213305e549899b109cde83ddcc3dfac17a7d1c1abc016ebc6dbb3235f17fd049eff96738be4e2832be55917
@@ -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
- ruby-version: ['3.0', '3.1']
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
@@ -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.new(group_name)
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)
@@ -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 = 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
- key = new
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 = OpenSSL::PKey::EC.new('prime256v1')
35
- @curve.generate_key
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
- curve.public_key = OpenSSL::PKey::EC::Point.new(group, to_big_num(key))
53
+ set_keys! key, nil
61
54
  end
62
55
 
63
56
  def private_key=(key)
64
- curve.private_key = to_big_num(key)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WebPush
4
- VERSION = '2.1.0'.freeze
4
+ VERSION = '3.0.0'.freeze
5
5
  end
@@ -4,9 +4,7 @@ describe WebPush::Encryption do
4
4
  describe '#encrypt' do
5
5
  let(:curve) do
6
6
  group = 'prime256v1'
7
- curve = OpenSSL::PKey::EC.new(group)
8
- curve.generate_key
9
- curve
7
+ OpenSSL::PKey::EC.generate(group)
10
8
  end
11
9
 
12
10
  let(:p256dh) do
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: 2.1.0
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: 2022-11-28 00:00:00.000000000 Z
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.3.26
142
+ rubygems_version: 3.4.1
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: Web Push library for Ruby (RFC8030)