Hardware:
software:
[Beginner's Guide] How to Build Yocto Linux BSP - i.MX FRDM Board Edition (Japanese Blog)
repo init -u https://github.com/nxp-imx/imx-manifest -b imx-linux-whinlatter -m imx-6.18.2-1.0.0.xml
DISTRO=fsl-imx-wayland MACHINE=imx93-11x11-lpddr4x-frdm source imx-setup-release.sh -b ./buildPKCS#11 (Public-Key Cryptography Standards #11) is an API specification for unified use of cryptographic hardware and software (e.g., HSMs, smart cards, USB tokens, etc.) from applications. It is also known as "Cryptoki".
For this example, we will use pkcs11-tool as the application that uses PKCS#11.
The relationship including imx-smw can be illustrated as follows:
PKCS#11を使用するアプリケーション(pkcs11-tool etc.)
↓ (PKCS#11 API経由での使用)
imx-smw
↓
imx-secure-enclave
↓
EdgeLock Secure Enclave HardwareFurthermore, in a previous article on using SE050 via OpenSSL , we explained how to use it via openssl using the openssl provider included in Plug and Trust Middleware.
SMW does not provide an openssl provider, but it is possible to use ELE via openssl because the PKCS#11 interface can be used from openssl by using the pkcs11-provider.
GitHub - openssl-projects/pkcs11-provider: A pkcs#11 provider for OpenSSL 3.0+ · GitHub
The relationship between not using an OpenSSL provider and using imx-smw + PKCS is illustrated below.
When a provider is not used, the key exists as a file on the file system, and encryption is performed by software.
When using imx-smw and pkcs11-provider, the key and encryption process are protected by ELE hardware. The key to be used is specified by a PKCS#11 URI located in the code or on the file system.
Note: Plug and Trust Middleware also provides a PKCS#11 API.
systemctl start nvm_daemon
systemctl status nvm_daemonsystemctl enable nvm_daemonexport MODULE_PKCS11=/usr/lib/libsmw_pkcs11.so.5pkcs11-tool --module $MODULE_PKCS11 -LAvailable slots:
Slot 0 (0x0): Security Middleware Abstraction
token label : smw
token manufacturer : NXP Semiconductor
token model :
token flags : login required, PIN pad present, token initialized
hardware version : 0.0
firmware version : 0.0
serial num :
pin min/max : 0/0
uri : pkcs11:model=;manufacturer=NXP%20Semiconductor;serial=;token=smwpkcs11-tool --module $MODULE_PKCS11 --login -Opkcs11-tool --module $MODULE_PKCS11 \
--login \
--keypairgen \
--key-type EC:prime256v1 \
--id 02 \
--label "MyECCKey" \
--usage-sign \
--allowed-mechanisms "ECDSA-SHA256"Using slot 0 with a present token (0x0)
Profile object 250360144
profile_id: CKP_BASELINE_PROVIDER (1)
Public Key Object; EC EC_POINT 256 bits
EC_POINT: 044104fe4c97a7a4f54702f9fc5740f62c0864e851098dc43cb4c9ba8633421e5bc362cdc559523118bb4fe4281851c051e24a88846a2d774eb3f928595761cf719e90
EC_PARAMS: 06082a8648ce3d030107 (OID 1.2.840.10045.3.1.7)
label: MyECCKey
ID: 02
Usage: verify
Access: none
Unique ID:
uri: pkcs11:model=;manufacturer=NXP%20Semiconductor;serial=;token=smw;id=%02;object=MyECCKey;type=public
Private Key Object; EC
label: MyECCKey
ID: 02
Usage: sign
Access: sensitive, always sensitive
Unique ID:
uri: pkcs11:model=;manufacturer=NXP%20Semiconductor;serial=;token=smw;id=%02;object=MyECCKey;type=privateecho hello > message.txt
pkcs11-tool --module $MODULE_PKCS11 \
--login \
--sign \
--id 02 \
--mechanism ECDSA-SHA256 \
--input-file message.txt \
--output-file signature.bin
pkcs11-tool --module $MODULE_PKCS11 \
--login \
--verify \
--id 02 \
--mechanism ECDSA-SHA256 \
--input-file message.txt \
--signature-file signature.binopenssl_conf = openssl_init
[openssl_init]
providers = provider_sect
[provider_sect]
default = default_sect
pkcs11 = pkcs11_sect
[default_sect]
activate = 1
[pkcs11_sect]
module = /usr/lib/ossl-modules/pkcs11.so
pkcs11-module-path = /usr/lib/libsmw_pkcs11.so.5
activate = 1export OPENSSL_CONF=<作成したopenssl.cnfの絶対path>openssl pkeyutl -sign -inkey "pkcs11:object=MyECCKey;type=private" -in message.txt -out sig.bin -digest sha256
openssl pkeyutl -verify -pubin -inkey "pkcs11:object=MyECCKey;type=public" -in message.txt -sigfile sig.bin -digest sha256python3 uri2pem.py --out MyECCKey.pem "pkcs11:object=MyECCKey;type=private"
Although I haven't been able to confirm the details, based on the contents of uri2pem.py, it seems that it's not possible to create pem files for URIs other than private keys.
By specifying the generated "MyECCKey.pem" as the signing key, you can perform the same actions as before.
openssl pkeyutl -sign -inkey MyECCKey.pem -in message.txt -out sig.bin -digest sha256
openssl pkeyutl -verify -pubin -inkey "pkcs11:object=MyECCKey;type=public" -in message.txt -sigfile sig.bin -digest sha256openssl req -new -key "pkcs11:object=MyECCKey" -outform PEM -subj /CN=frdmimx93_test -out frdmimx93_test.csr -sha256
openssl req -text -noout -in frdmimx93_test.csrNext, move "frdmimx93_test.csr" to the host PC and execute the following:
openssl ecparam -genkey -name prime256v1 -out rootCA_key_pair.pem
openssl req -new -x509 -subj /CN=rootCA -key rootCA_key_pair.pem > rootCA_cert.cer
openssl x509 -req -in frdmimx93_test.csr -days 365 -CA rootCA_cert.cer -CAkey rootCA_key_pair.pem -out frdmimx93_test_cert.cer
Place the created "frdmimx93_test_cert.cer" back onto the FRDM-IMX93. Since it will be used later in conjunction with " MyECCKey.pem ", place it in the same directory where you created it.
Additionally, you will register the created "rootCA_cert.cer" file in Azure IoT Hub and create a device named "frdmimx93_test".
For instructions, please refer to the "Adding an Intermediate CA Certificate to Azure IoT Hub" section in the following article.
Note: As mentioned above, the certificate registered here is for testing purposes only, so it is recommended to delete it after confirming its functionality.
export IOT_HUB_NAME=ShinjiIotHubTest
export DEVICE_NAME=frdmimx93_test
mosquitto_pub -h "${IOT_HUB_NAME}.azure-devices.net" -p 8883 -u "${IOT_HUB_NAME}.azure-devices.net/${DEVICE_NAME}/api-version=2016-11-14" -t "devices/${DEVICE_NAME}/messages/events/" -m '{"mes":"Hello Azure with i.MX93!"}' --capath /etc/ssl/certs/ --cert frdmimx93_test_cert.cer --key MyECCKey.pem -i ${DEVICE_NAME} -d -q 1If you see output similar to the following, it's a success.
Client frdmimx93_test sending CONNECT
Client frdmimx93_test received CONNACK (0)
Client frdmimx93_test sending PUBLISH (d0, q1, r0, m1, 'devices/frdmimx93_test/messages/events/', ... (34 bytes))
Client frdmimx93_test received PUBACK (Mid: 1, RC:0)
Client frdmimx93_test sending DISCONNECT
By following the steps in the article below, "Checking messages sent to IoT Hub and sending messages to devices," you can also check received messages in Cloud Shell on the Azure IoT Hub side.
=========================
We are currently unable to respond to comments left in the " Comment "
section of this post . We apologize for the inconvenience, but please refer to "
Technical Questions to NXP - How to Contact Us( Japanese Blog) " when making inquiries.(If you are already an NXP distributor or have a relationship with NXP, you may ask your representative directly.)