<?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>The function modem_key_mgmt_cmp() fails to identify valid certificate</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/61195/the-function-modem_key_mgmt_cmp-fails-to-identify-valid-certificate</link><description>Hi, 
 I&amp;#39;m running of the fw-nrfconnect-nrf master branch (commit: 96e75dba598320c2707dede3ffef44bf326a89e3) because there are some improvements since the release of SDK v1.2.0 that are of use to me. I&amp;#39;m testing the http_application_update sample in the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 26 Aug 2020 17:34:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/61195/the-function-modem_key_mgmt_cmp-fails-to-identify-valid-certificate" /><item><title>RE: The function modem_key_mgmt_cmp() fails to identify valid certificate</title><link>https://devzone.nordicsemi.com/thread/266584?ContentTypeID=1</link><pubDate>Wed, 26 Aug 2020 17:34:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b9dff4c-3f57-4062-8f61-6f1e88ab88a4</guid><dc:creator>Tiago Costa</dc:creator><description>&lt;p&gt;Hi emdi! Thanks for taking the time to fix this!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The function modem_key_mgmt_cmp() fails to identify valid certificate</title><link>https://devzone.nordicsemi.com/thread/260927?ContentTypeID=1</link><pubDate>Tue, 21 Jul 2020 08:24:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e23079e-6385-4087-81a9-35ad13cfc946</guid><dc:creator>emdi</dc:creator><description>&lt;p&gt;Hi Tiago, thank you for digging into this. I have opened a PR to sdk-nrf to fix this issue, you can find it here:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/pull/2613"&gt;https://github.com/nrfconnect/sdk-nrf/pull/2613&lt;/a&gt;.&amp;nbsp;Feel free to check it out and leave a comment :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The function modem_key_mgmt_cmp() fails to identify valid certificate</title><link>https://devzone.nordicsemi.com/thread/251314?ContentTypeID=1</link><pubDate>Fri, 22 May 2020 18:48:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4e3cad8-8598-4c42-8e5e-878d3a540725</guid><dc:creator>Tiago Costa</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I think I&amp;#39;ve managed to identify the problem, although I don&amp;#39;t have a solution for it yet.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;After further looking into the Modem Key Management library, I&amp;#39;ve noticed that the following function&amp;nbsp;&lt;span&gt;call under &lt;strong&gt;&lt;a title="lib/at_cmd/at_cmd.c" href="https://github.com/nrfconnect/sdk-nrf/blob/a66b8234796dfaaad1df10394df4710636058f70/lib/at_cmd/at_cmd.c"&gt;lib/at_cmd/at_cmd.c&lt;/a&gt;&lt;/strong&gt;&amp;nbsp;is returning a wrong payload length (of 626, significantly less than the certificate&amp;#39;s size), which in turn causes the certificates&amp;#39; size comparison to fail:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;pre class="ui-code" data-mode="c_cpp"&gt;payload_len = get_return_code(item-&amp;gt;data, &amp;amp;ret);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The function seems to return when it finds the string &amp;quot;OK&amp;quot; in the certificate&amp;#39;s content being&amp;nbsp;read from the modem. At a first glance, it seems this function might&amp;nbsp;not be&amp;nbsp;escaping AT command return codes correctly in the certificate&amp;#39;s payload string, and gets tricked into returning a wrong length because of that.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I believe a modem firmware&amp;nbsp;fix might be necessary before this can be&amp;nbsp;handled, either to do byte stuffing when reading certificates&amp;#39; strings from the modem, or simply by providing the certificate&amp;#39;s length in advance and having the function&amp;nbsp;parse a known length.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The function modem_key_mgmt_cmp() fails to identify valid certificate</title><link>https://devzone.nordicsemi.com/thread/251300?ContentTypeID=1</link><pubDate>Fri, 22 May 2020 16:32:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c16464cf-0f8f-41e9-b46e-1f6f805e4c4c</guid><dc:creator>Tiago Costa</dc:creator><description>&lt;p&gt;Hi emdi, thanks for the suggestion! I have increased the heap up to 16384 bytes but it made no difference however (I have set CONFIG_HEAP_MEM_POOL_SIZE=16384 in prj.conf).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The function modem_key_mgmt_cmp() fails to identify valid certificate</title><link>https://devzone.nordicsemi.com/thread/251193?ContentTypeID=1</link><pubDate>Fri, 22 May 2020 08:47:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4fccfdd-7cd7-42e5-9c02-b9cf7aca6897</guid><dc:creator>emdi</dc:creator><description>&lt;p&gt;Hi Tiago,&amp;nbsp;AT commands are put on the heap when parsed, and&amp;nbsp; if no memory is available the `at_cmd_parser` won&amp;#39;t report and error :/&lt;/p&gt;
