class SSHScan::FingerprintDatabase

Create and/or maintain a fingerprint database using YAML Store.

Public Class Methods

new(database_name) click to toggle source
# File lib/ssh_scan/fingerprint_database.rb, line 6
def initialize(database_name)
  @store = YAML::Store.new(database_name)
end

Public Instance Methods

add_fingerprint(fingerprint, ip) click to toggle source

Insert a (fingerprint, IP) record. @param fingerprint [String] fingerprint to insert @param ip [String] IP for which fingerprint has to be added

# File lib/ssh_scan/fingerprint_database.rb, line 22
def add_fingerprint(fingerprint, ip)
  @store.transaction do
    @store[ip] = [] if @store[ip].nil?
    @store[ip] << fingerprint
  end
end
clear_fingerprints(ip) click to toggle source

Empty the fingerprints database for given IP. @param ip [String] IP for which fingerprints should be

cleared.
# File lib/ssh_scan/fingerprint_database.rb, line 13
def clear_fingerprints(ip)
  @store.transaction do
    @store[ip] = []
  end
end
find_fingerprints(fingerprint) click to toggle source

Find IPs that have the given fingerprint. @param fingerprint [String] fingerprint for which search

should be performed

@return [Array<String>] return unique IPs for which the given

fingerprint has an entry
# File lib/ssh_scan/fingerprint_database.rb, line 34
def find_fingerprints(fingerprint)
  ip_matches = []

  @store.transaction(true) do
    @store.roots.each do |ip|
      @store[ip].each do |other_fingerprint|
        if fingerprint == other_fingerprint
          ip_matches << ip
        end
      end
    end
  end

  return ip_matches.uniq
end