xref: /curl/lib/vtls/gtls.h (revision fe8399f0)
1 #ifndef HEADER_CURL_GTLS_H
2 #define HEADER_CURL_GTLS_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 
27 #include "curl_setup.h"
28 #include <curl/curl.h>
29 
30 #ifdef USE_GNUTLS
31 
32 #include <gnutls/gnutls.h>
33 #include "timeval.h"
34 
35 #ifdef HAVE_GNUTLS_SRP
36 /* the function exists */
37 #ifdef USE_TLS_SRP
38 /* the functionality is not disabled */
39 #define USE_GNUTLS_SRP
40 #endif
41 #endif
42 
43 struct Curl_easy;
44 struct Curl_cfilter;
45 struct ssl_primary_config;
46 struct ssl_config_data;
47 struct ssl_peer;
48 struct ssl_connect_data;
49 
50 struct gtls_shared_creds {
51   gnutls_certificate_credentials_t creds;
52   char *CAfile; /* CAfile path used to generate X509 store */
53   struct curltime time; /* when the shared creds was created */
54   size_t refcount;
55   BIT(trust_setup); /* x509 anchors + CRLs have been set up */
56 };
57 
58 CURLcode Curl_gtls_shared_creds_create(struct Curl_easy *data,
59                                        struct gtls_shared_creds **pcreds);
60 CURLcode Curl_gtls_shared_creds_up_ref(struct gtls_shared_creds *creds);
61 void Curl_gtls_shared_creds_free(struct gtls_shared_creds **pcreds);
62 
63 struct gtls_ctx {
64   gnutls_session_t session;
65   struct gtls_shared_creds *shared_creds;
66 #ifdef USE_GNUTLS_SRP
67   gnutls_srp_client_credentials_t srp_client_cred;
68 #endif
69   CURLcode io_result; /* result of last IO cfilter operation */
70   BIT(sent_shutdown);
71 };
72 
73 typedef CURLcode Curl_gtls_ctx_setup_cb(struct Curl_cfilter *cf,
74                                         struct Curl_easy *data,
75                                         void *user_data);
76 
77 CURLcode Curl_gtls_ctx_init(struct gtls_ctx *gctx,
78                             struct Curl_cfilter *cf,
79                             struct Curl_easy *data,
80                             struct ssl_peer *peer,
81                             const unsigned char *alpn, size_t alpn_len,
82                             struct ssl_connect_data *connssl,
83                             Curl_gtls_ctx_setup_cb *cb_setup,
84                             void *cb_user_data,
85                             void *ssl_user_data);
86 
87 CURLcode Curl_gtls_client_trust_setup(struct Curl_cfilter *cf,
88                                       struct Curl_easy *data,
89                                       struct gtls_ctx *gtls);
90 
91 CURLcode Curl_gtls_verifyserver(struct Curl_easy *data,
92                                 gnutls_session_t session,
93                                 struct ssl_primary_config *config,
94                                 struct ssl_config_data *ssl_config,
95                                 struct ssl_peer *peer,
96                                 const char *pinned_key);
97 
98 /* Extract TLS session and place in cache, if configured. */
99 CURLcode Curl_gtls_update_session_id(struct Curl_cfilter *cf,
100                                      struct Curl_easy *data,
101                                      gnutls_session_t session,
102                                      struct ssl_peer *peer,
103                                      const char *alpn);
104 
105 extern const struct Curl_ssl Curl_ssl_gnutls;
106 
107 #endif /* USE_GNUTLS */
108 #endif /* HEADER_CURL_GTLS_H */
109