cose-key 0.2.0 → 0.3.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: 370bd05f8c80d2cacbc2fbae89fae839cb1f8096237a6d5e528900e188aaee86
4
- data.tar.gz: 5aedf59dc00d832569871159456972932b6c2ff2822f9bda791206c9765e0907
3
+ metadata.gz: 25e33a9ab42b0150e080aed45e9d969075129d6659d89eaad9942b980189469e
4
+ data.tar.gz: 42c6a23ae4be58f4d10fabb072a38232a6d11cfd92c2ad5fbade3169298d5cee
5
5
  SHA512:
6
- metadata.gz: 7e2a11691e743478199591f8f363c5c64cb9eef7e2b1c6164a81678111a20b3a91d43dbe8f879e26fc03e9ca917b2c2772681e0e62c0f786433fd5e4d4572d9b
7
- data.tar.gz: b7d56af7a6caf5c4f13392410af8e353465b1d352b115de783916c2ded3faa83aef6b4662b15fa74a7c834fa8e323e6c30207d73c0fdf0560736c054d82ac0be
6
+ metadata.gz: c3562e579900195cb9d85db75b5b7d7243800414f393b53203b56774fd1a0b5dbd854a7f06b4b4e32aab4d7fb5d21cd470074a5887be6c1c9910fdb3f235bed0
7
+ data.tar.gz: 0e43542e04582310e4d0790fe5200cd5500da44ffdea75aff5c9f2f653af6a70ef2f9be235c466893eea888526e5ad289ab046f9da651424313a7b23f0ff303f
@@ -0,0 +1,3 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: nov
@@ -0,0 +1,32 @@
1
+ name: Spec
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ spec:
14
+ strategy:
15
+ matrix:
16
+ os: ['ubuntu-20.04']
17
+ ruby-version: ['2.6', '2.7', '3.0', '3.1']
18
+ # ubuntu 22.04 only supports ssl 3 and thus only ruby 3.1
19
+ include:
20
+ - os: 'ubuntu-22.04'
21
+ ruby-version: '3.1'
22
+ runs-on: ${{ matrix.os }}
23
+
24
+ steps:
25
+ - uses: actions/checkout@v3
26
+ - name: Set up Ruby
27
+ uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby-version }}
30
+ bundler-cache: true
31
+ - name: Run Specs
32
+ run: bundle exec rake spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
data/cose-key.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.require_paths = ['lib']
14
14
  gem.required_ruby_version = '>= 2.3'
15
15
  gem.add_runtime_dependency 'cbor'
16
- gem.add_development_dependency 'rake', '~> 10.0'
16
+ gem.add_development_dependency 'rake'
17
17
  gem.add_development_dependency 'simplecov'
18
18
  gem.add_development_dependency 'rspec'
19
19
  gem.add_development_dependency 'rspec-its'
data/lib/cose/key/ec2.rb CHANGED
@@ -60,17 +60,31 @@ module COSE
60
60
  end
61
61
 
62
62
  def to_key
