class documentation

Test TransportBase. It implements the non-server/client specific parts of the SSH transport protocol.

Method test_avatar Test that the transport notifies the avatar of disconnections.
Method test_badPackets Test that the transport disconnects with an error when it receives bad packets.
Method test_badVersion Test that the transport disconnects when it receives a bad version.
Method test_ciphersAreValid Test that all the supportedCiphers are valid.
Method test_compatabilityVersion Test that the transport treats the compatibility version (1.99) as equivalent to version 2.0.
Method test_dataBeforeVersion Test that the transport ignores data sent before the version string.
Method test_dataReceived Test that dataReceived parses packets and dispatches them to ssh_* methods.
Method test_dataReceivedSSHVersionTrailingSpaces The trailing spaces from SSH version comment are not removed.
Method test_dataReceivedSSHVersionUnixNewline It can parse the SSH version string even when it ends only in Unix newlines (CR) and does not follows the RFC 4253 to use network newlines (CR LF).
Method test_dataReceiveVersionNotSentMemoryDOS When the peer is not sending its SSH version but keeps sending data, the connection is disconnected after 4KB to prevent buffering too much and running our of memory.
Method test_EXT_INFO When an EXT_INFO message is received, the transport stores a mapping of the peer's advertised extensions. See RFC 8308, section 2.3.
Method test_getPacketBoth Test that compressed and encrypted packets are retrieved correctly. See test_sendPacketBoth.
Method test_getPacketCompressed Test that compressed packets are retrieved correctly. See test_sendPacketCompressed.
Method test_getPacketEncrypted Test that encrypted packets are retrieved correctly. See test_sendPacketEncrypted.
Method test_getPacketPlain Test that packets are retrieved correctly out of the buffer when no encryption is enabled.
Method test_isEncrypted Test that the transport accurately reflects its encrypted status.
Method test_isVerified Test that the transport accurately reflects its verified status.
Method test_loseConnection Test that loseConnection sends a disconnect message and closes the connection.
Method test_multipleClasses Test that multiple instances have distinct states.
Method test_receiveDebug Test that debug messages are received correctly. See test_sendDebug.
Method test_receiveDisconnect Test that disconnection messages are received correctly. See test_sendDisconnect.
Method test_receiveIgnore Test that ignored messages are received correctly. See test_sendIgnore.
Method test_receiveKEXINITReply Immediately after connecting, the transport expects a KEXINIT message and does not reply to it.
Method test_receiveUnimplemented Test that unimplemented messages are received correctly. See test_sendUnimplemented.
Method test_sendDebug Test that debug messages are sent correctly. Payload:
Method test_sendDisconnect Test that disconnection messages are sent correctly. Payload:
Method test_sendExtInfo Test that EXT_INFO messages are sent correctly. See RFC 8308, section 2.3.
Method test_sendExtInfoUnsupported If the peer has not advertised support for extension negotiation, no EXT_INFO message is sent, since RFC 8308 only guarantees that the peer will be prepared to accept it if it has advertised support.
Method test_sendIgnore Test that ignored messages are sent correctly. Payload:
Method test_sendKexInit Test that the KEXINIT (key exchange initiation) message is sent correctly. Payload:
Method test_sendKexInitBlocksOthers After SSHTransportBase.sendKexInit has been called, messages types other than the following are queued and not sent until after NEWKEYS is sent by SSHTransportBase._keySetup.
Method test_sendKEXINITReply When a KEXINIT message is received which is not a reply to an earlier KEXINIT message which was sent, a KEXINIT reply is sent.
Method test_sendKexInitTwiceFails A new key exchange cannot be started while a key exchange is already in progress. If an attempt is made to send a KEXINIT message using SSHTransportBase.sendKexInit while a key exchange is in progress causes that method to raise a ...
Method test_sendPacketBoth Test that packets sent while compression and encryption are enabled are sent correctly. The packet type and data should be compressed and then the whole packet should be encrypted.
Method test_sendPacketCompressed Test that packets sent while compression is enabled are sent correctly. The packet type and data should be encrypted.
Method test_sendPacketEncrypted Test that packets sent while encryption is enabled are sent correctly. The whole packet should be encrypted.
Method test_sendPacketPlain Test that plain (unencrypted, uncompressed) packets are sent correctly. The format is:
Method test_sendUnimplemented Test that unimplemented messages are sent correctly. Payload:
Method test_sendVersion Test that the first thing sent over the connection is the version string. The 'softwareversion' part must consist of printable US-ASCII characters, with the exception of whitespace characters and the minus sign.
Method test_service Test that the transport can set the running service and dispatches packets to the service's packetReceived method.
Method test_supportedVersionsAreAllowed If an unusual SSH version is received and is included in supportedVersions, an unsupported version error is not emitted.
Method test_unimplementedPackets Test that unimplemented packet types cause MSG_UNIMPLEMENTED packets to be sent.
Method test_unsupportedVersionsCallUnsupportedVersionReceived If an unusual SSH version is received and is not included in supportedVersions, an unsupported version error is emitted.
Constant _A_KEXINIT_MESSAGE Undocumented

