|
|
105fd7 |
From 95924615ab42529e4dc7b95da1115346bf607fc6 Mon Sep 17 00:00:00 2001
|
|
|
105fd7 |
From: Jeremy Lin <jjlin@cs.stanford.edu>
|
|
|
105fd7 |
Date: Mon, 15 Sep 2014 21:16:46 -0700
|
|
|
105fd7 |
Subject: [PATCH 1/2] ssh: improve key file search
|
|
|
105fd7 |
|
|
|
105fd7 |
For private keys, use the first match from: user-specified key file
|
|
|
105fd7 |
(if provided), ~/.ssh/id_rsa, ~/.ssh/id_dsa, ./id_rsa, ./id_dsa
|
|
|
105fd7 |
|
|
|
105fd7 |
Note that the previous code only looked for id_dsa files. id_rsa is
|
|
|
105fd7 |
now generally preferred, as it supports larger key sizes.
|
|
|
105fd7 |
|
|
|
105fd7 |
For public keys, use the user-specified key file, if provided.
|
|
|
105fd7 |
Otherwise, try to extract the public key from the private key file.
|
|
|
105fd7 |
This means that passing --pubkey is typically no longer required,
|
|
|
105fd7 |
and makes the key-handling behavior more like OpenSSH.
|
|
|
105fd7 |
|
|
|
105fd7 |
Upstream-commit: fa7d04fed4d4578fe29bdff0b5465f6e4a7da81a
|
|
|
105fd7 |
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
|
|
|
105fd7 |
---
|
|
|
105fd7 |
docs/MANUAL | 26 ++++++++++++++-------
|
|
|
105fd7 |
docs/curl.1 | 8 ++++++-
|
|
|
105fd7 |
lib/ssh.c | 75 +++++++++++++++++++++++++++++++++++++++----------------------
|
|
|
105fd7 |
3 files changed, 73 insertions(+), 36 deletions(-)
|
|
|
105fd7 |
|
|
|
105fd7 |
diff --git a/docs/MANUAL b/docs/MANUAL
|
|
|
105fd7 |
index 4ad2e13..3f8d9b8 100644
|
|
|
105fd7 |
--- a/docs/MANUAL
|
|
|
105fd7 |
+++ b/docs/MANUAL
|
|
|
105fd7 |
@@ -41,12 +41,19 @@ SIMPLE USAGE
|
|
|
105fd7 |
|
|
|
105fd7 |
Get a file from an SSH server using SFTP:
|
|
|
105fd7 |
|
|
|
105fd7 |
- curl -u username sftp://shell.example.com/etc/issue
|
|
|
105fd7 |
+ curl -u username sftp://example.com/etc/issue
|
|
|
105fd7 |
|
|
|
105fd7 |
- Get a file from an SSH server using SCP using a private key to authenticate:
|
|
|
105fd7 |
+ Get a file from an SSH server using SCP using a private key
|
|
|
105fd7 |
+ (not password-protected) to authenticate:
|
|
|
105fd7 |
|
|
|
105fd7 |
- curl -u username: --key ~/.ssh/id_dsa --pubkey ~/.ssh/id_dsa.pub \
|
|
|
105fd7 |
- scp://shell.example.com/~/personal.txt
|
|
|
105fd7 |
+ curl -u username: --key ~/.ssh/id_rsa \
|
|
|
105fd7 |
+ scp://example.com/~/file.txt
|
|
|
105fd7 |
+
|
|
|
105fd7 |
+ Get a file from an SSH server using SCP using a private key
|
|
|
105fd7 |
+ (password-protected) to authenticate:
|
|
|
105fd7 |
+
|
|
|
105fd7 |
+ curl -u username: --key ~/.ssh/id_rsa --pass private_key_password \
|
|
|
105fd7 |
+ scp://example.com/~/file.txt
|
|
|
105fd7 |
|
|
|
105fd7 |
Get the main page from an IPv6 web server:
|
|
|
105fd7 |
|
|
|
105fd7 |
@@ -91,10 +98,13 @@ USING PASSWORDS
|
|
|
105fd7 |
|
|
|
105fd7 |
SFTP / SCP
|
|
|
105fd7 |
|
|
|
105fd7 |
- This is similar to FTP, but you can specify a private key to use instead of
|
|
|
105fd7 |
- a password. Note that the private key may itself be protected by a password
|
|
|
105fd7 |
- that is unrelated to the login password of the remote system. If you
|
|
|
105fd7 |
- provide a private key file you must also provide a public key file.
|
|
|
105fd7 |
+ This is similar to FTP, but you can use the --key option to specify a
|
|
|
105fd7 |
+ private key to use instead of a password. Note that the private key may
|
|
|
105fd7 |
+ itself be protected by a password that is unrelated to the login password
|
|
|
105fd7 |
+ of the remote system; this password is specified using the --pass option.
|
|
|
105fd7 |
+ Typically, curl will automatically extract the public key from the private
|
|
|
105fd7 |
+ key file, but in cases where curl does not have the proper library support,
|
|
|
105fd7 |
+ a matching public key file must be specified using the --pubkey option.
|
|
|
105fd7 |
|
|
|
105fd7 |
HTTP
|
|
|
105fd7 |
|
|
|
105fd7 |
diff --git a/docs/curl.1 b/docs/curl.1
|
|
|
105fd7 |
index 38fa084..d1675a0 100644
|
|
|
105fd7 |
--- a/docs/curl.1
|
|
|
105fd7 |
+++ b/docs/curl.1
|
|
|
105fd7 |
@@ -724,7 +724,8 @@ If this option is used several times, the last one will be used. If
|
|
|
105fd7 |
unspecified, the option defaults to 60 seconds.
|
|
|
105fd7 |
.IP "--key <key>"
|
|
|
105fd7 |
(SSL/SSH) Private key file name. Allows you to provide your private key in this
|
|
|
105fd7 |
-separate file.
|
|
|
105fd7 |
+separate file. For SSH, if not specified, curl tries the following candidates
|
|
|
105fd7 |
+in order: '~/.ssh/id_rsa', '~/.ssh/id_dsa', './id_rsa', './id_dsa'.
|
|
|
105fd7 |
|
|
|
105fd7 |
If this option is used several times, the last one will be used.
|
|
|
105fd7 |
.IP "--key-type <type>"
|
|
|
105fd7 |
@@ -1124,6 +1125,11 @@ protocol instead of the default HTTP 1.1.
|
|
|
105fd7 |
separate file.
|
|
|
105fd7 |
|
|
|
105fd7 |
If this option is used several times, the last one will be used.
|
|
|
105fd7 |
+
|
|
|
105fd7 |
+(As of 7.39.0, curl attempts to automatically extract the public key from the
|
|
|
105fd7 |
+private key file, so passing this option is generally not required. Note that
|
|
|
105fd7 |
+this public key extraction requires libcurl to be linked against a copy of
|
|
|
105fd7 |
+libssh2 1.2.8 or higher that is itself linked against OpenSSL.)
|
|
|
105fd7 |
.IP "-q"
|
|
|
105fd7 |
If used as the first parameter on the command line, the \fIcurlrc\fP config
|
|
|
105fd7 |
file will not be read and used. See the \fI-K, --config\fP for details on the
|
|
|
105fd7 |
diff --git a/lib/ssh.c b/lib/ssh.c
|
|
|
105fd7 |
index 43e3342..4ea7d9b 100644
|
|
|
105fd7 |
--- a/lib/ssh.c
|
|
|
105fd7 |
+++ b/lib/ssh.c
|
|
|
105fd7 |
@@ -780,7 +780,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
|
|
|
105fd7 |
if((data->set.ssh_auth_types & CURLSSH_AUTH_PUBLICKEY) &&
|
|
|
105fd7 |
(strstr(sshc->authlist, "publickey") != NULL)) {
|
|
|
105fd7 |
char *home = NULL;
|
|
|
105fd7 |
- bool rsa_pub_empty_but_ok = FALSE;
|
|
|
105fd7 |
+ bool out_of_memory = FALSE;
|
|
|
105fd7 |
|
|
|
105fd7 |
sshc->rsa_pub = sshc->rsa = NULL;
|
|
|
105fd7 |
|
|
|
105fd7 |
@@ -788,34 +788,55 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
|
|
|
105fd7 |
HOME environment variable etc? */
|
|
|
105fd7 |
home = curl_getenv("HOME");
|
|
|
105fd7 |
|
|
|
105fd7 |
- if(data->set.str[STRING_SSH_PUBLIC_KEY] &&
|
|
|
105fd7 |
- !*data->set.str[STRING_SSH_PUBLIC_KEY])
|
|
|
105fd7 |
- rsa_pub_empty_but_ok = true;
|
|
|
105fd7 |
- else if(data->set.str[STRING_SSH_PUBLIC_KEY])
|
|
|
105fd7 |
- sshc->rsa_pub = aprintf("%s", data->set.str[STRING_SSH_PUBLIC_KEY]);
|
|
|
105fd7 |
- else if(home)
|
|
|
105fd7 |
- sshc->rsa_pub = aprintf("%s/.ssh/id_dsa.pub", home);
|
|
|
105fd7 |
- else
|
|
|
105fd7 |
- /* as a final resort, try current dir! */
|
|
|
105fd7 |
- sshc->rsa_pub = strdup("id_dsa.pub");
|
|
|
105fd7 |
-
|
|
|
105fd7 |
- if(!rsa_pub_empty_but_ok && (sshc->rsa_pub == NULL)) {
|
|
|
105fd7 |
- Curl_safefree(home);
|
|
|
105fd7 |
- state(conn, SSH_SESSION_FREE);
|
|
|
105fd7 |
- sshc->actualcode = CURLE_OUT_OF_MEMORY;
|
|
|
105fd7 |
- break;
|
|
|
105fd7 |
+ if(data->set.str[STRING_SSH_PRIVATE_KEY])
|
|
|
105fd7 |
+ sshc->rsa = strdup(data->set.str[STRING_SSH_PRIVATE_KEY]);
|
|
|
105fd7 |
+ else {
|
|
|
105fd7 |
+ /* If no private key file is specified, try some common paths. */
|
|
|
105fd7 |
+ if(home) {
|
|
|
105fd7 |
+ /* Try ~/.ssh first. */
|
|
|
105fd7 |
+ sshc->rsa = aprintf("%s/.ssh/id_rsa", home);
|
|
|
105fd7 |
+ if(!sshc->rsa)
|
|
|
105fd7 |
+ out_of_memory = TRUE;
|
|
|
105fd7 |
+ else if(access(sshc->rsa, R_OK) != 0) {
|
|
|
105fd7 |
+ Curl_safefree(sshc->rsa);
|
|
|
105fd7 |
+ sshc->rsa = aprintf("%s/.ssh/id_dsa", home);
|
|
|
105fd7 |
+ if(!sshc->rsa)
|
|
|
105fd7 |
+ out_of_memory = TRUE;
|
|
|
105fd7 |
+ else if(access(sshc->rsa, R_OK) != 0) {
|
|
|
105fd7 |
+ Curl_safefree(sshc->rsa);
|
|
|
105fd7 |
+ }
|
|
|
105fd7 |
+ }
|
|
|
105fd7 |
+ }
|
|
|
105fd7 |
+ if(!out_of_memory && !sshc->rsa) {
|
|
|
105fd7 |
+ /* Nothing found; try the current dir. */
|
|
|
105fd7 |
+ sshc->rsa = strdup("id_rsa");
|
|
|
105fd7 |
+ if(sshc->rsa && access(sshc->rsa, R_OK) != 0) {
|
|
|
105fd7 |
+ Curl_safefree(sshc->rsa);
|
|
|
105fd7 |
+ sshc->rsa = strdup("id_dsa");
|
|
|
105fd7 |
+ if(sshc->rsa && access(sshc->rsa, R_OK) != 0) {
|
|
|
105fd7 |
+ Curl_safefree(sshc->rsa);
|
|
|
105fd7 |
+ /* Out of guesses. Set to the empty string to avoid
|
|
|
105fd7 |
+ * surprising info messages. */
|
|
|
105fd7 |
+ sshc->rsa = strdup("");
|
|
|
105fd7 |
+ }
|
|
|
105fd7 |
+ }
|
|
|
105fd7 |
+ }
|
|
|
105fd7 |
}
|
|
|
105fd7 |
|
|
|
105fd7 |
- if(data->set.str[STRING_SSH_PRIVATE_KEY])
|
|
|
105fd7 |
- sshc->rsa = aprintf("%s", data->set.str[STRING_SSH_PRIVATE_KEY]);
|
|
|
105fd7 |
- else if(home)
|
|
|
105fd7 |
- sshc->rsa = aprintf("%s/.ssh/id_dsa", home);
|
|
|
105fd7 |
- else
|
|
|
105fd7 |
- /* as a final resort, try current dir! */
|
|
|
105fd7 |
- sshc->rsa = strdup("id_dsa");
|
|
|
105fd7 |
+ /*
|
|
|
105fd7 |
+ * Unless the user explicitly specifies a public key file, let
|
|
|
105fd7 |
+ * libssh2 extract the public key from the private key file.
|
|
|
105fd7 |
+ * This is done by simply passing sshc->rsa_pub = NULL.
|
|
|
105fd7 |
+ */
|
|
|
105fd7 |
+ if(data->set.str[STRING_SSH_PUBLIC_KEY]) {
|
|
|
105fd7 |
+ sshc->rsa_pub = strdup(data->set.str[STRING_SSH_PUBLIC_KEY]);
|
|
|
105fd7 |
+ if(!sshc->rsa_pub)
|
|
|
105fd7 |
+ out_of_memory = TRUE;
|
|
|
105fd7 |
+ }
|
|
|
105fd7 |
|
|
|
105fd7 |
- if(sshc->rsa == NULL) {
|
|
|
105fd7 |
+ if(out_of_memory || sshc->rsa == NULL) {
|
|
|
105fd7 |
Curl_safefree(home);
|
|
|
105fd7 |
+ Curl_safefree(sshc->rsa);
|
|
|
105fd7 |
Curl_safefree(sshc->rsa_pub);
|
|
|
105fd7 |
state(conn, SSH_SESSION_FREE);
|
|
|
105fd7 |
sshc->actualcode = CURLE_OUT_OF_MEMORY;
|
|
|
105fd7 |
@@ -828,8 +849,8 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
|
|
|
105fd7 |
|
|
|
105fd7 |
Curl_safefree(home);
|
|
|
105fd7 |
|
|
|
105fd7 |
- infof(data, "Using ssh public key file %s\n", sshc->rsa_pub);
|
|
|
105fd7 |
- infof(data, "Using ssh private key file %s\n", sshc->rsa);
|
|
|
105fd7 |
+ infof(data, "Using SSH public key file '%s'\n", sshc->rsa_pub);
|
|
|
105fd7 |
+ infof(data, "Using SSH private key file '%s'\n", sshc->rsa);
|
|
|
105fd7 |
|
|
|
105fd7 |
state(conn, SSH_AUTH_PKEY);
|
|
|
105fd7 |
}
|
|
|
105fd7 |
--
|
|
|
105fd7 |
2.5.2
|
|
|
105fd7 |
|
|
|
105fd7 |
|
|
|
105fd7 |
From 2e18c6a12fc5dbab278670f22e58fcce51d32cac Mon Sep 17 00:00:00 2001
|
|
|
105fd7 |
From: Kamil Dudka <kdudka@redhat.com>
|
|
|
105fd7 |
Date: Fri, 15 Jan 2016 10:27:33 +0100
|
|
|
105fd7 |
Subject: [PATCH 2/2] ssh: make CURLOPT_SSH_PUBLIC_KEYFILE treat "" as NULL
|
|
|
105fd7 |
|
|
|
105fd7 |
The CURLOPT_SSH_PUBLIC_KEYFILE option has been documented to handle
|
|
|
105fd7 |
empty strings specially since curl-7_25_0-31-g05a443a but the behavior
|
|
|
105fd7 |
was unintentionally removed in curl-7_38_0-47-gfa7d04f.
|
|
|
105fd7 |
|
|
|
105fd7 |
This commit restores the original behavior and clarifies it in the
|
|
|
105fd7 |
documentation that NULL and "" have both the same meaning when passed
|
|
|
105fd7 |
to CURLOPT_SSH_PUBLIC_KEYFILE.
|
|
|
105fd7 |
|
|
|
105fd7 |
Bug: http://curl.haxx.se/mail/lib-2016-01/0072.html
|
|
|
105fd7 |
|
|
|
105fd7 |
Upstream-commit: be538e07667e1ba880b7201014be706851428d40
|
|
|
105fd7 |
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
|
|
|
105fd7 |
---
|
|
|
105fd7 |
docs/libcurl/curl_easy_setopt.3 | 6 +++---
|
|
|
105fd7 |
lib/ssh.c | 7 +++++--
|
|
|
105fd7 |
2 files changed, 8 insertions(+), 5 deletions(-)
|
|
|
105fd7 |
|
|
|
105fd7 |
diff --git a/docs/libcurl/curl_easy_setopt.3 b/docs/libcurl/curl_easy_setopt.3
|
|
|
105fd7 |
index ad739e1..0a9375e 100644
|
|
|
105fd7 |
--- a/docs/libcurl/curl_easy_setopt.3
|
|
|
105fd7 |
+++ b/docs/libcurl/curl_easy_setopt.3
|
|
|
105fd7 |
@@ -2446,9 +2446,9 @@ Pass a char * pointing to a file name for your public key. If not used,
|
|
|
105fd7 |
libcurl defaults to \fB$HOME/.ssh/id_dsa.pub\fP if the HOME environment
|
|
|
105fd7 |
variable is set, and just "id_dsa.pub" in the current directory if HOME is not
|
|
|
105fd7 |
set. (Added in 7.16.1)
|
|
|
105fd7 |
-If an empty string is passed, libcurl will pass no public key to libssh2
|
|
|
105fd7 |
-which then tries to compute it from the private key, this is known to work
|
|
|
105fd7 |
-when libssh2 1.4.0+ is linked against OpenSSL. (Added in 7.26.0)
|
|
|
105fd7 |
+If NULL (or an empty string) is passed, libcurl will pass no public key to
|
|
|
105fd7 |
+libssh2, which then tries to compute it from the private key. This is known
|
|
|
105fd7 |
+to work with libssh2 1.4.0+ linked against OpenSSL. (Added in 7.26.0)
|
|
|
105fd7 |
.IP CURLOPT_SSH_PRIVATE_KEYFILE
|
|
|
105fd7 |
Pass a char * pointing to a file name for your private key. If not used,
|
|
|
105fd7 |
libcurl defaults to \fB$HOME/.ssh/id_dsa\fP if the HOME environment variable
|
|
|
105fd7 |
diff --git a/lib/ssh.c b/lib/ssh.c
|
|
|
105fd7 |
index 4ea7d9b..589d4a3 100644
|
|
|
105fd7 |
--- a/lib/ssh.c
|
|
|
105fd7 |
+++ b/lib/ssh.c
|
|
|
105fd7 |
@@ -828,7 +828,9 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
|
|
|
105fd7 |
* libssh2 extract the public key from the private key file.
|
|
|
105fd7 |
* This is done by simply passing sshc->rsa_pub = NULL.
|
|
|
105fd7 |
*/
|
|
|
105fd7 |
- if(data->set.str[STRING_SSH_PUBLIC_KEY]) {
|
|
|
105fd7 |
+ if(data->set.str[STRING_SSH_PUBLIC_KEY]
|
|
|
105fd7 |
+ /* treat empty string the same way as NULL */
|
|
|
105fd7 |
+ && data->set.str[STRING_SSH_PUBLIC_KEY][0]) {
|
|
|
105fd7 |
sshc->rsa_pub = strdup(data->set.str[STRING_SSH_PUBLIC_KEY]);
|
|
|
105fd7 |
if(!sshc->rsa_pub)
|
|
|
105fd7 |
out_of_memory = TRUE;
|
|
|
105fd7 |
@@ -849,7 +851,8 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
|
|
|
105fd7 |
|
|
|
105fd7 |
Curl_safefree(home);
|
|
|
105fd7 |
|
|
|
105fd7 |
- infof(data, "Using SSH public key file '%s'\n", sshc->rsa_pub);
|
|
|
105fd7 |
+ if(sshc->rsa_pub)
|
|
|
105fd7 |
+ infof(data, "Using SSH public key file '%s'\n", sshc->rsa_pub);
|
|
|
105fd7 |
infof(data, "Using SSH private key file '%s'\n", sshc->rsa);
|
|
|
105fd7 |
|
|
|
105fd7 |
state(conn, SSH_AUTH_PKEY);
|
|
|
105fd7 |
--
|
|
|
105fd7 |
2.5.0
|
|
|
105fd7 |
|