lib/ssh_scan/crypto.rb in ssh_scan-0.0.20 vs lib/ssh_scan/crypto.rb in ssh_scan-0.0.21

- old
+ new

@@ -1,34 +1,45 @@ require 'openssl' require 'sshkey' require 'base64' module SSHScan + # All cryptography related methods. module Crypto + # House methods helpful in analysing SSH public keys. class PublicKey def initialize(key) @key = key end # Is the current key known to be in our known bad key list + # @return [Boolean] true if this {SSHScan::Crypto::PublicKey} + # instance's key is also in {SSHScan::Crypto}'s + # bad_public_keys, otherwise false 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 + # Generate MD5 fingerprint for this {SSHScan::Crypto::PublicKey} instance. + # @return [String] formatted MD5 fingerprint def fingerprint_md5 OpenSSL::Digest::MD5.hexdigest(::Base64.decode64(@key)).scan(/../).join(':') end + # Generate SHA1 fingerprint for this {SSHScan::Crypto::PublicKey} instance. + # @return [String] formatted SHA1 fingerprint def fingerprint_sha1 OpenSSL::Digest::SHA1.hexdigest(::Base64.decode64(@key)).scan(/../).join(':') end + # Generate SHA256 fingerprint for this {SSHScan::Crypto::PublicKey} instance. + # @return [String] formatted SHA256 fingerprint def fingerprint_sha256 OpenSSL::Digest::SHA256.hexdigest(::Base64.decode64(@key)).scan(/../).join(':') end end