Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Crea un gestore di certificati personalizzato per l'archiviazione sicura
La gestione dei certificati dei dispositivi è fondamentale per l'onboarding dell'hub di integrazioni gestite. Sebbene i certificati siano archiviati nel file system per impostazione predefinita, puoi creare un gestore di certificati personalizzato per una maggiore sicurezza e una gestione flessibile delle credenziali.
L'SDK per le integrazioni gestite End device fornisce un gestore di certificati per proteggere l'interfaccia di archiviazione che puoi implementare come libreria di oggetti condivisi (.so). Crea la tua implementazione di archiviazione sicura per leggere e scrivere certificati, quindi collega il file della libreria al processo in fase di esecuzione. HubOnboarding
Definizione e componenti dell'API
Consulta il seguente secure_storage_cert_handler_interface.hpp
file per comprendere i componenti e i requisiti dell'API per la tua implementazione
Definizione dell'API
Contenuto di secure_storage_cert_hander_interface.hpp
:
/* * Copyright 2024 Amazon.com, Inc. or its affiliates. All rights reserved. * * AMAZON PROPRIETARY/CONFIDENTIAL * * You may not use this file except in compliance with the terms and * conditions set forth in the accompanying LICENSE.txt file. * * THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS. AMAZON SPECIFICALLY * DISCLAIMS, WITH RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS, * IMPLIED, OR STATUTORY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. */ #ifndef SECURE_STORAGE_CERT_HANDLER_INTERFACE_HPP #define SECURE_STORAGE_CERT_HANDLER_INTERFACE_HPP #include <iostream> #include <memory> namespace IoTManagedIntegrationsDevice { namespace CertHandler { /** * @enum CERT_TYPE_T * @brief enumeration defining certificate types. */ typedef enum { CLAIM = 0, DHA = 1, PERMANENT = 2 } CERT_TYPE_T; class SecureStorageCertHandlerInterface { public: /** * @brief Read certificate and private key value of a particular certificate * type from secure storage. */ virtual bool read_cert_and_private_key(const CERT_TYPE_T cert_type, std::string &cert_value, std::string &private_key_value) = 0; /** * @brief Write permanent certificate and private key value to secure storage. */ virtual bool write_permanent_cert_and_private_key( std::string_view cert_value, std::string_view private_key_value) = 0; }; std::shared_ptr<SecureStorageCertHandlerInterface> createSecureStorageCertHandler(); } //namespace CertHandler } //namespace IoTManagedIntegrationsDevice #endif //SECURE_STORAGE_CERT_HANDLER_INTERFACE_HPP
Componenti chiave
-
CERT_TYPE_T: diversi tipi di certificati sull'hub.
-
CLAIM: il certificato di reclamo originariamente presente nell'hub verrà sostituito con un certificato permanente.
-
DHA: inutilizzato per ora.
-
PERMANENTE: certificato permanente per la connessione con l'endpoint delle integrazioni gestite.
-
-
read_cert_and_private_key - (FUNZIONE DA IMPLEMENTARE) Legge il certificato e il valore della chiave nell'input di riferimento. Questa funzione deve essere in grado di leggere sia il certificato CLAIM che quello PERMANENT ed è differenziata in base al tipo di certificato sopra menzionato.
-
write_permanent_cert_and_private_key - (FUNZIONE DA IMPLEMENTARE) scrive il certificato permanente e il valore della chiave nella posizione desiderata.
Esempio di build
Separa le intestazioni di implementazione interne dall'interfaccia pubblica (secure_storage_cert_handler_interface.hpp
) per mantenere una struttura di progetto pulita. Con questa separazione, puoi gestire i componenti pubblici e privati mentre crei il tuo gestore di certificati.
Nota
Dichiara secure_storage_cert_handler_interface.hpp
come pubblico.
Struttura del progetto

