<?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>nrf91_socket_offload_connect() fails when nrf_connect() is called for a TLS connection</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/52948/nrf91_socket_offload_connect-fails-when-nrf_connect-is-called-for-a-tls-connection</link><description>The IP mode is IPv4. 
 
 1. The hostname resolves to IP address. The resolved IP address is correct (verified with a nslookup command separately). 
 2. setsockopt(fd, SOL_TLS, TLS_PEER_VERIFY, &amp;amp;verify, sizeof (verify)); is called successfully (no error</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 08 Oct 2019 14:45:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/52948/nrf91_socket_offload_connect-fails-when-nrf_connect-is-called-for-a-tls-connection" /><item><title>RE: nrf91_socket_offload_connect() fails when nrf_connect() is called for a TLS connection</title><link>https://devzone.nordicsemi.com/thread/213971?ContentTypeID=1</link><pubDate>Tue, 08 Oct 2019 14:45:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1f62130c-84f4-4d3e-af61-34ca842cca07</guid><dc:creator>Venka Gade</dc:creator><description>&lt;p&gt;It was the host that had the problem. I am able to connect with other sites.&lt;/p&gt;
&lt;p&gt;Appreciate your help :-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf91_socket_offload_connect() fails when nrf_connect() is called for a TLS connection</title><link>https://devzone.nordicsemi.com/thread/213937?ContentTypeID=1</link><pubDate>Tue, 08 Oct 2019 13:24:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84966793-ed08-4b96-8a1b-a151d8f6fd1a</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Could you show the socket setup prior to the connect() call? Getting EINVAL back is a typical error if the setup is not aligned towards the protocol you&amp;#39;re trying to use.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf91_socket_offload_connect() fails when nrf_connect() is called for a TLS connection</title><link>https://devzone.nordicsemi.com/thread/213646?ContentTypeID=1</link><pubDate>Mon, 07 Oct 2019 12:25:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5980c99c-d62b-4e31-b70b-2033b709124c</guid><dc:creator>Venka Gade</dc:creator><description>&lt;p&gt;Thank you for the reply!&lt;/p&gt;
&lt;p&gt;I have added certificates already. In fact, I add it on every boot with&amp;nbsp;&lt;span class="s1"&gt;nrf_inbuilt_key_delete() and&amp;nbsp;&lt;/span&gt;&lt;span class="s1"&gt;nrf_inbuilt_key_write() calls.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="s1"&gt;Key Pair and Public Key Certificate are generated using the following command:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="s1"&gt;#&amp;nbsp;openssl req -newkey rsa:4096 -nodes -keyout domain.key -x509 -days 365 -out domain.crt&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="s1"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="s1"&gt;&lt;/span&gt;&lt;span class="s1"&gt;I added errno to the log and nrf91_connect() returns 22 (NRF_EINVAL).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="s1"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="s1"&gt;Thanks,&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf91_socket_offload_connect() fails when nrf_connect() is called for a TLS connection</title><link>https://devzone.nordicsemi.com/thread/213609?ContentTypeID=1</link><pubDate>Mon, 07 Oct 2019 10:56:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eafc88df-5600-4ead-9392-b74da46fb929</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]2.&amp;nbsp;&lt;span&gt;setsockopt(fd, SOL_TLS, TLS_PEER_VERIFY, &amp;amp;verify, &lt;/span&gt;&lt;span&gt;sizeof&lt;/span&gt;&lt;span&gt;(verify)); is called successfully (no error returned). verify is set to NONE&lt;/span&gt;[/quote]
&lt;p&gt;&amp;nbsp;This means do not verify the hostname (don&amp;#39;t check the domain name with CA certificates), that should be OK.&lt;/p&gt;
[quote user=""]&lt;span&gt;3.&amp;nbsp;&lt;/span&gt;&lt;span&gt;setsockopt(fd, SOL_TLS, TLS_SEC_TAG_LIST, sec_tag_list,&amp;nbsp;&lt;/span&gt;&lt;span&gt;sizeof&lt;/span&gt;&lt;span&gt;(sec_tag_t) * ARRAY_SIZE(sec_tag_list)); is called successfully (no error returned). sec_tag_list is initialized to { 1 }.&lt;/span&gt;[/quote]
&lt;p&gt;&amp;nbsp;This points to the certificates (private and public key, and optional; CA) should reside on the sec_tag &amp;#39;1&amp;#39;. Have you loaded your certificates into this sec_tag?&lt;/p&gt;
&lt;p&gt;If you first load at_client into your device, you can use the &amp;quot;Certificate manager&amp;quot; in LTE Link monitor to load the certs:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-51e3e1f7c66e4b649ff76611027c7004/pastedimage1570445719423v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If it gives an error when writing, please reset the board; as you cannot write certs while the modem is active.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]&lt;span&gt;4. connect() returns error. Looking deeper,&amp;nbsp;&lt;/span&gt;&lt;span&gt;nrf91_connect() (in&amp;nbsp;&lt;/span&gt;&lt;span&gt;nrf/lib/bsdlib/nrf91_sockets.c::&lt;/span&gt;&lt;span&gt;nrf91_socket_offload_connect() )&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;returns error -1.&lt;/span&gt;[/quote]
&lt;p&gt;-1 means that the call itself has failed. If you print errno (printk(&amp;quot;errno:%d\n&amp;quot;, errno);) it should give a more detailed error return.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>