1 #ifndef HEADER_CURL_VTLS_H
2 #define HEADER_CURL_VTLS_H
3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ***************************************************************************/
24 #include "curl_setup.h"
26 #include "openssl.h" /* OpenSSL versions */
27 #include "gtls.h" /* GnuTLS versions */
28 #include "nssg.h" /* NSS versions */
29 #include "gskit.h" /* Global Secure ToolKit versions */
30 #include "polarssl.h" /* PolarSSL versions */
31 #include "axtls.h" /* axTLS versions */
32 #include "cyassl.h" /* CyaSSL versions */
33 #include "schannel.h" /* Schannel SSPI version */
34 #include "darwinssl.h" /* SecureTransport (Darwin) version */
35 #include "mbedtls.h" /* mbedTLS versions */
37 #ifndef MAX_PINNED_PUBKEY_SIZE
38 #define MAX_PINNED_PUBKEY_SIZE 1048576 /* 1MB */
41 #ifndef MD5_DIGEST_LENGTH
42 #define MD5_DIGEST_LENGTH 16 /* fixed size */
45 #ifndef SHA256_DIGEST_LENGTH
46 #define SHA256_DIGEST_LENGTH 32 /* fixed size */
49 /* see https://tools.ietf.org/html/draft-ietf-tls-applayerprotoneg-04 */
50 #define ALPN_HTTP_1_1_LENGTH 8
51 #define ALPN_HTTP_1_1 "http/1.1"
53 /* set of helper macros for the backends to access the correct fields. For the
54 proxy or for the remote host - to properly support HTTPS proxy */
56 #define SSL_IS_PROXY() (CURLPROXY_HTTPS == conn->http_proxy.proxytype && \
57 ssl_connection_complete != conn->proxy_ssl[conn->sock[SECONDARYSOCKET] == \
58 CURL_SOCKET_BAD ? FIRSTSOCKET : SECONDARYSOCKET].state)
59 #define SSL_SET_OPTION(var) (SSL_IS_PROXY() ? data->set.proxy_ssl.var : \
61 #define SSL_CONN_CONFIG(var) (SSL_IS_PROXY() ? \
62 conn->proxy_ssl_config.var : conn->ssl_config.var)
64 bool Curl_ssl_config_matches(struct ssl_primary_config* data,
65 struct ssl_primary_config* needle);
66 bool Curl_clone_primary_ssl_config(struct ssl_primary_config *source,
67 struct ssl_primary_config *dest);
68 void Curl_free_primary_ssl_config(struct ssl_primary_config* sslc);
69 int Curl_ssl_getsock(struct connectdata *conn, curl_socket_t *socks,
72 int Curl_ssl_backend(void);
75 int Curl_ssl_init(void);
76 void Curl_ssl_cleanup(void);
77 CURLcode Curl_ssl_connect(struct connectdata *conn, int sockindex);
78 CURLcode Curl_ssl_connect_nonblocking(struct connectdata *conn,
81 /* tell the SSL stuff to close down all open information regarding
82 connections (and thus session ID caching etc) */
83 void Curl_ssl_close_all(struct Curl_easy *data);
84 void Curl_ssl_close(struct connectdata *conn, int sockindex);
85 CURLcode Curl_ssl_shutdown(struct connectdata *conn, int sockindex);
86 CURLcode Curl_ssl_set_engine(struct Curl_easy *data, const char *engine);
87 /* Sets engine as default for all SSL operations */
88 CURLcode Curl_ssl_set_engine_default(struct Curl_easy *data);
89 struct curl_slist *Curl_ssl_engines_list(struct Curl_easy *data);
91 /* init the SSL session ID cache */
92 CURLcode Curl_ssl_initsessions(struct Curl_easy *, size_t);
93 size_t Curl_ssl_version(char *buffer, size_t size);
94 bool Curl_ssl_data_pending(const struct connectdata *conn,
96 int Curl_ssl_check_cxn(struct connectdata *conn);
98 /* Certificate information list handling. */
100 void Curl_ssl_free_certinfo(struct Curl_easy *data);
101 CURLcode Curl_ssl_init_certinfo(struct Curl_easy *data, int num);
102 CURLcode Curl_ssl_push_certinfo_len(struct Curl_easy *data, int certnum,
103 const char *label, const char *value,
105 CURLcode Curl_ssl_push_certinfo(struct Curl_easy *data, int certnum,
106 const char *label, const char *value);
108 /* Functions to be used by SSL library adaptation functions */
110 /* Lock session cache mutex.
111 * Call this before calling other Curl_ssl_*session* functions
112 * Caller should unlock this mutex as soon as possible, as it may block
113 * other SSL connection from making progress.
114 * The purpose of explicitly locking SSL session cache data is to allow
115 * individual SSL engines to manage session lifetime in their specific way.
117 void Curl_ssl_sessionid_lock(struct connectdata *conn);
119 /* Unlock session cache mutex */
120 void Curl_ssl_sessionid_unlock(struct connectdata *conn);
122 /* extract a session ID
123 * Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
124 * Caller must make sure that the ownership of returned sessionid object
125 * is properly taken (e.g. its refcount is incremented
126 * under sessionid mutex).
128 bool Curl_ssl_getsessionid(struct connectdata *conn,
129 void **ssl_sessionid,
130 size_t *idsize, /* set 0 if unknown */
132 /* add a new session ID
133 * Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
134 * Caller must ensure that it has properly shared ownership of this sessionid
135 * object with cache (e.g. incrementing refcount on success)
137 CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
141 /* Kill a single session ID entry in the cache
142 * Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
143 * This will call engine-specific curlssl_session_free function, which must
144 * take sessionid object ownership from sessionid cache
145 * (e.g. decrement refcount).
147 void Curl_ssl_kill_session(struct curl_ssl_session *session);
148 /* delete a session from the cache
149 * Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
150 * This will call engine-specific curlssl_session_free function, which must
151 * take sessionid object ownership from sessionid cache
152 * (e.g. decrement refcount).
154 void Curl_ssl_delsessionid(struct connectdata *conn, void *ssl_sessionid);
156 /* get N random bytes into the buffer */
157 CURLcode Curl_ssl_random(struct Curl_easy *data, unsigned char *buffer,
159 CURLcode Curl_ssl_md5sum(unsigned char *tmp, /* input */
161 unsigned char *md5sum, /* output */
163 /* Check pinned public key. */
164 CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data,
165 const char *pinnedpubkey,
166 const unsigned char *pubkey, size_t pubkeylen);
168 bool Curl_ssl_cert_status_request(void);
170 bool Curl_ssl_false_start(void);
172 #define SSL_SHUTDOWN_TIMEOUT 10000 /* ms */
175 /* Set the API backend definition to none */
176 #define CURL_SSL_BACKEND CURLSSLBACKEND_NONE
178 /* When SSL support is not present, just define away these function calls */
179 #define Curl_ssl_init() 1
180 #define Curl_ssl_cleanup() Curl_nop_stmt
181 #define Curl_ssl_connect(x,y) CURLE_NOT_BUILT_IN
182 #define Curl_ssl_close_all(x) Curl_nop_stmt
183 #define Curl_ssl_close(x,y) Curl_nop_stmt
184 #define Curl_ssl_shutdown(x,y) CURLE_NOT_BUILT_IN
185 #define Curl_ssl_set_engine(x,y) CURLE_NOT_BUILT_IN
186 #define Curl_ssl_set_engine_default(x) CURLE_NOT_BUILT_IN
187 #define Curl_ssl_engines_list(x) NULL
188 #define Curl_ssl_send(a,b,c,d,e) -1
189 #define Curl_ssl_recv(a,b,c,d,e) -1
190 #define Curl_ssl_initsessions(x,y) CURLE_OK
191 #define Curl_ssl_version(x,y) 0
192 #define Curl_ssl_data_pending(x,y) 0
193 #define Curl_ssl_check_cxn(x) 0
194 #define Curl_ssl_free_certinfo(x) Curl_nop_stmt
195 #define Curl_ssl_connect_nonblocking(x,y,z) CURLE_NOT_BUILT_IN
196 #define Curl_ssl_kill_session(x) Curl_nop_stmt
197 #define Curl_ssl_random(x,y,z) ((void)x, CURLE_NOT_BUILT_IN)
198 #define Curl_ssl_cert_status_request() FALSE
199 #define Curl_ssl_false_start() FALSE
202 #endif /* HEADER_CURL_VTLS_H */