1 | #ifndef HEADER_CURL_VTLS_INT_H
|
---|
2 | #define HEADER_CURL_VTLS_INT_H
|
---|
3 | /***************************************************************************
|
---|
4 | * _ _ ____ _
|
---|
5 | * Project ___| | | | _ \| |
|
---|
6 | * / __| | | | |_) | |
|
---|
7 | * | (__| |_| | _ <| |___
|
---|
8 | * \___|\___/|_| \_\_____|
|
---|
9 | *
|
---|
10 | * Copyright (C) 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.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 | * SPDX-License-Identifier: curl
|
---|
24 | *
|
---|
25 | ***************************************************************************/
|
---|
26 | #include "curl_setup.h"
|
---|
27 | #include "cfilters.h"
|
---|
28 | #include "urldata.h"
|
---|
29 |
|
---|
30 | #ifdef USE_SSL
|
---|
31 |
|
---|
32 | /* see https://www.iana.org/assignments/tls-extensiontype-values/ */
|
---|
33 | #define ALPN_HTTP_1_1_LENGTH 8
|
---|
34 | #define ALPN_HTTP_1_1 "http/1.1"
|
---|
35 | #define ALPN_H2_LENGTH 2
|
---|
36 | #define ALPN_H2 "h2"
|
---|
37 | #define ALPN_H3_LENGTH 2
|
---|
38 | #define ALPN_H3 "h3"
|
---|
39 |
|
---|
40 | /* conservative sizes on the ALPN entries and count we are handling,
|
---|
41 | * we can increase these if we ever feel the need or have to accommodate
|
---|
42 | * ALPN strings from the "outside". */
|
---|
43 | #define ALPN_NAME_MAX 10
|
---|
44 | #define ALPN_ENTRIES_MAX 3
|
---|
45 | #define ALPN_PROTO_BUF_MAX (ALPN_ENTRIES_MAX * (ALPN_NAME_MAX + 1))
|
---|
46 |
|
---|
47 | struct alpn_spec {
|
---|
48 | const char entries[ALPN_ENTRIES_MAX][ALPN_NAME_MAX];
|
---|
49 | size_t count; /* number of entries */
|
---|
50 | };
|
---|
51 |
|
---|
52 | struct alpn_proto_buf {
|
---|
53 | unsigned char data[ALPN_PROTO_BUF_MAX];
|
---|
54 | int len;
|
---|
55 | };
|
---|
56 |
|
---|
57 | CURLcode Curl_alpn_to_proto_buf(struct alpn_proto_buf *buf,
|
---|
58 | const struct alpn_spec *spec);
|
---|
59 | CURLcode Curl_alpn_to_proto_str(struct alpn_proto_buf *buf,
|
---|
60 | const struct alpn_spec *spec);
|
---|
61 |
|
---|
62 | CURLcode Curl_alpn_set_negotiated(struct Curl_cfilter *cf,
|
---|
63 | struct Curl_easy *data,
|
---|
64 | const unsigned char *proto,
|
---|
65 | size_t proto_len);
|
---|
66 |
|
---|
67 | /* Information in each SSL cfilter context: cf->ctx */
|
---|
68 | struct ssl_connect_data {
|
---|
69 | ssl_connection_state state;
|
---|
70 | ssl_connect_state connecting_state;
|
---|
71 | struct ssl_peer peer;
|
---|
72 | const struct alpn_spec *alpn; /* ALPN to use or NULL for none */
|
---|
73 | void *backend; /* vtls backend specific props */
|
---|
74 | struct cf_call_data call_data; /* data handle used in current call */
|
---|
75 | struct curltime handshake_done; /* time when handshake finished */
|
---|
76 | int port; /* remote port at origin */
|
---|
77 | BIT(use_alpn); /* if ALPN shall be used in handshake */
|
---|
78 | BIT(reused_session); /* session-ID was reused for this */
|
---|
79 | BIT(peer_closed); /* peer has closed connection */
|
---|
80 | };
|
---|
81 |
|
---|
82 |
|
---|
83 | #undef CF_CTX_CALL_DATA
|
---|
84 | #define CF_CTX_CALL_DATA(cf) \
|
---|
85 | ((struct ssl_connect_data *)(cf)->ctx)->call_data
|
---|
86 |
|
---|
87 |
|
---|
88 | /* Definitions for SSL Implementations */
|
---|
89 |
|
---|
90 | struct Curl_ssl {
|
---|
91 | /*
|
---|
92 | * This *must* be the first entry to allow returning the list of available
|
---|
93 | * backends in curl_global_sslset().
|
---|
94 | */
|
---|
95 | curl_ssl_backend info;
|
---|
96 | unsigned int supports; /* bitfield, see above */
|
---|
97 | size_t sizeof_ssl_backend_data;
|
---|
98 |
|
---|
99 | int (*init)(void);
|
---|
100 | void (*cleanup)(void);
|
---|
101 |
|
---|
102 | size_t (*version)(char *buffer, size_t size);
|
---|
103 | int (*check_cxn)(struct Curl_cfilter *cf, struct Curl_easy *data);
|
---|
104 | int (*shut_down)(struct Curl_cfilter *cf,
|
---|
105 | struct Curl_easy *data);
|
---|
106 | bool (*data_pending)(struct Curl_cfilter *cf,
|
---|
107 | const struct Curl_easy *data);
|
---|
108 |
|
---|
109 | /* return 0 if a find random is filled in */
|
---|
110 | CURLcode (*random)(struct Curl_easy *data, unsigned char *entropy,
|
---|
111 | size_t length);
|
---|
112 | bool (*cert_status_request)(void);
|
---|
113 |
|
---|
114 | CURLcode (*connect_blocking)(struct Curl_cfilter *cf,
|
---|
115 | struct Curl_easy *data);
|
---|
116 | CURLcode (*connect_nonblocking)(struct Curl_cfilter *cf,
|
---|
117 | struct Curl_easy *data,
|
---|
118 | bool *done);
|
---|
119 |
|
---|
120 | /* During handshake, adjust the pollset to include the socket
|
---|
121 | * for POLLOUT or POLLIN as needed.
|
---|
122 | * Mandatory. */
|
---|
123 | void (*adjust_pollset)(struct Curl_cfilter *cf, struct Curl_easy *data,
|
---|
124 | struct easy_pollset *ps);
|
---|
125 | void *(*get_internals)(struct ssl_connect_data *connssl, CURLINFO info);
|
---|
126 | void (*close)(struct Curl_cfilter *cf, struct Curl_easy *data);
|
---|
127 | void (*close_all)(struct Curl_easy *data);
|
---|
128 | void (*session_free)(void *ptr);
|
---|
129 |
|
---|
130 | CURLcode (*set_engine)(struct Curl_easy *data, const char *engine);
|
---|
131 | CURLcode (*set_engine_default)(struct Curl_easy *data);
|
---|
132 | struct curl_slist *(*engines_list)(struct Curl_easy *data);
|
---|
133 |
|
---|
134 | bool (*false_start)(void);
|
---|
135 | CURLcode (*sha256sum)(const unsigned char *input, size_t inputlen,
|
---|
136 | unsigned char *sha256sum, size_t sha256sumlen);
|
---|
137 |
|
---|
138 | bool (*attach_data)(struct Curl_cfilter *cf, struct Curl_easy *data);
|
---|
139 | void (*detach_data)(struct Curl_cfilter *cf, struct Curl_easy *data);
|
---|
140 |
|
---|
141 | void (*free_multi_ssl_backend_data)(struct multi_ssl_backend_data *mbackend);
|
---|
142 |
|
---|
143 | ssize_t (*recv_plain)(struct Curl_cfilter *cf, struct Curl_easy *data,
|
---|
144 | char *buf, size_t len, CURLcode *code);
|
---|
145 | ssize_t (*send_plain)(struct Curl_cfilter *cf, struct Curl_easy *data,
|
---|
146 | const void *mem, size_t len, CURLcode *code);
|
---|
147 |
|
---|
148 | };
|
---|
149 |
|
---|
150 | extern const struct Curl_ssl *Curl_ssl;
|
---|
151 |
|
---|
152 |
|
---|
153 | int Curl_none_init(void);
|
---|
154 | void Curl_none_cleanup(void);
|
---|
155 | int Curl_none_shutdown(struct Curl_cfilter *cf, struct Curl_easy *data);
|
---|
156 | int Curl_none_check_cxn(struct Curl_cfilter *cf, struct Curl_easy *data);
|
---|
157 | CURLcode Curl_none_random(struct Curl_easy *data, unsigned char *entropy,
|
---|
158 | size_t length);
|
---|
159 | void Curl_none_close_all(struct Curl_easy *data);
|
---|
160 | void Curl_none_session_free(void *ptr);
|
---|
161 | bool Curl_none_data_pending(struct Curl_cfilter *cf,
|
---|
162 | const struct Curl_easy *data);
|
---|
163 | bool Curl_none_cert_status_request(void);
|
---|
164 | CURLcode Curl_none_set_engine(struct Curl_easy *data, const char *engine);
|
---|
165 | CURLcode Curl_none_set_engine_default(struct Curl_easy *data);
|
---|
166 | struct curl_slist *Curl_none_engines_list(struct Curl_easy *data);
|
---|
167 | bool Curl_none_false_start(void);
|
---|
168 | void Curl_ssl_adjust_pollset(struct Curl_cfilter *cf, struct Curl_easy *data,
|
---|
169 | struct easy_pollset *ps);
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * Get the SSL filter below the given one or NULL if there is none.
|
---|
173 | */
|
---|
174 | bool Curl_ssl_cf_is_proxy(struct Curl_cfilter *cf);
|
---|
175 |
|
---|
176 | /* extract a session ID
|
---|
177 | * Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
|
---|
178 | * Caller must make sure that the ownership of returned sessionid object
|
---|
179 | * is properly taken (e.g. its refcount is incremented
|
---|
180 | * under sessionid mutex).
|
---|
181 | */
|
---|
182 | bool Curl_ssl_getsessionid(struct Curl_cfilter *cf,
|
---|
183 | struct Curl_easy *data,
|
---|
184 | void **ssl_sessionid,
|
---|
185 | size_t *idsize); /* set 0 if unknown */
|
---|
186 | /* add a new session ID
|
---|
187 | * Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
|
---|
188 | * Caller must ensure that it has properly shared ownership of this sessionid
|
---|
189 | * object with cache (e.g. incrementing refcount on success)
|
---|
190 | */
|
---|
191 | CURLcode Curl_ssl_addsessionid(struct Curl_cfilter *cf,
|
---|
192 | struct Curl_easy *data,
|
---|
193 | void *ssl_sessionid,
|
---|
194 | size_t idsize,
|
---|
195 | bool *added);
|
---|
196 |
|
---|
197 | #include "openssl.h" /* OpenSSL versions */
|
---|
198 | #include "gtls.h" /* GnuTLS versions */
|
---|
199 | #include "wolfssl.h" /* wolfSSL versions */
|
---|
200 | #include "schannel.h" /* Schannel SSPI version */
|
---|
201 | #include "sectransp.h" /* SecureTransport (Darwin) version */
|
---|
202 | #include "mbedtls.h" /* mbedTLS versions */
|
---|
203 | #include "bearssl.h" /* BearSSL versions */
|
---|
204 | #include "rustls.h" /* rustls versions */
|
---|
205 |
|
---|
206 | #endif /* USE_SSL */
|
---|
207 |
|
---|
208 | #endif /* HEADER_CURL_VTLS_INT_H */
|
---|