Imported Upstream version 7.44.0
[platform/upstream/curl.git] / lib / vtls / vtls.h
1 #ifndef HEADER_CURL_VTLS_H
2 #define HEADER_CURL_VTLS_H
3 /***************************************************************************
4  *                                  _   _ ____  _
5  *  Project                     ___| | | |  _ \| |
6  *                             / __| | | | |_) | |
7  *                            | (__| |_| |  _ <| |___
8  *                             \___|\___/|_| \_\_____|
9  *
10  * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, 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 http://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
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
36 #ifndef MAX_PINNED_PUBKEY_SIZE
37 #define MAX_PINNED_PUBKEY_SIZE 1048576 /* 1MB */
38 #endif
39
40 #ifndef MD5_DIGEST_LENGTH
41 #define MD5_DIGEST_LENGTH 16 /* fixed size */
42 #endif
43
44 #ifndef SHA256_DIGEST_LENGTH
45 #define SHA256_DIGEST_LENGTH 32 /* fixed size */
46 #endif
47
48 /* see http://tools.ietf.org/html/draft-ietf-tls-applayerprotoneg-04 */
49 #define ALPN_HTTP_1_1_LENGTH 8
50 #define ALPN_HTTP_1_1 "http/1.1"
51
52 bool Curl_ssl_config_matches(struct ssl_config_data* data,
53                              struct ssl_config_data* needle);
54 bool Curl_clone_ssl_config(struct ssl_config_data* source,
55                            struct ssl_config_data* dest);
56 void Curl_free_ssl_config(struct ssl_config_data* sslc);
57
58 unsigned int Curl_rand(struct SessionHandle *);
59
60 int Curl_ssl_backend(void);
61
62 #ifdef USE_SSL
63 int Curl_ssl_init(void);
64 void Curl_ssl_cleanup(void);
65 CURLcode Curl_ssl_connect(struct connectdata *conn, int sockindex);
66 CURLcode Curl_ssl_connect_nonblocking(struct connectdata *conn,
67                                       int sockindex,
68                                       bool *done);
69 /* tell the SSL stuff to close down all open information regarding
70    connections (and thus session ID caching etc) */
71 void Curl_ssl_close_all(struct SessionHandle *data);
72 void Curl_ssl_close(struct connectdata *conn, int sockindex);
73 CURLcode Curl_ssl_shutdown(struct connectdata *conn, int sockindex);
74 CURLcode Curl_ssl_set_engine(struct SessionHandle *data, const char *engine);
75 /* Sets engine as default for all SSL operations */
76 CURLcode Curl_ssl_set_engine_default(struct SessionHandle *data);
77 struct curl_slist *Curl_ssl_engines_list(struct SessionHandle *data);
78
79 /* init the SSL session ID cache */
80 CURLcode Curl_ssl_initsessions(struct SessionHandle *, size_t);
81 size_t Curl_ssl_version(char *buffer, size_t size);
82 bool Curl_ssl_data_pending(const struct connectdata *conn,
83                            int connindex);
84 int Curl_ssl_check_cxn(struct connectdata *conn);
85
86 /* Certificate information list handling. */
87
88 void Curl_ssl_free_certinfo(struct SessionHandle *data);
89 CURLcode Curl_ssl_init_certinfo(struct SessionHandle * data, int num);
90 CURLcode Curl_ssl_push_certinfo_len(struct SessionHandle * data, int certnum,
91                                     const char * label, const char * value,
92                                     size_t valuelen);
93 CURLcode Curl_ssl_push_certinfo(struct SessionHandle * data, int certnum,
94                                 const char * label, const char * value);
95
96 /* Functions to be used by SSL library adaptation functions */
97
98 /* extract a session ID */
99 bool Curl_ssl_getsessionid(struct connectdata *conn,
100                            void **ssl_sessionid,
101                            size_t *idsize) /* set 0 if unknown */;
102 /* add a new session ID */
103 CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
104                                void *ssl_sessionid,
105                                size_t idsize);
106 /* Kill a single session ID entry in the cache */
107 void Curl_ssl_kill_session(struct curl_ssl_session *session);
108 /* delete a session from the cache */
109 void Curl_ssl_delsessionid(struct connectdata *conn, void *ssl_sessionid);
110
111 /* get N random bytes into the buffer, return 0 if a find random is filled
112    in */
113 int Curl_ssl_random(struct SessionHandle *data, unsigned char *buffer,
114                     size_t length);
115 CURLcode Curl_ssl_md5sum(unsigned char *tmp, /* input */
116                          size_t tmplen,
117                          unsigned char *md5sum, /* output */
118                          size_t md5len);
119 /* Check pinned public key. */
120 CURLcode Curl_pin_peer_pubkey(const char *pinnedpubkey,
121                               const unsigned char *pubkey, size_t pubkeylen);
122
123 bool Curl_ssl_cert_status_request(void);
124
125 bool Curl_ssl_false_start(void);
126
127 #define SSL_SHUTDOWN_TIMEOUT 10000 /* ms */
128
129 #else
130 /* Set the API backend definition to none */
131 #define CURL_SSL_BACKEND CURLSSLBACKEND_NONE
132
133 /* When SSL support is not present, just define away these function calls */
134 #define Curl_ssl_init() 1
135 #define Curl_ssl_cleanup() Curl_nop_stmt
136 #define Curl_ssl_connect(x,y) CURLE_NOT_BUILT_IN
137 #define Curl_ssl_close_all(x) Curl_nop_stmt
138 #define Curl_ssl_close(x,y) Curl_nop_stmt
139 #define Curl_ssl_shutdown(x,y) CURLE_NOT_BUILT_IN
140 #define Curl_ssl_set_engine(x,y) CURLE_NOT_BUILT_IN
141 #define Curl_ssl_set_engine_default(x) CURLE_NOT_BUILT_IN
142 #define Curl_ssl_engines_list(x) NULL
143 #define Curl_ssl_send(a,b,c,d,e) -1
144 #define Curl_ssl_recv(a,b,c,d,e) -1
145 #define Curl_ssl_initsessions(x,y) CURLE_OK
146 #define Curl_ssl_version(x,y) 0
147 #define Curl_ssl_data_pending(x,y) 0
148 #define Curl_ssl_check_cxn(x) 0
149 #define Curl_ssl_free_certinfo(x) Curl_nop_stmt
150 #define Curl_ssl_connect_nonblocking(x,y,z) CURLE_NOT_BUILT_IN
151 #define Curl_ssl_kill_session(x) Curl_nop_stmt
152 #define Curl_ssl_random(x,y,z) ((void)x, CURLE_NOT_BUILT_IN)
153 #define Curl_ssl_cert_status_request() FALSE
154 #define Curl_ssl_false_start() FALSE
155 #endif
156
157 #endif /* HEADER_CURL_VTLS_H */