The following example shows how to do Integrity and Confidentiality Protected Update for ECC key.
This folder provides a simplified flow with ready-to-run scripts:
- Step 1: Provision trust anchor + protected update secret + configure target ECC key metadata for protected update
- Step 2: Generate the manifest and the fragment for the ECC key update (payload version is auto-incremented)
- Step 3: Perform the protected update using the generated manifest/fragment
Note: OIDs, file paths, algorithms for ECC Protected Update and metadata settings can be configured in "config.sh".
Run Script: "step1_protected_update_ecc_provisioning.sh"
In "config.sh", OID 0xE0E8 is used as Trust Anchor in this example:
TRUST_ANCHOR_OID="e0e8"
TRUST_ANCHOR_CERT="$CERT_PATH/sample_ec_256_cert.pem"
TRUST_ANCHOR_META="2003E80111"
This script:
- Writes
sample_ec_256_cert.peminto0xE0E8as Trust Anchor (viatrustm_cert) - Writes
TRUST_ANCHOR_METAto0xE0E8to set the data object type to TA (Trust Anchor)
Note: OPTIGA™ Trust M provides two dedicated slots for storing trust anchor certificates:0xE0E8and0xE0E9.
In "config.sh", OID 0xF1D4 is used as Protected Update Secret:
PROTECTED_UPDATE_SECRET_OID="f1d4"
PROTECTED_UPDATE_SECRET="$SECRETPATH/secret.txt"
PROTECTED_UPDATE_SECRET_META="200BD103E1FC07D30100E80123"
This script:
- Writes the secret into
0xF1D4as Protected Update Secret - Writes
PROTECTED_UPDATE_SECRET_METAto0xF1D4to set the data object type to UPDATSEC (Protected Update Secret)
Note: The OID for Protected Update Secret can be chosen from0xF1D4to0xF1DB.
In "config.sh", OID 0xE0F2 is used as the target ECC key object:
TARGET_ECC_OID="e0f2"
TARGET_ECC_OID_META="200dC1020000D00721${TRUST_ANCHOR_OID}FD20${PROTECTED_UPDATE_SECRET_OID}"
Note: The OID for target ECC key protected update can be chosen from 0xE0F1 to 0xE0F3.
This script writes this metadata to 0x$TARGET_ECC_OID.
What this achieves:
- Sets the payload version field (
C1 ...) to0000 - Sets the change access condition for ECC key Protected Update:
- Integrity protection using the configured Trust Anchor OID
- Confidentiality protection using the configured Protected Update Secret OID
For detailed data object type and metadata definitions, please refer to the OPTIGA Trust M Solution Reference Manual.
Run Script: "step2_generate_manifest.sh"
This script does the following:
-
Reads metadata from the target ECC key OID (
0xE0F2) and saves it intoecc_metadata.txt -
Extracts the current payload version from the metadata output
-
Increments payload version
Note: Protected Update requires a monotonically increasing payload version.
In this test scripts:The payload version is automatically incremented by 1 for each new manifest + fragment pair that is generated.
If the payload version reaches the maximum limit, the script prints a warning message.
To reset the payload version, please use
step0_reset_payload_version.sh. -
Generates manifest and fragment for ECC key protected update
These two files are required for Step 3.
Run Script: "step3_protected_update_ecc.sh"
This script performs the ECC key protected update using:
./trustm_protected_update_ecckey -k 0x$TARGET_ECC_OID -f ecc_fragment.dat -m ecc_manifest.dat
If the protected update is successful, the ECC key inside 0x$TARGET_ECC_OID will be updated and the payload version in the object metadata will be updated to the new version used in Step 2.
After the successful ECC key protected update, the script also stores the corresponding public key into OID 0x$ECC_PUBKEY_OID:
./trustm_data -w 0x$ECC_PUBKEY_OID -i "$ECC_PUBKEY_TO_UPDATE" -e
Note: ECC_PUBKEY_OID and ECC_PUBKEY_TO_UPDATE can be configured in "config.sh"
Run Script: "step0_reset_payload_version.sh"
Resets the payload version field in the target ECC key OID metadata.
Run Script: "step0_reset_targetOID_metadata.sh"
Resets the change access condition and payload version for target ECC key OID.
Run Script: "cleanfiles.sh" to clean all the temporary files in the folder.
Run the test scripts inside folder following the sequence: linux-optiga-trust-m/scripts/protected_update_ecckey/:
# Step 1: Provisioning (usually one-time per device)
./step1_protected_update_ecc_provisioning.sh
# Step 2: Generate manifest + fragment
./step2_generate_manifest.sh
# Step 3: Perform protected update
./step3_protected_update_ecc.sh