Ticket #4428: 4428-bis.patch
| File 4428-bis.patch, 4.4 KB (added by alanfranzoni, 3 years ago) |
|---|
-
twisted/conch/test/test_transport.py
61 61 self.unimplementeds = [] 62 62 self.debugs = [] 63 63 self.ignoreds = [] 64 self.gotUnsupportedVersion = None 64 65 66 def _unsupportedVersionReceived(self, remoteVersion): 67 """ 68 Intercept unsupported version call. 65 69 70 @type remoteVersion: C{str} 71 """ 72 self.gotUnsupportedVersion = remoteVersion 73 return transport.SSHTransportBase._unsupportedVersionReceived(self, remoteVersion) 74 66 75 def receiveError(self, reasonCode, description): 67 76 """ 68 77 Store any errors received. … … 800 809 self.assertTrue(proto.gotVersion) 801 810 self.assertEquals(proto.otherVersionString, "SSH-1.99-OpenSSH") 802 811 812 def test_supportedVersionsAreAllowed(self): 813 """ 814 Test that versions configured as supported work. 815 """ 816 proto = MockTransportBase() 817 proto.supportedVersions = ("9.99", ) 818 proto.makeConnection(proto_helpers.StringTransport()) 819 proto.dataReceived("SSH-9.99-OpenSSH\n") 820 self.assert_(not proto.gotUnsupportedVersion) 803 821 822 def test_unsupportedVersionsCallUnsupportedVersionReceived(self): 823 """ 824 Test that versions not configured as supported don't work. 825 """ 826 proto = MockTransportBase() 827 proto.supportedVersions = ("2.0", ) 828 proto.makeConnection(proto_helpers.StringTransport()) 829 proto.dataReceived("SSH-9.99-OpenSSH\n") 830 self.assertEquals("9.99", proto.gotUnsupportedVersion) 831 804 832 def test_badPackets(self): 805 833 """ 806 834 Test that the transport disconnects with an error when it receives -
twisted/conch/topfiles/4428.feature
1 twisted.conch.ssh.transport.SSHTransportBase now allows supported ssh protocol versions to be overriden. -
twisted/conch/ssh/transport.py
67 67 @ivar supportedLanguages: A list of strings representing languages 68 68 supported, from most-preferred to least. 69 69 70 @ivar supportedVersions: A container of strings representing supported ssh 71 protcol version numbers. 72 70 73 @ivar isClient: A boolean indicating whether this is a client or server. 71 74 72 75 @ivar gotVersion: A boolean indicating whether we have receieved the … … 149 152 supportedPublicKeys = ['ssh-rsa', 'ssh-dss'] 150 153 supportedCompressions = ['none', 'zlib'] 151 154 supportedLanguages = () 155 supportedVersions = ('1.99', '2.0') 152 156 isClient = False 153 157 gotVersion = False 154 158 buf = '' … … 282 286 self.incomingPacketSequence += 1 283 287 return payload 284 288 289 def _unsupportedVersionReceived(self, remoteVersion): 290 """ 291 Called when an unsupported version of the ssh protocol is received from 292 the remote endpoint. 285 293 294 @param remoteVersion: remote ssh protocol version which is unsupported 295 by us. 296 @type remoteVersion: C{str} 297 """ 298 self.sendDisconnect(DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED, 299 'bad version ' + remoteVersion) 300 286 301 def dataReceived(self, data): 287 302 """ 288 303 First, check for the version string (SSH-2.0-*). After that has been … … 300 315 if p.startswith('SSH-'): 301 316 self.gotVersion = True 302 317 self.otherVersionString = p.strip() 303 if p.split('-')[1] not in ('1.99', '2.0'): # bad version 304 self.sendDisconnect( 305 DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED, 306 'bad version ' + p.split('-')[1]) 318 remoteVersion = p.split('-')[1] 319 if remoteVersion not in self.supportedVersions: 320 self._unsupportedVersionReceived(remoteVersion) 307 321 return 308 322 i = lines.index(p) 309 323 self.buf = '\n'.join(lines[i + 1:])
