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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cece173dd677644851673495e5ed8d9940683a19e435d1bdfeb7320676fc29a
4
- data.tar.gz: d2d7d17a2681bc98d5071f7fcecd1169c287cb6c120967772b69cfa0ac981cae
3
+ metadata.gz: 1e9fc90b31beed1be2df01a443242f9ec5a7fdebb05ef995d067777e330be73b
4
+ data.tar.gz: 99264ff526cfb7d4bfd058ef0ffdd44cc65449fddc0eae35a89eb9520a4bd173
5
5
  SHA512:
6
- metadata.gz: f6ad46ff1820c19f0ec92305b8ac019082da03273cd2230fdc6e8031ec07f12bc79f678b2c451d69231305982bbc16551bc8b7996898912aba0f84d9bedce6fd
7
- data.tar.gz: 5652309b708b29c6cf51611d1f07214cd6d25b0ddfb34d22ebc8e25dbd1023c79914d1345d46fa9c1d991be5fe0c68cb4b2c4c489e2a37a61aeda966701767f5
6
+ metadata.gz: a75f55dfd35bc92435032765b7f69127b1c832c5ffe5d96626f86c159689c4b04bbfd07fe95785d522cdb201a48de2ff129b3af2c0e11623381bdd10ff42fef9
7
+ data.tar.gz: e3f98bc5c363da8e812fa3ba1e75175c2a0136679a929b96e1b8b353fcbbc1a60fd1fbcc50083a3e5e24378bcc66054b440baaaa472f66def24f260a1f550db2
@@ -6,7 +6,7 @@ inherit_mode:
6
6
  - Exclude
7
7
 
8
8
  AllCops:
9
- TargetRubyVersion: 2.3
9
+ TargetRubyVersion: 2.4
10
10
  DisabledByDefault: true
11
11
  Exclude:
12
12
  - "gemfiles/**/*"
@@ -4,11 +4,10 @@ cache: bundler
4
4
 
5
5
  rvm:
6
6
  - ruby-head
7
- - 2.7.0-preview3
7
+ - 2.7.0
8
8
  - 2.6.5
9
9
  - 2.5.7
10
10
  - 2.4.9
11
- - 2.3.8
12
11
 
13
12
  gemfile:
14
13
  - gemfiles/openssl_head.gemfile
@@ -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/
@@ -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.3"
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"
@@ -3,8 +3,6 @@
3
3
  module COSE
4
4
  module Algorithm
5
5
  class Base
6
- BYTE_LENGTH = 8
7
-
8
6
  attr_reader :id, :name
9
7
 
10
8
  def initialize(id, name)
@@ -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 valid_signature?(key, signature, verification_data)
28
- pkey = to_pkey(key)
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
@@ -6,6 +6,8 @@ require "openssl"
6
6
  module COSE
7
7
  module Algorithm
8
8
  class HMAC < Base
9
+ BYTE_LENGTH = 8
10
+
9
11
  attr_reader :hash_function, :tag_length
10
12
 
11
13
  def initialize(*args, hash_function:, tag_length:)
@@ -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 valid_signature?(key, signature, verification_data)
29
- pkey = to_pkey(key)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module COSE
4
- VERSION = "0.10.0"
4
+ VERSION = "0.11.0"
5
5
  end
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.10.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: 2019-12-19 00:00:00.000000000 Z
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.3'
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.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)