proxygen
|
#include <AsyncSSLSocket.h>
Classes | |
class | DefaultOpenSSLAsyncFinishCallback |
class | HandshakeCB |
class | Timeout |
Public Member Functions | |
AsyncSSLSocket (const std::shared_ptr< folly::SSLContext > &ctx, EventBase *evb, bool deferSecurityNegotiation=false) | |
AsyncSSLSocket (const std::shared_ptr< folly::SSLContext > &ctx, EventBase *evb, int fd, bool server=true, bool deferSecurityNegotiation=false) | |
AsyncSSLSocket (const std::shared_ptr< folly::SSLContext > &ctx, AsyncSocket::UniquePtr oldAsyncSocket, bool server=true, bool deferSecurityNegotiation=false) | |
void | closeNow () override |
void | shutdownWrite () override |
void | shutdownWriteNow () override |
bool | good () const override |
bool | connecting () const override |
std::string | getApplicationProtocol () const noexceptoverride |
std::string | getSecurityProtocol () const override |
void | setEorTracking (bool track) override |
size_t | getRawBytesWritten () const override |
size_t | getRawBytesReceived () const override |
void | enableClientHelloParsing () |
virtual void | sslAccept (HandshakeCB *callback, std::chrono::milliseconds timeout=std::chrono::milliseconds::zero(), const folly::SSLContext::SSLVerifyPeerEnum &verifyPeer=folly::SSLContext::SSLVerifyPeerEnum::USE_CTX) |
void | restartSSLAccept () |
void | connect (ConnectCallback *callback, const folly::SocketAddress &address, int timeout=0, const OptionMap &options=emptyOptionMap, const folly::SocketAddress &bindAddr=anyAddress()) noexceptoverride |
virtual void | connect (ConnectCallback *callback, const folly::SocketAddress &address, std::chrono::milliseconds connectTimeout, std::chrono::milliseconds totalConnectTimeout, const OptionMap &options=emptyOptionMap, const folly::SocketAddress &bindAddr=anyAddress()) noexcept |
virtual void | sslConn (HandshakeCB *callback, std::chrono::milliseconds timeout=std::chrono::milliseconds::zero(), const folly::SSLContext::SSLVerifyPeerEnum &verifyPeer=folly::SSLContext::SSLVerifyPeerEnum::USE_CTX) |
SSLStateEnum | getSSLState () const |
SSL_SESSION * | getSSLSession () |
const SSL * | getSSL () const |
void | setSSLSession (SSL_SESSION *session, bool takeOwnership=false) |
virtual void | getSelectedNextProtocol (const unsigned char **protoName, unsigned *protoLen) const |
virtual bool | getSelectedNextProtocolNoThrow (const unsigned char **protoName, unsigned *protoLen) const |
virtual bool | getSSLSessionReused () const |
bool | sessionIDResumed () const |
void | setSessionIDResumed (bool resumed) |
virtual const char * | getNegotiatedCipherName () const |
const char * | getSSLServerName () const |
const char * | getSSLServerNameNoThrow () const |
int | getSSLVersion () const |
const char * | getSSLCertSigAlgName () const |
int | getSSLCertSize () const |
const X509 * | getSelfCert () const override |
void | attachEventBase (EventBase *eventBase) override |
void | detachEventBase () override |
bool | isDetachable () const override |
virtual void | attachTimeoutManager (TimeoutManager *manager) |
virtual void | detachTimeoutManager () |
const std::shared_ptr< folly::SSLContext > & | getSSLContext () const |
void | timeoutExpired (std::chrono::milliseconds timeout) noexcept |
void | getSSLClientCiphers (std::string &clientCiphers, bool convertToString=true) const |
std::string | getSSLClientComprMethods () const |
std::string | getSSLClientExts () const |
std::string | getSSLClientSigAlgs () const |
std::string | getSSLClientSupportedVersions () const |
std::string | getSSLAlertsReceived () const |
void | setSSLCertVerificationAlert (std::string alert) |
std::string | getSSLCertVerificationAlert () const |
void | getSSLSharedCiphers (std::string &sharedCiphers) const |
void | getSSLServerCiphers (std::string &serverCiphers) const |
bool | needsPeerVerification () const |
void | resetClientHelloParsing (SSL *ssl) |
ssl::ClientHelloInfo * | getClientHelloInfo () const |
virtual std::chrono::nanoseconds | getHandshakeTime () const |
void | setMinWriteSize (size_t minWriteSize) |
size_t | getMinWriteSize () const |
void | setReadCB (ReadCallback *callback) override |
void | setBufferMovableEnabled (bool enabled) |
const AsyncTransportCertificate * | getPeerCertificate () const override |
const AsyncTransportCertificate * | getSelfCertificate () const override |
ssl::X509UniquePtr | getPeerCert () const override |
void | forceCacheAddrOnFailure (bool force) |
const std::string & | getSessionKey () const |
void | setSessionKey (std::string sessionKey) |
void | setCertCacheHit (bool hit) |
bool | getCertCacheHit () const |
bool | sessionResumptionAttempted () const |
std::chrono::milliseconds | getTotalConnectTimeout () const |
void | setAsyncOperationFinishCallback (std::unique_ptr< ReadCallback > cb) |
Public Member Functions inherited from folly::AsyncSocket | |
AsyncSocket () | |
AsyncSocket (EventBase *evb) | |
void | setShutdownSocketSet (const std::weak_ptr< ShutdownSocketSet > &wSS) |
AsyncSocket (EventBase *evb, const folly::SocketAddress &address, uint32_t connectTimeout=0) | |
AsyncSocket (EventBase *evb, const std::string &ip, uint16_t port, uint32_t connectTimeout=0) | |
AsyncSocket (EventBase *evb, int fd, uint32_t zeroCopyBufId=0) | |
AsyncSocket (AsyncSocket::UniquePtr) | |
void | destroy () override |
EventBase * | getEventBase () const override |
virtual int | getFd () const |
virtual int | detachFd () |
void | connect (ConnectCallback *callback, const std::string &ip, uint16_t port, int timeout=0, const OptionMap &options=emptyOptionMap) noexcept |
void | cancelConnect () |
void | setSendTimeout (uint32_t milliseconds) override |
uint32_t | getSendTimeout () const override |
void | setMaxReadsPerEvent (uint16_t maxReads) |
uint16_t | getMaxReadsPerEvent () const |
virtual void | setErrMessageCB (ErrMessageCallback *callback) |
virtual ErrMessageCallback * | getErrMessageCallback () const |
virtual void | setSendMsgParamCB (SendMsgParamsCallback *callback) |
virtual SendMsgParamsCallback * | getSendMsgParamsCB () const |
ReadCallback * | getReadCallback () const override |
bool | setZeroCopy (bool enable) |
bool | getZeroCopy () const |
uint32_t | getZeroCopyBufId () const |
size_t | getZeroCopyReenableThreshold () const |
void | setZeroCopyReenableThreshold (size_t threshold) |
void | write (WriteCallback *callback, const void *buf, size_t bytes, WriteFlags flags=WriteFlags::NONE) override |
void | writev (WriteCallback *callback, const iovec *vec, size_t count, WriteFlags flags=WriteFlags::NONE) override |
void | writeChain (WriteCallback *callback, std::unique_ptr< folly::IOBuf > &&buf, WriteFlags flags=WriteFlags::NONE) override |
virtual void | writeRequest (WriteRequest *req) |
void | writeRequestReady () |
void | close () override |
void | closeWithReset () override |
bool | readable () const override |
bool | writable () const override |
bool | isPending () const override |
virtual bool | hangup () const |
bool | error () const override |
void | getLocalAddress (folly::SocketAddress *address) const override |
void | getPeerAddress (folly::SocketAddress *address) const override |
bool | isEorTrackingEnabled () const override |
virtual bool | isClosedByPeer () const |
virtual bool | isClosedBySelf () const |
size_t | getAppBytesWritten () const override |
size_t | getAppBytesReceived () const override |
std::chrono::nanoseconds | getConnectTime () const |
std::chrono::milliseconds | getConnectTimeout () const |
std::chrono::steady_clock::time_point | getConnectStartTime () const |
std::chrono::steady_clock::time_point | getConnectEndTime () const |
bool | getTFOAttempted () const |
bool | getTFOFinished () const |
bool | getTFOSucceded () const |
int | setNoDelay (bool noDelay) |
void | setCloseOnExec () |
int | setCongestionFlavor (const std::string &cname) |
int | setQuickAck (bool quickack) |
int | setSendBufSize (size_t bufsize) |
int | setRecvBufSize (size_t bufsize) |
int | setTCPProfile (int profd) |
template<typename T > | |
int | getSockOpt (int level, int optname, T *optval, socklen_t *optlen) |
template<typename T > | |
int | setSockOpt (int level, int optname, const T *optval) |
virtual int | getSockOptVirtual (int level, int optname, void *optval, socklen_t *optlen) |
virtual int | setSockOptVirtual (int level, int optname, void const *optval, socklen_t optlen) |
virtual void | setPreReceivedData (std::unique_ptr< IOBuf > data) |
void | enableTFO () |
void | disableTransparentTls () |
void | disableTSocks () |
void | setBufferCallback (BufferCallback *cb) |
void | setEvbChangedCallback (std::unique_ptr< EvbChangeCallback > cb) |
void | cacheAddresses () |
bool | isZeroCopyWriteInProgress () const noexcept |
bool | processZeroCopyWriteInProgress () noexcept |
void | setPeerCertificate (std::unique_ptr< const AsyncTransportCertificate > cert) |
void | setSelfCertificate (std::unique_ptr< const AsyncTransportCertificate > cert) |
Public Member Functions inherited from folly::AsyncTransportWrapper | |
virtual const AsyncTransportWrapper * | getWrappedTransport () const |
template<class T > | |
const T * | getUnderlyingTransport () const |
template<class T > | |
T * | getUnderlyingTransport () |
Public Member Functions inherited from folly::AsyncTransport | |
SocketAddress | getLocalAddress () const |
void | getAddress (SocketAddress *address) const override |
SocketAddress | getPeerAddress () const |
virtual bool | isReplaySafe () const |
virtual void | setReplaySafetyCallback (ReplaySafetyCallback *callback) |
Public Member Functions inherited from folly::DelayedDestruction | |
bool | getDestroyPending () const |
Public Member Functions inherited from folly::DelayedDestructionBase | |
virtual | ~DelayedDestructionBase ()=default |
Public Member Functions inherited from folly::AsyncSocketBase | |
virtual | ~AsyncSocketBase ()=default |
Static Public Member Functions | |
static std::shared_ptr< AsyncSSLSocket > | newSocket (const std::shared_ptr< folly::SSLContext > &ctx, EventBase *evb, int fd, bool server=true, bool deferSecurityNegotiation=false) |
static std::shared_ptr< AsyncSSLSocket > | newSocket (const std::shared_ptr< folly::SSLContext > &ctx, EventBase *evb, bool deferSecurityNegotiation=false) |
static int | getSSLExDataIndex () |
static AsyncSSLSocket * | getFromSSL (const SSL *ssl) |
static int | bioWrite (BIO *b, const char *in, int inl) |
static int | bioRead (BIO *b, char *out, int outl) |
static void | clientHelloParsingCallback (int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg) |
static const char * | getSSLServerNameFromSSL (SSL *ssl) |
Static Public Member Functions inherited from folly::AsyncSocket | |
static std::shared_ptr< AsyncSocket > | newSocket (EventBase *evb) |
static std::shared_ptr< AsyncSocket > | newSocket (EventBase *evb, const folly::SocketAddress &address, uint32_t connectTimeout=0) |
static std::shared_ptr< AsyncSocket > | newSocket (EventBase *evb, const std::string &ip, uint16_t port, uint32_t connectTimeout=0) |
static std::shared_ptr< AsyncSocket > | newSocket (EventBase *evb, int fd) |
static const folly::SocketAddress & | anyAddress () |
Protected Member Functions | |
~AsyncSSLSocket () override | |
void | prepareReadBuffer (void **buf, size_t *buflen) override |
void | handleRead () noexceptoverride |
void | handleWrite () noexceptoverride |
void | handleAccept () noexcept |
void | handleConnect () noexceptoverride |
void | invalidState (HandshakeCB *callback) |
bool | willBlock (int ret, int *sslErrorOut, unsigned long *errErrorOut) noexcept |
void | checkForImmediateRead () noexceptoverride |
void | handleInitialReadWrite () noexceptoverride |
WriteResult | interpretSSLError (int rc, int error) |
ReadResult | performRead (void **buf, size_t *buflen, size_t *offset) override |
WriteResult | performWrite (const iovec *vec, uint32_t count, WriteFlags flags, uint32_t *countWritten, uint32_t *partialWritten) override |
ssize_t | performWriteIovec (const iovec *vec, uint32_t count, WriteFlags flags, uint32_t *countWritten, uint32_t *partialWritten) |
virtual int | sslWriteImpl (SSL *ssl, const void *buf, int n) |
void | applyVerificationOptions (const ssl::SSLUniquePtr &ssl) |
bool | setupSSLBio () |
int | eorAwareSSLWrite (const ssl::SSLUniquePtr &ssl, const void *buf, int n, bool eor) |
void | failHandshake (const char *fn, const AsyncSocketException &ex) |
void | invokeHandshakeErr (const AsyncSocketException &ex) |
void | invokeHandshakeCB () |
void | invokeConnectErr (const AsyncSocketException &ex) override |
void | invokeConnectSuccess () override |
void | scheduleConnectTimeout () override |
void | startSSLConnect () |
Protected Member Functions inherited from folly::AsyncSocket | |
~AsyncSocket () override | |
void | init () |
void | scheduleImmediateRead () noexcept |
void | scheduleInitialReadWrite () noexcept |
void | ioReady (uint16_t events) noexcept |
virtual size_t | handleErrMessages () noexcept |
void | timeoutExpired () noexcept |
void | writeChainImpl (WriteCallback *callback, iovec *vec, size_t count, std::unique_ptr< folly::IOBuf > &&buf, WriteFlags flags) |
void | writeImpl (WriteCallback *callback, const iovec *vec, size_t count, std::unique_ptr< folly::IOBuf > &&buf, WriteFlags flags=WriteFlags::NONE) |
AsyncSocket::WriteResult | sendSocketMessage (int fd, struct msghdr *msg, int msg_flags) |
virtual ssize_t | tfoSendMsg (int fd, struct msghdr *msg, int msg_flags) |
int | socketConnect (const struct sockaddr *addr, socklen_t len) |
void | registerForConnectEvents () |
bool | updateEventRegistration () |
bool | updateEventRegistration (uint16_t enable, uint16_t disable) |
void | doClose () |
void | startFail () |
void | finishFail () |
void | finishFail (const AsyncSocketException &ex) |
void | invokeAllErrors (const AsyncSocketException &ex) |
void | fail (const char *fn, const AsyncSocketException &ex) |
void | failConnect (const char *fn, const AsyncSocketException &ex) |
void | failRead (const char *fn, const AsyncSocketException &ex) |
void | failErrMessageRead (const char *fn, const AsyncSocketException &ex) |
void | failWrite (const char *fn, WriteCallback *callback, size_t bytesWritten, const AsyncSocketException &ex) |
void | failWrite (const char *fn, const AsyncSocketException &ex) |
void | failAllWrites (const AsyncSocketException &ex) |
void | invalidState (ConnectCallback *callback) |
void | invalidState (ErrMessageCallback *callback) |
void | invalidState (ReadCallback *callback) |
void | invalidState (WriteCallback *callback) |
std::string | withAddr (const std::string &s) |
void | cacheLocalAddress () const |
void | cachePeerAddress () const |
bool | isZeroCopyRequest (WriteFlags flags) |
bool | isZeroCopyMsg (const cmsghdr &cmsg) const |
void | processZeroCopyMsg (const cmsghdr &cmsg) |
uint32_t | getNextZeroCopyBufId () |
void | adjustZeroCopyFlags (folly::WriteFlags &flags) |
void | addZeroCopyBuf (std::unique_ptr< folly::IOBuf > &&buf) |
void | addZeroCopyBuf (folly::IOBuf *ptr) |
void | setZeroCopyBuf (std::unique_ptr< folly::IOBuf > &&buf) |
bool | containsZeroCopyBuf (folly::IOBuf *ptr) |
void | releaseZeroCopyBuf (uint32_t id) |
Protected Member Functions inherited from folly::AsyncTransport | |
~AsyncTransport () override=default | |
Protected Member Functions inherited from folly::DelayedDestruction | |
~DelayedDestruction () override=default | |
DelayedDestruction () | |
Protected Member Functions inherited from folly::DelayedDestructionBase | |
DelayedDestructionBase () | |
uint32_t | getDestructorGuardCount () const |
Protected Member Functions inherited from folly::AsyncReader | |
virtual | ~AsyncReader ()=default |
Protected Member Functions inherited from folly::AsyncWriter | |
virtual | ~AsyncWriter ()=default |
Static Protected Member Functions | |
static void | sslInfoCallback (const SSL *ssl, int type, int val) |
static int | sslVerifyCallback (int preverifyOk, X509_STORE_CTX *ctx) |
Private Member Functions | |
void | handleReturnFromSSLAccept (int ret) |
void | init () |
Additional Inherited Members | |
Static Public Attributes inherited from folly::AsyncSocket | |
static const OptionMap | emptyOptionMap |
Protected Types inherited from folly::AsyncSocket | |
enum | ReadResultEnum { READ_EOF = 0, READ_ERROR = -1, READ_BLOCKING = -2, READ_NO_ERROR = -3 } |
enum | WriteResultEnum { WRITE_ERROR = -1 } |
enum | ShutdownFlags { SHUT_WRITE_PENDING = 0x01, SHUT_WRITE = 0x02, SHUT_READ = 0x04 } |
A class for performing asynchronous I/O on an SSL connection.
AsyncSSLSocket allows users to asynchronously wait for data on an SSL connection, and to asynchronously send data.
The APIs for reading and writing are intentionally asymmetric. Waiting for data to read is a persistent API: a callback is installed, and is notified whenever new data is available. It continues to be notified of new events until it is uninstalled.
AsyncSSLSocket does not provide read timeout functionality, because it typically cannot determine when the timeout should be active. Generally, a timeout should only be enabled when processing is blocked waiting on data from the remote endpoint. For server connections, the timeout should not be active if the server is currently processing one or more outstanding requests for this connection. For client connections, the timeout should not be active if there are no requests pending on the connection. Additionally, if a client has multiple pending requests, it will ususally want a separate timeout for each request, rather than a single read timeout.
The write API is fairly intuitive: a user can request to send a block of data, and a callback will be informed once the entire block has been transferred to the kernel, or on error. AsyncSSLSocket does provide a send timeout, since most callers want to give up if the remote end stops responding and no further progress can be made sending the data.
Definition at line 70 of file AsyncSSLSocket.h.
typedef std::unique_ptr<AsyncSSLSocket, Destructor> folly::AsyncSSLSocket::UniquePtr |
Definition at line 72 of file AsyncSSLSocket.h.
using folly::AsyncSSLSocket::X509_deleter = folly::static_function_deleter<X509, &X509_free> |
Definition at line 73 of file AsyncSSLSocket.h.
Enumerator | |
---|---|
STATE_UNINIT | |
STATE_UNENCRYPTED | |
STATE_ACCEPTING | |
STATE_CACHE_LOOKUP | |
STATE_ASYNC_PENDING | |
STATE_CONNECTING | |
STATE_ESTABLISHED | |
STATE_REMOTE_CLOSED | |
STATE_CLOSING |
remote end closed; we can still write close() called, but waiting on writes to complete |
STATE_CONNECTING_CLOSING |
close() called with pending writes, before connect() has completed |
STATE_CLOSED | |
STATE_ERROR |
Definition at line 428 of file AsyncSSLSocket.h.
folly::AsyncSSLSocket::AsyncSSLSocket | ( | const std::shared_ptr< folly::SSLContext > & | ctx, |
EventBase * | evb, | ||
bool | deferSecurityNegotiation = false |
||
) |
Create a client AsyncSSLSocket
Definition at line 222 of file AsyncSSLSocket.cpp.
References init(), sslState_, and STATE_UNENCRYPTED.
Referenced by AsyncSSLSocket(), and newSocket().
folly::AsyncSSLSocket::AsyncSSLSocket | ( | const std::shared_ptr< folly::SSLContext > & | ctx, |
EventBase * | evb, | ||
int | fd, | ||
bool | server = true , |
||
bool | deferSecurityNegotiation = false |
||
) |
Create a server/client AsyncSSLSocket from an already connected socket file descriptor.
Note that while AsyncSSLSocket enables TCP_NODELAY for sockets it creates when connecting, it does not change the socket options when given an existing file descriptor. If callers want TCP_NODELAY enabled when using this version of the constructor, they need to explicitly call setNoDelay(true) after the constructor returns.
ctx | SSL context for this connection. |
evb | EventBase that will manage this socket. |
fd | File descriptor to take over (should be a connected socket). |
server | Is socket in server mode? |
deferSecurityNegotiation | unencrypted data can be sent before sslConn/Accept |
Create a server/client AsyncSSLSocket
Definition at line 239 of file AsyncSSLSocket.cpp.
References ctx_, init(), folly::AsyncSocket::noTransparentTls_, sslInfoCallback(), sslState_, and STATE_UNENCRYPTED.
folly::AsyncSSLSocket::AsyncSSLSocket | ( | const std::shared_ptr< folly::SSLContext > & | ctx, |
AsyncSocket::UniquePtr | oldAsyncSocket, | ||
bool | server = true , |
||
bool | deferSecurityNegotiation = false |
||
) |
Create a server/client AsyncSSLSocket from an already connected AsyncSocket.
Definition at line 261 of file AsyncSSLSocket.cpp.
References AsyncSSLSocket(), ctx_, init(), folly::AsyncSocket::noTransparentTls_, sslInfoCallback(), sslState_, STATE_UNENCRYPTED, and string.
|
overrideprotected |
Protected destructor.
Users of AsyncSSLSocket must never delete it directly. Instead, invoke destroy() instead. (See the documentation in DelayedDestruction.h for more details.)
Definition at line 311 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::eventBase_, folly::AsyncSocket::eventFlags_, folly::AsyncSocket::fd_, sslState_, and folly::AsyncSocket::state_.
Referenced by setAsyncOperationFinishCallback().
|
protected |
Apply verification options passed to sslConn/sslAccept or those set in the underlying SSLContext object.
ssl | pointer to the SSL object on which verification options will be applied. If verifyPeer_ was explicitly set either via sslConn/sslAccept, those options override the settings in the underlying SSLContext. |
Definition at line 720 of file AsyncSSLSocket.cpp.
References ctx_, folly::SSLContext::getVerificationMode(), sslVerifyCallback(), and verifyPeer_.
Referenced by handleAccept(), sslConn(), and sslWriteImpl().
|
inlineoverridevirtual |
Attach the transport to a EventBase.
This may only be called if the transport is not currently attached to a EventBase (by an earlier call to detachEventBase()).
This method must be invoked in the EventBase's thread.
Reimplemented from folly::AsyncSocket.
Definition at line 569 of file AsyncSSLSocket.h.
References folly::AsyncTimeout::attachEventBase(), folly::AsyncSocket::attachEventBase(), connectionTimeout_, and handshakeTimeout_.
Referenced by folly::EvbAndContext::attach().
|
inlinevirtual |
Definition at line 585 of file AsyncSSLSocket.h.
References folly::AsyncTimeout::attachTimeoutManager(), and handshakeTimeout_.
|
static |
Definition at line 1751 of file AsyncSSLSocket.cpp.
References folly::IOBufQueue::append(), folly::ssl::OpenSSLUtils::getBioAppData(), folly::ssl::OpenSSLUtils::getBioFd(), folly::ssl::OpenSSLUtils::getBioShouldRetryWrite(), folly::IOBufQueue::move(), folly::gen::move, folly::io::detail::CursorBase< Derived, BufType >::pullAtMost(), folly::netops::recv(), and folly::IOBufQueue::trimStart().
Referenced by getSSLContext().
|
static |
Definition at line 1701 of file AsyncSSLSocket.cpp.
References folly::CORK, folly::EOR, folly::ssl::OpenSSLUtils::getBioAppData(), folly::ssl::OpenSSLUtils::getBioFd(), folly::ssl::OpenSSLUtils::getBioShouldRetryWrite(), folly::AsyncSocket::SendMsgParamsCallback::maxAncillaryDataSize, and folly::NONE.
Referenced by getSSLContext().
|
overrideprotectedvirtualnoexcept |
Reimplemented from folly::AsyncSocket.
Definition at line 1073 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::checkForImmediateRead(), folly::AsyncSocket::handleRead(), and ssl_.
Referenced by setAsyncOperationFinishCallback(), and sslAccept().
|
static |
Definition at line 1807 of file AsyncSSLSocket.cpp.
References clientHelloInfo_, folly::IOBuf::copyBuffer(), i, resetClientHelloParsing(), folly::ssl::SIGNATURE_ALGORITHMS, folly::ssl::SUPPORTED_VERSIONS, uint16_t, uint32_t, uint8_t, and folly::IOBuf::wrapBuffer().
Referenced by getSSLContext(), and handleAccept().
|
overridevirtual |
TODO: implement support for SSL renegotiation.
This involves proper handling of the SSL_ERROR_WANT_READ/WRITE code as a result of SSL_write/read(), instead of returning an error. In that case, the READ/WRITE event should be registered, and a flag (e.g., writeBlockedOnRead) should be set to indiciate the condition. In the next invocation of read/write callback, if the flag is on, performWrite()/performRead() should be called in addition to the normal call to performRead()/performWrite(), and the flag should be reset.
Reimplemented from folly::AsyncSocket.
Definition at line 327 of file AsyncSSLSocket.cpp.
References folly::AsyncTimeout::cancelTimeout(), folly::AsyncSocket::closeNow(), folly::AsyncSocketException::END_OF_FILE, folly::AsyncSocket::fd_, handshakeTimeout_, invokeHandshakeErr(), folly::AsyncTimeout::isScheduled(), ssl_, sslSession_, sslState_, and STATE_CLOSED.
Referenced by folly::test::MockAsyncSSLSocket::connect(), SSLCacheClient::handshakeSuc(), newSocket(), shutdownWriteNow(), and folly::TEST().
|
overridevirtualnoexcept |
Connect to the given address, invoking callback when complete or on error
Note timeout applies to TCP + SSL connection time
Reimplemented from folly::AsyncSocket.
Reimplemented in folly::test::MockAsyncSSLSocket.
Definition at line 682 of file AsyncSSLSocket.cpp.
References folly::detail::timeout.
Referenced by getSecurityProtocol().
|
virtualnoexcept |
A variant of connect that allows the caller to specify the timeout for the regular connect and the ssl connect separately. connectTimeout is specified as the time to establish a TCP connection. totalConnectTimeout defines the time it takes from starting the TCP connection to the time the ssl connection is established. The reason the timeout is defined this way is because user's rarely need to specify the SSL timeout independently of the connect timeout. It allows us to bound the time for a connect and SSL connection in a finer grained manner than if timeout was just defined independently for SSL.
Definition at line 692 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::connect(), folly::AsyncSocket::noTransparentTls_, server_, sslState_, folly::AsyncSocket::state_, STATE_UNENCRYPTED, STATE_UNINIT, totalConnectTimeout_, and folly::AsyncSocket::UNINIT.
|
overridevirtual |
Determine if transport is connected to the endpoint
Reimplemented from folly::AsyncSocket.
Definition at line 386 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::connecting(), folly::AsyncSocket::good(), server_, sslState_, STATE_CONNECTING, and STATE_UNINIT.
Referenced by newSocket().
|
inlineoverridevirtual |
Detach the transport from its EventBase.
This may only be called when the transport is idle and has no reads or writes pending. Once detached, the transport may not be used again until it is re-attached to a EventBase by calling attachEventBase().
This method must be called from the current EventBase's thread.
Reimplemented from folly::AsyncSocket.
Definition at line 575 of file AsyncSSLSocket.h.
References connectionTimeout_, folly::AsyncTimeout::detachEventBase(), folly::AsyncSocket::detachEventBase(), and handshakeTimeout_.
|
inlinevirtual |
Definition at line 589 of file AsyncSSLSocket.h.
References folly::AsyncTimeout::detachTimeoutManager(), and handshakeTimeout_.
void folly::AsyncSSLSocket::enableClientHelloParsing | ( | ) |
Definition at line 1796 of file AsyncSSLSocket.cpp.
References clientHelloInfo_, and parseClientHello_.
Referenced by getSecurityProtocol().
|
protected |
A SSL_write wrapper that understand EOR
ssl | SSL pointer |
buf | Buffer to be written |
n | Number of bytes to be written |
eor | Does the last byte (buf[n-1]) have the app-last-byte? |
Definition at line 1651 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::appBytesWritten_, appEorByteNo_, getRawBytesWritten(), folly::AsyncSocket::isEorTrackingEnabled(), minEorRawByteNo_, and sslWriteImpl().
Referenced by performWrite(), and sslWriteImpl().
|
protected |
Definition at line 650 of file AsyncSSLSocket.cpp.
References folly::AsyncTimeout::cancelTimeout(), folly::AsyncSocket::finishFail(), handshakeTimeout_, invokeHandshakeErr(), folly::AsyncTimeout::isScheduled(), and folly::AsyncSocket::startFail().
Referenced by handleAccept(), handleConnect(), handleReturnFromSSLAccept(), invalidState(), restartSSLAccept(), sslConn(), sslWriteImpl(), and timeoutExpired().
|
inline |
Force AsyncSSLSocket object to cache local and peer socket addresses. If called with "true" before connect() this function forces full local and remote socket addresses to be cached in the socket object and available through getLocalAddress()/getPeerAddress() methods even after the socket is closed.
Definition at line 765 of file AsyncSSLSocket.h.
References cacheAddrOnFailure_.
|
overridevirtualnoexcept |
Return the application protocol being used by the underlying transport protocol. This is useful for transports which are used to tunnel other protocols.
Reimplemented from folly::AsyncTransport.
Definition at line 394 of file AsyncSSLSocket.cpp.
References getSelectedNextProtocolNoThrow(), and string.
Referenced by newSocket().
|
inline |
|
inline |
Definition at line 716 of file AsyncSSLSocket.h.
References clientHelloInfo_.
Referenced by wangle::SSLContextManager::addSSLContextConfig().
|
static |
Definition at line 645 of file AsyncSSLSocket.cpp.
References getSSLExDataIndex().
Referenced by wangle::SSLContextManager::addSSLContextConfig(), wangle::SSLSessionCacheManager::getSession(), folly::TestSSLAsyncCacheServer::getSessionCallback(), wangle::SSLSessionCallbacks::getSessionKeyFromSSL(), getSSLContext(), folly::SNIServer::serverNameCallback(), sslInfoCallback(), and sslVerifyCallback().
|
inlinevirtual |
Returns the time taken to complete a handshake.
Definition at line 723 of file AsyncSSLSocket.h.
References handshakeEndTime_, and handshakeStartTime_.
|
inline |
Definition at line 731 of file AsyncSSLSocket.h.
References getPeerCertificate(), getSelfCertificate(), minWriteSize_, setBufferMovableEnabled(), and setReadCB().
|
virtual |
Get the negociated cipher name for this SSL connection. Returns the cipher used or the constant value "NONE" when no SSL session has been established.
Definition at line 882 of file AsyncSSLSocket.cpp.
References ssl_.
Referenced by proxygen::HTTPConnector::connectSuccess(), wangle::SSLAcceptorHandshakeHelper::fillSSLTransportInfoFields(), and setSessionIDResumed().
|
inlineoverridevirtual |
Returns the peer certificate, or nullptr if no peer certificate received.
Reimplemented from folly::AsyncTransport.
Definition at line 750 of file AsyncSSLSocket.h.
References getPeerCertificate().
|
overridevirtual |
Get the peer certificate information if any
Reimplemented from folly::AsyncSocket.
Definition at line 935 of file AsyncSSLSocket.cpp.
References folly::gen::move, folly::AsyncSocket::peerCertData_, and ssl_.
Referenced by getMinWriteSize(), and getPeerCert().
|
overridevirtual |
Reimplemented from folly::AsyncSocket.
Definition at line 429 of file AsyncSSLSocket.cpp.
Referenced by wangle::SSLAcceptorHandshakeHelper::fillSSLTransportInfoFields(), and getSecurityProtocol().
|
overridevirtual |
Reimplemented from folly::AsyncSocket.
Definition at line 411 of file AsyncSSLSocket.cpp.
References b, cpp.ast::next(), and ssl_.
Referenced by eorAwareSSLWrite(), wangle::SSLAcceptorHandshakeHelper::fillSSLTransportInfoFields(), and getSecurityProtocol().
|
inlineoverridevirtual |
Returns the name of the security protocol being used.
Reimplemented from folly::AsyncTransport.
Definition at line 330 of file AsyncSSLSocket.h.
References folly::AsyncSocket::anyAddress(), connect(), folly::AsyncSocket::connect(), folly::AsyncSocket::emptyOptionMap, enableClientHelloParsing(), getRawBytesReceived(), getRawBytesWritten(), folly::pushmi::__adl::noexcept(), restartSSLAccept(), setEorTracking(), sslAccept(), sslConn(), sslState_, STATE_UNENCRYPTED, and folly::detail::timeout.
Referenced by wangle::SSLAcceptorHandshakeHelper::fillSSLTransportInfoFields().
|
virtual |
Get the name of the protocol selected by the client during Application Layer Protocol Negotiation (ALPN)
Throw an exception if openssl does not support NPN
protoName | Name of the protocol (not guaranteed to be null terminated); will be set to nullptr if the client did not negotiate a protocol. Note: the AsyncSSLSocket retains ownership of this string. |
protoNameLen | Length of the name. |
protoType | Whether this was an NPN or ALPN negotiation |
Definition at line 853 of file AsyncSSLSocket.cpp.
References getSelectedNextProtocolNoThrow(), and folly::AsyncSocketException::NOT_SUPPORTED.
Referenced by folly::test::MockAsyncSSLSocket::connect(), getSSLState(), and CurlService::CurlClient::sslHandshakeFollowup().
|
virtual |
Get the name of the protocol selected by the client during Next Protocol Negotiation (NPN) or Application Layer Protocol Negotiation (ALPN)
protoName | Name of the protocol (not guaranteed to be null terminated); will be set to nullptr if the client did not negotiate a protocol. Note: the AsyncSSLSocket retains ownership of this string. |
protoNameLen | Length of the name. |
protoType | Whether this was an NPN or ALPN negotiation |
Definition at line 862 of file AsyncSSLSocket.cpp.
References ssl_.
Referenced by folly::test::MockAsyncSSLSocket::connect(), getApplicationProtocol(), getSelectedNextProtocol(), and getSSLState().
|
overridevirtual |
Get the certificate used for this SSL connection. May be null
Reimplemented from folly::AsyncTransport.
Definition at line 967 of file AsyncSSLSocket.cpp.
References ssl_.
Referenced by setSessionIDResumed().
|
overridevirtual |
Get the certificate information of this transport, if any
Reimplemented from folly::AsyncSocket.
Definition at line 950 of file AsyncSSLSocket.cpp.
References folly::gen::move, folly::AsyncSocket::selfCertData_, and ssl_.
Referenced by getMinWriteSize().
|
inline |
const SSL * folly::AsyncSSLSocket::getSSL | ( | ) | const |
Get a handle to the SSL struct.
Definition at line 837 of file AsyncSSLSocket.cpp.
References ssl_.
Referenced by getSSLState().
std::string folly::AsyncSSLSocket::getSSLAlertsReceived | ( | ) | const |
Definition at line 2004 of file AsyncSSLSocket.cpp.
References alertsReceived_, and string.
Referenced by getSSLContext().
const char * folly::AsyncSSLSocket::getSSLCertSigAlgName | ( | ) | const |
Get the signature algorithm used in the cert that is used for this connection.
Definition at line 915 of file AsyncSSLSocket.cpp.
References ssl_.
Referenced by wangle::SSLAcceptorHandshakeHelper::fillSSLTransportInfoFields(), and setSessionIDResumed().
int folly::AsyncSSLSocket::getSSLCertSize | ( | ) | const |
Get the certificate size used for this SSL connection.
Definition at line 924 of file AsyncSSLSocket.cpp.
References ssl_.
Referenced by wangle::SSLAcceptorHandshakeHelper::fillSSLTransportInfoFields(), and setSessionIDResumed().
std::string folly::AsyncSSLSocket::getSSLCertVerificationAlert | ( | ) | const |
Definition at line 2021 of file AsyncSSLSocket.cpp.
References sslVerificationAlert_.
Referenced by getSSLContext().
void folly::AsyncSSLSocket::getSSLClientCiphers | ( | std::string & | clientCiphers, |
bool | convertToString = true |
||
) | const |
Get the list of supported ciphers sent by the client in the client's preference order.
Definition at line 1919 of file AsyncSSLSocket.cpp.
References clientHelloInfo_, folly::gen::first, folly::ssl::OpenSSLUtils::getCipherName(), folly::hexlify(), folly::gen::move, name, parseClientHello_, string, and uint8_t.
Referenced by wangle::SSLAcceptorHandshakeHelper::fillSSLTransportInfoFields(), and getSSLContext().
std::string folly::AsyncSSLSocket::getSSLClientComprMethods | ( | ) | const |
Get the list of compression methods sent by the client in TLS Hello.
Definition at line 1962 of file AsyncSSLSocket.cpp.
References clientHelloInfo_, folly::join(), and parseClientHello_.
Referenced by wangle::SSLAcceptorHandshakeHelper::fillSSLTransportInfoFields(), and getSSLContext().
std::string folly::AsyncSSLSocket::getSSLClientExts | ( | ) | const |
Get the list of TLS extensions sent by the client in the TLS Hello.
Definition at line 1969 of file AsyncSSLSocket.cpp.
References clientHelloInfo_, folly::join(), and parseClientHello_.
Referenced by wangle::SSLAcceptorHandshakeHelper::fillSSLTransportInfoFields(), and getSSLContext().
std::string folly::AsyncSSLSocket::getSSLClientSigAlgs | ( | ) | const |
Definition at line 1976 of file AsyncSSLSocket.cpp.
References clientHelloInfo_, i, parseClientHello_, and string.
Referenced by wangle::SSLAcceptorHandshakeHelper::fillSSLTransportInfoFields(), and getSSLContext().
std::string folly::AsyncSSLSocket::getSSLClientSupportedVersions | ( | ) | const |
Get the list of versions in the supported versions extension (used to negotiate TLS 1.3).
Definition at line 1997 of file AsyncSSLSocket.cpp.
References clientHelloInfo_, folly::join(), and parseClientHello_.
Referenced by wangle::SSLAcceptorHandshakeHelper::fillSSLTransportInfoFields(), and getSSLContext().
|
inline |
Returns the original folly::SSLContext associated with this socket.
Suitable for use in AsyncSSLSocket constructor to construct a new AsyncSSLSocket using an existing socket's context.
switchServerSSLContext() does not affect this return value.
Definition at line 615 of file AsyncSSLSocket.h.
References b, bioRead(), bioWrite(), clientHelloParsingCallback(), ctx_, getFromSSL(), getSSLAlertsReceived(), getSSLCertVerificationAlert(), getSSLClientCiphers(), getSSLClientComprMethods(), getSSLClientExts(), getSSLClientSigAlgs(), getSSLClientSupportedVersions(), getSSLExDataIndex(), getSSLServerCiphers(), getSSLServerNameFromSSL(), getSSLSharedCiphers(), needsPeerVerification(), folly::pushmi::__adl::noexcept(), resetClientHelloParsing(), setSSLCertVerificationAlert(), string, folly::detail::timeout, folly::AsyncSocket::timeoutExpired(), and version.
|
static |
Definition at line 639 of file AsyncSSLSocket.cpp.
Referenced by getFromSSL(), getSSLContext(), handleAccept(), and sslConn().
void folly::AsyncSSLSocket::getSSLServerCiphers | ( | std::string & | serverCiphers | ) | const |
Get the list of ciphers supported by the server in the server's preference order.
Definition at line 2032 of file AsyncSSLSocket.cpp.
References cipher, i, and ssl_.
Referenced by wangle::SSLAcceptorHandshakeHelper::fillSSLTransportInfoFields(), and getSSLContext().
const char * folly::AsyncSSLSocket::getSSLServerName | ( | ) | const |
Get the server name for this SSL connection. Returns the server name used or the constant value "NONE" when no SSL session has been established. If openssl has no SNI support, throw TTransportException.
Definition at line 898 of file AsyncSSLSocket.cpp.
References getSSLServerNameFromSSL(), folly::AsyncSocketException::NOT_SUPPORTED, and ssl_.
Referenced by wangle::SSLAcceptorHandshakeHelper::fillSSLTransportInfoFields(), and setSessionIDResumed().
|
static |
Definition at line 887 of file AsyncSSLSocket.cpp.
Referenced by getSSLContext(), getSSLServerName(), getSSLServerNameNoThrow(), and wangle::SSLSessionCallbacks::newSessionCallback().
const char * folly::AsyncSSLSocket::getSSLServerNameNoThrow | ( | ) | const |
Get the server name for this SSL connection. Returns the server name used or the constant value "NONE" when no SSL session has been established. If openssl has no SNI support, return "NONE"
Definition at line 907 of file AsyncSSLSocket.cpp.
References getSSLServerNameFromSSL(), and ssl_.
Referenced by setSessionIDResumed().
SSL_SESSION * folly::AsyncSSLSocket::getSSLSession | ( | ) |
Get a handle to the negotiated SSL session. This increments the session refcount and must be deallocated by the caller.
Definition at line 829 of file AsyncSSLSocket.cpp.
References ssl_, sslSession_, sslState_, and STATE_ESTABLISHED.
Referenced by wangle::ClientBootstrap< Pipeline >::ConnectCallback::connectSuccess(), getSSLState(), and SSLCacheClient::handshakeSuc().
|
virtual |
Determine if the session specified during setSSLSession was reused or if the server rejected it and issued a new session.
Definition at line 875 of file AsyncSSLSocket.cpp.
References ssl_, sslState_, and STATE_ESTABLISHED.
Referenced by wangle::ClientBootstrap< Pipeline >::ConnectCallback::connectSuccess(), wangle::SSLUtil::getResumeState(), getSSLState(), and SSLCacheClient::handshakeSuc().
void folly::AsyncSSLSocket::getSSLSharedCiphers | ( | std::string & | sharedCiphers | ) | const |
Get the list of shared ciphers between the server and the client. Works well for only SSLv2, not so good for SSLv3 or TLSv1.
Definition at line 2025 of file AsyncSSLSocket.cpp.
References ssl_.
Referenced by getSSLContext().
|
inline |
Definition at line 444 of file AsyncSSLSocket.h.
References getSelectedNextProtocol(), getSelectedNextProtocolNoThrow(), getSSL(), getSSLSession(), getSSLSessionReused(), setSSLSession(), and sslState_.
int folly::AsyncSSLSocket::getSSLVersion | ( | ) | const |
Get the SSL version for this connection. Possible return values are SSL2_VERSION, SSL3_VERSION, TLS1_VERSION, with hexa representations 0x200, 0x300, 0x301, or 0 if no SSL session has been established.
Definition at line 911 of file AsyncSSLSocket.cpp.
References ssl_.
Referenced by proxygen::HTTPConnector::connectSuccess(), wangle::SSLAcceptorHandshakeHelper::fillSSLTransportInfoFields(), and setSessionIDResumed().
|
inline |
If the SSL socket was used to connect as well as establish an SSL connection, this gives the total timeout for the connect + SSL connection that was set.
Definition at line 795 of file AsyncSSLSocket.h.
References totalConnectTimeout_.
|
overridevirtual |
Determine if transport is open and ready to read or write.
Note that this function returns false on EOF; you must also call error() to distinguish between an EOF and an error.
Reimplemented from folly::AsyncSocket.
Definition at line 374 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::good(), sslState_, STATE_ACCEPTING, STATE_CONNECTING, STATE_ESTABLISHED, STATE_UNENCRYPTED, and STATE_UNINIT.
Referenced by folly::test::MockAsyncSSLSocket::connect(), and newSocket().
|
protectednoexcept |
Definition at line 1108 of file AsyncSSLSocket.cpp.
References applyVerificationOptions(), clientHelloParsingCallback(), ctx_, folly::AsyncSocket::ESTABLISHED, folly::AsyncSocket::eventFlags_, failHandshake(), folly::AsyncSocket::fd_, getSSLExDataIndex(), handleReturnFromSSLAccept(), folly::AsyncSocketException::INTERNAL_ERROR, folly::EventHandler::NONE, parseClientHello_, folly::EventHandler::READ, server_, setupSSLBio(), ssl_, sslState_, folly::AsyncSocket::state_, STATE_ACCEPTING, STATE_ERROR, folly::AsyncSocket::updateEventRegistration(), and folly::EventHandler::WRITE.
Referenced by handleRead(), handleWrite(), restartSSLAccept(), and setAsyncOperationFinishCallback().
|
overrideprotectedvirtualnoexcept |
Reimplemented from folly::AsyncSocket.
Definition at line 1209 of file AsyncSSLSocket.cpp.
References folly::AsyncTimeout::cancelTimeout(), folly::AsyncSocket::CONNECTING, folly::AsyncSocket::ESTABLISHED, folly::AsyncSocket::eventBase_, folly::AsyncSocket::eventFlags_, failHandshake(), folly::AsyncSocket::FAST_OPEN, folly::AsyncSocket::fd_, folly::AsyncSocket::handleConnect(), folly::AsyncSocket::handleInitialReadWrite(), handshakeComplete_, handshakeTimeout_, invokeHandshakeCB(), folly::AsyncTimeout::isScheduled(), folly::EventHandler::READ, server_, ssl_, sslState_, folly::AsyncSocket::state_, STATE_CONNECTING, STATE_ERROR, STATE_ESTABLISHED, folly::AsyncSocket::updateEventRegistration(), willBlock(), and folly::EventHandler::WRITE.
Referenced by handleRead(), handleWrite(), setAsyncOperationFinishCallback(), and startSSLConnect().
|
inlineoverrideprotectedvirtualnoexcept |
Reimplemented from folly::AsyncSocket.
Definition at line 836 of file AsyncSSLSocket.h.
References count, folly::AsyncSocket::error(), interpretSSLError(), performRead(), performWrite(), performWriteIovec(), and uint32_t.
|
overrideprotectedvirtualnoexcept |
Reimplemented from folly::AsyncSocket.
Definition at line 1357 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::ESTABLISHED, folly::AsyncSocket::eventFlags_, folly::AsyncSocket::fd_, handleAccept(), handleConnect(), folly::AsyncSocket::handleRead(), server_, sslState_, folly::AsyncSocket::state_, STATE_ACCEPTING, and STATE_CONNECTING.
Referenced by setAsyncOperationFinishCallback().
|
private |
Handle the return from invoking SSL_accept
Definition at line 1155 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::eventBase_, folly::AsyncSocket::eventFlags_, failHandshake(), folly::AsyncSocket::fd_, folly::AsyncSocket::handleInitialReadWrite(), handshakeComplete_, invokeHandshakeCB(), folly::EventHandler::READ, sslState_, folly::AsyncSocket::state_, STATE_ACCEPTING, STATE_ERROR, STATE_ESTABLISHED, folly::AsyncSocket::updateEventRegistration(), willBlock(), and folly::EventHandler::WRITE.
Referenced by handleAccept(), and setAsyncOperationFinishCallback().
|
overrideprotectedvirtualnoexcept |
This function attempts to write as much data as possible, until no more data can be written.
Reimplemented from folly::AsyncSocket.
Definition at line 1449 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::ESTABLISHED, folly::AsyncSocket::eventFlags_, folly::AsyncSocket::fd_, handleAccept(), handleConnect(), folly::AsyncSocket::handleWrite(), server_, sslState_, folly::AsyncSocket::state_, STATE_ACCEPTING, and STATE_CONNECTING.
Referenced by setAsyncOperationFinishCallback().
|
private |
Definition at line 318 of file AsyncSSLSocket.cpp.
References ctx_.
Referenced by AsyncSSLSocket(), and setAsyncOperationFinishCallback().
|
protected |
Definition at line 1473 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::eventFlags_, folly::AsyncSocket::fd_, folly::INVALID_RENEGOTIATION, sslState_, folly::AsyncSocket::state_, and folly::AsyncSocket::WRITE_ERROR.
Referenced by handleInitialReadWrite(), and performWrite().
|
protected |
Definition at line 438 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::eventFlags_, failHandshake(), folly::AsyncSocket::fd_, handshakeCallback_, handshakeEndTime_, handshakeTimeout_, folly::AsyncSocketException::INVALID_STATE, folly::AsyncTimeout::isScheduled(), now(), server_, sslState_, folly::AsyncSocket::state_, and STATE_ERROR.
Referenced by setAsyncOperationFinishCallback(), sslAccept(), and sslConn().
|
overrideprotectedvirtual |
Reimplemented from folly::AsyncSocket.
Definition at line 1281 of file AsyncSSLSocket.cpp.
References folly::AsyncTimeout::cancelTimeout(), connectionTimeout_, handshakeTimeout_, folly::AsyncSocket::invokeConnectErr(), invokeHandshakeErr(), folly::AsyncTimeout::isScheduled(), and sslState_.
Referenced by sslWriteImpl().
|
overrideprotectedvirtual |
Reimplemented from folly::AsyncSocket.
Definition at line 1294 of file AsyncSSLSocket.cpp.
References folly::AsyncTimeout::cancelTimeout(), connectionTimeout_, folly::AsyncSocket::invokeConnectSuccess(), sslState_, startSSLConnect(), and folly::AsyncSocket::tfoAttempted_.
Referenced by sslWriteImpl().
|
protected |
Definition at line 670 of file AsyncSSLSocket.cpp.
References folly::AsyncTimeout::cancelTimeout(), handshakeCallback_, handshakeEndTime_, folly::AsyncSSLSocket::HandshakeCB::handshakeSuc(), handshakeTimeout_, folly::AsyncTimeout::isScheduled(), and now().
Referenced by handleConnect(), handleReturnFromSSLAccept(), and sslWriteImpl().
|
protected |
Definition at line 661 of file AsyncSSLSocket.cpp.
References handshakeCallback_, handshakeEndTime_, folly::AsyncSSLSocket::HandshakeCB::handshakeErr(), and now().
Referenced by closeNow(), failHandshake(), invokeConnectErr(), and sslWriteImpl().
|
inlineoverridevirtual |
Determine if the transport can be detached.
This method must be called from the current EventBase's thread.
Reimplemented from folly::AsyncSocket.
Definition at line 581 of file AsyncSSLSocket.h.
References handshakeTimeout_, folly::AsyncSocket::isDetachable(), and folly::AsyncTimeout::isScheduled().
bool folly::AsyncSSLSocket::needsPeerVerification | ( | ) | const |
Method to check if peer verfication is set.
Definition at line 711 of file AsyncSSLSocket.cpp.
References ctx_, and verifyPeer_.
Referenced by getSSLContext().
|
inlinestatic |
Helper function to create a server/client shared_ptr<AsyncSSLSocket>.
Definition at line 239 of file AsyncSSLSocket.h.
References AsyncSSLSocket().
Referenced by wangle::ClientBootstrap< DefaultPipeline >::connect(), folly::SSLClient::connect(), folly::SSLServerAcceptCallbackBase::connectionAccepted(), folly::EvbAndContext::createSocket(), and newSocket().
|
inlinestatic |
Helper function to create a client shared_ptr<AsyncSSLSocket>.
Definition at line 253 of file AsyncSSLSocket.h.
References AsyncSSLSocket(), closeNow(), connecting(), getApplicationProtocol(), good(), newSocket(), folly::pushmi::__adl::noexcept(), shutdownWrite(), shutdownWriteNow(), and string.
|
overrideprotectedvirtual |
Attempt to read from the socket.
buf | The buffer to read data into. |
buflen | The length of the buffer. |
Reimplemented from folly::AsyncSocket.
Definition at line 1380 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::appBytesReceived_, folly::CLIENT_RENEGOTIATION, folly::AsyncSocket::eventFlags_, folly::AsyncSocket::fd_, folly::INVALID_RENEGOTIATION, folly::AsyncSocket::isBufferMovable_, folly::AsyncSocket::performRead(), folly::AsyncSocket::READ_BLOCKING, folly::AsyncSocket::READ_ERROR, renegotiateAttempted_, server_, ssl_, sslState_, folly::AsyncSocket::state_, and STATE_UNENCRYPTED.
Referenced by handleInitialReadWrite().
|
overrideprotectedvirtual |
Attempt to write to the socket.
vec | The iovec array pointing to the buffers to write. |
count | The length of the iovec array. |
flags | Set of write flags. |
countWritten | On return, the value pointed to by this parameter will contain the number of iovec entries that were fully written. |
partialWritten | On return, the value pointed to by this parameter will contain the number of bytes written in the partially written iovec entry. |
Reimplemented from folly::AsyncSocket.
Definition at line 1501 of file AsyncSSLSocket.cpp.
References folly::CORK, corkCurrentWrite_, count, folly::EARLY_WRITE, folly::EOR, eorAwareSSLWrite(), folly::AsyncSocket::eventFlags_, folly::AsyncSocket::fd_, i, interpretSSLError(), folly::isSet(), min, minWriteSize_, folly::AsyncSocket::performWrite(), SCOPE_EXIT, ssl_, sslState_, folly::AsyncSocket::state_, STATE_ESTABLISHED, STATE_UNENCRYPTED, uint32_t, and folly::AsyncSocket::WRITE_ERROR.
Referenced by handleInitialReadWrite().
|
protected |
Referenced by handleInitialReadWrite().
|
overrideprotectedvirtual |
Reimplemented from folly::AsyncSocket.
Definition at line 1346 of file AsyncSSLSocket.cpp.
References folly::AsyncReader::ReadCallback::getReadBuffer(), folly::AsyncSocket::isBufferMovable_, and folly::AsyncSocket::readCallback_.
Referenced by setAsyncOperationFinishCallback().
void folly::AsyncSSLSocket::resetClientHelloParsing | ( | SSL * | ssl | ) |
Definition at line 1801 of file AsyncSSLSocket.cpp.
References clientHelloInfo_.
Referenced by clientHelloParsingCallback(), and getSSLContext().
void folly::AsyncSSLSocket::restartSSLAccept | ( | ) |
Invoke SSL accept following an asynchronous session cache lookup
Definition at line 1084 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::eventFlags_, failHandshake(), folly::AsyncSocket::fd_, handleAccept(), sslState_, folly::AsyncSocket::state_, STATE_ACCEPTING, STATE_ASYNC_PENDING, STATE_CACHE_LOOKUP, STATE_CLOSED, STATE_ERROR, and folly::AsyncSocketException::TIMED_OUT.
Referenced by getSecurityProtocol(), folly::TestSSLAsyncCacheServer::getSessionCallback(), and wangle::SSLSessionCacheManager::restartSSLAccept().
|
overrideprotectedvirtual |
Reimplemented from folly::AsyncSocket.
Definition at line 1306 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::connectCallback_, connectionTimeout_, folly::AsyncSocket::connectTimeout_, folly::AsyncSocketException::INTERNAL_ERROR, folly::AsyncSocket::scheduleConnectTimeout(), folly::AsyncSSLSocket::Timeout::scheduleTimeout(), sslState_, and folly::AsyncSocket::withAddr().
Referenced by sslWriteImpl().
|
inline |
true if the session was resumed using session ID
Definition at line 514 of file AsyncSSLSocket.h.
References sessionIDResumed_.
Referenced by wangle::SSLUtil::getResumeState().
|
inline |
Definition at line 785 of file AsyncSSLSocket.h.
References sessionResumptionAttempted_.
|
inline |
Definition at line 800 of file AsyncSSLSocket.h.
References asyncOperationFinishCallback_, checkForImmediateRead(), handleAccept(), handleConnect(), handleRead(), handleReturnFromSSLAccept(), handleWrite(), init(), invalidState(), folly::gen::move, folly::pushmi::__adl::noexcept(), prepareReadBuffer(), willBlock(), and ~AsyncSSLSocket().
void folly::AsyncSSLSocket::setBufferMovableEnabled | ( | bool | enabled | ) |
Tries to enable the buffer movable experimental feature in openssl. This is not guaranteed to succeed in case openssl does not have the experimental feature built in.
Definition at line 1342 of file AsyncSSLSocket.cpp.
References bufferMovableEnabled_.
Referenced by getMinWriteSize().
|
inline |
|
overridevirtual |
Reimplemented from folly::AsyncSocket.
Definition at line 403 of file AsyncSSLSocket.cpp.
References appEorByteNo_, folly::AsyncSocket::isEorTrackingEnabled(), minEorRawByteNo_, and folly::AsyncSocket::setEorTracking().
Referenced by getSecurityProtocol().
|
inline |
|
overridevirtual |
Reimplemented from folly::AsyncSocket.
Definition at line 1328 of file AsyncSSLSocket.cpp.
References bufferMovableEnabled_, folly::AsyncReader::ReadCallback::isBufferMovable(), folly::AsyncSocket::isBufferMovable_, folly::AsyncSocket::setReadCB(), and ssl_.
Referenced by folly::test::MockAsyncSSLSocket::connect(), and getMinWriteSize().
|
inline |
Definition at line 518 of file AsyncSSLSocket.h.
References getNegotiatedCipherName(), getSelfCert(), getSSLCertSigAlgName(), getSSLCertSize(), getSSLServerName(), getSSLServerNameNoThrow(), getSSLVersion(), and sessionIDResumed_.
Referenced by wangle::SSLSessionCacheManager::getSession().
|
inline |
void folly::AsyncSSLSocket::setSSLCertVerificationAlert | ( | std::string | alert | ) |
Definition at line 2017 of file AsyncSSLSocket.cpp.
References folly::gen::move, and sslVerificationAlert_.
Referenced by getSSLContext().
void folly::AsyncSSLSocket::setSSLSession | ( | SSL_SESSION * | session, |
bool | takeOwnership = false |
||
) |
Set the SSL session to be used during sslConn. AsyncSSLSocket will hold a reference to the session until it is destroyed or released by the underlying SSL structure.
takeOwnership | if true, AsyncSSLSocket will assume the caller's reference count to session. |
Definition at line 841 of file AsyncSSLSocket.cpp.
References sslSession_.
Referenced by SSLCacheClient::connectSuccess(), and getSSLState().
|
protected |
Sets up SSL with a custom write bio which intercepts all writes.
Definition at line 740 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::fd_, folly::ssl::OpenSSLUtils::setBioAppData(), folly::ssl::OpenSSLUtils::setBioFd(), and ssl_.
Referenced by handleAccept(), sslConn(), and sslWriteImpl().
|
overridevirtual |
Perform a half-shutdown of the write side of the transport.
The caller should not make any more calls to write() or writev() after shutdownWrite() is called. Any future write attempts will fail immediately.
Not all transport types support half-shutdown. If the underlying transport does not support half-shutdown, it will fully shutdown both the read and write sides of the transport. (Fully shutting down the socket is better than doing nothing at all, since the caller may rely on the shutdownWrite() call to notify the other end of the connection that no more data can be read.)
If there is pending data still waiting to be written on the transport, the actual shutdown will be delayed until the pending data has been written.
Note: There is no corresponding shutdownRead() equivalent. Simply uninstall the read callback if you wish to stop reading. (On TCP sockets at least, shutting down the read side of the socket is a no-op anyway.)
Reimplemented from folly::AsyncSocket.
Definition at line 359 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::close().
Referenced by newSocket().
|
overridevirtual |
Perform a half-shutdown of the write side of the transport.
shutdownWriteNow() is identical to shutdownWrite(), except that it immediately performs the shutdown, rather than waiting for pending writes to complete. Any pending write requests will be immediately failed when shutdownWriteNow() is called.
Reimplemented from folly::AsyncSocket.
Definition at line 370 of file AsyncSSLSocket.cpp.
References closeNow().
Referenced by newSocket().
|
virtual |
Accept an SSL connection on the socket.
The callback will be invoked and uninstalled when an SSL connection has been established on the underlying socket. The value of verifyPeer determines the client verification method. By default, its set to use the value in the underlying context
callback | callback object to invoke on success/failure |
timeout | timeout for this function in milliseconds, or 0 for no timeout |
verifyPeer | SSLVerifyPeerEnum uses the options specified in the context by default, can be set explcitly to override the method in the context |
Reimplemented in folly::test::MockAsyncSSLSocket.
Definition at line 461 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::cacheAddresses(), cacheAddrOnFailure_, checkForImmediateRead(), ctx_, folly::EventBase::dcheckIsInEventBaseThread(), folly::AsyncSocket::eventBase_, folly::AsyncSocket::getFd(), folly::SSLContext::getSSLCtx(), folly::ssl::OpenSSLUtils::getSSLInitialCtx(), folly::gen::guard(), handshakeCallback_, handshakeEndTime_, handshakeStartTime_, handshakeTimeout_, invalidState(), folly::gen::move, now(), folly::EventHandler::READ, folly::AsyncSSLSocket::Timeout::scheduleTimeout(), server_, folly::ssl::OpenSSLUtils::setSSLInitialCtx(), ssl_, folly::portability::ssl::SSL_SESSION_get0_hostname(), sslInfoCallback(), sslState_, STATE_ACCEPTING, STATE_UNENCRYPTED, STATE_UNINIT, string, folly::AsyncSocket::updateEventRegistration(), verifyPeer_, and folly::EventHandler::WRITE.
Referenced by folly::SSLServerAcceptCallback::connAccepted(), folly::SSLServerAsyncCacheAcceptCallback::connAccepted(), folly::HandshakeErrorCallback::connAccepted(), and getSecurityProtocol().
|
virtual |
Initiate an SSL connection on the socket The callback will be invoked and uninstalled when an SSL connection has been establshed on the underlying socket. The verification option verifyPeer is applied if it's passed explicitly. If it's not, the options in SSLContext set on the underlying SSLContext are applied.
callback | callback object to invoke on success/failure |
timeout | timeout for this function in milliseconds, or 0 for no timeout |
verifyPeer | SSLVerifyPeerEnum uses the options specified in the context by default, can be set explcitly to override the method in the context. If verification is turned on sets SSL_VERIFY_PEER and invokes HandshakeCB::handshakeVer(). |
Reimplemented in folly::test::MockAsyncSSLSocket.
Definition at line 753 of file AsyncSSLSocket.cpp.
References applyVerificationOptions(), folly::AsyncSocket::cacheAddresses(), cacheAddrOnFailure_, ctx_, folly::EventBase::dcheckIsInEventBaseThread(), folly::AsyncSocket::eventBase_, failHandshake(), folly::AsyncSocket::fd_, getSSLExDataIndex(), handshakeCallback_, handshakeConnectTimeout_, folly::AsyncSocketException::INTERNAL_ERROR, invalidState(), server_, sessionResumptionAttempted_, setupSSLBio(), ssl_, sslSession_, sslState_, startSSLConnect(), STATE_CONNECTING, STATE_ERROR, STATE_UNENCRYPTED, STATE_UNINIT, and verifyPeer_.
Referenced by SSLCacheClient::connectSuccess(), and getSecurityProtocol().
|
staticprotected |
Definition at line 1686 of file AsyncSSLSocket.cpp.
References alertsReceived_, getFromSSL(), handshakeComplete_, renegotiateAttempted_, and type.
Referenced by AsyncSSLSocket(), sslAccept(), and sslWriteImpl().
|
staticprotected |
Definition at line 1782 of file AsyncSSLSocket.cpp.
References getFromSSL().
Referenced by applyVerificationOptions().
|
inlineprotectedvirtual |
Definition at line 855 of file AsyncSSLSocket.h.
References applyVerificationOptions(), eorAwareSSLWrite(), failHandshake(), invokeConnectErr(), invokeConnectSuccess(), invokeHandshakeCB(), invokeHandshakeErr(), scheduleConnectTimeout(), setupSSLBio(), sslInfoCallback(), startSSLConnect(), type, and val.
Referenced by eorAwareSSLWrite().
|
protected |
Definition at line 819 of file AsyncSSLSocket.cpp.
References handleConnect(), handshakeConnectTimeout_, handshakeEndTime_, handshakeStartTime_, handshakeTimeout_, now(), and folly::AsyncSSLSocket::Timeout::scheduleTimeout().
Referenced by invokeConnectSuccess(), sslConn(), and sslWriteImpl().
|
noexcept |
Definition at line 609 of file AsyncSSLSocket.cpp.
References folly::AsyncSocket::CONNECTING, folly::AsyncSocket::ESTABLISHED, failHandshake(), folly::sformat(), sslState_, folly::AsyncSocket::state_, STATE_ACCEPTING, STATE_ASYNC_PENDING, STATE_CACHE_LOOKUP, STATE_CONNECTING, STATE_ERROR, folly::AsyncSocketException::TIMED_OUT, and folly::detail::timeout.
|
protectednoexcept |
Definition at line 971 of file AsyncSSLSocket.cpp.
References asyncOperationFinishCallback_, folly::AsyncSocket::eventBase_, folly::AsyncSocket::eventFlags_, folly::AsyncSocket::fd_, folly::gen::move, folly::AsyncPipeReader::newReader(), folly::EventHandler::NONE, folly::EventHandler::READ, ssl_, sslState_, folly::AsyncSocket::state_, STATE_ASYNC_PENDING, STATE_CACHE_LOOKUP, folly::AsyncSocket::updateEventRegistration(), and folly::EventHandler::WRITE.
Referenced by handleConnect(), handleReturnFromSSLAccept(), and setAsyncOperationFinishCallback().
|
protected |
Definition at line 954 of file AsyncSSLSocket.h.
Referenced by getSSLAlertsReceived(), and sslInfoCallback().
|
protected |
Definition at line 926 of file AsyncSSLSocket.h.
Referenced by eorAwareSSLWrite(), and setEorTracking().
|
protected |
Definition at line 968 of file AsyncSSLSocket.h.
Referenced by setAsyncOperationFinishCallback(), and willBlock().
|
protected |
Definition at line 951 of file AsyncSSLSocket.h.
Referenced by setBufferMovableEnabled(), and setReadCB().
|
protected |
Definition at line 950 of file AsyncSSLSocket.h.
Referenced by forceCacheAddrOnFailure(), sslAccept(), and sslConn().
|
protected |
Definition at line 952 of file AsyncSSLSocket.h.
Referenced by getCertCacheHit(), and setCertCacheHit().
|
protected |
Definition at line 953 of file AsyncSSLSocket.h.
Referenced by clientHelloParsingCallback(), enableClientHelloParsing(), getClientHelloInfo(), getSSLClientCiphers(), getSSLClientComprMethods(), getSSLClientExts(), getSSLClientSigAlgs(), getSSLClientSupportedVersions(), and resetClientHelloParsing().
|
protected |
Definition at line 922 of file AsyncSSLSocket.h.
Referenced by attachEventBase(), detachEventBase(), invokeConnectErr(), invokeConnectSuccess(), and scheduleConnectTimeout().
|
protected |
Definition at line 906 of file AsyncSSLSocket.h.
Referenced by performWrite().
|
protected |
Definition at line 916 of file AsyncSSLSocket.h.
Referenced by applyVerificationOptions(), AsyncSSLSocket(), getSSLContext(), handleAccept(), init(), needsPeerVerification(), sslAccept(), and sslConn().
|
protected |
Definition at line 918 of file AsyncSSLSocket.h.
Referenced by invalidState(), invokeHandshakeCB(), invokeHandshakeErr(), folly::test::MockAsyncSSLSocket::sslAccept(), sslAccept(), folly::test::MockAsyncSSLSocket::sslConn(), and sslConn().
|
protected |
Definition at line 913 of file AsyncSSLSocket.h.
Referenced by handleConnect(), handleReturnFromSSLAccept(), and sslInfoCallback().
|
protected |
Definition at line 959 of file AsyncSSLSocket.h.
Referenced by sslConn(), and startSSLConnect().
|
protected |
Definition at line 958 of file AsyncSSLSocket.h.
Referenced by getHandshakeTime(), invalidState(), invokeHandshakeCB(), invokeHandshakeErr(), sslAccept(), and startSSLConnect().
|
protected |
Definition at line 957 of file AsyncSSLSocket.h.
Referenced by getHandshakeTime(), sslAccept(), and startSSLConnect().
|
protected |
Definition at line 921 of file AsyncSSLSocket.h.
Referenced by attachEventBase(), attachTimeoutManager(), closeNow(), detachEventBase(), detachTimeoutManager(), failHandshake(), handleConnect(), invalidState(), invokeConnectErr(), invokeHandshakeCB(), isDetachable(), folly::test::MockAsyncSSLSocket::sslAccept(), sslAccept(), folly::test::MockAsyncSSLSocket::sslConn(), and startSSLConnect().
|
protected |
Definition at line 934 of file AsyncSSLSocket.h.
Referenced by eorAwareSSLWrite(), and setEorTracking().
|
protected |
Definition at line 930 of file AsyncSSLSocket.h.
Referenced by getMinWriteSize(), performWrite(), and setMinWriteSize().
|
protected |
Definition at line 949 of file AsyncSSLSocket.h.
Referenced by enableClientHelloParsing(), getSSLClientCiphers(), getSSLClientComprMethods(), getSSLClientExts(), getSSLClientSigAlgs(), getSSLClientSupportedVersions(), and handleAccept().
|
protected |
Definition at line 914 of file AsyncSSLSocket.h.
Referenced by performRead(), and sslInfoCallback().
|
protected |
Definition at line 908 of file AsyncSSLSocket.h.
Referenced by connect(), connecting(), handleAccept(), handleConnect(), handleRead(), handleWrite(), invalidState(), performRead(), sslAccept(), and sslConn().
|
protected |
Definition at line 966 of file AsyncSSLSocket.h.
Referenced by sessionIDResumed(), and setSessionIDResumed().
|
protected |
Definition at line 941 of file AsyncSSLSocket.h.
Referenced by getSessionKey(), and setSessionKey().
|
protected |
Definition at line 964 of file AsyncSSLSocket.h.
Referenced by sessionResumptionAttempted(), and sslConn().
|
protected |
Definition at line 919 of file AsyncSSLSocket.h.
Referenced by checkForImmediateRead(), closeNow(), getNegotiatedCipherName(), getPeerCertificate(), getRawBytesReceived(), getRawBytesWritten(), getSelectedNextProtocolNoThrow(), getSelfCert(), getSelfCertificate(), getSSL(), getSSLCertSigAlgName(), getSSLCertSize(), getSSLServerCiphers(), getSSLServerName(), getSSLServerNameNoThrow(), getSSLSession(), getSSLSessionReused(), getSSLSharedCiphers(), getSSLVersion(), handleAccept(), handleConnect(), performRead(), performWrite(), setReadCB(), setupSSLBio(), sslAccept(), sslConn(), and willBlock().
|
protected |
Definition at line 920 of file AsyncSSLSocket.h.
Referenced by closeNow(), getSSLSession(), setSSLSession(), and sslConn().
|
protected |
Definition at line 915 of file AsyncSSLSocket.h.
Referenced by AsyncSSLSocket(), closeNow(), connect(), connecting(), getSecurityProtocol(), getSSLSession(), getSSLSessionReused(), getSSLState(), good(), handleAccept(), handleConnect(), handleRead(), handleReturnFromSSLAccept(), handleWrite(), interpretSSLError(), invalidState(), invokeConnectErr(), invokeConnectSuccess(), performRead(), performWrite(), restartSSLAccept(), scheduleConnectTimeout(), folly::test::MockAsyncSSLSocket::sslAccept(), sslAccept(), folly::test::MockAsyncSSLSocket::sslConn(), sslConn(), timeoutExpired(), willBlock(), and ~AsyncSSLSocket().
|
protected |
Definition at line 962 of file AsyncSSLSocket.h.
Referenced by getSSLCertVerificationAlert(), and setSSLCertVerificationAlert().
|
protected |
Definition at line 960 of file AsyncSSLSocket.h.
Referenced by connect(), and getTotalConnectTimeout().
|
protected |
Definition at line 943 of file AsyncSSLSocket.h.
Referenced by applyVerificationOptions(), needsPeerVerification(), sslAccept(), and sslConn().