예제 #1
0
 def channelOpen(self, data):
     command = self.command.encode("utf-8")
     self.conn.sendRequest(self, "exec", NS(command), wantReply=1)
예제 #2
0
 def writeChunk(self, offset, chunk):
     data = self.handle + struct.pack("!Q", offset) + NS(chunk)
     return self.parent._sendRequest(FXP_WRITE, data)
예제 #3
0
 def __init__(self, parent, handle):
     self.parent = parent
     self.handle = NS(handle)
     self.filesCache = []
예제 #4
0
 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))
예제 #5
0
 def __init__(self, parent, handle):
     self.parent = parent
     self.handle = NS(handle)
예제 #6
0
 def check(ignored):
     self.assertEqual(
         self.authServer.transport.packets,
         [(userauth.MSG_USERAUTH_PK_OK, NS(b'ssh-rsa') + NS(blob))])
예제 #7
0
 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))))
예제 #8
0
 def channelOpen(self, whatever):
     d = self.conn.sendRequest(self,
                               "subsystem",
                               NS("sftp"),
                               wantReply=True)
     d.addCallbacks(self._cbSFTP)
예제 #9
0
 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))
예제 #10
0
 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)
예제 #11
0
 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)
예제 #12
0
 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('')))
예제 #13
0
파일: ssh.py 프로젝트: veloutin/tilde
 def channelOpen(self, ignored):
     log.info('exec ' + self._command)
     self.conn.sendRequest(self, 'exec', NS(self._command))
     self._protocol.makeConnection(self)
예제 #14
0
 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,
         ),
     )
예제 #15
0
 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())
예제 #16
0
 def _cbRead(self, result, requestId):
     if result == '':  # python's read will return this for EOF
         raise EOFError()
     self.sendPacket(FXP_DATA, requestId + NS(result))
예제 #17
0
 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')))
예제 #18
0
 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))
예제 #19
0
 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'')))
예제 #20
0
 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)
예제 #21
0
 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))
예제 #22
0
 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))])