0

我正在按照教程尝试使用 libssh 打开和验证 SSH 连接,但是在 ssh_connect 之后,无论我尝试密码验证、公钥验证还是无验证,应用程序都会因核心转储而崩溃。

      t@1 (l@1) program terminated by signal BUS (invalid address alignment)
      0xffffffff74cab0cc: CRYPTO_ctr128_encrypt+0x0124:       ldx      [%l5 + %i5], %o1
      [1] CRYPTO_ctr128_encrypt(0x100151320, 0x10014e5a0, 0x20, 0x10014f410, 0x10014e360, 0xffffffff7fffebdc), at 0xffffffff74cab0cc
      [2] AES_ctr128_encrypt(0x100151320, 0x10014e5a0, 0x20, 0x10014f410, 0xffffffff74c971c0, 0xffffffff7fffebdc), at 0xffffffff74c92908
      [3] aes_ctr128_encrypt(0x1001502a0, 0x100151320, 0x10014e5a0, 0xffffffff7fffebec, 0xffffffff72d00240, 0x0), at 0xffffffff7d42aa64
      [4] packet_encrypt(0x1001479f0, 0x100151320, 0x10014fab0, 0x1, 0x1001502a0, 0x20), at 0xffffffff7d43454c
      [5] packet_send2(0x1001479f0, 0x100151320, 0xffffffff7d462759, 0x125c00, 0x11, 0x11), at 0xffffffff7d433958
      [6] ssh_service_request(0x1001479f0, 0xffffffff7d482520, 0x100001440, 0x169bf8, 0x0, 0xffffffff7d4839a0), at 0xffffffff7d41eac0
      [7] ssh_userauth_request_service(0x1001479f0, 0xffffffffffef9ee0, 0x106000, 0xffffffff7d588640, 0x1751fc, 0xffffffff76e4f67c), at 0xffffffff7d413468
      [8] ssh_userauth_password(0x1001479f0, 0x1000017b6, 0x1000017cb, 0x31, 0xffffffff7fffefc0, 0xffffffff7d588640), at 0xffffffff7d414ce0
    =>[9] main(argc = 1, argv = 0xffffffff7ffff178), line 33 in "testSSH.cc"

我在 Solaris 10 上使用 C++ 的 libssh v.0.7.3。这是重现问题的代码:

#include <libssh/libssh.h> 
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
    ssh_session m_ssh_session;

    m_ssh_session = ssh_new();
    if (m_ssh_session == NULL) {
        cerr << "Failed to create SSH session : returned null" << endl;
        exit(1);
    }

    int port = 22;
    ssh_options_set(m_ssh_session, SSH_OPTIONS_HOST, "my_hostname");
    ssh_options_set(m_ssh_session, SSH_OPTIONS_PORT, &port);
    ssh_options_set(m_ssh_session, SSH_OPTIONS_USER, "my_username");

    int rc = ssh_connect(m_ssh_session);
    if (rc != SSH_OK) {
        cerr << "Failed to connect SSH session: (" << rc << ") " << ssh_get_error(m_ssh_session) << endl;
        exit(1);
    }

    int state = ssh_is_server_known(m_ssh_session);
    if (state != SSH_SERVER_KNOWN_OK) {
        cerr << "Server unknown (" << state << ")" << endl;
        exit(1);
    }

    rc = ssh_userauth_password(m_ssh_session, NULL, "my_password");
    if (rc == SSH_AUTH_ERROR) {
        cerr << "Authentication failed: (" << rc << ") " << ssh_get_error(m_ssh_session) << endl;
    }
}

我错过了什么吗?

4

2 回答 2

1

我有同样的问题。'libeay32.lib'原来我链接到的 OpenSSL 库ssh.dll不兼容并导致崩溃。验证 OpenSSL 文件'libeay32.lib''libay32.dll'使用。

于 2016-07-22T16:26:10.433 回答
0

在您编辑之后,我可以毫无问题地编译和运行您的代码。

我能做的唯一建议是让你改变:

if (rc == SSH_AUTH_ERROR) {
    cerr << "Authentication failed: (" << rc << ") " << ssh_get_error(m_ssh_session) << endl;
}

if (rc != SSH_AUTH_SUCCESS) {
    cerr << "Authentication failed: (" << rc << ") " << ssh_get_error(m_ssh_session) << endl;
}

ssh_free此外,您应该在最后调用:

ssh_free(ssh_session);
于 2016-06-30T14:19:25.010 回答