Inherited from TransportTestCase (via BaseSSHTransportBaseCase):

Method finishKeyExchange Deliver enough additional messages to proto so that the key exchange which is started in SSHTransportBase.connectionMade completes and non-key exchange messages can be sent and received.
Method setUp Undocumented
Method simulateKeyExchange Finish a key exchange by calling _keySetup with the given arguments. Also do extra whitebox stuff to satisfy that method's assumption that some kind of key exchange has actually taken place.
Class Variable klass Undocumented
Instance Variable packets Undocumented
Instance Variable proto Undocumented
Instance Variable transport Undocumented

Inherited from TestCase (via BaseSSHTransportBaseCase, TransportTestCase):

Method __call__ Run the test. Should always do exactly the same thing as run().
Method __init__ Construct an asynchronous test case for methodName.
Method addCleanup Extend the base cleanup feature with support for cleanup functions which return Deferreds.
Method assertFailure Fail if deferred does not errback with one of expectedFailures. Returns the original Deferred with callbacks added. You will need to return this Deferred from your test case.
Method deferRunCleanups Run any scheduled cleanups and report errors (if any) to the result. object.
Method deferSetUp Undocumented
Method deferTearDown Undocumented
Method deferTestMethod Undocumented
Method getSuppress Undocumented
Method getTimeout Returns the timeout value set on this test. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a timeout attribute, returns that. Returns util.DEFAULT_TIMEOUT_DURATION...
Instance Variable timeout A real number of seconds. If set, the test will raise an error if it takes longer than timeout seconds. If not set, util.DEFAULT_TIMEOUT_DURATION is used.
Method _cbDeferTestMethod Undocumented
Method _classCleanUp Undocumented
Method _cleanUp Undocumented
Method _deprecateReactor Deprecate iterate, crash and stop on reactor. That is, each method is wrapped in a function that issues a deprecation warning, then calls the original.
Method _ebDeferSetUp Undocumented
Method _ebDeferTearDown Undocumented
Method _ebDeferTestMethod Undocumented
Method _makeReactorMethod Create a method which wraps the reactor method name. The new method issues a deprecation warning and calls the original.
Method _run Run a single method, either a test method or fixture.
Method _runFixturesAndTest Really run setUp, the test method, and tearDown. Any of these may return defer.Deferreds. After they complete, do some reactor cleanup.
Method _undeprecateReactor Restore the deprecated reactor methods. Undoes what _deprecateReactor did.
Method _wait Take a Deferred that only ever callbacks. Block until it happens.
Instance Variable _passed Undocumented
Instance Variable _reactorMethods Undocumented
Instance Variable _timedOut Undocumented

Inherited from SynchronousTestCase (via BaseSSHTransportBaseCase, TransportTestCase, TestCase):

