• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, <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 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 };
80 
81 
82 #undef CF_CTX_CALL_DATA
83 #define CF_CTX_CALL_DATA(cf)  \
84   ((struct ssl_connect_data *)(cf)->ctx)->call_data
85 
86 
87 /* Definitions for SSL Implementations */
88 
89 struct Curl_ssl {
90   /*
91    * This *must* be the first entry to allow returning the list of available
92    * backends in curl_global_sslset().
93    */
94   curl_ssl_backend info;
95   unsigned int supports; /* bitfield, see above */
96   size_t sizeof_ssl_backend_data;
97 
98   int (*init)(void);
99   void (*cleanup)(void);
100 
101   size_t (*version)(char *buffer, size_t size);
102   int (*check_cxn)(struct Curl_cfilter *cf, struct Curl_easy *data);
103   int (*shut_down)(struct Curl_cfilter *cf,
104                    struct Curl_easy *data);
105   bool (*data_pending)(struct Curl_cfilter *cf,
106                        const struct Curl_easy *data);
107 
108   /* return 0 if a find random is filled in */
109   CURLcode (*random)(struct Curl_easy *data, unsigned char *entropy,
110                      size_t length);
111   bool (*cert_status_request)(void);
112 
113   CURLcode (*connect_blocking)(struct Curl_cfilter *cf,
114                                struct Curl_easy *data);
115   CURLcode (*connect_nonblocking)(struct Curl_cfilter *cf,
116                                   struct Curl_easy *data,
117                                   bool *done);
118 
119   /* During handshake, adjust the pollset to include the socket
120    * for POLLOUT or POLLIN as needed.
121    * Mandatory. */
122   void (*adjust_pollset)(struct Curl_cfilter *cf, struct Curl_easy *data,
123                           struct easy_pollset *ps);
124   void *(*get_internals)(struct ssl_connect_data *connssl, CURLINFO info);
125   void (*close)(struct Curl_cfilter *cf, struct Curl_easy *data);
126   void (*close_all)(struct Curl_easy *data);
127   void (*session_free)(void *ptr);
128 
129   CURLcode (*set_engine)(struct Curl_easy *data, const char *engine);
130   CURLcode (*set_engine_default)(struct Curl_easy *data);
131   struct curl_slist *(*engines_list)(struct Curl_easy *data);
132 
133   bool (*false_start)(void);
134   CURLcode (*sha256sum)(const unsigned char *input, size_t inputlen,
135                     unsigned char *sha256sum, size_t sha256sumlen);
136 
137   bool (*attach_data)(struct Curl_cfilter *cf, struct Curl_easy *data);
138   void (*detach_data)(struct Curl_cfilter *cf, struct Curl_easy *data);
139 
140   void (*free_multi_ssl_backend_data)(struct multi_ssl_backend_data *mbackend);
141 
142   ssize_t (*recv_plain)(struct Curl_cfilter *cf, struct Curl_easy *data,
143                         char *buf, size_t len, CURLcode *code);
144   ssize_t (*send_plain)(struct Curl_cfilter *cf, struct Curl_easy *data,
145                         const void *mem, size_t len, CURLcode *code);
146 
147 };
148 
149 extern const struct Curl_ssl *Curl_ssl;
150 
151 
152 int Curl_none_init(void);
153 void Curl_none_cleanup(void);
154 int Curl_none_shutdown(struct Curl_cfilter *cf, struct Curl_easy *data);
155 int Curl_none_check_cxn(struct Curl_cfilter *cf, struct Curl_easy *data);
156 CURLcode Curl_none_random(struct Curl_easy *data, unsigned char *entropy,
157                           size_t length);
158 void Curl_none_close_all(struct Curl_easy *data);
159 void Curl_none_session_free(void *ptr);
160 bool Curl_none_data_pending(struct Curl_cfilter *cf,
161                             const struct Curl_easy *data);
162 bool Curl_none_cert_status_request(void);
163 CURLcode Curl_none_set_engine(struct Curl_easy *data, const char *engine);
164 CURLcode Curl_none_set_engine_default(struct Curl_easy *data);
165 struct curl_slist *Curl_none_engines_list(struct Curl_easy *data);
166 bool Curl_none_false_start(void);
167 void Curl_ssl_adjust_pollset(struct Curl_cfilter *cf, struct Curl_easy *data,
168                               struct easy_pollset *ps);
169 
170 /**
171  * Get the SSL filter below the given one or NULL if there is none.
172  */
173 bool Curl_ssl_cf_is_proxy(struct Curl_cfilter *cf);
174 
175 /* extract a session ID
176  * Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
177  * Caller must make sure that the ownership of returned sessionid object
178  * is properly taken (e.g. its refcount is incremented
179  * under sessionid mutex).
180  */
181 bool Curl_ssl_getsessionid(struct Curl_cfilter *cf,
182                            struct Curl_easy *data,
183                            void **ssl_sessionid,
184                            size_t *idsize); /* set 0 if unknown */
185 /* add a new session ID
186  * Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
187  * Caller must ensure that it has properly shared ownership of this sessionid
188  * object with cache (e.g. incrementing refcount on success)
189  */
190 CURLcode Curl_ssl_addsessionid(struct Curl_cfilter *cf,
191                                struct Curl_easy *data,
192                                void *ssl_sessionid,
193                                size_t idsize,
194                                bool *added);
195 
196 #include "openssl.h"        /* OpenSSL versions */
197 #include "gtls.h"           /* GnuTLS versions */
198 #include "wolfssl.h"        /* wolfSSL versions */
199 #include "schannel.h"       /* Schannel SSPI version */
200 #include "sectransp.h"      /* SecureTransport (Darwin) version */
201 #include "mbedtls.h"        /* mbedTLS versions */
202 #include "bearssl.h"        /* BearSSL versions */
203 #include "rustls.h"         /* rustls versions */
204 
205 #endif /* USE_SSL */
206 
207 #endif /* HEADER_CURL_VTLS_INT_H */
208