<?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 How is it possible to generate EC 256 key pair and a self-signed X.509 certificate?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/63576/nrf91-how-is-it-possible-to-generate-ec-256-key-pair-and-a-self-signed-x-509-certificate</link><description>Hi, 
 
 I want to connect to Google Cloud IoT and for that I would like to generate the needed credentials on the nRF9160. 
 I need these ones , but the private key should be both in PEM and in DER format. 
 PEM is needed by the modem and DER is used</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 31 May 2021 08:04:39 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/63576/nrf91-how-is-it-possible-to-generate-ec-256-key-pair-and-a-self-signed-x-509-certificate" /><item><title>RE: nRF91 How is it possible to generate EC 256 key pair and a self-signed X.509 certificate?</title><link>https://devzone.nordicsemi.com/thread/312557?ContentTypeID=1</link><pubDate>Mon, 31 May 2021 08:04:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:43ba18f2-8255-439e-8ca1-80d317a9492b</guid><dc:creator>mglettig</dc:creator><description>&lt;p&gt;I try to achieve the same thing. Thanks for posting a step by step guide. I will try this out. I guess the workaround (part 1 above) is no longer needed with the current release (v1.5.1) of NRF Connect. Correct? What about part 4. Were there any changes in NRF Connect regarding generating the entropy?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Michael&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF91 How is it possible to generate EC 256 key pair and a self-signed X.509 certificate?</title><link>https://devzone.nordicsemi.com/thread/263460?ContentTypeID=1</link><pubDate>Thu, 06 Aug 2020 13:34:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c7caaa5-1b86-406a-a13e-4f7ce2c2ccdf</guid><dc:creator>PopradiArpad</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;your workaround works like a charm :)&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here&amp;nbsp;is&amp;nbsp;step by step how to generate&amp;nbsp;EC 256 key pair. (X509 certificate is not needed by Google Cloud IoT)&lt;/p&gt;
&lt;p&gt;For nRF Connect SDK v1.3.0&lt;/p&gt;
&lt;p&gt;1. Apply the needed pieces of&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/pull/2519/files"&gt;workaround&lt;/a&gt;&amp;nbsp;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;secure_services.h
-----------------
// https://devzone.nordicsemi.com/f/nordic-q-a/63576/nrf91-how-is-it-possible-to-generate-ec-256-key-pair-and-a-self-signed-x-509-certificate https://github.com/nrfconnect/sdk-nrf/pull/2519/files
#include &amp;lt;zephyr.h&amp;gt;
..
// https://devzone.nordicsemi.com/f/nordic-q-a/63576/nrf91-how-is-it-possible-to-generate-ec-256-key-pair-and-a-self-signed-x-509-certificate https://github.com/nrfconnect/sdk-nrf/pull/2519/files
//int spm_request_random_number(u8_t *output, size_t len, size_t *olen);
static inline int spm_request_random_number(u8_t *output, size_t len, size_t *olen);
int spm_request_random_number_nsc(u8_t *output, size_t len, size_t *olen);
static inline int spm_request_random_number(u8_t *output, size_t len, size_t *olen)
{
	k_sched_lock();
	int err = spm_request_random_number_nsc(output, len, olen);

	k_sched_unlock();
	return err;
}

