<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>MBEDTLS taking too long</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/101173/mbedtls-taking-too-long</link><description>When trying to establish a TLS connection with an endpoint, two methods are taking extraordinarily long to complete: mbedtls_dhm_make_public() takes ~7 seconds to complete mbedtls_dhm_calc_secret() takes ~7 seconds to complete as well. 
 Together, this</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 04 Jul 2023 21:19:52 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/101173/mbedtls-taking-too-long" /><item><title>RE: MBEDTLS taking too long</title><link>https://devzone.nordicsemi.com/thread/434555?ContentTypeID=1</link><pubDate>Tue, 04 Jul 2023 21:19:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b55accc9-0397-45a6-af7f-0456f542e84d</guid><dc:creator>scath</dc:creator><description>&lt;p&gt;Solved. You were absolutely correct, though getting your solution working was frustrating for me and my staff.&lt;br /&gt;&lt;br /&gt;The guiconfig and documentation do terrible jobs of describing what prereqs need to be selected, and where.&lt;br /&gt;&lt;br /&gt;Specifically:&lt;br /&gt;&lt;br /&gt;1) The Custom mbed TLS configuration file &amp;quot;config-tls-generic.h&amp;quot; does not need further configuration from the engineer. This is not immediately apparent at first blush. This feature could be far better documented, and the file renamed to something akin to &amp;quot;config-tls-defaults.h&amp;quot;.&lt;br /&gt;&lt;br /&gt;2) When selecting ECDHE, it is necessary to choose which elliptic curves will be included in the build. This is not apparent from the documentation at all. Worse, no curves are selected by default, and no warning is given that no curves are selected.&lt;br /&gt;&lt;br /&gt;This causes a handshaking error for no apparent reason and where none should be occurring, prima facia.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;That said, it is still completely inappropriate for the build process to overwrite a configuration silently. This behavior isn&amp;#39;t documented anywhere I&amp;#39;ve seen, and&amp;nbsp;has caused numerous headaches for my staff.&lt;br /&gt;&lt;br /&gt;While I understand this point is outside the scope of this ticket, we would all benefit from someone bringing this to the correct party&amp;#39;s attention at Nordic.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;With thanks for your kindness and patience.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MBEDTLS taking too long</title><link>https://devzone.nordicsemi.com/thread/434549?ContentTypeID=1</link><pubDate>Tue, 04 Jul 2023 19:57:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:21305b8d-283c-41cb-ba96-716038159ae6</guid><dc:creator>scath</dc:creator><description>&lt;p&gt;Attempting to do this, but my choices inside the guiconfig (provided by the nRF Connect VSCode Plugin) are continually and consistently overwritten at some other part of the build process, silently reverting to defaults that do not work. &lt;br /&gt;&lt;br /&gt;When I keep the guiconfig tool open and attempt to build or flash I get the following:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;ninja: error: opening build log: Permission denied
FATAL ERROR: command exited with status 1: &amp;#39;c:\nordic\toolchains\31f4403e35\opt\bin\cmake.EXE&amp;#39; --build &amp;#39;d:\zephyr\samples\net\sockets\test_app\build&amp;#39;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If I then close and reopen guiconfig, I find that all of my configuration choices have reverted to said defaults - without warning!&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;This is&amp;nbsp;ridiculous, to&amp;nbsp;put it mildly.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;None of this is your fault, but I can&amp;#39;t even begin to use your proposed solution as it stands.&lt;br /&gt;&lt;br /&gt;Can you point me to some guidance on&amp;nbsp;&lt;/p&gt;
&lt;p&gt;a) How to prevent the .config file generated by the guiconfig tool inside nRF Connect from being overwritten.&lt;br /&gt;&lt;br /&gt;b) Configuring MBEDTLS options inside prj.conf, as opposed to using the guiconfig tool.&lt;br /&gt;&lt;br /&gt;Many thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MBEDTLS taking too long</title><link>https://devzone.nordicsemi.com/thread/433787?ContentTypeID=1</link><pubDate>Thu, 29 Jun 2023 20:06:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0061d0d4-be7e-4785-9b38-8c162994d72e</guid><dc:creator>Emil Lenngren</dc:creator><description>&lt;p&gt;This is just an educated guess but I assume the long computation time is due to the DHE cipher suite being used. I see that you have `CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED=y` so try disable that, and in general make sure all DH_* and DHE_* cipher suites are disabled.&lt;/p&gt;
&lt;p&gt;Diffie-Hellman ephemeral is &amp;quot;deprecated&amp;quot; nowadays; you should use the much faster ECDHE instead. DHE is very slow and especially on low-end hardware such as nRF52 and particularly if it is a non-optimized software implementation written in C.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MBEDTLS taking too long</title><link>https://devzone.nordicsemi.com/thread/433750?ContentTypeID=1</link><pubDate>Thu, 29 Jun 2023 15:19:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:06e9e672-72d2-4295-bd02-fa8387503d92</guid><dc:creator>scath</dc:creator><description>&lt;p&gt;Hi there,&lt;br /&gt;&lt;br /&gt;We aren&amp;#39;t using the Nordic Security Module. Can enable it if you think this will help.&lt;br /&gt;&lt;br /&gt;proj.conf&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_MAIN_STACK_SIZE=65536
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y

