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.

89 lines
3.2 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. --- a/acinclude.m4
  12. +++ b/acinclude.m4
  13. @@ -2614,8 +2614,8 @@ AC_HELP_STRING([--without-ca-path], [Don
  14. capath="no"
  15. elif test "x$want_capath" != "xno" -a "x$want_capath" != "xunset"; then
  16. dnl --with-ca-path given
  17. - if test "x$OPENSSL_ENABLED" != "x1" -a "x$POLARSSL_ENABLED" != "x1"; then
  18. - AC_MSG_ERROR([--with-ca-path only works with openSSL or PolarSSL])
  19. + if test "x$OPENSSL_ENABLED" != "x1" -a "x$GNUTLS_ENABLED" != "x1" -a "x$POLARSSL_ENABLED" != "x1"; then
  20. + AC_MSG_ERROR([--with-ca-path only works with OpenSSL, GnuTLS or PolarSSL])
  21. fi
  22. capath="$want_capath"
  23. ca="no"
  24. --- a/docs/libcurl/opts/CURLOPT_CAPATH.3
  25. +++ b/docs/libcurl/opts/CURLOPT_CAPATH.3
  26. @@ -43,9 +43,8 @@ All TLS based protocols: HTTPS, FTPS, IM
  27. .SH EXAMPLE
  28. TODO
  29. .SH AVAILABILITY
  30. -This option is OpenSSL-specific and does nothing if libcurl is built to use
  31. -GnuTLS. NSS-powered libcurl provides the option only for backward
  32. -compatibility.
  33. +This option is supported by the OpenSSL, GnuTLS and PolarSSL backends. The NSS
  34. +backend provides the option only for backward compatibility.
  35. .SH RETURN VALUE
  36. Returns CURLE_OK if TLS enabled, and CURLE_UNKNOWN_OPTION if not, or
  37. CURLE_OUT_OF_MEMORY if there was insufficient heap space.
  38. --- a/lib/vtls/gtls.c
  39. +++ b/lib/vtls/gtls.c
  40. @@ -98,6 +98,10 @@ static bool gtls_inited = FALSE;
  41. # define HAS_ALPN
  42. # endif
  43. # endif
  44. +
  45. +# if (GNUTLS_VERSION_NUMBER >= 0x030306)
  46. +# define HAS_CAPATH
  47. +# endif
  48. #endif
  49. /*
  50. @@ -463,6 +467,24 @@ gtls_connect_step1(struct connectdata *c
  51. rc, data->set.ssl.CAfile);
  52. }
  53. +#ifdef HAS_CAPATH
  54. + if(data->set.ssl.CApath) {
  55. + /* set the trusted CA cert directory */
  56. + rc = gnutls_certificate_set_x509_trust_dir(conn->ssl[sockindex].cred,
  57. + data->set.ssl.CApath,
  58. + GNUTLS_X509_FMT_PEM);
  59. + if(rc < 0) {
  60. + infof(data, "error reading ca cert file %s (%s)\n",
  61. + data->set.ssl.CAfile, gnutls_strerror(rc));
  62. + if(data->set.ssl.verifypeer)
  63. + return CURLE_SSL_CACERT_BADFILE;
  64. + }
  65. + else
  66. + infof(data, "found %d certificates in %s\n",
  67. + rc, data->set.ssl.CApath);
  68. + }
  69. +#endif
  70. +
  71. if(data->set.ssl.CRLfile) {
  72. /* set the CRL list file */
  73. rc = gnutls_certificate_set_x509_crl_file(conn->ssl[sockindex].cred,
  74. --- a/lib/vtls/gtls.h
  75. +++ b/lib/vtls/gtls.h
  76. @@ -53,6 +53,9 @@ void Curl_gtls_md5sum(unsigned char *tmp
  77. unsigned char *md5sum, /* output */
  78. size_t md5len);
  79. +/* this backend supports the CAPATH option */
  80. +#define have_curlssl_ca_path 1
  81. +
  82. /* API setup for GnuTLS */
  83. #define curlssl_init Curl_gtls_init
  84. #define curlssl_cleanup Curl_gtls_cleanup