a1668f2b23
Pubkeys are now stored as loot, and the Cred model has new and exciting ways to discover which pubkeys match which privkeys. Squashed commit of the following: commit 036d2eb61500da7e161f50d348a44fbf615f6e17 Author: Tod Beardsley <todb@metasploit.com> Date: Sun Jan 8 22:23:32 2012 -0600 Updates ssh credentials to easily find common keys Instead of making the modules do all the work of cross-checking keys, this introduces a few new methods to the Cred model to make this more universal. Also includes the long-overdue workspace() method for credentials. So far, nothing actually implements it, but it's nice that it's there now. commit c28430a721fc6272e48329bed902dd5853b4a75a Author: Tod Beardsley <todb@metasploit.com> Date: Sun Jan 8 20:10:40 2012 -0600 Adding back cross-checking for privkeys. Needs to test to see if anything depends on order, but should be okay to mark up the privkey proof with this as well. commit dd3563995d4d3c015173e730eebacf471c671b4f Author: Tod Beardsley <todb@metasploit.com> Date: Sun Jan 8 16:49:56 2012 -0600 Add SSHKey gem, convert PEM pubkeys to SSH pubkeys commit 11fc363ebda7bda2c3ad6d940299bf4cbafac6fd Author: Tod Beardsley <todb@metasploit.com> Date: Sun Jan 8 13:51:55 2012 -0600 Store pubkeys as loot for reuse. Yanked cross checking for now, will drop back in before pushing. commit aad12b31a897db2952999f7be0161df1f59b6000 Author: Tod Beardsley <todb@metasploit.com> Date: Sun Jan 8 02:10:12 2012 -0600 Fixes up a couple typos in ssh_identify_pubkeys commit 48937728a92b9ae52d0b93cdcd20bb83f15f8803 Author: Tod Beardsley <todb@metasploit.com> Date: Sat Jan 7 17:18:33 2012 -0600 Updates to ssh_identify_pubkeys and friends Switches reporting to cred-based rather than note-based, accurately deal with DSA keys, adds disable_agent option to other ssh modules, and reports successful ssh_login attempts pubkey fingerprints as well. This last thing Leads to some double accounting of creds, so I'm not super-thrilled, but it sure makes searching for ssh_pubkey types a lot easier.... maybe a better solution is to just have a special method for the cred model, though. |
||
---|---|---|
.. | ||
lib | ||
LICENSE | ||
README.md |
README.md
sshkey
Generate private and public SSH keys (RSA and DSA supported) using pure Ruby.
gem install sshkey
Tested on the following Rubies: MRI 1.8.7, 1.9.2, 1.9.3, REE. Ruby must be compiled with OpenSSL support.
Usage
When generating a new keypair the default key type is 2048-bit RSA, but you can supply the type
(RSA or DSA) and bits
in the options.
You can also (optionally) supply a comment
:
k = SSHKey.generate
k = SSHKey.generate(:type => "DSA", :bits => 1024, :comment => "foo@bar.com")
Return an SSHKey object from an existing RSA or DSA private key (provided as a string)
k = SSHKey.new(File.read("~/.ssh/id_rsa"), :comment => "foo@bar.com")
Both of these will return an SSHKey object with the following methods:
# Returns an OpenSSL::PKey::RSA or OpenSSL::PKey::DSA key object
# http://www.ruby-doc.org/stdlib/libdoc/openssl/rdoc/classes/OpenSSL/PKey/RSA.html
# http://www.ruby-doc.org/stdlib/libdoc/openssl/rdoc/classes/OpenSSL/PKey/DSA.html
k.key_object
# => -----BEGIN RSA PRIVATE KEY-----\nMIIEowI...
# Returns the Private Key as a string
k.private_key
# => "-----BEGIN RSA PRIVATE KEY-----\nMIIEowI..."
# Returns the Public Key as a string
k.public_key
# => "-----BEGIN RSA PUBLIC KEY-----\nMIIBCg..."
# Returns the SSH Public Key as a string
k.ssh_public_key
# => "ssh-rsa AAAAB3NzaC1yc2EA...."
# Returns the comment as a string
k.comment
# => "foo@bar.com"
# Returns the MD5 fingerprint as a string
k.md5_fingerprint
# => "2a:89:84:c9:29:05:d1:f8:49:79:1c:ba:73:99:eb:af"
# Returns the SHA1 fingerprint as a string
k.sha1_fingerprint
# => "e4:f9:79:f2:fe:d6:be:2d:ef:2e:c2:fa:aa:f8:b0:17:34:fe:0d:c0"
# Validates SSH Public Key
SSHKey.valid_ssh_public_key? "ssh-rsa AAAAB3NzaC1yc2EA...."
# => true
Copyright
Copyright (c) 2011 James Miller