I have some code that initiates a simple SSH client session using Libssh, but its failing at ssh_connect
int main()
{
ssh_session my_ssh_session;
int rc;
int port = 22;
const char* password;
int verbosity = SSH_LOG_FUNCTIONS;
// Open session and set options
my_ssh_session = ssh_new();
if (my_ssh_session == NULL)
exit(-1);
ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "10.10.10.100");
ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
ssh_options_set(my_ssh_session, SSH_OPTIONS_USER, "user");
ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
// Connect to server
rc = ssh_connect(my_ssh_session);
if (rc != SSH_OK)
{
fprintf(stderr, "Error connecting to localhost: %s\n",
ssh_get_error(my_ssh_session));
ssh_free(my_ssh_session);
exit(-99);
}
I have changed the verbosity on the logging, and it looks like it might be something to do with a PKI signature, but I am trying to authenticate using a username and password and I am not sure how to resolve.
[2022/09/23 05:27:38.440674, 2] ssh_packet_newkeys: Received SSH_MSG_NEWKEYS
[2022/09/23 05:27:38.440674, 4] ssh_pki_signature_verify: Going to verify a ssh-ed25519 type signature
[2022/09/23 05:27:38.440674, 4] pki_verify_data_signature: ED25519 error: Signature invalid
[2022/09/23 05:27:38.440674, 3] ssh_packet_socket_callback: Processing 276 bytes left in socket buffer
[2022/09/23 05:27:38.440674, 3] ssh_packet_socket_callback: Packet: processed 0 bytes
[2022/09/23 05:27:38.471928, 3] ssh_packet_socket_callback: Packet: processed 0 bytes
[2022/09/23 05:27:38.471928, 3] ssh_connect: current state : 9
I can connect to the SSH server using Putty with no issues.
Any help greatly appreciated
I have check the SSH logs and I can see the following:
sshd[22105]: debug1: rekey in after 134217728 blocks [preauth]
sshd[22105]: debug1: KEX done [preauth]
sshd[22105]: debug1: Connection closed by 10.10.10.1 port 49917 [preauth]
It very much looks like my program can't read the server host key file or that for some reason it doesn't like the format.
I have also tried changing to RSA, but to no avail.
I have also tried running ssh-keyscan on the client to verify a key is returned.
C:\Users\admin>ssh-keyscan 10.10.10.100
# 10.10.10.100:22 SSH-2.0-OpenSSH_8.4p1 Debian-5+deb11u1
# 10.10.10.100:22 SSH-2.0-OpenSSH_8.4p1 Debian-5+deb11u1
# 10.10.10.100:22 SSH-2.0-OpenSSH_8.4p1 Debian-5+deb11u1
10.10.10.100 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHMq2kcCJ/hfdkxoDORhh9BfiLZ3IbGGyQ0xgBXYRgVi
I build a Dropbear SSH box and it behaves exactly the same on there
If you build libssh
statically, you must call ssh_init()
early, and in a "main" context.
From the manual:
If libssh is statically linked, threading must be initialized by calling ssh_init() before using any of libssh provided functions. This initialization must be done outside of any threading context. Don't forget to call ssh_finalize() to avoid memory leak