Class: Sshkeyproof::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/sshkeyproof.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_string) ⇒ Server

Returns a new instance of Server.



31
32
33
# File 'lib/sshkeyproof.rb', line 31

def initialize(request_string)
  (@fingerprint,@random,@ciphertext) = request_string.to_s.split("|")
end

Instance Attribute Details

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



30
31
32
# File 'lib/sshkeyproof.rb', line 30

def fingerprint
  @fingerprint
end

Instance Method Details

#correct?(key) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/sshkeyproof.rb', line 35

def correct?(key)
  openssl_key = String===key ? OpenSSL::PKey::RSA.new(key) : key
  @fingerprint && @random && @ciphertext && openssl_key.public_key.public_decrypt(from_hex(@ciphertext)) == from_hex(@random) rescue nil
end

#from_hex(str) ⇒ Object



40
41
42
# File 'lib/sshkeyproof.rb', line 40

def from_hex(str)
  [str].pack('H*')
end