<?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>CoAP with DTLS on download sample</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89511/coap-with-dtls-on-download-sample</link><description>hello， 
 I use download sample on nRF9160DK with NCS2.0. I tried to change the SAMPLE_FILE_URL to my server URL, and the certificate was also modified, my configuration is as follow. 
 
 
 
 However, the connection to the server was rejected. 
 
 
 I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 04 Jul 2022 10:41:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89511/coap-with-dtls-on-download-sample" /><item><title>RE: CoAP with DTLS on download sample</title><link>https://devzone.nordicsemi.com/thread/375286?ContentTypeID=1</link><pubDate>Mon, 04 Jul 2022 10:41:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7643b933-50ef-475d-ad1c-5b2e2369082a</guid><dc:creator>Harvey Zheng</dc:creator><description>&lt;p&gt;hi&amp;nbsp;&lt;span&gt;&amp;Oslash;yvind,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I use PSK&amp;nbsp; in my sample,&amp;nbsp;my configuration is as follow,&amp;nbsp;&lt;/span&gt;I&amp;#39;m not sure that&amp;#39;s the right setup&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;# General config
CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_NEWLIB_LIBC=y

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n

# Modem library
CONFIG_NRF_MODEM_LIB=y
CONFIG_NRF_MODEM_LIB_TRACE_ENABLED=y
CONFIG_MODEM_KEY_MGMT=y

# AT Host
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_AT_HOST_LIBRARY=y

# CoAP
CONFIG_COAP=y

# Main thread
CONFIG_MAIN_STACK_SIZE=4096

CONFIG_LTE_NETWORK_MODE_NBIOT=y

CONFIG_TLS_CREDENTIALS=y
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
CONFIG_NET_SOCKETS_ENABLE_DTLS=y&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define SEC_TAG 2

static const char psk_id[] = &amp;quot;Client_identity&amp;quot;;

static uint8_t key[] = {
    0x73, 0x65, 0x63, 0x72, 0x65, 0x7c, 0x50, 0x53, 0x4c
};

/* Provision certificate to modem */
static int cert_provision(void)
{
	int err;
	bool exists;

    /*----------- PSK -----------------*/
    err = modem_key_mgmt_exists(SEC_TAG,
				    MODEM_KEY_MGMT_CRED_TYPE_PSK,
				    &amp;amp;exists);
	if (err) {
		printk(&amp;quot;Failed to check for certificates err %d\n&amp;quot;, err);
		return err;
	}

	if (exists) {
		printk(&amp;quot;PSK &amp;quot;);
		/* Let&amp;#39;s compare the existing credential */
		err = modem_key_mgmt_cmp(SEC_TAG,
					 MODEM_KEY_MGMT_CRED_TYPE_PSK,
					 key, sizeof(key));
		printk(&amp;quot;%s\n&amp;quot;, err ? &amp;quot;mismatch&amp;quot; : &amp;quot;match&amp;quot;);
		if (!err) {
			return 0;
		}
	} else {
        printk(&amp;quot;PSK is nonexistent\n&amp;quot;);
    }

    printk(&amp;quot;Provisioning PSK\n&amp;quot;);
	/*  Provision PSK to the modem */
	err = modem_key_mgmt_write(SEC_TAG,
				   MODEM_KEY_MGMT_CRED_TYPE_PSK,
				   key, sizeof(key));
	if (err) {
		printk(&amp;quot;Failed to provision certificate, err %d\n&amp;quot;, err);
		return err;
	}

    err = modem_key_mgmt_write(SEC_TAG,
				   MODEM_KEY_MGMT_CRED_TYPE_IDENTITY,
				   psk_id, sizeof(psk_id) -1);
	if (err) {
		printk(&amp;quot;Failed to provision certificate, err %d\n&amp;quot;, err);
		return err;
	}

	return 0;
}

