code
stringlengths 26
870k
| docstring
stringlengths 1
65.6k
| func_name
stringlengths 1
194
| language
stringclasses 1
value | repo
stringlengths 8
68
| path
stringlengths 5
194
| url
stringlengths 46
254
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
def test_getPeer(self):
"""
Test that the transport's L{getPeer} method returns an
L{SSHTransportAddress} with the L{IAddress} of the peer.
"""
self.assertEqual(self.proto.getPeer(),
address.SSHTransportAddress(
self.proto.transport.getPeer())) | Test that the transport's L{getPeer} method returns an
L{SSHTransportAddress} with the L{IAddress} of the peer. | test_getPeer | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_getHost(self):
"""
Test that the transport's L{getHost} method returns an
L{SSHTransportAddress} with the L{IAddress} of the host.
"""
self.assertEqual(self.proto.getHost(),
address.SSHTransportAddress(
self.proto.transport.getHost())) | Test that the transport's L{getHost} method returns an
L{SSHTransportAddress} with the L{IAddress} of the host. | test_getHost | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_KEXINITMultipleAlgorithms(self):
"""
Receiving a KEXINIT packet listing multiple supported algorithms will
set up the first common algorithm found in the client's preference
list.
"""
self.proto.dataReceived(
b'SSH-2.0-Twisted\r\n\x00\x00\x01\xf4\x04\x14'
b'\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99'
b'\x99\x00\x00\x00bdiffie-hellman-group1-sha1,diffie-hellman-g'
b'roup-exchange-sha1,diffie-hellman-group-exchange-sha256\x00'
b'\x00\x00\x0fssh-dss,ssh-rsa\x00\x00\x00\x85aes128-ctr,aes128-'
b'cbc,aes192-ctr,aes192-cbc,aes256-ctr,aes256-cbc,cast128-ctr,c'
b'ast128-cbc,blowfish-ctr,blowfish-cbc,3des-ctr,3des-cbc\x00'
b'\x00\x00\x85aes128-ctr,aes128-cbc,aes192-ctr,aes192-cbc,aes25'
b'6-ctr,aes256-cbc,cast128-ctr,cast128-cbc,blowfish-ctr,blowfis'
b'h-cbc,3des-ctr,3des-cbc\x00\x00\x00\x12hmac-md5,hmac-sha1\x00'
b'\x00\x00\x12hmac-md5,hmac-sha1\x00\x00\x00\tnone,zlib\x00\x00'
b'\x00\tnone,zlib\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x00\x99\x99\x99\x99')
# Even if as server we prefer diffie-hellman-group-exchange-sha256 the
# client preference is used, after skipping diffie-hellman-group1-sha1
self.assertEqual(self.proto.kexAlg,
b'diffie-hellman-group-exchange-sha1')
self.assertEqual(self.proto.keyAlg,
b'ssh-dss')
self.assertEqual(self.proto.outgoingCompressionType,
b'none')
self.assertEqual(self.proto.incomingCompressionType,
b'none')
ne = self.proto.nextEncryptions
self.assertEqual(ne.outCipType, b'aes128-ctr')
self.assertEqual(ne.inCipType, b'aes128-ctr')
self.assertEqual(ne.outMACType, b'hmac-md5')
self.assertEqual(ne.inMACType, b'hmac-md5') | Receiving a KEXINIT packet listing multiple supported algorithms will
set up the first common algorithm found in the client's preference
list. | test_KEXINITMultipleAlgorithms | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_ignoreGuessPacketKex(self):
"""
The client is allowed to send a guessed key exchange packet
after it sends the KEXINIT packet. However, if the key exchanges
do not match, that guess packet must be ignored. This tests that
the packet is ignored in the case of the key exchange method not
matching.
"""
kexInitPacket = b'\x00' * 16 + (
b''.join([common.NS(x) for x in
[b','.join(y) for y in
[self.proto.supportedKeyExchanges[::-1],
self.proto.supportedPublicKeys,
self.proto.supportedCiphers,
self.proto.supportedCiphers,
self.proto.supportedMACs,
self.proto.supportedMACs,
self.proto.supportedCompressions,
self.proto.supportedCompressions,
self.proto.supportedLanguages,
self.proto.supportedLanguages]]])) + (
b'\xff\x00\x00\x00\x00')
self.proto.ssh_KEXINIT(kexInitPacket)
self.assertTrue(self.proto.ignoreNextPacket)
self.proto.ssh_DEBUG(b"\x01\x00\x00\x00\x04test\x00\x00\x00\x00")
self.assertTrue(self.proto.ignoreNextPacket)
self.proto.ssh_KEX_DH_GEX_REQUEST_OLD(b'\x00\x00\x08\x00')
self.assertFalse(self.proto.ignoreNextPacket)
self.assertEqual(self.packets, [])
self.proto.ignoreNextPacket = True
self.proto.ssh_KEX_DH_GEX_REQUEST(b'\x00\x00\x08\x00' * 3)
self.assertFalse(self.proto.ignoreNextPacket)
self.assertEqual(self.packets, []) | The client is allowed to send a guessed key exchange packet
after it sends the KEXINIT packet. However, if the key exchanges
do not match, that guess packet must be ignored. This tests that
the packet is ignored in the case of the key exchange method not
matching. | test_ignoreGuessPacketKex | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_ignoreGuessPacketKey(self):
"""
Like test_ignoreGuessPacketKex, but for an incorrectly guessed
public key format.
"""
kexInitPacket = b'\x00' * 16 + (
b''.join([common.NS(x) for x in
[b','.join(y) for y in
[self.proto.supportedKeyExchanges,
self.proto.supportedPublicKeys[::-1],
self.proto.supportedCiphers,
self.proto.supportedCiphers,
self.proto.supportedMACs,
self.proto.supportedMACs,
self.proto.supportedCompressions,
self.proto.supportedCompressions,
self.proto.supportedLanguages,
self.proto.supportedLanguages]]])) + (
b'\xff\x00\x00\x00\x00')
self.proto.ssh_KEXINIT(kexInitPacket)
self.assertTrue(self.proto.ignoreNextPacket)
self.proto.ssh_DEBUG(b"\x01\x00\x00\x00\x04test\x00\x00\x00\x00")
self.assertTrue(self.proto.ignoreNextPacket)
self.proto.ssh_KEX_DH_GEX_REQUEST_OLD(b'\x00\x00\x08\x00')
self.assertFalse(self.proto.ignoreNextPacket)
self.assertEqual(self.packets, [])
self.proto.ignoreNextPacket = True
self.proto.ssh_KEX_DH_GEX_REQUEST(b'\x00\x00\x08\x00' * 3)
self.assertFalse(self.proto.ignoreNextPacket)
self.assertEqual(self.packets, []) | Like test_ignoreGuessPacketKex, but for an incorrectly guessed
public key format. | test_ignoreGuessPacketKey | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def assertKexDHInitResponse(self, kexAlgorithm, bits):
"""
Test that the KEXDH_INIT packet causes the server to send a
KEXDH_REPLY with the server's public key and a signature.
@param kexAlgorithm: The key exchange algorithm to use.
@type kexAlgorithm: L{str}
"""
self.proto.supportedKeyExchanges = [kexAlgorithm]
self.proto.supportedPublicKeys = [b'ssh-rsa']
self.proto.dataReceived(self.transport.value())
g, p = _kex.getDHGeneratorAndPrime(kexAlgorithm)
e = pow(g, 5000, p)
self.proto.ssh_KEX_DH_GEX_REQUEST_OLD(common.MP(e))
y = common.getMP(common.NS(b'\x99' * (bits // 8)))[0]
f = _MPpow(self.proto.g, y, self.proto.p)
self.assertEqual(self.proto.dhSecretKeyPublicMP, f)
sharedSecret = _MPpow(e, y, self.proto.p)
h = sha1()
h.update(common.NS(self.proto.ourVersionString) * 2)
h.update(common.NS(self.proto.ourKexInitPayload) * 2)
h.update(common.NS(self.proto.factory.publicKeys[b'ssh-rsa'].blob()))
h.update(common.MP(e))
h.update(f)
h.update(sharedSecret)
exchangeHash = h.digest()
signature = self.proto.factory.privateKeys[b'ssh-rsa'].sign(
exchangeHash)
self.assertEqual(
self.packets,
[(transport.MSG_KEXDH_REPLY,
common.NS(self.proto.factory.publicKeys[b'ssh-rsa'].blob())
+ f + common.NS(signature)),
(transport.MSG_NEWKEYS, b'')]) | Test that the KEXDH_INIT packet causes the server to send a
KEXDH_REPLY with the server's public key and a signature.
@param kexAlgorithm: The key exchange algorithm to use.
@type kexAlgorithm: L{str} | assertKexDHInitResponse | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_checkBad_KEX_ECDH_INIT_CurveName(self):
"""
Test that if the server receives a KEX_DH_GEX_REQUEST_OLD message
and the key exchange algorithm is not set, we raise a ConchError.
"""
self.proto.kexAlg = b'bad-curve'
self.proto.keyAlg = b'ssh-rsa'
self.assertRaises(UnsupportedAlgorithm,
self.proto._ssh_KEX_ECDH_INIT,
common.NS(b'unused-key')) | Test that if the server receives a KEX_DH_GEX_REQUEST_OLD message
and the key exchange algorithm is not set, we raise a ConchError. | test_checkBad_KEX_ECDH_INIT_CurveName | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_checkBad_KEX_INIT_CurveName(self):
"""
Test that if the server received a bad name for a curve
we raise an UnsupportedAlgorithm error.
"""
kexmsg = (
b"\xAA" * 16 +
common.NS(b'ecdh-sha2-nistp256') +
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')
self.proto.ssh_KEXINIT(kexmsg)
self.assertRaises(AttributeError)
self.assertRaises(UnsupportedAlgorithm) | Test that if the server received a bad name for a curve
we raise an UnsupportedAlgorithm error. | test_checkBad_KEX_INIT_CurveName | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_KEXDH_INIT_GROUP14(self):
"""
KEXDH_INIT messages are processed when the
diffie-hellman-group14-sha1 key exchange algorithm is requested.
"""
self.assertKexDHInitResponse(b'diffie-hellman-group14-sha1', 2048) | KEXDH_INIT messages are processed when the
diffie-hellman-group14-sha1 key exchange algorithm is requested. | test_KEXDH_INIT_GROUP14 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_keySetup(self):
"""
Test that _keySetup sets up the next encryption keys.
"""
self.proto.kexAlg = b'diffie-hellman-group14-sha1'
self.proto.nextEncryptions = MockCipher()
self.simulateKeyExchange(b'AB', b'CD')
self.assertEqual(self.proto.sessionID, b'CD')
self.simulateKeyExchange(b'AB', b'EF')
self.assertEqual(self.proto.sessionID, b'CD')
self.assertEqual(self.packets[-1], (transport.MSG_NEWKEYS, b''))
newKeys = [self.proto._getKey(c, b'AB', b'EF')
for c in iterbytes(b'ABCDEF')]
self.assertEqual(
self.proto.nextEncryptions.keys,
(newKeys[1], newKeys[3], newKeys[0], newKeys[2], newKeys[5],
newKeys[4])) | Test that _keySetup sets up the next encryption keys. | test_keySetup | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_ECDH_keySetup(self):
"""
Test that _keySetup sets up the next encryption keys.
"""
self.proto.kexAlg = b'ecdh-sha2-nistp256'
self.proto.nextEncryptions = MockCipher()
self.simulateKeyExchange(b'AB', b'CD')
self.assertEqual(self.proto.sessionID, b'CD')
self.simulateKeyExchange(b'AB', b'EF')
self.assertEqual(self.proto.sessionID, b'CD')
self.assertEqual(self.packets[-1], (transport.MSG_NEWKEYS, b''))
newKeys = [self.proto._getKey(c, b'AB', b'EF')
for c in iterbytes(b'ABCDEF')]
self.assertEqual(
self.proto.nextEncryptions.keys,
(newKeys[1], newKeys[3], newKeys[0], newKeys[2], newKeys[5],
newKeys[4])) | Test that _keySetup sets up the next encryption keys. | test_ECDH_keySetup | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_NEWKEYS(self):
"""
Test that NEWKEYS transitions the keys in nextEncryptions to
currentEncryptions.
"""
self.test_KEXINITMultipleAlgorithms()
self.proto.nextEncryptions = transport.SSHCiphers(b'none', b'none',
b'none', b'none')
self.proto.ssh_NEWKEYS(b'')
self.assertIs(self.proto.currentEncryptions,
self.proto.nextEncryptions)
self.assertIsNone(self.proto.outgoingCompression)
self.assertIsNone(self.proto.incomingCompression)
self.proto.outgoingCompressionType = b'zlib'
self.simulateKeyExchange(b'AB', b'CD')
self.proto.ssh_NEWKEYS(b'')
self.assertIsNotNone(self.proto.outgoingCompression)
self.proto.incomingCompressionType = b'zlib'
self.simulateKeyExchange(b'AB', b'EF')
self.proto.ssh_NEWKEYS(b'')
self.assertIsNotNone(self.proto.incomingCompression) | Test that NEWKEYS transitions the keys in nextEncryptions to
currentEncryptions. | test_NEWKEYS | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_SERVICE_REQUEST(self):
"""
Test that the SERVICE_REQUEST message requests and starts a
service.
"""
self.proto.ssh_SERVICE_REQUEST(common.NS(b'ssh-userauth'))
self.assertEqual(self.packets, [(transport.MSG_SERVICE_ACCEPT,
common.NS(b'ssh-userauth'))])
self.assertEqual(self.proto.service.name, b'MockService') | Test that the SERVICE_REQUEST message requests and starts a
service. | test_SERVICE_REQUEST | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_disconnectNEWKEYSData(self):
"""
Test that NEWKEYS disconnects if it receives data.
"""
self.proto.ssh_NEWKEYS(b"bad packet")
self.checkDisconnected() | Test that NEWKEYS disconnects if it receives data. | test_disconnectNEWKEYSData | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_disconnectSERVICE_REQUESTBadService(self):
"""
Test that SERVICE_REQUESTS disconnects if an unknown service is
requested.
"""
self.proto.ssh_SERVICE_REQUEST(common.NS(b'no service'))
self.checkDisconnected(transport.DISCONNECT_SERVICE_NOT_AVAILABLE) | Test that SERVICE_REQUESTS disconnects if an unknown service is
requested. | test_disconnectSERVICE_REQUESTBadService | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_KEX_DH_GEX_REQUEST_OLD(self):
"""
Test that the KEX_DH_GEX_REQUEST_OLD message causes the server
to reply with a KEX_DH_GEX_GROUP message with the correct
Diffie-Hellman group.
"""
self.proto.supportedKeyExchanges = [self.kexAlgorithm]
self.proto.supportedPublicKeys = [b'ssh-rsa']
self.proto.dataReceived(self.transport.value())
self.proto.ssh_KEX_DH_GEX_REQUEST_OLD(b'\x00\x00\x04\x00')
dhGenerator, dhPrime = self.proto.factory.getPrimes().get(2048)[0]
self.assertEqual(
self.packets,
[(transport.MSG_KEX_DH_GEX_GROUP,
common.MP(dhPrime) + b'\x00\x00\x00\x01\x02')])
self.assertEqual(self.proto.g, 2)
self.assertEqual(self.proto.p, dhPrime) | Test that the KEX_DH_GEX_REQUEST_OLD message causes the server
to reply with a KEX_DH_GEX_GROUP message with the correct
Diffie-Hellman group. | test_KEX_DH_GEX_REQUEST_OLD | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_KEX_DH_GEX_REQUEST_OLD_badKexAlg(self):
"""
Test that if the server receives a KEX_DH_GEX_REQUEST_OLD message
and the key exchange algorithm is not set, we raise a ConchError.
"""
self.proto.kexAlg = None
self.assertRaises(ConchError, self.proto.ssh_KEX_DH_GEX_REQUEST_OLD,
None) | Test that if the server receives a KEX_DH_GEX_REQUEST_OLD message
and the key exchange algorithm is not set, we raise a ConchError. | test_KEX_DH_GEX_REQUEST_OLD_badKexAlg | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_KEX_DH_GEX_REQUEST(self):
"""
Test that the KEX_DH_GEX_REQUEST message causes the server to reply
with a KEX_DH_GEX_GROUP message with the correct Diffie-Hellman
group.
"""
self.proto.supportedKeyExchanges = [self.kexAlgorithm]
self.proto.supportedPublicKeys = [b'ssh-rsa']
self.proto.dataReceived(self.transport.value())
self.proto.ssh_KEX_DH_GEX_REQUEST(b'\x00\x00\x04\x00\x00\x00\x08\x00' +
b'\x00\x00\x0c\x00')
dhGenerator, dhPrime = self.proto.factory.getPrimes().get(2048)[0]
self.assertEqual(
self.packets,
[(transport.MSG_KEX_DH_GEX_GROUP,
common.MP(dhPrime) + b'\x00\x00\x00\x01\x02')])
self.assertEqual(self.proto.g, 2)
self.assertEqual(self.proto.p, dhPrime) | Test that the KEX_DH_GEX_REQUEST message causes the server to reply
with a KEX_DH_GEX_GROUP message with the correct Diffie-Hellman
group. | test_KEX_DH_GEX_REQUEST | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_KEX_DH_GEX_INIT_after_REQUEST_OLD(self):
"""
Test that the KEX_DH_GEX_INIT message after the client sends
KEX_DH_GEX_REQUEST_OLD causes the server to send a KEX_DH_GEX_INIT
message with a public key and signature.
"""
self.test_KEX_DH_GEX_REQUEST_OLD()
e = pow(self.proto.g, 3, self.proto.p)
y = common.getMP(b'\x00\x00\x01\x00' + b'\x99' * 512)[0]
self.assertEqual(self.proto.dhSecretKey.private_numbers().x, y)
f = _MPpow(self.proto.g, y, self.proto.p)
self.assertEqual(self.proto.dhSecretKeyPublicMP, f)
sharedSecret = _MPpow(e, y, self.proto.p)
h = self.hashProcessor()
h.update(common.NS(self.proto.ourVersionString) * 2)
h.update(common.NS(self.proto.ourKexInitPayload) * 2)
h.update(common.NS(self.proto.factory.publicKeys[b'ssh-rsa'].blob()))
h.update(b'\x00\x00\x04\x00')
h.update(common.MP(self.proto.p))
h.update(common.MP(self.proto.g))
h.update(common.MP(e))
h.update(f)
h.update(sharedSecret)
exchangeHash = h.digest()
self.proto.ssh_KEX_DH_GEX_INIT(common.MP(e))
self.assertEqual(
self.packets[1:],
[(transport.MSG_KEX_DH_GEX_REPLY,
common.NS(self.proto.factory.publicKeys[b'ssh-rsa'].blob()) +
f + common.NS(self.proto.factory.privateKeys[b'ssh-rsa'].sign(
exchangeHash))),
(transport.MSG_NEWKEYS, b'')]) | Test that the KEX_DH_GEX_INIT message after the client sends
KEX_DH_GEX_REQUEST_OLD causes the server to send a KEX_DH_GEX_INIT
message with a public key and signature. | test_KEX_DH_GEX_INIT_after_REQUEST_OLD | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_KEX_DH_GEX_INIT_after_REQUEST(self):
"""
Test that the KEX_DH_GEX_INIT message after the client sends
KEX_DH_GEX_REQUEST causes the server to send a KEX_DH_GEX_INIT message
with a public key and signature.
"""
self.test_KEX_DH_GEX_REQUEST()
e = pow(self.proto.g, 3, self.proto.p)
y = common.getMP(b'\x00\x00\x01\x00' + b'\x99' * 256)[0]
f = _MPpow(self.proto.g, y, self.proto.p)
sharedSecret = _MPpow(e, y, self.proto.p)
h = self.hashProcessor()
h.update(common.NS(self.proto.ourVersionString) * 2)
h.update(common.NS(self.proto.ourKexInitPayload) * 2)
h.update(common.NS(self.proto.factory.publicKeys[b'ssh-rsa'].blob()))
h.update(b'\x00\x00\x04\x00\x00\x00\x08\x00\x00\x00\x0c\x00')
h.update(common.MP(self.proto.p))
h.update(common.MP(self.proto.g))
h.update(common.MP(e))
h.update(f)
h.update(sharedSecret)
exchangeHash = h.digest()
self.proto.ssh_KEX_DH_GEX_INIT(common.MP(e))
self.assertEqual(
self.packets[1],
(transport.MSG_KEX_DH_GEX_REPLY,
common.NS(self.proto.factory.publicKeys[b'ssh-rsa'].blob()) +
f + common.NS(self.proto.factory.privateKeys[b'ssh-rsa'].sign(
exchangeHash)))) | Test that the KEX_DH_GEX_INIT message after the client sends
KEX_DH_GEX_REQUEST causes the server to send a KEX_DH_GEX_INIT message
with a public key and signature. | test_KEX_DH_GEX_INIT_after_REQUEST | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def verifyHostKey(self, pubKey, fingerprint):
"""
Mock version of SSHClientTransport.verifyHostKey.
"""
self.calledVerifyHostKey = True
self.assertEqual(pubKey, self.blob)
self.assertEqual(fingerprint.replace(b':', b''),
binascii.hexlify(md5(pubKey).digest()))
return defer.succeed(True) | Mock version of SSHClientTransport.verifyHostKey. | verifyHostKey | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_KEXINITMultipleAlgorithms(self):
"""
Receiving a KEXINIT packet listing multiple supported
algorithms will set up the first common algorithm, ordered after our
preference.
"""
self.proto.dataReceived(
b'SSH-2.0-Twisted\r\n\x00\x00\x01\xf4\x04\x14'
b'\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99\x99'
b'\x99\x00\x00\x00bdiffie-hellman-group1-sha1,diffie-hellman-g'
b'roup-exchange-sha1,diffie-hellman-group-exchange-sha256\x00'
b'\x00\x00\x0fssh-dss,ssh-rsa\x00\x00\x00\x85aes128-ctr,aes128-'
b'cbc,aes192-ctr,aes192-cbc,aes256-ctr,aes256-cbc,cast128-ctr,c'
b'ast128-cbc,blowfish-ctr,blowfish-cbc,3des-ctr,3des-cbc\x00'
b'\x00\x00\x85aes128-ctr,aes128-cbc,aes192-ctr,aes192-cbc,aes25'
b'6-ctr,aes256-cbc,cast128-ctr,cast128-cbc,blowfish-ctr,blowfis'
b'h-cbc,3des-ctr,3des-cbc\x00\x00\x00\x12hmac-md5,hmac-sha1\x00'
b'\x00\x00\x12hmac-md5,hmac-sha1\x00\x00\x00\tzlib,none\x00\x00'
b'\x00\tzlib,none\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x00\x99\x99\x99\x99')
# Even if client prefer diffie-hellman-group1-sha1, we will go for
# diffie-hellman-group-exchange-sha256 as this what we prefer and is
# also supported by the server.
self.assertEqual(self.proto.kexAlg,
b'diffie-hellman-group-exchange-sha256')
self.assertEqual(self.proto.keyAlg,
b'ssh-rsa')
self.assertEqual(self.proto.outgoingCompressionType,
b'none')
self.assertEqual(self.proto.incomingCompressionType,
b'none')
ne = self.proto.nextEncryptions
self.assertEqual(ne.outCipType, b'aes256-ctr')
self.assertEqual(ne.inCipType, b'aes256-ctr')
self.assertEqual(ne.outMACType, b'hmac-sha1')
self.assertEqual(ne.inMACType, b'hmac-sha1') | Receiving a KEXINIT packet listing multiple supported
algorithms will set up the first common algorithm, ordered after our
preference. | test_KEXINITMultipleAlgorithms | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_notImplementedClientMethods(self):
"""
verifyHostKey() should return a Deferred which fails with a
NotImplementedError exception. connectionSecure() should raise
NotImplementedError().
"""
self.assertRaises(NotImplementedError, self.klass().connectionSecure)
def _checkRaises(f):
f.trap(NotImplementedError)
d = self.klass().verifyHostKey(None, None)
return d.addCallback(self.fail).addErrback(_checkRaises) | verifyHostKey() should return a Deferred which fails with a
NotImplementedError exception. connectionSecure() should raise
NotImplementedError(). | test_notImplementedClientMethods | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def assertKexInitResponseForDH(self, kexAlgorithm, bits):
"""
Test that a KEXINIT packet with a group1 or group14 key exchange
results in a correct KEXDH_INIT response.
@param kexAlgorithm: The key exchange algorithm to use
@type kexAlgorithm: L{str}
"""
self.proto.supportedKeyExchanges = [kexAlgorithm]
# Imitate reception of server key exchange request contained
# in data returned by self.transport.value()
self.proto.dataReceived(self.transport.value())
x = self.proto.dhSecretKey.private_numbers().x
self.assertEqual(common.MP(x)[5:], b'\x99' * (bits // 8))
# Data sent to server should be a transport.MSG_KEXDH_INIT
# message containing our public key.
self.assertEqual(
self.packets,
[(transport.MSG_KEXDH_INIT, self.proto.dhSecretKeyPublicMP)]) | Test that a KEXINIT packet with a group1 or group14 key exchange
results in a correct KEXDH_INIT response.
@param kexAlgorithm: The key exchange algorithm to use
@type kexAlgorithm: L{str} | assertKexInitResponseForDH | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_KEXINIT_group14(self):
"""
KEXINIT messages requesting diffie-hellman-group14-sha1 result in
KEXDH_INIT responses.
"""
self.assertKexInitResponseForDH(b'diffie-hellman-group14-sha1', 2048) | KEXINIT messages requesting diffie-hellman-group14-sha1 result in
KEXDH_INIT responses. | test_KEXINIT_group14 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_KEXINIT_badKexAlg(self):
"""
Test that the client raises a ConchError if it receives a
KEXINIT message but doesn't have a key exchange algorithm that we
understand.
"""
self.proto.supportedKeyExchanges = [b'diffie-hellman-group24-sha1']
data = self.transport.value().replace(b'group14', b'group24')
self.assertRaises(ConchError, self.proto.dataReceived, data) | Test that the client raises a ConchError if it receives a
KEXINIT message but doesn't have a key exchange algorithm that we
understand. | test_KEXINIT_badKexAlg | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def begin_KEXDH_REPLY(self):
"""
Utility for test_KEXDH_REPLY and
test_disconnectKEXDH_REPLYBadSignature.
Begins a Diffie-Hellman key exchange in the named group
Group-14 and computes information needed to return either a
correct or incorrect signature.
"""
self.test_KEXINIT_group14()
f = 2
fMP = common.MP(f)
x = self.proto.dhSecretKey.private_numbers().x
p = self.proto.p
sharedSecret = _MPpow(f, x, p)
h = sha1()
h.update(common.NS(self.proto.ourVersionString) * 2)
h.update(common.NS(self.proto.ourKexInitPayload) * 2)
h.update(common.NS(self.blob))
h.update(self.proto.dhSecretKeyPublicMP)
h.update(fMP)
h.update(sharedSecret)
exchangeHash = h.digest()
signature = self.privObj.sign(exchangeHash)
return (exchangeHash, signature, common.NS(self.blob) + fMP) | Utility for test_KEXDH_REPLY and
test_disconnectKEXDH_REPLYBadSignature.
Begins a Diffie-Hellman key exchange in the named group
Group-14 and computes information needed to return either a
correct or incorrect signature. | begin_KEXDH_REPLY | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_KEXDH_REPLY(self):
"""
Test that the KEXDH_REPLY message verifies the server.
"""
(exchangeHash, signature, packetStart) = self.begin_KEXDH_REPLY()
def _cbTestKEXDH_REPLY(value):
self.assertIsNone(value)
self.assertTrue(self.calledVerifyHostKey)
self.assertEqual(self.proto.sessionID, exchangeHash)
d = self.proto.ssh_KEX_DH_GEX_GROUP(
packetStart + common.NS(signature)
)
d.addCallback(_cbTestKEXDH_REPLY)
return d | Test that the KEXDH_REPLY message verifies the server. | test_KEXDH_REPLY | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_keySetup(self):
"""
Test that _keySetup sets up the next encryption keys.
"""
self.proto.kexAlg = b'diffie-hellman-group14-sha1'
self.proto.nextEncryptions = MockCipher()
self.simulateKeyExchange(b'AB', b'CD')
self.assertEqual(self.proto.sessionID, b'CD')
self.simulateKeyExchange(b'AB', b'EF')
self.assertEqual(self.proto.sessionID, b'CD')
self.assertEqual(self.packets[-1], (transport.MSG_NEWKEYS, b''))
newKeys = [self.proto._getKey(c, b'AB', b'EF')
for c in iterbytes(b'ABCDEF')]
self.assertEqual(self.proto.nextEncryptions.keys,
(newKeys[0], newKeys[2], newKeys[1], newKeys[3],
newKeys[4], newKeys[5])) | Test that _keySetup sets up the next encryption keys. | test_keySetup | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_NEWKEYS(self):
"""
Test that NEWKEYS transitions the keys from nextEncryptions to
currentEncryptions.
"""
self.test_KEXINITMultipleAlgorithms()
secure = [False]
def stubConnectionSecure():
secure[0] = True
self.proto.connectionSecure = stubConnectionSecure
self.proto.nextEncryptions = transport.SSHCiphers(
b'none', b'none', b'none', b'none')
self.simulateKeyExchange(b'AB', b'CD')
self.assertIsNot(self.proto.currentEncryptions,
self.proto.nextEncryptions)
self.proto.nextEncryptions = MockCipher()
self.proto.ssh_NEWKEYS(b'')
self.assertIsNone(self.proto.outgoingCompression)
self.assertIsNone(self.proto.incomingCompression)
self.assertIs(self.proto.currentEncryptions,
self.proto.nextEncryptions)
self.assertTrue(secure[0])
self.proto.outgoingCompressionType = b'zlib'
self.simulateKeyExchange(b'AB', b'GH')
self.proto.ssh_NEWKEYS(b'')
self.assertIsNotNone(self.proto.outgoingCompression)
self.proto.incomingCompressionType = b'zlib'
self.simulateKeyExchange(b'AB', b'IJ')
self.proto.ssh_NEWKEYS(b'')
self.assertIsNotNone(self.proto.incomingCompression) | Test that NEWKEYS transitions the keys from nextEncryptions to
currentEncryptions. | test_NEWKEYS | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_SERVICE_ACCEPT(self):
"""
Test that the SERVICE_ACCEPT packet starts the requested service.
"""
self.proto.instance = MockService()
self.proto.ssh_SERVICE_ACCEPT(b'\x00\x00\x00\x0bMockService')
self.assertTrue(self.proto.instance.started) | Test that the SERVICE_ACCEPT packet starts the requested service. | test_SERVICE_ACCEPT | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_requestService(self):
"""
Test that requesting a service sends a SERVICE_REQUEST packet.
"""
self.proto.requestService(MockService())
self.assertEqual(self.packets, [(transport.MSG_SERVICE_REQUEST,
b'\x00\x00\x00\x0bMockService')]) | Test that requesting a service sends a SERVICE_REQUEST packet. | test_requestService | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_disconnectKEXDH_REPLYBadSignature(self):
"""
Test that KEXDH_REPLY disconnects if the signature is bad.
"""
(exchangeHash, signature, packetStart) = self.begin_KEXDH_REPLY()
d = self.proto.ssh_KEX_DH_GEX_GROUP(
packetStart + common.NS(b"bad signature")
)
return d.addCallback(
lambda _: self.checkDisconnected(
transport.DISCONNECT_KEY_EXCHANGE_FAILED)
) | Test that KEXDH_REPLY disconnects if the signature is bad. | test_disconnectKEXDH_REPLYBadSignature | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_disconnectKEX_ECDH_REPLYBadSignature(self):
"""
Test that KEX_ECDH_REPLY disconnects if the signature is bad.
"""
kexmsg = (
b"\xAA" * 16 +
common.NS(b'ecdh-sha2-nistp256') +
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')
self.proto.ssh_KEXINIT(kexmsg)
self.proto.dataReceived(b"SSH-2.0-OpenSSH\r\n")
self.proto.ecPriv = ec.generate_private_key(ec.SECP256R1(),
default_backend())
self.proto.ecPub = self.proto.ecPriv.public_key()
# Generate the private key
thisPriv = ec.generate_private_key(ec.SECP256R1(), default_backend())
# Get the public key
thisPub = thisPriv.public_key()
encPub = thisPub.public_bytes(
serialization.Encoding.X962,
serialization.PublicFormat.UncompressedPoint
)
self.proto.curve = ec.SECP256R1()
self.proto.kexAlg = b'ecdh-sha2-nistp256'
self.proto._ssh_KEX_ECDH_REPLY(
common.NS(MockFactory().getPublicKeys()[b'ssh-rsa'].blob()) +
common.NS(encPub) + common.NS(b'bad-signature'))
self.checkDisconnected(transport.DISCONNECT_KEY_EXCHANGE_FAILED) | Test that KEX_ECDH_REPLY disconnects if the signature is bad. | test_disconnectKEX_ECDH_REPLYBadSignature | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_disconnectNEWKEYSData(self):
"""
Test that NEWKEYS disconnects if it receives data.
"""
self.proto.ssh_NEWKEYS(b"bad packet")
self.checkDisconnected() | Test that NEWKEYS disconnects if it receives data. | test_disconnectNEWKEYSData | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_disconnectSERVICE_ACCEPT(self):
"""
Test that SERVICE_ACCEPT disconnects if the accepted protocol is
differet from the asked-for protocol.
"""
self.proto.instance = MockService()
self.proto.ssh_SERVICE_ACCEPT(b'\x00\x00\x00\x03bad')
self.checkDisconnected() | Test that SERVICE_ACCEPT disconnects if the accepted protocol is
differet from the asked-for protocol. | test_disconnectSERVICE_ACCEPT | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_noPayloadSERVICE_ACCEPT(self):
"""
Some commercial SSH servers don't send a payload with the
SERVICE_ACCEPT message. Conch pretends that it got the correct
name of the service.
"""
self.proto.instance = MockService()
self.proto.ssh_SERVICE_ACCEPT(b'') # no payload
self.assertTrue(self.proto.instance.started)
self.assertEqual(len(self.packets), 0) # not disconnected | Some commercial SSH servers don't send a payload with the
SERVICE_ACCEPT message. Conch pretends that it got the correct
name of the service. | test_noPayloadSERVICE_ACCEPT | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_KEXINIT_groupexchange(self):
"""
KEXINIT packet with a group-exchange key exchange results
in a KEX_DH_GEX_REQUEST message.
"""
self.proto.supportedKeyExchanges = [self.kexAlgorithm]
self.proto.dataReceived(self.transport.value())
# The response will include our advertised group sizes.
self.assertEqual(self.packets, [(
transport.MSG_KEX_DH_GEX_REQUEST,
b'\x00\x00\x04\x00\x00\x00\x08\x00\x00\x00\x20\x00')]) | KEXINIT packet with a group-exchange key exchange results
in a KEX_DH_GEX_REQUEST message. | test_KEXINIT_groupexchange | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_KEX_DH_GEX_GROUP(self):
"""
Test that the KEX_DH_GEX_GROUP message results in a
KEX_DH_GEX_INIT message with the client's Diffie-Hellman public key.
"""
self.test_KEXINIT_groupexchange()
self.proto.ssh_KEX_DH_GEX_GROUP(
b'\x00\x00\x00\x03\x00\xfe\xf3\x00\x00\x00\x01\x02')
self.assertEqual(self.proto.p, 65267)
self.assertEqual(self.proto.g, 2)
x = self.proto.dhSecretKey.private_numbers().x
self.assertEqual(common.MP(x)[5:], b'\x99' * 2)
self.assertEqual(self.proto.dhSecretKeyPublicMP,
common.MP(pow(2, x, 65267)))
self.assertEqual(self.packets[1:], [(transport.MSG_KEX_DH_GEX_INIT,
self.proto.dhSecretKeyPublicMP)]) | Test that the KEX_DH_GEX_GROUP message results in a
KEX_DH_GEX_INIT message with the client's Diffie-Hellman public key. | test_KEX_DH_GEX_GROUP | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def begin_KEX_DH_GEX_REPLY(self):
"""
Utility for test_KEX_DH_GEX_REPLY and
test_disconnectGEX_REPLYBadSignature.
Begins a Diffie-Hellman key exchange in an unnamed
(server-specified) group and computes information needed to
return either a correct or incorrect signature.
"""
self.test_KEX_DH_GEX_GROUP()
p = self.proto.p
f = 3
fMP = common.MP(f)
sharedSecret = _MPpow(
f,
self.proto.dhSecretKey.private_numbers().x,
p)
h = self.hashProcessor()
h.update(common.NS(self.proto.ourVersionString) * 2)
h.update(common.NS(self.proto.ourKexInitPayload) * 2)
h.update(common.NS(self.blob))
# Here is the wire format for advertised min, pref and max DH sizes.
h.update(b'\x00\x00\x04\x00\x00\x00\x08\x00\x00\x00\x20\x00')
# And the selected group parameters.
h.update(b'\x00\x00\x00\x03\x00\xfe\xf3\x00\x00\x00\x01\x02')
h.update(self.proto.dhSecretKeyPublicMP)
h.update(fMP)
h.update(sharedSecret)
exchangeHash = h.digest()
signature = self.privObj.sign(exchangeHash)
return (
exchangeHash,
signature,
common.NS(self.blob) + fMP
) | Utility for test_KEX_DH_GEX_REPLY and
test_disconnectGEX_REPLYBadSignature.
Begins a Diffie-Hellman key exchange in an unnamed
(server-specified) group and computes information needed to
return either a correct or incorrect signature. | begin_KEX_DH_GEX_REPLY | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_KEX_DH_GEX_REPLY(self):
"""
Test that the KEX_DH_GEX_REPLY message results in a verified
server.
"""
(exchangeHash, signature, packetStart) = self.begin_KEX_DH_GEX_REPLY()
def _cbTestKEX_DH_GEX_REPLY(value):
self.assertIsNone(value)
self.assertTrue(self.calledVerifyHostKey)
self.assertEqual(self.proto.sessionID, exchangeHash)
d = self.proto.ssh_KEX_DH_GEX_REPLY(packetStart + common.NS(signature))
d.addCallback(_cbTestKEX_DH_GEX_REPLY)
return d | Test that the KEX_DH_GEX_REPLY message results in a verified
server. | test_KEX_DH_GEX_REPLY | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_disconnectGEX_REPLYBadSignature(self):
"""
Test that KEX_DH_GEX_REPLY disconnects if the signature is bad.
"""
(exchangeHash, signature, packetStart) = self.begin_KEX_DH_GEX_REPLY()
d = self.proto.ssh_KEX_DH_GEX_REPLY(
packetStart + common.NS(b"bad signature"))
return d.addCallback(
lambda _: self.checkDisconnected(
transport.DISCONNECT_KEY_EXCHANGE_FAILED)
) | Test that KEX_DH_GEX_REPLY disconnects if the signature is bad. | test_disconnectGEX_REPLYBadSignature | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_disconnectKEX_ECDH_REPLYBadSignature(self):
"""
Test that KEX_ECDH_REPLY disconnects if the signature is bad.
"""
kexmsg = (
b"\xAA" * 16 +
common.NS(b'ecdh-sha2-nistp256') +
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')
self.proto.ssh_KEXINIT(kexmsg)
self.proto.dataReceived(b"SSH-2.0-OpenSSH\r\n")
self.proto.ecPriv = ec.generate_private_key(ec.SECP256R1(),
default_backend())
self.proto.ecPub = self.proto.ecPriv.public_key()
# Generate the private key
thisPriv = ec.generate_private_key(ec.SECP256R1(), default_backend())
# Get the public key
thisPub = thisPriv.public_key()
encPub = thisPub.public_bytes(
serialization.Encoding.X962,
serialization.PublicFormat.UncompressedPoint
)
self.proto.curve = ec.SECP256R1()
self.proto.kexAlg = b'ecdh-sha2-nistp256'
self.proto._ssh_KEX_ECDH_REPLY(
common.NS(MockFactory().getPublicKeys()[b'ssh-rsa'].blob()) +
common.NS(encPub) + common.NS(b'bad-signature'))
self.checkDisconnected(transport.DISCONNECT_KEY_EXCHANGE_FAILED) | Test that KEX_ECDH_REPLY disconnects if the signature is bad. | test_disconnectKEX_ECDH_REPLYBadSignature | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def getSharedSecret(self):
"""
Generate a new shared secret to be used with the tests.
@return: A new secret.
@rtype: L{bytes}
"""
return insecureRandom(64) | Generate a new shared secret to be used with the tests.
@return: A new secret.
@rtype: L{bytes} | getSharedSecret | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def assertGetMAC(self, hmacName, hashProcessor, digestSize, blockPadSize):
"""
Check that when L{SSHCiphers._getMAC} is called with a supportd HMAC
algorithm name it returns a tuple of
(digest object, inner pad, outer pad, digest size) with a C{key}
attribute set to the value of the key supplied.
@param hmacName: Identifier of HMAC algorithm.
@type hmacName: L{bytes}
@param hashProcessor: Callable for the hash algorithm.
@type hashProcessor: C{callable}
@param digestSize: Size of the digest for algorithm.
@type digestSize: L{int}
@param blockPadSize: Size of padding applied to the shared secret to
match the block size.
@type blockPadSize: L{int}
"""
secret = self.getSharedSecret()
params = self.ciphers._getMAC(hmacName, secret)
key = secret[:digestSize] + b'\x00' * blockPadSize
innerPad = b''.join(chr(ord(b) ^ 0x36) for b in iterbytes(key))
outerPad = b''.join(chr(ord(b) ^ 0x5c) for b in iterbytes(key))
self.assertEqual(
(hashProcessor, innerPad, outerPad, digestSize), params)
self.assertEqual(key, params.key) | Check that when L{SSHCiphers._getMAC} is called with a supportd HMAC
algorithm name it returns a tuple of
(digest object, inner pad, outer pad, digest size) with a C{key}
attribute set to the value of the key supplied.
@param hmacName: Identifier of HMAC algorithm.
@type hmacName: L{bytes}
@param hashProcessor: Callable for the hash algorithm.
@type hashProcessor: C{callable}
@param digestSize: Size of the digest for algorithm.
@type digestSize: L{int}
@param blockPadSize: Size of padding applied to the shared secret to
match the block size.
@type blockPadSize: L{int} | assertGetMAC | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_hmacsha2512(self):
"""
When L{SSHCiphers._getMAC} is called with the C{b"hmac-sha2-512"} MAC
algorithm name it returns a tuple of (sha512 digest object, inner pad,
outer pad, sha512 digest size) with a C{key} attribute set to the
value of the key supplied.
"""
self.assertGetMAC(
b"hmac-sha2-512", sha512, digestSize=64, blockPadSize=64) | When L{SSHCiphers._getMAC} is called with the C{b"hmac-sha2-512"} MAC
algorithm name it returns a tuple of (sha512 digest object, inner pad,
outer pad, sha512 digest size) with a C{key} attribute set to the
value of the key supplied. | test_hmacsha2512 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_hmacsha2384(self):
"""
When L{SSHCiphers._getMAC} is called with the C{b"hmac-sha2-384"} MAC
algorithm name it returns a tuple of (sha384 digest object, inner pad,
outer pad, sha384 digest size) with a C{key} attribute set to the
value of the key supplied.
"""
self.assertGetMAC(
b"hmac-sha2-384", sha384, digestSize=48, blockPadSize=80) | When L{SSHCiphers._getMAC} is called with the C{b"hmac-sha2-384"} MAC
algorithm name it returns a tuple of (sha384 digest object, inner pad,
outer pad, sha384 digest size) with a C{key} attribute set to the
value of the key supplied. | test_hmacsha2384 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_hmacsha2256(self):
"""
When L{SSHCiphers._getMAC} is called with the C{b"hmac-sha2-256"} MAC
algorithm name it returns a tuple of (sha256 digest object, inner pad,
outer pad, sha256 digest size) with a C{key} attribute set to the
value of the key supplied.
"""
self.assertGetMAC(
b"hmac-sha2-256", sha256, digestSize=32, blockPadSize=32) | When L{SSHCiphers._getMAC} is called with the C{b"hmac-sha2-256"} MAC
algorithm name it returns a tuple of (sha256 digest object, inner pad,
outer pad, sha256 digest size) with a C{key} attribute set to the
value of the key supplied. | test_hmacsha2256 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_hmacsha1(self):
"""
When L{SSHCiphers._getMAC} is called with the C{b"hmac-sha1"} MAC
algorithm name it returns a tuple of (sha1 digest object, inner pad,
outer pad, sha1 digest size) with a C{key} attribute set to the value
of the key supplied.
"""
self.assertGetMAC(b"hmac-sha1", sha1, digestSize=20, blockPadSize=44) | When L{SSHCiphers._getMAC} is called with the C{b"hmac-sha1"} MAC
algorithm name it returns a tuple of (sha1 digest object, inner pad,
outer pad, sha1 digest size) with a C{key} attribute set to the value
of the key supplied. | test_hmacsha1 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_hmacmd5(self):
"""
When L{SSHCiphers._getMAC} is called with the C{b"hmac-md5"} MAC
algorithm name it returns a tuple of (md5 digest object, inner pad,
outer pad, md5 digest size) with a C{key} attribute set to the value of
the key supplied.
"""
self.assertGetMAC(b"hmac-md5", md5, digestSize=16, blockPadSize=48) | When L{SSHCiphers._getMAC} is called with the C{b"hmac-md5"} MAC
algorithm name it returns a tuple of (md5 digest object, inner pad,
outer pad, md5 digest size) with a C{key} attribute set to the value of
the key supplied. | test_hmacmd5 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_none(self):
"""
When L{SSHCiphers._getMAC} is called with the C{b"none"} MAC algorithm
name it returns a tuple of (None, "", "", 0).
"""
key = self.getSharedSecret()
params = self.ciphers._getMAC(b"none", key)
self.assertEqual((None, b"", b"", 0), params) | When L{SSHCiphers._getMAC} is called with the C{b"none"} MAC algorithm
name it returns a tuple of (None, "", "", 0). | test_none | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_init(self):
"""
Test that the initializer sets up the SSHCiphers object.
"""
ciphers = transport.SSHCiphers(b'A', b'B', b'C', b'D')
self.assertEqual(ciphers.outCipType, b'A')
self.assertEqual(ciphers.inCipType, b'B')
self.assertEqual(ciphers.outMACType, b'C')
self.assertEqual(ciphers.inMACType, b'D') | Test that the initializer sets up the SSHCiphers object. | test_init | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_getCipher(self):
"""
Test that the _getCipher method returns the correct cipher.
"""
ciphers = transport.SSHCiphers(b'A', b'B', b'C', b'D')
iv = key = b'\x00' * 16
for cipName, (algClass, keySize, counter) in ciphers.cipherMap.items():
cip = ciphers._getCipher(cipName, iv, key)
if cipName == b'none':
self.assertIsInstance(cip, transport._DummyCipher)
else:
self.assertIsInstance(cip.algorithm, algClass) | Test that the _getCipher method returns the correct cipher. | test_getCipher | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_setKeysCiphers(self):
"""
Test that setKeys sets up the ciphers.
"""
key = b'\x00' * 64
for cipName in transport.SSHTransportBase.supportedCiphers:
modName, keySize, counter = transport.SSHCiphers.cipherMap[cipName]
encCipher = transport.SSHCiphers(cipName, b'none', b'none',
b'none')
decCipher = transport.SSHCiphers(b'none', cipName, b'none',
b'none')
cip = encCipher._getCipher(cipName, key, key)
bs = cip.algorithm.block_size // 8
encCipher.setKeys(key, key, b'', b'', b'', b'')
decCipher.setKeys(b'', b'', key, key, b'', b'')
self.assertEqual(encCipher.encBlockSize, bs)
self.assertEqual(decCipher.decBlockSize, bs)
encryptor = cip.encryptor()
enc = encryptor.update(key[:bs])
enc2 = encryptor.update(key[:bs])
self.assertEqual(encCipher.encrypt(key[:bs]), enc)
self.assertEqual(encCipher.encrypt(key[:bs]), enc2)
self.assertEqual(decCipher.decrypt(enc), key[:bs])
self.assertEqual(decCipher.decrypt(enc2), key[:bs]) | Test that setKeys sets up the ciphers. | test_setKeysCiphers | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_setKeysMACs(self):
"""
Test that setKeys sets up the MACs.
"""
key = b'\x00' * 64
for macName, mod in transport.SSHCiphers.macMap.items():
outMac = transport.SSHCiphers(b'none', b'none', macName, b'none')
inMac = transport.SSHCiphers(b'none', b'none', b'none', macName)
outMac.setKeys(b'', b'', b'', b'', key, b'')
inMac.setKeys(b'', b'', b'', b'', b'', key)
if mod:
ds = mod().digest_size
else:
ds = 0
self.assertEqual(inMac.verifyDigestSize, ds)
if mod:
mod, i, o, ds = outMac._getMAC(macName, key)
seqid = 0
data = key
packet = b'\x00' * 4 + key
if mod:
mac = mod(o + mod(i + packet).digest()).digest()
else:
mac = b''
self.assertEqual(outMac.makeMAC(seqid, data), mac)
self.assertTrue(inMac.verify(seqid, data, mac)) | Test that setKeys sets up the MACs. | test_setKeysMACs | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_makeMAC(self):
"""
L{SSHCiphers.makeMAC} computes the HMAC of an outgoing SSH message with
a particular sequence id and content data.
"""
# Use the test vectors given in the appendix of RFC 2104.
vectors = [
(b"\x0b" * 16, b"Hi There",
b"9294727a3638bb1c13f48ef8158bfc9d"),
(b"Jefe", b"what do ya want for nothing?",
b"750c783e6ab0b503eaa86e310a5db738"),
(b"\xAA" * 16, b"\xDD" * 50,
b"56be34521d144c88dbb8c733f0e8b3f6"),
]
for key, data, mac in vectors:
outMAC = transport.SSHCiphers(b'none', b'none', b'hmac-md5',
b'none')
outMAC.outMAC = outMAC._getMAC(b"hmac-md5", key)
(seqid,) = struct.unpack('>L', data[:4])
shortened = data[4:]
self.assertEqual(
mac, binascii.hexlify(outMAC.makeMAC(seqid, shortened)),
"Failed HMAC test vector; key=%r data=%r" % (key, data)) | L{SSHCiphers.makeMAC} computes the HMAC of an outgoing SSH message with
a particular sequence id and content data. | test_makeMAC | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def _runClientServer(self, mod):
"""
Run an async client and server, modifying each using the mod function
provided. Returns a Deferred called back when both Protocols have
disconnected.
@type mod: C{func}
@rtype: C{defer.Deferred}
"""
factory = MockFactory()
server = transport.SSHServerTransport()
server.factory = factory
factory.startFactory()
server.errors = []
server.receiveError = lambda code, desc: server.errors.append((
code, desc))
client = transport.SSHClientTransport()
client.verifyHostKey = lambda x, y: defer.succeed(None)
client.errors = []
client.receiveError = lambda code, desc: client.errors.append((
code, desc))
client.connectionSecure = lambda: client.loseConnection()
server.supportedPublicKeys = list(
server.factory.getPublicKeys().keys())
server = mod(server)
client = mod(client)
def check(ignored, server, client):
name = repr([server.supportedCiphers[0],
server.supportedMACs[0],
server.supportedKeyExchanges[0],
server.supportedCompressions[0]])
self.assertEqual(client.errors, [])
self.assertEqual(server.errors, [(
transport.DISCONNECT_CONNECTION_LOST,
b"user closed connection")])
if server.supportedCiphers[0] == b'none':
self.assertFalse(server.isEncrypted(), name)
self.assertFalse(client.isEncrypted(), name)
else:
self.assertTrue(server.isEncrypted(), name)
self.assertTrue(client.isEncrypted(), name)
if server.supportedMACs[0] == b'none':
self.assertFalse(server.isVerified(), name)
self.assertFalse(client.isVerified(), name)
else:
self.assertTrue(server.isVerified(), name)
self.assertTrue(client.isVerified(), name)
d = loopback.loopbackAsync(server, client)
d.addCallback(check, server, client)
return d | Run an async client and server, modifying each using the mod function
provided. Returns a Deferred called back when both Protocols have
disconnected.
@type mod: C{func}
@rtype: C{defer.Deferred} | _runClientServer | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_ciphers(self):
"""
Test that the client and server play nicely together, in all
the various combinations of ciphers.
"""
deferreds = []
for cipher in transport.SSHTransportBase.supportedCiphers + [b'none']:
def setCipher(proto):
proto.supportedCiphers = [cipher]
return proto
deferreds.append(self._runClientServer(setCipher))
return defer.DeferredList(deferreds, fireOnOneErrback=True) | Test that the client and server play nicely together, in all
the various combinations of ciphers. | test_ciphers | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_macs(self):
"""
Like test_ciphers, but for the various MACs.
"""
deferreds = []
for mac in transport.SSHTransportBase.supportedMACs + [b'none']:
def setMAC(proto):
proto.supportedMACs = [mac]
return proto
deferreds.append(self._runClientServer(setMAC))
return defer.DeferredList(deferreds, fireOnOneErrback=True) | Like test_ciphers, but for the various MACs. | test_macs | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_keyexchanges(self):
"""
Like test_ciphers, but for the various key exchanges.
"""
deferreds = []
for kexAlgorithm in transport.SSHTransportBase.supportedKeyExchanges:
def setKeyExchange(proto):
proto.supportedKeyExchanges = [kexAlgorithm]
return proto
deferreds.append(self._runClientServer(setKeyExchange))
return defer.DeferredList(deferreds, fireOnOneErrback=True) | Like test_ciphers, but for the various key exchanges. | test_keyexchanges | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_compressions(self):
"""
Like test_ciphers, but for the various compressions.
"""
deferreds = []
for compression in transport.SSHTransportBase.supportedCompressions:
def setCompression(proto):
proto.supportedCompressions = [compression]
return proto
deferreds.append(self._runClientServer(setCompression))
return defer.DeferredList(deferreds, fireOnOneErrback=True) | Like test_ciphers, but for the various compressions. | test_compressions | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py | MIT |
def test_agentc_REQUEST_RSA_IDENTITIES(self):
"""
assert that we get the correct op code for an RSA identities request
"""
d = self.client.sendRequest(agent.AGENTC_REQUEST_RSA_IDENTITIES, b'')
self.pump.flush()
def _cb(packet):
self.assertEqual(
agent.AGENT_RSA_IDENTITIES_ANSWER, ord(packet[0:1]))
return d.addCallback(_cb) | assert that we get the correct op code for an RSA identities request | test_agentc_REQUEST_RSA_IDENTITIES | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_agentc_REMOVE_RSA_IDENTITY(self):
"""
assert that we get the correct op code for an RSA remove identity request
"""
d = self.client.sendRequest(agent.AGENTC_REMOVE_RSA_IDENTITY, b'')
self.pump.flush()
return d.addCallback(self.assertEqual, b'') | assert that we get the correct op code for an RSA remove identity request | test_agentc_REMOVE_RSA_IDENTITY | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_agentc_REMOVE_ALL_RSA_IDENTITIES(self):
"""
assert that we get the correct op code for an RSA remove all identities
request.
"""
d = self.client.sendRequest(agent.AGENTC_REMOVE_ALL_RSA_IDENTITIES, b'')
self.pump.flush()
return d.addCallback(self.assertEqual, b'') | assert that we get the correct op code for an RSA remove all identities
request. | test_agentc_REMOVE_ALL_RSA_IDENTITIES | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_signDataCallbackErrorHandling(self):
"""
Assert that L{SSHAgentClient.signData} raises a ConchError
if we get a response from the server whose opcode doesn't match
the protocol for data signing requests.
"""
d = self.client.signData(self.rsaPublic.blob(), b"John Hancock")
self.pump.flush()
return self.assertFailure(d, ConchError) | Assert that L{SSHAgentClient.signData} raises a ConchError
if we get a response from the server whose opcode doesn't match
the protocol for data signing requests. | test_signDataCallbackErrorHandling | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_requestIdentitiesCallbackErrorHandling(self):
"""
Assert that L{SSHAgentClient.requestIdentities} raises a ConchError
if we get a response from the server whose opcode doesn't match
the protocol for identity requests.
"""
d = self.client.requestIdentities()
self.pump.flush()
return self.assertFailure(d, ConchError) | Assert that L{SSHAgentClient.requestIdentities} raises a ConchError
if we get a response from the server whose opcode doesn't match
the protocol for identity requests. | test_requestIdentitiesCallbackErrorHandling | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_addRSAIdentityNoComment(self):
"""
L{SSHAgentClient.addIdentity} adds the private key it is called
with to the SSH agent server to which it is connected, associating
it with the comment it is called with.
This test asserts that omitting the comment produces an
empty string for the comment on the server.
"""
d = self.client.addIdentity(self.rsaPrivate.privateBlob())
self.pump.flush()
def _check(ignored):
serverKey = self.server.factory.keys[self.rsaPrivate.blob()]
self.assertEqual(self.rsaPrivate, serverKey[0])
self.assertEqual(b'', serverKey[1])
return d.addCallback(_check) | L{SSHAgentClient.addIdentity} adds the private key it is called
with to the SSH agent server to which it is connected, associating
it with the comment it is called with.
This test asserts that omitting the comment produces an
empty string for the comment on the server. | test_addRSAIdentityNoComment | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_addDSAIdentityNoComment(self):
"""
L{SSHAgentClient.addIdentity} adds the private key it is called
with to the SSH agent server to which it is connected, associating
it with the comment it is called with.
This test asserts that omitting the comment produces an
empty string for the comment on the server.
"""
d = self.client.addIdentity(self.dsaPrivate.privateBlob())
self.pump.flush()
def _check(ignored):
serverKey = self.server.factory.keys[self.dsaPrivate.blob()]
self.assertEqual(self.dsaPrivate, serverKey[0])
self.assertEqual(b'', serverKey[1])
return d.addCallback(_check) | L{SSHAgentClient.addIdentity} adds the private key it is called
with to the SSH agent server to which it is connected, associating
it with the comment it is called with.
This test asserts that omitting the comment produces an
empty string for the comment on the server. | test_addDSAIdentityNoComment | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_addRSAIdentityWithComment(self):
"""
L{SSHAgentClient.addIdentity} adds the private key it is called
with to the SSH agent server to which it is connected, associating
it with the comment it is called with.
This test asserts that the server receives/stores the comment
as sent by the client.
"""
d = self.client.addIdentity(
self.rsaPrivate.privateBlob(), comment=b'My special key')
self.pump.flush()
def _check(ignored):
serverKey = self.server.factory.keys[self.rsaPrivate.blob()]
self.assertEqual(self.rsaPrivate, serverKey[0])
self.assertEqual(b'My special key', serverKey[1])
return d.addCallback(_check) | L{SSHAgentClient.addIdentity} adds the private key it is called
with to the SSH agent server to which it is connected, associating
it with the comment it is called with.
This test asserts that the server receives/stores the comment
as sent by the client. | test_addRSAIdentityWithComment | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_addDSAIdentityWithComment(self):
"""
L{SSHAgentClient.addIdentity} adds the private key it is called
with to the SSH agent server to which it is connected, associating
it with the comment it is called with.
This test asserts that the server receives/stores the comment
as sent by the client.
"""
d = self.client.addIdentity(
self.dsaPrivate.privateBlob(), comment=b'My special key')
self.pump.flush()
def _check(ignored):
serverKey = self.server.factory.keys[self.dsaPrivate.blob()]
self.assertEqual(self.dsaPrivate, serverKey[0])
self.assertEqual(b'My special key', serverKey[1])
return d.addCallback(_check) | L{SSHAgentClient.addIdentity} adds the private key it is called
with to the SSH agent server to which it is connected, associating
it with the comment it is called with.
This test asserts that the server receives/stores the comment
as sent by the client. | test_addDSAIdentityWithComment | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_agentFailure(self):
"""
verify that the client raises ConchError on AGENT_FAILURE
"""
d = self.client.sendRequest(254, b'')
self.pump.flush()
return self.assertFailure(d, ConchError) | verify that the client raises ConchError on AGENT_FAILURE | test_agentFailure | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_signDataRSA(self):
"""
Sign data with an RSA private key and then verify it with the public
key.
"""
d = self.client.signData(self.rsaPublic.blob(), b"John Hancock")
self.pump.flush()
signature = self.successResultOf(d)
expected = self.rsaPrivate.sign(b"John Hancock")
self.assertEqual(expected, signature)
self.assertTrue(self.rsaPublic.verify(signature, b"John Hancock")) | Sign data with an RSA private key and then verify it with the public
key. | test_signDataRSA | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_signDataDSA(self):
"""
Sign data with a DSA private key and then verify it with the public
key.
"""
d = self.client.signData(self.dsaPublic.blob(), b"John Hancock")
self.pump.flush()
def _check(sig):
# Cannot do this b/c DSA uses random numbers when signing
# expected = self.dsaPrivate.sign("John Hancock")
# self.assertEqual(expected, sig)
self.assertTrue(self.dsaPublic.verify(sig, b"John Hancock"))
return d.addCallback(_check) | Sign data with a DSA private key and then verify it with the public
key. | test_signDataDSA | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_signDataRSAErrbackOnUnknownBlob(self):
"""
Assert that we get an errback if we try to sign data using a key that
wasn't added.
"""
del self.server.factory.keys[self.rsaPublic.blob()]
d = self.client.signData(self.rsaPublic.blob(), b"John Hancock")
self.pump.flush()
return self.assertFailure(d, ConchError) | Assert that we get an errback if we try to sign data using a key that
wasn't added. | test_signDataRSAErrbackOnUnknownBlob | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_requestIdentities(self):
"""
Assert that we get all of the keys/comments that we add when we issue a
request for all identities.
"""
d = self.client.requestIdentities()
self.pump.flush()
def _check(keyt):
expected = {}
expected[self.dsaPublic.blob()] = b'a comment'
expected[self.rsaPublic.blob()] = b'another comment'
received = {}
for k in keyt:
received[keys.Key.fromString(k[0], type='blob').blob()] = k[1]
self.assertEqual(expected, received)
return d.addCallback(_check) | Assert that we get all of the keys/comments that we add when we issue a
request for all identities. | test_requestIdentities | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_removeRSAIdentity(self):
"""
Assert that we can remove an RSA identity.
"""
# only need public key for this
d = self.client.removeIdentity(self.rsaPrivate.blob())
self.pump.flush()
def _check(ignored):
self.assertEqual(1, len(self.server.factory.keys))
self.assertIn(self.dsaPrivate.blob(), self.server.factory.keys)
self.assertNotIn(self.rsaPrivate.blob(), self.server.factory.keys)
return d.addCallback(_check) | Assert that we can remove an RSA identity. | test_removeRSAIdentity | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_removeDSAIdentity(self):
"""
Assert that we can remove a DSA identity.
"""
# only need public key for this
d = self.client.removeIdentity(self.dsaPrivate.blob())
self.pump.flush()
def _check(ignored):
self.assertEqual(1, len(self.server.factory.keys))
self.assertIn(self.rsaPrivate.blob(), self.server.factory.keys)
return d.addCallback(_check) | Assert that we can remove a DSA identity. | test_removeDSAIdentity | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_removeAllIdentities(self):
"""
Assert that we can remove all identities.
"""
d = self.client.removeAllIdentities()
self.pump.flush()
def _check(ignored):
self.assertEqual(0, len(self.server.factory.keys))
return d.addCallback(_check) | Assert that we can remove all identities. | test_removeAllIdentities | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_agent.py | MIT |
def test_verifyCryptedPassword(self):
"""
L{verifyCryptedPassword} returns C{True} if the plaintext password
passed to it matches the encrypted password passed to it.
"""
password = 'secret string'
salt = 'salty'
crypted = crypt.crypt(password, salt)
self.assertTrue(
checkers.verifyCryptedPassword(crypted, password),
'%r supposed to be valid encrypted password for %r' % (
crypted, password)) | L{verifyCryptedPassword} returns C{True} if the plaintext password
passed to it matches the encrypted password passed to it. | test_verifyCryptedPassword | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_verifyCryptedPasswordMD5(self):
"""
L{verifyCryptedPassword} returns True if the provided cleartext password
matches the provided MD5 password hash.
"""
password = 'password'
salt = '$1$salt'
crypted = crypt.crypt(password, salt)
self.assertTrue(
checkers.verifyCryptedPassword(crypted, password),
'%r supposed to be valid encrypted password for %s' % (
crypted, password)) | L{verifyCryptedPassword} returns True if the provided cleartext password
matches the provided MD5 password hash. | test_verifyCryptedPasswordMD5 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_refuteCryptedPassword(self):
"""
L{verifyCryptedPassword} returns C{False} if the plaintext password
passed to it does not match the encrypted password passed to it.
"""
password = 'string secret'
wrong = 'secret string'
crypted = crypt.crypt(password, password)
self.assertFalse(
checkers.verifyCryptedPassword(crypted, wrong),
'%r not supposed to be valid encrypted password for %s' % (
crypted, wrong)) | L{verifyCryptedPassword} returns C{False} if the plaintext password
passed to it does not match the encrypted password passed to it. | test_refuteCryptedPassword | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_pwdGetByName(self):
"""
L{_pwdGetByName} returns a tuple of items from the UNIX /etc/passwd
database if the L{pwd} module is present.
"""
userdb = UserDatabase()
userdb.addUser(
'alice', 'secrit', 1, 2, 'first last', '/foo', '/bin/sh')
self.patch(checkers, 'pwd', userdb)
self.assertEqual(
checkers._pwdGetByName('alice'), userdb.getpwnam('alice')) | L{_pwdGetByName} returns a tuple of items from the UNIX /etc/passwd
database if the L{pwd} module is present. | test_pwdGetByName | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_pwdGetByNameWithoutPwd(self):
"""
If the C{pwd} module isn't present, L{_pwdGetByName} returns L{None}.
"""
self.patch(checkers, 'pwd', None)
self.assertIsNone(checkers._pwdGetByName('alice')) | If the C{pwd} module isn't present, L{_pwdGetByName} returns L{None}. | test_pwdGetByNameWithoutPwd | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_shadowGetByName(self):
"""
L{_shadowGetByName} returns a tuple of items from the UNIX /etc/shadow
database if the L{spwd} is present.
"""
userdb = ShadowDatabase()
userdb.addUser('bob', 'passphrase', 1, 2, 3, 4, 5, 6, 7)
self.patch(checkers, 'spwd', userdb)
self.mockos.euid = 2345
self.mockos.egid = 1234
self.patch(util, 'os', self.mockos)
self.assertEqual(
checkers._shadowGetByName('bob'), userdb.getspnam('bob'))
self.assertEqual(self.mockos.seteuidCalls, [0, 2345])
self.assertEqual(self.mockos.setegidCalls, [0, 1234]) | L{_shadowGetByName} returns a tuple of items from the UNIX /etc/shadow
database if the L{spwd} is present. | test_shadowGetByName | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_shadowGetByNameWithoutSpwd(self):
"""
L{_shadowGetByName} returns L{None} if C{spwd} is not present.
"""
self.patch(checkers, 'spwd', None)
self.assertIsNone(checkers._shadowGetByName('bob'))
self.assertEqual(self.mockos.seteuidCalls, [])
self.assertEqual(self.mockos.setegidCalls, []) | L{_shadowGetByName} returns L{None} if C{spwd} is not present. | test_shadowGetByNameWithoutSpwd | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_deprecated(self):
"""
L{SSHPublicKeyDatabase} is deprecated as of version 15.0
"""
warningsShown = self.flushWarnings(
offendingFunctions=[self.setUp])
self.assertEqual(warningsShown[0]['category'], DeprecationWarning)
self.assertEqual(
warningsShown[0]['message'],
"twisted.conch.checkers.SSHPublicKeyDatabase "
"was deprecated in Twisted 15.0.0: Please use "
"twisted.conch.checkers.SSHPublicKeyChecker, "
"initialized with an instance of "
"twisted.conch.checkers.UNIXAuthorizedKeysFiles instead.")
self.assertEqual(len(warningsShown), 1) | L{SSHPublicKeyDatabase} is deprecated as of version 15.0 | test_deprecated | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_checkKey(self):
"""
L{SSHPublicKeyDatabase.checkKey} should retrieve the content of the
authorized_keys file and check the keys against that file.
"""
self._testCheckKey("authorized_keys")
self.assertEqual(self.mockos.seteuidCalls, [])
self.assertEqual(self.mockos.setegidCalls, []) | L{SSHPublicKeyDatabase.checkKey} should retrieve the content of the
authorized_keys file and check the keys against that file. | test_checkKey | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_checkKey2(self):
"""
L{SSHPublicKeyDatabase.checkKey} should retrieve the content of the
authorized_keys2 file and check the keys against that file.
"""
self._testCheckKey("authorized_keys2")
self.assertEqual(self.mockos.seteuidCalls, [])
self.assertEqual(self.mockos.setegidCalls, []) | L{SSHPublicKeyDatabase.checkKey} should retrieve the content of the
authorized_keys2 file and check the keys against that file. | test_checkKey2 | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_checkKeyAsRoot(self):
"""
If the key file is readable, L{SSHPublicKeyDatabase.checkKey} should
switch its uid/gid to the ones of the authenticated user.
"""
keyFile = self.sshDir.child("authorized_keys")
keyFile.setContent(self.content)
# Fake permission error by changing the mode
keyFile.chmod(0o000)
self.addCleanup(keyFile.chmod, 0o777)
# And restore the right mode when seteuid is called
savedSeteuid = self.mockos.seteuid
def seteuid(euid):
keyFile.chmod(0o777)
return savedSeteuid(euid)
self.mockos.euid = 2345
self.mockos.egid = 1234
self.patch(self.mockos, "seteuid", seteuid)
self.patch(util, 'os', self.mockos)
user = UsernamePassword(b"user", b"password")
user.blob = b"foobar"
self.assertTrue(self.checker.checkKey(user))
self.assertEqual(self.mockos.seteuidCalls, [0, 1, 0, 2345])
self.assertEqual(self.mockos.setegidCalls, [2, 1234]) | If the key file is readable, L{SSHPublicKeyDatabase.checkKey} should
switch its uid/gid to the ones of the authenticated user. | test_checkKeyAsRoot | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_requestAvatarId(self):
"""
L{SSHPublicKeyDatabase.requestAvatarId} should return the avatar id
passed in if its C{_checkKey} method returns True.
"""
def _checkKey(ignored):
return True
self.patch(self.checker, 'checkKey', _checkKey)
credentials = SSHPrivateKey(
b'test', b'ssh-rsa', keydata.publicRSA_openssh, b'foo',
keys.Key.fromString(keydata.privateRSA_openssh).sign(b'foo'))
d = self.checker.requestAvatarId(credentials)
def _verify(avatarId):
self.assertEqual(avatarId, b'test')
return d.addCallback(_verify) | L{SSHPublicKeyDatabase.requestAvatarId} should return the avatar id
passed in if its C{_checkKey} method returns True. | test_requestAvatarId | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_requestAvatarIdWithoutSignature(self):
"""
L{SSHPublicKeyDatabase.requestAvatarId} should raise L{ValidPublicKey}
if the credentials represent a valid key without a signature. This
tells the user that the key is valid for login, but does not actually
allow that user to do so without a signature.
"""
def _checkKey(ignored):
return True
self.patch(self.checker, 'checkKey', _checkKey)
credentials = SSHPrivateKey(
b'test', b'ssh-rsa', keydata.publicRSA_openssh, None, None)
d = self.checker.requestAvatarId(credentials)
return self.assertFailure(d, ValidPublicKey) | L{SSHPublicKeyDatabase.requestAvatarId} should raise L{ValidPublicKey}
if the credentials represent a valid key without a signature. This
tells the user that the key is valid for login, but does not actually
allow that user to do so without a signature. | test_requestAvatarIdWithoutSignature | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_requestAvatarIdInvalidKey(self):
"""
If L{SSHPublicKeyDatabase.checkKey} returns False,
C{_cbRequestAvatarId} should raise L{UnauthorizedLogin}.
"""
def _checkKey(ignored):
return False
self.patch(self.checker, 'checkKey', _checkKey)
d = self.checker.requestAvatarId(None);
return self.assertFailure(d, UnauthorizedLogin) | If L{SSHPublicKeyDatabase.checkKey} returns False,
C{_cbRequestAvatarId} should raise L{UnauthorizedLogin}. | test_requestAvatarIdInvalidKey | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_requestAvatarIdInvalidSignature(self):
"""
Valid keys with invalid signatures should cause
L{SSHPublicKeyDatabase.requestAvatarId} to return a {UnauthorizedLogin}
failure
"""
def _checkKey(ignored):
return True
self.patch(self.checker, 'checkKey', _checkKey)
credentials = SSHPrivateKey(
b'test', b'ssh-rsa', keydata.publicRSA_openssh, b'foo',
keys.Key.fromString(keydata.privateDSA_openssh).sign(b'foo'))
d = self.checker.requestAvatarId(credentials)
return self.assertFailure(d, UnauthorizedLogin) | Valid keys with invalid signatures should cause
L{SSHPublicKeyDatabase.requestAvatarId} to return a {UnauthorizedLogin}
failure | test_requestAvatarIdInvalidSignature | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_requestAvatarIdNormalizeException(self):
"""
Exceptions raised while verifying the key should be normalized into an
C{UnauthorizedLogin} failure.
"""
def _checkKey(ignored):
return True
self.patch(self.checker, 'checkKey', _checkKey)
credentials = SSHPrivateKey(b'test', None, b'blob', b'sigData', b'sig')
d = self.checker.requestAvatarId(credentials)
def _verifyLoggedException(failure):
errors = self.flushLoggedErrors(keys.BadKeyError)
self.assertEqual(len(errors), 1)
return failure
d.addErrback(_verifyLoggedException)
return self.assertFailure(d, UnauthorizedLogin) | Exceptions raised while verifying the key should be normalized into an
C{UnauthorizedLogin} failure. | test_requestAvatarIdNormalizeException | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_registerChecker(self):
"""
L{SSHProcotolChecker.registerChecker} should add the given checker to
the list of registered checkers.
"""
checker = checkers.SSHProtocolChecker()
self.assertEqual(checker.credentialInterfaces, [])
checker.registerChecker(checkers.SSHPublicKeyDatabase(), )
self.assertEqual(checker.credentialInterfaces, [ISSHPrivateKey])
self.assertIsInstance(checker.checkers[ISSHPrivateKey],
checkers.SSHPublicKeyDatabase) | L{SSHProcotolChecker.registerChecker} should add the given checker to
the list of registered checkers. | test_registerChecker | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_registerCheckerWithInterface(self):
"""
If a specific interface is passed into
L{SSHProtocolChecker.registerChecker}, that interface should be
registered instead of what the checker specifies in
credentialIntefaces.
"""
checker = checkers.SSHProtocolChecker()
self.assertEqual(checker.credentialInterfaces, [])
checker.registerChecker(checkers.SSHPublicKeyDatabase(),
IUsernamePassword)
self.assertEqual(checker.credentialInterfaces, [IUsernamePassword])
self.assertIsInstance(checker.checkers[IUsernamePassword],
checkers.SSHPublicKeyDatabase) | If a specific interface is passed into
L{SSHProtocolChecker.registerChecker}, that interface should be
registered instead of what the checker specifies in
credentialIntefaces. | test_registerCheckerWithInterface | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_requestAvatarId(self):
"""
L{SSHProtocolChecker.requestAvatarId} should defer to one if its
registered checkers to authenticate a user.
"""
checker = checkers.SSHProtocolChecker()
passwordDatabase = InMemoryUsernamePasswordDatabaseDontUse()
passwordDatabase.addUser(b'test', b'test')
checker.registerChecker(passwordDatabase)
d = checker.requestAvatarId(UsernamePassword(b'test', b'test'))
def _callback(avatarId):
self.assertEqual(avatarId, b'test')
return d.addCallback(_callback) | L{SSHProtocolChecker.requestAvatarId} should defer to one if its
registered checkers to authenticate a user. | test_requestAvatarId | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_requestAvatarIdWithNotEnoughAuthentication(self):
"""
If the client indicates that it is never satisfied, by always returning
False from _areDone, then L{SSHProtocolChecker} should raise
L{NotEnoughAuthentication}.
"""
checker = checkers.SSHProtocolChecker()
def _areDone(avatarId):
return False
self.patch(checker, 'areDone', _areDone)
passwordDatabase = InMemoryUsernamePasswordDatabaseDontUse()
passwordDatabase.addUser(b'test', b'test')
checker.registerChecker(passwordDatabase)
d = checker.requestAvatarId(UsernamePassword(b'test', b'test'))
return self.assertFailure(d, NotEnoughAuthentication) | If the client indicates that it is never satisfied, by always returning
False from _areDone, then L{SSHProtocolChecker} should raise
L{NotEnoughAuthentication}. | test_requestAvatarIdWithNotEnoughAuthentication | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_requestAvatarIdInvalidCredential(self):
"""
If the passed credentials aren't handled by any registered checker,
L{SSHProtocolChecker} should raise L{UnhandledCredentials}.
"""
checker = checkers.SSHProtocolChecker()
d = checker.requestAvatarId(UsernamePassword(b'test', b'test'))
return self.assertFailure(d, UnhandledCredentials) | If the passed credentials aren't handled by any registered checker,
L{SSHProtocolChecker} should raise L{UnhandledCredentials}. | test_requestAvatarIdInvalidCredential | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
def test_areDone(self):
"""
The default L{SSHProcotolChecker.areDone} should simply return True.
"""
self.assertTrue(checkers.SSHProtocolChecker().areDone(None)) | The default L{SSHProcotolChecker.areDone} should simply return True. | test_areDone | python | wistbean/learn_python3_spider | stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | https://github.com/wistbean/learn_python3_spider/blob/master/stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_checkers.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.