2020-07-03 20:56:46 +02:00
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
|
2020-10-15 20:34:23 +02:00
|
|
|
from ssh_audit.ssh2_kex import SSH2_Kex
|
|
|
|
from ssh_audit.ssh2_kexparty import SSH2_KexParty
|
|
|
|
|
2020-07-03 20:56:46 +02:00
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def kex(ssh_audit):
|
|
|
|
kex_algs, key_algs = [], []
|
|
|
|
enc, mac, compression, languages = [], [], ['none'], []
|
2020-10-15 20:34:23 +02:00
|
|
|
cli = SSH2_KexParty(enc, mac, compression, languages)
|
2020-07-03 20:56:46 +02:00
|
|
|
enc, mac, compression, languages = [], [], ['none'], []
|
2020-10-15 20:34:23 +02:00
|
|
|
srv = SSH2_KexParty(enc, mac, compression, languages)
|
2020-07-03 20:56:46 +02:00
|
|
|
cookie = os.urandom(16)
|
2020-10-15 20:34:23 +02:00
|
|
|
kex = SSH2_Kex(cookie, kex_algs, key_algs, cli, srv, 0)
|
2020-07-03 20:56:46 +02:00
|
|
|
return kex
|
|
|
|
|
|
|
|
|
|
|
|
def test_prevent_runtime_error_regression(ssh_audit, kex):
|
|
|
|
"""Prevent a regression of https://github.com/jtesta/ssh-audit/issues/41
|
|
|
|
|
|
|
|
The following test setup does not contain any sensible data.
|
|
|
|
It was made up to reproduce a situation when there are several host
|
|
|
|
keys, and an error occurred when iterating and modifying them at the
|
|
|
|
same time.
|
|
|
|
"""
|
|
|
|
kex.set_host_key("ssh-rsa", b"\x00\x00\x00\x07ssh-rsa\x00\x00\x00")
|
|
|
|
kex.set_host_key("ssh-rsa1", b"\x00\x00\x00\x07ssh-rsa\x00\x00\x00")
|
|
|
|
kex.set_host_key("ssh-rsa2", b"\x00\x00\x00\x07ssh-rsa\x00\x00\x00")
|
|
|
|
kex.set_host_key("ssh-rsa3", b"\x00\x00\x00\x07ssh-rsa\x00\x00\x00")
|
|
|
|
kex.set_host_key("ssh-rsa4", b"\x00\x00\x00\x07ssh-rsa\x00\x00\x00")
|
|
|
|
kex.set_host_key("ssh-rsa5", b"\x00\x00\x00\x07ssh-rsa\x00\x00\x00")
|
|
|
|
kex.set_host_key("ssh-rsa6", b"\x00\x00\x00\x07ssh-rsa\x00\x00\x00")
|
|
|
|
kex.set_host_key("ssh-rsa7", b"\x00\x00\x00\x07ssh-rsa\x00\x00\x00")
|
|
|
|
kex.set_host_key("ssh-rsa8", b"\x00\x00\x00\x07ssh-rsa\x00\x00\x00")
|
|
|
|
|
2021-02-01 19:10:06 +01:00
|
|
|
rv = ssh_audit.build_struct('localhost', banner=None, kex=kex)
|
2020-07-03 20:56:46 +02:00
|
|
|
|
2021-05-21 00:03:24 +02:00
|
|
|
assert len(rv["fingerprints"]) == (9 * 2) # Each host key generates two hash fingerprints: one using SHA256, and one using MD5.
|
2020-07-03 20:56:46 +02:00
|
|
|
|
|
|
|
for key in ['banner', 'compression', 'enc', 'fingerprints', 'kex', 'key', 'mac']:
|
|
|
|
assert key in rv
|