Hello,
I found that, /programs/pkeyrsa_genkey.c creates a plaintext rsa private
key. Is there any way I can generate the keys in the same format from a
.pem format?
Regards,
Shariful Alam
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.
>
>