ncouture / MockSSH

Mock an SSH server and define all commands it supports (Python, Twisted)
Other
125 stars 23 forks source link

Add instructions to generate primes and keys (and where to store them) #12

Closed xavierhardy closed 8 years ago

xavierhardy commented 8 years ago

Add instructions to generate primes and keys (and where to store them). Running one the example out of the box, without any knowledge of how Twisted Conch works, results in an error, since primes are missing by default.

> python examples/mock_cisco.py
2016-05-31 11:59:38+0200 [-] Log opened.
2016-05-31 11:59:39+0200 [-] SSHFactory starting on 9999
2016-05-31 11:59:39+0200 [-] Starting factory <MockSSH.SSHFactory instance at 0x338dc68>
2016-05-31 12:00:01+0200 [-] New connection: 127.0.0.1:40963 (127.0.0.1:9999) [session: 0]
2016-05-31 12:00:01+0200 [-] Remote SSH version: SSH-2.0-OpenSSH_6.0p1 Debian-4+deb7u4
2016-05-31 12:00:01+0200 [SSHTransport,0,127.0.0.1] kex alg, key alg: diffie-hellman-group-exchange-sha256 ssh-rsa
2016-05-31 12:00:01+0200 [SSHTransport,0,127.0.0.1] outgoing: aes128-ctr hmac-md5 none
2016-05-31 12:00:01+0200 [SSHTransport,0,127.0.0.1] incoming: aes128-ctr hmac-md5 none
2016-05-31 12:00:01+0200 [SSHTransport,0,127.0.0.1] Unhandled Error
    Traceback (most recent call last):
      File "/tmp/mock_env/local/lib/python2.7/site-packages/Twisted-16.2.0-py2.7-linux-x86_64.egg/twisted/python/log.py", line 101, in callWithLogger
        return callWithContext({"system": lp}, func, *args, **kw)
      File "/tmp/mock_env/local/lib/python2.7/site-packages/Twisted-16.2.0-py2.7-linux-x86_64.egg/twisted/python/log.py", line 84, in callWithContext
        return context.call({ILogContext: newCtx}, func, *args, **kw)
      File "/tmp/mock_env/local/lib/python2.7/site-packages/Twisted-16.2.0-py2.7-linux-x86_64.egg/twisted/python/context.py", line 118, in callWithContext
        return self.currentContext().callWithContext(ctx, func, *args, **kw)
      File "/tmp/mock_env/local/lib/python2.7/site-packages/Twisted-16.2.0-py2.7-linux-x86_64.egg/twisted/python/context.py", line 81, in callWithContext
        return func(*args,**kw)
    --- <exception caught here> ---
      File "/tmp/mock_env/local/lib/python2.7/site-packages/Twisted-16.2.0-py2.7-linux-x86_64.egg/twisted/internet/posixbase.py", line 597, in _doReadOrWrite
        why = selectable.doRead()
      File "/tmp/mock_env/local/lib/python2.7/site-packages/Twisted-16.2.0-py2.7-linux-x86_64.egg/twisted/internet/tcp.py", line 209, in doRead
        return self._dataReceived(data)
      File "/tmp/mock_env/local/lib/python2.7/site-packages/Twisted-16.2.0-py2.7-linux-x86_64.egg/twisted/internet/tcp.py", line 215, in _dataReceived
        rval = self.protocol.dataReceived(data)
      File "build/bdist.linux-x86_64/egg/MockSSH.py", line 377, in dataReceived

      File "/tmp/mock_env/local/lib/python2.7/site-packages/Twisted-16.2.0-py2.7-linux-x86_64.egg/twisted/conch/ssh/transport.py", line 724, in dataReceived
        self.dispatchMessage(messageNum, packet[1:])
      File "/tmp/mock_env/local/lib/python2.7/site-packages/Twisted-16.2.0-py2.7-linux-x86_64.egg/twisted/conch/ssh/transport.py", line 742, in dispatchMessage
        f(payload)
      File "/tmp/mock_env/local/lib/python2.7/site-packages/Twisted-16.2.0-py2.7-linux-x86_64.egg/twisted/conch/ssh/transport.py", line 1329, in ssh_KEX_DH_GEX_REQUEST
        self.g, self.p = self.factory.getDHPrime(ideal)
      File "/tmp/mock_env/local/lib/python2.7/site-packages/Twisted-16.2.0-py2.7-linux-x86_64.egg/twisted/conch/ssh/factory.py", line 106, in getDHPrime
        primesKeys = self.primes.keys()
    exceptions.AttributeError: 'NoneType' object has no attribute 'keys'

2016-05-31 12:00:01+0200 [SSHTransport,0,127.0.0.1] connection lost
ncouture commented 8 years ago

The exception you are seeing is due to a bug (#13) in MockSSH. SSH keys are generated automatically, no instructions are necessary.

Please upgrade to 1.4.3 and continue to report issues on Github. Thank you!