2#include <trantor/exports.h>
24 const std::vector<std::pair<std::string, std::string>> &sslConfCmds)
26 sslConfCmds_ = sslConfCmds;
74 useOldTLS_ = useOldTLS;
90 alpnProtocols_ = alpnProtocols;
93 TLSPolicy &setAlpnProtocols(std::vector<std::string> &&alpnProtocols)
95 alpnProtocols_ = std::move(alpnProtocols);
107 useSystemCertStore_ = useSystemCertStore;
133 allowBrokenChain_ = allow;
138 const std::vector<std::pair<std::string, std::string>> &getConfCmds()
const
142 const std::string &getHostname()
const
146 const std::string &getCertPath()
const
150 const std::string &getKeyPath()
const
154 const std::string &getCaPath()
const
158 bool getUseOldTLS()
const
162 bool getValidate()
const
166 bool getAllowBrokenChain()
const
168 return allowBrokenChain_;
170 const std::vector<std::string> &getAlpnProtocols()
const
172 return alpnProtocols_;
174 const std::vector<std::string> &getAlpnProtocols()
176 return alpnProtocols_;
179 bool getUseSystemCertStore()
const
181 return useSystemCertStore_;
184 static std::shared_ptr<TLSPolicy> defaultServerPolicy(
185 const std::string &certPath,
186 const std::string &keyPath)
188 auto policy = std::make_shared<TLSPolicy>();
189 policy->setValidate(
false)
191 .setUseSystemCertStore(
false)
192 .setCertPath(certPath)
193 .setKeyPath(keyPath);
197 static std::shared_ptr<TLSPolicy> defaultClientPolicy(
198 const std::string &hostname =
"")
200 auto policy = std::make_shared<TLSPolicy>();
201 policy->setValidate(
true)
203 .setUseSystemCertStore(
true)
204 .setHostname(hostname);
209 std::vector<std::pair<std::string, std::string>> sslConfCmds_ = {};
210 std::string hostname_ =
"";
211 std::string certPath_ =
"";
212 std::string keyPath_ =
"";
213 std::string caPath_ =
"";
214 std::vector<std::string> alpnProtocols_ = {};
215 bool useOldTLS_ =
false;
216 bool validate_ =
true;
217 bool allowBrokenChain_ =
false;
218 bool useSystemCertStore_ =
true;
220using TLSPolicyPtr = std::shared_ptr<TLSPolicy>;
Definition EventLoop.h:34
Definition TLSPolicy.h:12
TLSPolicy & setAllowBrokenChain(bool allow)
Allow broken chain (self-signed certificate, root CA not in allowed list, etc..) but still validate t...
Definition TLSPolicy.h:131
TLSPolicy & setHostname(const std::string &hostname)
set the hostname to be used for SNI and certificate validation.
Definition TLSPolicy.h:32
TLSPolicy & setKeyPath(const std::string &keyPath)
set the path to the private key file. The file must be in PEM format.
Definition TLSPolicy.h:52
TLSPolicy & setAlpnProtocols(const std::vector< std::string > &alpnProtocols)
set the list of protocols to be used for ALPN.
Definition TLSPolicy.h:88
TLSPolicy & setUseSystemCertStore(bool useSystemCertStore)
Weather to use the system's certificate store.
Definition TLSPolicy.h:105
TLSPolicy & setConfCmds(const std::vector< std::pair< std::string, std::string > > &sslConfCmds)
set the ssl configuration commands. The commands will be passed to the ssl library....
Definition TLSPolicy.h:23
TLSPolicy & setCertPath(const std::string &certPath)
set the path to the certificate file. The file must be in PEM format.
Definition TLSPolicy.h:42
TLSPolicy & setCaPath(const std::string &caPath)
set the path to the CA file or directory. The file must be in PEM format.
Definition TLSPolicy.h:62
TLSPolicy & setValidate(bool enable)
Enable certificate validation.
Definition TLSPolicy.h:114
TLSPolicy & setUseOldTLS(bool useOldTLS)
enables the use of the old TLS protocol (old meaning < TLS 1.2). TLS providers may not support old pr...
Definition TLSPolicy.h:72