2021-11-16 21:51:42 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#########################################################################################
|
|
|
|
# Common functions used for HIRS system tests
|
|
|
|
#
|
|
|
|
#########################################################################################
|
2024-06-07 10:28:25 +00:00
|
|
|
. ./.ci/docker/.env && set -a
|
|
|
|
|
|
|
|
# Setting variables
|
|
|
|
aca_container=hirs-aca1
|
|
|
|
tpm2_container=hirs-provisioner1-tpm2
|
2021-11-16 21:51:42 +00:00
|
|
|
|
2022-01-10 18:36:38 +00:00
|
|
|
# Check container status and abort if container is not running
|
|
|
|
checkContainerStatus() {
|
|
|
|
container_name=$1
|
|
|
|
container_id="$(docker ps -aqf "name=$container_name")"
|
2021-11-16 21:51:42 +00:00
|
|
|
container_status="$(docker inspect $container_id --format='{{.State.Status}}')"
|
2022-01-10 18:36:38 +00:00
|
|
|
echo "Container id is $container_id and the status is $container_status"
|
2021-11-16 21:51:42 +00:00
|
|
|
|
|
|
|
if [ "$container_status" != "running" ]; then
|
|
|
|
container_exit_code="$(docker inspect $container_id --format='{{.State.ExitCode}}')"
|
|
|
|
echo "Container Exit Code: $container_exit_code"
|
|
|
|
docker info
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-01-10 18:36:38 +00:00
|
|
|
# clear all policy settings
|
2021-11-16 21:51:42 +00:00
|
|
|
setPolicyNone() {
|
2024-07-22 10:03:09 +00:00
|
|
|
docker exec -i $aca_container mysql -u root -proot -D hirs_db -e "Update PolicySettings set ecValidationEnabled=0, pcAttributeValidationEnabled=0, pcValidationEnabled=0,
|
2024-06-07 10:28:25 +00:00
|
|
|
utcValidationEnabled=0, firmwareValidationEnabled=0, expiredCertificateValidationEnabled=0, ignoreGptEnabled=0, ignoreImaEnabled=0, ignoretBootEnabled=0;"
|
2021-11-16 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 18:36:38 +00:00
|
|
|
# Policy Settings for tests ...
|
2021-11-16 21:51:42 +00:00
|
|
|
setPolicyEkOnly() {
|
2024-07-22 10:03:09 +00:00
|
|
|
docker exec -i $aca_container mysql -u root -proot -D hirs_db -e "Update PolicySettings set ecValidationEnabled=1, pcAttributeValidationEnabled=0, pcValidationEnabled=0,
|
2024-06-07 10:28:25 +00:00
|
|
|
utcValidationEnabled=0, firmwareValidationEnabled=0, expiredCertificateValidationEnabled=0, ignoreGptEnabled=0, ignoreImaEnabled=0, ignoretBootEnabled=0;"
|
2021-11-16 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setPolicyEkPc_noAttCheck() {
|
2024-07-22 10:03:09 +00:00
|
|
|
docker exec -i $aca_container mysql -u root -proot -D hirs_db -e "Update PolicySettings set ecValidationEnabled=1, pcAttributeValidationEnabled=0, pcValidationEnabled=1,
|
2024-06-07 10:28:25 +00:00
|
|
|
utcValidationEnabled=0, firmwareValidationEnabled=0, expiredCertificateValidationEnabled=0, ignoreGptEnabled=0, ignoreImaEnabled=0, ignoretBootEnabled=0;"
|
2021-11-16 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setPolicyEkPc() {
|
2024-07-22 10:03:09 +00:00
|
|
|
docker exec -i $aca_container mysql -u root -proot -D hirs_db -e "Update PolicySettings set ecValidationEnabled=1, pcAttributeValidationEnabled=1, pcValidationEnabled=1,
|
2024-06-07 10:28:25 +00:00
|
|
|
utcValidationEnabled=0, firmwareValidationEnabled=0, expiredCertificateValidationEnabled=0, ignoreGptEnabled=0, ignoreImaEnabled=0, ignoretBootEnabled=0;"
|
2021-11-16 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setPolicyEkPcFw() {
|
2024-07-22 10:03:09 +00:00
|
|
|
docker exec -i $aca_container mysql -u root -proot -D hirs_db -e "Update PolicySettings set ecValidationEnabled=1, pcAttributeValidationEnabled=1, pcValidationEnabled=1,
|
2024-06-07 10:28:25 +00:00
|
|
|
utcValidationEnabled=0, firmwareValidationEnabled=1, expiredCertificateValidationEnabled=0, ignoreGptEnabled=0, ignoreImaEnabled=1, ignoretBootEnabled=0;"
|
2021-11-16 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
2024-06-07 10:28:25 +00:00
|
|
|
# Clear all ACA DB items excluding policy
|
2022-01-10 18:36:38 +00:00
|
|
|
clearAcaDb() {
|
2024-07-22 10:03:09 +00:00
|
|
|
docker exec -i $aca_container mysql -u root -proot -e "use hirs_db; set foreign_key_checks=0; truncate Appraiser;
|
2024-06-07 10:28:25 +00:00
|
|
|
truncate Certificate;truncate Certificate_Certificate;truncate CertificatesUsedToValidate;truncate ComponentAttributeResult;
|
|
|
|
truncate ComponentInfo;truncate ComponentResult;truncate Device;truncate DeviceInfoReport;truncate PortalInfo;
|
|
|
|
truncate ReferenceDigestValue;truncate ReferenceManifest;truncate Report;truncate SupplyChainValidation;
|
|
|
|
truncate SupplyChainValidationSummary;truncate SupplyChainValidationSummary_SupplyChainValidation;
|
|
|
|
truncate TPM2ProvisionerState;set foreign_key_checks=1;"
|
2022-01-10 18:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Upload Certs to the ACA DB
|
2021-11-16 21:51:42 +00:00
|
|
|
uploadTrustedCerts() {
|
2024-06-07 10:28:25 +00:00
|
|
|
# Create EK Cert from IBMTSS Tools
|
|
|
|
# docker exec $tpm2_container sh -c "pushd /ibmtss/utils > /dev/null \
|
|
|
|
# && ./createekcert -rsa 2048 -cakey cakey.pem -capwd rrrr -v 1> /dev/null \
|
|
|
|
# && popd > /dev/null"
|
|
|
|
# Upload CA Cert from IBMTSS Tools
|
2024-07-22 10:03:09 +00:00
|
|
|
echo "Uploading Trust Certificates to ${HIRS_ACA_HOSTNAME}:${HIRS_ACA_PORTAL_PORT}"
|
|
|
|
echo "Uploading the EK Certificate CA(s)..."
|
2024-07-25 18:57:30 +00:00
|
|
|
docker exec -i $tpm2_container /bin/bash -c "curl -k -F 'file=@/ibmtss/utils/certificates/cacert.pem' $SERVER_CACERT_POST" > /dev/null 2>&1
|
2024-07-22 10:03:09 +00:00
|
|
|
echo "...done"
|
2024-06-07 10:28:25 +00:00
|
|
|
# Upload Trusted Certs from HIRS
|
2024-07-22 10:03:09 +00:00
|
|
|
echo "Uploading the Platform Certificate CA(s)..."
|
2024-07-25 18:42:07 +00:00
|
|
|
docker exec -i $aca_container /bin/bash -c "curl -k -F 'file=@$HIRS_CI_REPO_ROOT/.ci/setup/certs/ca.crt' https://localhost:${HIRS_ACA_PORTAL_PORT}/$HIRS_ACA_POST_POINT_TRUST" > /dev/null 2>&1
|
2024-07-22 10:03:09 +00:00
|
|
|
echo "...done"
|
|
|
|
echo "Uploading the RIM CA(s)..."
|
2024-07-25 18:42:07 +00:00
|
|
|
docker exec -i $aca_container /bin/bash -c "curl -k -F 'file=@$HIRS_CI_REPO_ROOT/.ci/setup/certs/RIMCaCert.pem' https://localhost:${HIRS_ACA_PORTAL_PORT}/$HIRS_ACA_POST_POINT_TRUST" > /dev/null 2>&1
|
|
|
|
docker exec -i $aca_container /bin/bash -c "curl -k -F 'file=@$HIRS_CI_REPO_ROOT/.ci/setup/certs/RimSignCert.pem' https://localhost:${HIRS_ACA_PORTAL_PORT}/$HIRS_ACA_POST_POINT_TRUST" > /dev/null 2>&1
|
2024-07-22 10:03:09 +00:00
|
|
|
echo "...done"
|
2021-11-16 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# provision_tpm2 takes one parameter which is the expected result of the provion: "pass" or "fail"
|
|
|
|
# updates totalTests and failedTests counts
|
2022-01-10 18:36:38 +00:00
|
|
|
# provision_tpm2 <expected_results>
|
2022-01-26 17:08:29 +00:00
|
|
|
provisionTpm2() {
|
2021-11-16 21:51:42 +00:00
|
|
|
expected_result=$1
|
|
|
|
((totalTests++))
|
2024-07-22 10:03:09 +00:00
|
|
|
provisionOutput=$(docker exec -i $tpm2_container /bin/bash -c "/usr/share/hirs/tpm_aca_provision --tcp --ip 127.0.0.1:2321 --sim");
|
2021-11-16 21:51:42 +00:00
|
|
|
echo "==========="
|
|
|
|
echo "$provisionOutput";
|
|
|
|
echo "===========";
|
|
|
|
if [[ $provisionOutput == *"failed"* ]]; then
|
|
|
|
if [[ $expected_result == "pass" ]]; then
|
|
|
|
((failedTests++))
|
2024-06-07 10:28:25 +00:00
|
|
|
echo "!!! Provisioning failed, but was expected to pass"
|
2021-11-16 21:51:42 +00:00
|
|
|
else
|
2024-06-07 10:28:25 +00:00
|
|
|
echo "Provisioning failed as expected."
|
2021-11-16 21:51:42 +00:00
|
|
|
fi
|
2024-07-25 17:33:16 +00:00
|
|
|
elif [[ $provisionOutput == *"Provisioning successful"* ]]; then
|
|
|
|
if [[ $expected_result == "fail" ]]; then
|
|
|
|
((failedTests++))
|
|
|
|
echo "!!! Provisioning passed, but was expected to fail."
|
|
|
|
else
|
|
|
|
echo "Provisioning passed as expected."
|
|
|
|
fi
|
|
|
|
else # Unexpected output
|
|
|
|
((failedTests++))
|
|
|
|
echo "Provisioning failed. Provisioner provided an unexpected output."
|
2021-11-16 21:51:42 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-07-22 10:03:09 +00:00
|
|
|
resetTpmForNewTest() {
|
|
|
|
docker exec -i $tpm2_container /bin/bash -c "source $HIRS_CI_REPO_ROOT/.ci/setup/container/tpm2_common.sh; startFreshTpmServer -f; startupTpm; installEkCert"
|
|
|
|
}
|
|
|
|
|
2022-01-10 18:36:38 +00:00
|
|
|
# Places platform cert(s) held in the test folder(s) in the provisioners tcg folder
|
|
|
|
setPlatformCerts() {
|
2024-07-22 10:03:09 +00:00
|
|
|
OPTIONS="$@"
|
|
|
|
echo "Asking container $tpm2_container to run pc_setup.sh $OPTIONS"
|
|
|
|
docker exec -i $tpm2_container /bin/bash -c "$HIRS_CI_REPO_ROOT/.ci/system-tests/container/pc_setup.sh $OPTIONS"
|
2022-01-10 18:36:38 +00:00
|
|
|
}
|
|
|
|
|
2022-01-25 15:54:54 +00:00
|
|
|
# Places RIM files held in the test folder in the provisioners tcg folder
|
|
|
|
setRims() {
|
2024-07-22 10:03:09 +00:00
|
|
|
OPTIONS="$@"
|
|
|
|
echo "Asking container $tpm2_container to run rim_setup.sh $OPTIONS"
|
|
|
|
docker exec -i $tpm2_container /bin/bash -c "$HIRS_CI_REPO_ROOT/.ci/system-tests/container/rim_setup.sh $OPTIONS"
|
2022-01-10 18:36:38 +00:00
|
|
|
}
|
|
|
|
|
2024-07-22 10:03:09 +00:00
|
|
|
setAppsettings() {
|
|
|
|
OPTIONS="$@"
|
|
|
|
echo "Asking container $tpm2_container to set the appsettings file with options: $OPTIONS"
|
|
|
|
docker exec -i $tpm2_container /bin/bash -c "source $HIRS_CI_REPO_ROOT/.ci/setup/container/tpm2_common.sh; setCiHirsAppsettingsFile $OPTIONS"
|
2024-06-07 10:28:25 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 18:36:38 +00:00
|
|
|
# Writes to the Action ouput, ACA log, and Provisioner Log
|
|
|
|
# Used for marking the start of system tests and noting the result
|
|
|
|
# write_to_logs <log statement>
|
2022-01-26 18:59:07 +00:00
|
|
|
writeToLogs() {
|
2022-01-10 18:36:38 +00:00
|
|
|
line=$1
|
|
|
|
echo $line;
|
2024-07-22 10:03:09 +00:00
|
|
|
docker exec -i $aca_container /bin/bash -c "cd .. && echo '$line' >> /var/log/hirs/HIRS_AttestationCA_Portal.log"
|
2022-01-21 16:26:23 +00:00
|
|
|
}
|