Squid Web Cache master
Loading...
Searching...
No Matches
forward.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#ifndef SQUID_SRC_SECURITY_FORWARD_H
10#define SQUID_SRC_SECURITY_FORWARD_H
11
12#include "base/CbDataList.h"
13#include "base/forward.h"
14#include "base/ToCpp.h"
16
17#if HAVE_LIBGNUTLS
18#if HAVE_GNUTLS_ABSTRACT_H
19#include <gnutls/abstract.h>
20#endif
21#endif /* HAVE_LIBGNUTLS */
22#include <list>
23#include <limits>
24#include <memory>
25#if USE_OPENSSL
26#include "compat/openssl.h"
27#if HAVE_OPENSSL_BN_H
28#include <openssl/bn.h>
29#endif
30#if HAVE_OPENSSL_ERR_H
31#include <openssl/err.h>
32#endif
33#if HAVE_OPENSSL_RSA_H
34#include <openssl/rsa.h>
35#endif
36#if HAVE_OPENSSL_X509_H
37#include <openssl/x509.h>
38#endif
39#endif /* USE_OPENSSL */
40#include <unordered_set>
41
42#if USE_OPENSSL
43// Macro to be used to define the C++ wrapper functor of the sk_*_pop_free
44// OpenSSL family of functions. The C++ functor is suffixed with the _free_wrapper
45// extension
46#define sk_dtor_wrapper(sk_object, argument_type, freefunction) \
47 struct sk_object ## _free_wrapper { \
48 void operator()(argument_type a) { sk_object ## _pop_free(a, freefunction); } \
49 }
50#endif /* USE_OPENSSL */
51
52/* flags a SSL connection can be configured with */
53#define SSL_FLAG_NO_DEFAULT_CA (1<<0)
54#define SSL_FLAG_DELAYED_AUTH (1<<1)
55#define SSL_FLAG_DONT_VERIFY_PEER (1<<2)
56#define SSL_FLAG_DONT_VERIFY_DOMAIN (1<<3)
57#define SSL_FLAG_NO_SESSION_REUSE (1<<4)
58#define SSL_FLAG_VERIFY_CRL (1<<5)
59#define SSL_FLAG_VERIFY_CRL_ALL (1<<6)
60#define SSL_FLAG_CONDITIONAL_AUTH (1<<7)
61
62#if !USE_OPENSSL && !HAVE_LIBGNUTLS
67struct notls_x509 {};
68#endif
69
71namespace Security
72{
73
74class CertError;
77
78#if USE_OPENSSL
79typedef X509 Certificate;
80#elif HAVE_LIBGNUTLS
81typedef struct gnutls_x509_crt_int Certificate;
82#else
83typedef struct notls_x509 Certificate;
84#endif
85
86#if USE_OPENSSL
87CtoCpp1(X509_free, X509 *);
89#elif HAVE_LIBGNUTLS
90typedef std::shared_ptr<struct gnutls_x509_crt_int> CertPointer;
91#else
92typedef std::shared_ptr<Certificate> CertPointer;
93#endif
94
95#if USE_OPENSSL
96CtoCpp1(X509_CRL_free, X509_CRL *);
98#elif HAVE_LIBGNUTLS
99CtoCpp1(gnutls_x509_crl_deinit, gnutls_x509_crl_t);
101#else
102typedef void *CrlPointer;
103#endif
104
105typedef std::list<Security::CertPointer> CertList;
106
107typedef std::list<Security::CrlPointer> CertRevokeList;
108
109#if USE_OPENSSL
110CtoCpp1(EVP_PKEY_free, EVP_PKEY *)
112#elif HAVE_LIBGNUTLS
113using PrivateKeyPointer = std::shared_ptr<struct gnutls_x509_privkey_int>;
114#else
115using PrivateKeyPointer = std::shared_ptr<void>;
116#endif
117
118#if USE_OPENSSL
119#if OPENSSL_VERSION_MAJOR < 3
120CtoCpp1(DH_free, DH *);
122#else
123using DhePointer = PrivateKeyPointer;
124#endif
125#elif HAVE_LIBGNUTLS
126using DhePointer = void *;
127#else
128using DhePointer = void *;
129#endif
130
131class EncryptorAnswer;
132
134typedef int ErrorCode;
135
137#if USE_OPENSSL
141typedef unsigned long LibErrorCode;
142#elif HAVE_LIBGNUTLS
145typedef int LibErrorCode;
146#else
148typedef int LibErrorCode;
149#endif
150
152inline const char *ErrorString(const LibErrorCode code) {
153#if USE_OPENSSL
154 return ERR_error_string(code, nullptr);
155#elif HAVE_LIBGNUTLS
156 return gnutls_strerror(code);
157#else
158 (void)code;
159 return "[no TLS library]";
160#endif
161}
162
165typedef std::unordered_set<Security::ErrorCode> Errors;
166
167namespace Io
168{
169enum Type {
170#if USE_OPENSSL
173#elif HAVE_LIBGNUTLS
174 // NP: this is odd looking but correct.
175 // 'to-client' means we are a server, and vice versa.
176 BIO_TO_CLIENT = GNUTLS_SERVER,
177 BIO_TO_SERVER = GNUTLS_CLIENT
178#else
179 BIO_TO_CLIENT = 6000,
181#endif
183
184} // namespace Io
185
186// TODO: Either move to Security::Io or remove/restrict the Io namespace.
187class IoResult;
188
189class CommunicationSecrets;
190class KeyData;
191class KeyLog;
192
193#if USE_OPENSSL
194using ParsedOptions = uint64_t;
195#elif HAVE_LIBGNUTLS
196typedef std::shared_ptr<struct gnutls_priority_st> ParsedOptions;
197#else
198class ParsedOptions {}; // we never parse/use TLS options in this case
199#endif
200
204typedef long ParsedPortFlags;
205
206class PeerConnector;
208class PeerOptions;
209
210class ServerOptions;
211
213
214class ErrorDetail;
216
217std::ostream &operator <<(std::ostream &, const KeyLog &);
218
219void OpenLogs();
220void RotateLogs();
221void CloseLogs();
222
223} // namespace Security
224
229enum {
230 SQUID_TLS_ERR_OFFSET = std::numeric_limits<int>::min(),
231
232 /* TLS library calls/contexts other than validation (e.g., I/O) */
235
236 /* certificate validation problems not covered by official errors */
240
243
244#endif /* SQUID_SRC_SECURITY_FORWARD_H */
245
#define CtoCpp1(function, argument)
Definition ToCpp.h:14
A PeerConnector for TLS cache_peers and origin servers. No SslBump capabilities.
A combination of PeerOptions and the corresponding Context.
a single tls_key_log directive configuration and logging handler
Definition KeyLog.h:20
TLS squid.conf settings for a remote server peer.
Definition PeerOptions.h:26
TLS squid.conf settings for a listening port.
Network/connection security abstraction layer.
Definition Connection.h:34
Security::LockingPointer< X509_CRL, X509_CRL_free_cpp, HardFun< int, X509_CRL *, X509_CRL_up_ref > > CrlPointer
Definition forward.h:97
RefCount< ErrorDetail > ErrorDetailPointer
Definition forward.h:215
Security::LockingPointer< DH, DH_free_cpp, HardFun< int, DH *, DH_up_ref > > DhePointer
Definition forward.h:121
uint64_t ParsedOptions
Definition forward.h:194
int ErrorCode
Squid-defined error code (<0), an error code returned by X.509 API, or zero.
Definition forward.h:134
void OpenLogs()
opens logs enabled in the current configuration
Definition KeyLog.cc:71
unsigned long LibErrorCode
TLS library-reported non-validation error.
Definition forward.h:141
X509 Certificate
Definition forward.h:79
CbDataList< Security::CertError > CertErrors
Holds a list of X.509 certificate errors.
Definition forward.h:76
Security::LockingPointer< X509, X509_free_cpp, HardFun< int, X509 *, X509_up_ref > > CertPointer
Definition forward.h:88
long ParsedPortFlags
Definition forward.h:204
std::unordered_set< Security::ErrorCode > Errors
Definition forward.h:165
std::list< Security::CrlPointer > CertRevokeList
Definition forward.h:107
std::list< Security::CertPointer > CertList
Definition forward.h:105
void CloseLogs()
closes logs opened by OpenLogs()
Definition KeyLog.cc:85
const char * ErrorString(const LibErrorCode code)
converts numeric LibErrorCode into a human-friendlier string
Definition forward.h:152
void RotateLogs()
rotates logs opened by OpenLogs()
Definition KeyLog.cc:78
std::ostream & operator<<(std::ostream &, const EncryptorAnswer &)
@ SQUID_X509_V_ERR_INFINITE_VALIDATION
Definition forward.h:239
@ SQUID_X509_V_ERR_DOMAIN_MISMATCH
Definition forward.h:238
@ SQUID_TLS_ERR_END
Definition forward.h:241
@ SQUID_TLS_ERR_CONNECT
failure to establish a connection with a TLS server
Definition forward.h:234
@ SQUID_TLS_ERR_ACCEPT
failure to accept a connection from a TLS client
Definition forward.h:233
@ SQUID_X509_V_ERR_CERT_CHANGE
Definition forward.h:237
@ SQUID_TLS_ERR_OFFSET
Definition forward.h:230