summaryrefslogtreecommitdiffstats
path: root/Utilities/cmcurl/lib/vssh/libssh.c
diff options
context:
space:
mode:
Diffstat (limited to 'Utilities/cmcurl/lib/vssh/libssh.c')
-rw-r--r--Utilities/cmcurl/lib/vssh/libssh.c89
1 files changed, 72 insertions, 17 deletions
diff --git a/Utilities/cmcurl/lib/vssh/libssh.c b/Utilities/cmcurl/lib/vssh/libssh.c
index 647b4d4..8988e23 100644
--- a/Utilities/cmcurl/lib/vssh/libssh.c
+++ b/Utilities/cmcurl/lib/vssh/libssh.c
@@ -345,13 +345,27 @@ static int myssh_is_known(struct connectdata *conn)
return rc;
if(data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5]) {
+ int i;
+ char md5buffer[33];
+ const char *pubkey_md5 = data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5];
+
rc = ssh_get_publickey_hash(pubkey, SSH_PUBLICKEY_HASH_MD5,
&hash, &hlen);
- if(rc != SSH_OK)
+ if(rc != SSH_OK || hlen != 16) {
+ failf(data,
+ "Denied establishing ssh session: md5 fingerprint not available");
goto cleanup;
+ }
+
+ for(i = 0; i < 16; i++)
+ msnprintf(&md5buffer[i*2], 3, "%02x", (unsigned char)hash[i]);
- if(hlen != strlen(data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5]) ||
- memcmp(&data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5], hash, hlen)) {
+ infof(data, "SSH MD5 fingerprint: %s\n", md5buffer);
+
+ if(!strcasecompare(md5buffer, pubkey_md5)) {
+ failf(data,
+ "Denied establishing ssh session: mismatch md5 fingerprint. "
+ "Remote %s is not equal to %s", md5buffer, pubkey_md5);
rc = SSH_ERROR;
goto cleanup;
}
@@ -389,6 +403,9 @@ static int myssh_is_known(struct connectdata *conn)
knownkey.keytype = CURLKHTYPE_RSA1;
break;
case SSH_KEYTYPE_ECDSA:
+ case SSH_KEYTYPE_ECDSA_P256:
+ case SSH_KEYTYPE_ECDSA_P384:
+ case SSH_KEYTYPE_ECDSA_P521:
knownkey.keytype = CURLKHTYPE_ECDSA;
break;
case SSH_KEYTYPE_ED25519:
@@ -456,6 +473,11 @@ static int myssh_is_known(struct connectdata *conn)
foundkey.keytype = CURLKHTYPE_RSA1;
break;
case SSH_KEYTYPE_ECDSA:
+#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0,9,0)
+ case SSH_KEYTYPE_ECDSA_P256:
+ case SSH_KEYTYPE_ECDSA_P384:
+ case SSH_KEYTYPE_ECDSA_P521:
+#endif
foundkey.keytype = CURLKHTYPE_ECDSA;
break;
#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0,7,0)
@@ -2127,6 +2149,7 @@ static CURLcode myssh_connect(struct connectdata *conn, bool *done)
CURLcode result;
curl_socket_t sock = conn->sock[FIRSTSOCKET];
struct Curl_easy *data = conn->data;
+ int rc;
/* initialize per-handle data if not already */
if(!data->req.protop)
@@ -2153,38 +2176,70 @@ static CURLcode myssh_connect(struct connectdata *conn, bool *done)
return CURLE_FAILED_INIT;
}
- ssh_options_set(ssh->ssh_session, SSH_OPTIONS_FD, &sock);
+ rc = ssh_options_set(ssh->ssh_session, SSH_OPTIONS_HOST, conn->host.name);
+ if(rc != SSH_OK) {
+ failf(data, "Could not set remote host");
+ return CURLE_FAILED_INIT;
+ }
+
+ rc = ssh_options_parse_config(ssh->ssh_session, NULL);
+ if(rc != SSH_OK) {
+ infof(data, "Could not parse SSH configuration files");
+ /* ignore */
+ }
- if(conn->user) {
+ rc = ssh_options_set(ssh->ssh_session, SSH_OPTIONS_FD, &sock);
+ if(rc != SSH_OK) {
+ failf(data, "Could not set socket");
+ return CURLE_FAILED_INIT;
+ }
+
+ if(conn->user && conn->user[0] != '\0') {
infof(data, "User: %s\n", conn->user);
- ssh_options_set(ssh->ssh_session, SSH_OPTIONS_USER, conn->user);
+ rc = ssh_options_set(ssh->ssh_session, SSH_OPTIONS_USER, conn->user);
+ if(rc != SSH_OK) {
+ failf(data, "Could not set user");
+ return CURLE_FAILED_INIT;
+ }
}
if(data->set.str[STRING_SSH_KNOWNHOSTS]) {
infof(data, "Known hosts: %s\n", data->set.str[STRING_SSH_KNOWNHOSTS]);
- ssh_options_set(ssh->ssh_session, SSH_OPTIONS_KNOWNHOSTS,
- data->set.str[STRING_SSH_KNOWNHOSTS]);
+ rc = ssh_options_set(ssh->ssh_session, SSH_OPTIONS_KNOWNHOSTS,
+ data->set.str[STRING_SSH_KNOWNHOSTS]);
+ if(rc != SSH_OK) {
+ failf(data, "Could not set known hosts file path");
+ return CURLE_FAILED_INIT;
+ }
}
- ssh_options_set(ssh->ssh_session, SSH_OPTIONS_HOST, conn->host.name);
- if(conn->remote_port)
- ssh_options_set(ssh->ssh_session, SSH_OPTIONS_PORT,
- &conn->remote_port);
+ if(conn->remote_port) {
+ rc = ssh_options_set(ssh->ssh_session, SSH_OPTIONS_PORT,
+ &conn->remote_port);
+ if(rc != SSH_OK) {
+ failf(data, "Could not set remote port");
+ return CURLE_FAILED_INIT;
+ }
+ }
if(data->set.ssh_compression) {
- ssh_options_set(ssh->ssh_session, SSH_OPTIONS_COMPRESSION,
- "zlib,zlib@openssh.com,none");
+ rc = ssh_options_set(ssh->ssh_session, SSH_OPTIONS_COMPRESSION,
+ "zlib,zlib@openssh.com,none");
+ if(rc != SSH_OK) {
+ failf(data, "Could not set compression");
+ return CURLE_FAILED_INIT;
+ }
}
ssh->privkey = NULL;
ssh->pubkey = NULL;
if(data->set.str[STRING_SSH_PUBLIC_KEY]) {
- int rc = ssh_pki_import_pubkey_file(data->set.str[STRING_SSH_PUBLIC_KEY],
- &ssh->pubkey);
+ rc = ssh_pki_import_pubkey_file(data->set.str[STRING_SSH_PUBLIC_KEY],
+ &ssh->pubkey);
if(rc != SSH_OK) {
failf(data, "Could not load public key file");
- /* ignore */
+ return CURLE_FAILED_INIT;
}
}