# JSON
CONFIG_JSON_LIBRARY=y
CONFIG_CJSON_LIB=y

# Watchdog
CONFIG_WATCHDOG=y
CONFIG_WDT_LOG_LEVEL_DBG=y
CONFIG_WDT_DISABLE_AT_BOOT=n

# Networking config
CONFIG_NETWORKING=y
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=n
CONFIG_NET_TCP=y
CONFIG_NET_UDP=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_NET_LOG=y

# Sockets
CONFIG_NET_SOCKETS_POLL_MAX=4

# Modem
CONFIG_MODEM=y
CONFIG_MODEM_HL7800=y
CONFIG_MODEM_HL7800_BOOT_DELAY=y
CONFIG_MODEM_LOG_LEVEL_INF=n
CONFIG_MODEM_LOG_LEVEL_DBG=n
CONFIG_MODEM_LOG_LEVEL_WRN=n
CONFIG_MODEM_LOG_LEVEL_ERR=y


# Sockets
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
CONFIG_NET_MGMT=y
CONFIG_NET_MGMT_EVENT=y


# HTTP
CONFIG_HTTP_CLIENT=y
CONFIG_DNS_RESOLVER=y

# Network debug config
CONFIG_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_NET_LOG=y
CONFIG_NET_SOCKETS_LOG_LEVEL_DBG=n
CONFIG_NET_HTTP_LOG_LEVEL_DBG=n
CONFIG_NET_HTTP_LOG_LEVEL_INF=n

CONFIG_HWINFO=y

# BLE
CONFIG_BT=y
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_CENTRAL=y
CONFIG_BT_SMP=y
CONFIG_BT_GATT_CLIENT=y

CONFIG_BT_SCAN=y
CONFIG_BT_SCAN_FILTER_ENABLE=y
CONFIG_BT_SCAN_UUID_CNT=0
CONFIG_BT_SCAN_NAME_CNT=1
CONFIG_BT_GATT_DM=y

# TLS
CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_BUILTIN=y

CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_APP_LINK_WITH_MBEDTLS=y
CONFIG_MBEDTLS_HEAP_SIZE=30000
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=4096

CONFIG_NET_SOCKETS_TLS_MAX_CONTEXTS=6

# ciphers - this is necessary because some part of NCS/Zephyr has a tendancy to overwrite 
#           our configs silently, causing builds to break for no apparent reason.
#           Very strange.
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED=y
CONFIG_MBEDTLS_CIPHER_AES_ENABLED=y
CONFIG_MBEDTLS_AES_ROM_TABLES=y
CONFIG_MBEDTLS_CIPHER_GCM_ENABLED=y
CONFIG_MBEDTLS_CIPHER_MODE_CBC_ENABLED=y

# SHA hash
CONFIG_MBEDTLS_HASH_SHA256_ENABLED=y
CONFIG_MBEDTLS_HASH_SHA384_ENABLED=y
CONFIG_MBEDTLS_HASH_SHA512_ENABLED=y

# MD5 &amp;amp; MAC
CONFIG_MBEDTLS_MAC_MD5_ENABLED=y
CONFIG_MBEDTLS_MAC_SHA1_ENABLED=y
CONFIG_MBEDTLS_MAC_SHA256_ENABLED=y
CONFIG_MBEDTLS_SHA256_SMALLER=y
CONFIG_MBEDTLS_MAC_SHA384_ENABLED=y
CONFIG_MBEDTLS_MAC_SHA512_ENABLED=y

# Random number generators
CONFIG_MBEDTLS_CTR_DRBG_ENABLED=y


# Other TLS
CONFIG_MBEDTLS_CIPHER=y
CONFIG_MBEDTLS_MD=y

#TLS DEBUG
CONFIG_MBEDTLS_DEBUG=y
CONFIG_MBEDTLS_DEBUG_LEVEL=3
CONFIG_MBEDTLS_LOG_LEVEL_INF=n
CONFIG_MBEDTLS_LOG_LEVEL_WRN=n
CONFIG_MBEDTLS_LOG_LEVEL_ERR=y
CONFIG_MBEDTLS_LOG_LEVEL_DBG=n&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Socket Creation/Config&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int create_socket(struct addrinfo *res){
	int sock = -1;
	
	while ( sock &amp;lt; 0 ){
		if (IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS)) {
			LOG_WRN(&amp;quot;** CREATING SECURE SOCKET **&amp;quot;);
			sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TLS_1_2);
		}
		else
			sock = socket(res-&amp;gt;ai_family, res-&amp;gt;ai_socktype, res-&amp;gt;ai_protocol);
    ...
    
    int result = tls_setup_http(sock);
	LOG_INF(&amp;quot;tls_setup_http returned %d&amp;quot;, result);
	if (result &amp;lt; 0 ){
		LOG_ERR(&amp;quot;ERROR creating Secure Socket: %d&amp;quot;, errno);
	}
}


