Hi,
I'm getting the following errors printed:
tls : error : [2021/06/21 21:43:12.360] [id = 10]:
../../src/../externals/mbedtls/mbedtls/library/ssl_tls.c(4369):
mbedtls_ssl_handle_message_type() returned -30848 (-0x7880)
tls : error : [2021/06/21 21:43:12.360] [id = 11]:
../../src/../externals/mbedtls/mbedtls/library/ssl_tls.c(8335):
mbedtls_ssl_read_record() returned -30848 (-0x7880)
after a file is successfully downloaded. It looks like
MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY gets interpreted and printed as error.
How can I fix this? Is this a configuration thing or do I edit the
ssl_tls.c source code?
Thank you,
Ron
mbedtls 2.16.0
On 2021-08-16 11:11 a.m., Ron Eggler via mbed-tls wrote:
> Hi,
>
> I am working on a client where I need to login to a FTPS server
> (vsftpd). I establish the connection, exchange Hellos, certificate &
> key exchange and all seems succesful and are happening fine.
>
> I am able to send "PBSZ 0" to the server which gets acknowledged with
> "200 PBSZ set to 0." (as seen in Wireshark).
>
> Then, when it comes to sending "PROT P", I cannot see it encoded in
> Wireshark. it just says "Application Data" and the next frame reads
> "Alert (Level: Fatal, Description: Bad Record Mac)". I have
> investigated my code (mostly for differences between "PBSZ 0" and
> "PROT P" but came up empty) and have searched the web but have failed
> to find the resolution to my problem, as of yet. It seems obvious that
> the problem must be in my code but I seem to be unable to put my
> finger on it! I thought I should check if someone here may have any
> other hints that will help me resolve the problem.
>
> I have temporarily set "mbedtls_ssl_conf_authmode( &ctxt.conf,
> MBEDTLS_SSL_VERIFY_NONE);" to make sure that the CA is not the causing
> any issues.
>
I have been able to resolve this. It was caused by usage of different
context structure pointers.
Hi,
I am working on a client where I need to login to a FTPS server
(vsftpd). I establish the connection, exchange Hellos, certificate & key
exchange and all seems succesful and are happening fine.
I am able to send "PBSZ 0" to the server which gets acknowledged with
"200 PBSZ set to 0." (as seen in Wireshark).
Then, when it comes to sending "PROT P", I cannot see it encoded in
Wireshark. it just says "Application Data" and the next frame reads
"Alert (Level: Fatal, Description: Bad Record Mac)". I have investigated
my code (mostly for differences between "PBSZ 0" and "PROT P" but came
up empty) and have searched the web but have failed to find the
resolution to my problem, as of yet. It seems obvious that the problem
must be in my code but I seem to be unable to put my finger on it! I
thought I should check if someone here may have any other hints that
will help me resolve the problem.
I have temporarily set "mbedtls_ssl_conf_authmode( &ctxt.conf,
MBEDTLS_SSL_VERIFY_NONE);" to make sure that the CA is not the causing
any issues.
Thank you!
Hi, I wonder if anyone can tell me what I'm doing wrong.
I use a modified client1.c for getting payment objects from an aws
address, curl says that the connection uses "SSL connection using
TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256" if it's any use.
I can retrieve any single payment object which has a content length of
about 443 but when I try to get the entire record of payments of which
I only need the first or latest payment to check that I'm in sync, I
get "Last error was: -28928 - SSL - Bad input parameters to function".
This started at a certain point in the payment object accumulation
don't quite know when, the current record of all payments is 22526 and
it grows with every transaction.
The GET request for the all the payment objects ends in "/payments/"
and for a single object /payments/ has the objects id appended to it.
There must be a way to receive a truncated record of all payments.
Here is my latest config.h:
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
/* System support */
//#define MBEDTLS_HAVE_ASM
#define MBEDTLS_HAVE_TIME
#define MBEDTLS_NO_PLATFORM_ENTROPY
#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
#define MBEDTLS_TEST_NULL_ENTROPY
#define MBEDTLS_ERROR_C
#define MBEDTLS_PLATFORM_C
//#define MBEDTLS_PLATFORM_EXIT_ALT
//#define MBEDTLS_PLATFORM_TIME_ALT
//#define MBEDTLS_PLATFORM_FPRINTF_ALT
//#define MBEDTLS_PLATFORM_PRINTF_ALT
//#define MBEDTLS_PLATFORM_SNPRINTF_ALT
//#define MBEDTLS_PLATFORM_VSNPRINTF_ALT
//#define MBEDTLS_PLATFORM_NV_SEED_ALT
//#define MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT
/* mbed TLS feature support */
#define MBEDTLS_CIPHER_MODE_CBC
#define MBEDTLS_PKCS1_V15
#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
#define MBEDTLS_SSL_PROTO_TLS1_2
#define MBEDTLS_SSL_CLI_C
#define MBEDTLS_SSL_TLS_C
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
//experiment
#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
#define MBEDTLS_ECDH_C
#define MBEDTLS_ECP_C
#define MBEDTLS_ECP_DP_SECP192R1_ENABLED
#define MBEDTLS_RSA_C
#define MBEDTLS_OID_C
#define MBEDTLS_PKCS1_V15
#define MBEDTLS_X509_CRT_PARSE_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_MD_C
#define MBEDTLS_BIGNUM_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_PK_PARSE_C
#define MBEDTLS_PK_C
#define MBEDTLS_ASN1_PARSE_C
/* mbed TLS modules */
#define MBEDTLS_AES_C
/*
#define MBEDTLS_ASN1_WRITE_C
#define MBEDTLS_BIGNUM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_DES_C
#define MBEDTLS_MD_C
#define MBEDTLS_MD5_C
//#define MBEDTLS_RSA_C
#define MBEDTLS_SHA1_C
#define MBEDTLS_SHA256_C
*/
#define MBEDTLS_X509_USE_C
/* For test certificates */
#define MBEDTLS_BASE64_C
#define MBEDTLS_CERTS_C
#define MBEDTLS_PEM_PARSE_C
/* Limit memory use*/
#define MBEDTLS_SSL_MAX_CONTENT_LEN 16384
/* For testing with compat.sh */
//#define MBEDTLS_FS_IO
#include "check_config.h"
#endif /* MBEDTLS_CONFIG_H */
Thanks,
Dave P
Hi,
I'd like to compare a signing cert in a cert chain against a pinned cert.
Given two mbedtls_x509_crt (or two mbedtls_rsa_context), what is the
recommended way to compare them?
Thanks!
--
Nassim Eddequiouaq
Hello,
I don't see anything obviously wrong with the code. Heap fragmentation
is a possibility. A memory leak is also a possibility; we do fairly
extensive testing for memory leaks in unit tests, but this doesn't catch
unusual conditions (especially not recovering after a low-memory condition).
I think the first tool to investigate is to enable MBEDTLS_MEMORY_DEBUG.
This has a small cost in code size and gives you access to some
introspection functions mbedtls_memory_buffer_alloc_status() and
mbedtls_memory_buffer_alloc_max_get(). Call these functions on an error,
and also perhaps at other times for comparison.
There's also an option MBEDTLS_MEMORY_BACKTRACE which creates extremely
verbose logs. Those logs might be helpful, but they're so verbose that
they often aren't practical in a real-world application.
I notice that the allocation is for a little over 16kB. The default size
of the SSL input/output buffers is 16kB because that's the maximum size
of a message according to the specification. However you can usually get
away with a lot less, especially on IoT networks where the
infrastructure is geared towards much smaller messages. See
https://tls.mbed.org/kb/how-to/controlling_package_size
<https://tls.mbed.org/kb/how-to/controlling_package_size> for more
information on message sizes and buffer sizes. If the problem is a
memory leak, smaller buffers will only delay the failure. But if the
problem is that the application just needs a bit more heap space, this
could solve the problem.
Concretely, try setting MBEDTLS_SSL_IN_CONTENT_LEN and
MBEDTLS_SSL_OUT_CONTENT_LEN in the compile-time configuration to much
lower values. MBEDTLS_SSL_OUT_CONTENT_LEN can be as low as you like as
long as the handshake messages fit. MBEDTLS_SSL_IN_CONTENT_LEN has to be
large enough for the messages that you're sent.
Alternatively, enable the option MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH,
which results in smaller buffers but can make fragmentation worse due to
reallocations.
Hope this helps.
--
Gilles Peskine
Mbed TLS developer
On 01/08/2021 22:40, Alan Chen via mbed-tls wrote:
>
> I posted the question on the mbedTLS forum, only to realized that
> mbedTLS is now maintained by the project�s mailing list. Here is the
> copy of what I wrote:
>
> �
>
> *Occasionally*� I am getting MBEDTLS_ERR_SSL_ALLOC_FAILED from
> mbedtls_ssl_setup() during repeated HTTP partial content download.
> Since this problem happens very rarely, it is a bit difficult to
> troubleshoot.
>
> �
>
> I am running mbedTLS on a Microchip PIC32MZ MCU, connected to a
> LTE-M/NB-IoT modem. I have 128K static memory reserved for the library
> with MBEDTLS_PLATFORM_MEMORY defined in the config.h file. The MCU
> runs two main tasks - MQTT client, talking to the AWS MQTT broker, and
> HTTPS client, for downloading new firmware image from the AWS S3
> bucket over the air.
>
> �
>
> Due to the slowness and limited bandwidth of the LTE-M and NB-IoT
> technologies, the HTTP file download has to use the partial content
> GET, basically 2KB per request, until all ~700KB of data are received.
> During the course of the file download, one can see as many as 30
> disconnect and reconnect, and each time the TLS session would close
> down and re-open once the cell network is established. Here are some
> of my functions:
>
> �
>
> ```
>
> #define MBEDTLS_MAX_MEMORY_ALLOCATED��� (1024 * 128)
>
> static uint8_t tls_memory_buf[MBEDTLS_MAX_MEMORY_ALLOCATED];
>
> �
>
> // called in main()
>
> void mbedtls_mem_init(void)
>
> {
>
> ��� mbedtls_memory_buffer_alloc_init(tls_memory_buf, sizeof
> tls_memory_buf);
>
> }
>
> �
>
> void HTTPS_TLS_CLOSE(void)
>
> {
>
> ��� if (server_fd_https.fd != -1)
>
> ��� {�������
>
> ��������mbedtls_entropy_free(&entropy_https);
>
> ������� mbedtls_x509_crt_free(&cacert_https);
>
> ������� mbedtls_ctr_drbg_free(&ctr_drbg_https);
>
> ������� mbedtls_ssl_config_free(&conf_https);
>
> ������� mbedtls_ssl_free(&ssl_https);
>
> �
>
> ������� server_fd_https.fd = -1;
>
> ��� }
>
> }
>
> �
>
> bool HTTPS_TLS_OPEN(void)
>
> {
>
> ��� int ret;
>
> ��� const char *pers = "https_tls_wrapper";
>
> �
>
> �
>
> ��� server_fd_https.fd = 1;
>
> ��� mbedtls_debug_set_threshold(1);
>
> �
>
> ��� mbedtls_ssl_init(&ssl_https);
>
> ��� mbedtls_ssl_config_init(&conf_https);
>
> ��� mbedtls_ctr_drbg_init(&ctr_drbg_https);
>
> ��� mbedtls_x509_crt_init(&cacert_https);
>
> ���
>
> ����mbedtls_entropy_init(&entropy_https);���
>
> ����mbedtls_entropy_add_source(&entropy_https, my_https_entropy, NULL,
> sizeof my_https_random, MBEDTLS_ENTROPY_SOURCE_STRONG);
>
> ���
>
> ����ret = mbedtls_ctr_drbg_seed(&ctr_drbg_https, mbedtls_entropy_func,
> &entropy_https, (const unsigned char *)pers, strlen(pers));
>
> ��� if (ret != 0)
>
> ��� {
>
> ������� printf("%s: mbedtls_ctr_drbg_seed ERROR -0x%x\r\n",
> __FUNCTION__, -ret);
>
> ������� return false;
>
> ��� }
>
> �
>
> ��� ret = mbedtls_x509_crt_parse(&cacert_https, TRUSTED_ROOT_CA,
> TRUSTED_ROOT_CA_SIZE);
>
> ��� if (ret != 0)
>
> ��� {
>
> ������� printf("%s: mbedtls_x509_crt_parse cacert ERROR -0x%x\r\n",
> __FUNCTION__, -ret);
>
> ������� return false;
>
> ��� }
>
> ���
>
> ����ret = mbedtls_ssl_config_defaults(&conf_https,
> MBEDTLS_SSL_IS_CLIENT, MBEDTLS_SSL_TRANSPORT_STREAM,
> MBEDTLS_SSL_PRESET_DEFAULT);
>
> ��� if (ret != 0)
>
> ��� {
>
> ������� printf("%s: mbedtls_ssl_config_defaults ERROR -0x%x\r\n",
> __FUNCTION__, -ret);
>
> ������� return false;
>
> ��� }
>
> �
>
> ��� mbedtls_ssl_conf_verify(&conf_https, NULL, NULL);
>
> ��� mbedtls_ssl_conf_authmode(&conf_https, MBEDTLS_SSL_VERIFY_REQUIRED);
>
> ��� mbedtls_ssl_conf_rng(&conf_https, mbedtls_ctr_drbg_random,
> &ctr_drbg_https);
>
> ��� mbedtls_ssl_conf_dbg(&conf_https, my_https_debug, stdout);
>
> ��� mbedtls_ssl_conf_ca_chain(&conf_https, &cacert_https, NULL);
>
> �������
>
> ����mbedtls_ssl_conf_read_timeout(&conf_https, TLS_TIMEOUT_MS);
>
> �
>
> ��� HTTPS_SetHostname(); /* calling mbedtls_ssl_set_hostname */
>
> ���
>
> ����ret = mbedtls_ssl_setup(&ssl_https, &conf_https);
>
> ��� if (ret != 0)
>
> ��� {
>
> ������� printf("%s: mbedtls_ssl_setup ERROR -0x%x\r\n", __FUNCTION__,
> -ret);
>
> ������� return false;
>
> ��� }
>
> �
>
> ��� mbedtls_ssl_set_bio(&ssl_https, &server_fd_https,
> mbedtls_https_send, mbedtls_https_recv, NULL);
>
> �
>
> ��� return true;
>
> }
>
> ```
>
> Can someone please tell me if I am doing something inappropriate here?
> I am speculating that perhaps there is a memory leak or the heap
> becomes so fragmented that it fails on mbedtls_calloc(). The exact
> error message in my case is:
>
> �
>
> > ../mbedtls_lib/ssl_tls.c:5661: alloc(16717 bytes) failed
>
> �
>
> Thanks.
>
> �
>
> Alan Chen
>
>
>
> ------------------------------------------------------------------------
> <https://home.mcafee.com/utm_medium=email&utm_source=link&utm_campaign=sig-e…>
> Scanned by McAfee
> <https://home.mcafee.com/utm_medium=email&utm_source=link&utm_campaign=sig-e…>
> and confirmed virus-free.
>
>
Hi Dave and Gilles,
Perfect, so I will wait for the last 2.x (presumably the 2.28.x) strand
of the version later this year.
Thanks again.
Regards,
Matteo
------ Messaggio Originale ------
Da: mbed-tls(a)lists.trustedfirmware.org
A: Gilles.Peskine(a)arm.com; mbed-tls(a)lists.trustedfirmware.org
Inviato: giovedì 29 luglio 2021 15:33
Oggetto: Re: [mbed-tls] Mbed TLS: long term support versions
Sorry, just realised that myself! Gilles is correct, I should
have said 2.28.
Thanks
Dave
On 29/07/2021, 14:25, "mbed-tls on behalf of Gilles Peskine via
mbed-tls" <mbed-tls-bounces(a)lists.trustedfirmware.org on behalf of
mbed-tls(a)lists.trustedfirmware.org> wrote:
Off-by-one error! The current 2.x release is 2.27.0. Most
development
work is happening on 3.x but there will be at least one more 2.x
release: 2.28.0. The last 2.x release will become an LTS.
--
Gilles Peskine
Mbed TLS developer
On 29/07/2021 15:05, Dave Rodgman via mbed-tls wrote:
>
> Hi Matteo,
>
>
>
> We expect to release an LTS later this year. It’s likely to be
2.27,
> and very likely will be supported for the usual LTS period of 3
years.
>
>
>
> So if you are considering updating to a new LTS, you could use
2.26
> for prototyping in the short term until the LTS becomes
available. The
> upcoming LTS will be API-compatible with 2.26.
>
>
>
> Hope this helps,
>
>
>
> Dave
>
>
>
> *From: *mbed-tls <mbed-tls-bounces(a)lists.trustedfirmware.org> on
> behalf of "matteo.cogi--- via mbed-tls"
> <mbed-tls(a)lists.trustedfirmware.org>
> *Reply to: *"matteo.cogi(a)alice.it" <matteo.cogi(a)alice.it>
> *Date: *Tuesday, 27 July 2021 at 07:44
> *To: *"mbed-tls(a)lists.trustedfirmware.org"
> <mbed-tls(a)lists.trustedfirmware.org>
> *Subject: *[mbed-tls] Mbed TLS: long term support versions
>
>
>
> Dear all,
> I wish to know which are the future LTS (Long Term Support)
versions
> for Mbed TLS.
> In these last years I have been working with the 2.16.x, but I
read it
> will be maintained until at least the end of 2021 (
>
https://github.com/ARMmbed/mbedtls/blob/development/BRANCHES.md#current-bra…
>
<https://github.com/ARMmbed/mbedtls/blob/development/BRANCHES.md#current-bra…>
> ), so I am considering an update to a newer LTS version.
> However I don’t find which are the next LTS version and for how
much
> time they will be maintained.
> Thanks in advance.
> Regards,
> Matteo
>
>
--
mbed-tls mailing list
mbed-tls(a)lists.trustedfirmware.org
https://lists.trustedfirmware.org/mailman/listinfo/mbed-tls
--
mbed-tls mailing list
mbed-tls(a)lists.trustedfirmware.org
https://lists.trustedfirmware.org/mailman/listinfo/mbed-tls
(Note: I'm replying to the list. Please keep list conversations on the
list.)
Writing memory allocators is a specialty. It's not my specialty, and
apparently it's not your specialty either, so if we design a memory
allocator we're likely to end up with poor performance. On most systems,
the standard library malloc is designed by experts, and often fine-tuned
for the type of platform and usage (e.g. large or small pools, with or
without MMU, with or without cache).
memory_buffer_alloc uses an array to implement malloc.
One possible explanation for poor performance is if your allocator
doesn't align data nicely. Some platforms supports unaligned accesses
(e.g. accessing a 4-byte value at an address that isn't a multiple of 4)
but with a significant performance penalty (most others just crash). If
there's a cache, alignment with cache line boundaries can also help.
Another potential reason in a multithreaded program is not doing
synchronization efficiently, or doing it too often. Note that you do NOT
need synchronization if each thread has its own memory pool and no
thread ever modifies the data of another thread. Note, however, that
Mbed TLS caches some data in public/private key objects, so doing an
operation with a key modifies the key object, therefore each thread
would need to have its own copy of the key. There are undoubtedly other
likely reasons that I'm not thinking of.
Best regards,
--
Gilles Peskine
Mbed TLS developer
On 29/07/2021 22:38, Shariful Alam wrote:
> Hi Gilles,
> Hope you are well. The project that I'm currently working on requires
> static memory allocation instead of dynamic memory allocation. I was
> trying to use "memory_buffer_alloc()". Since memory_buffer_alloc()
> doesn't support multiple memory pools, seems like I can't use this
> function in my project.
>
> I have a working version of a modified bignum.c & bignum.h, where
> malloc is replaced with an array. The library is working. However, the
> performance is poor (~4 times slower). I was wondering what could
> cause this slow performance. I mean, I understand it will be slow, but
> I did not expect it to be 4 times slower.
>
> Is there any version, where an array was used instead of malloc? Or if
> you could point out some of the reasons for this library to slow down
> while using an array, I will be very grateful.
>
> Best regards,
> Shariful
>
>
> On Tue, Jul 20, 2021 at 2:22 PM Gilles Peskine <gilles.peskine(a)arm.com
> <mailto:gilles.peskine@arm.com>> wrote:
>
> Hi Shariful,
>
> You just call mbedtls_calloc() (or let other functions call it).
> It will use the memory pool set by mbedtls_memory_buffer_alloc_init().
>
> The memory_buffer_alloc module does not support multiple memory
> pools. If you want a separate pool for each thread's allocation
> for performance reasons on a multicore system, you'd better rely
> on your platform's built-in calloc(). It's likely to be
> fined-tuned for multicore operation. The built-in allocator in
> Mbed TLS is intended for highly resource-constrained systems where
> the basic platform doesn't even include an allocator.
>
> Best regards,
>
> --
> Gilles Peskine
> Mbed TLS developer
>
> On 20/07/2021 22:10, Shariful Alam wrote:
>> Hi Gilles,
>> Thank you very much, for your reply. Sorry to bother you again. I
>> am trying to follow your instructions. I have a question
>> regarding your suggestions.
>>
>> You said "applications call mbedtls_memory_buffer_alloc_init() in
>> the startup code of the initial thread, before creating other
>> threads. The alloc/free functions are thread-safe, but the
>> initialization and deinitialization functions aren't."
>>
>> I'm a little confused here. Say, if I call
>> mbedtls_memory_buffer_alloc_init() with a buffer in the main
>> thread, how did all other threads use this memory (or how do all
>> the threads know which memory block to use)?
>>
>> After calling mbedtls_memory_buffer_alloc_init() in the main
>> thread, I can get the address of the buffer and pass it to the
>> threads, do I have to call mbedtls_memory_buffer_alloc_init()
>> again inside each thread?
>>
>> Thanks,
>> Shariful
>>
>> On Mon, Jul 19, 2021 at 3:48 AM Gilles Peskine via mbed-tls
>> <mbed-tls(a)lists.trustedfirmware.org
>> <mailto:mbed-tls@lists.trustedfirmware.org>> wrote:
>>
>> Hi Shariful,
>>
>> First, please note that the library called PolarSSL with
>> functions like
>> rsa_private() and memory_buffer_alloc_init() has not been
>> supported for
>> several years. You should upgrade to Mbed TLS, with functions
>> like
>> mbedtls_rsa_private() and mbedtls_memory_buffer_alloc_init().
>> That being
>> said, the memory_buffer_alloc module works in the same way.
>>
>> Normally, applications call
>> mbedtls_memory_buffer_alloc_init() in the
>> startup code of the initial thread, before creating other
>> threads. The
>> alloc/free functions are thread-safe, but the initialization and
>> deinitialization functions aren't. If you must call
>> mbedtls_memory_buffer_alloc_init() after creating other
>> threads, make
>> sure that no thread calls mbedtls_calloc until
>> mbedtls_memory_buffer_alloc_init() has returned.
>>
>> The same principle applies to other parts of Mbed TLS that are
>> thread-safe. For example, only the RSA operations (encryption,
>> decryption, signature, verification, and also the low-level
>> functions
>> mbedtls_rsa_public() and mbedtls_rsa_private()) are
>> protected. So you
>> must finish setting up the RSA key inside one thread before
>> you pass a
>> pointer to other threads. Similarly, only
>> mbedtls_xxx_drbg_random() is
>> thread-safe, and the RNG setup (including
>> mbedtls_xxx_drgb_seed())
>> should be done as part of the initial application startup.
>>
>> Finally, note that mbedtls_rsa_private() alone cannot decrypt
>> a message:
>> all it does it to apply the private key operation. To decrypt
>> a simple
>> message encrypted with RSA-OAEP, call
>> mbedtls_rsa_rsaes_oaep_decrypt()
>> or mbedtls_rsa_pkcs1_decrypt() with a key set up for
>> MBEDTLS_RSA_PKCS_V21 encoding. To use the legacy PKCS#1v1.5
>> mechanism,
>> call mbedtls_rsa_rsaes_pkcs1_v15_decrypt() or
>> mbedtls_rsa_pkcs1_decrypt() with a key set up for
>> .MBEDTLS_RSA_PKCS_V15.
>> To decrypt a message using a RSA FDH hybrid scheme, you do
>> need to call
>> mbedtls_rsa_private() since Mbed TLS doesn't support it
>> natively, but
>> what this gives you is the intermediate secret from which you
>> then need
>> to derive a symmetric key, not the message itself.
>>
>> Best regards,
>>
>> --
>> Gilles Peskine
>> Mbed TLS developer
>>
>> On 18/07/2021 07:16, Shariful Alam via mbed-tls wrote:
>> > Hello,
>> > I have a simple example code to decrypt an
>> encrypted message using
>> > *rsa_private()*. I use *memory_buffer_alloc_init(), *in
>> order to use
>> > a static memory for the computation. I want to run my code
>> > concurrently. My code works with a single pthread. However,
>> when I try
>> > to run more than one thread my program fails to decrypt.
>> >
>> > ** I check the same code
>> without *memory_buffer_alloc_init(), *it
>> > works concurrently, without any issues at all.
>> >
>> > Therefore, I believe, the issue that I'm facing is
>> coming from the use
>> > of static memory(e.g. *memory_buffer_alloc_init()*). The
>> documentation
>> > of memorry_buffer_alloc.h shows,
>> >
>> > /**
>> >
>> > * \brief Initialize use of stack-based memory allocator.
>> >
>> > * The stack-based allocator does memory
>> management
>> > inside the
>> >
>> > * presented buffer and does not call malloc()
>> and free().
>> >
>> > * It sets the global polarssl_malloc() and
>> > polarssl_free() pointers
>> >
>> > * to its own functions.
>> >
>> > * (Provided polarssl_malloc() and
>> polarssl_free() are
>> > thread-safe if
>> >
>> > * POLARSSL_THREADING_C is defined)
>> >
>> > *
>> >
>> > * \note This code is not optimized and provides a
>> straight-forward
>> >
>> > * implementation of a stack-based memory
>> allocator.
>> >
>> > *
>> >
>> > * \param buf buffer to use as heap
>> >
>> > * \param len size of the buffer
>> >
>> > *
>> >
>> > * \return 0 if successful
>> >
>> > */
>> >
>> >
>> > So, I added the following configuration to the *config.h*
>> file
>> >
>> > 1. #define POLARSSL_THREADING_PTHREAD
>> > 2. #define POLARSSL_THREADING_C
>> >
>> > But I'm still getting errors while decrypting. Any help on
>> how to fix
>> > this? or what else should I add into the config.h file to
>> > make *memory_buffer_alloc_init() *thread-safe? Here is my
>> sample
>> > code: https://pastebin.com/uyW3vknt
>> <https://pastebin.com/uyW3vknt>
>> <https://pastebin.com/uyW3vknt <https://pastebin.com/uyW3vknt>>
>> >
>> > Thanks,
>> > Shariful
>> >
>>
>> --
>> mbed-tls mailing list
>> mbed-tls(a)lists.trustedfirmware.org
>> <mailto:mbed-tls@lists.trustedfirmware.org>
>> https://lists.trustedfirmware.org/mailman/listinfo/mbed-tls
>> <https://lists.trustedfirmware.org/mailman/listinfo/mbed-tls>
>>
>
I posted the question on the mbedTLS forum, only to realized that mbedTLS is now maintained by the project's mailing list. Here is the copy of what I wrote:
*Occasionally* I am getting MBEDTLS_ERR_SSL_ALLOC_FAILED from mbedtls_ssl_setup() during repeated HTTP partial content download. Since this problem happens very rarely, it is a bit difficult to troubleshoot.
I am running mbedTLS on a Microchip PIC32MZ MCU, connected to a LTE-M/NB-IoT modem. I have 128K static memory reserved for the library with MBEDTLS_PLATFORM_MEMORY defined in the config.h file. The MCU runs two main tasks - MQTT client, talking to the AWS MQTT broker, and HTTPS client, for downloading new firmware image from the AWS S3 bucket over the air.
Due to the slowness and limited bandwidth of the LTE-M and NB-IoT technologies, the HTTP file download has to use the partial content GET, basically 2KB per request, until all ~700KB of data are received. During the course of the file download, one can see as many as 30 disconnect and reconnect, and each time the TLS session would close down and re-open once the cell network is established. Here are some of my functions:
```
#define MBEDTLS_MAX_MEMORY_ALLOCATED (1024 * 128)
static uint8_t tls_memory_buf[MBEDTLS_MAX_MEMORY_ALLOCATED];
// called in main()
void mbedtls_mem_init(void)
{
mbedtls_memory_buffer_alloc_init(tls_memory_buf, sizeof tls_memory_buf);
}
void HTTPS_TLS_CLOSE(void)
{
if (server_fd_https.fd != -1)
{
mbedtls_entropy_free(&entropy_https);
mbedtls_x509_crt_free(&cacert_https);
mbedtls_ctr_drbg_free(&ctr_drbg_https);
mbedtls_ssl_config_free(&conf_https);
mbedtls_ssl_free(&ssl_https);
server_fd_https.fd = -1;
}
}
bool HTTPS_TLS_OPEN(void)
{
int ret;
const char *pers = "https_tls_wrapper";
server_fd_https.fd = 1;
mbedtls_debug_set_threshold(1);
mbedtls_ssl_init(&ssl_https);
mbedtls_ssl_config_init(&conf_https);
mbedtls_ctr_drbg_init(&ctr_drbg_https);
mbedtls_x509_crt_init(&cacert_https);
mbedtls_entropy_init(&entropy_https);
mbedtls_entropy_add_source(&entropy_https, my_https_entropy, NULL, sizeof my_https_random, MBEDTLS_ENTROPY_SOURCE_STRONG);
ret = mbedtls_ctr_drbg_seed(&ctr_drbg_https, mbedtls_entropy_func, &entropy_https, (const unsigned char *)pers, strlen(pers));
if (ret != 0)
{
printf("%s: mbedtls_ctr_drbg_seed ERROR -0x%x\r\n", __FUNCTION__, -ret);
return false;
}
ret = mbedtls_x509_crt_parse(&cacert_https, TRUSTED_ROOT_CA, TRUSTED_ROOT_CA_SIZE);
if (ret != 0)
{
printf("%s: mbedtls_x509_crt_parse cacert ERROR -0x%x\r\n", __FUNCTION__, -ret);
return false;
}
ret = mbedtls_ssl_config_defaults(&conf_https, MBEDTLS_SSL_IS_CLIENT, MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT);
if (ret != 0)
{
printf("%s: mbedtls_ssl_config_defaults ERROR -0x%x\r\n", __FUNCTION__, -ret);
return false;
}
mbedtls_ssl_conf_verify(&conf_https, NULL, NULL);
mbedtls_ssl_conf_authmode(&conf_https, MBEDTLS_SSL_VERIFY_REQUIRED);
mbedtls_ssl_conf_rng(&conf_https, mbedtls_ctr_drbg_random, &ctr_drbg_https);
mbedtls_ssl_conf_dbg(&conf_https, my_https_debug, stdout);
mbedtls_ssl_conf_ca_chain(&conf_https, &cacert_https, NULL);
mbedtls_ssl_conf_read_timeout(&conf_https, TLS_TIMEOUT_MS);
HTTPS_SetHostname(); /* calling mbedtls_ssl_set_hostname */
ret = mbedtls_ssl_setup(&ssl_https, &conf_https);
if (ret != 0)
{
printf("%s: mbedtls_ssl_setup ERROR -0x%x\r\n", __FUNCTION__, -ret);
return false;
}
mbedtls_ssl_set_bio(&ssl_https, &server_fd_https, mbedtls_https_send, mbedtls_https_recv, NULL);
return true;
}
```
Can someone please tell me if I am doing something inappropriate here? I am speculating that perhaps there is a memory leak or the heap becomes so fragmented that it fails on mbedtls_calloc(). The exact error message in my case is:
> ../mbedtls_lib/ssl_tls.c:5661: alloc(16717 bytes) failed
Thanks.
Alan Chen
________________________________
[https://secureimages.mcafee.com/common/affiliateImages/mfe/logo.png]<https://home.mcafee.com/utm_medium=email&utm_source=link&utm_campaign=sig-e…> Scanned by McAfee<https://home.mcafee.com/utm_medium=email&utm_source=link&utm_campaign=sig-e…> and confirmed virus-free.
Sorry, just realised that myself! Gilles is correct, I should have said 2.28.
Thanks
Dave
On 29/07/2021, 14:25, "mbed-tls on behalf of Gilles Peskine via mbed-tls" <mbed-tls-bounces(a)lists.trustedfirmware.org on behalf of mbed-tls(a)lists.trustedfirmware.org> wrote:
Off-by-one error! The current 2.x release is 2.27.0. Most development
work is happening on 3.x but there will be at least one more 2.x
release: 2.28.0. The last 2.x release will become an LTS.
--
Gilles Peskine
Mbed TLS developer
On 29/07/2021 15:05, Dave Rodgman via mbed-tls wrote:
>
> Hi Matteo,
>
>
>
> We expect to release an LTS later this year. It’s likely to be 2.27,
> and very likely will be supported for the usual LTS period of 3 years.
>
>
>
> So if you are considering updating to a new LTS, you could use 2.26
> for prototyping in the short term until the LTS becomes available. The
> upcoming LTS will be API-compatible with 2.26.
>
>
>
> Hope this helps,
>
>
>
> Dave
>
>
>
> *From: *mbed-tls <mbed-tls-bounces(a)lists.trustedfirmware.org> on
> behalf of "matteo.cogi--- via mbed-tls"
> <mbed-tls(a)lists.trustedfirmware.org>
> *Reply to: *"matteo.cogi(a)alice.it" <matteo.cogi(a)alice.it>
> *Date: *Tuesday, 27 July 2021 at 07:44
> *To: *"mbed-tls(a)lists.trustedfirmware.org"
> <mbed-tls(a)lists.trustedfirmware.org>
> *Subject: *[mbed-tls] Mbed TLS: long term support versions
>
>
>
> Dear all,
> I wish to know which are the future LTS (Long Term Support) versions
> for Mbed TLS.
> In these last years I have been working with the 2.16.x, but I read it
> will be maintained until at least the end of 2021 (
> https://github.com/ARMmbed/mbedtls/blob/development/BRANCHES.md#current-bra…
> <https://github.com/ARMmbed/mbedtls/blob/development/BRANCHES.md#current-bra…>
> ), so I am considering an update to a newer LTS version.
> However I don’t find which are the next LTS version and for how much
> time they will be maintained.
> Thanks in advance.
> Regards,
> Matteo
>
>
--
mbed-tls mailing list
mbed-tls(a)lists.trustedfirmware.org
https://lists.trustedfirmware.org/mailman/listinfo/mbed-tls
Off-by-one error! The current 2.x release is 2.27.0. Most development
work is happening on 3.x but there will be at least one more 2.x
release: 2.28.0. The last 2.x release will become an LTS.
--
Gilles Peskine
Mbed TLS developer
On 29/07/2021 15:05, Dave Rodgman via mbed-tls wrote:
>
> Hi Matteo,
>
>
>
> We expect to release an LTS later this year. It’s likely to be 2.27,
> and very likely will be supported for the usual LTS period of 3 years.
>
>
>
> So if you are considering updating to a new LTS, you could use 2.26
> for prototyping in the short term until the LTS becomes available. The
> upcoming LTS will be API-compatible with 2.26.
>
>
>
> Hope this helps,
>
>
>
> Dave
>
>
>
> *From: *mbed-tls <mbed-tls-bounces(a)lists.trustedfirmware.org> on
> behalf of "matteo.cogi--- via mbed-tls"
> <mbed-tls(a)lists.trustedfirmware.org>
> *Reply to: *"matteo.cogi(a)alice.it" <matteo.cogi(a)alice.it>
> *Date: *Tuesday, 27 July 2021 at 07:44
> *To: *"mbed-tls(a)lists.trustedfirmware.org"
> <mbed-tls(a)lists.trustedfirmware.org>
> *Subject: *[mbed-tls] Mbed TLS: long term support versions
>
>
>
> Dear all,
> I wish to know which are the future LTS (Long Term Support) versions
> for Mbed TLS.
> In these last years I have been working with the 2.16.x, but I read it
> will be maintained until at least the end of 2021 (
> https://github.com/ARMmbed/mbedtls/blob/development/BRANCHES.md#current-bra…
> <https://github.com/ARMmbed/mbedtls/blob/development/BRANCHES.md#current-bra…>
> ), so I am considering an update to a newer LTS version.
> However I don’t find which are the next LTS version and for how much
> time they will be maintained.
> Thanks in advance.
> Regards,
> Matteo
>
>
Hi Matteo,
We expect to release an LTS later this year. It’s likely to be 2.27, and very likely will be supported for the usual LTS period of 3 years.
So if you are considering updating to a new LTS, you could use 2.26 for prototyping in the short term until the LTS becomes available. The upcoming LTS will be API-compatible with 2.26.
Hope this helps,
Dave
From: mbed-tls <mbed-tls-bounces(a)lists.trustedfirmware.org> on behalf of "matteo.cogi--- via mbed-tls" <mbed-tls(a)lists.trustedfirmware.org>
Reply to: "matteo.cogi(a)alice.it" <matteo.cogi(a)alice.it>
Date: Tuesday, 27 July 2021 at 07:44
To: "mbed-tls(a)lists.trustedfirmware.org" <mbed-tls(a)lists.trustedfirmware.org>
Subject: [mbed-tls] Mbed TLS: long term support versions
Dear all,
I wish to know which are the future LTS (Long Term Support) versions for Mbed TLS.
In these last years I have been working with the 2.16.x, but I read it will be maintained until at least the end of 2021 ( https://github.com/ARMmbed/mbedtls/blob/development/BRANCHES.md#current-bra… ), so I am considering an update to a newer LTS version.
However I don’t find which are the next LTS version and for how much time they will be maintained.
Thanks in advance.
Regards,
Matteo
Hello,
Mbed TLS has never supported a build with SHA-256 but not SHA-224. In
Mbed TLS 2.x, enabling MBEDTLS_SHA256_C enables both SHA-256 and
SHA-224. Likewise, MBEDTLS_SHA512_C enables both SHA-512 and SHA-384.
The reason for this design is that SHA-256 and SHA-224 have essentially
the same code but different constants, and likewise for SHA-512 and SHA-384.
What changed in Mbed TLS 3.0 is that there are now separate
configuration options for each of the four SHA2 variants.
It is not possible yet to enable SHA-384 without SHA-512, SHA-224
without SHA-256 or SHA-256 without SHA-224. These are implementation
limitations due to missing #ifdef in various places. We expect to lift
these limitations in one of the next 3.x releases.
Best regards,
--
Gilles Peskine
Mbed TLS developer
On 19/07/2021 14:50, David Hu via mbed-tls wrote:
>
> Hi,
>
> �
>
> It seems that SHA224 is mandatory if SHA256 is selected, in Mbed TLS
> latest version, according to this new check below:
>
> �
>
> #if defined(MBEDTLS_SHA256_C) && !defined(MBEDTLS_SHA224_C)
>
> #error "MBEDTLS_SHA256_C defined without MBEDTLS_SHA224_C"
>
> #endif
>
> �
>
> May I know why SHA224 must be enabled with SHA256?
>
> Could you please point me to any reference/document?
>
> �
>
> Best regards,
>
> Hu Ziji
>
>
Hi Gilles,
Thank you very much, for your reply. Sorry to bother you again. I am trying
to follow your instructions. I have a question regarding your suggestions.
You said "applications call mbedtls_memory_buffer_alloc_init() in the
startup code of the initial thread, before creating other threads. The
alloc/free functions are thread-safe, but the initialization and
deinitialization functions aren't."
I'm a little confused here. Say, if I call
mbedtls_memory_buffer_alloc_init() with a buffer in the main thread, how
did all other threads use this memory (or how do all the threads know which
memory block to use)?
After calling mbedtls_memory_buffer_alloc_init() in the main thread, I can
get the address of the buffer and pass it to the threads, do I have to call
mbedtls_memory_buffer_alloc_init() again inside each thread?
Thanks,
Shariful
On Mon, Jul 19, 2021 at 3:48 AM Gilles Peskine via mbed-tls <
mbed-tls(a)lists.trustedfirmware.org> wrote:
> Hi Shariful,
>
> First, please note that the library called PolarSSL with functions like
> rsa_private() and memory_buffer_alloc_init() has not been supported for
> several years. You should upgrade to Mbed TLS, with functions like
> mbedtls_rsa_private() and mbedtls_memory_buffer_alloc_init(). That being
> said, the memory_buffer_alloc module works in the same way.
>
> Normally, applications call mbedtls_memory_buffer_alloc_init() in the
> startup code of the initial thread, before creating other threads. The
> alloc/free functions are thread-safe, but the initialization and
> deinitialization functions aren't. If you must call
> mbedtls_memory_buffer_alloc_init() after creating other threads, make
> sure that no thread calls mbedtls_calloc until
> mbedtls_memory_buffer_alloc_init() has returned.
>
> The same principle applies to other parts of Mbed TLS that are
> thread-safe. For example, only the RSA operations (encryption,
> decryption, signature, verification, and also the low-level functions
> mbedtls_rsa_public() and mbedtls_rsa_private()) are protected. So you
> must finish setting up the RSA key inside one thread before you pass a
> pointer to other threads. Similarly, only mbedtls_xxx_drbg_random() is
> thread-safe, and the RNG setup (including mbedtls_xxx_drgb_seed())
> should be done as part of the initial application startup.
>
> Finally, note that mbedtls_rsa_private() alone cannot decrypt a message:
> all it does it to apply the private key operation. To decrypt a simple
> message encrypted with RSA-OAEP, call mbedtls_rsa_rsaes_oaep_decrypt()
> or mbedtls_rsa_pkcs1_decrypt() with a key set up for
> MBEDTLS_RSA_PKCS_V21 encoding. To use the legacy PKCS#1v1.5 mechanism,
> call mbedtls_rsa_rsaes_pkcs1_v15_decrypt() or
> mbedtls_rsa_pkcs1_decrypt() with a key set up for .MBEDTLS_RSA_PKCS_V15.
> To decrypt a message using a RSA FDH hybrid scheme, you do need to call
> mbedtls_rsa_private() since Mbed TLS doesn't support it natively, but
> what this gives you is the intermediate secret from which you then need
> to derive a symmetric key, not the message itself.
>
> Best regards,
>
> --
> Gilles Peskine
> Mbed TLS developer
>
> On 18/07/2021 07:16, Shariful Alam via mbed-tls wrote:
> > Hello,
> > I have a simple example code to decrypt an encrypted message using
> > *rsa_private()*. I use *memory_buffer_alloc_init(), *in order to use
> > a static memory for the computation. I want to run my code
> > concurrently. My code works with a single pthread. However, when I try
> > to run more than one thread my program fails to decrypt.
> >
> > ** I check the same code without *memory_buffer_alloc_init(), *it
> > works concurrently, without any issues at all.
> >
> > Therefore, I believe, the issue that I'm facing is coming from the use
> > of static memory(e.g. *memory_buffer_alloc_init()*). The documentation
> > of memorry_buffer_alloc.h shows,
> >
> > /**
> >
> > * \brief Initialize use of stack-based memory allocator.
> >
> > * The stack-based allocator does memory management
> > inside the
> >
> > * presented buffer and does not call malloc() and free().
> >
> > * It sets the global polarssl_malloc() and
> > polarssl_free() pointers
> >
> > * to its own functions.
> >
> > * (Provided polarssl_malloc() and polarssl_free() are
> > thread-safe if
> >
> > * POLARSSL_THREADING_C is defined)
> >
> > *
> >
> > * \note This code is not optimized and provides a
> straight-forward
> >
> > * implementation of a stack-based memory allocator.
> >
> > *
> >
> > * \param buf buffer to use as heap
> >
> > * \param len size of the buffer
> >
> > *
> >
> > * \return 0 if successful
> >
> > */
> >
> >
> > So, I added the following configuration to the *config.h* file
> >
> > 1. #define POLARSSL_THREADING_PTHREAD
> > 2. #define POLARSSL_THREADING_C
> >
> > But I'm still getting errors while decrypting. Any help on how to fix
> > this? or what else should I add into the config.h file to
> > make *memory_buffer_alloc_init() *thread-safe? Here is my sample
> > code: https://pastebin.com/uyW3vknt <https://pastebin.com/uyW3vknt>
> >
> > Thanks,
> > Shariful
> >
>
> --
> mbed-tls mailing list
> mbed-tls(a)lists.trustedfirmware.org
> https://lists.trustedfirmware.org/mailman/listinfo/mbed-tls
>
Hi,
It seems that SHA224 is mandatory if SHA256 is selected, in Mbed TLS latest version, according to this new check below:
#if defined(MBEDTLS_SHA256_C) && !defined(MBEDTLS_SHA224_C)
#error "MBEDTLS_SHA256_C defined without MBEDTLS_SHA224_C"
#endif
May I know why SHA224 must be enabled with SHA256?
Could you please point me to any reference/document?
Best regards,
Hu Ziji
Hi Shariful,
First, please note that the library called PolarSSL with functions like
rsa_private() and memory_buffer_alloc_init() has not been supported for
several years. You should upgrade to Mbed TLS, with functions like
mbedtls_rsa_private() and mbedtls_memory_buffer_alloc_init(). That being
said, the memory_buffer_alloc module works in the same way.
Normally, applications call mbedtls_memory_buffer_alloc_init() in the
startup code of the initial thread, before creating other threads. The
alloc/free functions are thread-safe, but the initialization and
deinitialization functions aren't. If you must call
mbedtls_memory_buffer_alloc_init() after creating other threads, make
sure that no thread calls mbedtls_calloc until
mbedtls_memory_buffer_alloc_init() has returned.
The same principle applies to other parts of Mbed TLS that are
thread-safe. For example, only the RSA operations (encryption,
decryption, signature, verification, and also the low-level functions
mbedtls_rsa_public() and mbedtls_rsa_private()) are protected. So you
must finish setting up the RSA key inside one thread before you pass a
pointer to other threads. Similarly, only mbedtls_xxx_drbg_random() is
thread-safe, and the RNG setup (including mbedtls_xxx_drgb_seed())
should be done as part of the initial application startup.
Finally, note that mbedtls_rsa_private() alone cannot decrypt a message:
all it does it to apply the private key operation. To decrypt a simple
message encrypted with RSA-OAEP, call mbedtls_rsa_rsaes_oaep_decrypt()
or mbedtls_rsa_pkcs1_decrypt() with a key set up for
MBEDTLS_RSA_PKCS_V21 encoding. To use the legacy PKCS#1v1.5 mechanism,
call mbedtls_rsa_rsaes_pkcs1_v15_decrypt() or
mbedtls_rsa_pkcs1_decrypt() with a key set up for .MBEDTLS_RSA_PKCS_V15.
To decrypt a message using a RSA FDH hybrid scheme, you do need to call
mbedtls_rsa_private() since Mbed TLS doesn't support it natively, but
what this gives you is the intermediate secret from which you then need
to derive a symmetric key, not the message itself.
Best regards,
--
Gilles Peskine
Mbed TLS developer
On 18/07/2021 07:16, Shariful Alam via mbed-tls wrote:
> Hello,
> I have a simple example code to decrypt an encrypted message using
> *rsa_private()*. I use *memory_buffer_alloc_init(), *in order to use
> a static memory for the computation. I want to run my code
> concurrently. My code works with a single pthread. However, when I try
> to run more than one thread my program fails to decrypt.
>
> ** I check the same code without *memory_buffer_alloc_init(), *it
> works concurrently, without any issues at all.
>
> Therefore, I believe, the issue that I'm facing is coming from the use
> of static memory(e.g. *memory_buffer_alloc_init()*). The documentation
> of memorry_buffer_alloc.h shows,
>
> /**
>
> * \brief Initialize use of stack-based memory allocator.
>
> * The stack-based allocator does memory management
> inside the
>
> * presented buffer and does not call malloc() and free().
>
> * It sets the global polarssl_malloc() and
> polarssl_free() pointers
>
> * to its own functions.
>
> * (Provided polarssl_malloc() and polarssl_free() are
> thread-safe if
>
> * POLARSSL_THREADING_C is defined)
>
> *
>
> * \note This code is not optimized and provides a straight-forward
>
> * implementation of a stack-based memory allocator.
>
> *
>
> * \param buf buffer to use as heap
>
> * \param len size of the buffer
>
> *
>
> * \return 0 if successful
>
> */
>
>
> So, I added the following configuration to the *config.h* file
>
> 1. #define POLARSSL_THREADING_PTHREAD
> 2. #define POLARSSL_THREADING_C
>
> But I'm still getting errors while decrypting. Any help on how to fix
> this? or what else should I add into the config.h file to
> make *memory_buffer_alloc_init() *thread-safe? Here is my sample
> code: https://pastebin.com/uyW3vknt <https://pastebin.com/uyW3vknt>
>
> Thanks,
> Shariful
>
Hello,
I have a simple example code to decrypt an encrypted message using
*rsa_private()*. I use *memory_buffer_alloc_init(), *in order to use a
static memory for the computation. I want to run my code concurrently. My
code works with a single pthread. However, when I try to run more than one
thread my program fails to decrypt.
** I check the same code without *memory_buffer_alloc_init(), *it works
concurrently, without any issues at all.
Therefore, I believe, the issue that I'm facing is coming from the use of
static memory(e.g. *memory_buffer_alloc_init()*). The documentation of
memorry_buffer_alloc.h shows,
/**
* \brief Initialize use of stack-based memory allocator.
* The stack-based allocator does memory management inside the
* presented buffer and does not call malloc() and free().
* It sets the global polarssl_malloc() and polarssl_free()
> pointers
* to its own functions.
* (Provided polarssl_malloc() and polarssl_free() are thread-safe
> if
* POLARSSL_THREADING_C is defined)
*
* \note This code is not optimized and provides a straight-forward
* implementation of a stack-based memory allocator.
*
* \param buf buffer to use as heap
* \param len size of the buffer
*
* \return 0 if successful
*/
So, I added the following configuration to the *config.h* file
1. #define POLARSSL_THREADING_PTHREAD
2. #define POLARSSL_THREADING_C
But I'm still getting errors while decrypting. Any help on how to fix this?
or what else should I add into the config.h file to make
*memory_buffer_alloc_init()
*thread-safe? Here is my sample code: https://pastebin.com/uyW3vknt
Thanks,
Shariful
Hi,
I'm working on a client application that will connect to an FTPS server (vsftpd) to download files.
Now, I have ca-cert, cert and key files all setup to work with curl like:
curl -3 -k -v --ftp-ssl --tlsv1.2 --ftp-ssl-reqd --ftp-pasv --verbose \
--ssl \
--cert ./en-cert.pem \
--cert-type PEM \
--key ./en-cert.key \
--key-type PEM \
--cacert ./ca-cert \
ftp://user:pass@10.10.100.1/test.txt -O
Now, I use the same cert, key & ca-cert with mbedtls but am unable to handshake, mbedtls_ssl_handshake()
keeps giving me an error, what is done in order:
- init cert, ca-cert, key, entropy, drbg, ssl, config
- parse ca-cert, cert & key
- seed RNG - mbedtls_ctr_drbg_seed with mbedtls_hardware_poll
- set config defaults MBEDTLS_SSL_IS_CLIENT, MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT
- mbedtls_ssl_conf_ca_chain
- mbedtls_ssl_conf_rng with mbedtls_ctr_drbg_random
- mbedtls_ssl_conf_dbg
- mbedtls_ssl_conf_own_cert
- mbedtls_ssl_setup
- mbedtls_ssl_set_bio
- mbedtls_ssl_handshake
which up to the handshake all seems to go through without any issues.
When I look at it with wireshark, I see something like:
Response: 234 Proceed with negotiation.
Request:looks like the certificate jumbled up
Response 500 OOPS:
Response :SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown
Any hints on how I best go about troubleshooting this? I have confirmed that ca-cert, cert & key are identical to the ones
that are used for the above curl command.
Thanks,
Hi,
Semantic versioning applies only to API compatibility but not for ABI. When we break the ABI we increase the SO version for that part of the library and this is how linux distributions normally track our ABI compatibility. Additionally, we try very hard not to break ABI at all in LTS versions.
You can find a detailed description what Mbed TLS promises regarding API/ABI compatibility:
https://github.com/ARMmbed/mbedtls/blob/development/BRANCHES.md
Kind regards,
Janos
From: mbed-tls <mbed-tls-bounces(a)lists.trustedfirmware.org> on behalf of Hugues De Valon via mbed-tls <mbed-tls(a)lists.trustedfirmware.org>
Date: Wednesday, 14 July 2021 at 17:09
To: mbed-tls(a)lists.trustedfirmware.org <mbed-tls(a)lists.trustedfirmware.org>
Subject: [mbed-tls] Question about dynamic linking, versioning and API/ABI stability
Hello,
We are using Mbed Crypto in our Parsec project through the psa-crypto Rust crate (https://github.com/parallaxsecond/rust-psa-crypto). We currently have Mbed Crypto through Mbed TLS 2.25.0 which we build statically from scratch by default.
We also offer the option to dynamically link with an Mbed Crypto library available on the system. Ideally, this would offer an easy and simple way to patch bug fixes without having to recompile everything.
However, as we observed API (and probably ABI) breaking changes over the past versions of Mbed TLS we were wondering if this (dynamic linking) was a model we should promote at all.
Is there a semantic versioning process currently applied in Mbed TLS? If we use Mbed TLS 3.0.0 in our crate, can we be sure than 3.x.y versions won’t contain any API/ABI breaking changes or is there nothing of the sort?
I believe that Mbed Crypto is catching up to be fully compliant with PSA Crypto 1.0.1. Once that will be the case, will its API/ABI be stable and follow the PSA Crypto semantic versioning?
It might be that the good solution is that we shouldn’t dynamically link with Mbed Crypto but always compile it from scratch as we do by default. I am just sending this email so that we follow the good approach!
Kind regards,
Hugues
Hello,
We are using Mbed Crypto in our Parsec project through the psa-crypto Rust crate (https://github.com/parallaxsecond/rust-psa-crypto). We currently have Mbed Crypto through Mbed TLS 2.25.0 which we build statically from scratch by default.
We also offer the option to dynamically link with an Mbed Crypto library available on the system. Ideally, this would offer an easy and simple way to patch bug fixes without having to recompile everything.
However, as we observed API (and probably ABI) breaking changes over the past versions of Mbed TLS we were wondering if this (dynamic linking) was a model we should promote at all.
Is there a semantic versioning process currently applied in Mbed TLS? If we use Mbed TLS 3.0.0 in our crate, can we be sure than 3.x.y versions won't contain any API/ABI breaking changes or is there nothing of the sort?
I believe that Mbed Crypto is catching up to be fully compliant with PSA Crypto 1.0.1. Once that will be the case, will its API/ABI be stable and follow the PSA Crypto semantic versioning?
It might be that the good solution is that we shouldn't dynamically link with Mbed Crypto but always compile it from scratch as we do by default. I am just sending this email so that we follow the good approach!
Kind regards,
Hugues
Hello, we are using the mbed-tls for secure communication for FTP. FTP
server is handling the client hello serially one at a time, one
communication is blocking other clients to communicate. What could be the
reason and how to solve this issue.
--
Thanks and Regards,
Sunil Jain
Gilles,
Thanks for getting me to try to read DER files. There must definitely be
something wrong in that area. I am speficying support for PEM in the
build but reading DER gets me past that error.
Searching further :-)
Again, thanks
Danny
On 05/07/2021 20:27, Gilles Peskine via mbed-tls wrote:
> Hello,
>
> The first thing when you see an unexpected error code is to look up the
> corresponding error message. Mbed TLS comes with a utility for that:
>
> programs/util/strerror 0x2180
> Last error was: -0x2180 - X509 - The CRT/CRL/CSR format is invalid,
> e.g. different type expected
>
> You can also search the error code in the source code:
>
> grep 0x2180 include/mbedtls/*.h
> include/mbedtls/x509.h:#define
> MBEDTLS_ERR_X509_INVALID_FORMAT -0x2180 /**< The
> CRT/CRL/CSR format is invalid, e.g. different type expected. */
>
> At first glance it looks like there's only one case for which CRT
> parsing return MBEDTLS_ERR_X509_INVALID_FORMAT as opposed to
> (MBEDTLS_ERR_X509_INVALID_FORMAT + low_level_error_code), and that's if
> the certificate doesn't parse like a DER format at the top level. A
> plausible reason for that is that the certificate is in PEM format and
> your build has PEM support turned off. If that's the case, convert the
> certifcate to DER when you copy it to the device. You can use the Mbed
> TLS utility programs/util/pem2der for that.
>
> Best regards,
>
--
Danny Backx - dannybackx(a)telenet.be - http://danny.backx.info
Hi, mbedtls experts
I note that there is AES NI support (aesni.c) on x86 platform.
I'm wondering why there is no SHA NI support for SHA1 and SHA256? How can I get SHA NI support? Should I choose another crypto library?
Thanks,
Jingdong
Hello,
The first thing when you see an unexpected error code is to look up the
corresponding error message. Mbed TLS comes with a utility for that:
programs/util/strerror 0x2180
Last error was: -0x2180 - X509 - The CRT/CRL/CSR format is invalid,
e.g. different type expected
You can also search the error code in the source code:
grep 0x2180 include/mbedtls/*.h
include/mbedtls/x509.h:#define
MBEDTLS_ERR_X509_INVALID_FORMAT -0x2180 /**< The
CRT/CRL/CSR format is invalid, e.g. different type expected. */
At first glance it looks like there's only one case for which CRT
parsing return MBEDTLS_ERR_X509_INVALID_FORMAT as opposed to
(MBEDTLS_ERR_X509_INVALID_FORMAT + low_level_error_code), and that's if
the certificate doesn't parse like a DER format at the top level. A
plausible reason for that is that the certificate is in PEM format and
your build has PEM support turned off. If that's the case, convert the
certifcate to DER when you copy it to the device. You can use the Mbed
TLS utility programs/util/pem2der for that.
Best regards,
--
Gilles Peskine
Mbed TLS developer
On 05/07/2021 18:10, Danny Backx via mbed-tls wrote:
>
> Hi,
>
> I must be missing something obvious but my code (on an ESP32) fails to
> accept an incoming connection.
>
> I tried the same certificate on an ESP32 sample, and it appears to
> work there.
>
> Does anyone have a clue where to look next ?
>
> Danny
>
> I (16:06:51.481) esp_https_server: performing session handshake
> E (16:06:51.483) x509_crt: x509_crt_parse_der_core -> 0x2180
> E (16:06:51.484) esp_tls_mbedtls: set_pki_context: public_cert
> 0x3ffdb924, len 5750 -> ret 0x2180
> E (16:06:51.493) esp-tls-mbedtls: mbedtls_x509_crt_parse returned -0x2180
> E (16:06:51.501) esp-tls-mbedtls: Failed to set server pki context
> E (16:06:51.508) esp-tls-mbedtls: Failed to set server configurations
> E (16:06:51.515) esp-tls-mbedtls: create_ssl_handle failed
> E (16:06:51.521) esp_https_server: esp_tls_create_server_session failed
> W (16:06:51.528) httpd: httpd_accept_conn: session creation failed
> W (16:06:51.538) httpd: httpd_server: error accepting new connection
>
> --
> Danny Backx - dannybackx(a)telenet.be - http://danny.backx.info
>
Hi,
I must be missing something obvious but my code (on an ESP32) fails to
accept an incoming connection.
I tried the same certificate on an ESP32 sample, and it appears to work
there.
Does anyone have a clue where to look next ?
Danny
I (16:06:51.481) esp_https_server: performing session handshake
E (16:06:51.483) x509_crt: x509_crt_parse_der_core -> 0x2180
E (16:06:51.484) esp_tls_mbedtls: set_pki_context: public_cert
0x3ffdb924, len 5750 -> ret 0x2180
E (16:06:51.493) esp-tls-mbedtls: mbedtls_x509_crt_parse returned -0x2180
E (16:06:51.501) esp-tls-mbedtls: Failed to set server pki context
E (16:06:51.508) esp-tls-mbedtls: Failed to set server configurations
E (16:06:51.515) esp-tls-mbedtls: create_ssl_handle failed
E (16:06:51.521) esp_https_server: esp_tls_create_server_session failed
W (16:06:51.528) httpd: httpd_accept_conn: session creation failed
W (16:06:51.538) httpd: httpd_server: error accepting new connection
--
Danny Backx - dannybackx(a)telenet.be - http://danny.backx.info
Hello everyone,
I am currently evaluating SSL with a local server and an STM32 device. I'm
unable to figure out why the decryption fails with CCM as the cipher suite.
FYI: I am using MbedTLS *v2.14.1.*
*Setup*:
I'm using *x86 local server* with *STM32* device as a client.
Here is what happens-
1. Software CCM implementation on the client:
When I use the *software* implementation of the CCM. Handshake and
decryption is *successful*. Therefore, I can stream
the data from STM32 and read it on the local server.
2. Hardware CCM implementation with MBEDTLS_CCM_ALT:
I have used ccm_alt.c provided from STM32Cube v1.9.0. Here, the
handshake is successful. But *decrypting* the
message *fails*.
The errors are:
ssl_decrypt_buf() returned -29056 (-0x7180)
mbedtls_ssl_read_record() returned -29056 (-0x7180)
Checks performed:
- Same certificates are used for SW and HW implementations.
- CCM self test returns '0' for both HW and SW CCM implementations.
- I have reserved enough heap, no memory issues.
Please find all the necessary data in the attachment provided. I have added
the logs from the server and the client. I have added the certificates and
the code files as well.
It would be of great help if somebody could point at what might be going
wrong.
Thank you!
Best regards,
Navin
Hi Shudong,
Mbed TLS currently does not provide EdDSA. The contribution by @aurel32 is a first step in this direction. The work leading up to a fully functional EdDSA implementation is tracked here:
https://github.com/ARMmbed/mbedtls/projects/2#column-11150355
Kind regards,
Janos
From: mbed-tls <mbed-tls-bounces(a)lists.trustedfirmware.org> on behalf of Shudong Zhang via mbed-tls <mbed-tls(a)lists.trustedfirmware.org>
Date: Wednesday, 30 June 2021 at 07:28
To: mbed-tls(a)lists.trustedfirmware.org <mbed-tls(a)lists.trustedfirmware.org>
Subject: [mbed-tls] Is the a version that can use the EdDSA signature algorithm currently?
Hello,
I want to use EdDSA signature algorithm, but I did’t find API for it in 2.26.0.Then I searched in the issue of Github and I found @aurel32 contributed some code about ed25519.But I am still not sure whether there are any versions under development that provide interface functions for EdDSA signature algorithm. Can someone help me answer my question?
Thanks and kind regards,
Shudong
Hello,
I want to use EdDSA signature algorithm, but I did’t find API for it in 2.26.0.Then I searched in the issue of Github and I found @aurel32 contributed some code about ed25519.But I am still not sure whether there are any versions under development that provide interface functions for EdDSA signature algorithm. Can someone help me answer my question?
Thanks and kind regards,
Shudong
Hi,
I have an ACME client library for esp32, and I try to extend it to
support multiple host names. First step is to include alternate names in
the CSR.
After I tried the ARMmbed issues forum, I was pointed to this list.
My code is in
http://svn.code.sf.net/p/esp32-acme-client/code/trunk/libraries/acmeclient/…
<http://svn.code.sf.net/p/esp32-acme-client/code/trunk/libraries/acmeclient/…>
(see function Acme::CreateAltUrlList) , the function below is an attempt
to do what I described, but doesn't work.
Can anyone help ?
Danny
int Acme::CreateAltUrlList(mbedtls_x509write_csr req) {
int l = 20;
int ret;
for (int i=0; alt_urls[i]; i++) {
l += strlen(alt_urls[i]) + 20;
}
unsigned char *buf = (unsigned char *)malloc(l), *p = buf + l;
int len = 0;
for (int i=0; alt_urls[i]; i++) {
MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_raw_buffer(&p, buf, (const
unsigned char *)alt_urls[i], strlen(alt_urls[i])));
MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&p, buf,
strlen(alt_urls[i])));
MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&p, buf,
MBEDTLS_ASN1_CONTEXT_SPECIFIC | 2));
}
MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&p, buf, len));
MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&p, buf,
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE));
if ((ret = mbedtls_x509write_csr_set_extension(&req,
MBEDTLS_OID_SUBJECT_ALT_NAME,
MBEDTLS_OID_SIZE(MBEDTLS_OID_SUBJECT_ALT_NAME),
(const unsigned char *)p, len)) != 0) {
char errbuf[80];
mbedtls_strerror(ret, errbuf, sizeof(errbuf));
ESP_LOGE(acme_tag, "%s: mbedtls_x509write_csr_set_extension failed %s
(0x%04x)", *__FUNCTION__*, errbuf, -ret);
}
free(buf);
ESP_LOGD(acme_tag, "%s: ret %d", *__FUNCTION*__, ret);
return ret;
}
--
Danny Backx - dannybackx(a)telenet.be - http://danny.backx.info
Hi David,
Archive can be found here
https://lists.trustedfirmware.org/pipermail/mbed-tls/https://lists.trustedfirmware.org/pipermail/psa-crypto/
Regards,
Shebu
-----Original Message-----
From: mbed-tls <mbed-tls-bounces(a)lists.trustedfirmware.org> On Behalf Of David Higton via mbed-tls
Sent: Friday, June 25, 2021 2:51 PM
To: mbed-tls(a)lists.trustedfirmware.org
Subject: [mbed-tls] List archive?
Hi everybody,
I've just joined the list. The first thing I did was to try to find an archive of list postings, but I haven't found one. Is there one, and, if so, where do I find it?
The information may have been staring me in the face; if that's the case, I apologise.
David
--
mbed-tls mailing list
mbed-tls(a)lists.trustedfirmware.org
https://lists.trustedfirmware.org/mailman/listinfo/mbed-tls
Hi everybody,
I've just joined the list. The first thing I did was to try to find an
archive of list postings, but I haven't found one. Is there one, and,
if so, where do I find it?
The information may have been staring me in the face; if that's the
case, I apologise.
David
Hi Anasasija,
Mbed TLS is entirely agnostic of the communication channel or protocol. You can configure it to use any underlying layer, like TCP, UDP or even just a local buffer.
That said, we have a module that makes it more convenient to use Mbed TLS with TCP (or UDP) on common platforms:
https://github.com/ARMmbed/mbedtls/blob/development/include/mbedtls/net_soc…
You can see an example for using the module in several sample applications, for example:
https://github.com/ARMmbed/mbedtls/blob/development/programs/ssl/ssl_client… and
https://github.com/ARMmbed/mbedtls/blob/development/programs/ssl/ssl_server…
Kind regards,
Janos
From: mbed-tls <mbed-tls-bounces(a)lists.trustedfirmware.org> on behalf of 1637062--- via mbed-tls <mbed-tls(a)lists.trustedfirmware.org>
Date: Friday, 25 June 2021 at 09:27
To: mbed-tls(a)lists.trustedfirmware.org <mbed-tls(a)lists.trustedfirmware.org>
Subject: [mbed-tls] Is TCP integrated in mbed-TLS?
Hello,
I am a Student and for my bachelor thesis I am working on a tool that
is able to detect whether a server is vulnerable regarding
Bleichenbacher's attack or not, testing multiple side channels.
For this I am looking for a TLS implementation that has the TCP
protocol integrated and generates the TCP messages.
I was wondering if mbed-tls has the TCP integrated in the
implementation or not.
If so, I could make use of this information, too.
Thanks and kind regards,
Anastasija
--
mbed-tls mailing list
mbed-tls(a)lists.trustedfirmware.org
https://lists.trustedfirmware.org/mailman/listinfo/mbed-tls
Hi Lijin,
It still can be the endianness of the keys. If the key is reversed, there won’t be any discernible pattern or relationship between the derived secrets.
Regards,
Janos
From: mbed-tls <mbed-tls-bounces(a)lists.trustedfirmware.org> on behalf of T V LIJIN (EXT) via mbed-tls <mbed-tls(a)lists.trustedfirmware.org>
Date: Friday, 25 June 2021 at 09:15
To: mbed-tls(a)lists.trustedfirmware.org <mbed-tls(a)lists.trustedfirmware.org>
Subject: Re: [mbed-tls] mbed-tls Digest, Vol 16, Issue 12
Hello,
We couldn't see word swap in the output from both the end. Issue doesn't look related to the endianness.
Could you please confirm that the code used for ECDHE key exchange is proper?
SHARED_SECRET (Computed on Client):
11 36 F7 DB 2B 14 BB 86
1C A0 FC DF 6D 4D 17 70
BE 4F D8 58 C2 11 67 10
42 D7 47 EB 14 4B 10 5E
SHARED_SECRET(Computed on Sever):
c6 96 d9 f0 ec 37 be 9e
1a 60 a4 5f 88 f2 13 d3
bb 98 15 3f 3b d9 81 37
c6 10 12 85 e5 8b 49 16
Thanks,
LIJIN T V
________________________________
From: mbed-tls <mbed-tls-bounces(a)lists.trustedfirmware.org> on behalf of mbed-tls-request(a)lists.trustedfirmware.org <mbed-tls-request(a)lists.trustedfirmware.org>
Sent: Friday, June 25, 2021 4:52 AM
To: mbed-tls(a)lists.trustedfirmware.org <mbed-tls(a)lists.trustedfirmware.org>
Subject: mbed-tls Digest, Vol 16, Issue 12
This message is from an external sender. Be cautious, especially with links and attachments.
Send mbed-tls mailing list submissions to
mbed-tls(a)lists.trustedfirmware.org
To subscribe or unsubscribe via the World Wide Web, visit
https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.tru…
or, via email, send a message with subject or body 'help' to
mbed-tls-request(a)lists.trustedfirmware.org
You can reach the person managing the list at
mbed-tls-owner(a)lists.trustedfirmware.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of mbed-tls digest..."
Today's Topics:
1. ECDHE Shared Secret is computed differently (T V LIJIN (EXT))
2. Re: ECDHE Shared Secret is computed differently (Brian D.)
3. How does the bignum.c works? (Shariful Alam)
----------------------------------------------------------------------
Message: 1
Date: Thu, 24 Jun 2021 13:35:03 +0000
From: "T V LIJIN (EXT)" <lijin.tv(a)kone.com>
To: "mbed-tls(a)lists.trustedfirmware.org"
<mbed-tls(a)lists.trustedfirmware.org>
Subject: [mbed-tls] ECDHE Shared Secret is computed differently
Message-ID:
<AS8PR07MB8006A77D2451AD93FAFDA3D8FE079(a)AS8PR07MB8006.eurprd07.prod.outlook.com>
Content-Type: text/plain; charset="iso-8859-1"
Hello ,
We are trying to perform an ECDHE key exchange between two devices running on different platforms.[one on Linux and another on RTOS]
Both the devices use the same code to compute the ECDHE shared secret. The peer public parameters are exchanged in the base64 format and passed to the functions correctly , but the final shared secret computed seems to be different on both ends.
We have tested the same source code on Visual studio and found working.
I have attached the source files
Could you please comment on why the computed shared secret are different on both the ends?
Thanks,
LIJIN T V
Hello,
I am a Student and for my bachelor thesis I am working on a tool that
is able to detect whether a server is vulnerable regarding
Bleichenbacher's attack or not, testing multiple side channels.
For this I am looking for a TLS implementation that has the TCP
protocol integrated and generates the TCP messages.
I was wondering if mbed-tls has the TCP integrated in the
implementation or not.
If so, I could make use of this information, too.
Thanks and kind regards,
Anastasija
Hello,
We couldn't see word swap in the output from both the end. Issue doesn't look related to the endianness.
Could you please confirm that the code used for ECDHE key exchange is proper?
SHARED_SECRET (Computed on Client):
11 36 F7 DB 2B 14 BB 86
1C A0 FC DF 6D 4D 17 70
BE 4F D8 58 C2 11 67 10
42 D7 47 EB 14 4B 10 5E
SHARED_SECRET(Computed on Sever):
c6 96 d9 f0 ec 37 be 9e
1a 60 a4 5f 88 f2 13 d3
bb 98 15 3f 3b d9 81 37
c6 10 12 85 e5 8b 49 16
Thanks,
LIJIN T V
________________________________
From: mbed-tls <mbed-tls-bounces(a)lists.trustedfirmware.org> on behalf of mbed-tls-request(a)lists.trustedfirmware.org <mbed-tls-request(a)lists.trustedfirmware.org>
Sent: Friday, June 25, 2021 4:52 AM
To: mbed-tls(a)lists.trustedfirmware.org <mbed-tls(a)lists.trustedfirmware.org>
Subject: mbed-tls Digest, Vol 16, Issue 12
This message is from an external sender. Be cautious, especially with links and attachments.
Send mbed-tls mailing list submissions to
mbed-tls(a)lists.trustedfirmware.org
To subscribe or unsubscribe via the World Wide Web, visit
https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.tru…
or, via email, send a message with subject or body 'help' to
mbed-tls-request(a)lists.trustedfirmware.org
You can reach the person managing the list at
mbed-tls-owner(a)lists.trustedfirmware.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of mbed-tls digest..."
Today's Topics:
1. ECDHE Shared Secret is computed differently (T V LIJIN (EXT))
2. Re: ECDHE Shared Secret is computed differently (Brian D.)
3. How does the bignum.c works? (Shariful Alam)
----------------------------------------------------------------------
Message: 1
Date: Thu, 24 Jun 2021 13:35:03 +0000
From: "T V LIJIN (EXT)" <lijin.tv(a)kone.com>
To: "mbed-tls(a)lists.trustedfirmware.org"
<mbed-tls(a)lists.trustedfirmware.org>
Subject: [mbed-tls] ECDHE Shared Secret is computed differently
Message-ID:
<AS8PR07MB8006A77D2451AD93FAFDA3D8FE079(a)AS8PR07MB8006.eurprd07.prod.outlook.com>
Content-Type: text/plain; charset="iso-8859-1"
Hello ,
We are trying to perform an ECDHE key exchange between two devices running on different platforms.[one on Linux and another on RTOS]
Both the devices use the same code to compute the ECDHE shared secret. The peer public parameters are exchanged in the base64 format and passed to the functions correctly , but the final shared secret computed seems to be different on both ends.
We have tested the same source code on Visual studio and found working.
I have attached the source files
Could you please comment on why the computed shared secret are different on both the ends?
Thanks,
LIJIN T V
Hello,
Can someone please briefly explain how does the bignum.c library works in
terms of RSA? I understand that this is too broad a question to ask. but If
someone can briefly explain the basic working mechanism it will be a great
help.
Thanks,
Shariful
Hi Linjin,
I am not part of the mbed-tls staff but I developed a lot with mbed library and I had your same problem. Try to check the byte order, I had issues when computing the shared secret because I had the little endian from the other side but mbed uses big endian.
Try to do a quick test and this could resolve your problem, let me know!
Bye,
Brian
24 giu 2021, 15:35 da mbed-tls(a)lists.trustedfirmware.org:
> Hello ,
> We are trying to perform an ECDHE key exchange between two devices running on different platforms.[one on Linux and another on RTOS]
> Both the devices use the same code to compute the ECDHE shared secret. The peer public parameters are exchanged in the base64 format and passed to the functions correctly , but the final shared secret computed seems to be different on both ends.
> We have tested the same source code on Visual studio and found working.
> I have attached the source files
>
> Could you please comment on why the computed shared secret are different on both the ends?
>
> Thanks,
> LIJIN T V
>
Hello ,
We are trying to perform an ECDHE key exchange between two devices running on different platforms.[one on Linux and another on RTOS]
Both the devices use the same code to compute the ECDHE shared secret. The peer public parameters are exchanged in the base64 format and passed to the functions correctly , but the final shared secret computed seems to be different on both ends.
We have tested the same source code on Visual studio and found working.
I have attached the source files
Could you please comment on why the computed shared secret are different on both the ends?
Thanks,
LIJIN T V
Hi Andrey,
Thank you for your interest in Mbed TLS! In general we welcome
contributions to the project. Unfortunately, our limiting factor is
bandwidth for review. In 2021 the Mbed TLS team has grown, so we have
more time for reviews, but we are still struggling to catch up with the
large backlog.
There is already an old attempt to add unencrypted PKCS#8 writing
support (https://github.com/ARMmbed/mbedtls/issues/1695
<https://github.com/ARMmbed/mbedtls/issues/1695>). There is a long
pending request for encrypted PKCS#8 writing support
(https://github.com/ARMmbed/mbedtls/issues/1372
<https://github.com/ARMmbed/mbedtls/issues/1372>) but I'm not aware of
any prior implementation.
We would be glad to have your contribution, but I must be honest and say
it might take us several months to get around to it.
Best regards,
--
Gilles Peskine
Mbed TLS developer
On 09/06/2021 22:46, Андрей Макаров via mbed-tls wrote:
> Recently I used mbedtls library in my working project. In accordance
> with the needs of the project, I added some functions to mbedtls for
> saving and loading keys in plain and encrypted pem and der forms.
> The changes are still raw and should be brought up to pull request
> requirements - there are no tests, since the functions tested as part
> of a working project which uses mbedtls. I can, over time, finalize
> the changes to a pull request, but it will take some time and effort
> that you don't want to waste unnecessarily — this will have to be done
> at my home time.
> If there is an interest for this work, then I will try to do it, but
> if few people need it or do not coincide with the general direction of
> development of the project, then I would not bother.
> To be done: 1) added mbedtls_pk_write_key_pkcs8_der() write
> non-encrypted pkcs8 der key 2) added mbedtls_pk_write_key_pkcs8_pem()
> write non-encrypted pkcs8 pem key 3) added
> mbedtls_pk_write_key_encrypted_pem() write legacy encryped pem file
> with DEK-Info header 4) added
> mbedtls_pk_write_key_pkcs8_encrypted_der() write to encrypted pkcs8
> der key; pkcs5 pbes1, pkcs12 and pbes2 schemes are supported 5) added
> mbedtls_pk_write_key_pkcs8_encrypted_pem() same as above but pem key
> 6) changed mbedtls_pem_read_buffer() which reads legacy encrypted pem
> formats (with DEK-Info header) now it uses mbedtls_cipher_… functions
> which allow to use any supported cipher rather than four enforced (was
> limited to des-cbc, des-ede3-cbc, ars-128-cbc and aes-256-cbc) 7)
> changed pk_parse_key_pkcs8_encrypted_der() 7.1) added pkcs5 pbes1
> support MD5-DES-CB CpbeWithMD5AndDES-CBC) and SHA1-DES-CBC
> (pbeWithSHA1AndDES-CBC) 7.2) changed pkcs12 pbe (use same cipher for
> all SHA1-DES2-EDE-CBC (pbeWithSHAAnd2-KeyTripleDES-CBC),
> SHA1-DES3-EDE-CBC (pbeWithSHAAnd3-KeyTripleDES-CBC) and SHA1-RC4-128
> (pbeWithSHA1And128BitRC4); (the special
> mbedtls_pkcs12_pbe_sha1_rc4_128() is not used now and may be removed)
> 7.3) changed pkcs5 pbes2 support: added AES-128-CBC and AES-256-CBC
> ciphers Some «preview» is available at fork
> https://github.com/loafer-mka/mbedtls
> <https://github.com/loafer-mka/mbedtls>, branch ‘dev_clean’ Of course,
> many changes relate to obsolete formats, and may be undesirable … also
> I do not touch PSK at all.
> Please, give me some feedback — try to finish this with tests, pull
> request, etc or not. ----------- Regards, Andrey
>
Just finishing off this thread:
The issue appeared due to an invalid pointer access else where in the
application that coincided with the mbedtls_ssl_set_bio function.
Working on resolution now.
Thanks for all the help, pointers & hints from the list!
On 2021-06-08 2:27 p.m., Ron Eggler via mbed-tls wrote:
>
> Yes, there's some kind of "memory magic" going on here:
>
> The task got terminated due to "Load from invalid memory"
>
> and I see:
>
> |Instruction at 0x6310604d is trying to load data at 0x4, which is an
> invalid memory area. You are probably dereferencing a NULL pointer.|
>
> |and i got some trace back addresses that point to:|
>
> *
>
> mbedtls_aes_crypt_ecb
>
> *
>
> mbedtls_ctr_drbg_random_with_add
>
> *
>
> mbedtls_ssl_handshake_step
>
> *
>
> mbedtls_ssl_handshake
>
>
> ||
>
> On 2021-06-08 11:43 a.m., Gilles Peskine via mbed-tls wrote:
>> Hi Ron,
>>
>> This behavior can't be explained by the library code and the code you
>> posted alone. There has to be something wrong elsewhere.
>>
>> Check that you aren't exceeding a limitation such as the stack size or
>> the size of executable and data sections. If it can be an issue on your
>> platform, check that load addresses are correct and sections don't
>> overlap. Make sure there's no overlap with any device memory mapping either.
>>
>> Make sure that the whole binary is compiled with consistent settings.
>> The layout of mbedtls_ssl_context can be influenced by the Mbed TLS
>> configuration, so make sure that there's a single copy of
>> mbedtls/config.h and both Mbed TLS itself and your application were
>> built against that copy. The layout of mbedtls_ssl_context can also be
>> influenced by compiler settings on some platforms (e.g. structure
>> packing options), so make sure those are consistent across your build.
>>
>> That's all I can think of for now. It may help to add a lot of printf
>> debugging with %p on various addresses, and compare these addresses with
>> what you know about memory mappings on that platform. Good luck!
>>
>
Recently I used mbedtls library in my working project.
In accordance with the needs of the project, I added some functions to mbedtls
for saving and loading keys in plain and encrypted pem and der forms.
The changes are still raw and should be brought up to pull request requirements - there
are no tests, since the functions tested as part of a working project which uses mbedtls.
I can, over time, finalize the changes to a pull request, but it will take some time and
effort that you don't want to waste unnecessarily — this will have to be done at my home time.
If there is an interest for this work, then I will try to do it, but if few people need
it or do not coincide with the general direction of development of the project, then I
would not bother.
To be done:
1) added mbedtls_pk_write_key_pkcs8_der()
write non-encrypted pkcs8 der key
2) added mbedtls_pk_write_key_pkcs8_pem()
write non-encrypted pkcs8 pem key
3) added mbedtls_pk_write_key_encrypted_pem()
write legacy encryped pem file with DEK-Info header
4) added mbedtls_pk_write_key_pkcs8_encrypted_der()
write to encrypted pkcs8 der key; pkcs5 pbes1, pkcs12 and pbes2 schemes are supported
5) added mbedtls_pk_write_key_pkcs8_encrypted_pem()
same as above but pem key
6) changed mbedtls_pem_read_buffer()
which reads legacy encrypted pem formats (with DEK-Info header)
now it uses mbedtls_cipher_… functions which allow to use any supported cipher rather than four
enforced (was limited to des-cbc, des-ede3-cbc, ars-128-cbc and aes-256-cbc)
7) changed pk_parse_key_pkcs8_encrypted_der()
7.1) added pkcs5 pbes1 support MD5-DES-CB CpbeWithMD5AndDES-CBC) and SHA1-DES-CBC (pbeWithSHA1AndDES-CBC)
7.2) changed pkcs12 pbe (use same cipher for all SHA1-DES2-EDE-CBC (pbeWithSHAAnd2-KeyTripleDES-CBC),
SHA1-DES3-EDE-CBC (pbeWithSHAAnd3-KeyTripleDES-CBC) and SHA1-RC4-128 (pbeWithSHA1And128BitRC4);
(the special mbedtls_pkcs12_pbe_sha1_rc4_128() is not used now and may be removed)
7.3) changed pkcs5 pbes2 support: added AES-128-CBC and AES-256-CBC ciphers
Some «preview» is available at fork https://github.com/loafer-mka/mbedtls, branch ‘dev_clean’
Of course, many changes relate to obsolete formats, and may be undesirable … also I do not touch PSK at all.
Please, give me some feedback — try to finish this with tests, pull request, etc or not.
-----------
Regards,
Andrey
Dear All,
I am having multiple queries regarding session resumption and renegotiation.
I understand that normally session resumption is used at every new
connection and session renegotiation is used on live connection.
Our domain standards recommends to use session resumption to change session
key ( or keyblock
key_block = PRF(SecurityParameters.master_secret,
"key expansion",
SecurityParameters.server_random +
SecurityParameters.client_random);
) at regular intervals without closing connection and session renegotiation
to change master key at regular interval using session renegotiation. This
is due to the fact that the connection will be long lasting.
Query 1:
I understand that mbedtls currently does not support session resumption on
live connection. Is there any plan to include it in the near future? ( may
be similar to openssl SSL_renegotiate_abbreviated api)
Query 3:
If the application wants to know if session renegotiation has happened as
part of mbedtls_tls_read and mbedtls_tls_write, is there any callback/API
for that?
--> I am only thinking of using session->start comparison in application to
know if session is renegotiated. Is there any better method?
Query 4:
Our requirement is to understand and log security event in case failure due
to certificate verification fail (revoked/expired etc..) currently we use
mbedtls_ssl_get_verify_result api for same
There is a case when certificate becomes expired/revoked while doing
session renegotiation, mbedtls_ssl_get_verify_result api returns value 0 in
above case
I am thinking in case of session renegotiation, a valid session will always
be available (it will not be NULL in the method below) and session
renegotiation failure information will be available with session_negotiate
pointer instead of session pointer in the below function.
uint32_t mbedtls_ssl_get_verify_result( const mbedtls_ssl_context *ssl )
{
if( ssl->session != NULL )
return( ssl->session->verify_result );
if( ssl->session_negotiate != NULL )
return( ssl->session_negotiate->verify_result );
return( 0xFFFFFFFF );
}
Am I using the right API to get certificate verify_result?
should mbedtls_ssl_get_verify_result api checks give priority to
session_negotiate then session? I think when there is a failure, the result
will always be with session_negotiate, when success session_negotiate
becomes NULL and session_negotiate pointers will be assigned to session
pointers.
uint32_t mbedtls_ssl_get_verify_result( const mbedtls_ssl_context *ssl )
{
if( ssl->session_negotiate != NULL )
return( ssl->session_negotiate->verify_result );
if( ssl->session != NULL )
return( ssl->session->verify_result );
return( 0xFFFFFFFF );
}
Kind request to guide me
Thanks in advance
Regards
Hardik Dave
Yes, there's some kind of "memory magic" going on here:
The task got terminated due to "Load from invalid memory"
and I see:
|Instruction at 0x6310604d is trying to load data at 0x4, which is an
invalid memory area. You are probably dereferencing a NULL pointer.|
|and i got some trace back addresses that point to:|
*
mbedtls_aes_crypt_ecb
*
mbedtls_ctr_drbg_random_with_add
*
mbedtls_ssl_handshake_step
*
mbedtls_ssl_handshake
||
On 2021-06-08 11:43 a.m., Gilles Peskine via mbed-tls wrote:
> Hi Ron,
>
> This behavior can't be explained by the library code and the code you
> posted alone. There has to be something wrong elsewhere.
>
> Check that you aren't exceeding a limitation such as the stack size or
> the size of executable and data sections. If it can be an issue on your
> platform, check that load addresses are correct and sections don't
> overlap. Make sure there's no overlap with any device memory mapping either.
>
> Make sure that the whole binary is compiled with consistent settings.
> The layout of mbedtls_ssl_context can be influenced by the Mbed TLS
> configuration, so make sure that there's a single copy of
> mbedtls/config.h and both Mbed TLS itself and your application were
> built against that copy. The layout of mbedtls_ssl_context can also be
> influenced by compiler settings on some platforms (e.g. structure
> packing options), so make sure those are consistent across your build.
>
> That's all I can think of for now. It may help to add a lot of printf
> debugging with %p on various addresses, and compare these addresses with
> what you know about memory mappings on that platform. Good luck!
>
Hi Ron,
This behavior can't be explained by the library code and the code you
posted alone. There has to be something wrong elsewhere.
Check that you aren't exceeding a limitation such as the stack size or
the size of executable and data sections. If it can be an issue on your
platform, check that load addresses are correct and sections don't
overlap. Make sure there's no overlap with any device memory mapping either.
Make sure that the whole binary is compiled with consistent settings.
The layout of mbedtls_ssl_context can be influenced by the Mbed TLS
configuration, so make sure that there's a single copy of
mbedtls/config.h and both Mbed TLS itself and your application were
built against that copy. The layout of mbedtls_ssl_context can also be
influenced by compiler settings on some platforms (e.g. structure
packing options), so make sure those are consistent across your build.
That's all I can think of for now. It may help to add a lot of printf
debugging with %p on various addresses, and compare these addresses with
what you know about memory mappings on that platform. Good luck!
--
Gilles Peskine
Mbed TLS developer
On 08/06/2021 19:16, Ron Eggler via mbed-tls wrote:
>
> On 2021-06-08 7:40 a.m., Ron Eggler via mbed-tls wrote:
>> On 2021-06-08 12:28 a.m., Gilles Peskine via mbed-tls wrote:
>>> Hi Ron,
>>>
>>> The code you've shown so far only consists of setup functions that
>>> populate fields in the configuration structure, then in the context
>>> structure. Communication has not started yet. mbedtls_ssl_set_bio in
>>> particular is a very simple setter function.
>>>
>>> Where does the code actually hang? Have some messages already been
>>> exchanged on the network at that point? Can you get a stack trace?
>>>
>>> Best regards,
>>>
>> Hi Gilles,
>>
>> Thank you for the response!
>>
>> I've inserted print statements after each of the setup functions and
>> can see that it never gets past mbedtls_ssl_set_bio. The messages
>> that have been exchanged, include the complete bring up and login of
>> the control channel, on the data channel, I call
>> mbedtls_x509_crt_init
>> mbedtls_pk_init
>> mbedtls_entropy_init
>> mbedtls_ctr_drbg_init
>> mbedtls_ssl_init
>> mbedtls_ssl_config_init
>> followed by the certificate and key file got parsing, seeding of the
>> RNG and that's where the previously mentioned procedure with
>> mbedtls_ssl_config_defaults() starts.
>> I unfortunately do not have a debugger available on that platform and
>> hence getting a stack trace won't be so straight forward. Do you have
>> any pointers as to what could be the issue potentially?
>>
>> Thank you,
>>
>> Ron
>
> Okay, I've made some further findings:
>
> I changed the mbedtls_ssl_set_bio funmction so that I inserted a print
> statement on entry and after every set line, like so:
>
> void mbedtls_ssl_set_bio( mbedtls_ssl_context *ssl,
> void *p_bio,
> mbedtls_ssl_send_t *f_send,
> mbedtls_ssl_recv_t *f_recv,
> mbedtls_ssl_recv_timeout_t *f_recv_timeout )
> {
> iprintf("mbedtls_ssl_set_bio::entry\n");
> ssl->p_bio = p_bio;
> iprintf("mbedtls_ssl_set_bio::p_bio set\n");
> ssl->f_send = f_send;
> iprintf("mbedtls_ssl_set_bio::f_send set\n");
> ssl->f_recv = f_recv;
> iprintf("mbedtls_ssl_set_bio::f_recv set\n");
> ssl->f_recv_timeout = f_recv_timeout;
> iprintf("mbedtls_ssl_set_bio::f_recv_timeout set\n");
> }
>
> and turns out, that I only see the very first print on
> "mbedtls_ssl_set_bio::entry\n" and nothing there after, which leads me
> to the believe that my *ssl is invalid which is odd as that variable
> is also used for ret = mbedtls_ssl_setup( &ssl_d, &conf_d ); and it is
> initialized at the beginning of the function with mbedtls_ssl_init(
> &ssl_d );
>
>
On 2021-06-08 7:40 a.m., Ron Eggler via mbed-tls wrote:
> On 2021-06-08 12:28 a.m., Gilles Peskine via mbed-tls wrote:
>> Hi Ron,
>>
>> The code you've shown so far only consists of setup functions that
>> populate fields in the configuration structure, then in the context
>> structure. Communication has not started yet. mbedtls_ssl_set_bio in
>> particular is a very simple setter function.
>>
>> Where does the code actually hang? Have some messages already been
>> exchanged on the network at that point? Can you get a stack trace?
>>
>> Best regards,
>>
> Hi Gilles,
>
> Thank you for the response!
>
> I've inserted print statements after each of the setup functions and
> can see that it never gets past mbedtls_ssl_set_bio. The messages that
> have been exchanged, include the complete bring up and login of the
> control channel, on the data channel, I call
> mbedtls_x509_crt_init
> mbedtls_pk_init
> mbedtls_entropy_init
> mbedtls_ctr_drbg_init
> mbedtls_ssl_init
> mbedtls_ssl_config_init
> followed by the certificate and key file got parsing, seeding of the
> RNG and that's where the previously mentioned procedure with
> mbedtls_ssl_config_defaults() starts.
> I unfortunately do not have a debugger available on that platform and
> hence getting a stack trace won't be so straight forward. Do you have
> any pointers as to what could be the issue potentially?
>
> Thank you,
>
> Ron
Okay, I've made some further findings:
I changed the mbedtls_ssl_set_bio funmction so that I inserted a print
statement on entry and after every set line, like so:
void mbedtls_ssl_set_bio( mbedtls_ssl_context *ssl,
void *p_bio,
mbedtls_ssl_send_t *f_send,
mbedtls_ssl_recv_t *f_recv,
mbedtls_ssl_recv_timeout_t *f_recv_timeout )
{
iprintf("mbedtls_ssl_set_bio::entry\n");
ssl->p_bio = p_bio;
iprintf("mbedtls_ssl_set_bio::p_bio set\n");
ssl->f_send = f_send;
iprintf("mbedtls_ssl_set_bio::f_send set\n");
ssl->f_recv = f_recv;
iprintf("mbedtls_ssl_set_bio::f_recv set\n");
ssl->f_recv_timeout = f_recv_timeout;
iprintf("mbedtls_ssl_set_bio::f_recv_timeout set\n");
}
and turns out, that I only see the very first print on
"mbedtls_ssl_set_bio::entry\n" and nothing there after, which leads me
to the believe that my *ssl is invalid which is odd as that variable is
also used for ret = mbedtls_ssl_setup( &ssl_d, &conf_d ); and it is
initialized at the beginning of the function with mbedtls_ssl_init(
&ssl_d );
On 2021-06-08 12:28 a.m., Gilles Peskine via mbed-tls wrote:
> Hi Ron,
>
> The code you've shown so far only consists of setup functions that
> populate fields in the configuration structure, then in the context
> structure. Communication has not started yet. mbedtls_ssl_set_bio in
> particular is a very simple setter function.
>
> Where does the code actually hang? Have some messages already been
> exchanged on the network at that point? Can you get a stack trace?
>
> Best regards,
>
Hi Gilles,
Thank you for the response!
I've inserted print statements after each of the setup functions and can
see that it never gets past mbedtls_ssl_set_bio. The messages that have
been exchanged, include the complete bring up and login of the control
channel, on the data channel, I call
mbedtls_x509_crt_init
mbedtls_pk_init
mbedtls_entropy_init
mbedtls_ctr_drbg_init
mbedtls_ssl_init
mbedtls_ssl_config_init
followed by the certificate and key file got parsing, seeding of the RNG
and that's where the previously mentioned procedure with
mbedtls_ssl_config_defaults() starts.
I unfortunately do not have a debugger available on that platform and
hence getting a stack trace won't be so straight forward. Do you have
any pointers as to what could be the issue potentially?
Thank you,
Ron