@@ -22,33 +22,36 @@ bool HTTPSConnection::isSecure() {
2222 *
2323 * The call WILL BLOCK if accept(serverSocketID) blocks. So use select() to check for that in advance.
2424 */
25- int HTTPSConnection::initialize (int serverSocketID, SSL_CTX * sslCtx, HTTPHeaders *defaultHeaders) {
25+ int HTTPSConnection::initialize (int serverSocketID, esp_tls_t * sslCtx, esp_tls_cfg_server_t * cfgSrv , HTTPHeaders *defaultHeaders) {
2626 if (_connectionState == STATE_UNDEFINED) {
2727 // Let the base class connect the plain tcp socket
2828 int resSocket = HTTPConnection::initialize (serverSocketID, defaultHeaders);
29-
29+
3030 // Build up SSL Connection context if the socket has been created successfully
3131 if (resSocket >= 0 ) {
32-
33- _ssl = SSL_new (sslCtx);
34-
35- if (_ssl) {
32+ // _ssl = SSL_new(sslCtx);
33+ int res=esp_tls_server_session_create (cfgSrv,resSocket,sslCtx);
34+ if (0 ==res) {
35+ esp_tls_cfg_server_session_tickets_init (cfgSrv);
36+ _ssl = sslCtx;
37+ _cfg = cfgSrv;
38+
3639 // Bind SSL to the socket
37- int success = SSL_set_fd (_ssl, resSocket);
38- if (success ) {
39-
40- // Perform the handshake
41- success = SSL_accept (_ssl);
42- if (success) {
40+ // int success = SSL_set_fd(_ssl, resSocket);
41+ if (ESP_OK == esp_tls_get_conn_sockfd (sslCtx,&resSocket) ) {
42+
43+ // // Perform the handshake
44+ // success = SSL_accept(_ssl);
45+ // if (success) {
4346 return resSocket;
44- } else {
45- HTTPS_LOGE (" SSL_accept failed. Aborting handshake. FID=%d" , resSocket);
46- }
4747 } else {
48- HTTPS_LOGE (" SSL_set_fd failed. Aborting handshake. FID=%d" , resSocket);
48+ HTTPS_LOGE (" SSL_accept failed. Aborting handshake. FID=%d" , resSocket);
4949 }
50+ // } else {
51+ // HTTPS_LOGE("SSL_set_fd failed. Aborting handshake. FID=%d", resSocket);
52+ // }
5053 } else {
51- HTTPS_LOGE (" SSL_new failed. Aborting handshake. FID =%d" , resSocket );
54+ HTTPS_LOGE (" SSL_new failed. Aborting handshake. Error =%d" , res );
5255 }
5356
5457 } else {
@@ -84,18 +87,10 @@ void HTTPSConnection::closeConnection() {
8487
8588 // Try to tear down SSL while we are in the _shutdownTS timeout period or if an error occurred
8689 if (_ssl) {
87- if (_connectionState == STATE_ERROR || SSL_shutdown (_ssl) == 0 ) {
88- // SSL_shutdown will return 1 as soon as the client answered with close notify
89- // This means we are safe to close the socket
90- SSL_free (_ssl);
91- _ssl = NULL ;
92- } else if (_shutdownTS + HTTPS_SHUTDOWN_TIMEOUT < millis ()) {
93- // The timeout has been hit, we force SSL shutdown now by freeing the context
94- SSL_free (_ssl);
95- _ssl = NULL ;
96- HTTPS_LOGW (" SSL_shutdown did not receive close notification from the client" );
97- _connectionState = STATE_ERROR;
98- }
90+ esp_tls_cfg_server_session_tickets_free (_cfg);
91+ esp_tls_server_session_delete (_ssl);
92+ _ssl = NULL ;
93+ _connectionState = STATE_ERROR;
9994 }
10095
10196 // If SSL has been brought down, close the socket
@@ -105,19 +100,19 @@ void HTTPSConnection::closeConnection() {
105100}
106101
107102size_t HTTPSConnection::writeBuffer (byte* buffer, size_t length) {
108- return SSL_write (_ssl, buffer, length);
103+ return esp_tls_conn_write (_ssl,buffer,length); // SSL_write(_ssl, buffer, length);
109104}
110105
111106size_t HTTPSConnection::readBytesToBuffer (byte* buffer, size_t length) {
112- return SSL_read (_ssl, buffer, length);
107+ return esp_tls_conn_read (_ssl, buffer, length);
113108}
114109
115110size_t HTTPSConnection::pendingByteCount () {
116- return SSL_pending (_ssl);
111+ return esp_tls_get_bytes_avail (_ssl);
117112}
118113
119114bool HTTPSConnection::canReadData () {
120- return HTTPConnection::canReadData () || (SSL_pending (_ssl) > 0 );
115+ return HTTPConnection::canReadData () || (esp_tls_get_bytes_avail (_ssl) > 0 );
121116}
122117
123118} /* namespace httpsserver */
0 commit comments