int tls_setup_http(int sock)
{

    int err = 0;
    int verify = TLS_PEER_VERIFY_REQUIRED;
    
	LOG_INF(&amp;quot;Setting Secure Socket Options&amp;quot;);

    const sec_tag_t tls_sec_tag[] = {
        CA_CERTIFICATE_TAG,
    };

	tls_credential_add(CA_CERTIFICATE_TAG, TLS_CREDENTIAL_CA_CERTIFICATE,
			   ca_certificate, sizeof(ca_certificate));

  
    err = setsockopt(sock, SOL_TLS, TLS_PEER_VERIFY, &amp;amp;verify, sizeof(verify));
    if (err)
    {
        LOG_ERR(&amp;quot;Failed to setup peer verification, err %d\n&amp;quot;, errno);
        return err;
    }

    err = setsockopt(sock, SOL_TLS, TLS_SEC_TAG_LIST, tls_sec_tag,
             sizeof(tls_sec_tag));
    if (err)
    {
        LOG_ERR(&amp;quot;Failed to setup TLS sec tag, err %d\n&amp;quot;, errno);
        return err;
    }
	
	LOG_INF(&amp;quot;Setting HOST NAME and PORT for TLS&amp;quot;);
    err = setsockopt(sock, SOL_TLS, TLS_HOSTNAME, HTTP_HOST, sizeof(HTTP_HOST));
    if (err)
    {
        LOG_ERR(&amp;quot;Failed to setup TLS_HOSTNAME, err %d\n&amp;quot;, errno);
        return err;
    }
	

	LOG_INF(&amp;quot;Socket=%d with Security Tag Id %d is ready\n&amp;quot;,  sock, CA_CERTIFICATE_TAG);    

    return 0;
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Cheers,&lt;br /&gt;&lt;br /&gt;S.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MBEDTLS taking too long</title><link>https://devzone.nordicsemi.com/thread/433612?ContentTypeID=1</link><pubDate>Thu, 29 Jun 2023 07:54:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f5e9648-b1dd-48ac-af8a-f75ef7077e7d</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hi, thanks for clarifying how the product works.&lt;/p&gt;
&lt;p&gt;Could you provide the prj.conf of your project and where you configure the TLS? Are you using the Nordic Security module, which can be&lt;span&gt;&amp;nbsp;enabled with either&amp;nbsp;&lt;/span&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.1.0/nrfxlib/nrf_security/doc/configuration.html#psa-driver-support"&gt;PSA driver support&lt;/a&gt;&lt;span&gt;&amp;nbsp;or with&amp;nbsp;&lt;/span&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.1.0/nrfxlib/nrf_security/doc/configuration.html#id1"&gt;Legacy crypto support&lt;/a&gt;?&lt;/p&gt;
&lt;p&gt;Thanks&lt;br /&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MBEDTLS taking too long</title><link>https://devzone.nordicsemi.com/thread/433519?ContentTypeID=1</link><pubDate>Wed, 28 Jun 2023 16:30:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ec514871-a869-42e3-b397-7afa356b0407</guid><dc:creator>scath</dc:creator><description>&lt;p&gt;Thanks for getting back, Oyvind.&lt;br /&gt;&lt;br /&gt;The MG100 is shipped with an hl7800 onboard - they have a socket specifically made for it on their PCB.&lt;br /&gt;&lt;br /&gt;To make calls, we set up socket for an IPv4 connection using TLS 1.2 as follows:&lt;br /&gt;&lt;br /&gt;a. We use a signed certificate and require peer verification ( TLS_PEER_VERIFY = TLS_PEER_VERIFY_REQUIRED).&lt;br /&gt;&lt;br /&gt;b. We associate the socket the the security tag placed into an array of valid CA Certs (TLS_SEC_TAG_LIST = sec_tag_t array that we create and populate).&lt;br /&gt;&lt;br /&gt;Let me know&amp;nbsp;what other information I can provide.&lt;br /&gt;&lt;br /&gt;Best,&lt;br /&gt;&lt;br /&gt;S.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MBEDTLS taking too long</title><link>https://devzone.nordicsemi.com/thread/433108?ContentTypeID=1</link><pubDate>Tue, 27 Jun 2023 07:29:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:07f22fbe-e6f5-4147-b781-f12e60acb58a</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sorry for the late reply. Are you able to provide more information on how you have implemented this feature in your application? How is the modem and M100 connected?&lt;/p&gt;
&lt;p&gt;Thanks.&lt;br /&gt;&lt;br /&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>