class TLSmap::CLI
Offline version of {App}
Constants
- INTEGRITY
Public Class Methods
new(force = false)
click to toggle source
Load and parse data from marshalized hash (`data/mapping.marshal`). It must match the integrity check for security purpose. @param force [Boolean] Force parsing even if integrity check failed (DANGEROUS,
may result in command execution vulnerability)
# File lib/tls_map/cli/cli.rb, line 16 def initialize(force = false) # rubocop:disable Lint/MissingSuper @storage_location = 'data/' @database_path = absolute_db_path('mapping.marshal') database_exists? @tls_map = [] parse(force) end
Public Instance Methods
update()
click to toggle source
# File lib/tls_map/cli/cli.rb, line 50 def update tm = TLSmap::App.new tm.export(@database_path, :marshal) end
Protected Instance Methods
absolute_db_path(filename)
click to toggle source
Find the absolute path of the a data file from its relative location @param filename [String] file name @return [String] absolute filename of the data file
# File lib/tls_map/cli/cli.rb, line 27 def absolute_db_path(filename) pn = Pathname.new(__FILE__) install_dir = pn.dirname.parent.parent.parent.to_s + Pathname::SEPARATOR_LIST install_dir + @storage_location + filename end
database_exists?()
click to toggle source
Check if the TLS database DB exists @return [Boolean] `true` if the file exists
# File lib/tls_map/cli/cli.rb, line 35 def database_exists? exists = File.file?(@database_path) raise "Database does not exist: #{@database_path}" unless exists exists end
parse(force = false)
click to toggle source
# File lib/tls_map/cli/cli.rb, line 42 def parse(force = false) if Digest::SHA256.file(@database_path).hexdigest == INTEGRITY || force # rubocop:disable Style/GuardClause @tls_map = Marshal.load(File.read(@database_path)) # rubocop:disable Security/MarshalLoad else raise 'Integrity check failed, maybe be due to unvalidated database after update' end end