<?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>nRF9160 Dev Kit MQTT simple + TLS : exception fault while deleting keys</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/54460/nrf9160-dev-kit-mqtt-simple-tls-exception-fault-while-deleting-keys</link><description>Hi, 
 Using the nRF9160DK, an orange SIM card, MODEM firmware mfwnrf9160101 , I managed to make run the sample code: mqtt_simple .using NBIoT 
 My setup is up to date October 15th, 2019, so I suppose SDK 1.0.0. 
 Programmer v1.2.3 
 Segger Embedded Studio</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 15 Nov 2019 15:45:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/54460/nrf9160-dev-kit-mqtt-simple-tls-exception-fault-while-deleting-keys" /><item><title>RE: nRF9160 Dev Kit MQTT simple + TLS : exception fault while deleting keys</title><link>https://devzone.nordicsemi.com/thread/220374?ContentTypeID=1</link><pubDate>Fri, 15 Nov 2019 15:45:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39e36cab-7da1-4ef5-a448-d358498efafc</guid><dc:creator>Julien</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you for your support.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know which CA certificate field I intentionally corrupted.&lt;/p&gt;
&lt;p&gt;I made another test that behaved as expected, where I did not use the same CA certificate on both sides. Just after the Server Hello Done step in the TLS connection establishment, the client sends an alert &amp;quot;unknown CA&amp;quot; leading to a failed connection as expected.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Julien&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 Dev Kit MQTT simple + TLS : exception fault while deleting keys</title><link>https://devzone.nordicsemi.com/thread/220373?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 08:31:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c902ac8d-90e1-4817-a728-6e8016a44252</guid><dc:creator>Didrik Rokhaug</dc:creator><description>&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;I have talked with our modem developers, and here are our findings:&lt;/p&gt;
&lt;p&gt;A PEM file is a Base64 encoded ASCII file, and a full file integrity check is not possible. A PEM file consits of many different parts, e.g. version, serial number, issuer, validity, key info, signature, etc. Not all parts of the certificate are used in all cases. Therefore, a modified certificate can be used if the use case does not use the modified part of the certificate.&lt;/p&gt;
&lt;p&gt;For example, the signature field of a certificate is used to prove that the certificate is legit. It is signed by someone higher up the trust chain, as proof that it is trusted. However, a root certificate is at the top of the trust chain. Therefore no one can sign the root certificate, but as the PEM format requires the signature, it must be there. What is then done is that the root certificate is signed by itself. This leads to two ways of viewing the signature of a root certificate: Either it is worthless, as anyone can issue a self-signed certificate, or the signature is irrelevant, as you trust the certificate regardless (it is, after all, the &amp;quot;root of trust&amp;quot;).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;In our case, this is exactly what happens. As we only are corrupting the signature of a root certificate, we are still able to use the certificate because the signature is not used. However, if we corrupt other, used, parts of the certificate, we do not get a connection. We also tested with OpenSSL and could see the same behavior there.&lt;/p&gt;
&lt;p&gt;In conclusion, everything works as it is supposed to do, even if it looks a bit strange at first glance.&lt;/p&gt;
&lt;p&gt;Hope this helps, if you any more questions, feel free to ask them.&lt;/p&gt;
&lt;p&gt;Didrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 Dev Kit MQTT simple + TLS : exception fault while deleting keys</title><link>https://devzone.nordicsemi.com/thread/220372?ContentTypeID=1</link><pubDate>Fri, 08 Nov 2019 12:41:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84a0dbd3-2100-44b8-983a-f6169006ff7a</guid><dc:creator>Didrik Rokhaug</dc:creator><description>&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;I just did some testing with modem firmware version 1.0.1 and NCS version 1.1.0-rc2.&lt;/p&gt;
&lt;p&gt;1. First I ran asset_tracker with correct CA certificate, public and private key =&amp;gt; Everything OK (as expected).&lt;/p&gt;
&lt;p&gt;2. Then, I changed the CA certificate to the certificate of mqtt.eclipse.org =&amp;gt; Could &lt;strong&gt;not&lt;/strong&gt; connect to nRF Cloud with error 95 (EOPNOTSUPP) (as expected).&lt;/p&gt;
&lt;p&gt;3. After that, I changed the peer_verify field in the TLS configuration from 2 (always) to 0 (never) =&amp;gt; Could connect with the wrong CA certificate (as expected).&lt;/p&gt;
&lt;p&gt;4. I then reverted to the old firmware, but changed a couple of letters at the beginning of the CA certificate =&amp;gt; Could &lt;strong&gt;not&lt;/strong&gt; connect to nRF Cloud with error 95 (as expected).&lt;/p&gt;
&lt;p&gt;5. Finally, I fixed the changed letters at the beginning and instead changed some letters at the end of the CA certificate =&amp;gt; Could connect with the wrong CA certificate (&lt;strong&gt;not&lt;/strong&gt; as expected).&lt;/p&gt;
&lt;p&gt;In the end, I got this &amp;quot;corrupted&amp;quot; CA certificate to work, but if I change the &amp;quot;C&amp;quot; at the end to an &amp;quot;a&amp;quot;, I am no longer able to connect:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;-----BEGIN CERTIFICATE-----
MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF
ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6
b24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&lt;a href="https://www.amazontrust.com/repository/AmazonRootCA1.pem"&gt;https://www.amazontrust.com/repository/AmazonRootCA1.pem&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I have informed our developers about the unexpected result in case 5.&lt;/p&gt;
&lt;p&gt;Have you changed the peer_verify field (on line 359 in main.c from the original post)?&lt;br /&gt;Which part of the CA certificate did you &amp;quot;corrupt&amp;quot;?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Didrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 Dev Kit MQTT simple + TLS : exception fault while deleting keys</title><link>https://devzone.nordicsemi.com/thread/220371?ContentTypeID=1</link><pubDate>Wed, 06 Nov 2019 15:40:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bd7c924c-56ec-4973-90b4-f474031ba2fb</guid><dc:creator>Julien</dc:creator><description>&lt;p&gt;Thank you. I managed to establish the secure connection using the provision function in the code and the CA certificate in the certificates.h file.&lt;/p&gt;
&lt;p&gt;Nevertheless, I just made a small check that let me doubt about the setup. I &amp;quot;corrupted&amp;quot; the content of the CA certificate in the certificates.h file, cleaned the solution, rebuilt and reprogram the nRF. The connection nevertheless established and so I wonder if the nRF really validates the server certificate sent by the certificate during the TLS connection establishment.&lt;/p&gt;
&lt;p&gt;Is the verification of the server certificate by the client done only of the CA certificate stored in the modem is valid?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Any idea?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Julien&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 Dev Kit MQTT simple + TLS : exception fault while deleting keys</title><link>https://devzone.nordicsemi.com/thread/220370?ContentTypeID=1</link><pubDate>Thu, 17 Oct 2019 09:00:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:80f43d5c-8b1f-4da4-89ed-3b1d9ed3d3a3</guid><dc:creator>Didrik Rokhaug</dc:creator><description>&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;Can you check what commit you are on in the nrf repo (and run &amp;quot;west update&amp;quot; afterward)?&lt;/p&gt;
&lt;p&gt;I tried running your code (had to make a couple of changes to make it compile, but nothing big). Instead of an exception, it just hanged at nrf_inbuilt_key_delete.&lt;/p&gt;
&lt;p&gt;I tried removing and disabling the modem_info module, and then everything worked as expected.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Didrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 Dev Kit MQTT simple + TLS : exception fault while deleting keys</title><link>https://devzone.nordicsemi.com/thread/220368?ContentTypeID=1</link><pubDate>Wed, 16 Oct 2019 13:52:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6931320-3ef2-4092-85ed-ca5a8f5e57a6</guid><dc:creator>Didrik Rokhaug</dc:creator><description>[quote user="Julien Mercenier"]You&amp;#39;ll see in autoconf.h that the port 8883 is used, not 1883.[/quote]
&lt;p&gt;&amp;nbsp;I see now that the offending line in your prj.conf is commented out. Sorry for the confusion.&lt;/p&gt;
&lt;p&gt;When getting new certificates from nRF Cloud, these certificates come in JSON format (client ID, private key, public key, CA certificate). For simplicity, the Certificate Manager can import the certificates directly from this JSON file. However, the certificates themselves are PEM formatted, and you should be able to copy a PEM formatted key/certificate into the corresponding text box.&lt;/p&gt;
&lt;p&gt;Again, note that you probably have to increase the buffer size in the at_client sample by setting CONFIG_AT_CMD_RESPONSE_MAX_LEN (3000 should be more than enough).&lt;/p&gt;
&lt;p&gt;One tip for reducing the problem with writing certificates from the application is to only do it when you want to update the certificates, so set CONFIG_PROVISION_CERTIFICATES to &amp;quot;n&amp;quot; after successfully writing certificates.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll try your code to see if I can reproduce your problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 Dev Kit MQTT simple + TLS : exception fault while deleting keys</title><link>https://devzone.nordicsemi.com/thread/220367?ContentTypeID=1</link><pubDate>Wed, 16 Oct 2019 13:15:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6dacfca-5a69-462f-85dd-bfc0fd22ecb7</guid><dc:creator>Julien</dc:creator><description>&lt;p&gt;Hi Didrik,&lt;/p&gt;
&lt;p&gt;Thank you very much for your rapid answer.&lt;/p&gt;
&lt;p&gt;As I tried several codes, with and without key deletion, I may have copied the wrong log. Sorry for that.&lt;/p&gt;
&lt;p&gt;I saw the &amp;quot;Certificate Manager&amp;quot; in the LTE Link Monitor. If I understand it correctly, this manager requires &lt;strong&gt;&lt;em&gt;JSON formats&lt;/em&gt;&lt;/strong&gt; for certificates. The CA certificate I own was generated by openssl and has a&amp;nbsp;CRT/PEM format. I put it in a defined string in the certificates.h file. How can I convert it in a format accepted by the &amp;quot;Certificate Manager&amp;quot;&amp;nbsp; so that I can at least try this tool?&lt;/p&gt;
&lt;p&gt;I am well aware&amp;nbsp;of the flash wearing problematic. My code is just a proof of concept. I want to master both ways of writing certificates.&lt;/p&gt;
&lt;p&gt;You&amp;#39;ll see in autoconf.h that the port 8883 is used, not 1883.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you for your advice regarding NB-IoT and TCP. Once I manage to make my application&amp;nbsp;MQTT+TLS work, I&amp;#39;ll take a look at UDP based protocol.&lt;/p&gt;
&lt;p&gt;Will you nevertheless try my code to&amp;nbsp; help finding the problem?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Julien&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 Dev Kit MQTT simple + TLS : exception fault while deleting keys</title><link>https://devzone.nordicsemi.com/thread/220366?ContentTypeID=1</link><pubDate>Wed, 16 Oct 2019 12:54:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2361055b-61b3-4e66-a7ee-59bf9d5d49f5</guid><dc:creator>Didrik Rokhaug</dc:creator><description>&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;While I have not tried to run your code yet, I cannot see anything that looks wrong. However, one thing I noticed in your log is that you do not print &amp;quot;Deleting certs sec_tag: %d\n&amp;quot;. Is there a reason for these five lines missing from the log?&lt;/p&gt;
&lt;p&gt;In general, we do not recommend writing certificates from the application. This has several downsides:&lt;/p&gt;
&lt;p&gt;The certificates are present in the flash, they will be present in modem traces, and writing the certificates on every reboot leads to rapid flash wear.&lt;/p&gt;
&lt;p&gt;Instead, what we recommend is that you use the &amp;quot;Certificate Manager&amp;quot; in the LTE Link Monitor application in nRF Connect for Desktop, using the at_client (with increased buffers) on the nRF9160.&lt;/p&gt;
&lt;p&gt;This way, you only write the certificates when you need to, they are not stored easily accessible in flash, and will not show up in modem traces (unless you take a trace of the certificate writing).&lt;/p&gt;
&lt;p&gt;You should also consider using another sec_tag, as the nrf_cloud library uses 16842753. This means that if you delete or write new certificates to that sec_tag, you will not be able to connect to nRF Cloud without getting new certificates (guide here: &lt;a href="https://devzone.nordicsemi.com/nordic/cellular-iot-guides/b/getting-started-cellular/posts/nrf-cloud-certificate-update"&gt;https://devzone.nordicsemi.com/nordic/cellular-iot-guides/b/getting-started-cellular/posts/nrf-cloud-certificate-update&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Also, if you want to connect to mqtt.eclipse.org with TLS, you must use port 8883, not 1883.&lt;/p&gt;
&lt;p&gt;Finally, NB-IoT is not well suited for TCP traffic. Instead of using MQTT, which relies on TCP. You might want to take a look at UDP based protocols with STLS for security.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Didrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>