static int socket_sectag_set(int fd, int sec_tag)
{
	int err;
	int verify;
	sec_tag_t sec_tag_list[] = { sec_tag };

	enum {
		NONE = 0,
		OPTIONAL = 1,
		REQUIRED = 2,
	};

	verify = REQUIRED;

	err = setsockopt(fd, SOL_TLS, TLS_PEER_VERIFY, &amp;amp;verify, sizeof(verify));
	if (err) {
		printk(&amp;quot;Failed to setup peer verification, errno %d&amp;quot;, errno);
		return -errno;
	}

	printk(&amp;quot;Setting up TLS credentials, tag %d\n&amp;quot;, sec_tag);
	err = setsockopt(fd, SOL_TLS, TLS_SEC_TAG_LIST, sec_tag_list,
			 sizeof(sec_tag_list));
	if (err) {
		printk(&amp;quot;Failed to setup socket security tag, errno %d&amp;quot;, errno);
		return -errno;
	}

    nrf_sec_cipher_t cipher_list[] = { 0xC0A8 };

    err = setsockopt(fd, SOL_TLS, TLS_CIPHERSUITE_LIST, cipher_list, sizeof(cipher_list));
    if (err) {
       /* Failed to set up cipher suite list. */
       return -errno;
    }

	return 0;
}

static int socket_tls_hostname_set(int fd)
{
	int err;

	err = setsockopt(fd, SOL_TLS, TLS_HOSTNAME, CONFIG_COAP_SERVER_HOSTNAME,
			 strlen(CONFIG_COAP_SERVER_HOSTNAME));
	if (err) {
		printk(&amp;quot;Failed to setup TLS hostname (%s), errno %d&amp;quot;,
			CONFIG_COAP_SERVER_HOSTNAME, errno);
		return -errno;
	}

	return 0;
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;And, b&lt;/span&gt;ased on this configuration, I still can&amp;#39;t connect.&amp;nbsp;There&amp;#39;s no CLIENT_KEY_EXCHANGE after&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;SERVER_HELLO_DONE. My modem trace log is as follow.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/trace_2D00_2022_2D00_07_2D00_04T10_2D00_29_2D00_08.340Z.rar"&gt;devzone.nordicsemi.com/.../trace_2D00_2022_2D00_07_2D00_04T10_2D00_29_2D00_08.340Z.rar&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CoAP with DTLS on download sample</title><link>https://devzone.nordicsemi.com/thread/374910?ContentTypeID=1</link><pubDate>Thu, 30 Jun 2022 12:42:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65da5db2-39d9-40e2-adeb-cad6fb823b5b</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Yes, it seems likely that&amp;nbsp;this is the root cause.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;-Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CoAP with DTLS on download sample</title><link>https://devzone.nordicsemi.com/thread/374902?ContentTypeID=1</link><pubDate>Thu, 30 Jun 2022 12:15:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13bfbc68-609c-45db-8b98-23649036df35</guid><dc:creator>Harvey Zheng</dc:creator><description>&lt;p&gt;hi,&lt;/p&gt;
&lt;pre&gt;&lt;strong&gt;DTLS supports PSK authentication only&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;I use CA certificates, so based on this information, the certificate type is incorrect?&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CoAP with DTLS on download sample</title><link>https://devzone.nordicsemi.com/thread/374899?ContentTypeID=1</link><pubDate>Thu, 30 Jun 2022 12:10:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf5dfff2-010b-4ac6-9b86-0b17ac0318bf</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The DevZone team is currently entering summer vacation period, some delays in answers must be expected.&lt;/span&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Are you able to share full log output from the application? What certificates are you using? What modem FW are you running on your device?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Errno&amp;nbsp;&lt;span&gt;ECONNREFUSED&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;111&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;/* Connection refused */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Please be aware of the following limitations in the modem:&lt;/p&gt;
&lt;blockquote&gt;
&lt;pre&gt;- TLS/DTLS
    - One TLS handshake at a time is supported.
    - Up to three simultaneous TLS/DTLS connections are possible.
    - Maximum server certificate chain size has a limit of 4kB.
    - Server certificate expiry time is not verified.
    - pkcs#8 is not supported.
    - Absolute maximum number of supported credentials is 32. The actual amount depends on size of
      credentials as memory area reserved for credentials may be a limiting factor as well.
    - DTLS supports PSK authentication only.
    - &lt;strong&gt;2kB secure socket buffer size.
&lt;/strong&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;p&gt;We might need a &lt;a href="https://infocenter.nordicsemi.com/topic/ug_trace_collector/UG/trace_collector/collect_modem_trace.html"&gt;modem trace to see what is failing&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>