72 typedef std::unique_ptr<AsyncSSLSocket, Destructor>
UniquePtr;
137 return scheduleTimeout(std::chrono::milliseconds{timeoutMs});
162 : pipeReader_(
std::
move(reader)),
167 pipeReader_->setReadCB(
nullptr);
168 sslSocket_->setAsyncOperationFinishCallback(
nullptr);
174 pipeReader_->setReadCB(
nullptr);
175 sslSocket_->setAsyncOperationFinishCallback(
nullptr);
198 const std::shared_ptr<folly::SSLContext>& ctx,
200 bool deferSecurityNegotiation =
false);
220 const std::shared_ptr<folly::SSLContext>& ctx,
224 bool deferSecurityNegotiation =
false);
231 const std::shared_ptr<folly::SSLContext>& ctx,
234 bool deferSecurityNegotiation =
false);
240 const std::shared_ptr<folly::SSLContext>& ctx,
244 bool deferSecurityNegotiation =
false) {
245 return std::shared_ptr<AsyncSSLSocket>(
246 new AsyncSSLSocket(ctx, evb, fd, server, deferSecurityNegotiation),
254 const std::shared_ptr<folly::SSLContext>& ctx,
256 bool deferSecurityNegotiation =
false) {
257 return std::shared_ptr<AsyncSSLSocket>(
261 #if FOLLY_OPENSSL_HAS_SNI 267 const std::shared_ptr<folly::SSLContext>& ctx,
270 bool deferSecurityNegotiation =
false);
288 const std::shared_ptr<folly::SSLContext>& ctx,
292 bool deferSecurityNegotiation =
false);
294 static std::shared_ptr<AsyncSSLSocket>
newSocket(
295 const std::shared_ptr<folly::SSLContext>& ctx,
298 bool deferSecurityNegotiation =
false) {
299 return std::shared_ptr<AsyncSSLSocket>(
300 new AsyncSSLSocket(ctx, evb, serverName, deferSecurityNegotiation),
303 #endif // FOLLY_OPENSSL_HAS_SNI 326 bool good()
const override;
359 std::chrono::milliseconds
timeout = std::chrono::milliseconds::zero(),
361 folly::SSLContext::SSLVerifyPeerEnum::USE_CTX);
398 std::chrono::milliseconds connectTimeout,
399 std::chrono::milliseconds totalConnectTimeout,
424 std::chrono::milliseconds
timeout = std::chrono::milliseconds::zero(),
426 folly::SSLContext::SSLVerifyPeerEnum::USE_CTX);
457 const SSL*
getSSL()
const;
467 void setSSLSession(SSL_SESSION* session,
bool takeOwnership =
false);
484 const unsigned char** protoName,
485 unsigned* protoLen)
const;
502 const unsigned char** protoName,
503 unsigned* protoLen)
const;
593 #if OPENSSL_VERSION_NUMBER >= 0x009080bfL 599 void attachSSLContext(
const std::shared_ptr<folly::SSLContext>& ctx);
604 void detachSSLContext();
619 #if FOLLY_OPENSSL_HAS_SNI 624 void switchServerSSLContext(
625 const std::shared_ptr<folly::SSLContext>& handshakeCtx);
635 bool isServerNameMatch()
const;
642 #endif // FOLLY_OPENSSL_HAS_SNI 652 bool convertToString =
true)
const;
701 static AsyncSSLSocket*
getFromSSL(
const SSL* ssl);
702 static int bioWrite(BIO*
b,
const char* in,
int inl);
703 static int bioRead(BIO* b,
char* out,
int outl);
755 return peerCert->getX509();
856 return SSL_write(ssl, buf, n);
916 std::shared_ptr<folly::SSLContext>
ctx_;
935 #if FOLLY_OPENSSL_HAS_SNI 936 std::shared_ptr<folly::SSLContext> handshakeCtx_;
944 folly::SSLContext::SSLVerifyPeerEnum::USE_CTX};
void detachEventBase() override
void applyVerificationOptions(const ssl::SSLUniquePtr &ssl)
bool good() const override
size_t getRawBytesReceived() const override
void checkForImmediateRead() noexceptoverride
bool sessionResumptionAttempted_
ReadResult performRead(void **buf, size_t *buflen, size_t *offset) override
void invokeHandshakeErr(const AsyncSocketException &ex)
bool sessionIDResumed() const
DefaultOpenSSLAsyncFinishCallback(AsyncPipeReader::UniquePtr reader, AsyncSSLSocket *sslSocket, DestructorGuard dg)
std::unique_ptr< AsyncPipeReader, folly::DelayedDestruction::Destructor > UniquePtr
bool sessionResumptionAttempted() const
std::chrono::milliseconds timeout_type
void enableClientHelloParsing()
std::unique_ptr< ReadCallback > asyncOperationFinishCallback_
std::unique_ptr< X509, X509Deleter > X509UniquePtr
void handleInitialReadWrite() noexceptoverride
void handleRead() noexceptoverride
WriteResult interpretSSLError(int rc, int error)
bool connecting() const override
static int sslVerifyCallback(int preverifyOk, X509_STORE_CTX *ctx)
static int bioRead(BIO *b, char *out, int outl)
static const char * getSSLServerNameFromSSL(SSL *ssl)
close() called with pending writes, before connect() has completed
folly::SSLContext::SSLVerifyPeerEnum verifyPeer_
virtual void attachTimeoutManager(TimeoutManager *manager)
void setEorTracking(bool track) override
void connect(ConnectCallback *callback, const folly::SocketAddress &address, int timeout=0, const OptionMap &options=emptyOptionMap, const folly::SocketAddress &bindAddr=anyAddress()) noexceptoverride
void timeoutExpired() noexceptoverride
const char * getSSLCertSigAlgName() const
AsyncSSLSocket * sslSocket_
size_t getRawBytesWritten() const override
bool willBlock(int ret, int *sslErrorOut, unsigned long *errErrorOut) noexcept
std::string getSSLClientComprMethods() const
virtual ~HandshakeCB()=default
std::string getSSLClientSupportedVersions() const
const AsyncTransportCertificate * getPeerCertificate() const override
const X509 * getSelfCert() const override
constexpr detail::Map< Move > move
virtual void sslAccept(HandshakeCB *callback, std::chrono::milliseconds timeout=std::chrono::milliseconds::zero(), const folly::SSLContext::SSLVerifyPeerEnum &verifyPeer=folly::SSLContext::SSLVerifyPeerEnum::USE_CTX)
WriteResult performWrite(const iovec *vec, uint32_t count, WriteFlags flags, uint32_t *countWritten, uint32_t *partialWritten) override
std::string getSecurityProtocol() const override
bool renegotiateAttempted_
virtual void sslConn(HandshakeCB *callback, std::chrono::milliseconds timeout=std::chrono::milliseconds::zero(), const folly::SSLContext::SSLVerifyPeerEnum &verifyPeer=folly::SSLContext::SSLVerifyPeerEnum::USE_CTX)
std::chrono::milliseconds handshakeConnectTimeout_
SSL_SESSION * sslSession_
void readEOF() noexceptoverride
void setSessionIDResumed(bool resumed)
const char * getSSLServerName() const
bool bufferMovableEnabled_
void shutdownWrite() override
void setAsyncOperationFinishCallback(std::unique_ptr< ReadCallback > cb)
std::string sslVerificationAlert_
Timeout(AsyncSSLSocket *sslSocket, EventBase *eventBase)
—— Concurrent Priority Queue Implementation ——
~AsyncSSLSocket() override
requires E e noexcept(noexcept(s.error(std::move(e))))
bool error() const override
const std::shared_ptr< folly::SSLContext > & getSSLContext() const
virtual void detachTimeoutManager()
Timeout handshakeTimeout_
void setMinWriteSize(size_t minWriteSize)
static std::shared_ptr< AsyncSSLSocket > newSocket(const std::shared_ptr< folly::SSLContext > &ctx, EventBase *evb, int fd, bool server=true, bool deferSecurityNegotiation=false)
virtual void connect(ConnectCallback *callback, const folly::SocketAddress &address, int timeout=0, const OptionMap &options=emptyOptionMap, const folly::SocketAddress &bindAddr=anyAddress()) noexcept
bool needsPeerVerification() const
void attachEventBase(EventBase *eventBase) override
ssize_t performWriteIovec(const iovec *vec, uint32_t count, WriteFlags flags, uint32_t *countWritten, uint32_t *partialWritten)
std::shared_ptr< folly::SSLContext > ctx_
void scheduleConnectTimeout() override
void setReadCB(ReadCallback *callback) override
void handleWrite() noexceptoverride
std::unique_ptr< AsyncSSLSocket, Destructor > UniquePtr
ssl::X509UniquePtr getPeerCert() const override
void setCertCacheHit(bool hit)
std::chrono::milliseconds totalConnectTimeout_
std::map< OptionKey, int > OptionMap
SSLStateEnum getSSLState() const
void setSessionKey(std::string sessionKey)
void invokeConnectSuccess() override
static const folly::SocketAddress & anyAddress()
void attachTimeoutManager(TimeoutManager *timeoutManager, InternalEnum internal=InternalEnum::NORMAL)
AsyncSSLSocket::UniquePtr sslSocket_
void detachEventBase() override
void handleReturnFromSSLAccept(int ret)
void readErr(const folly::AsyncSocketException &) noexceptoverride
ssl::ClientHelloInfo * getClientHelloInfo() const
std::string getSSLCertVerificationAlert() const
static void clientHelloParsingCallback(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)
void invokeConnectErr(const AsyncSocketException &ex) override
void timeoutExpired() noexcept
Timeout connectionTimeout_
void forceCacheAddrOnFailure(bool force)
static const OptionMap emptyOptionMap
TimeoutManager::timeout_type getTimeout()
void getSSLClientCiphers(std::string &clientCiphers, bool convertToString=true) const
void setBufferMovableEnabled(bool enabled)
remote end closed; we can still write
bool getCertCacheHit() const
virtual bool getSSLSessionReused() const
void getSSLSharedCiphers(std::string &sharedCiphers) const
bool isDetachable() const override
const std::string & getSessionKey() const
void attachEventBase(EventBase *eventBase) override
void attachEventBase(EventBase *eventBase, InternalEnum internal=InternalEnum::NORMAL)
virtual void handshakeSuc(AsyncSSLSocket *sock) noexcept=0
void prepareReadBuffer(void **buf, size_t *buflen) override
void getReadBuffer(void **bufReturn, size_t *lenReturn) noexceptoverride
void handleConnect() noexceptoverride
virtual bool handshakeVer(AsyncSSLSocket *, bool preverifyOk, X509_STORE_CTX *) noexcept
virtual void handshakeErr(AsyncSSLSocket *sock, const AsyncSocketException &ex) noexcept=0
void setSSLCertVerificationAlert(std::string alert)
virtual bool getSelectedNextProtocolNoThrow(const unsigned char **protoName, unsigned *protoLen) const
std::vector< std::pair< char, StringPiece > > alertsReceived_
std::unique_ptr< ssl::ClientHelloInfo > clientHelloInfo_
std::string getSSLClientExts() const
void getSSLServerCiphers(std::string &serverCiphers) const
TimeoutManager::timeout_type timeout_
AsyncSSLSocket(const std::shared_ptr< folly::SSLContext > &ctx, EventBase *evb, bool deferSecurityNegotiation=false)
std::chrono::steady_clock::time_point handshakeEndTime_
std::string getSSLClientSigAlgs() const
SSL_SESSION * getSSLSession()
void resetClientHelloParsing(SSL *ssl)
virtual std::chrono::nanoseconds getHandshakeTime() const
bool scheduleTimeout(uint32_t milliseconds)
void setSSLSession(SSL_SESSION *session, bool takeOwnership=false)
HandshakeCB * handshakeCallback_
std::string getSSLAlertsReceived() const
void detachTimeoutManager()
void failHandshake(const char *fn, const AsyncSocketException &ex)
int eorAwareSSLWrite(const ssl::SSLUniquePtr &ssl, const void *buf, int n, bool eor)
void invalidState(HandshakeCB *callback)
std::chrono::steady_clock::time_point handshakeStartTime_
bool scheduleTimeout(TimeoutManager::timeout_type timeout)
bool scheduleTimeout(uint32_t timeoutMs)
std::string getApplicationProtocol() const noexceptoverride
bool isDetachable() const override
const SSL * getSSL() const
const AsyncTransportCertificate * getSelfCertificate() const override
static int bioWrite(BIO *b, const char *in, int inl)
int getSSLCertSize() const
std::chrono::milliseconds getTotalConnectTimeout() const
static std::shared_ptr< AsyncSSLSocket > newSocket(const std::shared_ptr< folly::SSLContext > &ctx, EventBase *evb, bool deferSecurityNegotiation=false)
~DefaultOpenSSLAsyncFinishCallback()
int getSSLVersion() const
virtual const char * getNegotiatedCipherName() const
void shutdownWriteNow() override
size_t getMinWriteSize() const
static void sslInfoCallback(const SSL *ssl, int type, int val)
static AsyncSSLSocket * getFromSSL(const SSL *ssl)
std::unique_ptr< AsyncSocket, Destructor > UniquePtr
static int getSSLExDataIndex()
AsyncPipeReader::UniquePtr pipeReader_
const char * getSSLServerNameNoThrow() const
virtual int sslWriteImpl(SSL *ssl, const void *buf, int n)
void readDataAvailable(size_t len) noexceptoverride
virtual void getSelectedNextProtocol(const unsigned char **protoName, unsigned *protoLen) const
void handleAccept() noexcept
std::unique_ptr< SSL, SSLDeleter > SSLUniquePtr