102-CVE-2017-7468.patch 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. From 8166b637bce299f4ac64d371c20cd5afea72c364 Mon Sep 17 00:00:00 2001
  2. From: Jay Satiro <raysatiro@yahoo.com>
  3. Date: Wed, 22 Mar 2017 01:59:49 -0400
  4. Subject: [PATCH] TLS: Fix switching off SSL session id when client cert is
  5. used
  6. - Move the sessionid flag to ssl_primary_config so that ssl and
  7. proxy_ssl will each have their own sessionid flag.
  8. Regression since HTTPS-Proxy support was added in cb4e2be. Prior to that
  9. this issue had been fixed in 247d890, CVE-2016-5419.
  10. Bug: https://github.com/curl/curl/issues/1341
  11. Reported-by: lijian996@users.noreply.github.com
  12. ---
  13. lib/url.c | 5 +++--
  14. lib/urldata.h | 2 +-
  15. lib/vtls/axtls.c | 4 ++--
  16. lib/vtls/cyassl.c | 4 ++--
  17. lib/vtls/darwinssl.c | 2 +-
  18. lib/vtls/gtls.c | 4 ++--
  19. lib/vtls/mbedtls.c | 4 ++--
  20. lib/vtls/nss.c | 2 +-
  21. lib/vtls/openssl.c | 4 ++--
  22. lib/vtls/polarssl.c | 4 ++--
  23. lib/vtls/schannel.c | 4 ++--
  24. lib/vtls/vtls.c | 9 ++++++---
  25. 12 files changed, 26 insertions(+), 22 deletions(-)
  26. --- a/lib/url.c
  27. +++ b/lib/url.c
  28. @@ -548,7 +548,7 @@ CURLcode Curl_init_userdefined(struct Us
  29. #endif
  30. set->ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth
  31. type */
  32. - set->general_ssl.sessionid = TRUE; /* session ID caching enabled by
  33. + set->ssl.primary.sessionid = TRUE; /* session ID caching enabled by
  34. default */
  35. set->proxy_ssl = set->ssl;
  36. @@ -2470,8 +2470,9 @@ CURLcode Curl_setopt(struct Curl_easy *d
  37. break;
  38. case CURLOPT_SSL_SESSIONID_CACHE:
  39. - data->set.general_ssl.sessionid = (0 != va_arg(param, long)) ?
  40. + data->set.ssl.primary.sessionid = (0 != va_arg(param, long)) ?
  41. TRUE : FALSE;
  42. + data->set.proxy_ssl.primary.sessionid = data->set.ssl.primary.sessionid;
  43. break;
  44. #ifdef USE_LIBSSH2
  45. --- a/lib/urldata.h
  46. +++ b/lib/urldata.h
  47. @@ -354,6 +354,7 @@ struct ssl_primary_config {
  48. char *random_file; /* path to file containing "random" data */
  49. char *egdsocket; /* path to file containing the EGD daemon socket */
  50. char *cipher_list; /* list of ciphers to use */
  51. + bool sessionid; /* cache session IDs or not */
  52. };
  53. struct ssl_config_data {
  54. @@ -383,7 +384,6 @@ struct ssl_config_data {
  55. };
  56. struct ssl_general_config {
  57. - bool sessionid; /* cache session IDs or not */
  58. size_t max_ssl_sessions; /* SSL session id cache size */
  59. };
  60. --- a/lib/vtls/axtls.c
  61. +++ b/lib/vtls/axtls.c
  62. @@ -256,7 +256,7 @@ static CURLcode connect_prep(struct conn
  63. * 2) setting up callbacks. these seem gnutls specific
  64. */
  65. - if(data->set.general_ssl.sessionid) {
  66. + if(SSL_SET_OPTION(primary.sessionid)) {
  67. const uint8_t *ssl_sessionid;
  68. size_t ssl_idsize;
  69. @@ -386,7 +386,7 @@ static CURLcode connect_finish(struct co
  70. conn->send[sockindex] = axtls_send;
  71. /* Put our freshly minted SSL session in cache */
  72. - if(data->set.general_ssl.sessionid) {
  73. + if(SSL_SET_OPTION(primary.sessionid)) {
  74. const uint8_t *ssl_sessionid = ssl_get_session_id_size(ssl);
  75. size_t ssl_idsize = ssl_get_session_id(ssl);
  76. Curl_ssl_sessionid_lock(conn);
  77. --- a/lib/vtls/cyassl.c
  78. +++ b/lib/vtls/cyassl.c
  79. @@ -383,7 +383,7 @@ cyassl_connect_step1(struct connectdata
  80. #endif /* HAVE_ALPN */
  81. /* Check if there's a cached ID we can/should use here! */
  82. - if(data->set.general_ssl.sessionid) {
  83. + if(SSL_SET_OPTION(primary.sessionid)) {
  84. void *ssl_sessionid = NULL;
  85. Curl_ssl_sessionid_lock(conn);
  86. @@ -597,7 +597,7 @@ cyassl_connect_step3(struct connectdata
  87. DEBUGASSERT(ssl_connect_3 == connssl->connecting_state);
  88. - if(data->set.general_ssl.sessionid) {
  89. + if(SSL_SET_OPTION(primary.sessionid)) {
  90. bool incache;
  91. SSL_SESSION *our_ssl_sessionid;
  92. void *old_ssl_sessionid = NULL;
  93. --- a/lib/vtls/darwinssl.c
  94. +++ b/lib/vtls/darwinssl.c
  95. @@ -1541,7 +1541,7 @@ static CURLcode darwinssl_connect_step1(
  96. #endif /* CURL_BUILD_MAC_10_9 || CURL_BUILD_IOS_7 */
  97. /* Check if there's a cached ID we can/should use here! */
  98. - if(data->set.general_ssl.sessionid) {
  99. + if(SSL_SET_OPTION(primary.sessionid)) {
  100. char *ssl_sessionid;
  101. size_t ssl_sessionid_len;
  102. --- a/lib/vtls/gtls.c
  103. +++ b/lib/vtls/gtls.c
  104. @@ -782,7 +782,7 @@ gtls_connect_step1(struct connectdata *c
  105. /* This might be a reconnect, so we check for a session ID in the cache
  106. to speed up things */
  107. - if(data->set.general_ssl.sessionid) {
  108. + if(SSL_SET_OPTION(primary.sessionid)) {
  109. void *ssl_sessionid;
  110. size_t ssl_idsize;
  111. @@ -1311,7 +1311,7 @@ gtls_connect_step3(struct connectdata *c
  112. conn->recv[sockindex] = gtls_recv;
  113. conn->send[sockindex] = gtls_send;
  114. - if(data->set.general_ssl.sessionid) {
  115. + if(SSL_SET_OPTION(primary.sessionid)) {
  116. /* we always unconditionally get the session id here, as even if we
  117. already got it from the cache and asked to use it in the connection, it
  118. might've been rejected and then a new one is in use now and we need to
  119. --- a/lib/vtls/mbedtls.c
  120. +++ b/lib/vtls/mbedtls.c
  121. @@ -374,7 +374,7 @@ mbed_connect_step1(struct connectdata *c
  122. mbedtls_ssl_list_ciphersuites());
  123. /* Check if there's a cached ID we can/should use here! */
  124. - if(data->set.general_ssl.sessionid) {
  125. + if(SSL_SET_OPTION(primary.sessionid)) {
  126. void *old_session = NULL;
  127. Curl_ssl_sessionid_lock(conn);
  128. @@ -618,7 +618,7 @@ mbed_connect_step3(struct connectdata *c
  129. DEBUGASSERT(ssl_connect_3 == connssl->connecting_state);
  130. - if(data->set.general_ssl.sessionid) {
  131. + if(SSL_SET_OPTION(primary.sessionid)) {
  132. int ret;
  133. mbedtls_ssl_session *our_ssl_sessionid;
  134. void *old_ssl_sessionid = NULL;
  135. --- a/lib/vtls/nss.c
  136. +++ b/lib/vtls/nss.c
  137. @@ -1696,7 +1696,7 @@ static CURLcode nss_setup_connect(struct
  138. goto error;
  139. /* do not use SSL cache if disabled or we are not going to verify peer */
  140. - ssl_no_cache = (data->set.general_ssl.sessionid
  141. + ssl_no_cache = (SSL_SET_OPTION(primary.sessionid)
  142. && SSL_CONN_CONFIG(verifypeer)) ? PR_FALSE : PR_TRUE;
  143. if(SSL_OptionSet(model, SSL_NO_CACHE, ssl_no_cache) != SECSuccess)
  144. goto error;
  145. --- a/lib/vtls/openssl.c
  146. +++ b/lib/vtls/openssl.c
  147. @@ -2161,7 +2161,7 @@ static CURLcode ossl_connect_step1(struc
  148. #endif
  149. /* Check if there's a cached ID we can/should use here! */
  150. - if(data->set.general_ssl.sessionid) {
  151. + if(SSL_SET_OPTION(primary.sessionid)) {
  152. void *ssl_sessionid = NULL;
  153. Curl_ssl_sessionid_lock(conn);
  154. @@ -2915,7 +2915,7 @@ static CURLcode ossl_connect_step3(struc
  155. DEBUGASSERT(ssl_connect_3 == connssl->connecting_state);
  156. - if(data->set.general_ssl.sessionid) {
  157. + if(SSL_SET_OPTION(primary.sessionid)) {
  158. bool incache;
  159. SSL_SESSION *our_ssl_sessionid;
  160. void *old_ssl_sessionid = NULL;
  161. --- a/lib/vtls/polarssl.c
  162. +++ b/lib/vtls/polarssl.c
  163. @@ -327,7 +327,7 @@ polarssl_connect_step1(struct connectdat
  164. ssl_set_ciphersuites(&connssl->ssl, ssl_list_ciphersuites());
  165. /* Check if there's a cached ID we can/should use here! */
  166. - if(data->set.general_ssl.sessionid) {
  167. + if(SSL_SET_OPTION(primary.sessionid)) {
  168. void *old_session = NULL;
  169. Curl_ssl_sessionid_lock(conn);
  170. @@ -555,7 +555,7 @@ polarssl_connect_step3(struct connectdat
  171. DEBUGASSERT(ssl_connect_3 == connssl->connecting_state);
  172. - if(data->set.general_ssl.sessionid) {
  173. + if(SSL_SET_OPTION(primary.sessionid)) {
  174. int ret;
  175. ssl_session *our_ssl_sessionid;
  176. void *old_ssl_sessionid = NULL;
  177. --- a/lib/vtls/schannel.c
  178. +++ b/lib/vtls/schannel.c
  179. @@ -145,7 +145,7 @@ schannel_connect_step1(struct connectdat
  180. connssl->cred = NULL;
  181. /* check for an existing re-usable credential handle */
  182. - if(data->set.general_ssl.sessionid) {
  183. + if(SSL_SET_OPTION(primary.sessionid)) {
  184. Curl_ssl_sessionid_lock(conn);
  185. if(!Curl_ssl_getsessionid(conn, (void **)&old_cred, NULL, sockindex)) {
  186. connssl->cred = old_cred;
  187. @@ -714,7 +714,7 @@ schannel_connect_step3(struct connectdat
  188. #endif
  189. /* save the current session data for possible re-use */
  190. - if(data->set.general_ssl.sessionid) {
  191. + if(SSL_SET_OPTION(primary.sessionid)) {
  192. bool incache;
  193. struct curl_schannel_cred *old_cred = NULL;
  194. --- a/lib/vtls/vtls.c
  195. +++ b/lib/vtls/vtls.c
  196. @@ -120,6 +120,9 @@ Curl_clone_primary_ssl_config(struct ssl
  197. CLONE_STRING(egdsocket);
  198. CLONE_STRING(random_file);
  199. CLONE_STRING(clientcert);
  200. +
  201. + /* Disable dest sessionid cache if a client cert is used, CVE-2016-5419. */
  202. + dest->sessionid = (dest->clientcert ? false : source->sessionid);
  203. return TRUE;
  204. }
  205. @@ -293,9 +296,9 @@ bool Curl_ssl_getsessionid(struct connec
  206. int port = isProxy ? (int)conn->port : conn->remote_port;
  207. *ssl_sessionid = NULL;
  208. - DEBUGASSERT(data->set.general_ssl.sessionid);
  209. + DEBUGASSERT(SSL_SET_OPTION(primary.sessionid));
  210. - if(!data->set.general_ssl.sessionid)
  211. + if(!SSL_SET_OPTION(primary.sessionid))
  212. /* session ID re-use is disabled */
  213. return TRUE;
  214. @@ -397,7 +400,7 @@ CURLcode Curl_ssl_addsessionid(struct co
  215. &conn->proxy_ssl_config :
  216. &conn->ssl_config;
  217. - DEBUGASSERT(data->set.general_ssl.sessionid);
  218. + DEBUGASSERT(SSL_SET_OPTION(primary.sessionid));
  219. clone_host = strdup(isProxy ? conn->http_proxy.host.name : conn->host.name);
  220. if(!clone_host)