Hi Jeff,
It looks like you're using an old version of Mbed TLS.
mbedtls_hmac_drbg_seed used to set ctx->entropy_len to entropy_len * 3 /
2, but this changed (https://github.com/ARMmbed/mbed-crypto/pull/238) to
making a call to mbedtls_entropy_func for entropy_len and then one again
for entropy_len / 2, precisely to avoid the scenario you're describing
where the HMAC_DRBG module would request more entropy than the entropy
can deliver in a single call.
Please upgrade to the latest release of Mbed TLS, or the latest 2.16
release if you want a long-time support branch. The version you're using
is old and has known vulnerabilities.
--
Gilles Peskine
Mbed TLS developer
On 06/04/2021 13:59, Thompson, Jeff via mbed-tls wrote:
>
> �
>
> The call flow is mbedtls_hmac_drbg -> mbedtls_hmac_drbg_reseed ->
> mbedtls_entropy_func where the parameter, len, is 48 and
> MBEDTLS_ENTROPY_BLOCK_SIZE is 32. I see that mbedtls_hmac_drbg_seed
> sets �ctx->entropy_len = entropy_len * 3 / 2, which explains the size
> difference. I�ve probably mis-configured (see attached) in order to
> use TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA, because other ciphers take too
> long.
>
> �
>
> *Jeff Thompson*�| �Senior Electrical Engineer-Firmware
> +1 704 752 6513 x1394
> www.invue.com <www.invue.com>
>
> �
>
>
The call flow is mbedtls_hmac_drbg -> mbedtls_hmac_drbg_reseed -> mbedtls_entropy_func where the parameter, len, is 48 and MBEDTLS_ENTROPY_BLOCK_SIZE is 32. I see that mbedtls_hmac_drbg_seed sets ctx->entropy_len = entropy_len * 3 / 2, which explains the size difference. I've probably mis-configured (see attached) in order to use TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA, because other ciphers take too long.
Jeff Thompson | Senior Electrical Engineer-Firmware
+1 704 752 6513 x1394
www.invue.com
[cid:image001.gif@01D72ABA.56C4A310]
Hi Keith,
Those are good questions, and the short answer is everything should work in a multi-threaded environment if Mbed TLS was built with threading support (for example, enabling MBEDTLS_THREADING_C and MBEDTLS_THREADING_PTHREAD in config.h).
Now for some more details: regarding mbedtls_ssl_config, it is indeed treated as read-only by all function in the SSL/TLS module, except of course those functions that are explicitly meant to modify it (those whose name starts with mbedtls_ssl_conf_). So, if you set it up in the main thread and then use it in other threads, everything will be fine regarding the top-level structure itself (for sub-structures see below), regardless of whether threading support is enabled.
For the DRBG contexts, you're right that each time we draw from them, they need to update their state. However, this is protected by a mutex if threading support was enabled at compile-time. A similar thing goes for private keys : RSA private keys are protected by a mutex if threading support is enabled (using them mutates state used for side-channel countermeasures), and ECDSA private keys are safe too. X.509 structures are always treated as read-only.
Regarding documentation: we did recently expand the documentation on DRBGs: https://github.com/ARMmbed/mbedtls/commit/f305d92480c81c6eb02934a4e1af58152… Regarding SSL, I agree this should be better documented. If you'd like to open a PR to add documentation that would have answered your question, that would be very welcome.
Regards,
Manuel
________________________________
From: mbed-tls <mbed-tls-bounces(a)lists.trustedfirmware.org> on behalf of Keith Cancel via mbed-tls <mbed-tls(a)lists.trustedfirmware.org>
Sent: 02 April 2021 06:43
To: mbed-tls(a)lists.trustedfirmware.org <mbed-tls(a)lists.trustedfirmware.org>
Subject: [mbed-tls] Mbed TLS mbedtls_ssl_config (struct) Question
Hello,
I hope this a simple question regarding mbedtls_ssl_config. So it
seems this structure is meant to be shared/used for multiple
connections. However, if I have multiple threads is it treated as a
read only structure by all the library code, or does it update some
state at times? Similar thing regarding the mbedtls_x509_crt struct
and mbedtls_ctr_drbg_context which also seem to be added to the config
when I setup the config.
I was hoping that once set I don’t have to worry about any
mutexs/locks being used by the library under the hood. Mainly, that
once the configuration is set in the main thread it state is never
updated again. What made me curious about this is the fact the RNG
seems to be part of the configuration and a CPRNG will generally have
state that needs to change. Moreover, I can’t really find a clear
answer looking at the docs.
Thanks,
Keith Cancel
--
mbed-tls mailing list
mbed-tls(a)lists.trustedfirmware.org
https://lists.trustedfirmware.org/mailman/listinfo/mbed-tls
Hello,
I hope this a simple question regarding mbedtls_ssl_config. So it
seems this structure is meant to be shared/used for multiple
connections. However, if I have multiple threads is it treated as a
read only structure by all the library code, or does it update some
state at times? Similar thing regarding the mbedtls_x509_crt struct
and mbedtls_ctr_drbg_context which also seem to be added to the config
when I setup the config.
I was hoping that once set I don’t have to worry about any
mutexs/locks being used by the library under the hood. Mainly, that
once the configuration is set in the main thread it state is never
updated again. What made me curious about this is the fact the RNG
seems to be part of the configuration and a CPRNG will generally have
state that needs to change. Moreover, I can’t really find a clear
answer looking at the docs.
Thanks,
Keith Cancel
Hello,
I
run a client that has been ported MbedTLS, but the client connect
server faild. I check the debug log, the end client state is 15. In the
client state 3, the client receive only one certificate from server,
and the log printing "Certificate verification flags 8". Here are part
of logs:
..\MbedTLS\library\ssl_tls.c:4232: dumping 'input record from network' (4467 bytes)
..\MbedTLS\library\ssl_tls.c:4232: 0000: 16 03 03 11 6e 0b 00 11 6a 00 11 67 00 05 c2 30 ....n...j..g...0
..\MbedTLS\library\ssl_tls.c:4232: 0010: -------- omit some network input data --------
..\MbedTLS\library\ssl_tls.c:4232: 0ff0: 38 a0 36 a0 34 86 32 68 74 74 70 3a 2f 2f 63 72 8.6.4.2http://cr
..\MbedTLS\library\ssl_tls.c:3624: handshake message: msglen = 4462, type = 11, hslen = 4462
..\MbedTLS\library\ssl_tls.c:4385: <= read record
..\MbedTLS\library\ssl_tls.c:5606: peer certificate #1:
..\MbedTLS\library\ssl_tls.c:5606: cert. version : 3
..\MbedTLS\library\ssl_tls.c:5606: serial number : F0:57:5F:65:80:A9:70:B4:F9:8E:42:91:AE:D0:70:27
..\MbedTLS\library\ssl_tls.c:5606:
issuer name : C=GB, ST=Greater Manchester, L=Salford, O=Sectigo
Limited, CN=Sectigo RSA Domain Validation Secure Server CA
..\MbedTLS\library\ssl_tls.c:5606: subject name : CN=*.xxxxxxxx.com
..\MbedTLS\library\ssl_tls.c:5606: issued on : 2020-06-01 00:00:00
..\MbedTLS\library\ssl_tls.c:5606: expires on : 2021-05-26 23:59:59
..\MbedTLS\library\ssl_tls.c:5606: signed using : RSA with SHA-256
..\MbedTLS\library\ssl_tls.c:5606: RSA key size : 2048 bits
..\MbedTLS\library\ssl_tls.c:5606: basic constraints : CA=false
..\MbedTLS\library\ssl_tls.c:5606: subject alt name : *.xxxxxxxx.com, xxxxxxxx.com
..\MbedTLS\library\ssl_tls.c:5606: key usage : Digital Signature, Key Encipherment
..\MbedTLS\library\ssl_tls.c:5606: ext key usage : TLS Web Server Authentication, TLS Web Client Authentication
..\MbedTLS\library\ssl_tls.c:5606: value of 'crt->rsa.N' (2048 bits) is:
..\MbedTLS\library\ssl_tls.c:5606: af b7 73 1a f9 8a 2d 5e a2 e8 0f fd 89 5d 60 1d
..\MbedTLS\library\ssl_tls.c:5606: -------- omit some bits --------
..\MbedTLS\library\ssl_tls.c:5606: e6 8e f8 3e ed ec 8e dd ec 46 48 85 9a b4 c8 71
..\MbedTLS\library\ssl_tls.c:5606: value of 'crt->rsa.E' (17 bits) is:
..\MbedTLS\library\ssl_tls.c:5606: 01 00 01
..\MbedTLS\library\ssl_tls.c:5757: x509_verify_cert() returned -9984 (-0x2700)
..\MbedTLS\library\ssl_tls.c:5851: ! Certificate verification flags 8
..\MbedTLS\library\ssl_tls.c:5863: <= parse certificate
At
the client side, I download certificate of server, and get CA and root
CA base on this certificate. Loading any one of these certificates into
the client can't connect server.
I
did a test with another server. The different of the handshark is that
the server issued two certificates, one is server's cert and another is
CA cert. Loading CA or root CA into the client both can connect server
successfully.
problems:
1. Must the server send CA certificate in handshake phase?
2. The client holds CA certificate, dose MbedTLS client support downloading CA base on server's certificate?
3. In the source code, the certificate chain only contains the
certificate issued by the server during handshake, not the CA
certificate downloaded by the client according to the server
certificate?
Thank you very much for the answers.
Best regards,
berry chen