2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_SRC_SECURITY_PEEROPTIONS_H
10 #define SQUID_SRC_SECURITY_PEEROPTIONS_H
12 #include "base/YesNoNone.h"
13 #include "ConfigParser.h"
14 #include "security/forward.h"
15 #include "security/KeyData.h"
22 /// TLS squid.conf settings for a remote server peer
27 PeerOptions(const PeerOptions
&) = default;
28 PeerOptions
&operator =(const PeerOptions
&) = default;
29 PeerOptions(PeerOptions
&&) = default;
30 PeerOptions
&operator =(PeerOptions
&&) = default;
31 virtual ~PeerOptions() {}
33 /// parse a TLS squid.conf option
34 virtual void parse(const char *);
36 /// parse and verify the [tls-]options= string in sslOptions
39 /// reset the configuration details to default
40 virtual void clear() {*this = PeerOptions();}
42 /// generate an unset security context object
43 virtual Security::ContextPointer
createBlankContext() const;
45 /// generate a security client-context from these configured options
46 Security::ContextPointer
createClientContext(bool setOptions
);
48 /// sync the context options with tls-min-version=N configuration
49 void updateTlsVersionLimits();
51 /// Setup the library specific 'options=' parameters for the given context.
52 void updateContextOptions(Security::ContextPointer
&);
54 /// setup the NPN extension details for the given context
55 void updateContextNpn(Security::ContextPointer
&);
57 /// setup the CA details for the given context
58 void updateContextCa(Security::ContextPointer
&);
60 /// setup the CRL details for the given context
61 void updateContextCrl(Security::ContextPointer
&);
63 /// decide which CAs to trust
64 void updateContextTrust(Security::ContextPointer
&);
66 /// setup any library-specific options that can be set for the given session
67 void updateSessionOptions(Security::SessionPointer
&);
69 /// output squid.conf syntax with 'pfx' prefix on parameters for the stored settings
70 virtual void dumpCfg(Packable
*, const char *pfx
) const;
73 ParsedPortFlags
parseFlags();
78 SBuf sslOptions
; ///< library-specific options string
79 SBuf caDir
; ///< path of directory containing a set of trusted Certificate Authorities
80 SBuf crlFile
; ///< path of file containing Certificate Revoke List
83 SBuf sslFlags
; ///< flags defining what TLS operations Squid performs
86 SBuf tlsMinVersion
; ///< version label for minimum TLS version to permit
89 /// Library-specific options string generated from tlsMinVersion.
90 /// Call updateTlsVersionLimits() to regenerate this string.
93 /// Parsed value of sslOptions + tlsMinOptions settings.
94 /// Set optsReparse=true to have this re-parsed before next use.
95 Security::ParsedOptions parsedOptions
;
97 /// whether parsedOptions content needs to be regenerated
98 bool optsReparse
= true;
101 ParsedPortFlags parsedFlags
= 0; ///< parsed value of sslFlags
103 std::list
<Security::KeyData
> certs
; ///< details from the cert= and file= config parameters
104 std::list
<SBuf
> caFiles
; ///< paths of files containing trusted Certificate Authority
105 Security::CertRevokeList parsedCrl
; ///< CRL to use when verifying the remote end certificate
109 Security::ContextPointer
convertContextFromRawPtr(T ctx
) const {
111 debugs(83, 5, "SSL_CTX construct, this=" << (void*)ctx
);
112 return ContextPointer(ctx
, [](SSL_CTX
*p
) {
113 debugs(83, 5, "SSL_CTX destruct, this=" << (void*)p
);
117 debugs(83, 5, "gnutls_certificate_credentials construct, this=" << (void*)ctx
);
118 return Security::ContextPointer(ctx
, [](gnutls_certificate_credentials_t p
) {
119 debugs(83, 5, "gnutls_certificate_credentials destruct, this=" << (void*)p
);
120 gnutls_certificate_free_credentials(p
);
124 return Security::ContextPointer();
130 /// flags governing Squid internal TLS operations
132 flags_() : tlsDefaultCa(true), tlsNpn(true) {}
133 flags_(const flags_
&) = default;
134 flags_
&operator =(const flags_
&) = default;
136 /// whether to use the system default Trusted CA when verifying the remote end certificate
137 YesNoNone tlsDefaultCa
;
139 /// whether to use the TLS NPN extension on these connections
144 /// whether transport encryption (TLS/SSL) is to be used on connections to the peer
145 bool encryptTransport
= false;
148 /// configuration options for DIRECT server access
149 extern PeerOptions ProxyOutgoingConfig
;
151 } // namespace Security
153 // parse the tls_outgoing_options directive
154 void parse_securePeerOptions(Security::PeerOptions
*);
155 #define free_securePeerOptions(x) Security::ProxyOutgoingConfig.clear()
156 #define dump_securePeerOptions(e,n,x) do { (e)->appendf(n); (x).dumpCfg((e),""); (e)->append("\n",1); } while(false)
158 #endif /* SQUID_SRC_SECURITY_PEEROPTIONS_H */