Compare commits

...

3 Commits

Author SHA1 Message Date
Juhani Krekelä 7754f17cc9 Use .sshwot/*.sshwot by default in sshwot-filter 2018-09-01 21:55:09 +03:00
Juhani Krekelä 013d588537 Use os.path.join 2018-09-01 21:49:11 +03:00
Juhani Krekelä 44bc940675 Chain throws 2018-09-01 21:43:35 +03:00
4 changed files with 36 additions and 6 deletions

View File

@ -4,7 +4,7 @@ SSHWOT_EXPORT_KNOWN_HOSTS_MAIN:=src/main-export-known-hosts.py
SSHWOT_EXPORT_KNOWN_HOSTS_DEPS:=src/entry.py src/hashing.py src/process_known_hosts.py src/write_file.py
SSHWOT_FILTER_MAIN:=src/main-filter.py
SSHWOT_FILTER_DEPS:=src/entry.py src/hashing.py src/read_file.py src/write_file.py
SSHWOT_FILTER_DEPS:=src/entry.py src/hashing.py src/open_default_files.py src/read_file.py src/write_file.py
all: $(BINS)

View File

@ -48,14 +48,14 @@ def main():
try:
homedir = os.environ['HOME']
except KeyError:
raise KeyError('$HOME is not set')
except KeyError as err:
raise KeyError('$HOME is not set') from err
# The input file
# Default to ~/.ssh/known_hosts
parser.add_argument('infile',
nargs = '?',
default = homedir + '/.ssh/known_hosts',
default = os.path.join(homedir, '.ssh/known_hosts'),
help = 'a file in .ssh/known_hosts format'
)

View File

@ -3,11 +3,11 @@ import sys
import entry
import hashing
import open_default_files
import read_file
import write_file
def main():
# TODO: Default location to search
parser = argparse.ArgumentParser(
description = """Search sshwot file(s) for given host and/or
fingerprint.""",
@ -94,8 +94,14 @@ def main():
else:
fingerprint = None
# Use the default files if no input files were specified
if len(args.infiles) == 0:
infiles = open_default_files.open_all()
else:
infiles = args.infiles
matches = []
for infile in args.infiles:
for infile in infiles:
entries, file_comment = read_file.read(infile)
# Filter by host if it's present

24
src/open_default_files.py Normal file
View File

@ -0,0 +1,24 @@
import os
def open_all():
"""open_all() → [file(rb)]
Open the default sshwot files"""
try:
homedir = os.environ['HOME']
except KeyError as err:
raise KeyError('$HOME is not set') from err
# If the directory doesn't exist, just return empty
try:
sshwot_dir = os.listdir(os.path.join(homedir, '.sshwot'))
except FileNotFoundError:
return []
# Read all the .sshwot files from /.sshwot by default
files = []
for dir_entry in sshwot_dir:
if dir_entry.split('.')[-1] == 'sshwot':
files.append(open(dir_entry, 'rb'))
return files