[En-Nut-Discussion] [PATCH 2/2] FIX: TLS when sending & receiving simultaneously
Krzysztof Sawicki
krzysztof.sawicki at mlabs.pl
Tue Apr 25 09:21:54 CEST 2017
On 24.04.2017 13:09, Uwe Bonnes wrote:
>>>>>> "Krzysztof" == Krzysztof Sawicki <krzysztof.sawicki at mlabs.pl> writes:
>
> Krzysztof> --- nut/tls/tls1.c | 8 +++++++- 1 file changed, 7
> Krzysztof> insertions(+), 1 deletion(-)
>
> Krzysztof> diff --git a/nut/tls/tls1.c b/nut/tls/tls1.c index
> Krzysztof> 2d76eb9..de46e6d 100644 --- a/nut/tls/tls1.c +++
> Krzysztof> b/nut/tls/tls1.c @@ -936,7 +936,6 @@ static int
> Krzysztof> send_raw_packet(SSL *ssl, uint8_t protocol) } }
>
> Krzysztof> - SET_SSL_FLAG(SSL_NEED_RECORD); /* reset for next time */
> ssl-> bm_index = 0;
>
> Krzysztof> if (protocol != PT_APP_PROTOCOL_DATA) @@ -1143,6
> Krzysztof> +1142,13 @@ int basic_read(SSL *ssl, uint8_t **in_data) int
> Krzysztof> read_len, is_client = IS_SET_SSL_FLAG(SSL_IS_CLIENT); uint8_t
> Krzysztof> *buf = ssl->bm_data;
>
> Krzysztof> + uint32_t avail = 0; + NutTcpDeviceIOCtl((TCPSOCKET *)
> Krzysztof> ssl->client_fd, IOCTL_GETINBUFCOUNT, &avail); + if (avail <
> Krzysztof> ssl->need_bytes) { + NutThreadYield(); // allow another
> Krzysztof> thread to receive data from network + return SSL_OK; + } +
> Krzysztof> read_len = NutTcpReceive ((TCPSOCKET *)ssl->client_fd,
> Krzysztof> &buf[ssl->bm_read_index],
> ssl-> need_bytes-ssl->got_bytes);
>
> Krzysztof> -- 2.7.4
>
> Can you explain the first change? For me it seems unrelated!
> Bye
I examined the situation in debugger and it happens as I described:
we call:
a) ssl_read()
b) ssl_write()
c) ssl_read()
ad. a - we get only ssl header (5B), so ssl_read returns 0
ad. b - send some data
ad. c - ssl_read returns error - SSL_ERROR_INVALID_PROT_MSG - it is
because ssl_write->send_packet->send_raw_packet sets
SET_SSL_FLAG(SSL_NEED_RECORD) so we expect SSL header again but get SSL data
After the fix, it works.
--
Krzysztof Sawicki
MLabs sp. z o.o.
ul. Kaliska 21
61-131 Poznań
tel. 61 646 84 27
KRS: 0000390306
NIP: 7822533401
More information about the En-Nut-Discussion
mailing list