Skip to content

Commit

Permalink
Turn b"ext-info-[cs]" into private constants
Browse files Browse the repository at this point in the history
  • Loading branch information
cjwatson committed Oct 15, 2021
1 parent b38508e commit 58d1cf5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/twisted/conch/ssh/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,14 @@ class SSHTransportBase(protocol.Protocol):
_keyExchangeState = _KEY_EXCHANGE_NONE
_blockedByKeyExchange = None

# Added to key exchange algorithms by a client to indicate support for
# extension negotiation.
_EXT_INFO_C = b"ext-info-c"

# Added to key exchange algorithms by a server to indicate support for
# extension negotiation.
_EXT_INFO_S = b"ext-info-s"

_supportsExtensionNegotiation = False
otherExtensions: Dict[bytes, bytes] = {}

Expand Down Expand Up @@ -543,7 +551,9 @@ def sendKexInit(self):
# there's nothing to forbid the server from sending it as well, and
# doing so makes things easier if it needs to process extensions
# sent by clients in future.
supportedKeyExchanges.append(b"ext-info-c" if self.isClient else b"ext-info-s")
supportedKeyExchanges.append(
self._EXT_INFO_C if self.isClient else self._EXT_INFO_S
)

self.ourKexInitPayload = b"".join(
[
Expand Down Expand Up @@ -906,7 +916,7 @@ def ssh_KEXINIT(self, packet):
self.incomingCompressionType,
)
# RFC 8308, section 2.2
or self.kexAlg in (b"ext-info-c", b"ext-info-s")
or self.kexAlg in (self._EXT_INFO_C, self._EXT_INFO_S)
):
self.sendDisconnect(
DISCONNECT_KEY_EXCHANGE_FAILED, b"couldn't match all kex parts"
Expand All @@ -918,7 +928,7 @@ def ssh_KEXINIT(self, packet):
)
return
self._supportsExtensionNegotiation = (
b"ext-info-s" if self.isClient else b"ext-info-c"
self._EXT_INFO_S if self.isClient else self._EXT_INFO_C
) in kexAlgs
self._log.debug(
"kex alg={kexAlg!r} key alg={keyAlg!r}",
Expand Down

0 comments on commit 58d1cf5

Please sign in to comment.