secure_services.c
-----------------
// https://devzone.nordicsemi.com/f/nordic-q-a/63576/nrf91-how-is-it-possible-to-generate-ec-256-key-pair-and-a-self-signed-x-509-certificate https://github.com/nrfconnect/sdk-nrf/pull/2519/files
//int spm_request_random_number(u8_t *output, size_t len, size_t *olen)
int spm_request_random_number_nsc(u8_t *output, size_t len, size_t *olen)
{
	int err;

	if (len != MBEDTLS_ENTROPY_MAX_GATHER) {
		return -EINVAL;
	}

	err = mbedtls_hardware_poll(NULL, output, len, olen);
	return err;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;2. Add mbedTLS support in prj.conf:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;# Generate credentials
# Based on
#   ncs/zephyr/samples/net/cloud/google_iot_mqtt/prj.conf
#   ncs/iluminate-hub-nrf9160/build_nrf9160dk_nrf9160ns/mcuboot/zephyr/.config
CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_BUILTIN=y
#   Configure mbedTLS directly with its configuration file instead through Zephyr config symbols
#     Relative from ncs/modules/crypto/mbedtls/configs/config-tls-generic.h
CONFIG_MBEDTLS_CFG_FILE=&amp;quot;../../../../iluminate-hub-nrf9160/config-mbedtls.h&amp;quot;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;3. Configure mbedTLS by an own mbedTLS config file based on&amp;nbsp;ncs/modules/crypto/mbedtls/configs/config-tls-generic.h and positioned in the project directory.&lt;/p&gt;
&lt;p&gt;I named it&amp;nbsp;config-mbedtls.h.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;//Changes relative to ncs/modules/crypto/mbedtls/configs/config-tls-generic.h
//----------------------------------------------------------------------------------
  // general settings
#define MBEDTLS_ERROR_C
  // for printing mbedTLS keys and certificates
#define MBEDTLS_PEM_WRITE_C
#define MBEDTLS_PK_WRITE_C
#define MBEDTLS_BASE64_C
  // for key generation
#define MBEDTLS_PK_C
#define MBEDTLS_ECP_C
#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
#define MBEDTLS_OID_C
#define MBEDTLS_ASN1_WRITE_C
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;4. The C code&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;quot;secure_services.h&amp;quot;
#include &amp;quot;mbedtls/ecdsa.h&amp;quot;
#include &amp;quot;mbedtls/pk.h&amp;quot;
#include &amp;quot;mbedtls/error.h&amp;quot;

#include &amp;lt;logging/log.h&amp;gt;
LOG_MODULE_REGISTER(credentials, CONFIG_ASSET_TRACKER_LOG_LEVEL);


// The generated random number has fix 144 length. See doc of spm_request_random_number
#define GENERATED_RANDOM_NUMBER_LENGTH 144

// See mbedtls_entropy_func as example
static int gen_true_random_number(void *unused, unsigned char *output, size_t len )
{
  // spm_request_random_number uses uint8_t and not unsigned char
  __ASSERT(sizeof(unsigned char) == sizeof(uint8_t), &amp;quot;Adapt type!&amp;quot;);

  if( len &amp;gt; GENERATED_RANDOM_NUMBER_LENGTH )
  {
    LOG_ERR( &amp;quot;Max generatable real random number length exceeded&amp;quot;);
    return -1;
  }

  static uint8_t rnd_number[GENERATED_RANDOM_NUMBER_LENGTH];
  memset( rnd_number, 0, GENERATED_RANDOM_NUMBER_LENGTH);
  size_t rnd_number_length = 0;
  int err = spm_request_random_number(rnd_number, GENERATED_RANDOM_NUMBER_LENGTH, &amp;amp;rnd_number_length);
  if( err != 0 )
  {
    LOG_ERR( &amp;quot;Can&amp;#39;t get real random number: %d&amp;quot;, err);
    return -1;
  }

  if( rnd_number_length &amp;lt; len )
  {
    LOG_ERR( &amp;quot;Generated real random number is too short&amp;quot;);
    return -1;
  }

  memcpy( output, rnd_number, len );

  return 0;
}

static void log_key(mbedtls_pk_context * key, int (f_writer)( mbedtls_pk_context *, unsigned char *, size_t), char* err_buf, size_t err_buf_length)
{
  unsigned char buf[1024];
  int err = f_writer(key, buf, sizeof(buf));
  if (err != 0)
  {
    mbedtls_strerror(err, err_buf, err_buf_length);
    LOG_ERR(&amp;quot;Can not write -0x%04x - %s\n\n&amp;quot;, (unsigned int) -err, err_buf);
    return;
  }
  LOG_INF(&amp;quot;\n%s&amp;quot;,buf);
}

static inline void log_private_key(mbedtls_pk_context * key, char* err_buf, size_t err_buf_length)
{
  log_key(key, mbedtls_pk_write_key_pem, err_buf, err_buf_length);
}

static inline void log_public_key(mbedtls_pk_context * key, char* err_buf, size_t err_buf_length)
{
  log_key(key, mbedtls_pk_write_pubkey_pem, err_buf, err_buf_length);
}

static void log_keys(mbedtls_pk_context * key, char* err_buf, size_t err_buf_length)
{
  log_private_key(key, err_buf, err_buf_length);
  log_public_key(key, err_buf, err_buf_length);
}


static int generate_key(mbedtls_pk_context * key, char* err_buf, size_t err_buf_length)
{
  int err;

  LOG_INF(&amp;quot;Generating key pairs, it takes ~3 sec.&amp;quot;);
  mbedtls_pk_init(key);
  if ((err = mbedtls_pk_setup(key, mbedtls_pk_info_from_type( MBEDTLS_PK_ECKEY))) != 0)
  {
    mbedtls_strerror(err, err_buf, err_buf_length);
    LOG_ERR(&amp;quot;Can&amp;#39;t setup key context -0x%04x - %s\n\n&amp;quot;, (unsigned int) -err, err_buf);
    return err;
  }

  err = mbedtls_ecp_gen_key(MBEDTLS_ECP_DP_SECP256R1, /*ec_curve,*/
                            mbedtls_pk_ec(*key),
                            gen_true_random_number, NULL );
  if (err != 0)
  {
    mbedtls_strerror(err, err_buf, err_buf_length);
    LOG_ERR(&amp;quot;Can not generate key -0x%04x - %s\n\n&amp;quot;, (unsigned int) -err, err_buf);
    return err;
  }
  LOG_INF( &amp;quot;Key pair generated.&amp;quot;);

  return 0;
}

// https://tls.mbed.org/kb/how-to/generate-a-self-signed-certificate
// https://github.com/ARMmbed/mbedtls/blob/development/programs/pkey/gen_key.c
/*
  Check whether the generated key pair are right:
  1. log_keys(&amp;amp;key)
  2. Copy the content into private_key.pem, public_key.pem
  3. Verify them with a sign and verify process
    cat blablabla &amp;gt; bla.txt
    openssl dgst -sha1 -sign private_key.pem bla.txt &amp;gt; signature.bin
    openssl dgst -sha1 -verify public_key.pem -signature signature.bin bla.txt
*/
void main(void)
{
  char err_buf[512];

  mbedtls_pk_context key;
 
  if (generate_key(&amp;amp;key, err_buf, sizeof(err_buf)) != 0)
    return;

  log_keys(&amp;amp;key, err_buf, sizeof(err_buf));

  mbedtls_pk_free(&amp;amp;key);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;That&amp;#39;s it.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The x509 certificate creation needs more setup and code but because it&amp;#39;s not needed I don&amp;#39;t post it.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;&amp;Aacute;rp&amp;aacute;d&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF91 How is it possible to generate EC 256 key pair and a self-signed X.509 certificate?</title><link>https://devzone.nordicsemi.com/thread/263073?ContentTypeID=1</link><pubDate>Tue, 04 Aug 2020 16:19:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d8c48cd2-99e1-454f-b906-2ad5a632ce84</guid><dc:creator>PopradiArpad</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;thank you for your answer!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;to mbedTLS configuration&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;It&amp;#39;s really much easier to configure mbedTLS directly by an mbedTLS config file then through the predefined&amp;nbsp;Zephyr config symbols. The only tricky part was having that file within my project.&lt;/p&gt;
&lt;p&gt;But this &lt;strong&gt;prj.conf&lt;/strong&gt; snippets does it:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;# Generate credentials
CONFIG_MBEDTLS=y
# Configure mbedTLS directly with its configuration file instead through Zephyr config symbols
# Relative from ncs/modules/crypto/mbedtls/configs/config-tls-generic.h
CONFIG_MBEDTLS_CFG_FILE=&amp;quot;../../../../MY-PROJECT/config-tls.h&amp;quot;
&lt;/pre&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Writing the config file is easy: all the&amp;nbsp;missing mbedTLS config definitions are checked by mbedTLS itself&lt;/p&gt;
&lt;p&gt;during compilation or in case of a link error it&amp;#39;s easy to find by the guard macro name.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;to the secure service causing crash:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;later.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;&amp;Aacute;rp&amp;aacute;d&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF91 How is it possible to generate EC 256 key pair and a self-signed X.509 certificate?</title><link>https://devzone.nordicsemi.com/thread/262911?ContentTypeID=1</link><pubDate>Tue, 04 Aug 2020 07:55:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:877d09a0-adc0-4e1e-a104-7908c9762237</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Árpád,&lt;/p&gt;
[quote user="PopradiArpad"]thanks for the hint. By trying to follow it, I get trapped by &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/60850/nrf9160-secure-services-causing-a-crash"&gt;secure service causing a crash&lt;/a&gt;.&amp;nbsp;[/quote]
&lt;p&gt;I see. Have you applied the &lt;a href="https://github.com/nrfconnect/sdk-nrf/pull/2519/files"&gt;workaround&lt;/a&gt;?&lt;/p&gt;
[quote user="PopradiArpad"]How can I create and use such a config file without&amp;nbsp;messing up Nordic&amp;#39;s mbedtls configuration?[/quote]
&lt;p&gt;I have not had a chance to test this myself, but I would not expect setting&amp;nbsp;MBEDTLS_PK_WRITE_C in the mbedTLS config header file would mess up anything? In what way does it cause problems?&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF91 How is it possible to generate EC 256 key pair and a self-signed X.509 certificate?</title><link>https://devzone.nordicsemi.com/thread/262838?ContentTypeID=1</link><pubDate>Mon, 03 Aug 2020 14:49:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc219ca7-689f-4d80-a01d-0d80792e11ae</guid><dc:creator>PopradiArpad</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;thanks for the hint. By trying to follow it, I get trapped by &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/60850/nrf9160-secure-services-causing-a-crash"&gt;secure service causing a crash&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And I have other problem too: I want to print out the created keys to the console with&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;mbedtls_pk_write_pubkey_pem&lt;/strong&gt; and&amp;nbsp;&lt;strong&gt;mbedtls_pk_write_key_pem&lt;/strong&gt;&amp;nbsp;but they need&lt;/p&gt;
&lt;p&gt;MBEDTLS_PK_WRITE_C to be defined, which needs a specialized mbedtls config file.&lt;/p&gt;
&lt;p&gt;(At least I have not found a Zephyr Kconfig macro to accomplish this.)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;How can I create and use such a config file without&amp;nbsp;messing up Nordic&amp;#39;s mbedtls configuration?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;&amp;Aacute;rp&amp;aacute;d&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF91 How is it possible to generate EC 256 key pair and a self-signed X.509 certificate?</title><link>https://devzone.nordicsemi.com/thread/262372?ContentTypeID=1</link><pubDate>Thu, 30 Jul 2020 10:54:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f6bb960-f728-4212-a11d-e4a10db10276</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Árpád,&lt;/p&gt;
&lt;p&gt;I cannot comment on when new features will be available, unfortunately. However, I see I was a bit too pessimistic in my previous reply. You can in fact make your own solution, and use the RNG support in the CC310 via the Secure Partition Manager, which has the&amp;nbsp;spm_request_random_number() function. See &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/include/secure_services.html"&gt;Secure services&lt;/a&gt;. This just gives you entropy, and then you can use a pure SW library of your preference for the rest.&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF91 How is it possible to generate EC 256 key pair and a self-signed X.509 certificate?</title><link>https://devzone.nordicsemi.com/thread/262224?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2020 14:01:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:341d1930-0887-478e-9f2d-d9e42f8f70cb</guid><dc:creator>PopradiArpad</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;thank you for your fast answer. I understand ongoing work :)&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Approximately when do you have a proper solution?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;&amp;Aacute;rp&amp;aacute;d&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF91 How is it possible to generate EC 256 key pair and a self-signed X.509 certificate?</title><link>https://devzone.nordicsemi.com/thread/262220?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2020 13:28:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e102433f-8a20-49ee-80e6-23b5b147ae32</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Árpád,&lt;/p&gt;
&lt;p&gt;This is not straightforward.&lt;/p&gt;
&lt;p&gt;[quote user="PopradiArpad"][/quote]&lt;/p&gt;
&lt;p&gt;Why does the mbedTLS depends on CONFIG_NORDIC_SECURITY_BACKEND?&lt;/p&gt;
&lt;p&gt;mbedTLS is a standalone lib, why is this dependency?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You need an entropy source in order to generate random numbers, and the only entropy source available to the application on the nRF9160 is the TRNG within the CC310 peripheral. The API for the CC310 in the nRF Connect SDK is mbed TLS, via the nordic security backend. This is still ongoing work, though. We do not have a proper solution ready at the moment.&lt;/p&gt;
&lt;p&gt;It might be better to find some other way to generate the X509 certificate in pure SW, but in that case, it would only be for experimentation, as you will not have a usable secure solution without a proper entropy source.&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF91 How is it possible to generate EC 256 key pair and a self-signed X.509 certificate?</title><link>https://devzone.nordicsemi.com/thread/262209?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2020 13:07:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e82e8c5-da13-4559-b628-2cfd59ee095f</guid><dc:creator>PopradiArpad</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;thank you for your reply.&amp;nbsp;Unfortunately&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_MBEDTLS_X509_LIBRARY=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;depends on&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_NORDIC_SECURITY_BACKEND=y
CONFIG_MBEDTLS_CFG_FILE=&amp;quot;config-tls-generic.h&amp;quot;&lt;/pre&gt;&lt;br /&gt;and the compilation results in:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;get_target_property() called with non-existent target &amp;quot;platform_cc310&amp;quot;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I build for&amp;nbsp;&lt;strong&gt;nrf9160dk_nrf9160ns&lt;/strong&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;How can I setup&amp;nbsp;prj.conf to get the mbedTLS X509 module?&lt;/p&gt;
&lt;p&gt;Why does the mbedTLS depends on CONFIG_NORDIC_SECURITY_BACKEND?&lt;/p&gt;
&lt;p&gt;mbedTLS is a standalone lib, why is this dependency?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Here are my mbed config settings:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;# Generate keys
CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED=y
CONFIG_MBEDTLS_ENTROPY_ENABLED=y
# Create certificate
CONFIG_MBEDTLS_CFG_FILE=&amp;quot;config-tls-generic.h&amp;quot;
CONFIG_NORDIC_SECURITY_BACKEND=y
# Why this depends on CONFIG_NORDIC_SECURITY_BACKEND??
CONFIG_MBEDTLS_X509_LIBRARY=y
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;&amp;Aacute;rp&amp;aacute;d&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF91 How is it possible to generate EC 256 key pair and a self-signed X.509 certificate?</title><link>https://devzone.nordicsemi.com/thread/262039?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2020 15:01:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74da82ff-7e74-4d60-8a56-aef2b06b66ca</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Árpád,&lt;/p&gt;
&lt;p&gt;I would assume that you could do this using the &lt;a href="https://tls.mbed.org/api/group__x509__module.html"&gt;X.509 module&lt;/a&gt;&amp;nbsp;in mbed TLS. It has support for building X509 certificates. I have not tested this myself though, and cannot provide any more details.&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF91 How is it possible to generate EC 256 key pair and a self-signed X.509 certificate?</title><link>https://devzone.nordicsemi.com/thread/261547?ContentTypeID=1</link><pubDate>Fri, 24 Jul 2020 09:33:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:091ce497-c64b-430d-88aa-3f5c14ba8b15</guid><dc:creator>PopradiArpad</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;that is&amp;nbsp;partially answer to my question. Thank you.&lt;/p&gt;
&lt;p&gt;The rest of the question is:&lt;/p&gt;
&lt;p&gt;is it possible -and if yes how- to generate elliptic curve keys and an x509 certificate needed by Google Cloud IoT on the nRF9160?&lt;/p&gt;
&lt;p&gt;The generation with openssl on a desktop machine is described here:&lt;/p&gt;
&lt;div&gt;&lt;a href="https://cloud.google.com/iot/docs/how-tos/credentials/keys#generating_an_elliptic_curve_keys"&gt;https://cloud.google.com/iot/docs/how-tos/credentials/keys#generating_an_elliptic_curve_keys&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;&lt;a href="https://cloud.google.com/iot/docs/how-tos/credentials/keys#generating_an_es256_key_with_a_self-signed_x509_certificate"&gt;https://cloud.google.com/iot/docs/how-tos/credentials/keys#generating_an_es256_key_with_a_self-signed_x509_certificate&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;I want to know whether it&amp;#39;s possible to do the same - of course not with openssl- on the device itself.&lt;/p&gt;
&lt;p&gt;Probably with the nrf_oberon crypto library?&lt;/p&gt;
&lt;p&gt;For example I found &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/crypto/doc/api.html#_CPPv429ocrypto_ecdsa_p256_public_keyAL64E_7uint8_tAL32E_K7uint8_t"&gt;ocrypto_ecdsa_p256_public_key&lt;/a&gt;&amp;nbsp;in the nrf_oberon lib,&amp;nbsp;but how to make an X509 certificate?&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/crypto/doc/api.html#_CPPv429ocrypto_ecdsa_p256_public_keyAL64E_7uint8_tAL32E_K7uint8_t"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;With kind regards,&lt;/p&gt;
&lt;p&gt;&amp;Aacute;rp&amp;aacute;d&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF91 How is it possible to generate EC 256 key pair and a self-signed X.509 certificate?</title><link>https://devzone.nordicsemi.com/thread/261468?ContentTypeID=1</link><pubDate>Thu, 23 Jul 2020 20:54:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7fc21549-172a-4517-b6e4-87d9ddbe6c3e</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I got an answer on how to go about this:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;em&gt;&amp;quot;DER is just a binary encoded PEM.&amp;nbsp; they can use base64_decode(), passing in the base64 text from the PEM (data between&amp;nbsp;the BEGIN/END lines).&amp;nbsp;&lt;/em&gt;&lt;/p&gt;
&lt;div style="padding-left:30px;"&gt;
&lt;div style="padding-left:30px;"&gt;&lt;em&gt;verify using openssl:&lt;/em&gt;&lt;/div&gt;
&lt;div style="padding-left:30px;"&gt;&lt;em&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div style="padding-left:30px;"&gt;&lt;em&gt;openssl x509 -outform der -in pem_in.pem -out der_out.crt&amp;quot;&lt;/em&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Simon&lt;em&gt;&lt;br /&gt;&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF91 How is it possible to generate EC 256 key pair and a self-signed X.509 certificate?</title><link>https://devzone.nordicsemi.com/thread/261268?ContentTypeID=1</link><pubDate>Wed, 22 Jul 2020 20:00:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6977aca6-119f-4012-82aa-b81eb89d686e</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I&amp;#39;m sorry for the delay, somehow I left this ticket behind and forgot to do further investigation. I have asked some developers internally and currently waiting for an answer.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF91 How is it possible to generate EC 256 key pair and a self-signed X.509 certificate?</title><link>https://devzone.nordicsemi.com/thread/259660?ContentTypeID=1</link><pubDate>Mon, 13 Jul 2020 10:17:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c758d52-bf23-488b-adb5-fc13830f48ca</guid><dc:creator>PopradiArpad</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;thank your for your reply, but my question is how to generate all of this ON the nRF9160. Because if that would be possible&lt;/p&gt;
&lt;p&gt;than the private key should not leave the device ensuring a higher security level compared to generating these keys outside of the device and transmitting over some channel.&lt;/p&gt;
&lt;p&gt;Could you please ask for that? It would be good,&amp;nbsp;if the key generation could happen on the device.&lt;/p&gt;
&lt;p&gt;With kind regards,&lt;/p&gt;
&lt;p&gt;&amp;Aacute;rp&amp;aacute;d&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF91 How is it possible to generate EC 256 key pair and a self-signed X.509 certificate?</title><link>https://devzone.nordicsemi.com/thread/259589?ContentTypeID=1</link><pubDate>Sun, 12 Jul 2020 21:40:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:59762f06-6baa-4100-a65f-1892c14e5c30</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I &lt;a href="https://support.ssl.com/Knowledgebase/Article/View/19/0/der-vs-crt-vs-cer-vs-pem-certificates-and-how-to-convert-them"&gt;this link&lt;/a&gt; useful? I don&amp;#39;t know too much about this, but I can do some more investigation and&amp;nbsp;ask internally if the link didn&amp;#39;t help.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>