Class: Sshkeyproof::Client
- Inherits:
-
Object
- Object
- Sshkeyproof::Client
- Defined in:
- lib/sshkeyauth.rb
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Client
constructor
A new instance of Client.
- #random ⇒ Object
- #request ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 |
# File 'lib/sshkeyauth.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/sshkeyauth.rb', line 15 def random @random ||= OpenSSL::Random.random_bytes(10).unpack('H*').first end |
#request ⇒ Object
19 20 21 22 |
# File 'lib/sshkeyauth.rb', line 19 def request ciphertext = @privkey.private_encrypt(random).unpack('H*').first "#{SSHKey.sha1_fingerprint(@pubkey.to_s)}|#{random.unpack('H*').first}|#{ciphertext}" end |