63
- key = OpenSSL::PKey::EC.new crv_name
64
- key.private_key = OpenSSL::BN.new(d, 2) if d
65
- key.public_key = OpenSSL::PKey::EC::Point.new(
63
+ point = OpenSSL::PKey::EC::Point.new(
66
64
  OpenSSL::PKey::EC::Group.new(crv_name),
67
- OpenSSL::BN.new([
68
- '04' +
69
- x.unpack('H*').first +
70
- y.unpack('H*').first
71
- ].pack('H*'), 2)
65
+ OpenSSL::BN.new(['04' + x.unpack('H*').first + y.unpack('H*').first].pack('H*'), 2)
72
66
  )
73
- key
67
+
68
+ # Public key
69
+ data_sequence = OpenSSL::ASN1::Sequence([
70
+ OpenSSL::ASN1::Sequence([
71
+ OpenSSL::ASN1::ObjectId("id-ecPublicKey"),
72
+ OpenSSL::ASN1::ObjectId(crv_name)
73
+ ]),
74
+ OpenSSL::ASN1::BitString(point.to_octet_string(:uncompressed))
75
+ ])
76
+
77
+ if d
78
+ # Private key
79
+ data_sequence = OpenSSL::ASN1::Sequence([
80
+ OpenSSL::ASN1::Integer(1),
81
+ OpenSSL::ASN1::OctetString(OpenSSL::BN.new(d, 2).to_s(2)),
82
+ OpenSSL::ASN1::ObjectId(crv_name, 0, :EXPLICIT),
83
+ OpenSSL::ASN1::BitString(point.to_octet_string(:uncompressed), 1, :EXPLICIT)
84
+ ])
85
+ end
86
+
87
+ OpenSSL::PKey::EC.new(data_sequence.to_der)
74
88
  end
75
89
 
76
90
  def verify(signature, signature_base_string)
data/lib/cose/key/rsa.rb CHANGED
@@ -52,6 +52,28 @@ module COSE
52
52
  end
53
53
 
54
54
  def to_key
55
+ # Public key
56
+ data_sequence = OpenSSL::ASN1::Sequence([
57
+ OpenSSL::ASN1::Integer(n),
58
+ OpenSSL::ASN1::Integer(e),
59
+ ])
60
+
61
+ if d && p && q && dp && dq && qi
62
+ data_sequence = OpenSSL::ASN1::Sequence([
63
+ OpenSSL::ASN1::Integer(0),
64
+ OpenSSL::ASN1::Integer(n),
65
+ OpenSSL::ASN1::Integer(e),
66
+ OpenSSL::ASN1::Integer(d),
67
+ OpenSSL::ASN1::Integer(p),
68
+ OpenSSL::ASN1::Integer(q),
69
+ OpenSSL::ASN1::Integer(dp),
70
+ OpenSSL::ASN1::Integer(dq),
71
+ OpenSSL::ASN1::Integer(qi),
72
+ ])
73
+ end
74
+
75
+ asn1 = OpenSSL::ASN1::Sequence(data_sequence)
76
+ OpenSSL::PKey::RSA.new(asn1.to_der)
55
77
  key = OpenSSL::PKey::RSA.new
56
78
  if key.respond_to? :set_key
57
79
  key.set_key n, e, d
data/lib/cose/key.rb CHANGED
@@ -40,6 +40,10 @@ module COSE
40
40
  raise NotImplementedError, 'Implement me'
41
41
  end
42
42
 
43
+ def verify(signature, signature_base_string)
44
+ raise NotImplementedError, 'Implement me'
45
+ end
46
+
43
47
  class << self
44
48
  def decode(cbor)
45
49
  key = detect CBOR.decode(cbor)
@@ -67,4 +71,4 @@ module COSE
67
71
  end
68
72
 
69
73
  require 'cose/key/ec2'
70
- require 'cose/key/rsa'
74
+ require 'cose/key/rsa'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cose-key
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov matake
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-05 00:00:00.000000000 Z
11
+ date: 2022-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cbor
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: simplecov
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -87,9 +87,10 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".github/FUNDING.yml"
91
+ - ".github/workflows/spec.yml"
90
92
  - ".gitignore"
91
93
  - ".rspec"
92
- - ".travis.yml"
93
94
  - Gemfile
94
95
  - LICENSE.txt
95
96
  - README.md
@@ -107,7 +108,7 @@ homepage: https://github.com/nov/cose-key
107
108
  licenses:
108
109
  - MIT
109
110
  metadata: {}
110
- post_install_message:
111
+ post_install_message:
111
112
  rdoc_options: []
112
113
  require_paths:
113
114
  - lib
@@ -122,9 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
123
  - !ruby/object:Gem::Version
123
124
  version: '0'
124
125
  requirements: []
125
- rubyforge_project:
126
- rubygems_version: 2.7.3
127
- signing_key:
126
+ rubygems_version: 3.3.7
127
+ signing_key:
128
128
  specification_version: 4
129
129
  summary: COSE Key in Ruby
130
130
  test_files:
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.5.1
7
- - 2.4.4
8
- - 2.3.7
9
- before_install: gem install bundler -v 1.16.4