openssl-signature_algorithm 1.0.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14fbf64f6f493adb44ffe4e2f8dc537a8800a6af79c7716c85a49eaab5664ce0
4
- data.tar.gz: 700d2d7ebfa40f05f004735eca6dc938066b69a02015c2b2cca0349db1b330ed
3
+ metadata.gz: 829f2b6155e541e120828301a89ccf7dccdf850f6e0c011dd9f3a24d4c0481e3
4
+ data.tar.gz: eba31639c4813641c2eea718c96913534e4454388fdf6401eb3f4f189c2456bf
5
5
  SHA512:
6
- metadata.gz: dd9b7bd8aca161cc531427cb7b2b2e0dfcc5143b5d4443069f95bf4d135fb5d936806372de7c5ed8f91739c8ebe7b1e98f8268bd1186df4061a1a587fc722b3c
7
- data.tar.gz: 36ceaa919dbd5dfda0dfcf90848c53d5e9eeed9be7cc1eaafdf1d15c5351b4f9782ee4c501c40cad9db147b6c1955f1c8ce3405cd4a49ccb9cf741e5878512b3
6
+ metadata.gz: 986c6f9e6593cb407f0023d80364257846281377d2b623066c006a13fb3c8543d72c0d4db6aaea11e626f16e0a7d4c9c7ff2e17f12d6f5409d84e8f40f328ebf
7
+ data.tar.gz: 36fba5619a93296702fa2656277926c5f8e26d08ba46938e7b73c39440542aaf4fa8d3f29da693880e954db7ae9b8733052d0a7e453cce6ca9c1cba7ed2c67aa
@@ -0,0 +1,38 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: build
9
+
10
+ on: push
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-20.04
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ ruby-version:
19
+ - 3.0.0
20
+ - 2.7.2
21
+ - 2.6.6
22
+ - 2.5.8
23
+ - 2.4.10
24
+ gemfile:
25
+ - openssl_3_0
26
+ - openssl_2_2
27
+ - openssl_2_1
28
+ - openssl_2_0
29
+ env:
30
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
31
+ steps:
32
+ - uses: actions/checkout@v2
33
+ - run: rm Gemfile.lock
34
+ - uses: ruby/setup-ruby@v1
35
+ with:
36
+ ruby-version: ${{ matrix.ruby-version }}
37
+ bundler-cache: true
38
+ - run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -3,6 +3,7 @@ AllCops:
3
3
  DisabledByDefault: true
4
4
  Exclude:
5
5
  - "gemfiles/**/*"
6
+ - "vendor/bundle/**/*"
6
7
 
7
8
  Bundler:
8
9
  Enabled: true
data/Appraisals CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise "openssl_head" do
4
- gem "openssl", git: "https://github.com/ruby/openssl"
3
+ appraise "openssl_3_0" do
4
+ gem "openssl", "~> 3.0.0"
5
5
  end
6
6
 
7
7
  appraise "openssl_2_2" do
@@ -15,6 +15,3 @@ end
15
15
  appraise "openssl_2_0" do
16
16
  gem "openssl", "~> 2.0.0"
17
17
  end
18
-
19
- appraise "openssl_default" do
20
- end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [v1.2.1] - 2022-06-05
4
+
5
+ - Support OpenSSL ~>3.0.0. Credits to @ClearlyClaire <3
6
+
7
+ ## [v1.1.1] - 2021-02-11
8
+
9
+ ### Fixed
10
+
11
+ - Fix error asking for ed25519 gem when actually not using EdDSA
12
+
13
+ ## [v1.1.0] - 2021-02-11
14
+
15
+ ### Added
16
+
17
+ - EdDSA support added (requires adding the `ed25519` gem to your `Gemfile`) ([@santiagorodriguez96])
18
+
3
19
  ## [v1.0.0] - 2020-07-08
4
20
 
5
21
  ### Added
@@ -72,9 +88,15 @@
72
88
  - `OpenSSL::SignatureAlgorithm::RSAPSS`
73
89
  - `OpenSSL::SignatureAlgorithm::RSAPKCS1`
74
90
 
