Skip to content

Commit

Permalink
Fix SSL to continue decrypting data after renego completes (#4234)
Browse files Browse the repository at this point in the history
* Fix SSL to continue decrypting data after renego completes

* Update SSL socket with OpenSSL backend to return PJ_EEOF only when renegotiation is needed (or not completed).
  • Loading branch information
nanangizz authored Dec 25, 2024
1 parent e16edee commit 8bc04d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pjlib/src/pj/ssl_sock_imp_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,11 @@ static pj_bool_t ssock_on_data_read (pj_ssl_sock_t *ssock,
"Failed to flush delayed send"));
goto on_error;
}

/* If renego has been completed, continue reading data */
if (status == PJ_SUCCESS)
continue;

} else if (status != PJ_EPENDING) {
PJ_PERROR(1,(ssock->pool->obj_name, status,
"Renegotiation failed"));
Expand Down
12 changes: 8 additions & 4 deletions pjlib/src/pj/ssl_sock_ossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2476,7 +2476,9 @@ static pj_status_t ssl_read(pj_ssl_sock_t *ssock, void *data, int *size)
/* SSL might just return SSL_ERROR_WANT_READ in
* re-negotiation.
*/
if (err != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ) {
if (err != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ &&
err != SSL_ERROR_ZERO_RETURN)
{
if (err == SSL_ERROR_SYSCALL && size_ == -1 &&
ERR_peek_error() == 0 && errno == 0)
{
Expand All @@ -2499,9 +2501,11 @@ static pj_status_t ssl_read(pj_ssl_sock_t *ssock, void *data, int *size)
}
}

pj_lock_release(ssock->write_mutex);
/* Need renegotiation */
return PJ_EEOF;
/* Return PJ_EEOF when SSL needs renegotiation */
if (!SSL_is_init_finished(ossock->ossl_ssl)) {
pj_lock_release(ssock->write_mutex);
return PJ_EEOF;
}
}

pj_lock_release(ssock->write_mutex);
Expand Down

0 comments on commit 8bc04d9

Please sign in to comment.