Method __eq__ Override the comparison defined by the base TestCase which considers instances of the same class with the same _testMethodName to be equal. Since trial puts TestCase instances into a set, that definition of comparison makes it impossible to run the same test method twice...
Method __hash__ Undocumented
Method callDeprecated Call a function that should have been deprecated at a specific version and in favor of a specific alternative, and assert that it was thusly deprecated.
Method flushLoggedErrors Remove stored errors received from the log.
Method flushWarnings Remove stored warnings from the list of captured warnings and return them.
Method getDeprecatedModuleAttribute Retrieve a module attribute which should have been deprecated, and assert that we saw the appropriate deprecation warning.
Method getSkip Return the skip reason set on this test, if any is set. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a skip attribute, returns that in a tuple (...
Method getTodo Return a Todo object if the test is marked todo. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a todo attribute, returns that. Returns ...
Method mktemp Create a new path name which can be used for a new file or directory.
Method patch Monkey patch an object for the duration of the test.
Method run Run the test case, storing the results in result.
Method runTest If no methodName argument is passed to the constructor, run will treat this method as the thing with the actual test inside.
Method shortDescription Undocumented
Instance Variable failureException An exception class, defaulting to FailTest. If the test method raises this exception, it will be reported as a failure, rather than an exception. All of the assertion methods raise this if the assertion fails.
Instance Variable skip None or a string explaining why this test is to be skipped. If defined, the test will not be run. Instead, it will be reported to the result object as 'skipped' (if the TestResult supports skipping).
Instance Variable suppress None or a list of tuples of (args, kwargs) to be passed to warnings.filterwarnings. Use these to suppress warnings raised in a test. Useful for testing deprecated code. See also util.suppress.
Instance Variable todo None, a string or a tuple of (errors, reason) where errors is either an exception class or an iterable of exception classes, and reason is a string. See Todo or makeTodo for more information.
Method _getSkipReason Return the reason to use for skipping a test method.
Method _getSuppress Returns any warning suppressions set for this test. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a suppress attribute, returns that. ...
Method _installObserver Undocumented
Method _removeObserver Undocumented
Method _runCleanups Synchronously run any cleanups which have been added.
Instance Variable _cleanups Undocumented
Instance Variable _observer Undocumented
Instance Variable _parents Undocumented
Instance Variable _testMethodName Undocumented
Instance Variable _warnings Undocumented

Inherited from _Assertions (via BaseSSHTransportBaseCase, TransportTestCase, TestCase, SynchronousTestCase):

Method assertAlmostEqual Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero.
Method assertApproximates Fail if first - second > tolerance
Method assertEqual Fail the test if first and second are not equal.
Method assertFalse Fail the test if condition evaluates to True.
Method assertIn Fail the test if containee is not found in container.
Method assertIs Fail the test if first is not second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test.
Method assertIsInstance Fail if instance is not an instance of the given class or of one of the given classes.
Method assertIsNot Fail the test if first is second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test.
Method assertNoResult Assert that deferred does not have a result at this point.
Method assertNotAlmostEqual Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero.
Method assertNotEqual Fail the test if first == second.
Method assertNotIn Fail the test if containee is found in container.
Method assertNotIsInstance Fail if instance is an instance of the given class or of one of the given classes.
Method assertNotSubstring Fail if astring contains substring.
Method assertRaises Fail the test unless calling the function f with the given args and kwargs raises exception. The failure will report the traceback and call stack of the unexpected exception.
Method assertSubstring Fail if substring does not exist within astring.
Method assertTrue Fail the test if condition evaluates to False.
Method assertWarns Fail if the given function doesn't generate the specified warning when called. It calls the function, checks the warning, and forwards the result of the function if everything is fine.
Method fail Absolutely fail the test. Do not pass go, do not collect $200.
Method failureResultOf Return the current failure result of deferred or raise self.failureException.
Method successResultOf Return the current success result of deferred or raise self.failureException.
def test_avatar(self): (source)

Test that the transport notifies the avatar of disconnections.

def test_badPackets(self): (source)

Test that the transport disconnects with an error when it receives bad packets.

def test_badVersion(self): (source)

Test that the transport disconnects when it receives a bad version.

def test_ciphersAreValid(self): (source)

Test that all the supportedCiphers are valid.

def test_compatabilityVersion(self): (source)

Test that the transport treats the compatibility version (1.99) as equivalent to version 2.0.

def test_dataBeforeVersion(self): (source)

Test that the transport ignores data sent before the version string.

def test_dataReceived(self): (source)

Test that dataReceived parses packets and dispatches them to ssh_* methods.

def test_dataReceivedSSHVersionTrailingSpaces(self): (source)

The trailing spaces from SSH version comment are not removed.

The SSH version string needs to be kept as received (without CR LF end of line) as they are used in the host authentication process.

This can happen with a Bitvise SSH server which hides its version.

def test_dataReceivedSSHVersionUnixNewline(self): (source)

It can parse the SSH version string even when it ends only in Unix newlines (CR) and does not follows the RFC 4253 to use network newlines (CR LF).

def test_dataReceiveVersionNotSentMemoryDOS(self): (source)

When the peer is not sending its SSH version but keeps sending data, the connection is disconnected after 4KB to prevent buffering too much and running our of memory.

def test_EXT_INFO(self): (source)

When an EXT_INFO message is received, the transport stores a mapping of the peer's advertised extensions. See RFC 8308, section 2.3.

def test_getPacketBoth(self): (source)

Test that compressed and encrypted packets are retrieved correctly. See test_sendPacketBoth.

def test_getPacketCompressed(self): (source)

Test that compressed packets are retrieved correctly. See test_sendPacketCompressed.

def test_getPacketEncrypted(self): (source)

Test that encrypted packets are retrieved correctly. See test_sendPacketEncrypted.

def test_getPacketPlain(self): (source)

Test that packets are retrieved correctly out of the buffer when no encryption is enabled.

def test_isEncrypted(self): (source)

Test that the transport accurately reflects its encrypted status.

def test_isVerified(self): (source)

Test that the transport accurately reflects its verified status.

def test_loseConnection(self): (source)

Test that loseConnection sends a disconnect message and closes the connection.

def test_multipleClasses(self): (source)

Test that multiple instances have distinct states.

def test_receiveDebug(self): (source)

Test that debug messages are received correctly. See test_sendDebug.

def test_receiveDisconnect(self): (source)

Test that disconnection messages are received correctly. See test_sendDisconnect.

def test_receiveIgnore(self): (source)

Test that ignored messages are received correctly. See test_sendIgnore.

def test_receiveKEXINITReply(self): (source)

Immediately after connecting, the transport expects a KEXINIT message and does not reply to it.

def test_receiveUnimplemented(self): (source)

Test that unimplemented messages are received correctly. See test_sendUnimplemented.

def test_sendDebug(self): (source)

Test that debug messages are sent correctly. Payload:

    bool always display
    string debug message
    string language
def test_sendDisconnect(self): (source)

Test that disconnection messages are sent correctly. Payload:

    uint32 reason code
    string reason description
    string language
def test_sendExtInfo(self): (source)

Test that EXT_INFO messages are sent correctly. See RFC 8308, section 2.3.

def test_sendExtInfoUnsupported(self): (source)

If the peer has not advertised support for extension negotiation, no EXT_INFO message is sent, since RFC 8308 only guarantees that the peer will be prepared to accept it if it has advertised support.

def test_sendIgnore(self): (source)

Test that ignored messages are sent correctly. Payload:

    string ignored data
def test_sendKexInit(self): (source)

Test that the KEXINIT (key exchange initiation) message is sent correctly. Payload:

    bytes[16] cookie
    string key exchange algorithms
    string public key algorithms
    string outgoing ciphers
    string incoming ciphers
    string outgoing MACs
    string incoming MACs
    string outgoing compressions
    string incoming compressions
    bool first packet follows
    uint32 0
def test_sendKexInitBlocksOthers(self): (source)

After SSHTransportBase.sendKexInit has been called, messages types other than the following are queued and not sent until after NEWKEYS is sent by SSHTransportBase._keySetup.

RFC 4253, section 7.1.

def test_sendKEXINITReply(self): (source)

When a KEXINIT message is received which is not a reply to an earlier KEXINIT message which was sent, a KEXINIT reply is sent.

def test_sendKexInitTwiceFails(self): (source)

A new key exchange cannot be started while a key exchange is already in progress. If an attempt is made to send a KEXINIT message using SSHTransportBase.sendKexInit while a key exchange is in progress causes that method to raise a RuntimeError.

def test_sendPacketBoth(self): (source)

Test that packets sent while compression and encryption are enabled are sent correctly. The packet type and data should be compressed and then the whole packet should be encrypted.

def test_sendPacketCompressed(self): (source)

Test that packets sent while compression is enabled are sent correctly. The packet type and data should be encrypted.

def test_sendPacketEncrypted(self): (source)

Test that packets sent while encryption is enabled are sent correctly. The whole packet should be encrypted.

def test_sendPacketPlain(self): (source)

Test that plain (unencrypted, uncompressed) packets are sent correctly. The format is:

    uint32 length (including type and padding length)
    byte padding length
    byte type
    bytes[length-padding length-2] data
    bytes[padding length] padding
def test_sendUnimplemented(self): (source)

Test that unimplemented messages are sent correctly. Payload:

    uint32 sequence number
def test_sendVersion(self): (source)

Test that the first thing sent over the connection is the version string. The 'softwareversion' part must consist of printable US-ASCII characters, with the exception of whitespace characters and the minus sign.

RFC 4253, section 4.2.

def test_service(self): (source)

Test that the transport can set the running service and dispatches packets to the service's packetReceived method.

def test_supportedVersionsAreAllowed(self): (source)

If an unusual SSH version is received and is included in supportedVersions, an unsupported version error is not emitted.

def test_unimplementedPackets(self): (source)

Test that unimplemented packet types cause MSG_UNIMPLEMENTED packets to be sent.

def test_unsupportedVersionsCallUnsupportedVersionReceived(self): (source)

If an unusual SSH version is received and is not included in supportedVersions, an unsupported version error is emitted.

_A_KEXINIT_MESSAGE = (source)

Undocumented

Value
(((((((((((b'\xaa'*16+common.NS(b'diffie-hellman-group14-sha1'))+common.NS(b'ssh-rsa'))+common.NS(b'aes256-ctr'))+common.NS(b'aes256-ctr'))+common.NS(b'hmac-sha1'))+common.NS(b'hmac-sha1'))+common.NS(b'none'))+common.NS(b'none'))+common.NS(b''))+common.NS(b''))+b'\x00')+b'\x00\x00\x00\x00'