Class: Sshkeyproof::Server
- Inherits:
-
Object
- Object
- Sshkeyproof::Server
- Defined in:
- lib/sshkeyproof.rb
Instance Attribute Summary collapse
-
#fingerprint ⇒ Object
readonly
Returns the value of attribute fingerprint.
Instance Method Summary collapse
- #correct?(key) ⇒ Boolean
- #from_hex(str) ⇒ Object
-
#initialize(request_string) ⇒ Server
constructor
A new instance of Server.
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
#fingerprint ⇒ Object (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
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 |