Synss / python-mbedtls

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

Add cache configurability #52

Closed cartoush closed 2 years ago

cartoush commented 2 years 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

Hi, I am currently trying to do some benchmarks with different DTLS setups, and for that I would need to be able to modify the value of the session cache timeout so that I'm not stuck with the default value of 1 day

Current behavior

It is currently impossible to modify the session cache timeout value from this package's bindings to mbedtls

Expected behavior

Have the mbedtls_ssl_cache_set_max_entries, mbedtls_ssl_cache_set_timeout, and mbedtls_ssl_conf_session_cache exposed through the Python bindings so that the behavior of mbedtls cache can be modified

Other information

Synss commented 2 years ago

Hi! Thank you for your feedback. That seems reasonable but not entirely trivial as I will need to wrap an mbedtls_ssl_cache_context * as well. I will look into it.

[Note to self] mbedtls docs:

cartoush commented 2 years ago

Thanks a lot !

Synss commented 2 years ago

mbedtls_ssl_conf_session_cache() is tricky with its two callbacks. Would changing the defaults of the C library be an option for your tests?

https://github.com/ARMmbed/mbedtls/blob/v2.16.12/include/mbedtls/ssl_cache.h#L72-L78

#if !defined(MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT)
#define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT       86400   /*!< 1 day  */
#endif

#if !defined(MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES)
#define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES      50   /*!< Maximum entries in cache */
#endif

Please have a look here to recompile the C library and its bindings.

cartoush commented 2 years ago

It might do the trick yes, i'll try that, thanks !