vtls.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #ifndef HEADER_CURL_VTLS_H
  2. #define HEADER_CURL_VTLS_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2016, Daniel Stenberg, <[email protected]>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.haxx.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. ***************************************************************************/
  24. #include "curl_setup.h"
  25. #include "openssl.h" /* OpenSSL versions */
  26. #include "gtls.h" /* GnuTLS versions */
  27. #include "nssg.h" /* NSS versions */
  28. #include "gskit.h" /* Global Secure ToolKit versions */
  29. #include "polarssl.h" /* PolarSSL versions */
  30. #include "axtls.h" /* axTLS versions */
  31. #include "cyassl.h" /* CyaSSL versions */
  32. #include "schannel.h" /* Schannel SSPI version */
  33. #include "darwinssl.h" /* SecureTransport (Darwin) version */
  34. #include "mbedtls.h" /* mbedTLS versions */
  35. #ifndef MAX_PINNED_PUBKEY_SIZE
  36. #define MAX_PINNED_PUBKEY_SIZE 1048576 /* 1MB */
  37. #endif
  38. #ifndef MD5_DIGEST_LENGTH
  39. #define MD5_DIGEST_LENGTH 16 /* fixed size */
  40. #endif
  41. #ifndef SHA256_DIGEST_LENGTH
  42. #define SHA256_DIGEST_LENGTH 32 /* fixed size */
  43. #endif
  44. /* see https://tools.ietf.org/html/draft-ietf-tls-applayerprotoneg-04 */
  45. #define ALPN_HTTP_1_1_LENGTH 8
  46. #define ALPN_HTTP_1_1 "http/1.1"
  47. /* set of helper macros for the backends to access the correct fields. For the
  48. proxy or for the remote host - to properly support HTTPS proxy */
  49. #define SSL_IS_PROXY() (CURLPROXY_HTTPS == conn->http_proxy.proxytype && \
  50. ssl_connection_complete != conn->proxy_ssl[conn->sock[SECONDARYSOCKET] == \
  51. CURL_SOCKET_BAD ? FIRSTSOCKET : SECONDARYSOCKET].state)
  52. #define SSL_SET_OPTION(var) (SSL_IS_PROXY() ? data->set.proxy_ssl.var : \
  53. data->set.ssl.var)
  54. #define SSL_CONN_CONFIG(var) (SSL_IS_PROXY() ? \
  55. conn->proxy_ssl_config.var : conn->ssl_config.var)
  56. bool Curl_ssl_config_matches(struct ssl_primary_config* data,
  57. struct ssl_primary_config* needle);
  58. bool Curl_clone_primary_ssl_config(struct ssl_primary_config *source,
  59. struct ssl_primary_config *dest);
  60. void Curl_free_primary_ssl_config(struct ssl_primary_config* sslc);
  61. int Curl_ssl_getsock(struct connectdata *conn, curl_socket_t *socks,
  62. int numsocks);
  63. int Curl_ssl_backend(void);
  64. #ifdef USE_SSL
  65. int Curl_ssl_init(void);
  66. void Curl_ssl_cleanup(void);
  67. CURLcode Curl_ssl_connect(struct connectdata *conn, int sockindex);
  68. CURLcode Curl_ssl_connect_nonblocking(struct connectdata *conn,
  69. int sockindex,
  70. bool *done);
  71. /* tell the SSL stuff to close down all open information regarding
  72. connections (and thus session ID caching etc) */
  73. void Curl_ssl_close_all(struct Curl_easy *data);
  74. void Curl_ssl_close(struct connectdata *conn, int sockindex);
  75. CURLcode Curl_ssl_shutdown(struct connectdata *conn, int sockindex);
  76. CURLcode Curl_ssl_set_engine(struct Curl_easy *data, const char *engine);
  77. /* Sets engine as default for all SSL operations */
  78. CURLcode Curl_ssl_set_engine_default(struct Curl_easy *data);
  79. struct curl_slist *Curl_ssl_engines_list(struct Curl_easy *data);
  80. /* init the SSL session ID cache */
  81. CURLcode Curl_ssl_initsessions(struct Curl_easy *, size_t);
  82. size_t Curl_ssl_version(char *buffer, size_t size);
  83. bool Curl_ssl_data_pending(const struct connectdata *conn,
  84. int connindex);
  85. int Curl_ssl_check_cxn(struct connectdata *conn);
  86. /* Certificate information list handling. */
  87. void Curl_ssl_free_certinfo(struct Curl_easy *data);
  88. CURLcode Curl_ssl_init_certinfo(struct Curl_easy *data, int num);
  89. CURLcode Curl_ssl_push_certinfo_len(struct Curl_easy *data, int certnum,
  90. const char *label, const char *value,
  91. size_t valuelen);
  92. CURLcode Curl_ssl_push_certinfo(struct Curl_easy *data, int certnum,
  93. const char *label, const char *value);
  94. /* Functions to be used by SSL library adaptation functions */
  95. /* Lock session cache mutex.
  96. * Call this before calling other Curl_ssl_*session* functions
  97. * Caller should unlock this mutex as soon as possible, as it may block
  98. * other SSL connection from making progress.
  99. * The purpose of explicitly locking SSL session cache data is to allow
  100. * individual SSL engines to manage session lifetime in their specific way.
  101. */
  102. void Curl_ssl_sessionid_lock(struct connectdata *conn);
  103. /* Unlock session cache mutex */
  104. void Curl_ssl_sessionid_unlock(struct connectdata *conn);
  105. /* extract a session ID
  106. * Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
  107. * Caller must make sure that the ownership of returned sessionid object
  108. * is properly taken (e.g. its refcount is incremented
  109. * under sessionid mutex).
  110. */
  111. bool Curl_ssl_getsessionid(struct connectdata *conn,
  112. void **ssl_sessionid,
  113. size_t *idsize, /* set 0 if unknown */
  114. int sockindex);
  115. /* add a new session ID
  116. * Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
  117. * Caller must ensure that it has properly shared ownership of this sessionid
  118. * object with cache (e.g. incrementing refcount on success)
  119. */
  120. CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
  121. void *ssl_sessionid,
  122. size_t idsize,
  123. int sockindex);
  124. /* Kill a single session ID entry in the cache
  125. * Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
  126. * This will call engine-specific curlssl_session_free function, which must
  127. * take sessionid object ownership from sessionid cache
  128. * (e.g. decrement refcount).
  129. */
  130. void Curl_ssl_kill_session(struct curl_ssl_session *session);
  131. /* delete a session from the cache
  132. * Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
  133. * This will call engine-specific curlssl_session_free function, which must
  134. * take sessionid object ownership from sessionid cache
  135. * (e.g. decrement refcount).
  136. */
  137. void Curl_ssl_delsessionid(struct connectdata *conn, void *ssl_sessionid);
  138. /* get N random bytes into the buffer */
  139. CURLcode Curl_ssl_random(struct Curl_easy *data, unsigned char *buffer,
  140. size_t length);
  141. CURLcode Curl_ssl_md5sum(unsigned char *tmp, /* input */
  142. size_t tmplen,
  143. unsigned char *md5sum, /* output */
  144. size_t md5len);
  145. /* Check pinned public key. */
  146. CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data,
  147. const char *pinnedpubkey,
  148. const unsigned char *pubkey, size_t pubkeylen);
  149. bool Curl_ssl_cert_status_request(void);
  150. bool Curl_ssl_false_start(void);
  151. #define SSL_SHUTDOWN_TIMEOUT 10000 /* ms */
  152. #else
  153. /* Set the API backend definition to none */
  154. #define CURL_SSL_BACKEND CURLSSLBACKEND_NONE
  155. /* When SSL support is not present, just define away these function calls */
  156. #define Curl_ssl_init() 1
  157. #define Curl_ssl_cleanup() Curl_nop_stmt
  158. #define Curl_ssl_connect(x,y) CURLE_NOT_BUILT_IN
  159. #define Curl_ssl_close_all(x) Curl_nop_stmt
  160. #define Curl_ssl_close(x,y) Curl_nop_stmt
  161. #define Curl_ssl_shutdown(x,y) CURLE_NOT_BUILT_IN
  162. #define Curl_ssl_set_engine(x,y) CURLE_NOT_BUILT_IN
  163. #define Curl_ssl_set_engine_default(x) CURLE_NOT_BUILT_IN
  164. #define Curl_ssl_engines_list(x) NULL
  165. #define Curl_ssl_send(a,b,c,d,e) -1
  166. #define Curl_ssl_recv(a,b,c,d,e) -1
  167. #define Curl_ssl_initsessions(x,y) CURLE_OK
  168. #define Curl_ssl_version(x,y) 0
  169. #define Curl_ssl_data_pending(x,y) 0
  170. #define Curl_ssl_check_cxn(x) 0
  171. #define Curl_ssl_free_certinfo(x) Curl_nop_stmt
  172. #define Curl_ssl_connect_nonblocking(x,y,z) CURLE_NOT_BUILT_IN
  173. #define Curl_ssl_kill_session(x) Curl_nop_stmt
  174. #define Curl_ssl_random(x,y,z) ((void)x, CURLE_NOT_BUILT_IN)
  175. #define Curl_ssl_cert_status_request() FALSE
  176. #define Curl_ssl_false_start() FALSE
  177. #endif
  178. #endif /* HEADER_CURL_VTLS_H */