Module: PuTTY::Key::OpenSSL::ClassMethods

Defined in:
lib/putty/key/openssl.rb

Overview

The ClassMethods module is used to extend OpenSSL::PKey when using the PuTTY::Key refinement or calling PuTTY::Key.global_install. This adds a from_ppk class method to OpenSSL::PKey.

Instance Method Summary collapse

Instance Method Details

#from_ppk(ppk) ⇒ Object

Creates a new OpenSSL::PKey from a PuTTY private key (instance of PPK).

This method is called using OpenSSL::PKey.from_ppk(ppk).

PuTTY keys using the algorithms ssh-dss, ssh-rsa, ecdsa-sha2-nistp256, ecdsa-sha2-nistp384 and ecdsa-sha2-nistp521 are supported.

Returns:

  • (Object)

    An instance of either OpenSSL::PKey::DSA, OpenSSL::PKey::RSA or OpenSSL::PKey::EC depending on the algorithm of ppk.

Raises:

  • (ArgumentError)

    If ppk is nil.

  • (ArgumentError)

    If the algorithm of ppk is not supported.



304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/putty/key/openssl.rb', line 304

def from_ppk(ppk)
  raise ArgumentError, 'ppk must not be nil' unless ppk

  case ppk.algorithm
  when 'ssh-dss'
    PKeyBuilding.ppk_to_dsa(ppk)
  when 'ssh-rsa'
    PKeyBuilding.ppk_to_rsa(ppk)
  when /\Aecdsa-sha2-(nistp(?:256|384|521))\z/
    PKeyBuilding.ppk_to_ec(ppk, $1)
  else
    raise ArgumentError, "Unsupported algorithm: #{ppk.algorithm}"
  end
end