&lt;p&gt;Try to increase the heap and see if the problem is solved.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The function modem_key_mgmt_cmp() fails to identify valid certificate</title><link>https://devzone.nordicsemi.com/thread/249994?ContentTypeID=1</link><pubDate>Thu, 14 May 2020 14:05:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b716c79-cc6c-4f49-8fff-5b5fe8662da8</guid><dc:creator>Tiago Costa</dc:creator><description>&lt;p&gt;Hi Heidi, thanks for the feedback!&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The function modem_key_mgmt_cmp() fails to identify valid certificate</title><link>https://devzone.nordicsemi.com/thread/249948?ContentTypeID=1</link><pubDate>Thu, 14 May 2020 12:07:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f8e33289-2ae8-4ec0-8dff-e168a090a37a</guid><dc:creator>Heidi</dc:creator><description>&lt;p&gt;Hi, thank you.&lt;/p&gt;
&lt;p&gt;It looks like this might be a bug at&amp;nbsp;the AT Command parser level: either it&amp;#39;s filling the incorrect size, or it&amp;#39;s not able to parse the&amp;nbsp;response&amp;nbsp;from the modem. The developers will have a look either tomorrow or the beginning of next week, and I&amp;#39;ll let you know as soon as we find the root cause of this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Heidi&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The function modem_key_mgmt_cmp() fails to identify valid certificate</title><link>https://devzone.nordicsemi.com/thread/249634?ContentTypeID=1</link><pubDate>Wed, 13 May 2020 09:21:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18464f0a-0b74-4fc5-ae96-e2b5a69bc1d6</guid><dc:creator>Tiago Costa</dc:creator><description>&lt;p&gt;Hi Heidi, thanks for getting back to me. I&amp;#39;ve added AT CMD Level debug to&amp;nbsp;my http_application_update example and got the following output:&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.1.99-ncs1-1145-g13dc96f83bab  ***
HTTPS application update sample started v1
Initializing bsdlib
Initialized bsdlib
D: Setting notification handler to 0x0003952d
D: Common AT socket created
D: Common AT socket processing thread created
D: Sending command AT+CMEE?
DD: Awaiting response for AT+CMEE?
: AT socket thread started
D: Allocating memory slab for AT socket
D: Allocation done
D: at_cmd_rx 15 bytes, +CMEE: 0
OK

D: Bytes sent: 8
D: Sending command AT+CMEE=1
D: Allocating memory slab for AT socket
D: Allocation done
D: Awaiting response for AT+CMEE=1
D: at_cmd_rx 5 bytes, OK

D: Bytes sent: 9
D: Sending command AT%CMNG=1,24514698,0
D: Allocating memory slab for AT socket
D: Allocation done
D: Awaiting response for AT%CMNG=1,24514698,0
D: at_cmd_rx 91 bytes, %CMNG: 24514698,0,&amp;quot;0000000000000000000000000000000000000000000000000000000000000000&amp;quot;
OK

D: Bytes sent: 20
D: Sending command AT+CMEE=0
D: Allocating memory slab for AT socket
D: Allocation done
D: Awaiting response for AT+CMEE=0
D: at_cmd_rx 5 bytes, OK

D: Bytes sent: 9
D: Sending: AT%CMNG=2,24514698,0
D: Sending command AT+CMEE?
D: Allocating memory slab for AT socket
D: Allocation done
D: Awaiting response for AT+CMEE?
D: at_cmd_rx 15 bytes, +CMEE: 0
OK

D: Bytes sent: 8
D: Sending command AT+CMEE=1
D: Allocating memory slab for AT socket
D: Allocation done
D: Awaiting response for AT+CMEE=1
D: at_cmd_rx 5 bytes, OK

