MCPcopy
hub / github.com/jtesta/ssh-audit / Algorithms

Class Algorithms

src/ssh_audit/algorithms.py:40–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38
39
40class Algorithms:
41 def __init__(self, pkm: Optional[SSH1_PublicKeyMessage], kex: Optional[SSH2_Kex]) -> None:
42 self.__ssh1kex = pkm
43 self.__ssh2kex = kex
44
45 @property
46 def ssh1kex(self) -> Optional[SSH1_PublicKeyMessage]:
47 return self.__ssh1kex
48
49 @property
50 def ssh2kex(self) -> Optional[SSH2_Kex]:
51 return self.__ssh2kex
52
53 @property
54 def ssh1(self) -> Optional['Algorithms.Item']:
55 if self.ssh1kex is None:
56 return None
57 item = Algorithms.Item(1, SSH1_KexDB.get_db())
58 item.add('key', ['ssh-rsa1'])
59 item.add('enc', self.ssh1kex.supported_ciphers)
60 item.add('aut', self.ssh1kex.supported_authentications)
61 return item
62
63 @property
64 def ssh2(self) -> Optional['Algorithms.Item']:
65 if self.ssh2kex is None:
66 return None
67 item = Algorithms.Item(2, SSH2_KexDB.get_db())
68 item.add('kex', self.ssh2kex.kex_algorithms)
69 item.add('key', self.ssh2kex.key_algorithms)
70 item.add('enc', self.ssh2kex.server.encryption)
71 item.add('mac', self.ssh2kex.server.mac)
72 return item
73
74 @property
75 def values(self) -> Iterable['Algorithms.Item']:
76 for item in [self.ssh1, self.ssh2]:
77 if item is not None:
78 yield item
79
80 @property
81 def maxlen(self) -> int:
82 def _ml(items: Sequence[str]) -> int:
83 return max(len(i) for i in items)
84 maxlen = 0
85 if self.ssh1kex is not None:
86 maxlen = max(_ml(self.ssh1kex.supported_ciphers),
87 _ml(self.ssh1kex.supported_authentications),
88 maxlen)
89 if self.ssh2kex is not None:
90 maxlen = max(_ml(self.ssh2kex.kex_algorithms),
91 _ml(self.ssh2kex.key_algorithms),
92 _ml(self.ssh2kex.server.encryption),
93 _ml(self.ssh2kex.server.mac),
94 maxlen)
95 return maxlen
96
97 def get_ssh_timeframe(self, for_server: Optional[bool] = None) -> 'Timeframe':

Callers 1

outputFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected