Create a build system
This commit is contained in:
parent
49576e052d
commit
5aea3fc7ee
|
@ -2,3 +2,5 @@ __pycache__
|
||||||
*.pyc
|
*.pyc
|
||||||
*.swp
|
*.swp
|
||||||
*.sshwot
|
*.sshwot
|
||||||
|
build
|
||||||
|
sshwot-export-known-hosts
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
BINS=sshwot-export-known-hosts
|
||||||
|
|
||||||
|
SSHWOT_EXPORT_KNOWN_HOSTS_MAIN:=src/main-export-known-hosts.py
|
||||||
|
SSHWOT_EXPORT_KNOWN_HOSTS_DEPS:=$(SSHWOT_EXPORT_KNOWN_HOSTS_MAIN) src/entry.py src/hashing.py src/process_known_hosts.py src/write_file.py
|
||||||
|
|
||||||
|
all: $(BINS)
|
||||||
|
|
||||||
|
sshwot-export-known-hosts: $(SSHWOT_EXPORT_KNOWN_HOSTS_MAIN) $(SSHWOT_EXPORT_KNOWN_HOSTS_DEPS)
|
||||||
|
mkdir -p build/$@
|
||||||
|
cp $(SSHWOT_EXPORT_KNOWN_HOSTS_DEPS) build/$@/
|
||||||
|
cp $(SSHWOT_EXPORT_KNOWN_HOSTS_MAIN) build/$@/__main__.py
|
||||||
|
zip --quiet --junk-paths build/$@.zip build/$@/*.py
|
||||||
|
mkdir -p bin/
|
||||||
|
echo '#!/usr/bin/env python3' > $@
|
||||||
|
cat build/$@.zip >> $@
|
||||||
|
chmod +x $@
|
||||||
|
|
||||||
|
.PHONY: all clean distclean buildclean
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf build $(BINS)
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
|
||||||
|
buildclean:
|
||||||
|
rm -rf build
|
|
@ -3,14 +3,12 @@ import enum
|
||||||
import entry
|
import entry
|
||||||
import hashing
|
import hashing
|
||||||
|
|
||||||
class result(enum.Enum):
|
|
||||||
notfound, ok, fail = range(3)
|
|
||||||
|
|
||||||
def check_fingerprint(entries, domain, port, fingerprint):
|
def check_fingerprint(entries, domain, port, fingerprint):
|
||||||
"""check_fingerprint([Entry], str, u16, bytes[32]) → (enum result: result, str / None: comment)
|
"""check_fingerprint([Entry], str, u16, bytes[32]) → ([str]: successes, [str]: fails)
|
||||||
Checks if the given host is found with the given fingerprint.
|
Checks if the given host is found with the given fingerprint.
|
||||||
Will return the comment on the host if the host is found, regardless
|
The successes and fails lists returned by the function have the
|
||||||
of whether the fingerprint checks out."""
|
comments for the hosts that match and have the same fingerpring and
|
||||||
|
the hosts that match but have a different fingerprint, respectively"""
|
||||||
assert type(entries) == list and all(type(i) == entry.Entry for i in entries)
|
assert type(entries) == list and all(type(i) == entry.Entry for i in entries)
|
||||||
assert type(domain) == str
|
assert type(domain) == str
|
||||||
assert type(port) == int and 0 <= port <= (1<<16) - 1
|
assert type(port) == int and 0 <= port <= (1<<16) - 1
|
||||||
|
@ -26,26 +24,17 @@ def check_fingerprint(entries, domain, port, fingerprint):
|
||||||
if port != 22:
|
if port != 22:
|
||||||
normalized_hosts.append(entry.normalize_host(domain, 22))
|
normalized_hosts.append(entry.normalize_host(domain, 22))
|
||||||
|
|
||||||
|
successes = []
|
||||||
|
fails = []
|
||||||
for possible_match in entries:
|
for possible_match in entries:
|
||||||
for normalized_host in normalized_hosts:
|
for normalized_host in normalized_hosts:
|
||||||
hashed_host = hashing.hash_with_salt(normalized_host, possible_match.salt)
|
hashed_host = hashing.hash_with_salt(normalized_host, possible_match.salt)
|
||||||
if hashed_host == possible_match.hashed_host:
|
if hashed_host == possible_match.hashed_host:
|
||||||
# Convert the comment to a string
|
|
||||||
# We put replacement characters where
|
|
||||||
# decoding fails instead of throwing an
|
|
||||||
# error, because even whilethe comment
|
|
||||||
# field must be valid utf-8, failing in this
|
|
||||||
# situation is bad UX
|
|
||||||
comment = possible_match.comment.decode('utf-8', errors = 'replace')
|
|
||||||
# TODO: Justify this
|
|
||||||
# We only care about the first match, so we
|
|
||||||
# return here
|
|
||||||
if fingerprint == possible_match.fingerprint:
|
if fingerprint == possible_match.fingerprint:
|
||||||
# Fingerprint matches, it passes
|
# Fingerprint matches, it passes
|
||||||
return (result.ok, comment)
|
successes.append(possible_match.comment)
|
||||||
else:
|
else:
|
||||||
# Fingerprint different, it fails
|
# Fingerprint different, it fails
|
||||||
return (result.fail, comment)
|
fails.append(possible_match.comment)
|
||||||
|
|
||||||
# We did not match, tell the caller so
|
return successes, fails
|
||||||
return (result.notfound, None)
|
|
||||||
|
|
|
@ -3,11 +3,13 @@ import hashlib
|
||||||
|
|
||||||
import entry
|
import entry
|
||||||
|
|
||||||
|
# TODO: Include line number in the error
|
||||||
class KnownHostsSyntaxError(Exception): pass
|
class KnownHostsSyntaxError(Exception): pass
|
||||||
|
|
||||||
class HashedHostError(Exception): pass
|
class HashedHostError(Exception): pass
|
||||||
|
|
||||||
def process_line(line):
|
def process_line(line):
|
||||||
|
# TODO: Add a way to skip IPs
|
||||||
"""process_line(str) → [Entry]
|
"""process_line(str) → [Entry]
|
||||||
Given a string containing one line of .ssh/known_hosts file, create
|
Given a string containing one line of .ssh/known_hosts file, create
|
||||||
a list of Entries based on it."""
|
a list of Entries based on it."""
|
||||||
|
|
|
@ -2,6 +2,7 @@ import base64
|
||||||
|
|
||||||
import entry
|
import entry
|
||||||
|
|
||||||
|
# TODO: Include file number in the error info
|
||||||
class FileFormatError(Exception): pass
|
class FileFormatError(Exception): pass
|
||||||
|
|
||||||
class VersionMismatch(Exception): pass
|
class VersionMismatch(Exception): pass
|
||||||
|
|
Loading…
Reference in New Issue