Eredita l'interfaccia
Crea una classe concreta che erediti l'interfaccia. Nascondi questo file di intestazione e altri file in una directory separata in modo che le intestazioni private e pubbliche possano essere facilmente differenziate durante la creazione.
#ifndef IOTMANAGEDINTEGRATIONSDEVICE_SDK_STUB_SECURE_STORAGE_CERT_HANDLER_HPP #define IOTMANAGEDINTEGRATIONSDEVICE_SDK_STUB_SECURE_STORAGE_CERT_HANDLER_HPP #include "secure_storage_cert_handler_interface.hpp" namespace IoTManagedIntegrationsDevice::CertHandler { class StubSecureStorageCertHandler : public SecureStorageCertHandlerInterface { public: StubSecureStorageCertHandler() = default; bool read_cert_and_private_key(const CERT_TYPE_T cert_type, std::string &cert_value, std::string &private_key_value) override; bool write_permanent_cert_and_private_key( std::string_view cert_value, std::string_view private_key_value) override; /* * any other resource for function you might need */ }; } #endif //IOTMANAGEDINTEGRATIONSDEVICE_SDK_STUB_SECURE_STORAGE_CERT_HANDLER_HPP
Implementazione
Implementa la classe di archiviazione definita sopra,. src/stub_secure_storage_cert_handler.cpp
/* * Copyright 2024 Amazon.com, Inc. or its affiliates. All rights reserved. * * AMAZON PROPRIETARY/CONFIDENTIAL * * You may not use this file except in compliance with the terms and * conditions set forth in the accompanying LICENSE.txt file. * * THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS. AMAZON SPECIFICALLY * DISCLAIMS, WITH RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS, * IMPLIED, OR STATUTORY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. */ #include "stub_secure_storage_cert_handler.hpp" using namespace IoTManagedIntegrationsDevice::CertHandler; bool StubSecureStorageCertHandler::write_permanent_cert_and_private_key( std::string_view cert_value, std::string_view private_key_value) { // TODO: implement write function return true; } bool StubSecureStorageCertHandler::read_cert_and_private_key(const CERT_TYPE_T cert_type, std::string &cert_value, std::string &private_key_value) { std::cout<<"Using Stub Secure Storage Cert Handler, returning dummy values"; cert_value = "StubCertVal"; private_key_value = "StubKeyVal"; // TODO: implement read function return true; }
Implementa la funzione di fabbrica definita nell'interfaccia,src/secure_storage_cert_handler.cpp
.
#include "stub_secure_storage_cert_handler.hpp" std::shared_ptr<IoTManagedIntegrationsDevice::CertHandler::SecureStorageCertHandlerInterface> IoTManagedIntegrationsDevice::CertHandler::createSecureStorageCertHandler() { // TODO: replace with your implementation return std::make_shared<IoTManagedIntegrationsDevice::CertHandler::StubSecureStorageCertHandler>(); }
CMakeList.txt
#project name must stay the same project(SecureStorageCertHandler) # Public Header files. The interface definition must be in top level with exactly the same name #ie. Not in anotherDir/secure_storage_cert_hander_interface.hpp set(PUBLIC_HEADERS ${PROJECT_SOURCE_DIR}/include ) # private implementation headers. set(PRIVATE_HEADERS ${PROJECT_SOURCE_DIR}/internal/stub ) #set all sources set(SOURCES ${PROJECT_SOURCE_DIR}/src/secure_storage_cert_handler.cpp ${PROJECT_SOURCE_DIR}/src/stub_secure_storage_cert_handler.cpp ) # Create the shared library add_library(${PROJECT_NAME} SHARED ${SOURCES}) target_include_directories( ${PROJECT_NAME} PUBLIC ${PUBLIC_HEADERS} PRIVATE ${PRIVATE_HEADERS} ) # Set the library output location. Location can be customized but version must stay the same set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../lib VERSION 1.0 SOVERSION 1 ) # Install rules install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib ) install(FILES ${HEADERS} DESTINATION include/SecureStorageCertHandler )
Utilizzo
Dopo la compilazione, avrai un file di libreria di oggetti libSecureStorageCertHandler.so
condiviso e i relativi link simbolici associati. Copiate sia il file di libreria che i collegamenti simbolici nella posizione della libreria prevista dal file binario. HubOnboarding
Considerazioni chiave
-
Verifica che il tuo account utente disponga delle autorizzazioni di lettura e scrittura sia per il HubOnboarding file binario che per la libreria.
libSecureStorageCertHandler.so
-
Conservalo
secure_storage_cert_handler_interface.hpp
come unico file di intestazione pubblico. Tutti gli altri file di intestazione devono rimanere nell'implementazione privata. -
Verifica il nome della tua libreria di oggetti condivisi. Durante la compilazione
libSecureStorageCertHandler.so
, HubOnboarding potrebbe essere necessaria una versione specifica nel nome del file, ad esempio.libSecureStorageCertHandler.so.1.0
Utilizzate illdd
comando per controllare le dipendenze delle librerie e creare collegamenti simbolici secondo necessità. -
Se l'implementazione della libreria condivisa ha dipendenze esterne, memorizzale in una directory HubOnboarding accessibile, ad esempio una directory.
/usr/lib or the iotmi_common
Usa l'archiviazione sicura
Aggiorna il iotmi_config.json
file impostando entrambe le impostazioni iot_claim_cert_path
e iot_claim_pk_path
suSECURE_STORAGE
.
{ "ro": { "iot_provisioning_method": "FLEET_PROVISIONING", "iot_claim_cert_path": "
SECURE_STORAGE
", "iot_claim_pk_path": "SECURE_STORAGE
", "fp_template_name": "device-integration-example", "iot_endpoint_url": "[ACCOUNT-PREFIX
]-ats.iot.AWS-REGION
.amazonaws.com", "SN": "1234567890", "UPC": "1234567890" }, "rw": { "iot_provisioning_state": "NOT_PROVISIONED" } }