Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def output_fingerprint(kex, pkm, sha256=True, padlen=0):
# type: (Optional[SSH2.Kex], Optional[SSH1.PublicKeyMessage], bool, int) -> None
with OutputBuffer() as obuf:
fps = []
if pkm is not None:
name = 'ssh-rsa1'
fp = SSH.Fingerprint(pkm.host_key_fingerprint_data)
bits = pkm.host_key_bits
fps.append((name, fp, bits))
for fpp in fps:
name, fp, bits = fpp
fpo = fp.sha256 if sha256 else fp.md5
p = '' if out.batch else ' ' * (padlen - len(name))
out.good('(fin) {0}{1} -- {2} {3}'.format(name, p, bits, fpo))
if len(obuf) > 0:
out.head('# fingerprints')
obuf.flush()
out.sep()
def output_algorithms(title, alg_db, alg_type, algorithms, maxlen=0):
# type: (str, Dict[str, Dict[str, List[List[str]]]], str, List[text_type], int) -> None
with OutputBuffer() as obuf:
for algorithm in algorithms:
output_algorithm(alg_db, alg_type, algorithm, maxlen)
if len(obuf) > 0:
out.head('# ' + title)
obuf.flush()
out.sep()
def output_recommendations(software, kex, pkm, padlen=0):
# type: (SSH.Software, SSH2.Kex, SSH1.PublicKeyMessage, int) -> None
for_server = True
with OutputBuffer() as obuf:
software, alg_rec = get_alg_recommendations(software, kex, pkm, for_server)
for sshv in range(2, 0, -1):
if sshv not in alg_rec:
continue
for alg_type in ['kex', 'key', 'enc', 'mac']:
if alg_type not in alg_rec[sshv]:
continue
for action in ['del', 'add']:
if action not in alg_rec[sshv][alg_type]:
continue
for name in alg_rec[sshv][alg_type][action]:
p = '' if out.batch else ' ' * (padlen - len(name))
if action == 'del':
an, sg, fn = 'remove', '-', out.warn
if alg_rec[sshv][alg_type][action][name] >= 10:
fn = out.fail
def output_security(banner, padlen):
# type: (SSH.Banner, int) -> None
with OutputBuffer() as obuf:
if banner:
software = SSH.Software.parse(banner)
output_security_sub('cve', software, padlen)
output_security_sub('txt', software, padlen)
if len(obuf) > 0:
out.head('# security')
obuf.flush()
out.sep()