27 #include <glog/logging.h> 29 #ifndef FOLLY_NO_CONFIG 82 finallyFunc(acceptFunc());
119 : weight(wt), protocols(ptcls) {}
128 const unsigned char*,
138 return getErrors(errno);
160 virtual void setCiphersOrThrow(
const std::string& ciphers);
166 template <
typename Iterator>
168 if (ibegin != iend) {
171 setCiphersOrThrow(opensslCipherList);
175 template <
typename Container>
178 setCipherList(
begin(cipherList),
end(cipherList));
181 template <
typename Value>
183 setCipherList(cipherList.begin(), cipherList.end());
191 template <
typename Iterator>
193 if (ibegin != iend) {
194 #if OPENSSL_VERSION_NUMBER >= 0x1000200fL 196 join(
":", ibegin, iend, opensslSigAlgsList);
197 if (!SSL_CTX_set1_sigalgs_list(
ctx_, opensslSigAlgsList.c_str())) {
198 throw std::runtime_error(
"SSL_CTX_set1_sigalgs_list " + getErrors());
204 template <
typename Container>
210 template <
typename Value>
220 void setClientECCurvesList(
const std::vector<std::string>& ecCurves);
227 void setServerECCurve(
const std::string& curveName);
250 verifyPeer_ == SSLVerifyPeerEnum::VERIFY ||
251 verifyPeer_ == SSLVerifyPeerEnum::VERIFY_REQ_CLIENT_CERT);
272 virtual int getVerificationMode();
286 virtual void authenticate(
296 virtual void loadCertificate(
const char* path,
const char*
format =
"PEM");
310 virtual void loadPrivateKey(
const char* path,
const char*
format =
"PEM");
325 virtual void loadCertKeyPairFromBufferPEM(
338 virtual void loadCertKeyPairFromFiles(
339 const char* certPath,
341 const char* certFormat =
"PEM",
342 const char* keyFormat =
"PEM");
350 virtual bool isCertKeyPairValid()
const;
357 virtual void loadTrustedCertificates(
const char* path);
363 virtual void loadTrustedCertificates(X509_STORE* store);
367 virtual void loadClientCAList(
const char* path);
373 virtual void passwordCollector(std::shared_ptr<PasswordCollector> collector);
382 #if FOLLY_OPENSSL_HAS_SNI 386 enum ServerNameCallbackResult {
388 SERVER_NAME_NOT_FOUND,
389 SERVER_NAME_NOT_FOUND_ALERT_FATAL,
426 typedef std::function<ServerNameCallbackResult(SSL* ssl)> ServerNameCallback;
427 virtual void setServerNameCallback(
const ServerNameCallback& cb);
433 typedef std::function<void(SSL* ssl)> ClientHelloCallback;
434 virtual void addClientHelloCallback(
const ClientHelloCallback& cb);
435 #endif // FOLLY_OPENSSL_HAS_SNI 440 SSL* createSSL()
const;
450 void setOptions(
long options);
452 #if FOLLY_OPENSSL_HAS_ALPN 468 bool setAdvertisedNextProtocols(
const std::list<std::string>& protocols);
490 bool setRandomizedAdvertisedNextProtocols(
491 const std::list<NextProtocolsItem>& items);
496 void unsetNextProtocols();
497 void deleteNextProtocolsStrings();
498 #endif // FOLLY_OPENSSL_HAS_ALPN 516 return checkPeerName_;
519 return peerFixedName_;
522 #if defined(SSL_MODE_HANDSHAKE_CUTTHROUGH) 528 void enableFalseStart();
536 if (
nullptr == runner) {
537 LOG(ERROR) <<
"Ignore invalid runner";
544 return sslAcceptRunner_.get();
550 static bool matchName(
const char* host,
const char* pattern,
int size);
552 [[deprecated(
"Use folly::ssl::init")]]
static void initializeOpenSSL();
563 #if FOLLY_OPENSSL_HAS_SNI 564 ServerNameCallback serverNameCb_;
565 std::vector<ClientHelloCallback> clientHelloCbs_;
574 #if FOLLY_OPENSSL_HAS_ALPN 576 struct AdvertisedNextProtocolsItem {
577 unsigned char* protocols;
584 std::vector<AdvertisedNextProtocolsItem> advertisedNextProtocols_;
585 std::vector<int> advertisedNextProtocolWeights_;
586 std::discrete_distribution<int> nextProtocolDistribution_;
588 static int advertisedNextProtocolCallback(
590 const unsigned char** out,
591 unsigned int* outlen,
594 static int alpnSelectCallback(
596 const unsigned char** out,
597 unsigned char* outlen,
598 const unsigned char* in,
602 size_t pickNextProtocols();
604 #endif // FOLLY_OPENSSL_HAS_ALPN 608 #if FOLLY_OPENSSL_HAS_SNI 619 static int baseServerNameOpenSSLCallback(
static std::string getErrors()
virtual std::shared_ptr< PasswordCollector > passwordCollector()
void setCipherList(const std::initializer_list< Value > &cipherList)
void setCipherList(Iterator ibegin, Iterator iend)
virtual void run(Function< int()> acceptFunc, Function< void(int)> finallyFunc) const
void setCipherList(const Container &cipherList)
NextProtocolsItem(int wt, const std::list< std::string > &ptcls)
const SSLAcceptRunner * sslAcceptRunner()
constexpr detail::Map< Move > move
auto begin(TestAdlIterable &instance)
—— Concurrent Priority Queue Implementation ——
void setSignatureAlgorithms(const std::initializer_list< Value > &sigalgs)
virtual ~PasswordCollector()=default
void sslAcceptRunner(std::unique_ptr< SSLAcceptRunner > runner)
std::shared_ptr< FizzServerContext > ctx_
std::shared_ptr< PasswordCollector > collector_
virtual void getPassword(std::string &password, int size) const =0
constexpr auto size(C const &c) -> decltype(c.size())
SSL_CTX * getSSLCtx() const
bool(*)(unsigned char **, unsigned int *, const unsigned char *, unsigned int) ClientProtocolFilterCallback
std::shared_ptr< SSLContext > SSLContextPtr
auto end(TestAdlIterable &instance)
virtual std::string describe() const =0
constexpr auto data(C &c) -> decltype(c.data())
void setSignatureAlgorithms(const Container &sigalgs)
void setSignatureAlgorithms(SSLContext &ctx)
std::unique_ptr< SSLAcceptRunner > sslAcceptRunner_
virtual bool needsPeerVerification()
void setSignatureAlgorithms(Iterator ibegin, Iterator iend)
std::string peerFixedName()
void join(const Delim &delimiter, Iterator begin, Iterator end, String &output)
static int passwordCallback(char *password, int size, int, void *data)
Formatter< false, Args... > format(StringPiece fmt, Args &&...args)
std::list< std::string > protocols
std::unique_ptr< X509_VERIFY_PARAM, X509VerifyParamDeleter > X509VerifyParam
std::string peerFixedName_
std::string providedCiphersString_
std::ostream & operator<<(std::ostream &out, dynamic const &d)