Class: Sshkeyproof::Client
- Inherits:
-
Object
- Object
- Sshkeyproof::Client
- Defined in:
- lib/sshkeyproof.rb
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Client
constructor
A new instance of Client.
- #random ⇒ Object
- #request ⇒ Object
- #to_hex(str) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 |
# File 'lib/sshkeyproof.rb', line 7 def initialize(params={}) key_file = params[:key_file] || '~/.ssh/id_rsa' ssh_key = params[:ssh_key] || File.read(key_file) openssl_key = params[:openssl_key] || OpenSSL::PKey::RSA.new(ssh_key) @privkey = openssl_key if openssl_key.private? @pubkey = @privkey && @privkey.public_key || openssl_key end |
Instance Method Details
#random ⇒ Object
15 16 17 |
# File 'lib/sshkeyproof.rb', line 15 def random @random ||= OpenSSL::Random.random_bytes(10) end |
#request ⇒ Object
19 20 21 22 |
# File 'lib/sshkeyproof.rb', line 19 def request ciphertext = to_hex @privkey.private_encrypt(random) [SSHKey.sha1_fingerprint(@pubkey.to_s),to_hex(random),ciphertext].join('|') end |
#to_hex(str) ⇒ Object
24 25 26 |
# File 'lib/sshkeyproof.rb', line 24 def to_hex(str) str.unpack('H*').first end |