D: Bytes sent: 9
D: Sending command AT%CMNG=2,24514698,0
D: Allocating memory slab for AT socket
D: Allocation done
D: Awaiting response for AT%CMNG=2,24514698,0
D: at_cmd_rx 2265 bytes, %CMNG: 24514698,0,&amp;quot;0000000000000000000000000000000000000000000000000000000000000000&amp;quot;,&amp;quot;-----BEGIN CERTIFICATE-----
MIIGFzCCA/+gAwIBAgIUN6ec2FP/QL5ASPNvIjpjSvsNZv4wDQYJKoZIhvcNAQEL
BQAwgZoxCzAJBgNVBAYTAlBUMQ4wDAYDVQQIDAVQb3J0bzEaMBgGA1UEBwwRVmls
YSBOb3ZhIGRlIEdhaWExFjAUBgNVBAoMDVVyYmFuIENvbnRyb2wxGTAXBgNVB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HUnWtvlwLx+rf5zEF9DNl+tHykCAwEAAaNTMFEwHQYDVR0OBBYE
FEu1g2lXCONMLcDGZwcjNf64QtGqMB8GA1UdIwQYMBaAFEu1g2lXCONMLcDGZwcj
Nf64QtGqMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggIBAG0xHXli
l4d9lud8Ub0BbHy26o02Ye7Q8RNG1g8USwynHKbaw+Y4ceG/KRpQQJLBaNSTQyuD
8/9hTulJt7iS1aBdckiJWZzkhTu0H13QmDIwmphTkhZLaf2ffQvHp0M1kLiiTvxk
s7WDOEgw2bPhzUeul2Opvy8I2gGVBL5h5qp2Gm4WRDDMUK6YnJ0yINRmO307GdK9
688svP2WZG9S7OLX+40BJmi4FLdXI4mUyDzLJIx2yFTHLBxdc+rldUeK1WFB+g17
g4t3MvbBM1Nfa/CONRtJlxVommn0t+KDbXmGnBOWgL5kmjSjkOyyDfLS191wRagv
5T8LFZFYSKCnZWg/ZTaIlja70vtYLW0vzDKs2COeqnrrc9eAQhFmD3Idw0FrM9zR
Vsz6bKdcG3oMTs6goFEmPJVLgXsNHLtCKMfpgYL8TcoK/sOclQEIIzn0iMbhTSE6
fyPtr56BiYrFSHP3ONTf6G3lauWAUg/+6QZOinUK0dFgumEfUJoriwKZoeD37M25
ZdgpnMvsPOlmJfSpBEKsVw8vkdbj7jpAvM1VCS2XPzctU+tuz49yh9ldXHwJiWCo
AA9uRd6aAbzFmH/JIHYBaFgSyV1ft8tEFPthX7mS+nltNdthVb7lXVySzcULXR4J
XDMjezxXeiOjLp2lVe8yUTMEVxX0OmmYAKVJ
-----END CERTIFICATE-----
&amp;quot;
OK

D: Bytes sent: 20
D: Sending command AT+CMEE=0
D: Allocating memory slab for AT socket
D: Allocation done
D: Awaiting response for AT+CMEE=0
D: at_cmd_rx 5 bytes, OK

D: Bytes sent: 9
D: Credential length 0 bytes (expected 2171)
Certificate/key mismatch. Deleting existing certificate/key..., err 1

(...)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Please let me know if you also want me to send the command manually to the modem.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;TC&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The function modem_key_mgmt_cmp() fails to identify valid certificate</title><link>https://devzone.nordicsemi.com/thread/249607?ContentTypeID=1</link><pubDate>Wed, 13 May 2020 07:26:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f74a7dd7-84ba-48a8-8f81-014a2b0f46ae</guid><dc:creator>Heidi</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;Sorry for the delayed reply, I&amp;#39;ve been taking a look at this with a developer. I am unfortunately not able to reproduce your error, so I&amp;#39;ll need some debug information from you.&lt;/p&gt;
&lt;p&gt;If you add CONFIG_AT_CMD_LOG_LEVEL__DBG=y to your project, you should get you a message like &amp;quot;Sending AT%CMNG=&amp;lt;&amp;gt;&amp;quot;. I need you to flash an NCS sample that allows you to send AT commands directly to the modem and then and send that specific AT command and see what the output is.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Heidi&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>