M5Stack Core2 for AWSのSecure Element ATECC608Aをインタラクティブに触ってみる

遅れながらこちらを購入して触ってみました。

www.switch-science.com

触ってみる

触ってみるには、こちらの公式のハンズオンを見てみたり、

edukit.workshop.aws

こちらの記事を参考にすることをオススメします。

qiita.com

インタラクティブかつ簡単にSE(ATECC608A)に命令を送る

本記事の目的はタイトルの通りで、派生のTips的な内容になります。

このデバイスの特徴の一つであるSecure Elementとのやりとりを、色々インタラクティブに試してみたい場合の方法を書きます。

できるだけシンプルにしてるのでESP-IDFのインストールなどは書かずに、基本的なところは揃った前提としてます。

イメージのダウンロード

まずはCore2-for-AWS-IoT-EduKitをダウンロードします。

git clone https://github.com/m5stack/Core2-for-AWS-IoT-EduKit.git
cd Core2-for-AWS-IoT-EduKit/

必要なファイルは実は一つで secure_cert_mfg_esp32.bin です。以下のようにそれぞれのハンズオンシナリオの中に含まれているので、どれでも良いので、どれか一つ選びます。

$ find -name secure_cert_mfg_esp32.bin
./Alexa_for_IoT-Intro/components/esp-cryptoauthlib/esp_cryptoauth_utility/sample_bins/secure_cert_mfg_esp32.bin
./Blinky-Hello-World/components/esp-cryptoauthlib/esp_cryptoauth_utility/sample_bins/secure_cert_mfg_esp32.bin
./Smart-Thermostat/components/esp-cryptoauthlib/esp_cryptoauth_utility/sample_bins/secure_cert_mfg_esp32.bin
./Getting-Started/components/esp-cryptoauthlib/esp_cryptoauth_utility/sample_bins/secure_cert_mfg_esp32.bin
./Hardware-Features-Demo/components/esp-cryptoauthlib/esp_cryptoauth_utility/sample_bins/secure_cert_mfg_esp32.bin
./Factory-Firmware/components/esp-cryptoauthlib/esp_cryptoauth_utility/sample_bins/secure_cert_mfg_esp32.bin

ここでは以下を使います。

./Alexa_for_IoT-Intro/components/esp-cryptoauthlib/esp_cryptoauth_utility/sample_bins/secure_cert_mfg_esp32.bin

機器へのイメージ書き込み

epstool.pyのload_ramでデバイスにロードします。

PORT=/dev/ttyUSB0
IMAGE=./Alexa_for_IoT-Intro/components/esp-cryptoauthlib/esp_cryptoauth_utility/sample_bins/secure_cert_mfg_esp32.bin
esptool.py --chip esp32 --port ${PORT} load_ram ${IMAGE}

以下のように出力され書き込まれます。

esptool.py v3.1
Serial port /dev/ttyUSB0
Connecting........_____.
Chip is ESP32-D0WDQ6-V3 (revision 3)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 08:3a:f2:65:db:70
Uploading stub...
Running stub...
Stub running...
RAM boot...
Downloading 31364 bytes at 3ffb0000... done!
Downloading 456 bytes at 3ffb8f28... done!
Downloading 1028 bytes at 40080000... done!
Downloading 107384 bytes at 40080404... done!
Downloading 4 bytes at 4009a77c... done!
All segments done, executing at 40081bf0
Exiting immediately.

シリアル接続

シリアル接続します。ここでは picocom を使っています。

PORT=/dev/ttyUSB0
picocom ${PORT} -b115200

Enterで待ち受けの >> が表示されます。

Type [C-a] [C-h] to see available commands
Terminal ready
>>

インタラクティブにATECC608Aに命令を送る

実際にATECC608Aに命令を送るにはこちらのデータシートなどを参考に命令を組み立てる必要があって面倒です。

ただ、こちらのイメージからなら以下のような命令を送ることが可能です。

入力命令 説明
init Initialize the ATECC chip on WROOM32SE locks config, data zone if not locked already
print-chip-info Print the Serial Number of the atecc608a chip Serial number is a 9 byte number, unique to every chip
get-tngtls-root-cert get tngtls root cert, which already stored on the device The ATECC608A device type should be TNG ( Trust & G0 )
get-tngtls-signer-cert get tngtls signer cert, which already stored on the device The ATECC608A device type should be TNG ( Trust & GO )
get-tngtls-device-cert get tngtls device cert, which already stored on the device The ATECC608A device type should be TNG ( Trust & GO )

f:id:yomon8:20210724141355p:plain

使い方は以下の部分などが参考になりますので、色々触ってみると理解が進みます。

https://github.com/m5stack/Core2-for-AWS-IoT-EduKit/blob/master/Blinky-Hello-World/components/esp-cryptoauthlib/esp_cryptoauth_utility/helper_scripts/manifest.py#L108