0002-nss-fix-build-with-disabled-proxy-support.patch 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. From d040da28f57d0b3fcd6f63809a8c85a600f87a62 Mon Sep 17 00:00:00 2001
  2. Message-Id: <d040da28f57d0b3fcd6f63809a8c85a600f87a62.1594274337.git.baruch@tkos.co.il>
  3. From: Baruch Siach <baruch@tkos.co.il>
  4. Date: Thu, 9 Jul 2020 08:14:49 +0300
  5. Subject: [PATCH] nss: fix build with disabled proxy support
  6. Avoid reference to fields that do not exist when CURL_DISABLE_PROXY is
  7. defined.
  8. Signed-off-by: Baruch Siach <baruch@tkos.co.il>
  9. ---
  10. Upstream status: https://github.com/curl/curl/pull/5667
  11. lib/vtls/nss.c | 44 +++++++++++++++++++++++++++++++++++---------
  12. 1 file changed, 35 insertions(+), 9 deletions(-)
  13. diff --git a/lib/vtls/nss.c b/lib/vtls/nss.c
  14. index fca292613815..0f0d1ee6c80f 100644
  15. --- a/lib/vtls/nss.c
  16. +++ b/lib/vtls/nss.c
  17. @@ -1027,9 +1027,11 @@ static SECStatus BadCertHandler(void *arg, PRFileDesc *sock)
  18. CERTCertificate *cert;
  19. /* remember the cert verification result */
  20. +#ifndef CURL_DISABLE_PROXY
  21. if(SSL_IS_PROXY())
  22. data->set.proxy_ssl.certverifyresult = err;
  23. else
  24. +#endif
  25. data->set.ssl.certverifyresult = err;
  26. if(err == SSL_ERROR_BAD_CERT_DOMAIN && !SSL_CONN_CONFIG(verifyhost))
  27. @@ -1553,24 +1555,32 @@ static void nss_close(struct ssl_connect_data *connssl)
  28. static void Curl_nss_close(struct connectdata *conn, int sockindex)
  29. {
  30. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  31. +#ifndef CURL_DISABLE_PROXY
  32. struct ssl_connect_data *connssl_proxy = &conn->proxy_ssl[sockindex];
  33. +#endif
  34. struct ssl_backend_data *backend = connssl->backend;
  35. - if(backend->handle || connssl_proxy->backend->handle) {
  36. + if(backend->handle
  37. +#ifndef CURL_DISABLE_PROXY
  38. + || connssl_proxy->backend->handle
  39. +#endif
  40. + ) {
  41. /* NSS closes the socket we previously handed to it, so we must mark it
  42. as closed to avoid double close */
  43. fake_sclose(conn->sock[sockindex]);
  44. conn->sock[sockindex] = CURL_SOCKET_BAD;
  45. }
  46. +#ifndef CURL_DISABLE_PROXY
  47. if(backend->handle)
  48. /* nss_close(connssl) will transitively close also
  49. connssl_proxy->backend->handle if both are used. Clear it to avoid
  50. a double close leading to crash. */
  51. connssl_proxy->backend->handle = NULL;
  52. - nss_close(connssl);
  53. nss_close(connssl_proxy);
  54. +#endif
  55. + nss_close(connssl);
  56. }
  57. /* return true if NSS can provide error code (and possibly msg) for the
  58. @@ -1828,6 +1838,12 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex)
  59. CURLcode result;
  60. bool second_layer = FALSE;
  61. SSLVersionRange sslver_supported;
  62. +#ifndef CURL_DISABLE_PROXY
  63. + const char *hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
  64. + conn->host.name;
  65. +#else
  66. + const char *hostname = conn->host.name;
  67. +#endif
  68. SSLVersionRange sslver = {
  69. SSL_LIBRARY_VERSION_TLS_1_0, /* min */
  70. @@ -1932,9 +1948,11 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex)
  71. goto error;
  72. /* not checked yet */
  73. +#ifndef CURL_DISABLE_PROXY
  74. if(SSL_IS_PROXY())
  75. data->set.proxy_ssl.certverifyresult = 0;
  76. else
  77. +#endif
  78. data->set.ssl.certverifyresult = 0;
  79. if(SSL_BadCertHook(model, BadCertHandler, conn) != SECSuccess)
  80. @@ -1991,12 +2009,14 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex)
  81. goto error;
  82. }
  83. +#ifndef CURL_DISABLE_PROXY
  84. if(conn->proxy_ssl[sockindex].use) {
  85. DEBUGASSERT(ssl_connection_complete == conn->proxy_ssl[sockindex].state);
  86. DEBUGASSERT(conn->proxy_ssl[sockindex].backend->handle != NULL);
  87. nspr_io = conn->proxy_ssl[sockindex].backend->handle;
  88. second_layer = TRUE;
  89. }
  90. +#endif
  91. else {
  92. /* wrap OS file descriptor by NSPR's file descriptor abstraction */
  93. nspr_io = PR_ImportTCPSocket(sockfd);
  94. @@ -2077,8 +2097,11 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex)
  95. unsigned char protocols[128];
  96. #ifdef USE_NGHTTP2
  97. - if(data->set.httpversion >= CURL_HTTP_VERSION_2 &&
  98. - (!SSL_IS_PROXY() || !conn->bits.tunnel_proxy)) {
  99. + if(data->set.httpversion >= CURL_HTTP_VERSION_2
  100. +#ifndef CURL_DISABLE_PROXY
  101. + && (!SSL_IS_PROXY() || !conn->bits.tunnel_proxy)
  102. +#endif
  103. + ) {
  104. protocols[cur++] = NGHTTP2_PROTO_VERSION_ID_LEN;
  105. memcpy(&protocols[cur], NGHTTP2_PROTO_VERSION_ID,
  106. NGHTTP2_PROTO_VERSION_ID_LEN);
  107. @@ -2101,14 +2124,11 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex)
  108. goto error;
  109. /* propagate hostname to the TLS layer */
  110. - if(SSL_SetURL(backend->handle, SSL_IS_PROXY() ? conn->http_proxy.host.name :
  111. - conn->host.name) != SECSuccess)
  112. + if(SSL_SetURL(backend->handle, hostname) != SECSuccess)
  113. goto error;
  114. /* prevent NSS from re-using the session for a different hostname */
  115. - if(SSL_SetSockPeerID(backend->handle, SSL_IS_PROXY() ?
  116. - conn->http_proxy.host.name : conn->host.name)
  117. - != SECSuccess)
  118. + if(SSL_SetSockPeerID(backend->handle, hostname) != SECSuccess)
  119. goto error;
  120. return CURLE_OK;
  121. @@ -2127,11 +2147,17 @@ static CURLcode nss_do_connect(struct connectdata *conn, int sockindex)
  122. struct Curl_easy *data = conn->data;
  123. CURLcode result = CURLE_SSL_CONNECT_ERROR;
  124. PRUint32 timeout;
  125. +#ifndef CURL_DISABLE_PROXY
  126. long * const certverifyresult = SSL_IS_PROXY() ?
  127. &data->set.proxy_ssl.certverifyresult : &data->set.ssl.certverifyresult;
  128. const char * const pinnedpubkey = SSL_IS_PROXY() ?
  129. data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY] :
  130. data->set.str[STRING_SSL_PINNEDPUBLICKEY_ORIG];
  131. +#else
  132. + long * const certverifyresult = &data->set.ssl.certverifyresult;
  133. + const char * const pinnedpubkey =
  134. + data->set.str[STRING_SSL_PINNEDPUBLICKEY_ORIG];
  135. +#endif
  136. /* check timeout situation */
  137. --
  138. 2.27.0