9d7d3f
From 5285b2518773185c049b0c2af980654a0b1c6871 Mon Sep 17 00:00:00 2001
9d7d3f
From: Kamil Dudka <kdudka@redhat.com>
9d7d3f
Date: Wed, 8 Mar 2017 12:21:09 +0100
9d7d3f
Subject: [PATCH 1/4] socks: use proxy_user instead of proxy_name
9d7d3f
9d7d3f
... to make it obvious what the data is used for
9d7d3f
9d7d3f
Upstream-commit: 641072b919b1a52c58664cd18619f8dd1c4c0cee
9d7d3f
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
9d7d3f
---
9d7d3f
 lib/socks.c | 30 +++++++++++++++---------------
9d7d3f
 1 file changed, 15 insertions(+), 15 deletions(-)
9d7d3f
9d7d3f
diff --git a/lib/socks.c b/lib/socks.c
9d7d3f
index 0cf397c..9aac9ca 100644
9d7d3f
--- a/lib/socks.c
9d7d3f
+++ b/lib/socks.c
9d7d3f
@@ -106,7 +106,7 @@ int Curl_blockread_all(struct connectdata *conn, /* connection data */
9d7d3f
 *   Set protocol4a=true for  "SOCKS 4A (Simple Extension to SOCKS 4 Protocol)"
9d7d3f
 *   Nonsupport "Identification Protocol (RFC1413)"
9d7d3f
 */
9d7d3f
-CURLcode Curl_SOCKS4(const char *proxy_name,
9d7d3f
+CURLcode Curl_SOCKS4(const char *proxy_user,
9d7d3f
                      const char *hostname,
9d7d3f
                      int remote_port,
9d7d3f
                      int sockindex,
9d7d3f
@@ -200,8 +200,8 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
9d7d3f
    * This is currently not supporting "Identification Protocol (RFC1413)".
9d7d3f
    */
9d7d3f
   socksreq[8] = 0; /* ensure empty userid is NUL-terminated */
9d7d3f
-  if(proxy_name)
9d7d3f
-    strlcat((char*)socksreq + 8, proxy_name, sizeof(socksreq) - 8);
9d7d3f
+  if(proxy_user)
9d7d3f
+    strlcat((char*)socksreq + 8, proxy_user, sizeof(socksreq) - 8);
9d7d3f
 
9d7d3f
   /*
9d7d3f
    * Make connection
9d7d3f
@@ -337,7 +337,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
9d7d3f
  * This function logs in to a SOCKS5 proxy and sends the specifics to the final
9d7d3f
  * destination server.
9d7d3f
  */
9d7d3f
-CURLcode Curl_SOCKS5(const char *proxy_name,
9d7d3f
+CURLcode Curl_SOCKS5(const char *proxy_user,
9d7d3f
                      const char *proxy_password,
9d7d3f
                      const char *hostname,
9d7d3f
                      int remote_port,
9d7d3f
@@ -410,12 +410,12 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
9d7d3f
 
9d7d3f
   socksreq[0] = 5; /* version */
9d7d3f
 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
9d7d3f
-  socksreq[1] = (char)(proxy_name ? 3 : 2); /* number of methods (below) */
9d7d3f
+  socksreq[1] = (char)(proxy_user ? 3 : 2); /* number of methods (below) */
9d7d3f
   socksreq[2] = 0; /* no authentication */
9d7d3f
   socksreq[3] = 1; /* gssapi */
9d7d3f
   socksreq[4] = 2; /* username/password */
9d7d3f
 #else
9d7d3f
-  socksreq[1] = (char)(proxy_name ? 2 : 1); /* number of methods (below) */
9d7d3f
+  socksreq[1] = (char)(proxy_user ? 2 : 1); /* number of methods (below) */
9d7d3f
   socksreq[2] = 0; /* no authentication */
9d7d3f
   socksreq[3] = 2; /* username/password */
9d7d3f
 #endif
9d7d3f
@@ -474,13 +474,13 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
9d7d3f
 #endif
9d7d3f
   else if(socksreq[1] == 2) {
9d7d3f
     /* Needs user name and password */
9d7d3f
-    size_t proxy_name_len, proxy_password_len;
9d7d3f
-    if(proxy_name && proxy_password) {
9d7d3f
-      proxy_name_len = strlen(proxy_name);
9d7d3f
+    size_t proxy_user_len, proxy_password_len;
9d7d3f
+    if(proxy_user && proxy_password) {
9d7d3f
+      proxy_user_len = strlen(proxy_user);
9d7d3f
       proxy_password_len = strlen(proxy_password);
9d7d3f
     }
9d7d3f
     else {
9d7d3f
-      proxy_name_len = 0;
9d7d3f
+      proxy_user_len = 0;
9d7d3f
       proxy_password_len = 0;
9d7d3f
     }
9d7d3f
 
9d7d3f
@@ -493,10 +493,10 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
9d7d3f
      */
9d7d3f
     len = 0;
9d7d3f
     socksreq[len++] = 1;    /* username/pw subnegotiation version */
9d7d3f
-    socksreq[len++] = (unsigned char) proxy_name_len;
9d7d3f
-    if(proxy_name && proxy_name_len)
9d7d3f
-      memcpy(socksreq + len, proxy_name, proxy_name_len);
9d7d3f
-    len += proxy_name_len;
9d7d3f
+    socksreq[len++] = (unsigned char) proxy_user_len;
9d7d3f
+    if(proxy_user && proxy_user_len)
9d7d3f
+      memcpy(socksreq + len, proxy_user, proxy_user_len);
9d7d3f
+    len += proxy_user_len;
9d7d3f
     socksreq[len++] = (unsigned char) proxy_password_len;
9d7d3f
     if(proxy_password && proxy_password_len)
9d7d3f
       memcpy(socksreq + len, proxy_password, proxy_password_len);
9d7d3f
@@ -535,7 +535,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
9d7d3f
     }
9d7d3f
     else if(socksreq[1] == 255) {
9d7d3f
 #endif
9d7d3f
-      if(!proxy_name || !*proxy_name) {
9d7d3f
+      if(!proxy_user || !*proxy_user) {
9d7d3f
         failf(data,
9d7d3f
               "No authentication method was acceptable. (It is quite likely"
9d7d3f
               " that the SOCKS5 server wanted a username/password, since none"
9d7d3f
-- 
9d7d3f
2.13.5
9d7d3f
9d7d3f
9d7d3f
From 3676c3fab628e848270e2169398f912a1449c31b Mon Sep 17 00:00:00 2001
9d7d3f
From: Kamil Dudka <kdudka@redhat.com>
9d7d3f
Date: Wed, 8 Mar 2017 12:16:01 +0100
9d7d3f
Subject: [PATCH 2/4] socks: deduplicate the code for auth request
9d7d3f
9d7d3f
Upstream-commit: cd1c9f08078d4a8566ed10f6df9ae9a729f3290b
9d7d3f
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
9d7d3f
---
9d7d3f
 lib/socks.c | 19 ++++++++++---------
9d7d3f
 1 file changed, 10 insertions(+), 9 deletions(-)
9d7d3f
9d7d3f
diff --git a/lib/socks.c b/lib/socks.c
9d7d3f
index 9aac9ca..398e0ac 100644
9d7d3f
--- a/lib/socks.c
9d7d3f
+++ b/lib/socks.c
9d7d3f
@@ -362,6 +362,7 @@ CURLcode Curl_SOCKS5(const char *proxy_user,
9d7d3f
   */
9d7d3f
 
9d7d3f
   unsigned char socksreq[600]; /* room for large user/pw (255 max each) */
9d7d3f
+  int idx;
9d7d3f
   ssize_t actualread;
9d7d3f
   ssize_t written;
9d7d3f
   int result;
9d7d3f
@@ -408,17 +409,17 @@ CURLcode Curl_SOCKS5(const char *proxy_user,
9d7d3f
     return CURLE_COULDNT_CONNECT;
9d7d3f
   }
9d7d3f
 
9d7d3f
-  socksreq[0] = 5; /* version */
9d7d3f
+  idx = 0;
9d7d3f
+  socksreq[idx++] = 5;   /* version */
9d7d3f
+  idx++;                 /* reserve for the number of authentication methods */
9d7d3f
+  socksreq[idx++] = 0;   /* no authentication */
9d7d3f
 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
9d7d3f
-  socksreq[1] = (char)(proxy_user ? 3 : 2); /* number of methods (below) */
9d7d3f
-  socksreq[2] = 0; /* no authentication */
9d7d3f
-  socksreq[3] = 1; /* gssapi */
9d7d3f
-  socksreq[4] = 2; /* username/password */
9d7d3f
-#else
9d7d3f
-  socksreq[1] = (char)(proxy_user ? 2 : 1); /* number of methods (below) */
9d7d3f
-  socksreq[2] = 0; /* no authentication */
9d7d3f
-  socksreq[3] = 2; /* username/password */
9d7d3f
+  socksreq[idx++] = 1;   /* GSS-API */
9d7d3f
 #endif
9d7d3f
+  if(proxy_user)
9d7d3f
+    socksreq[idx++] = 2; /* username/password */
9d7d3f
+  /* write the number of authentication methods */
9d7d3f
+  socksreq[1] = (unsigned char) (idx - 2);
9d7d3f
 
9d7d3f
   curlx_nonblock(sock, FALSE);
9d7d3f
 
9d7d3f
-- 
9d7d3f
2.13.5
9d7d3f
9d7d3f
9d7d3f
From a76468431c030fc832aed7a5fa5b4b3f9acfe2ae Mon Sep 17 00:00:00 2001
9d7d3f
From: Kamil Dudka <kdudka@redhat.com>
9d7d3f
Date: Thu, 27 Apr 2017 15:18:49 +0200
9d7d3f
Subject: [PATCH 3/4] CURLOPT_SOCKS5_AUTH: allowed methods for SOCKS5 proxy
9d7d3f
 auth
9d7d3f
9d7d3f
If libcurl was built with GSS-API support, it unconditionally advertised
9d7d3f
GSS-API authentication while connecting to a SOCKS5 proxy.  This caused
9d7d3f
problems in environments with improperly configured Kerberos: a stock
9d7d3f
libcurl failed to connect, despite libcurl built without GSS-API
9d7d3f
connected fine using username and password.
9d7d3f
9d7d3f
This commit introduces the CURLOPT_SOCKS5_AUTH option to control the
9d7d3f
allowed methods for SOCKS5 authentication at run time.
9d7d3f
9d7d3f
Note that a new option was preferred over reusing CURLOPT_PROXYAUTH
9d7d3f
for compatibility reasons because the set of authentication methods
9d7d3f
allowed by default was different for HTTP and SOCKS5 proxies.
9d7d3f
9d7d3f
Bug: https://curl.haxx.se/mail/lib-2017-01/0005.html
9d7d3f
Closes https://github.com/curl/curl/pull/1454
9d7d3f
9d7d3f
Upstream-commit: 8924f58c370afa756fc4fd13916dfdea91d21b21
9d7d3f
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
9d7d3f
---
9d7d3f
 docs/libcurl/curl_easy_setopt.3  |  8 ++++++++
9d7d3f
 docs/libcurl/symbols-in-versions |  2 ++
9d7d3f
 include/curl/curl.h              |  6 ++++++
9d7d3f
 lib/socks.c                      | 27 ++++++++++++++++++---------
9d7d3f
 lib/url.c                        |  8 ++++++++
9d7d3f
 lib/urldata.h                    |  1 +
9d7d3f
 6 files changed, 43 insertions(+), 9 deletions(-)
9d7d3f
9d7d3f
diff --git a/docs/libcurl/curl_easy_setopt.3 b/docs/libcurl/curl_easy_setopt.3
9d7d3f
index 0a9375e..4ce8207 100644
9d7d3f
--- a/docs/libcurl/curl_easy_setopt.3
9d7d3f
+++ b/docs/libcurl/curl_easy_setopt.3
9d7d3f
@@ -862,6 +862,14 @@ Set the parameter to 1 to make the library tunnel all operations through a
9d7d3f
 given HTTP proxy. There is a big difference between using a proxy and to
9d7d3f
 tunnel through it. If you don't know what this means, you probably don't want
9d7d3f
 this tunneling option.
9d7d3f
+.IP CURLOPT_SOCKS5_AUTH
9d7d3f
+Pass a long as parameter, which is set to a bitmask, to tell libcurl which
9d7d3f
+authentication method(s) are allowed for SOCKS5 proxy authentication.  The only
9d7d3f
+supported flags are \fICURLAUTH_BASIC\fP, which allows username/password
9d7d3f
+authentication, \fICURLAUTH_GSSAPI\fP, which allows GSS-API authentication, and
9d7d3f
+\fICURLAUTH_NONE\fP, which allows no authentication.  Set the actual user name
9d7d3f
+and password with the \fICURLOPT_PROXYUSERPWD(3)\fP option.  Defaults to
9d7d3f
+\fICURLAUTH_BASIC|CURLAUTH_GSSAPI\fP.  (Added in 7.55.0)
9d7d3f
 .IP CURLOPT_SOCKS5_GSSAPI_SERVICE
9d7d3f
 Pass a char * as parameter to a string holding the name of the service. The
9d7d3f
 default service name for a SOCKS5 server is rcmd/server-fqdn. This option
9d7d3f
diff --git a/docs/libcurl/symbols-in-versions b/docs/libcurl/symbols-in-versions
9d7d3f
index 0f7469d..b0b6232 100644
9d7d3f
--- a/docs/libcurl/symbols-in-versions
9d7d3f
+++ b/docs/libcurl/symbols-in-versions
9d7d3f
@@ -17,6 +17,7 @@ CURLAUTH_ANYSAFE                7.10.6
9d7d3f
 CURLAUTH_BASIC                  7.10.6
9d7d3f
 CURLAUTH_DIGEST                 7.10.6
9d7d3f
 CURLAUTH_DIGEST_IE              7.19.3
9d7d3f
+CURLAUTH_GSSAPI                 7.55.0
9d7d3f
 CURLAUTH_GSSNEGOTIATE           7.10.6
9d7d3f
 CURLAUTH_NONE                   7.10.6
9d7d3f
 CURLAUTH_NTLM                   7.10.6
9d7d3f
@@ -454,6 +455,7 @@ CURLOPT_SERVER_RESPONSE_TIMEOUT 7.20.0
9d7d3f
 CURLOPT_SHARE                   7.10
9d7d3f
 CURLOPT_SOCKOPTDATA             7.16.0
9d7d3f
 CURLOPT_SOCKOPTFUNCTION         7.16.0
9d7d3f
+CURLOPT_SOCKS5_AUTH             7.55.0
9d7d3f
 CURLOPT_SOCKS5_GSSAPI_NEC       7.19.4
9d7d3f
 CURLOPT_SOCKS5_GSSAPI_SERVICE   7.19.4
9d7d3f
 CURLOPT_SOURCE_HOST             7.12.1        -           7.15.5
9d7d3f
diff --git a/include/curl/curl.h b/include/curl/curl.h
9d7d3f
index 14f6fd7..0375a64 100644
9d7d3f
--- a/include/curl/curl.h
9d7d3f
+++ b/include/curl/curl.h
9d7d3f
@@ -626,6 +626,9 @@ typedef enum {
9d7d3f
 #define CURLAUTH_ANY          (~CURLAUTH_DIGEST_IE)
9d7d3f
 #define CURLAUTH_ANYSAFE      (~(CURLAUTH_BASIC|CURLAUTH_DIGEST_IE))
9d7d3f
 
9d7d3f
+/* Used for CURLOPT_SOCKS5_AUTH to stay terminologically correct */
9d7d3f
+#define CURLAUTH_GSSAPI CURLAUTH_GSSNEGOTIATE
9d7d3f
+
9d7d3f
 #define CURLSSH_AUTH_ANY       ~0     /* all types supported by the server */
9d7d3f
 #define CURLSSH_AUTH_NONE      0      /* none allowed, silly but complete */
9d7d3f
 #define CURLSSH_AUTH_PUBLICKEY (1<<0) /* public/private key files */
9d7d3f
@@ -1539,6 +1542,9 @@ typedef enum {
9d7d3f
   /* Path to UNIX domain socket */
9d7d3f
   CINIT(UNIX_SOCKET_PATH, OBJECTPOINT, 231),
9d7d3f
 
9d7d3f
+  /* bitmask of allowed auth methods for connections to SOCKS5 proxies */
9d7d3f
+  CINIT(SOCKS5_AUTH, LONG, 267),
9d7d3f
+
9d7d3f
   CURLOPT_LASTENTRY /* the last unused */
9d7d3f
 } CURLoption;
9d7d3f
 
9d7d3f
diff --git a/lib/socks.c b/lib/socks.c
9d7d3f
index 398e0ac..5900063 100644
9d7d3f
--- a/lib/socks.c
9d7d3f
+++ b/lib/socks.c
9d7d3f
@@ -373,6 +373,8 @@ CURLcode Curl_SOCKS5(const char *proxy_user,
9d7d3f
   bool socks5_resolve_local = (conn->proxytype == CURLPROXY_SOCKS5)?TRUE:FALSE;
9d7d3f
   const size_t hostname_len = strlen(hostname);
9d7d3f
   ssize_t len = 0;
9d7d3f
+  const unsigned long auth = data->set.socks5auth;
9d7d3f
+  bool allow_gssapi = FALSE;
9d7d3f
 
9d7d3f
   /* RFC1928 chapter 5 specifies max 255 chars for domain name in packet */
9d7d3f
   if(!socks5_resolve_local && hostname_len > 255) {
9d7d3f
@@ -409,13 +411,24 @@ CURLcode Curl_SOCKS5(const char *proxy_user,
9d7d3f
     return CURLE_COULDNT_CONNECT;
9d7d3f
   }
9d7d3f
 
9d7d3f
+  if(auth & ~(CURLAUTH_BASIC | CURLAUTH_GSSAPI))
9d7d3f
+    infof(conn->data,
9d7d3f
+        "warning: unsupported value passed to CURLOPT_SOCKS5_AUTH: %lu\n",
9d7d3f
+        auth);
9d7d3f
+  if(!(auth & CURLAUTH_BASIC))
9d7d3f
+    /* disable username/password auth */
9d7d3f
+    proxy_user = NULL;
9d7d3f
+#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
9d7d3f
+  if(auth & CURLAUTH_GSSAPI)
9d7d3f
+    allow_gssapi = TRUE;
9d7d3f
+#endif
9d7d3f
+
9d7d3f
   idx = 0;
9d7d3f
   socksreq[idx++] = 5;   /* version */
9d7d3f
   idx++;                 /* reserve for the number of authentication methods */
9d7d3f
   socksreq[idx++] = 0;   /* no authentication */
9d7d3f
-#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
9d7d3f
-  socksreq[idx++] = 1;   /* GSS-API */
9d7d3f
-#endif
9d7d3f
+  if(allow_gssapi)
9d7d3f
+    socksreq[idx++] = 1; /* GSS-API */
9d7d3f
   if(proxy_user)
9d7d3f
     socksreq[idx++] = 2; /* username/password */
9d7d3f
   /* write the number of authentication methods */
9d7d3f
@@ -465,7 +478,7 @@ CURLcode Curl_SOCKS5(const char *proxy_user,
9d7d3f
     ;
9d7d3f
   }
9d7d3f
 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
9d7d3f
-  else if(socksreq[1] == 1) {
9d7d3f
+  else if(allow_gssapi && (socksreq[1] == 1)) {
9d7d3f
     code = Curl_SOCKS5_gssapi_negotiate(sockindex, conn);
9d7d3f
     if(code != CURLE_OK) {
9d7d3f
       failf(data, "Unable to negotiate SOCKS5 gssapi context.");
9d7d3f
@@ -526,16 +539,12 @@ CURLcode Curl_SOCKS5(const char *proxy_user,
9d7d3f
   }
9d7d3f
   else {
9d7d3f
     /* error */
9d7d3f
-#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
9d7d3f
-    if(socksreq[1] == 255) {
9d7d3f
-#else
9d7d3f
-    if(socksreq[1] == 1) {
9d7d3f
+    if(!allow_gssapi && (socksreq[1] == 1)) {
9d7d3f
       failf(data,
9d7d3f
             "SOCKS5 GSSAPI per-message authentication is not supported.");
9d7d3f
       return CURLE_COULDNT_CONNECT;
9d7d3f
     }
9d7d3f
     else if(socksreq[1] == 255) {
9d7d3f
-#endif
9d7d3f
       if(!proxy_user || !*proxy_user) {
9d7d3f
         failf(data,
9d7d3f
               "No authentication method was acceptable. (It is quite likely"
9d7d3f
diff --git a/lib/url.c b/lib/url.c
9d7d3f
index 19a40c7..d632813 100644
9d7d3f
--- a/lib/url.c
9d7d3f
+++ b/lib/url.c
9d7d3f
@@ -516,6 +516,9 @@ CURLcode Curl_init_userdefined(struct UserDefined *set)
9d7d3f
   set->httpauth = CURLAUTH_BASIC;  /* defaults to basic */
9d7d3f
   set->proxyauth = CURLAUTH_BASIC; /* defaults to basic */
9d7d3f
 
9d7d3f
+  /* SOCKS5 proxy auth defaults to username/password + GSS-API */
9d7d3f
+  set->socks5auth = CURLAUTH_BASIC | CURLAUTH_GSSAPI;
9d7d3f
+
9d7d3f
   /* make libcurl quiet by default: */
9d7d3f
   set->hide_progress = TRUE;  /* CURLOPT_NOPROGRESS changes these */
9d7d3f
 
9d7d3f
@@ -1380,6 +1383,11 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
9d7d3f
     break;
9d7d3f
 #endif   /* CURL_DISABLE_PROXY */
9d7d3f
 
9d7d3f
+  case CURLOPT_SOCKS5_AUTH:
9d7d3f
+    data->set.socks5auth = va_arg(param, unsigned long);
9d7d3f
+    if(data->set.socks5auth & ~(CURLAUTH_BASIC | CURLAUTH_GSSAPI))
9d7d3f
+      result = CURLE_NOT_BUILT_IN;
9d7d3f
+    break;
9d7d3f
 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
9d7d3f
   case CURLOPT_SOCKS5_GSSAPI_SERVICE:
9d7d3f
     /*
9d7d3f
diff --git a/lib/urldata.h b/lib/urldata.h
9d7d3f
index f4c6222..3e6ace5 100644
9d7d3f
--- a/lib/urldata.h
9d7d3f
+++ b/lib/urldata.h
9d7d3f
@@ -1406,6 +1406,7 @@ struct UserDefined {
9d7d3f
   long use_port;     /* which port to use (when not using default) */
9d7d3f
   unsigned long httpauth;  /* kind of HTTP authentication to use (bitmask) */
9d7d3f
   unsigned long proxyauth; /* kind of proxy authentication to use (bitmask) */
9d7d3f
+  unsigned long socks5auth;/* kind of SOCKS5 authentication to use (bitmask) */
9d7d3f
   long followlocation; /* as in HTTP Location: */
9d7d3f
   long maxredirs;    /* maximum no. of http(s) redirects to follow, set to -1
9d7d3f
                         for infinity */
9d7d3f
-- 
9d7d3f
2.13.5
9d7d3f
9d7d3f
9d7d3f
From 08f6dc218afe2d7e74f87996965f0770a566f185 Mon Sep 17 00:00:00 2001
9d7d3f
From: Kamil Dudka <kdudka@redhat.com>
9d7d3f
Date: Fri, 19 May 2017 18:11:47 +0200
9d7d3f
Subject: [PATCH 4/4] curl --socks5-{basic,gssapi}: control socks5 auth
9d7d3f
9d7d3f
Closes https://github.com/curl/curl/pull/1454
9d7d3f
9d7d3f
Upstream-commit: ce2c3ebda20919fe636e675f219ae387e386f508
9d7d3f
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
9d7d3f
---
9d7d3f
 docs/curl.1         | 10 ++++++++++
9d7d3f
 src/tool_cfgable.h  |  1 +
9d7d3f
 src/tool_getparam.c | 16 ++++++++++++++++
9d7d3f
 src/tool_help.c     |  2 ++
9d7d3f
 src/tool_operate.c  |  5 +++++
9d7d3f
 src/tool_setopt.c   |  1 +
9d7d3f
 src/tool_setopt.h   |  1 +
9d7d3f
 7 files changed, 36 insertions(+)
9d7d3f
9d7d3f
diff --git a/docs/curl.1 b/docs/curl.1
9d7d3f
index c9bb336..7906f1f 100644
9d7d3f
--- a/docs/curl.1
9d7d3f
+++ b/docs/curl.1
9d7d3f
@@ -1343,6 +1343,16 @@ Since 7.21.7, this option is superfluous since you can specify a socks4a proxy
9d7d3f
 with \fI-x, --proxy\fP using a socks4a:// protocol prefix.
9d7d3f
 
9d7d3f
 If this option is used several times, the last one will be used.
9d7d3f
+.IP "--socks5-basic"
9d7d3f
+Tells curl to use username/password authentication when connecting to a SOCKS5
9d7d3f
+proxy.  The username/password authentication is enabled by default.  Use
9d7d3f
+\fI--socks5-gssapi\fP to force GSS-API authentication to SOCKS5 proxies.
9d7d3f
+(Added in 7.55.0)
9d7d3f
+.IP "--socks5-gssapi"
9d7d3f
+Tells curl to use GSS-API authentication when connecting to a SOCKS5 proxy.
9d7d3f
+The GSS-API authentication is enabled by default (if curl is compiled with
9d7d3f
+GSS-API support).  Use \fI--socks5-basic\fP to force username/password
9d7d3f
+authentication to SOCKS5 proxies.  (Added in 7.55.0)
9d7d3f
 .IP "--socks5-hostname <host[:port]>"
9d7d3f
 Use the specified SOCKS5 proxy (and let the proxy resolve the host name). If
9d7d3f
 the port number is not specified, it is assumed at port 1080. (Added in
9d7d3f
diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h
9d7d3f
index a9b033b..68d0297 100644
9d7d3f
--- a/src/tool_cfgable.h
9d7d3f
+++ b/src/tool_cfgable.h
9d7d3f
@@ -172,6 +172,7 @@ struct Configurable {
9d7d3f
                                  * default rcmd */
9d7d3f
   int socks5_gssapi_nec ;   /* The NEC reference server does not protect
9d7d3f
                              * the encryption type exchange */
9d7d3f
+  unsigned long socks5_auth;/* auth bitmask for socks5 proxies */
9d7d3f
 
9d7d3f
   bool tcp_nodelay;
9d7d3f
   long req_retry;           /* number of retries */
9d7d3f
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
9d7d3f
index 33db742..32fc68b 100644
9d7d3f
--- a/src/tool_getparam.c
9d7d3f
+++ b/src/tool_getparam.c
9d7d3f
@@ -210,6 +210,8 @@ static const struct LongShort aliases[]= {
9d7d3f
   {"El", "tlspassword",              TRUE},
9d7d3f
   {"Em", "tlsauthtype",              TRUE},
9d7d3f
   {"En", "ssl-allow-beast",          FALSE},
9d7d3f
+  {"EA", "socks5-basic",             FALSE},
9d7d3f
+  {"EB", "socks5-gssapi",            FALSE},
9d7d3f
   {"f",  "fail",                     FALSE},
9d7d3f
   {"F",  "form",                     TRUE},
9d7d3f
   {"Fs", "form-string",              TRUE},
9d7d3f
@@ -1324,6 +1326,20 @@ ParameterError getparameter(char *flag,    /* f or -long-flag */
9d7d3f
         if(curlinfo->features & CURL_VERSION_SSL)
9d7d3f
           config->ssl_allow_beast = toggle;
9d7d3f
         break;
9d7d3f
+      case 'A':
9d7d3f
+        /* --socks5-basic */
9d7d3f
+        if(toggle)
9d7d3f
+          config->socks5_auth |= CURLAUTH_BASIC;
9d7d3f
+        else
9d7d3f
+          config->socks5_auth &= ~CURLAUTH_BASIC;
9d7d3f
+        break;
9d7d3f
+      case 'B':
9d7d3f
+        /* --socks5-gssapi */
9d7d3f
+        if(toggle)
9d7d3f
+          config->socks5_auth |= CURLAUTH_GSSAPI;
9d7d3f
+        else
9d7d3f
+          config->socks5_auth &= ~CURLAUTH_GSSAPI;
9d7d3f
+        break;
9d7d3f
       default: /* certificate file */
9d7d3f
       {
9d7d3f
         char *certname, *passphrase;
9d7d3f
diff --git a/src/tool_help.c b/src/tool_help.c
9d7d3f
index 3a64e35..c2883eb 100644
9d7d3f
--- a/src/tool_help.c
9d7d3f
+++ b/src/tool_help.c
9d7d3f
@@ -179,6 +179,8 @@ static const char *const helptext[] = {
9d7d3f
   "     --socks4 HOST[:PORT]  SOCKS4 proxy on given host + port",
9d7d3f
   "     --socks4a HOST[:PORT]  SOCKS4a proxy on given host + port",
9d7d3f
   "     --socks5 HOST[:PORT]  SOCKS5 proxy on given host + port",
9d7d3f
+  "     --socks5-basic  Enable username/password auth for SOCKS5 proxies",
9d7d3f
+  "     --socks5-gssapi Enable GSS-API auth for SOCKS5 proxies",
9d7d3f
   "     --socks5-hostname HOST[:PORT] "
9d7d3f
   "SOCKS5 proxy, pass host name to proxy",
9d7d3f
 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
9d7d3f
diff --git a/src/tool_operate.c b/src/tool_operate.c
9d7d3f
index 41b0e6b..185f9c6 100644
9d7d3f
--- a/src/tool_operate.c
9d7d3f
+++ b/src/tool_operate.c
9d7d3f
@@ -1208,6 +1208,11 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
9d7d3f
           if(config->socks5_gssapi_nec)
9d7d3f
             my_setopt_str(curl, CURLOPT_SOCKS5_GSSAPI_NEC,
9d7d3f
                           config->socks5_gssapi_nec);
9d7d3f
+
9d7d3f
+          /* new in curl 7.55.0 */
9d7d3f
+          if(config->socks5_auth)
9d7d3f
+            my_setopt_bitmask(curl, CURLOPT_SOCKS5_AUTH,
9d7d3f
+                              (long)config->socks5_auth);
9d7d3f
         }
9d7d3f
 #endif
9d7d3f
         /* curl 7.13.0 */
9d7d3f
diff --git a/src/tool_setopt.c b/src/tool_setopt.c
9d7d3f
index 9860117..5ae32cd 100644
9d7d3f
--- a/src/tool_setopt.c
9d7d3f
+++ b/src/tool_setopt.c
9d7d3f
@@ -130,6 +130,7 @@ const NameValue setopt_nv_CURLPROTO[] = {
9d7d3f
 static const NameValue setopt_nv_CURLNONZERODEFAULTS[] = {
9d7d3f
   NV1(CURLOPT_SSL_VERIFYPEER, 1),
9d7d3f
   NV1(CURLOPT_SSL_VERIFYHOST, 1),
9d7d3f
+  NV1(CURLOPT_SOCKS5_AUTH, 1),
9d7d3f
   NVEND
9d7d3f
 };
9d7d3f
 
9d7d3f
diff --git a/src/tool_setopt.h b/src/tool_setopt.h
9d7d3f
index d107756..60e614c 100644
9d7d3f
--- a/src/tool_setopt.h
9d7d3f
+++ b/src/tool_setopt.h
9d7d3f
@@ -64,6 +64,7 @@ extern const NameValueUnsigned setopt_nv_CURLAUTH[];
9d7d3f
 #define setopt_nv_CURLOPT_REDIR_PROTOCOLS setopt_nv_CURLPROTO
9d7d3f
 #define setopt_nv_CURLOPT_PROXYTYPE setopt_nv_CURLPROXY
9d7d3f
 #define setopt_nv_CURLOPT_PROXYAUTH setopt_nv_CURLAUTH
9d7d3f
+#define setopt_nv_CURLOPT_SOCKS5_AUTH setopt_nv_CURLAUTH
9d7d3f
 
9d7d3f
 /* Intercept setopt calls for --libcurl */
9d7d3f
 
9d7d3f
-- 
9d7d3f
2.13.5
9d7d3f