Skip to content

SSH Error: SSH startup: Unable to exchange encryption keys #26

@freeseacher

Description

@freeseacher

Hi!
i got that error with old mikrotik

> system routerboard print
       routerboard: yes
             model: "SXT 5HnD"
     serial-number: "292901552E3D"
  current-firmware: "2.32"
  upgrade-firmware: "2.32"

the code is

class SSHIOStream(IOStream):
    SSH_KEY_PREFIX = os.path.join("var", "etc", "ssh")

    def __init__(self, sock, cli, *args, **kwargs):
        super(SSHIOStream, self).__init__(sock, *args, **kwargs)
        self.cli = cli
        self.script = self.cli.script
        self.logger = cli.logger
        self.session = libssh2.Session()
        self.channel = None

    @tornado.gen.coroutine
    def startup(self):
        """
        SSH session startup
        """
        user = self.script.credentials["user"]
        self.logger.debug("Startup ssh session")
        try:
            self.session.set_trace(libssh2.LIBSSH2_TRACE_SOCKET | libssh2.LIBSSH2_TRACE_TRANS)
            self.session.session_method_pref(20,"diffie-hellman-group1-sha1")
            self.session.startup(self.socket)
            host_hash = self.session.hostkey_hash(2)  # SHA1
            self.logger.debug("Connected. Host fingerprint is %s",
                              host_hash.encode("hex"))
            auth_methods = self.session.userauth_list(user).split(",")
            self.logger.debug("Supported authentication methods: %s",
                              ", ".join(auth_methods))
            # Try to authenticate
            authenticated = False
            for method in auth_methods:
                ah = getattr(self, "auth_%s" % method, None)
                if ah:
                    authenticated |= ah()
                    if authenticated:
                        break
            if authenticated:
                self.logger.debug("User is authenticated")
            else:
                self.logger.error("Failed to authenticate user '%s'", user)
                raise self.cli.CLIError("Failed to log in")
            self.logger.debug("Open channel")
            self.channel = self.session.open_session()
            self.channel.pty("xterm")
            self.channel.shell()
            self.channel.setblocking(0)
        except _libssh2.Error, why:
            raise self.cli.CLIError("SSH Error: %s" % why)

i got error on

self.session.startup(self.socket)

because mikrotik wants old style packet. so in console i got
Protocol error: expected packet type 30, got 34

i am using python 2.7 and libssh2 from master branch and Debian 8.4

# dpkg -l | grep libssh2
ii  libssh2-1:amd64                1.4.3-4.1+deb8u1            amd64        SSH2 client-side library
ii  libssh2-1-dev:amd64            1.4.3-4.1+deb8u1            amd64        SSH2 client-side library (development headers)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions