def channelOpen(self, data): command = self.command.encode("utf-8") self.conn.sendRequest(self, "exec", NS(command), wantReply=1)
def writeChunk(self, offset, chunk): data = self.handle + struct.pack("!Q", offset) + NS(chunk) return self.parent._sendRequest(FXP_WRITE, data)
def __init__(self, parent, handle): self.parent = parent self.handle = NS(handle) self.filesCache = []
def sendBanner(self, text, language='en'): bytes = '\r\n'.join(text.encode('UTF8').splitlines() + ['']) self.transport.sendPacket(userauth.MSG_USERAUTH_BANNER, NS(bytes) + NS(language))
def __init__(self, parent, handle): self.parent = parent self.handle = NS(handle)
def check(ignored): self.assertEqual( self.authServer.transport.packets, [(userauth.MSG_USERAUTH_PK_OK, NS(b'ssh-rsa') + NS(blob))])
def test_publickey(self): """ Test that the client can authenticate with a public key. """ self.authClient.ssh_USERAUTH_FAILURE(NS(b'publickey') + b'\x00') self.assertEqual( self.authClient.transport.packets[-1], (userauth.MSG_USERAUTH_REQUEST, NS(b'foo') + NS(b'nancy') + NS(b'publickey') + b'\x00' + NS(b'ssh-dss') + NS(keys.Key.fromString(keydata.publicDSA_openssh).blob()))) # that key isn't good self.authClient.ssh_USERAUTH_FAILURE(NS(b'publickey') + b'\x00') blob = NS(keys.Key.fromString(keydata.publicRSA_openssh).blob()) self.assertEqual(self.authClient.transport.packets[-1], (userauth.MSG_USERAUTH_REQUEST, (NS(b'foo') + NS(b'nancy') + NS(b'publickey') + b'\x00' + NS(b'ssh-rsa') + blob))) self.authClient.ssh_USERAUTH_PK_OK( NS(b'ssh-rsa') + NS(keys.Key.fromString(keydata.publicRSA_openssh).blob())) sigData = (NS(self.authClient.transport.sessionID) + bytes( (userauth.MSG_USERAUTH_REQUEST, )) + NS(b'foo') + NS(b'nancy') + NS(b'publickey') + b'\x01' + NS(b'ssh-rsa') + blob) obj = keys.Key.fromString(keydata.privateRSA_openssh) self.assertEqual(self.authClient.transport.packets[-1], (userauth.MSG_USERAUTH_REQUEST, NS(b'foo') + NS(b'nancy') + NS(b'publickey') + b'\x01' + NS(b'ssh-rsa') + blob + NS(obj.sign(sigData))))
def channelOpen(self, whatever): d = self.conn.sendRequest(self, "subsystem", NS("sftp"), wantReply=True) d.addCallbacks(self._cbSFTP)
def _cbOpenFile(self, fileObj, requestId): fileId = str(hash(fileObj)) if fileId in self.openFiles: raise KeyError('id already open') self.openFiles[fileId] = fileObj self.sendPacket(FXP_HANDLE, requestId + NS(fileId))
def channelOpen(self, data): print "Executing %s..." % CMD self.model = Modeler() self.exptime = time.time() d = self.conn.sendRequest(self, 'exec', NS(CMD), wantReply=1)
def channelOpen(self, data): if self.timeout: reactor.callLater(self.timeout, self._execution_timeout) command = self.command.encode("utf-8") self.conn.sendRequest(self, "exec", NS(command), wantReply=1)
def check(ignored): self.assertEquals( self.authServer.transport.packets[-1], (transport.MSG_DISCONNECT, '\x00' * 3 + chr(transport.DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE) + NS("too many bad auths") + NS('')))
def channelOpen(self, ignored): log.info('exec ' + self._command) self.conn.sendRequest(self, 'exec', NS(self._command)) self._protocol.makeConnection(self)
def test_password(self): """ Test that the client can authentication with a password. This includes changing the password. """ self.authClient.ssh_USERAUTH_FAILURE(NS(b"password") + b"\x00") self.assertEqual( self.authClient.transport.packets[-1], ( userauth.MSG_USERAUTH_REQUEST, NS(b"foo") + NS(b"nancy") + NS(b"password") + b"\x00" + NS(b"foo"), ), ) self.authClient.ssh_USERAUTH_PK_OK(NS(b"") + NS(b"")) self.assertEqual( self.authClient.transport.packets[-1], ( userauth.MSG_USERAUTH_REQUEST, NS(b"foo") + NS(b"nancy") + NS(b"password") + b"\xff" + NS(b"foo") * 2, ), )
def channelOpen(self, ignoredData): d = self.conn.sendRequest(self, 'subsystem', NS('amp'), wantReply=True) d.addCallback(self._cbSubsystem) d.addErrback(logAndPassThrough) d.addErrback(lambda f: self.conn.transport.transport.loseConnection())
def _cbRead(self, result, requestId): if result == '': # python's read will return this for EOF raise EOFError() self.sendPacket(FXP_DATA, requestId + NS(result))
def check(ignored): self.assertEqual( self.authServer.transport.packets[0], (userauth.MSG_USERAUTH_INFO_REQUEST, (NS('') + NS('') + NS('') + '\x00\x00\x00\x02' + NS('Name: ') + '\x01' + NS('Password: '******'\x00')))
def _cbOpenDirectory(self, dirObj, requestId): handle = str(hash(dirObj)) if handle in self.openDirs: raise KeyError("already opened this directory") self.openDirs[handle] = [dirObj, iter(dirObj)] self.sendPacket(FXP_HANDLE, requestId + NS(handle))
def check(ignored): self.assertEqual( self.authServer.transport.packets[-1], (transport.MSG_DISCONNECT, b'\x00' * 3 + bytes( (transport.DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE, )) + NS(b"too many bad auths") + NS(b'')))
def connectionMade(self): data = struct.pack('!L', max(self.versions)) for k, v in self.extData.itervalues(): data += NS(k) + NS(v) self.sendPacket(FXP_INIT, data)
def test_password(self): """ Test that the client can authentication with a password. This includes changing the password. """ self.authClient.ssh_USERAUTH_FAILURE(NS(b'password') + b'\x00') self.assertEqual( self.authClient.transport.packets[-1], (userauth.MSG_USERAUTH_REQUEST, NS(b'foo') + NS(b'nancy') + NS(b'password') + b'\x00' + NS(b'foo'))) self.authClient.ssh_USERAUTH_PK_OK(NS(b'') + NS(b'')) self.assertEqual( self.authClient.transport.packets[-1], (userauth.MSG_USERAUTH_REQUEST, NS(b'foo') + NS(b'nancy') + NS(b'password') + b'\xff' + NS(b'foo') * 2))
def check(ignored): # Check that the server reports the failure, including 'password' # as a valid authentication type. self.assertEqual( self.authServer.transport.packets, [(userauth.MSG_USERAUTH_FAILURE, NS('password') + chr(0))])