Synss / python-mbedtls

Cryptographic library with an mbed TLS back end
MIT License
79 stars 28 forks source link

Possibility to change mbedtls_ssl_conf_read_timeout #101

Closed sebachm94 closed 6 months ago

sebachm94 commented 6 months ago

NOTE: Please use stackoverflow for support questions. This repository's issues are reserved for feature requests and bug reports.

I am submitting a …

Description

I'm using yours library to communicate with some embedded device with low resources power, so some calculation takes some time(2-4sec). I would like to have possibility to set up the response time, because I noticed it's set up to 1s by default (correct me if I'm wrong). There is mbedtls_ssl_conf_read_timeout function to set up the desired value, would it be possible to add support for it?

Current behavior

Can't handle answers which comes after 1sec. image

Expected behavior

It's possible to set up read timeout.

Synss commented 6 months ago

That makes sense and looks easy enough. Do you want to prepare a PR? Otherwise I can most likely add the binding in the next few days.

sebachm94 commented 6 months ago

Sure, I will try to make it today, so you can review or help if there will be some problems.

Synss commented 6 months ago

Looks good. I've merged your commit and will make a new release. BTW: Did it solve your issue?

PR #102

sebachm94 commented 6 months ago

Yes, it does. Thanks a lot for quick support :)

Btw, I have a question, maybe it's something I don't understand or don't know how to configure. My cert chain is > 1024B long in total and while trying to send it only up to 1024 bytes are send, there is something I need to configure to split packets into smaller parts?

It's send here: image

Synss commented 6 months ago

I'd expect larger chains to work as well because it's in the while loop (line 438). If the stream is incomplete, do_handshake (line 440) should raise WantReadError or WantWriteError and the loop proceeds the next chunk. If that's not the case, then it's a bug.

The internal buffers are 32K.

sebachm94 commented 6 months ago

Looks like it sends only first chunk. At least in my case. I also tried to lower the MCU but it didn't helped too. And it looks like it changes state to WantToRead.

Synss commented 6 months ago

I’ll have a look. It should be easy to test or simulate. Could you open a different issue for this?