SSL_read function strange behavior vs openssl's SSL_read
fadinglr opened this issue · comments
Dear author,
I found a strange behavior in SSL_read function compared with openssl's SSL_read function.
when i use openssl, the number of bytes ssl_read int the client side returned will never larger than the number of bytes ssl_write from the server side, the code is like below:
server side:
SSL_write(ssl, text, 32); SSL_write(ssl, text, 32); SSL_write(ssl, text, 32); SSL_write(ssl, text, 32); SSL_write(ssl, text, 32); SSL_write(ssl, text, 32); SSL_write(ssl, text, 32);
client side:
`while (1) {
printf("\n---------------------------------\n");
int n = SSL_read(pssl, (char*)sz_temp, 128);
if (n <= 0)
{
SSL_shutdown(pssl);
SSL_free(pssl);
closesocket(sock);
break;
}
else
{
for (int i = 0; i < n; i++) {
printf("%02x ", (unsigned int)sz_temp[i]);
}
}`
the result:
i will only receive 32 byte one time i called ssl_read.
while, when i use your awsome project tlse, the client side result is like this:
I received 128 bytes one time, and this caught some stick package error in my project.
Could you please help me with this problem?
in openssl,
ssl3_get_record will only get one record each time when called.
while in tlse,
` unsigned char client_message[0xFFFF];
// accept
int read_size;
while ((!context->application_buffer_len) && ((read_size = _private_tls_safe_read(context, (char *)client_message, sizeof(client_message))) > 0)) {
if (tls_consume_stream(context, client_message, read_size, ssl_data->certificate_verify) > 0)
_tls_ssl_private_send_pending(ssl_data->fd, context);
if ((context->critical_error) && (!context->application_buffer_len))
return TLS_GENERIC_ERROR;
}`
_private_tls_safe_read get too much data each time.
the openssl fiset call ssl3_read_n(5) to get the header, and then call ss3_read_n(length), the length is got from the header.