Skip to content

Commit

Permalink
Fix key signing for OpenSSL 3.
Browse files Browse the repository at this point in the history
See issue potatosalad#19
chore: Force OpenSSL 3 on dev.
chore: Upgrade Bundler.
  • Loading branch information
ronald05arias committed Mar 15, 2023
1 parent e1be589 commit 4a9e839
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ platforms :ruby do
gem 'pry-doc'
# gem 'redcarpet'
gem 'yard'
gem 'openssl', '~> 3.1'
end
end

Expand Down
2 changes: 1 addition & 1 deletion jose.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Gem::Specification.new do |spec|

spec.add_dependency "hamster"

spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "bundler", "~> 2.2"
spec.add_development_dependency "rake", "~> 12.3"
spec.add_development_dependency "minitest"
spec.add_development_dependency "json"
Expand Down
19 changes: 15 additions & 4 deletions lib/jose/jwk/kty_ec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@ def self.from_map(fields)
else
raise ArgumentError, "invalid 'EC' JWK"
end
ec = OpenSSL::PKey::EC.new(crv)
x = JOSE.urlsafe_decode64(fields['x'])
y = JOSE.urlsafe_decode64(fields['y'])
ec.public_key = OpenSSL::PKey::EC::Point.new(
OpenSSL::PKey::EC::Group.new(crv),
OpenSSL::BN.new([0x04, x, y].pack('Ca*a*'), 2)

group = OpenSSL::PKey::EC::Group.new(crv)
bn = OpenSSL::BN.new([0x04, x, y].pack('Ca*a*'), 2)
point = OpenSSL::PKey::EC::Point.new group, bn
sequence = OpenSSL::ASN1::Sequence(
[
OpenSSL::ASN1::Sequence(
[
OpenSSL::ASN1::ObjectId("id-ecPublicKey"),
OpenSSL::ASN1::ObjectId(crv)
]
),
OpenSSL::ASN1::BitString(point.to_octet_string(:uncompressed))
]
)
ec = OpenSSL::PKey::EC.new sequence.to_der
if fields['d'].is_a?(String)
ec.private_key = OpenSSL::BN.new(JOSE.urlsafe_decode64(fields['d']), 2)
end
Expand Down

0 comments on commit 4a9e839

Please sign in to comment.