openssl-additions 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openssl/ssh_pkey.rb +41 -18
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 960c29488ad97c87c67fa2b6aa7a286a51b4678ab190ebc628a3d55efcb9125a
4
- data.tar.gz: 284c3dc79c7325406e06567c7e2c34d6439b3050f8bf25202b088e5a1fe802f7
3
+ metadata.gz: 9d01b46bfb7b9b7ede0a8bb827bcd9471fc77b9b742e0c05f48e3f087d5825fe
4
+ data.tar.gz: 997750442f217b63103d55aef642d668f2979075cf8e7d96fd50e4e00e13ee5e
5
5
  SHA512:
6
- metadata.gz: 578c11f9214f96bb30aed6332fb8893fdd547a66b5d0c6c10fff5df39dbcc5d48d71966dce0f88b2e52344d7ac4cf126fd829939fbf75783b61ae801b93eebb7
7
- data.tar.gz: 788e22b2e62c2d1573ce49d4c6de45f56af518f1bb0476e7a83856164480d81a9f3cfbd6cad41b4d801817078069c75d76c7b20d8603ba8f9720bc9d9184fd83
6
+ metadata.gz: 9baca53d9a137c51dc68e1dc57187864cad7aba656616752a7d5c7d8493a0650372923969313f080623283990e31d81d4fe6ecdf55b28d31b8cb8a5c9e160b1a
7
+ data.tar.gz: 0a6ce69fa390f8295e81dad132b5994031eeb28fa8df962c6aad957404bf3eb36e7f877a37e9e4d96f82a08b6d95567187bfdc14ed17006d314af85f373aa04d
@@ -296,7 +296,7 @@ module OpenSSL::PKey
296
296
  end
297
297
 
298
298
  def self.decode_public_ssh_key(s)
299
- if s =~ /\A(ssh|ecdsa)-[a-z0-9-]+ /
299
+ if s =~ /\A(sk-)?(ssh|ecdsa)-/
300
300
  # WHOOP WHOOP prefixed key detected.
301
301
  s = s.split(" ")[1]
302
302
  else
@@ -313,27 +313,50 @@ module OpenSSL::PKey
313
313
 
314
314
  case parts.first
315
315
  when "ssh-rsa"
316
- OpenSSL::PKey::RSA.new.tap do |k|
317
- # n, e
318
- k.set_key(ssh_key_mpi_decode(parts[2]), ssh_key_mpi_decode(parts[1]), nil)
319
- end
320
- when "ssh-dss"
321
- OpenSSL::PKey::DSA.new.tap do |k|
322
- # Self-explanatory, one would hope
323
- k.set_pqg(ssh_key_mpi_decode(parts[1]), ssh_key_mpi_decode(parts[2]), ssh_key_mpi_decode(parts[3]))
324
- end
316
+ e = ssh_key_mpi_decode(parts[1])
317
+ n = ssh_key_mpi_decode(parts[2])
318
+
319
+ # OpenSSL 3.0 stole our set_key, so we now have to play silly DER round-trip games... sigh
320
+ OpenSSL::PKey.read(
321
+ OpenSSL::ASN1::Sequence.new([
322
+ OpenSSL::ASN1::Sequence.new([
323
+ OpenSSL::ASN1::ObjectId.new("rsaEncryption"),
324
+ OpenSSL::ASN1::Null.new(nil),
325
+ ]),
326
+ OpenSSL::ASN1::BitString.new(
327
+ OpenSSL::ASN1::Sequence.new([
328
+ OpenSSL::ASN1::Integer.new(n),
329
+ OpenSSL::ASN1::Integer.new(e),
330
+ ]).to_der
331
+ ),
332
+ ]).to_der
333
+ )
325
334
  when /ecdsa-sha2-/
326
- begin
327
- OpenSSL::PKey::EC.new(SSH_CURVE_NAME_MAP[parts[1]]).tap do |k|
328
- k.public_key = OpenSSL::PKey::EC::Point.new(k.group, parts[2])
329
- end
330
- rescue TypeError
331
- raise OpenSSL::PKey::PKeyError.new,
332
- "Unknown curve identifier #{parts[1]}"
335
+ curve_name = SSH_CURVE_NAME_MAP[parts[1]]
336
+ if curve_name.nil?
337
+ raise OpenSSL::PKey::PKeyError.new, "Unknown curve identifier #{parts[1]}"
333
338
  end
339
+ point = parts[2]
340
+
341
+ # OpenSSL 3.0 stole our set_key, so we now have to play silly DER round-trip games... sigh
342
+ OpenSSL::PKey.read(
343
+ OpenSSL::ASN1::Sequence.new([
344
+ OpenSSL::ASN1::Sequence.new([
345
+ OpenSSL::ASN1::ObjectId.new("id-ecPublicKey"),
346
+ OpenSSL::ASN1::ObjectId.new(curve_name),
347
+ ]),
348
+ OpenSSL::ASN1::BitString.new(point),
349
+ ]).to_der
350
+ )
351
+ when "ssh-ed25519", "sk-ssh-ed25519@openssh.com"
352
+ # The Ruby OpenSSL bindings don't appear to provide a way to directly construct
353
+ # an ed25519 key from its parts; instead, we've got to encode our own public key
354
+ # DER and then get OpenSSL to read it. Thankfully, ed25519 keys aren't too
355
+ # complicated to construct in DER.
356
+ OpenSSL::PKey.read(OpenSSL::ASN1::Sequence.new([OpenSSL::ASN1::Sequence.new([OpenSSL::ASN1::ObjectId.new("ED25519")]), OpenSSL::ASN1::BitString.new(parts[1])]).to_der)
334
357
  else
335
358
  raise OpenSSL::PKey::PKeyError,
336
- "Unknown key type #{parts.first.inspect}"
359
+ "Unsupported key type #{parts.first.inspect}"
337
360
  end
338
361
  end
339
362
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openssl-additions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Palmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-13 00:00:00.000000000 Z
11
+ date: 2024-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler