<?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>changing certificate in https_client sample</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/78816/changing-certificate-in-https_client-sample</link><description>I am trying the https_client sample and I can get it to work unchanged. 
 
 But I would like to connect to a different site than www.example .com. 
 
 As far as I can understand what I need to do is: 
 
 change &amp;quot;example.com&amp;quot; in the HTTP_HEAD to another</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 30 Aug 2021 09:10:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/78816/changing-certificate-in-https_client-sample" /><item><title>RE: changing certificate in https_client sample</title><link>https://devzone.nordicsemi.com/thread/327141?ContentTypeID=1</link><pubDate>Mon, 30 Aug 2021 09:10:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b842a21b-a7af-4fef-ab68-b2dc5012e16a</guid><dc:creator>AnnaD</dc:creator><description>&lt;p&gt;Hello H&amp;aring;kon,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I added \ to every line, but the last in my vecka.cer file and it solved the problem together with the extra&amp;nbsp;setsockopt().&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m guessing that the problem was that it only read the first line of the certificate, although I don&amp;#39;t understand why \ was not needed in the provided certificate?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: changing certificate in https_client sample</title><link>https://devzone.nordicsemi.com/thread/327126?ContentTypeID=1</link><pubDate>Mon, 30 Aug 2021 08:22:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ff6251b-fd23-4d4b-9875-f5bcc569f59c</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Anna,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/https_5F00_vecka_5F00_change.diff"&gt;devzone.nordicsemi.com/.../https_5F00_vecka_5F00_change.diff&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And here&amp;#39;s the &lt;a href="https://letsencrypt.org/certificates/"&gt;lets-encrypt-r3 (signed by X1)&lt;/a&gt;&amp;nbsp;in C form:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;quot;-----BEGIN CERTIFICATE-----\n&amp;quot; \
&amp;quot;MIIFFjCCAv6gAwIBAgIRAJErCErPDBinU/bWLiWnX1owDQYJKoZIhvcNAQELBQAw\n&amp;quot; \
&amp;quot;TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh\n&amp;quot; \
&amp;quot;cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMjAwOTA0MDAwMDAw\n&amp;quot; \
&amp;quot;WhcNMjUwOTE1MTYwMDAwWjAyMQswCQYDVQQGEwJVUzEWMBQGA1UEChMNTGV0J3Mg\n&amp;quot; \
&amp;quot;RW5jcnlwdDELMAkGA1UEAxMCUjMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK\n&amp;quot; \
&amp;quot;AoIBAQC7AhUozPaglNMPEuyNVZLD+ILxmaZ6QoinXSaqtSu5xUyxr45r+XXIo9cP\n&amp;quot; \
&amp;quot;R5QUVTVXjJ6oojkZ9YI8QqlObvU7wy7bjcCwXPNZOOftz2nwWgsbvsCUJCWH+jdx\n&amp;quot; \
&amp;quot;sxPnHKzhm+/b5DtFUkWWqcFTzjTIUu61ru2P3mBw4qVUq7ZtDpelQDRrK9O8Zutm\n&amp;quot; \
&amp;quot;NHz6a4uPVymZ+DAXXbpyb/uBxa3Shlg9F8fnCbvxK/eG3MHacV3URuPMrSXBiLxg\n&amp;quot; \
&amp;quot;Z3Vms/EY96Jc5lP/Ooi2R6X/ExjqmAl3P51T+c8B5fWmcBcUr2Ok/5mzk53cU6cG\n&amp;quot; \
&amp;quot;/kiFHaFpriV1uxPMUgP17VGhi9sVAgMBAAGjggEIMIIBBDAOBgNVHQ8BAf8EBAMC\n&amp;quot; \
&amp;quot;AYYwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMBMBIGA1UdEwEB/wQIMAYB\n&amp;quot; \
&amp;quot;Af8CAQAwHQYDVR0OBBYEFBQusxe3WFbLrlAJQOYfr52LFMLGMB8GA1UdIwQYMBaA\n&amp;quot; \
&amp;quot;FHm0WeZ7tuXkAXOACIjIGlj26ZtuMDIGCCsGAQUFBwEBBCYwJDAiBggrBgEFBQcw\n&amp;quot; \
&amp;quot;AoYWaHR0cDovL3gxLmkubGVuY3Iub3JnLzAnBgNVHR8EIDAeMBygGqAYhhZodHRw\n&amp;quot; \
&amp;quot;Oi8veDEuYy5sZW5jci5vcmcvMCIGA1UdIAQbMBkwCAYGZ4EMAQIBMA0GCysGAQQB\n&amp;quot; \
&amp;quot;gt8TAQEBMA0GCSqGSIb3DQEBCwUAA4ICAQCFyk5HPqP3hUSFvNVneLKYY611TR6W\n&amp;quot; \
&amp;quot;PTNlclQtgaDqw+34IL9fzLdwALduO/ZelN7kIJ+m74uyA+eitRY8kc607TkC53wl\n&amp;quot; \
&amp;quot;ikfmZW4/RvTZ8M6UK+5UzhK8jCdLuMGYL6KvzXGRSgi3yLgjewQtCPkIVz6D2QQz\n&amp;quot; \
&amp;quot;CkcheAmCJ8MqyJu5zlzyZMjAvnnAT45tRAxekrsu94sQ4egdRCnbWSDtY7kh+BIm\n&amp;quot; \
&amp;quot;lJNXoB1lBMEKIq4QDUOXoRgffuDghje1WrG9ML+Hbisq/yFOGwXD9RiX8F6sw6W4\n&amp;quot; \
&amp;quot;avAuvDszue5L3sz85K+EC4Y/wFVDNvZo4TYXao6Z0f+lQKc0t8DQYzk1OXVu8rp2\n&amp;quot; \
&amp;quot;yJMC6alLbBfODALZvYH7n7do1AZls4I9d1P4jnkDrQoxB3UqQ9hVl3LEKQ73xF1O\n&amp;quot; \
&amp;quot;yK5GhDDX8oVfGKF5u+decIsH4YaTw7mP3GFxJSqv3+0lUFJoi5Lc5da149p90Ids\n&amp;quot; \
&amp;quot;hCExroL1+7mryIkXPeFM5TgO9r0rvZaBFOvV2z0gp35Z0+L4WPlbuEjN/lxPFin+\n&amp;quot; \
&amp;quot;HlUjr8gRsI3qfJOQFy/9rKIJR0Y/8Omwt/8oTWgy1mdeHmmjk7j1nYsvC9JSQ6Zv\n&amp;quot; \
&amp;quot;MldlTTKB3zhThV1+XWYp6rjd5JW1zbVWEkLNxE7GJThEUG3szgBVGP7pSWTUTsqX\n&amp;quot; \
&amp;quot;nLRbwHOoq7hHwg==\n&amp;quot; \
&amp;quot;-----END CERTIFICATE-----\n&amp;quot;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And here&amp;#39;s the output at my end:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;HTTPS client sample started
Provisioning certificate
Waiting for network.. OK
Connecting to vecka.nu
Sent 58 bytes
Received 367 bytes

&amp;gt;        HTTP/1.1 200 OK

Finished, closing socket.
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note: you need mfw v1.2.3 or newer for SNI to work.&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: changing certificate in https_client sample</title><link>https://devzone.nordicsemi.com/thread/327118?ContentTypeID=1</link><pubDate>Mon, 30 Aug 2021 07:38:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0104cf73-6be7-42e0-b815-76cbb3ec8a31</guid><dc:creator>AnnaD</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I tried copying the setsockopt into the tls_setup() as you said, but I still got the same error&lt;pre class="ui-code" data-mode="c_cpp"&gt;int tls_setup(int fd)
{
	int err;
	int verify;

	/* Security tag that we have provisioned the certificate with */
	const sec_tag_t tls_sec_tag[] = {
		TLS_SEC_TAG,
	};

	/* Set up TLS peer verification */
	enum {
		NONE = 0,
		OPTIONAL = 1,
		REQUIRED = 2,
	};

	verify = REQUIRED;

	err = setsockopt(fd, SOL_TLS, TLS_HOSTNAME, &amp;quot;vecka.nu&amp;quot;, sizeof(&amp;quot;vecka.nu&amp;quot;));
	if (err) {
		printk(&amp;quot;Failed to setup TLS sec tag, err %d\n&amp;quot;, errno);
		return err;
	}

	err = setsockopt(fd, SOL_TLS, TLS_PEER_VERIFY, &amp;amp;verify, sizeof(verify));
	if (err) {
		printk(&amp;quot;Failed to setup peer verification, err %d\n&amp;quot;, errno);
		return err;
	}

	/* Associate the socket with the security tag
	 * we have provisioned the certificate with.
	 */
	err = setsockopt(fd, SOL_TLS, TLS_SEC_TAG_LIST, tls_sec_tag,
			 sizeof(tls_sec_tag));
	if (err) {
		printk(&amp;quot;Failed to setup TLS sec tag, err %d\n&amp;quot;, errno);
		return err;
	}
	return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
HTTPS client sample started
Provisioning certificate
Waiting for network.. OK
Connecting to example.com
connect() failed, err: 111&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you for the terminal command, it is much simpler than using a web browser.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;//Anna&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: changing certificate in https_client sample</title><link>https://devzone.nordicsemi.com/thread/327026?ContentTypeID=1</link><pubDate>Fri, 27 Aug 2021 14:36:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7146def1-cfdb-46a0-81e4-4e6d9b979498</guid><dc:creator>NordicSwissTom</dc:creator><description>&lt;p&gt;&amp;nbsp;FYI with the huge headers, it seems like&lt;/p&gt;
&lt;p&gt;&amp;nbsp;CONFIG_DOWNLOAD_CLIENT_HTTP_FRAG_SIZE_1024=y&lt;/p&gt;
&lt;p&gt;helped with some of my servers, but not yet with my preferred server (nextcloud,nginx), it just sends&amp;nbsp;too much garbage headers, plus&amp;nbsp;uses alias download URLs, not&amp;nbsp;the real filename (which&amp;nbsp;can only be found in the respons&amp;nbsp; by a&amp;nbsp;Content-Disposition header).&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: changing certificate in https_client sample</title><link>https://devzone.nordicsemi.com/thread/327015?ContentTypeID=1</link><pubDate>Fri, 27 Aug 2021 13:59:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:93e16dae-c92b-4970-8388-87f4e4f480ad</guid><dc:creator>NordicSwissTom</dc:creator><description>&lt;p&gt;Oh no, just wasted hours in finding a bug in my source (based on https_client); for me, the error with my server (nextcloud , others IIS based) setup was&amp;nbsp;ECONNRESET 104&amp;nbsp; &amp;nbsp;(note, some other servers worked so far, I guess 50% affected);&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;** BUT **&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There is a&amp;nbsp;corresponding&amp;nbsp; issue with the download sample&amp;nbsp; ( path&amp;nbsp;&amp;nbsp;\nrf\samples\nrf9160\download&amp;nbsp; )!!! there is a flag now required:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;static struct download_client_cfg config = {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;#if CONFIG_SAMPLE_SECURE_SOCKET&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt; .sec_tag = SEC_TAG,&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#3366ff;font-size:150%;"&gt;&lt;strong&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt; .set_tls_hostname = true,&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This fixed the connection issue. unfortunately for me, the next issue is with huge headers in the http response, so the waste of time continues.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: changing certificate in https_client sample</title><link>https://devzone.nordicsemi.com/thread/326383?ContentTypeID=1</link><pubDate>Tue, 24 Aug 2021 12:54:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2b020e84-8029-48e6-92fc-f1ebb1de7969</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The whole certificate chain can be fetched using openssl (also from your browser as you did):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;openssl s_client -showcerts -connect vecka.nu:443 -tls1_2&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It seems that you have found a bug&amp;nbsp;in this specific sample,&amp;nbsp;when we added SNI support in our modem fw, we forgot to specify the TLS_HOSTNAME (SNI requirement).&lt;/p&gt;
&lt;p&gt;Can you try to add this in tls_setup() function and see if it starts working?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	err = setsockopt(fd, SOL_TLS, TLS_HOSTNAME, &amp;quot;vecka.nu&amp;quot;, sizeof(&amp;quot;vecka.nu&amp;quot;));
	if (err) {
		printk(&amp;quot;Failed to setup TLS sec tag, err %d\n&amp;quot;, errno);
		return err;
	}&lt;/pre&gt;&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>