From 48203a84a626d3926d616d94fbb1ac23c3fd487a Mon Sep 17 00:00:00 2001 From: iadgovuser29 <33426478+iadgovuser29@users.noreply.github.com> Date: Fri, 12 Jul 2024 11:37:10 -0400 Subject: [PATCH] Defining efi paths in CI env file --- .ci/docker/.env | 29 +++++- .ci/setup/container/tpm2_common.sh | 29 +++--- .ci/system-tests/container/efi_setup.sh | 52 ++++++++++ .ci/system-tests/container/pc_setup.sh | 78 +++++++++++---- .ci/system-tests/container/rim_setup.sh | 94 +++++++++++++------ .ci/system-tests/sys_test_common.sh | 49 +++++----- .ci/system-tests/tests/aca_policy_tests.sh | 8 +- .ci/system-tests/tests/platform_cert_tests.sh | 6 +- .ci/system-tests/tests/rim_system_tests.sh | 12 +-- 9 files changed, 261 insertions(+), 96 deletions(-) create mode 100755 .ci/system-tests/container/efi_setup.sh diff --git a/.ci/docker/.env b/.ci/docker/.env index 0fea64ca..e5846636 100644 --- a/.ci/docker/.env +++ b/.ci/docker/.env @@ -12,4 +12,31 @@ HIRS_ACA_HOSTNAME=hirsaca HIRS_SUBNET=172.19.0.0/16 -TEST_STATUS=0 \ No newline at end of file +TEST_STATUS=0 + +HIRS_DEFAULT_APPSETTINGS_FILE=/usr/share/hirs/appsettings.json + +HIRS_CI_REPO_ROOT=/hirs + +HIRS_CI_TEST_ROOT=/ci_test +HIRS_CI_EFI_PATH_ROOT=$HIRS_CI_TEST_ROOT/boot/efi +HIRS_CI_EFI_PATH_TCG=$HIRS_CI_EFI_PATH_ROOT/EFI/tcg +HIRS_CI_EFI_PATH_PLATFORM=$HIRS_CI_EFI_PATH_TCG/cert/platform +HIRS_CI_EFI_PATH_RIM=$HIRS_CI_EFI_PATH_TCG/manifest/rim +HIRS_CI_EFI_PATH_SWIDTAG=$HIRS_CI_EFI_PATH_TCG/manifest/swidtag +HIRS_CI_TEST_HW_JSON_FILE=$HIRS_CI_TEST_ROOT/hw.json +HIRS_CI_TEST_EVENT_LOG_FILE=$HIRS_CI_TEST_ROOT/binary_bios_measurements + +HIRS_CI_TPM_EK_CERT_FILE=/hirs/.ci/setup/certs/ek_cert.der +HIRS_CI_TPM_EK_CERT_NV_ATTR="0x2000A" +HIRS_CI_TPM_EK_CERT_NV_INDEX="0x1c00002" + +HIRS_ACA_POST_POINT_EK=HIRS_AttestationCAPortal/portal/certificate-request/endorsement-key-credentials/upload +HIRS_ACA_POST_POINT_PLATFORM=HIRS_AttestationCAPortal/portal/certificate-request/platform-credentials/upload +HIRS_ACA_POST_POINT_RIM=HIRS_AttestationCAPortal/portal/reference-manifests/upload +HIRS_ACA_POST_POINT_TRUST=HIRS_AttestationCAPortal/portal/certificate-request/trust-chain/upload + +SERVER_ECERT_POST="https://$HIRS_ACA_HOSTNAME:$HIRS_ACA_PORTAL_PORT/$HIRS_ACA_POST_POINT_EK" +SERVER_PCERT_POST="https://$HIRS_ACA_HOSTNAME:$HIRS_ACA_PORTAL_PORT/$HIRS_ACA_POST_POINT_PLATFORM" +SERVER_CACERT_POST="https://$HIRS_ACA_HOSTNAME:$HIRS_ACA_PORTAL_PORT/$HIRS_ACA_POST_POINT_TRUST" +SERVER_RIM_POST="https://$HIRS_ACA_HOSTNAME:$HIRS_ACA_PORTAL_PORT/$HIRS_ACA_POST_POINT_RIM" diff --git a/.ci/setup/container/tpm2_common.sh b/.ci/setup/container/tpm2_common.sh index 517ee260..a3fa98b2 100755 --- a/.ci/setup/container/tpm2_common.sh +++ b/.ci/setup/container/tpm2_common.sh @@ -152,11 +152,11 @@ DEFAULT_SITE_CONFIG_FILE # Function to update the hirs-site.config file function setCiHirsAppsettingsFile { # Setting configurations - . /HIRS/.ci/docker/.env + . /hirs/.ci/docker/.env - HIRS_APPSETTINGS_FILE="/usr/share/hirs/appsettings.json" + HIRS_APPSETTINGS_FILE=$HIRS_DEFAULT_APPSETTINGS_FILE ACA_ADDRESS="https://${HIRS_ACA_PORTAL_IP}:${HIRS_ACA_PORTAL_PORT}" - EFI_PREFIX_PATH="/ci_test/boot/efi" + EFI_PREFIX_PATH=$HIRS_CI_EFI_PATH_ROOT PACCOR_OUTPUT_FILE="" EVENT_LOG_FILE="" HARDWARE_MANIFEST_COLLECTORS="paccor_scripts" @@ -216,13 +216,13 @@ function setCiHirsAppsettingsFile { DEFAULT_APPSETTINGS_FILE if [ "$USE_LINUX_DMI" = YES ]; then cat <> $HIRS_APPSETTINGS_FILE - "linux_bios_vendor_file": "/ci_test/dmi/id/bios_vendor", - "linux_bios_version_file": "/ci_test/dmi/id/bios_version", - "linux_bios_date_file": "/ci_test/dmi/id/bios_date", - "linux_sys_vendor_file": "/ci_test/dmi/id/sys_vendor", - "linux_product_name_file": "/ci_test/dmi/id/product_name", - "linux_product_version_file": "/ci_test/dmi/id/product_version", - "linux_product_serial_file": "/ci_test/dmi/id/product_serial", + "linux_bios_vendor_file": "$HIRS_CI_TEST_ROOT/dmi/id/bios_vendor", + "linux_bios_version_file": "$HIRS_CI_TEST_ROOT/dmi/id/bios_version", + "linux_bios_date_file": "$HIRS_CI_TEST_ROOT/dmi/id/bios_date", + "linux_sys_vendor_file": "$HIRS_CI_TEST_ROOT/dmi/id/sys_vendor", + "linux_product_name_file": "$HIRS_CI_TEST_ROOT/dmi/id/product_name", + "linux_product_version_file": "$HIRS_CI_TEST_ROOT/dmi/id/product_version", + "linux_product_serial_file": "$HIRS_CI_TEST_ROOT/dmi/id/product_serial", DEFAULT_APPSETTINGS_FILE fi cat <> $HIRS_APPSETTINGS_FILE @@ -305,9 +305,12 @@ function startupTpm { } function installEkCert { - echo "Installing EK Cert /hirs/.ci/setup/certs/ek_cert.der into TPM NVRAM at index 0x1c00002" - tpm2_nvdefine -T mssim -C o -a 0x2000A -s $(cat /hirs/.ci/setup/certs/ek_cert.der | wc -c) 0x1c00002 - tpm2_nvwrite -T mssim -C o -i /hirs/.ci/setup/certs/ek_cert.der 0x1c00002 + # Setting configurations + . /hirs/.ci/docker/.env + + echo "Installing EK Cert $HIRS_CI_TPM_EK_CERT_FILE into TPM NVRAM at index $HIRS_CI_TPM_EK_CERT_NV_INDEX" + tpm2_nvdefine -T mssim -C o -a $HIRS_CI_TPM_EK_CERT_NV_ATTR -s $(cat $HIRS_CI_TPM_EK_CERT_FILE | wc -c) $HIRS_CI_TPM_EK_CERT_NV_INDEX + tpm2_nvwrite -T mssim -C o -i $HIRS_CI_TPM_EK_CERT_FILE $HIRS_CI_TPM_EK_CERT_NV_INDEX echo "Finished installing EK cert." } diff --git a/.ci/system-tests/container/efi_setup.sh b/.ci/system-tests/container/efi_setup.sh new file mode 100755 index 00000000..44027215 --- /dev/null +++ b/.ci/system-tests/container/efi_setup.sh @@ -0,0 +1,52 @@ +#!/bin/bash +######################################################################################### +# Setup a local directory to act as the ESP for testing +# This just creates the directory structure. +# usage efi_setup.sh [-c] [-p] [-r] +# -c: clear all artifact directories +# -p: clear only the platform directory +# -r: clear only the rim directories +######################################################################################### + +# Load env variables +. /hirs/.ci/docker/.env + +# Process parameters Argument handling +POSITIONAL_ARGS=() +ORIGINAL_ARGS=("$@") +while [[ $# -gt 0 ]]; do + case $1 in + -c|--clear-all) + CLEAR_ALL=YES + shift # past argument + ;; + -p|--clear-platform) + CLEAR_PLATFORM=YES + shift # past argument + ;; + -r|--clear-rim) + CLEAR_RIM=YES + shift # past argument + ;; + *) + POSITIONAL_ARGS+=("$1") # save positional arg + # shift # past argument + break + ;; + esac + +# Ensure file structure is there +mkdir -p $HIRS_CI_EFI_PATH_PLATFORM +mkdir -p $HIRS_CI_EFI_PATH_RIM +mkdir -p $HIRS_CI_EFI_PATH_SWIDTAG + +# Clear out any previous artifacts + +if [ "$CLEAR_ALL" = YES ] || [ "$CLEAR_PLATFORM" = YES ] ; then + rm -f $HIRS_CI_EFI_PATH_PLATFORM/* +fi +if [ "$CLEAR_ALL" = YES ] || [ "$CLEAR_RIM" = YES ] ; then + rm -f $HIRS_CI_EFI_PATH_RIM/* + rm -f $HIRS_CI_EFI_PATH_SWIDTAG/* +fi + diff --git a/.ci/system-tests/container/pc_setup.sh b/.ci/system-tests/container/pc_setup.sh index 17f88b44..4cc0621c 100755 --- a/.ci/system-tests/container/pc_setup.sh +++ b/.ci/system-tests/container/pc_setup.sh @@ -1,23 +1,65 @@ #!/bin/bash ######################################################################################### # Setup for platform certificates for testing -# Copies platform certs (Base and Delta) to the tcg directory -# usage pc_setup.sh +# usage pc_setup.sh -p -t [-u] [-n] +# By default, copies platform certs (Base and Delta) to the tcg directory. +# -u: upload the certs to the ACA directly. +# -n: disable copy of certs to the tcg directory. ######################################################################################### -profile=$1 -test=$2 -ciTestDir="/ci_test" -tcgDir="$ciTestDir/boot/efi/EFI/tcg/cert/platform/" +# Load env variables +. ./.ci/docker/.env + +profile=laptop +test=default +ciTestDir=$HIRS_CI_TEST_ROOT +ciTestHwJsonFile=$HIRS_CI_TEST_HW_JSON_FILE + +# By default save the artifacts in EFI and do not upload to the ACA +UPLOAD_ARTIFACTS=NO +PUT_ARTIFACTS_IN_ESP=YES + +# Process parameters Argument handling +POSITIONAL_ARGS=() +ORIGINAL_ARGS=("$@") +while [[ $# -gt 0 ]]; do + case $1 in + -p|--profile) + shift # past argument + profile=$1 + shift # past parameter + ;; + -t|--test) + shift # past argument + test=$1 + shift # past parameter + ;; + -u|--upload) + UPLOAD_ARTIFACTS=YES + shift # past argument + ;; + -n|--no-efi) + PUT_ARTIFACTS_IN_ESP=NO + shift # past argument + ;; + -*|--*) + echo "pc_setup.sh: Unknown option $1" + shift # past argument + ;; + *) + POSITIONAL_ARGS+=("$1") # save positional arg + # shift # past argument + break + ;; + esac # Profile selections -profileDir="/hirs/.ci/system-tests/profiles/$profile" +profileDir="$HIRS_CI_REPO_ROOT/.ci/system-tests/profiles/$profile" testDir="$profileDir/$test" pcDir="$testDir/platformcerts" dmiZip="$profileDir/$profile"_dmi.zip hwJsonFileName="$profile"_"$test"_hw.json hwJsonFile="$testDir/$hwJsonFileName" -ciTestHwJsonFile="$ciTestDir/hw.json" # Use default settings if profile does not have specific changes if [ ! -f "$hwJsonFile" ]; then @@ -30,9 +72,8 @@ if [ ! -f "$dmiZip" ]; then dmiZip="$profileDir"/default/laptop_dmi.zip fi -# Current TCG folder for platform certs -mkdir -p $tcgDir; # Create the platform cert folder if its not there -rm -f $tcgDir*; # Clear out any previous data +# Ensure platform folder under efi is set up and cleared +$HIRS_CI_REPO_ROOT/.ci/system-tests/container/efi_setup.sh -p echo "Test is using platform cert(s) from $profile : $test" # Step 1: Copy hw json file, if it exists. @@ -48,16 +89,21 @@ dnf install -y unzip &> /dev/null echo "dmi file used was $dmiZip" unzip -o "$dmiZip" -d "$ciTestDir" -# Step 3: Copy the platform cert to tcg folder +# Step 3: Copy the platform cert to tcg folder and or upload it to the ACA if [[ ! -d $pcDir ]]; then pcDir=$profileDir/default/platformcerts; fi + pushd $pcDir > /dev/null # Skip copy of platform cert if .gitigore exists (empty profile) -if [[ ! -f ".gitignore" ]]; then + if [[ ! -f ".gitignore" ]]; then for cert in * ; do - cp -f $cert $tcgDir$cert; + if [ "$PUT_ARTIFACTS_IN_ESP" = YES ]; then + cp $cert $HIRS_CI_EFI_PATH_PLATFORM + fi + if [ "$UPLOAD_ARTIFACTS" = YES ]; then + curl -k -F "file=@$cert" $SERVER_PCERT_POST + fi done -fi - + fi popd > /dev/null diff --git a/.ci/system-tests/container/rim_setup.sh b/.ci/system-tests/container/rim_setup.sh index cf284932..2bb8d659 100644 --- a/.ci/system-tests/container/rim_setup.sh +++ b/.ci/system-tests/container/rim_setup.sh @@ -1,33 +1,71 @@ #!/bin/bash ######################################################################################### # Setup for PC Client Reference Integrity Manifest (RIM) tests -# usage rim_setup.sh