2 * Copyright 2017 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <folly/Optional.h>
22 #include <folly/String.h>
23 #include <folly/io/async/AsyncSocket.h>
24 #include <folly/io/async/AsyncTimeout.h>
25 #include <folly/io/async/SSLContext.h>
26 #include <folly/io/async/TimeoutManager.h>
27 #include <folly/io/async/ssl/OpenSSLPtrTypes.h>
28 #include <folly/io/async/ssl/OpenSSLUtils.h>
29 #include <folly/io/async/ssl/SSLErrors.h>
30 #include <folly/io/async/ssl/TLSDefinitions.h>
32 #include <folly/Bits.h>
33 #include <folly/io/IOBuf.h>
34 #include <folly/io/Cursor.h>
35 #include <folly/portability/OpenSSL.h>
36 #include <folly/portability/Sockets.h>
41 * A class for performing asynchronous I/O on an SSL connection.
43 * AsyncSSLSocket allows users to asynchronously wait for data on an
44 * SSL connection, and to asynchronously send data.
46 * The APIs for reading and writing are intentionally asymmetric.
47 * Waiting for data to read is a persistent API: a callback is
48 * installed, and is notified whenever new data is available. It
49 * continues to be notified of new events until it is uninstalled.
51 * AsyncSSLSocket does not provide read timeout functionality,
52 * because it typically cannot determine when the timeout should be
53 * active. Generally, a timeout should only be enabled when
54 * processing is blocked waiting on data from the remote endpoint.
55 * For server connections, the timeout should not be active if the
56 * server is currently processing one or more outstanding requests for
57 * this connection. For client connections, the timeout should not be
58 * active if there are no requests pending on the connection.
59 * Additionally, if a client has multiple pending requests, it will
60 * ususally want a separate timeout for each request, rather than a
61 * single read timeout.
63 * The write API is fairly intuitive: a user can request to send a
64 * block of data, and a callback will be informed once the entire
65 * block has been transferred to the kernel, or on error.
66 * AsyncSSLSocket does provide a send timeout, since most callers
67 * want to give up if the remote end stops responding and no further
68 * progress can be made sending the data.
70 class AsyncSSLSocket : public virtual AsyncSocket {
72 typedef std::unique_ptr<AsyncSSLSocket, Destructor> UniquePtr;
73 using X509_deleter = folly::static_function_deleter<X509, &X509_free>;
77 virtual ~HandshakeCB() = default;
80 * handshakeVer() is invoked during handshaking to give the
81 * application chance to validate it's peer's certificate.
83 * Note that OpenSSL performs only rudimentary internal
84 * consistency verification checks by itself. Any other validation
85 * like whether or not the certificate was issued by a trusted CA.
86 * The default implementation of this callback mimics what what
87 * OpenSSL does internally if SSL_VERIFY_PEER is set with no
88 * verification callback.
90 * See the passages on verify_callback in SSL_CTX_set_verify(3)
93 virtual bool handshakeVer(AsyncSSLSocket* /*sock*/,
95 X509_STORE_CTX* /*ctx*/) noexcept {
100 * handshakeSuc() is called when a new SSL connection is
101 * established, i.e., after SSL_accept/connect() returns successfully.
103 * The HandshakeCB will be uninstalled before handshakeSuc()
106 * @param sock SSL socket on which the handshake was initiated
108 virtual void handshakeSuc(AsyncSSLSocket *sock) noexcept = 0;
111 * handshakeErr() is called if an error occurs while
112 * establishing the SSL connection.
114 * The HandshakeCB will be uninstalled before handshakeErr()
117 * @param sock SSL socket on which the handshake was initiated
118 * @param ex An exception representing the error.
120 virtual void handshakeErr(
121 AsyncSSLSocket *sock,
122 const AsyncSocketException& ex)
126 class Timeout : public AsyncTimeout {
128 Timeout(AsyncSSLSocket* sslSocket, EventBase* eventBase)
129 : AsyncTimeout(eventBase), sslSocket_(sslSocket) {}
131 bool scheduleTimeout(TimeoutManager::timeout_type timeout) {
133 return AsyncTimeout::scheduleTimeout(timeout);
136 bool scheduleTimeout(uint32_t timeoutMs) {
137 return scheduleTimeout(std::chrono::milliseconds{timeoutMs});
140 TimeoutManager::timeout_type getTimeout() {
144 virtual void timeoutExpired() noexcept override {
145 sslSocket_->timeoutExpired(timeout_);
149 AsyncSSLSocket* sslSocket_;
150 TimeoutManager::timeout_type timeout_;
154 * Create a client AsyncSSLSocket
156 AsyncSSLSocket(const std::shared_ptr<folly::SSLContext> &ctx,
157 EventBase* evb, bool deferSecurityNegotiation = false);
160 * Create a server/client AsyncSSLSocket from an already connected
161 * socket file descriptor.
163 * Note that while AsyncSSLSocket enables TCP_NODELAY for sockets it creates
164 * when connecting, it does not change the socket options when given an
165 * existing file descriptor. If callers want TCP_NODELAY enabled when using
166 * this version of the constructor, they need to explicitly call
167 * setNoDelay(true) after the constructor returns.
169 * @param ctx SSL context for this connection.
170 * @param evb EventBase that will manage this socket.
171 * @param fd File descriptor to take over (should be a connected socket).
172 * @param server Is socket in server mode?
173 * @param deferSecurityNegotiation
174 * unencrypted data can be sent before sslConn/Accept
176 AsyncSSLSocket(const std::shared_ptr<folly::SSLContext>& ctx,
177 EventBase* evb, int fd,
178 bool server = true, bool deferSecurityNegotiation = false);
182 * Helper function to create a server/client shared_ptr<AsyncSSLSocket>.
184 static std::shared_ptr<AsyncSSLSocket> newSocket(
185 const std::shared_ptr<folly::SSLContext>& ctx,
186 EventBase* evb, int fd, bool server=true,
187 bool deferSecurityNegotiation = false) {
188 return std::shared_ptr<AsyncSSLSocket>(
189 new AsyncSSLSocket(ctx, evb, fd, server, deferSecurityNegotiation),
194 * Helper function to create a client shared_ptr<AsyncSSLSocket>.
196 static std::shared_ptr<AsyncSSLSocket> newSocket(
197 const std::shared_ptr<folly::SSLContext>& ctx,
198 EventBase* evb, bool deferSecurityNegotiation = false) {
199 return std::shared_ptr<AsyncSSLSocket>(
200 new AsyncSSLSocket(ctx, evb, deferSecurityNegotiation),
205 #if FOLLY_OPENSSL_HAS_SNI
207 * Create a client AsyncSSLSocket with tlsext_servername in
208 * the Client Hello message.
210 AsyncSSLSocket(const std::shared_ptr<folly::SSLContext> &ctx,
212 const std::string& serverName,
213 bool deferSecurityNegotiation = false);
216 * Create a client AsyncSSLSocket from an already connected
217 * socket file descriptor.
219 * Note that while AsyncSSLSocket enables TCP_NODELAY for sockets it creates
220 * when connecting, it does not change the socket options when given an
221 * existing file descriptor. If callers want TCP_NODELAY enabled when using
222 * this version of the constructor, they need to explicitly call
223 * setNoDelay(true) after the constructor returns.
225 * @param ctx SSL context for this connection.
226 * @param evb EventBase that will manage this socket.
227 * @param fd File descriptor to take over (should be a connected socket).
228 * @param serverName tlsext_hostname that will be sent in ClientHello.
230 AsyncSSLSocket(const std::shared_ptr<folly::SSLContext>& ctx,
233 const std::string& serverName,
234 bool deferSecurityNegotiation = false);
236 static std::shared_ptr<AsyncSSLSocket> newSocket(
237 const std::shared_ptr<folly::SSLContext>& ctx,
239 const std::string& serverName,
240 bool deferSecurityNegotiation = false) {
241 return std::shared_ptr<AsyncSSLSocket>(
242 new AsyncSSLSocket(ctx, evb, serverName, deferSecurityNegotiation),
245 #endif // FOLLY_OPENSSL_HAS_SNI
248 * TODO: implement support for SSL renegotiation.
250 * This involves proper handling of the SSL_ERROR_WANT_READ/WRITE
251 * code as a result of SSL_write/read(), instead of returning an
252 * error. In that case, the READ/WRITE event should be registered,
253 * and a flag (e.g., writeBlockedOnRead) should be set to indiciate
254 * the condition. In the next invocation of read/write callback, if
255 * the flag is on, performWrite()/performRead() should be called in
256 * addition to the normal call to performRead()/performWrite(), and
257 * the flag should be reset.
260 // Inherit TAsyncTransport methods from AsyncSocket except the
262 // See the documentation in TAsyncTransport.h
263 // TODO: implement graceful shutdown in close()
264 // TODO: implement detachSSL() that returns the SSL connection
265 virtual void closeNow() override;
266 virtual void shutdownWrite() override;
267 virtual void shutdownWriteNow() override;
268 virtual bool good() const override;
269 virtual bool connecting() const override;
270 virtual std::string getApplicationProtocol() noexcept override;
272 virtual std::string getSecurityProtocol() const override { return "TLS"; }
274 virtual void setEorTracking(bool track) override;
275 virtual size_t getRawBytesWritten() const override;
276 virtual size_t getRawBytesReceived() const override;
277 void enableClientHelloParsing();
279 void setPreReceivedData(std::unique_ptr<IOBuf> data);
282 * Accept an SSL connection on the socket.
284 * The callback will be invoked and uninstalled when an SSL
285 * connection has been established on the underlying socket.
286 * The value of verifyPeer determines the client verification method.
287 * By default, its set to use the value in the underlying context
289 * @param callback callback object to invoke on success/failure
290 * @param timeout timeout for this function in milliseconds, or 0 for no
292 * @param verifyPeer SSLVerifyPeerEnum uses the options specified in the
293 * context by default, can be set explcitly to override the
294 * method in the context
296 virtual void sslAccept(
297 HandshakeCB* callback,
298 std::chrono::milliseconds timeout = std::chrono::milliseconds::zero(),
299 const folly::SSLContext::SSLVerifyPeerEnum& verifyPeer =
300 folly::SSLContext::SSLVerifyPeerEnum::USE_CTX);
303 * Invoke SSL accept following an asynchronous session cache lookup
305 void restartSSLAccept();
308 * Connect to the given address, invoking callback when complete or on error
310 * Note timeout applies to TCP + SSL connection time
312 void connect(ConnectCallback* callback,
313 const folly::SocketAddress& address,
315 const OptionMap &options = emptyOptionMap,
316 const folly::SocketAddress& bindAddr = anyAddress())
319 using AsyncSocket::connect;
322 * Initiate an SSL connection on the socket
323 * The callback will be invoked and uninstalled when an SSL connection
324 * has been establshed on the underlying socket.
325 * The verification option verifyPeer is applied if it's passed explicitly.
326 * If it's not, the options in SSLContext set on the underlying SSLContext
329 * @param callback callback object to invoke on success/failure
330 * @param timeout timeout for this function in milliseconds, or 0 for no
332 * @param verifyPeer SSLVerifyPeerEnum uses the options specified in the
333 * context by default, can be set explcitly to override the
334 * method in the context. If verification is turned on sets
335 * SSL_VERIFY_PEER and invokes
336 * HandshakeCB::handshakeVer().
338 virtual void sslConn(
339 HandshakeCB* callback,
340 std::chrono::milliseconds timeout = std::chrono::milliseconds::zero(),
341 const folly::SSLContext::SSLVerifyPeerEnum& verifyPeer =
342 folly::SSLContext::SSLVerifyPeerEnum::USE_CTX);
352 STATE_REMOTE_CLOSED, /// remote end closed; we can still write
353 STATE_CLOSING, ///< close() called, but waiting on writes to complete
354 /// close() called with pending writes, before connect() has completed
355 STATE_CONNECTING_CLOSING,
360 SSLStateEnum getSSLState() const { return sslState_;}
363 * Get a handle to the negotiated SSL session. This increments the session
364 * refcount and must be deallocated by the caller.
366 SSL_SESSION *getSSLSession();
369 * Get a handle to the SSL struct.
371 const SSL* getSSL() const;
374 * Set the SSL session to be used during sslConn. AsyncSSLSocket will
375 * hold a reference to the session until it is destroyed or released by the
376 * underlying SSL structure.
378 * @param takeOwnership if true, AsyncSSLSocket will assume the caller's
379 * reference count to session.
381 void setSSLSession(SSL_SESSION *session, bool takeOwnership = false);
384 * Get the name of the protocol selected by the client during
385 * Next Protocol Negotiation (NPN) or Application Layer Protocol Negotiation
388 * Throw an exception if openssl does not support NPN
390 * @param protoName Name of the protocol (not guaranteed to be
391 * null terminated); will be set to nullptr if
392 * the client did not negotiate a protocol.
393 * Note: the AsyncSSLSocket retains ownership
395 * @param protoNameLen Length of the name.
396 * @param protoType Whether this was an NPN or ALPN negotiation
398 virtual void getSelectedNextProtocol(
399 const unsigned char** protoName,
401 SSLContext::NextProtocolType* protoType = nullptr) const;
404 * Get the name of the protocol selected by the client during
405 * Next Protocol Negotiation (NPN) or Application Layer Protocol Negotiation
408 * @param protoName Name of the protocol (not guaranteed to be
409 * null terminated); will be set to nullptr if
410 * the client did not negotiate a protocol.
411 * Note: the AsyncSSLSocket retains ownership
413 * @param protoNameLen Length of the name.
414 * @param protoType Whether this was an NPN or ALPN negotiation
415 * @return false if openssl does not support NPN
417 virtual bool getSelectedNextProtocolNoThrow(
418 const unsigned char** protoName,
420 SSLContext::NextProtocolType* protoType = nullptr) const;
423 * Determine if the session specified during setSSLSession was reused
424 * or if the server rejected it and issued a new session.
426 virtual bool getSSLSessionReused() const;
429 * true if the session was resumed using session ID
431 bool sessionIDResumed() const { return sessionIDResumed_; }
433 void setSessionIDResumed(bool resumed) {
434 sessionIDResumed_ = resumed;
438 * Get the negociated cipher name for this SSL connection.
439 * Returns the cipher used or the constant value "NONE" when no SSL session
440 * has been established.
442 virtual const char* getNegotiatedCipherName() const;
445 * Get the server name for this SSL connection.
446 * Returns the server name used or the constant value "NONE" when no SSL
447 * session has been established.
448 * If openssl has no SNI support, throw TTransportException.
450 const char *getSSLServerName() const;
453 * Get the server name for this SSL connection.
454 * Returns the server name used or the constant value "NONE" when no SSL
455 * session has been established.
456 * If openssl has no SNI support, return "NONE"
458 const char *getSSLServerNameNoThrow() const;
461 * Get the SSL version for this connection.
462 * Possible return values are SSL2_VERSION, SSL3_VERSION, TLS1_VERSION,
463 * with hexa representations 0x200, 0x300, 0x301,
464 * or 0 if no SSL session has been established.
466 int getSSLVersion() const;
469 * Get the signature algorithm used in the cert that is used for this
472 const char *getSSLCertSigAlgName() const;
475 * Get the certificate size used for this SSL connection.
477 int getSSLCertSize() const;
480 * Get the certificate used for this SSL connection. May be null
482 virtual const X509* getSelfCert() const override;
484 virtual void attachEventBase(EventBase* eventBase) override {
485 AsyncSocket::attachEventBase(eventBase);
486 handshakeTimeout_.attachEventBase(eventBase);
487 connectionTimeout_.attachEventBase(eventBase);
490 virtual void detachEventBase() override {
491 AsyncSocket::detachEventBase();
492 handshakeTimeout_.detachEventBase();
493 connectionTimeout_.detachEventBase();
496 virtual bool isDetachable() const override {
497 return AsyncSocket::isDetachable() && !handshakeTimeout_.isScheduled();
500 virtual void attachTimeoutManager(TimeoutManager* manager) {
501 handshakeTimeout_.attachTimeoutManager(manager);
504 virtual void detachTimeoutManager() {
505 handshakeTimeout_.detachTimeoutManager();
508 #if OPENSSL_VERSION_NUMBER >= 0x009080bfL
510 * This function will set the SSL context for this socket to the
511 * argument. This should only be used on client SSL Sockets that have
512 * already called detachSSLContext();
514 void attachSSLContext(const std::shared_ptr<folly::SSLContext>& ctx);
517 * Detaches the SSL context for this socket.
519 void detachSSLContext();
522 #if FOLLY_OPENSSL_HAS_SNI
524 * Switch the SSLContext to continue the SSL handshake.
525 * It can only be used in server mode.
527 void switchServerSSLContext(
528 const std::shared_ptr<folly::SSLContext>& handshakeCtx);
531 * Did server recognize/support the tlsext_hostname in Client Hello?
532 * It can only be used in client mode.
534 * @return true - tlsext_hostname is matched by the server
535 * false - tlsext_hostname is not matched or
536 * is not supported by server
538 bool isServerNameMatch() const;
541 * Set the SNI hostname that we'll advertise to the server in the
542 * ClientHello message.
544 void setServerName(std::string serverName) noexcept;
545 #endif // FOLLY_OPENSSL_HAS_SNI
547 void timeoutExpired(std::chrono::milliseconds timeout) noexcept;
550 * Get the list of supported ciphers sent by the client in the client's
553 void getSSLClientCiphers(
554 std::string& clientCiphers,
555 bool convertToString = true) const;
558 * Get the list of compression methods sent by the client in TLS Hello.
560 std::string getSSLClientComprMethods() const;
563 * Get the list of TLS extensions sent by the client in the TLS Hello.
565 std::string getSSLClientExts() const;
567 std::string getSSLClientSigAlgs() const;
570 * Get the list of versions in the supported versions extension (used to
571 * negotiate TLS 1.3).
573 std::string getSSLClientSupportedVersions() const;
575 std::string getSSLAlertsReceived() const;
578 * Get the list of shared ciphers between the server and the client.
579 * Works well for only SSLv2, not so good for SSLv3 or TLSv1.
581 void getSSLSharedCiphers(std::string& sharedCiphers) const;
584 * Get the list of ciphers supported by the server in the server's
587 void getSSLServerCiphers(std::string& serverCiphers) const;
590 * Method to check if peer verfication is set.
592 * @return true if peer verification is required.
594 bool needsPeerVerification() const;
596 static int getSSLExDataIndex();
597 static AsyncSSLSocket* getFromSSL(const SSL *ssl);
598 static int bioWrite(BIO* b, const char* in, int inl);
599 static int bioRead(BIO* b, char* out, int outl);
600 void resetClientHelloParsing(SSL *ssl);
601 static void clientHelloParsingCallback(int write_p, int version,
602 int content_type, const void *buf, size_t len, SSL *ssl, void *arg);
603 static const char* getSSLServerNameFromSSL(SSL* ssl);
606 ssl::ClientHelloInfo* getClientHelloInfo() const {
607 return clientHelloInfo_.get();
611 * Returns the time taken to complete a handshake.
613 virtual std::chrono::nanoseconds getHandshakeTime() const {
614 return handshakeEndTime_ - handshakeStartTime_;
617 void setMinWriteSize(size_t minWriteSize) {
618 minWriteSize_ = minWriteSize;
621 size_t getMinWriteSize() const {
622 return minWriteSize_;
625 void setReadCB(ReadCallback* callback) override;
628 * Tries to enable the buffer movable experimental feature in openssl.
629 * This is not guaranteed to succeed in case openssl does not have
630 * the experimental feature built in.
632 void setBufferMovableEnabled(bool enabled);
635 * Returns the peer certificate, or nullptr if no peer certificate received.
637 virtual ssl::X509UniquePtr getPeerCert() const override {
642 X509* cert = SSL_get_peer_certificate(ssl_);
643 return ssl::X509UniquePtr(cert);
647 * Force AsyncSSLSocket object to cache local and peer socket addresses.
648 * If called with "true" before connect() this function forces full local
649 * and remote socket addresses to be cached in the socket object and available
650 * through getLocalAddress()/getPeerAddress() methods even after the socket is
653 void forceCacheAddrOnFailure(bool force) { cacheAddrOnFailure_ = force; }
655 const std::string& getServiceIdentity() const { return serviceIdentity_; }
657 void setServiceIdentity(std::string serviceIdentity) {
658 serviceIdentity_ = std::move(serviceIdentity);
661 void setCertCacheHit(bool hit) {
665 bool getCertCacheHit() const {
666 return certCacheHit_;
669 bool sessionResumptionAttempted() const {
670 return sessionResumptionAttempted_;
680 * Protected destructor.
682 * Users of AsyncSSLSocket must never delete it directly. Instead, invoke
683 * destroy() instead. (See the documentation in DelayedDestruction.h for
688 // Inherit event notification methods from AsyncSocket except
690 void prepareReadBuffer(void** buf, size_t* buflen) override;
691 void handleRead() noexcept override;
692 void handleWrite() noexcept override;
693 void handleAccept() noexcept;
694 void handleConnect() noexcept override;
696 void invalidState(HandshakeCB* callback);
697 bool willBlock(int ret,
699 unsigned long* errErrorOut) noexcept;
701 virtual void checkForImmediateRead() noexcept override;
702 // AsyncSocket calls this at the wrong time for SSL
703 void handleInitialReadWrite() noexcept override {}
705 WriteResult interpretSSLError(int rc, int error);
706 ReadResult performRead(void** buf, size_t* buflen, size_t* offset) override;
707 WriteResult performWrite(
711 uint32_t* countWritten,
712 uint32_t* partialWritten) override;
714 ssize_t performWriteIovec(const iovec* vec, uint32_t count,
715 WriteFlags flags, uint32_t* countWritten,
716 uint32_t* partialWritten);
718 // This virtual wrapper around SSL_write exists solely for testing/mockability
719 virtual int sslWriteImpl(SSL *ssl, const void *buf, int n) {
720 return SSL_write(ssl, buf, n);
724 * Apply verification options passed to sslConn/sslAccept or those set
725 * in the underlying SSLContext object.
727 * @param ssl pointer to the SSL object on which verification options will be
728 * applied. If verifyPeer_ was explicitly set either via sslConn/sslAccept,
729 * those options override the settings in the underlying SSLContext.
731 void applyVerificationOptions(SSL * ssl);
734 * Sets up SSL with a custom write bio which intercepts all writes.
736 * @return true, if succeeds and false if there is an error creating the bio.
741 * A SSL_write wrapper that understand EOR
743 * @param ssl: SSL* object
744 * @param buf: Buffer to be written
745 * @param n: Number of bytes to be written
746 * @param eor: Does the last byte (buf[n-1]) have the app-last-byte?
747 * @return: The number of app bytes successfully written to the socket
749 int eorAwareSSLWrite(SSL *ssl, const void *buf, int n, bool eor);
751 // Inherit error handling methods from AsyncSocket, plus the following.
752 void failHandshake(const char* fn, const AsyncSocketException& ex);
754 void invokeHandshakeErr(const AsyncSocketException& ex);
755 void invokeHandshakeCB();
757 void invokeConnectErr(const AsyncSocketException& ex) override;
758 void invokeConnectSuccess() override;
759 void scheduleConnectTimeout() override;
761 void cacheLocalPeerAddr();
763 void startSSLConnect();
765 static void sslInfoCallback(const SSL *ssl, int type, int val);
767 // Whether the current write to the socket should use MSG_MORE.
768 bool corkCurrentWrite_{false};
769 // SSL related members.
771 // Used to prevent client-initiated renegotiation. Note that AsyncSSLSocket
772 // doesn't fully support renegotiation, so we could just fail all attempts
773 // to enforce this. Once it is supported, we should make it an option
774 // to disable client-initiated renegotiation.
775 bool handshakeComplete_{false};
776 bool renegotiateAttempted_{false};
777 SSLStateEnum sslState_{STATE_UNINIT};
778 std::shared_ptr<folly::SSLContext> ctx_;
779 // Callback for SSL_accept() or SSL_connect()
780 HandshakeCB* handshakeCallback_{nullptr};
782 SSL_SESSION *sslSession_{nullptr};
783 Timeout handshakeTimeout_;
784 Timeout connectionTimeout_;
785 // whether the SSL session was resumed using session ID or not
786 bool sessionIDResumed_{false};
788 // The app byte num that we are tracking for the MSG_EOR
789 // Only one app EOR byte can be tracked.
790 size_t appEorByteNo_{0};
792 // Try to avoid calling SSL_write() for buffers smaller than this.
793 // It doesn't take effect when it is 0.
794 size_t minWriteSize_{1500};
796 // When openssl is about to sendmsg() across the minEorRawBytesNo_,
797 // it will pass MSG_EOR to sendmsg().
798 size_t minEorRawByteNo_{0};
799 #if FOLLY_OPENSSL_HAS_SNI
800 std::shared_ptr<folly::SSLContext> handshakeCtx_;
801 std::string tlsextHostname_;
804 // a service identity that this socket/connection is associated with
805 std::string serviceIdentity_;
807 folly::SSLContext::SSLVerifyPeerEnum
808 verifyPeer_{folly::SSLContext::SSLVerifyPeerEnum::USE_CTX};
810 // Callback for SSL_CTX_set_verify()
811 static int sslVerifyCallback(int preverifyOk, X509_STORE_CTX* ctx);
813 bool parseClientHello_{false};
814 bool cacheAddrOnFailure_{false};
815 bool bufferMovableEnabled_{false};
816 bool certCacheHit_{false};
817 std::unique_ptr<ssl::ClientHelloInfo> clientHelloInfo_;
818 std::vector<std::pair<char, StringPiece>> alertsReceived_;
820 // Time taken to complete the ssl handshake.
821 std::chrono::steady_clock::time_point handshakeStartTime_;
822 std::chrono::steady_clock::time_point handshakeEndTime_;
823 std::chrono::milliseconds handshakeConnectTimeout_{0};
824 bool sessionResumptionAttempted_{false};
826 std::unique_ptr<IOBuf> preReceivedData_;