Class: SSHScan::Crypto::PublicKey

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

Overview

House methods helpful in analysing SSH public keys.

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ PublicKey

Returns a new instance of PublicKey.



10
11
12
# File 'lib/ssh_scan/crypto.rb', line 10

def initialize(key)
  @key = key
end

Instance Method Details

#bad_key?Boolean

Is the current key known to be in our known bad key list

Returns:



18
19
20
21
22
23
24
25
26
# File 'lib/ssh_scan/crypto.rb', line 18

def bad_key?
  SSHScan::Crypto.bad_public_keys.each do |other_key|
    if self.fingerprint_sha256 == other_key.fingerprint_sha256
      return true
    end
  end

  return false
end

#fingerprint_md5String

Generate MD5 fingerprint for this SSHScan::Crypto::PublicKey instance.

Returns:

  • (String)

    formatted MD5 fingerprint



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

def fingerprint_md5
  OpenSSL::Digest::MD5.hexdigest(::Base64.decode64(@key)).scan(/../).join(':')
end

#fingerprint_sha1String

Generate SHA1 fingerprint for this SSHScan::Crypto::PublicKey instance.

Returns:

  • (String)

    formatted SHA1 fingerprint



36
37
38
# File 'lib/ssh_scan/crypto.rb', line 36

def fingerprint_sha1
  OpenSSL::Digest::SHA1.hexdigest(::Base64.decode64(@key)).scan(/../).join(':')
end

#fingerprint_sha256String

Generate SHA256 fingerprint for this SSHScan::Crypto::PublicKey instance.

Returns:

  • (String)

    formatted SHA256 fingerprint



42
43
44
# File 'lib/ssh_scan/crypto.rb', line 42

def fingerprint_sha256
  OpenSSL::Digest::SHA256.hexdigest(::Base64.decode64(@key)).scan(/../).join(':')
end