[Twisted-Python] Possible error on key authentication of twisted conch

Mustafa Sakalsiz sakalsiz at gmail.com
Fri Jan 23 07:55:28 EST 2009


I have a python script that executes a python code on a remote host using
SSH. It was working perfectly with Twisted 2.5. The method of returning
private and public has changed in userauth.SSHUserAuthClient (Twisted 8.1).

I was using (Twisted 2.5)
def getPublicKey(self):
  return keys.getPublicKeyString(self.keyfile+'.pub')

def getPrivateKey(self):
  return defer.succeed(keys.getPrivateKeyObject(self.keyfile))

Now I am using (Twisted 8.1)
def getPublicKey(self):
  return keys.Key.fromFile(self.keyfile+'.pub')

def getPrivateKey(self):
  return defer.succeed(keys.Key.fromFile(self.keyfile))

and it doesn't work any more. I have attached the simplified script. Here is
the scenario I am using and the exception I got. Any help is greatly

I am creating a DSA key using ssh-keygen (in Debian and Ubuntu) with an
empty password

$ ssh-keygen -t dsa

and copy it to my localhost

$ ssh-copy-id -i ~/.ssh/id_dsa localhost

then run the attached script, which tries to execute a python script
remotely using SSH and get the following error

Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/twisted/internet/selectreactor.py",
line 146, in _doReadOrWrite
    why = getattr(selectable, method)()
  File "/usr/lib/python2.5/site-packages/twisted/internet/tcp.py", line 362,
in doRead
    return self.protocol.dataReceived(data)
  File "/usr/lib/python2.5/site-packages/twisted/conch/ssh/transport.py",
line 314, in dataReceived
    self.dispatchMessage(messageNum, packet[1:])
  File "/usr/lib/python2.5/site-packages/twisted/conch/ssh/transport.py",
line 336, in dispatchMessage
    messageNum, payload)
--- <exception caught here> ---
  File "/usr/lib/python2.5/site-packages/twisted/python/log.py", line 51, in
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/usr/lib/python2.5/site-packages/twisted/python/log.py", line 36, in
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/usr/lib/python2.5/site-packages/twisted/python/context.py", line
59, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/lib/python2.5/site-packages/twisted/python/context.py", line
37, in callWithContext
    return func(*args,**kw)
  File "/usr/lib/python2.5/site-packages/twisted/conch/ssh/service.py", line
44, in packetReceived
    return f(packet)
  File "/usr/lib/python2.5/site-packages/twisted/conch/ssh/userauth.py",
line 262, in ssh_USERAUTH_FAILURE
    if method not in self.authenticatedWith and self.tryAuth(method):
  File "/usr/lib/python2.5/site-packages/twisted/conch/ssh/userauth.py",
line 234, in tryAuth
    return f()
  File "/usr/lib/python2.5/site-packages/twisted/conch/ssh/userauth.py",
line 338, in auth_publickey
    keyType = getNS(publicKey)[0]
  File "/usr/lib/python2.5/site-packages/twisted/conch/ssh/common.py", line
51, in getNS
    l, = struct.unpack('!L',s[c:c+4])
exceptions.TypeError: 'Key' object is unsubscriptable


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20090123/109940b8/attachment.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mysshconnection.py
Type: text/x-python
Size: 7644 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20090123/109940b8/attachment.py 

More information about the Twisted-Python mailing list