pythonshellautomated-testshoneypottwisted.conch

Twisted Conch MockSSH: implement 'stty -echo'


I am attempting to set up a mock ssh shell server using MockSSH.

To test the particular application I'm dealing with, I need to be able to stop the shell from echoing input. The application always starts by issuing the 'stty -echo' command, so that stdout only contains output. EX:

user@host> echo "hello world"
hello world
user@host> stty -echo
user@host>
hello world
user@host>
I swear I just typed 'echo "hello world"'!

disabling echo by default, or when the 'stty -echo' command is issued would work equally well.


Solution

  • After a few days worth of work, I found a solution that will work for my purposes, Commenting out "self.termina.write(ch)" from the SSHProtocol implementation's characterReceived method totally disabled input printing, as if the 'stty -echo' command had been run in bash.

    class SSHProtocol(recvline.HistoricRecvLine):
        [...]
        def characterReceived(self, ch, moreCharactersComing):
            self.lineBuffer[self.lineBufferIndex:self.lineBufferIndex+1] = [ch]
            self.lineBufferIndex += 1
    
            #if not self.password_input:
            #    self.terminal.write(ch)
    

    this works for my purposes, I'm sure you could easily set a flag in your SSH protocol to enable/disable input printing.

    what I've learned is that the recvline.HistoricRecvLine.characterRecieved() method handles input text from the terminal, and terminal.write() is used to print to STDOUT.