|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2025 Contributors to the Parsec project. |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | + |
| 6 | +# This script builds and tests the examples. |
| 7 | +# It can be run inside the container which Dockerfile |
| 8 | +# is in the same folder. |
| 9 | + |
| 10 | +set -euf -o pipefail |
| 11 | + |
| 12 | +################################################# |
| 13 | +# Change rust toolchain version |
| 14 | +################################################# |
| 15 | +if [[ ! -z ${RUST_TOOLCHAIN_VERSION:+x} ]]; then |
| 16 | + rustup override set ${RUST_TOOLCHAIN_VERSION} |
| 17 | + # Use the frozen Cargo lock to prevent any drift from MSRV being upgraded |
| 18 | + # underneath our feet. |
| 19 | + cp tests/Cargo.lock.frozen ../Cargo.lock |
| 20 | +fi |
| 21 | + |
| 22 | +############################ |
| 23 | +# Run the TPM SWTPM server # |
| 24 | +############################ |
| 25 | +mkdir /tmp/tpmdir |
| 26 | +swtpm_setup --tpm2 \ |
| 27 | + --tpmstate /tmp/tpmdir \ |
| 28 | + --createek --decryption --create-ek-cert \ |
| 29 | + --create-platform-cert \ |
| 30 | + --pcr-banks sha1,sha256 \ |
| 31 | + --display |
| 32 | +swtpm socket --tpm2 \ |
| 33 | + --tpmstate dir=/tmp/tpmdir \ |
| 34 | + --flags startup-clear \ |
| 35 | + --ctrl type=tcp,port=2322 \ |
| 36 | + --server type=tcp,port=2321 \ |
| 37 | + --daemon |
| 38 | + |
| 39 | +#################### |
| 40 | +# Start tpm2-abrmd # |
| 41 | +#################### |
| 42 | +tpm2-abrmd \ |
| 43 | + --logger=stdout \ |
| 44 | + --tcti=swtpm: \ |
| 45 | + --allow-root \ |
| 46 | + --session \ |
| 47 | + --flush-all & |
| 48 | + |
| 49 | +################# |
| 50 | +# Clear the TPM # |
| 51 | +################# |
| 52 | +tpm2_startup -c -T tabrmd:bus_type=session |
| 53 | + |
| 54 | +######################## |
| 55 | +# Declare the examples # |
| 56 | +######################## |
| 57 | +examples=( |
| 58 | + "duplication_secret" |
| 59 | + "duplication" |
| 60 | + "hmac" |
| 61 | + "rsa_oaep" |
| 62 | + "sealed_data_object" |
| 63 | + "symmetric_file_encrypt_decrypt" |
| 64 | +) |
| 65 | + |
| 66 | +########################################## |
| 67 | +# Environment variables used by examples # |
| 68 | +########################################## |
| 69 | +export EXAMPLES_INITIAL_DATA_FILE="/tmp/rust-tss-esapi/tss-esapi/examples/symmetric_file_encrypt_decrypt_example.txt" |
| 70 | + |
| 71 | +#################### |
| 72 | +# Run the examples # |
| 73 | +#################### |
| 74 | +for e in ${examples[@]}; do |
| 75 | + TEST_TCTI=tabrmd:bus_type=session RUST_BACKTRACE=1 RUST_LOG=info cargo run --example ${e} |
| 76 | +done |
0 commit comments