cose 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.travis.yml +1 -2
- data/CHANGELOG.md +7 -0
- data/cose.gemspec +2 -1
- data/lib/cose/algorithm/base.rb +0 -2
- data/lib/cose/algorithm/ecdsa.rb +3 -27
- data/lib/cose/algorithm/hmac.rb +2 -0
- data/lib/cose/algorithm/rsa_pss.rb +3 -14
- data/lib/cose/algorithm/signature_algorithm.rb +27 -0
- data/lib/cose/version.rb +1 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e9fc90b31beed1be2df01a443242f9ec5a7fdebb05ef995d067777e330be73b
|
4
|
+
data.tar.gz: 99264ff526cfb7d4bfd058ef0ffdd44cc65449fddc0eae35a89eb9520a4bd173
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a75f55dfd35bc92435032765b7f69127b1c832c5ffe5d96626f86c159689c4b04bbfd07fe95785d522cdb201a48de2ff129b3af2c0e11623381bdd10ff42fef9
|
7
|
+
data.tar.gz: e3f98bc5c363da8e812fa3ba1e75175c2a0136679a929b96e1b8b353fcbbc1a60fd1fbcc50083a3e5e24378bcc66054b440baaaa472f66def24f260a1f550db2
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [v0.11.0] - 2020-01-30
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- Let others easily support more signature algorithms by making `COSE::Algorithm::SignatureAlgorithm` smarter
|
8
|
+
|
3
9
|
## [v0.10.0] - 2019-12-19
|
4
10
|
|
5
11
|
### Added
|
@@ -109,6 +115,7 @@
|
|
109
115
|
- EC2 key object
|
110
116
|
- Works with ruby 2.5
|
111
117
|
|
118
|
+
[v0.11.0]: https://github.com/cedarcode/cose-ruby/compare/v0.10.0...v0.11.0/
|
112
119
|
[v0.10.0]: https://github.com/cedarcode/cose-ruby/compare/v0.9.0...v0.10.0/
|
113
120
|
[v0.9.0]: https://github.com/cedarcode/cose-ruby/compare/v0.8.0...v0.9.0/
|
114
121
|
[v0.8.0]: https://github.com/cedarcode/cose-ruby/compare/v0.7.0...v0.8.0/
|
data/cose.gemspec
CHANGED
@@ -29,9 +29,10 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
30
|
spec.require_paths = ["lib"]
|
31
31
|
|
32
|
-
spec.required_ruby_version = ">= 2.
|
32
|
+
spec.required_ruby_version = ">= 2.4"
|
33
33
|
|
34
34
|
spec.add_dependency "cbor", "~> 0.5.9"
|
35
|
+
spec.add_dependency "openssl-signature_algorithm", "~> 0.3.0"
|
35
36
|
|
36
37
|
spec.add_development_dependency "appraisal", "~> 2.2.0"
|
37
38
|
spec.add_development_dependency "bundler", ">= 1.17", "< 3"
|
data/lib/cose/algorithm/base.rb
CHANGED
data/lib/cose/algorithm/ecdsa.rb
CHANGED
@@ -4,6 +4,7 @@ require "cose/algorithm/signature_algorithm"
|
|
4
4
|
require "cose/error"
|
5
5
|
require "cose/key/ec2"
|
6
6
|
require "openssl"
|
7
|
+
require "openssl/signature_algorithm/ecdsa"
|
7
8
|
|
8
9
|
module COSE
|
9
10
|
module Algorithm
|
@@ -16,18 +17,10 @@ module COSE
|
|
16
17
|
@hash_function = hash_function
|
17
18
|
end
|
18
19
|
|
19
|
-
def compatible_key?(key)
|
20
|
-
to_pkey(key)
|
21
|
-
rescue COSE::Error
|
22
|
-
false
|
23
|
-
end
|
24
|
-
|
25
20
|
private
|
26
21
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
pkey.verify(hash_function, in_der(signature, pkey.group.degree), verification_data)
|
22
|
+
def signature_algorithm_class
|
23
|
+
OpenSSL::SignatureAlgorithm::ECDSA
|
31
24
|
end
|
32
25
|
|
33
26
|
def to_pkey(key)
|
@@ -40,23 +33,6 @@ module COSE
|
|
40
33
|
raise(COSE::Error, "Incompatible key for algorithm")
|
41
34
|
end
|
42
35
|
end
|
43
|
-
|
44
|
-
# Borrowed from jwt rubygem.
|
45
|
-
# https://github.com/jwt/ruby-jwt/blob/7a6a3f1dbaff806993156d1dff9c217bb2523ff8/lib/jwt/security_utils.rb#L34-L39
|
46
|
-
#
|
47
|
-
# Hopefully this will be provided by openssl rubygem in the future.
|
48
|
-
def in_der(signature, key_length)
|
49
|
-
n = (key_length.to_f / BYTE_LENGTH).ceil
|
50
|
-
|
51
|
-
if signature.size == n * 2
|
52
|
-
r = signature[0..(n - 1)]
|
53
|
-
s = signature[n..-1]
|
54
|
-
|
55
|
-
OpenSSL::ASN1::Sequence.new([r, s].map { |int| OpenSSL::ASN1::Integer.new(OpenSSL::BN.new(int, 2)) }).to_der
|
56
|
-
else
|
57
|
-
signature
|
58
|
-
end
|
59
|
-
end
|
60
36
|
end
|
61
37
|
end
|
62
38
|
end
|
data/lib/cose/algorithm/hmac.rb
CHANGED
@@ -4,6 +4,7 @@ require "cose/algorithm/signature_algorithm"
|
|
4
4
|
require "cose/key/rsa"
|
5
5
|
require "cose/error"
|
6
6
|
require "openssl"
|
7
|
+
require "openssl/signature_algorithm/rsapss"
|
7
8
|
|
8
9
|
module COSE
|
9
10
|
module Algorithm
|
@@ -17,22 +18,10 @@ module COSE
|
|
17
18
|
@salt_length = salt_length
|
18
19
|
end
|
19
20
|
|
20
|
-
def compatible_key?(key)
|
21
|
-
to_pkey(key)
|
22
|
-
rescue COSE::Error
|
23
|
-
false
|
24
|
-
end
|
25
|
-
|
26
21
|
private
|
27
22
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
if pkey.respond_to?(:verify_pss)
|
32
|
-
pkey.verify_pss(hash_function, signature, verification_data, salt_length: :digest, mgf1_hash: hash_function)
|
33
|
-
else
|
34
|
-
raise(COSE::Error, "Update to openssl gem >= v2.1 to have RSA-PSS support")
|
35
|
-
end
|
23
|
+
def signature_algorithm_class
|
24
|
+
OpenSSL::SignatureAlgorithm::RSAPSS
|
36
25
|
end
|
37
26
|
|
38
27
|
def to_pkey(key)
|
@@ -9,6 +9,33 @@ module COSE
|
|
9
9
|
def verify(key, signature, verification_data)
|
10
10
|
valid_signature?(key, signature, verification_data) || raise(COSE::Error, "Signature verification failed")
|
11
11
|
end
|
12
|
+
|
13
|
+
def compatible_key?(key)
|
14
|
+
to_pkey(key)
|
15
|
+
rescue COSE::Error
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def valid_signature?(key, signature, verification_data)
|
22
|
+
signature_algorithm = signature_algorithm_class.new(hash_function[3..-1])
|
23
|
+
signature_algorithm.verify_key = to_pkey(key)
|
24
|
+
|
25
|
+
begin
|
26
|
+
signature_algorithm.verify(signature, verification_data)
|
27
|
+
rescue OpenSSL::SignatureAlgorithm::Error
|
28
|
+
false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def signature_algorithm_class
|
33
|
+
raise NotImplementedError
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_pkey(_key)
|
37
|
+
raise NotImplementedError
|
38
|
+
end
|
12
39
|
end
|
13
40
|
end
|
14
41
|
end
|
data/lib/cose/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gonzalo Rodriguez
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cbor
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 0.5.9
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: openssl-signature_algorithm
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.3.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.3.0
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: appraisal
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,14 +212,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
198
212
|
requirements:
|
199
213
|
- - ">="
|
200
214
|
- !ruby/object:Gem::Version
|
201
|
-
version: '2.
|
215
|
+
version: '2.4'
|
202
216
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
217
|
requirements:
|
204
218
|
- - ">="
|
205
219
|
- !ruby/object:Gem::Version
|
206
220
|
version: '0'
|
207
221
|
requirements: []
|
208
|
-
rubygems_version: 3.1.
|
222
|
+
rubygems_version: 3.1.2
|
209
223
|
signing_key:
|
210
224
|
specification_version: 4
|
211
225
|
summary: Ruby implementation of RFC 8152 CBOR Object Signing and Encryption (COSE)
|