/* * FreeRTOS STM32 Reference Integration * Copyright (C) 2020-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #define MBEDTLS_ALLOW_PRIVATE_ACCESS /* FreeRTOS */ #include "FreeRTOS.h" #include "message_buffer.h" #include "task.h" /* Project Specific */ #include "cli.h" #include "cli_prv.h" #include "logging.h" #include "kvstore.h" /* Standard Lib */ #include #include #include "tls_transport_config.h" #include "mbedtls_transport.h" #ifdef MBEDTLS_TRANSPORT_PKCS11 /* PKCS11 */ #include "pkcs11.h" #include "core_pkcs11_config.h" #include "core_pkcs11.h" #include "core_pki_utils.h" #endif /* MBEDTLS_TRANSPORT_PKCS11 */ /* Mbedtls */ #include "mbedtls/pem.h" #include "mbedtls/base64.h" #include "mbedtls/x509_csr.h" #include "mbedtls/x509_crt.h" #include "mbedtls/x509.h" #include "mbedtls/entropy.h" #include "mbedtls/ctr_drbg.h" #include "mbedtls/pk.h" #include "mbedtls/platform.h" #include "pk_wrap.h" #include "mbedtls/ecp.h" #define LABEL_PUB_IDX 3 #define LABEL_PRV_IDX 4 #define LABEL_IDX LABEL_PUB_IDX #define PEM_CERT_MAX_LEN 2048 #define PEM_LINE_ENDING "\n" #define PEM_LINE_ENDING_LEN 1 #define PEM_BEGIN "-----BEGIN " #define PEM_END "-----END " #define PEM_META_SUFFIX "-----" /* Local static functions */ static void vCommand_PKI( ConsoleIO_t * pxCIO, uint32_t ulArgc, char * ppcArgv[] ); const CLI_Command_Definition_t xCommandDef_pki = { .pcCommand = "pki", .pcHelpString = "pki:\r\n" " Perform public/private key operations.\r\n" " Usage:\r\n" " pki \r\n" " Valid verbs are { generate, import, export, list }\r\n" " Valid object types are { key, csr, cert }\r\n" " Arguments should be specified in -- \r\n\n" " pki generate key \r\n" " Generates a new private key to be stored in the specified labels\r\n\n" " pki generate csr