SWRU455M February 2017 – October 2020 CC3120 , CC3120MOD , CC3130 , CC3135 , CC3135MOD , CC3220MOD , CC3220MODA , CC3220R , CC3220S , CC3220SF , CC3230S , CC3230SF , CC3235MODAS , CC3235MODASF , CC3235MODS , CC3235MODSF , CC3235S , CC3235SF
This command is used to create a self-signed certificate or a certificate signing request (CSR) with one of the installed keys, device unique key-pair or the temporary key.
It is possible to set the attributes of the certificate. The self-signed certificate is stored at the file system upon creation in "/cert/iot/cert.der" and the CSR is stored in "/cert/iot/csr.der and can be retrieved using the sl_FsRead command. The creation of either a self-signed certificate or CSR is selected by choosing the right sub option from the following values:
Example of creating CSR:
uint16_t retVal;
uint8_t i;
uint8_t udid[16];
SlNetUtilCryptoCmdCreateCertAttrib_t certCmd;
uint32_t certVersion;
uint32_t certSerial;
uint32_t certSigType;
uint32_t certDaysValid;
uint32_t certIsCa;
uint8_t* certSubjectCountry;
uint8_t* certSubjectState;
uint8_t* certSubjectLocality;
uint8_t* certSubjectSur;
uint8_t* certSubjectCommonName;
uint8_t* certSubjectOrg;
uint8_t* certSubjectOrgUnit;
uint8_t* certSubjectEmail;
uint16_t outputLen = 0;
/* initialize the creation process */
certCmd.SubCmd = SL_NETUTIL_CRYPTO_CERT_INIT;
certCmd.ObjId = SL_NETUTIL_CRYPTO_SERVICES_IOT_RESERVED_INDEX;
certCmd.Flags = 0;
retVal = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_CREATE_CERT,
(uint8_t*)&certCmd,sizeof(certCmd),
NULL,0,
NULL,&outputLen);
if(0 != retVal) return retVal;
/*
* set the version of the certificate
* this number represent the version of the encoded certificate.
* 0=v1, 1=v2, 2=v3
* the SimpleLink device support only v3
*
*/
certCmd.SubCmd = SL_NETUTIL_CRYPTO_CERT_VER;
certVersion = 2;
retVal = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_CREATE_CERT,
(uint8_t*)&certCmd, sizeof(SlNetUtilCryptoCmdCreateCertAttrib_t),
(uint8_t*)&certVersion, sizeof(certVersion),
NULL, &outputLen);
if(0 != retVal) return retVal;
/*
* set a serial number for the certificate
* this serial number must be a positive integer unique number per issuer name
* (i.e., the issuer name and serial number identify a unique certificate, every time a
* certificate is generated on a device, the serial number must be changed)
* the simplelink device allow serial number of up to 8 bytes (64bits)
*
*/
certCmd.SubCmd = SL_NETUTIL_CRYPTO_CERT_SERIAL;
certSerial = 0x00000001;
retVal = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_CREATE_CERT,
(uint8_t*)&certCmd, sizeof(SlNetUtilCryptoCmdCreateCertAttrib_t),
(uint8_t*)&certSerial, sizeof(certSerial),
NULL, &outputLen);
if(0 != retVal) return retVal;
/*
* set the signature type of the certificate
* the type represent the algorithm used
* by the device to sign the certificate
* the simplelink device support only SL_UTILS_CRYPTO_SIG_SHAwECDSA for certificate generation
*
*/
certCmd.SubCmd = SL_NETUTIL_CRYPTO_CERT_SIG_TYPE;
certSigType = SL_NETUTIL_CRYPTO_SIG_SHAwECDSA;
retVal = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_CREATE_CERT,
(uint8_t*)&certCmd, sizeof(SlNetUtilCryptoCmdCreateCertAttrib_t),
(uint8_t*)&certSigType, sizeof(certSigType),
NULL, &outputLen);
if(0 != retVal) return retVal;
/*
* set validity period of the certificate
* the validity period dates defined from now until now + daysValid
*
*/
certCmd.SubCmd = SL_NETUTIL_CRYPTO_CERT_DAYS_VALID;
certDaysValid = 365*3;
retVal = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_CREATE_CERT,
(uint8_t *)&certCmd, sizeof(SlNetUtilCryptoCmdCreateCertAttrib_t),
(uint8_t*)&certDaysValid, sizeof(certDaysValid),
NULL, &outputLen);
if(0 != retVal) return retVal;
/*
* define if the certificate is ca certificate
*
*/
certCmd.SubCmd = SL_NETUTIL_CRYPTO_CERT_IS_CA;
certIsCa = 0;
retVal = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_CREATE_CERT,
(uint8_t*)&certCmd, sizeof(SlNetUtilCryptoCmdCreateCertAttrib_t),
(uint8_t*)&certIsCa, sizeof(certIsCa),
NULL, &outputLen);
if(0 != retVal) return retVal;
/*
* Set subject country
*/
certCmd.SubCmd = SL_NETUTIL_CRYPTO_CERT_SUBJECT_COUNTRY;
certSubjectCountry = "US";
retVal = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_CREATE_CERT,
(uint8_t*)&certCmd, sizeof(SlNetUtilCryptoCmdCreateCertAttrib_t),
certSubjectCountry, (strlen((char *)certSubjectCountry)+1),
NULL, &outputLen);
if(0 != retVal) return retVal;
/*
* Set subject state
*/
certCmd.SubCmd = SL_NETUTIL_CRYPTO_CERT_SUBJECT_STATE;
certSubjectState = "Texas";
retVal = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_CREATE_CERT,
(uint8_t*)&certCmd, sizeof(SlNetUtilCryptoCmdCreateCertAttrib_t),
certSubjectState, (strlen((char *)certSubjectState)+1),
NULL, &outputLen);
if(0 != retVal) return retVal;
/*
* Set the subject locality
*/
certCmd.SubCmd = SL_NETUTIL_CRYPTO_CERT_SUBJECT_LOCALITY;
certSubjectLocality = "Dallas";
retVal = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_CREATE_CERT,
(uint8_t*)&certCmd, sizeof(SlNetUtilCryptoCmdCreateCertAttrib_t),
certSubjectLocality, (strlen((char *)certSubjectLocality)+1),
NULL, &outputLen);
if(0 != retVal) return retVal;
/*
* Set the subject surname
*/
certCmd.SubCmd = SL_NETUTIL_CRYPTO_CERT_SUBJECT_SUR;
certSubjectSur = "Jack";
retVal = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_CREATE_CERT,
(uint8_t*)&certCmd, sizeof(SlNetUtilCryptoCmdCreateCertAttrib_t),
certSubjectSur, (strlen((char *)certSubjectSur)+1),
NULL, &outputLen);
if(0 != retVal) return retVal;
/*
* Set the subject organization
*/
certCmd.SubCmd = SL_NETUTIL_CRYPTO_CERT_SUBJECT_ORG;
certSubjectOrg = "Texas Instruments";
retVal = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_CREATE_CERT,
(uint8_t*)&certCmd, sizeof(SlNetUtilCryptoCmdCreateCertAttrib_t),
certSubjectOrg, (strlen((char *)certSubjectOrg)+1),
NULL, &outputLen);
if(0 != retVal) return retVal;
/*
* Set the subject organization unit
*/
certCmd.SubCmd = SL_NETUTIL_CRYPTO_CERT_SUBJECT_ORG_UNIT;
certSubjectOrgUnit = "ECS";
retVal = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_CREATE_CERT,
(uint8_t*)&certCmd, sizeof(SlNetUtilCryptoCmdCreateCertAttrib_t),
certSubjectOrgUnit, (strlen((char *)certSubjectOrgUnit)+1),
NULL, &outputLen);
if(0 != retVal) return retVal;
/*
* Set the subject common name
*/
certCmd.SubCmd = SL_NETUTIL_CRYPTO_CERT_SUBJECT_COMMON_NAME;
certSubjectCommonName = "SimpleLink-1234";
retVal = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_CREATE_CERT,
(uint8_t*)&certCmd, sizeof(SlNetUtilCryptoCmdCreateCertAttrib_t),
certSubjectCommonName, (strlen((char *)certSubjectCommonName)+1),
NULL, &outputLen);
if(0 != retVal) return retVal;
/*
* Set the subject email
*/
certCmd.SubCmd = SL_NETUTIL_CRYPTO_CERT_SUBJECT_EMAIL;
certSubjectEmail = "SimpleLink-1234@ti-iot.com";
retVal = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_CREATE_CERT,
(uint8_t*)&certCmd, sizeof(SlNetUtilCryptoCmdCreateCertAttrib_t),
certSubjectEmail, (strlen((char *)certSubjectEmail)+1),
NULL, &outputLen);
if(0 != retVal) return retVal;
/*
* Close the process and create the certificate
*/
certCmd.SubCmd = SL_NETUTIL_CRYPTO_CSR_SAVE;
retVal = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_CREATE_CERT,
(uint8_t*)&certCmd, sizeof(SlNetUtilCryptoCmdCreateCertAttrib_t),
NULL, 0,
NULL, &outputLen);