91
+ [v1.2.1]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v1.1.1...v1.2.1/
92
+ [v1.1.1]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v1.1.0...v1.1.1/
93
+ [v1.1.0]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v1.0.0...v1.1.0/
75
94
  [v1.0.0]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v0.4.0...v1.0.0/
76
95
  [v0.4.0]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v0.3.0...v0.4.0/
77
96
  [v0.3.0]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v0.2.0...v0.3.0/
78
97
  [v0.2.0]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v0.1.1...v0.2.0/
79
98
  [v0.1.1]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v0.1.0...v0.1.1/
80
99
  [v0.1.0]: https://github.com/cedarcode/openssl-signature_algorithm/compare/41887c277dc7fa0c884ccf8924cf990ff76784d9...v0.1.0/
100
+
101
+ [@santiagorodriguez96]: https://github.com/santiagorodriguez96
102
+ [@ClearlyClaire]: https://github.com/clearlyclaire
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ gemspec
7
7
 
8
8
  gem "appraisal", "~> 2.2"
9
9
  gem "byebug", "~> 11.0"
10
+ gem "ed25519", "~> 1.2"
10
11
  gem "rake", "~> 13.0"
11
12
  gem "rspec", "~> 3.0"
12
13
  gem "rubocop", "~> 0.80.1"
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openssl-signature_algorithm (1.0.0)
4
+ openssl-signature_algorithm (1.1.1)
5
+ openssl (> 2.0, < 3.1)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
@@ -13,7 +14,9 @@ GEM
13
14
  ast (2.4.0)
14
15
  byebug (11.1.1)
15
16
  diff-lcs (1.3)
17
+ ed25519 (1.2.4)
16
18
  jaro_winkler (1.5.4)
19
+ openssl (3.0.0)
17
20
  parallel (1.19.1)
18
21
  parser (2.7.0.5)
19
22
  ast (~> 2.4.0)
@@ -51,10 +54,11 @@ PLATFORMS
51
54
  DEPENDENCIES
52
55
  appraisal (~> 2.2)
53
56
  byebug (~> 11.0)
57
+ ed25519 (~> 1.2)
54
58
  openssl-signature_algorithm!
55
59
  rake (~> 13.0)
56
60
  rspec (~> 3.0)
57
61
  rubocop (~> 0.80.1)
58
62
 
59
63
  BUNDLED WITH
60
- 2.1.4
64
+ 2.2.8
data/README.md CHANGED
@@ -1,16 +1,18 @@
1
1
  # OpenSSL::SignatureAlgorithm
2
2
 
3
- > ECDSA, RSA-PSS and RSA-PKCS#1 signature algorithms for ruby
3
+ > ECDSA, EdDSA, RSA-PSS and RSA-PKCS#1 signature algorithms for ruby
4
4
 
5
5
  Sign and verify using signature algorithm wrappers, instead of key objects.
6
6
 
7
- Provides `OpenSSL::SignatureAlgorithm::ECDSA`, `OpenSSL::SignatureAlgorithm::RSAPSS`
7
+ Provides `OpenSSL::SignatureAlgorithm::ECDSA`, `OpenSSL::SignatureAlgorithm::EdDSA`, `OpenSSL::SignatureAlgorithm::RSAPSS`
8
8
  and `OpenSSL::SignatureAlgorithm::RSAPKCS1` ruby object wrappers on top of `OpenSSL::PKey::EC`
9
9
  and `OpenSSL::PKey::RSA`, so that you can reason in terms of the algorithms and do less when
10
10
  signing or verifying signatures.
11
11
 
