Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSL_read function strange behavior vs openssl's SSL_read #69

Open
fadinglr opened this issue Jun 8, 2022 · 1 comment
Open

SSL_read function strange behavior vs openssl's SSL_read #69

fadinglr opened this issue Jun 8, 2022 · 1 comment

Comments

@fadinglr
Copy link

fadinglr commented Jun 8, 2022

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.
image
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.
image

Could you please help me with this problem?

@fadinglr
Copy link
Author

fadinglr commented Jun 8, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant