You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.6 KiB

  1. From 5a1614cecdd57cab8b4ae3e9bc19dfff5ba77e80 Mon Sep 17 00:00:00 2001
  2. From: Alessandro Ghedini <alessandro@ghedini.me>
  3. Date: Sun, 8 Mar 2015 20:11:06 +0100
  4. Subject: [PATCH] gtls: add support for CURLOPT_CAPATH
  5. ---
  6. acinclude.m4 | 4 ++--
  7. docs/libcurl/opts/CURLOPT_CAPATH.3 | 5 ++---
  8. lib/vtls/gtls.c | 22 ++++++++++++++++++++++
  9. lib/vtls/gtls.h | 3 +++
  10. 4 files changed, 29 insertions(+), 5 deletions(-)
  11. diff --git a/acinclude.m4 b/acinclude.m4
  12. index 6ed7ffb..ca01869 100644
  13. --- a/acinclude.m4
  14. +++ b/acinclude.m4
  15. @@ -2615,8 +2615,8 @@ AC_HELP_STRING([--without-ca-path], [Don't use a default CA path]),
  16. capath="no"
  17. elif test "x$want_capath" != "xno" -a "x$want_capath" != "xunset"; then
  18. dnl --with-ca-path given
  19. - if test "x$OPENSSL_ENABLED" != "x1" -a "x$POLARSSL_ENABLED" != "x1"; then
  20. - AC_MSG_ERROR([--with-ca-path only works with openSSL or PolarSSL])
  21. + if test "x$OPENSSL_ENABLED" != "x1" -a "x$GNUTLS_ENABLED" != "x1" -a "x$POLARSSL_ENABLED" != "x1"; then
  22. + AC_MSG_ERROR([--with-ca-path only works with OpenSSL, GnuTLS or PolarSSL])
  23. fi
  24. capath="$want_capath"
  25. ca="no"
  26. diff --git a/docs/libcurl/opts/CURLOPT_CAPATH.3 b/docs/libcurl/opts/CURLOPT_CAPATH.3
  27. index 642953d..6695f9f 100644
  28. --- a/docs/libcurl/opts/CURLOPT_CAPATH.3
  29. +++ b/docs/libcurl/opts/CURLOPT_CAPATH.3
  30. @@ -43,9 +43,8 @@ All TLS based protocols: HTTPS, FTPS, IMAPS, POP3, SMTPS etc.
  31. .SH EXAMPLE
  32. TODO
  33. .SH AVAILABILITY
  34. -This option is OpenSSL-specific and does nothing if libcurl is built to use
  35. -GnuTLS. NSS-powered libcurl provides the option only for backward
  36. -compatibility.
  37. +This option is supported by the OpenSSL, GnuTLS and PolarSSL backends. The NSS
  38. +backend provides the option only for backward compatibility.
  39. .SH RETURN VALUE
  40. Returns CURLE_OK if TLS enabled, and CURLE_UNKNOWN_OPTION if not, or
  41. CURLE_OUT_OF_MEMORY if there was insufficient heap space.
  42. diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c
  43. index 05aef19..c792540 100644
  44. --- a/lib/vtls/gtls.c
  45. +++ b/lib/vtls/gtls.c
  46. @@ -97,6 +97,10 @@ static bool gtls_inited = FALSE;
  47. # if (GNUTLS_VERSION_NUMBER >= 0x03020d)
  48. # define HAS_OCSP
  49. # endif
  50. +
  51. +# if (GNUTLS_VERSION_NUMBER >= 0x030306)
  52. +# define HAS_CAPATH
  53. +# endif
  54. #endif
  55. #ifdef HAS_OCSP
  56. @@ -462,6 +466,24 @@ gtls_connect_step1(struct connectdata *conn,
  57. rc, data->set.ssl.CAfile);
  58. }
  59. +#ifdef HAS_CAPATH
  60. + if(data->set.ssl.CApath) {
  61. + /* set the trusted CA cert directory */
  62. + rc = gnutls_certificate_set_x509_trust_dir(conn->ssl[sockindex].cred,
  63. + data->set.ssl.CApath,
  64. + GNUTLS_X509_FMT_PEM);
  65. + if(rc < 0) {
  66. + infof(data, "error reading ca cert file %s (%s)\n",
  67. + data->set.ssl.CAfile, gnutls_strerror(rc));
  68. + if(data->set.ssl.verifypeer)
  69. + return CURLE_SSL_CACERT_BADFILE;
  70. + }
  71. + else
  72. + infof(data, "found %d certificates in %s\n",
  73. + rc, data->set.ssl.CApath);
  74. + }
  75. +#endif
  76. +
  77. if(data->set.ssl.CRLfile) {
  78. /* set the CRL list file */
  79. rc = gnutls_certificate_set_x509_crl_file(conn->ssl[sockindex].cred,
  80. diff --git a/lib/vtls/gtls.h b/lib/vtls/gtls.h
  81. index c3867e5..af1cb5b 100644
  82. --- a/lib/vtls/gtls.h
  83. +++ b/lib/vtls/gtls.h
  84. @@ -54,6 +54,9 @@ bool Curl_gtls_cert_status_request(void);
  85. /* Set the API backend definition to GnuTLS */
  86. #define CURL_SSL_BACKEND CURLSSLBACKEND_GNUTLS
  87. +/* this backend supports the CAPATH option */
  88. +#define have_curlssl_ca_path 1
  89. +
  90. /* API setup for GnuTLS */
  91. #define curlssl_init Curl_gtls_init
  92. #define curlssl_cleanup Curl_gtls_cleanup
  93. --
  94. 2.4.4