12
+ Loosely inspired by [rbnacl](https://github.com/RubyCrypto/rbnacl)'s [Digital Signatures](https://github.com/RubyCrypto/rbnacl/wiki/Digital-Signatures) interface.
13
+
12
14
  [![Gem](https://img.shields.io/gem/v/openssl-signature_algorithm.svg?style=flat-square&color=informational)](https://rubygems.org/gems/openssl-signature_algorithm)
13
- [![Travis](https://img.shields.io/travis/cedarcode/openssl-signature_algorithm/master.svg?style=flat-square)](https://travis-ci.org/cedarcode/openssl-signature_algorithm)
15
+ [![Actions Build](https://github.com/cedarcode/openssl-signature_algorithm/workflows/build/badge.svg)](https://github.com/cedarcode/openssl-signature_algorithm/actions)
14
16
 
15
17
  ## Installation
16
18
 
@@ -50,6 +52,30 @@ algorithm.verify_key = verify_key
50
52
  algorithm.verify(signature, to_be_signed)
51
53
  ```
52
54
 
55
+ ### EdDSA
56
+
57
+ Requires adding the `ed25519` gem to your `Gemfile`
58
+
59
+ ```ruby
60
+ require "openssl/signature_algorithm/eddsa"
61
+
62
+ to_be_signed = "to-be-signed"
63
+
64
+ # Signer
65
+ algorithm = OpenSSL::SignatureAlgorithm::EdDSA.new
66
+ signing_key = algorithm.generate_signing_key
67
+ signature = algorithm.sign(to_be_signed)
68
+
69
+ # Signer sends verify key to Verifier
70
+ verify_key_string = signing_key.verify_key.serialize
71
+
72
+ # Verifier
73
+ verify_key = OpenSSL::SignatureAlgorithm::EdDSA::VerifyKey.deserialize(verify_key_string)
74
+ algorithm = OpenSSL::SignatureAlgorithm::EdDSA.new
75
+ algorithm.verify_key = verify_key
76
+ algorithm.verify(signature, to_be_signed)
77
+ ```
78
+
53
79
  ### RSA-PSS
54
80
 
55
81
  ```ruby
@@ -7,6 +7,7 @@ gem "byebug", "~> 11.0"
7
7
  gem "rake", "~> 13.0"
8
8
  gem "rspec", "~> 3.0"
9
9
  gem "rubocop", "~> 0.80.1"
10
+ gem "ed25519", "~> 1.2"
10
11
  gem "openssl", "~> 2.0.0"
11
12
 
12
13
  gemspec path: "../"
@@ -7,6 +7,7 @@ gem "byebug", "~> 11.0"
7
7
  gem "rake", "~> 13.0"
8
8
  gem "rspec", "~> 3.0"
9
9
  gem "rubocop", "~> 0.80.1"
10
+ gem "ed25519", "~> 1.2"
10
11
  gem "openssl", "~> 2.1.0"
11
12
 
12
13
  gemspec path: "../"
@@ -7,6 +7,7 @@ gem "byebug", "~> 11.0"
7
7
  gem "rake", "~> 13.0"
8
8
  gem "rspec", "~> 3.0"
9
9
  gem "rubocop", "~> 0.80.1"
10
+ gem "ed25519", "~> 1.2"
10
11
  gem "openssl", "~> 2.2.0"
11
12
 
12
13
  gemspec path: "../"
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "delegate"
3
4
  require "openssl"
4
5
  require "openssl/signature_algorithm/base"
5
6
 
@@ -8,9 +9,9 @@ module OpenSSL
8
9
  class ECDSA < Base
9
10
  BYTE_LENGTH = 8
10
11
 
11
- class SigningKey < OpenSSL::PKey::EC
12
+ class SigningKey < DelegateClass(OpenSSL::PKey::EC)
12
13
  def initialize(*args)
13
- super(*args).generate_key
14
+ super(OpenSSL::PKey::EC.generate(*args))
14
15
  end
15
16
 
16
17
  def verify_key
@@ -18,7 +19,11 @@ module OpenSSL
18
19
  end
19
20
  end
20
21
 
21
- class VerifyKey < OpenSSL::PKey::EC::Point
22
+ class VerifyKey < DelegateClass(OpenSSL::PKey::EC::Point)
23
+ def initialize(*args)
24
+ super(OpenSSL::PKey::EC::Point.new(*args))
25
+ end
26
+
22
27
  def self.deserialize(pem_string)
23
28
  new(OpenSSL::PKey::EC.new(pem_string).public_key)
24
29
  end
@@ -30,10 +35,16 @@ module OpenSSL
30
35
  def ec_key
31
36
  @ec_key ||=
32
37
  begin
33
- ec_key = OpenSSL::PKey::EC.new(group)
34
- ec_key.public_key = self
35
-
36
- ec_key
38
+ # RFC5480 SubjectPublicKeyInfo
39
+ asn1 = OpenSSL::ASN1::Sequence([
40
+ OpenSSL::ASN1::Sequence([
41
+ OpenSSL::ASN1::ObjectId("id-ecPublicKey"),
42
+ OpenSSL::ASN1::ObjectId(group.curve_name),
43
+ ]),
44
+ OpenSSL::ASN1::BitString(to_octet_string(:uncompressed))
45
+ ])
46
+
47
+ OpenSSL::PKey::EC.new(asn1.to_der)
37
48
  end
38
49
  end
39
50
 
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ gem "ed25519", ">= 1.0.0"
5
+ require "ed25519"
6
+ rescue LoadError
7
+ warn "OpenSSL::SignatureAlgorithm::EdDSA requires the ed25519 gem, version 1.0 or higher. "\
8
+ "Please add it to your Gemfile: `gem \"ed25519\", \"~> 1.0\"`"
9
+ raise
10
+ end
11
+
12
+ require "openssl/signature_algorithm/base"
13
+
14
+ module OpenSSL
15
+ module SignatureAlgorithm
16
+ class EdDSA < Base
17
+ class SigningKey < ::Ed25519::SigningKey
18
+ def verify_key
19
+ VerifyKey.new(keypair[32, 32])
20
+ end
21
+ end
22
+
23
+ class VerifyKey < ::Ed25519::VerifyKey
24
+ def self.deserialize(key_bytes)
25
+ new(key_bytes)
26
+ end
27
+
28
+ def serialize
29
+ to_bytes
30
+ end
31
+ end
32
+
33
+ def generate_signing_key
34
+ @signing_key = SigningKey.generate
35
+ end
36
+
37
+ def sign(data)
38
+ signing_key.sign(data)
39
+ end
40
+
41
+ def verify(signature, verification_data)
42
+ verify_key.verify(signature, verification_data)
43
+ rescue ::Ed25519::VerifyError
44
+ raise(OpenSSL::SignatureAlgorithm::SignatureVerificationError, "Signature verification failed")
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,22 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "delegate"
3
4
  require "openssl"
4
5
  require "openssl/signature_algorithm/base"
5
6
 
6
7
  module OpenSSL
7
8
  module SignatureAlgorithm
8
9
  class RSA < Base
9
- class SigningKey < OpenSSL::PKey::RSA
10
+ class SigningKey < DelegateClass(OpenSSL::PKey::RSA)
11
+ def initialize(*args)
12
+ super(OpenSSL::PKey::RSA.new(*args))
13
+ end
14
+
10
15
  def verify_key
11
16
  VerifyKey.new(public_key.to_pem)
12
17
  end
13
18
  end
14
19
 
15
- class VerifyKey < OpenSSL::PKey::RSA
20
+ class VerifyKey < DelegateClass(OpenSSL::PKey::RSA)
16
21
  class << self
17
22
  alias_method :deserialize, :new
18
23
  end
19
24
 
25
+ def initialize(*args)
26
+ super(OpenSSL::PKey::RSA.new(*args))
27
+ end
28
+
20
29
  def serialize
21
30
  to_pem
22
31
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OpenSSL
4
4
  module SignatureAlgorithm
5
- VERSION = "1.0.0"
5
+ VERSION = "1.2.1"
6
6
  end
7
7
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["gonzalo@cedarcode.com"]
10
10
  spec.license = "Apache-2.0"
11
11
 
12
- spec.summary = "ECDSA, RSA-PSS and RSA-PKCS#1 algorithms for ruby"
12
+ spec.summary = "ECDSA, EdDSA, RSA-PSS and RSA-PKCS#1 algorithms for ruby"
13
13
  spec.description = spec.summary
14
14
 
15
15
  spec.homepage = "https://github.com/cedarcode/openssl-signature_algorithm"
@@ -27,4 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.bindir = "exe"
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
+
31
+ spec.add_runtime_dependency "openssl", "> 2.0", "< 3.1"
30
32
  end
metadata CHANGED
@@ -1,26 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openssl-signature_algorithm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gonzalo Rodriguez
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-08 00:00:00.000000000 Z
12
- dependencies: []
13
- description: ECDSA, RSA-PSS and RSA-PKCS#1 algorithms for ruby
11
+ date: 2022-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: openssl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.1'
33
+ description: ECDSA, EdDSA, RSA-PSS and RSA-PKCS#1 algorithms for ruby
14
34
  email:
15
35
  - gonzalo@cedarcode.com
16
36
  executables: []
17
37
  extensions: []
18
38
  extra_rdoc_files: []
19
39
  files:
40
+ - ".github/workflows/build.yml"
20
41
  - ".gitignore"
21
42
  - ".rspec"
22
43
  - ".rubocop.yml"
23
- - ".travis.yml"
24
44
  - Appraisals
25
45
  - CHANGELOG.md
26
46
  - Gemfile
@@ -34,11 +54,10 @@ files:
34
54
  - gemfiles/openssl_2_0.gemfile
35
55
  - gemfiles/openssl_2_1.gemfile
36
56
  - gemfiles/openssl_2_2.gemfile
37
- - gemfiles/openssl_default.gemfile
38
- - gemfiles/openssl_head.gemfile
39
57
  - lib/openssl/signature_algorithm.rb
40
58
  - lib/openssl/signature_algorithm/base.rb
41
59
  - lib/openssl/signature_algorithm/ecdsa.rb
60
+ - lib/openssl/signature_algorithm/eddsa.rb
42
61
  - lib/openssl/signature_algorithm/error.rb
43
62
  - lib/openssl/signature_algorithm/rsa.rb
44
63
  - lib/openssl/signature_algorithm/rsapkcs1.rb
@@ -52,7 +71,7 @@ metadata:
52
71
  homepage_uri: https://github.com/cedarcode/openssl-signature_algorithm
53
72
  source_code_uri: https://github.com/cedarcode/openssl-signature_algorithm
54
73
  changelog_uri: https://github.com/cedarcode/openssl-signature_algorithm/blob/master/CHANGELOG.md
55
- post_install_message:
74
+ post_install_message:
56
75
  rdoc_options: []
57
76
  require_paths:
58
77
  - lib
@@ -67,8 +86,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
86
  - !ruby/object:Gem::Version
68
87
  version: '0'
69
88
  requirements: []
70
- rubygems_version: 3.1.4
71
- signing_key:
89
+ rubygems_version: 3.2.32
90
+ signing_key:
72
91
  specification_version: 4
73
- summary: ECDSA, RSA-PSS and RSA-PKCS#1 algorithms for ruby
92
+ summary: ECDSA, EdDSA, RSA-PSS and RSA-PKCS#1 algorithms for ruby
74
93
  test_files: []
data/.travis.yml DELETED
@@ -1,24 +0,0 @@
1
- ---
2
- dist: bionic
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - ruby-head
7
- - 2.7.1
8
- - 2.6.6
9
- - 2.5.8
10
- - 2.4.10
11
- gemfile:
12
- - gemfiles/openssl_head.gemfile
13
- - gemfiles/openssl_2_2.gemfile
14
- - gemfiles/openssl_2_1.gemfile
15
- - gemfiles/openssl_2_0.gemfile
16
- - gemfiles/openssl_default.gemfile
17
- matrix:
18
- fast_finish: true
19
- allow_failures:
20
- - rvm: ruby-head
21
- - gemfile: gemfiles/openssl_head.gemfile
22
- before_install:
23
- - gem install bundler -v 2.1.4
24
- - rm Gemfile.lock
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal", "~> 2.2"
6
- gem "byebug", "~> 11.0"
7
- gem "rake", "~> 13.0"
8
- gem "rspec", "~> 3.0"
9
- gem "rubocop", "~> 0.80.1"
10
-
11
- gemspec path: "../"
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal", "~> 2.2"
6
- gem "byebug", "~> 11.0"
7
- gem "rake", "~> 13.0"
8
- gem "rspec", "~> 3.0"
9
- gem "rubocop", "~> 0.80.1"
10
- gem "openssl", git: "https://github.com/ruby/openssl"
11
-
12
- gemspec path: "../"