Re: [PATCH 1/2] http.c: prompt for SSL client certificate password

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH 1/2] http.c: prompt for SSL client certificate password

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:46:56

Mark Lodato [off-list ref] writes:
quoted hunk
@@ -189,6 +207,16 @@ static CURL *get_curl_handle(void)
 
 	if (ssl_cert != NULL)
 		curl_easy_setopt(result, CURLOPT_SSLCERT, ssl_cert);
+	if (has_cert_password())
+		curl_easy_setopt(result,
+#if LIBCURL_VERSION_NUM >= 0x071700
+				 CURLOPT_KEYPASSWD,
+#elif LIBCURL_VERSION_NUM >= 0x070903
+				 CURLOPT_SSLKEYPASSWD,
+#else
+				 CURLOPT_SSLCERTPASSWD,
+#endif
+				 ssl_cert_password);
This is purely style and readability, but if you do something like this
much earlier in the file:

    #if !defined(CURLOPT_KEYPASSWD)
    # if defined(CURLOPT_SSLKEYPASSWD)
    #  define CURLOPT_KEYTPASSWD CURLOPT_SSLKEYPASSWD
    # elif defined(CURLOPT_SSLCERTPASSWD
    #  define CURLOPT_KEYTPASSWD CURLOPT_SSLCERTPASSWD
    # endif
    #endif

you can write your main codepath using the latest cURL API without ifdef.
The callsite can simply say:

	if (must_set_cert_password())
        	curl_easy_setopt(result, CURLOPT_KEYPASSWD, ssl_cert_password);

which I think would be much easier to follow.

This assumes that KEYPASSWD is the latest API, and in older versions only
names are different, which your code implies.  I have a vague recollection
that SSLCERTPASSWD actually deprecated KEYPASSWD (i.e. your #if...#endif
chain is wrong), but I didn't actually check the cURL documentation [*1*]
to see if that is the case.

[Reference]

*1* http://cool.haxx.se/cvs.cgi/curl/docs/libcurl/symbols-in-versions?rev=HEAD

Re: [PATCH 1/2] http.c: prompt for SSL client certificate password

From: Daniel Stenberg <hidden>
Date: 2016-06-15 22:46:56

On Thu, 11 Jun 2009, Junio C Hamano wrote:
   #if !defined(CURLOPT_KEYPASSWD)
   # if defined(CURLOPT_SSLKEYPASSWD)
   #  define CURLOPT_KEYTPASSWD CURLOPT_SSLKEYPASSWD
   # elif defined(CURLOPT_SSLCERTPASSWD
   #  define CURLOPT_KEYTPASSWD CURLOPT_SSLCERTPASSWD
   # endif
   #endif
Just note that these CURLOPT_* symbols provided by libcurl are enums, not 
defines, so unfortunately you can't do it this exact #ifdef way.

-- 

  / daniel.haxx.se

Re: [PATCH 1/2] http.c: prompt for SSL client certificate password

From: Mark Lodato <hidden>
Date: 2016-06-15 22:46:56

On Fri, Jun 12, 2009 at 2:34 AM, Junio C Hamano[off-list ref] wrote:
Mark Lodato [off-list ref] writes:
quoted
@@ -189,6 +207,16 @@ static CURL *get_curl_handle(void)
      if (ssl_cert != NULL)
              curl_easy_setopt(result, CURLOPT_SSLCERT, ssl_cert);
+     if (has_cert_password())
+             curl_easy_setopt(result,
+#if LIBCURL_VERSION_NUM >= 0x071700
+                              CURLOPT_KEYPASSWD,
+#elif LIBCURL_VERSION_NUM >= 0x070903
+                              CURLOPT_SSLKEYPASSWD,
+#else
+                              CURLOPT_SSLCERTPASSWD,
+#endif
+                              ssl_cert_password);
This is purely style and readability, but if you do something like this
much earlier in the file:

   #if !defined(CURLOPT_KEYPASSWD)
   # if defined(CURLOPT_SSLKEYPASSWD)
   #  define CURLOPT_KEYTPASSWD CURLOPT_SSLKEYPASSWD
   # elif defined(CURLOPT_SSLCERTPASSWD
   #  define CURLOPT_KEYTPASSWD CURLOPT_SSLCERTPASSWD
   # endif
   #endif

you can write your main codepath using the latest cURL API without ifdef.
The callsite can simply say:

       if (must_set_cert_password())
               curl_easy_setopt(result, CURLOPT_KEYPASSWD, ssl_cert_password);

which I think would be much easier to follow.
I realized this after I submitted the patch.  Locally I have modified
my version to do something similar to the above, but checking libcurl
versions rather than checking the existence of the macros (which don't
exist, as Daniel pointed out.)  If this patch series is accepted, I
will make a cleaner version that includes this change.

Mark
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help