Skip to content

Commit c46c9b9

Browse files
Merge pull request #5 from ClearlyClaire/openssl-3
Add support for OpenSSL 3.0
2 parents 5bf43cd + 5185307 commit c46c9b9

File tree

6 files changed

+37
-12
lines changed

6 files changed

+37
-12
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
- 2.5.8
2323
- 2.4.10
2424
gemfile:
25+
- openssl_3_0
2526
- openssl_2_2
2627
- openssl_2_1
2728
- openssl_2_0

Appraisals

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# frozen_string_literal: true
22

3+
appraise "openssl_3_0" do
4+
gem "openssl", "~> 3.0.0"
5+
end
6+
37
appraise "openssl_2_2" do
48
gem "openssl", "~> 2.2.0"
59
end

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PATH
22
remote: .
33
specs:
44
openssl-signature_algorithm (1.1.1)
5-
openssl (~> 2.0)
5+
openssl (> 2.0, < 3.1)
66

77
GEM
88
remote: https://rubygems.org/
@@ -16,7 +16,7 @@ GEM
1616
diff-lcs (1.3)
1717
ed25519 (1.2.4)
1818
jaro_winkler (1.5.4)
19-
openssl (2.2.0)
19+
openssl (3.0.0)
2020
parallel (1.19.1)
2121
parser (2.7.0.5)
2222
ast (~> 2.4.0)

lib/openssl/signature_algorithm/ecdsa.rb

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require "delegate"
34
require "openssl"
45
require "openssl/signature_algorithm/base"
56

@@ -8,17 +9,21 @@ module SignatureAlgorithm
89
class ECDSA < Base
910
BYTE_LENGTH = 8
1011

11-
class SigningKey < OpenSSL::PKey::EC
12+
class SigningKey < DelegateClass(OpenSSL::PKey::EC)
1213
def initialize(*args)
13-
super(*args).generate_key
14+
super(OpenSSL::PKey::EC.generate(*args))
1415
end
1516

1617
def verify_key
1718
VerifyKey.new(group, public_key.to_bn)
1819
end
1920
end
2021

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+
2227
def self.deserialize(pem_string)
2328
new(OpenSSL::PKey::EC.new(pem_string).public_key)
2429
end
@@ -30,10 +35,16 @@ def serialize
3035
def ec_key
3136
@ec_key ||=
3237
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)
3748
end
3849
end
3950

lib/openssl/signature_algorithm/rsa.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
# frozen_string_literal: true
22

3+
require "delegate"
34
require "openssl"
45
require "openssl/signature_algorithm/base"
56

67
module OpenSSL
78
module SignatureAlgorithm
89
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+
1015
def verify_key
1116
VerifyKey.new(public_key.to_pem)
1217
end
1318
end
1419

15-
class VerifyKey < OpenSSL::PKey::RSA
20+
class VerifyKey < DelegateClass(OpenSSL::PKey::RSA)
1621
class << self
1722
alias_method :deserialize, :new
1823
end
1924

25+
def initialize(*args)
26+
super(OpenSSL::PKey::RSA.new(*args))
27+
end
28+
2029
def serialize
2130
to_pem
2231
end

openssl-signature_algorithm.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ Gem::Specification.new do |spec|
2828
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2929
spec.require_paths = ["lib"]
3030

31-
spec.add_runtime_dependency "openssl", "~> 2.0"
31+
spec.add_runtime_dependency "openssl", "> 2.0", "< 3.1"
3232
end

0 commit comments

Comments
 (0)