cose 1.1.0 → 1.2.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: ef03f2ea3b2f4f4bb8f81fdd777cf3ae3905e1eae953599f0e6b0feca89343f5
4
- data.tar.gz: 94db44b9a0a449bdb81ae9274fb193365838ec84f9df3db3540dcf5eb1ca3303
3
+ metadata.gz: a9bd8e1fa2c7e0f08d903f81ec2303a60a2377e6ba63c548b0c7f72d1c3197ee
4
+ data.tar.gz: ccf797d8600edc7020c9248db5bfc60ffdfd7c07f11f7c39cad172116176430e
5
5
  SHA512:
6
- metadata.gz: 17492d5ba3f7fce248418a158d29419392f9d849f33421d7b6192e61e021e5d62ca14f6a42721a05e77e31dfc67ef267c18e8be7138360a9146e359e5cb5b740
7
- data.tar.gz: 49834d1df018a49669dfc02b8548c30f2aedf99fbad979cd072ee480eff99e9b6076e74654cfff72e6d6a6da96798d1de7902497f19f70e53b6464ac5a7d716a
6
+ metadata.gz: 5f27deece5637039eb3fd8ce9a8d33baf99c31fab75036462e40d599c4e0df789cf6f5ada85fcd4df75ebfddef91faa49132b0f08486f2e322e731cf2e217808
7
+ data.tar.gz: 6eebcecddf4fc55ce1b8f7f219d9dc8bd37f1e01a18a4e3877b47b84398de883cae204d6013349e409836111b82c254a6374e9b104e552c4339ad7a94153df4b
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [v1.2.0] - 2020-07-10
4
+
5
+ ### Added
6
+
7
+ - Support ES256K signature algorithm
8
+
3
9
  ## [v1.1.0] - 2020-07-09
4
10
 
5
11
  ### Dependencies
@@ -129,6 +135,7 @@ NOTE: No breaking changes. Moving out of `v0.x` to express the intention to keep
129
135
  - EC2 key object
130
136
  - Works with ruby 2.5
131
137
 
138
+ [v1.2.0]: https://github.com/cedarcode/cose-ruby/compare/v1.1.0...v1.2.0/
132
139
  [v1.1.0]: https://github.com/cedarcode/cose-ruby/compare/v1.0.0...v1.1.0/
133
140
  [v1.0.0]: https://github.com/cedarcode/cose-ruby/compare/v0.11.0...v1.0.0/
134
141
  [v0.11.0]: https://github.com/cedarcode/cose-ruby/compare/v0.10.0...v0.11.0/
@@ -26,9 +26,10 @@ module COSE
26
26
  @registered_by_name[name]
27
27
  end
28
28
 
29
- register(ECDSA.new(-7, "ES256", hash_function: "SHA256"))
30
- register(ECDSA.new(-35, "ES384", hash_function: "SHA384"))
31
- register(ECDSA.new(-36, "ES512", hash_function: "SHA512"))
29
+ register(ECDSA.new(-7, "ES256", hash_function: "SHA256", curve_name: "P-256"))
30
+ register(ECDSA.new(-35, "ES384", hash_function: "SHA384", curve_name: "P-384"))
31
+ register(ECDSA.new(-36, "ES512", hash_function: "SHA512", curve_name: "P-521"))
32
+ register(ECDSA.new(-47, "ES256K", hash_function: "SHA256", curve_name: "secp256k1"))
32
33
  register(RSAPSS.new(-37, "PS256", hash_function: "SHA256", salt_length: 32))
33
34
  register(RSAPSS.new(-38, "PS384", hash_function: "SHA384", salt_length: 48))
34
35
  register(RSAPSS.new(-39, "PS512", hash_function: "SHA512", salt_length: 64))
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "cose/algorithm/signature_algorithm"
4
4
  require "cose/error"
5
+ require "cose/key/curve"
5
6
  require "cose/key/ec2"
6
7
  require "openssl"
7
8
  require "openssl/signature_algorithm/ecdsa"
@@ -9,12 +10,13 @@ require "openssl/signature_algorithm/ecdsa"
9
10
  module COSE
10
11
  module Algorithm
11
12
  class ECDSA < SignatureAlgorithm
12
- attr_reader :hash_function
13
+ attr_reader :hash_function, :curve
13
14
 
14
- def initialize(*args, hash_function:)
15
+ def initialize(*args, hash_function:, curve_name:)
15
16
  super(*args)
16
17
 
17
18
  @hash_function = hash_function
19
+ @curve = COSE::Key::Curve.by_name(curve_name) || raise("Couldn't find curve with name='#{curve_name}'")
18
20
  end
19
21
 
20
22
  private
@@ -29,6 +31,14 @@ module COSE
29
31
  OpenSSL::SignatureAlgorithm::ECDSA
30
32
  end
31
33
 
34
+ def signature_algorithm_parameters
35
+ if curve
36
+ super.merge(curve: curve.pkey_name)
37
+ else
38
+ super
39
+ end
40
+ end
41
+
32
42
  def to_pkey(key)
33
43
  case key
34
44
  when COSE::Key::EC2
@@ -20,7 +20,7 @@ module COSE
20
20
  private
21
21
 
22
22
  def valid_signature?(key, signature, verification_data)
23
- signature_algorithm = signature_algorithm_class.new(hash_function: hash_function)
23
+ signature_algorithm = signature_algorithm_class.new(**signature_algorithm_parameters)
24
24
  signature_algorithm.verify_key = to_pkey(key)
25
25
 
26
26
  begin
@@ -30,6 +30,10 @@ module COSE
30
30
  end
31
31
  end
32
32
 
33
+ def signature_algorithm_parameters
34
+ { hash_function: hash_function }
35
+ end
36
+
33
37
  def to_cose_key(key)
34
38
  case key
35
39
  when COSE::Key::Base
@@ -32,3 +32,4 @@ end
32
32
  COSE::Key::Curve.register(1, "P-256", "prime256v1")
33
33
  COSE::Key::Curve.register(2, "P-384", "secp384r1")
34
34
  COSE::Key::Curve.register(3, "P-521", "secp521r1")
35
+ COSE::Key::Curve.register(8, "secp256k1", "secp256k1")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module COSE
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.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: 1.1.0
4
+ version: 1.2.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: 2020-07-09 00:00:00.000000000 Z
12
+ date: 2020-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cbor