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-06-07 10:28:25 +00:00
|
|
|
docker exec $aca_container mysql -u root -proot -D hirs_db -e "Update PolicySettings set ecValidationEnabled=0, pcAttributeValidationEnabled=0, pcValidationEnabled=0,
|
|
|
|
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-06-07 10:28:25 +00:00
|
|
|
docker exec $aca_container mysql -u root -proot -D hirs_db -e "Update PolicySettings set ecValidationEnabled=1, pcAttributeValidationEnabled=0, pcValidationEnabled=0,
|
|
|
|
utcValidationEnabled=0, firmwareValidationEnabled=0, expiredCertificateValidationEnabled=0, ignoreGptEnabled=0, ignoreImaEnabled=0, ignoretBootEnabled=0;"
|
2021-11-16 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setPolicyEkPc_noAttCheck() {
|
2024-06-07 10:28:25 +00:00
|
|
|
docker exec $aca_container mysql -u root -proot -D hirs_db -e "Update PolicySettings set ecValidationEnabled=1, pcAttributeValidationEnabled=0, pcValidationEnabled=1,
|
|
|
|
utcValidationEnabled=0, firmwareValidationEnabled=0, expiredCertificateValidationEnabled=0, ignoreGptEnabled=0, ignoreImaEnabled=0, ignoretBootEnabled=0;"
|
2021-11-16 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setPolicyEkPc() {
|
2024-06-07 10:28:25 +00:00
|
|
|
docker exec $aca_container mysql -u root -proot -D hirs_db -e "Update PolicySettings set ecValidationEnabled=1, pcAttributeValidationEnabled=1, pcValidationEnabled=1,
|
|
|
|
utcValidationEnabled=0, firmwareValidationEnabled=0, expiredCertificateValidationEnabled=0, ignoreGptEnabled=0, ignoreImaEnabled=0, ignoretBootEnabled=0;"
|
2021-11-16 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setPolicyEkPcFw() {
|
2024-06-07 10:28:25 +00:00
|
|
|
docker exec $aca_container mysql -u root -proot -D hirs_db -e "Update PolicySettings set ecValidationEnabled=1, pcAttributeValidationEnabled=1, pcValidationEnabled=1,
|
|
|
|
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-06-07 10:28:25 +00:00
|
|
|
docker exec hirs-aca1 mysql -u root -proot -e "use hirs_db; set foreign_key_checks=0; truncate Appraiser;
|
|
|
|
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
|
|
|
|
docker exec $tpm2_container sh -c "pushd /ibmtss/utils/certificates > /dev/null \
|
|
|
|
&& curl -k -s -F 'file=@cacert.pem' https://${HIRS_ACA_PORTAL_IP}:${HIRS_ACA_PORTAL_PORT}/HIRS_AttestationCAPortal/portal/certificate-request/trust-chain/upload \
|
|
|
|
&& popd > /dev/null"
|
|
|
|
# Upload Trusted Certs from HIRS
|
|
|
|
pushd .ci/setup/certs > /dev/null
|
|
|
|
curl -k -s -F "file=@ca.crt" https://${HIRS_ACA_PORTAL_IP}:${HIRS_ACA_PORTAL_PORT}/HIRS_AttestationCAPortal/portal/certificate-request/trust-chain/upload
|
|
|
|
curl -k -s -F "file=@RIMCaCert.pem" https://${HIRS_ACA_PORTAL_IP}:${HIRS_ACA_PORTAL_PORT}/HIRS_AttestationCAPortal/portal/certificate-request/trust-chain/upload
|
|
|
|
curl -k -s -F "file=@RimSignCert.pem" https://${HIRS_ACA_PORTAL_IP}:${HIRS_ACA_PORTAL_PORT}/HIRS_AttestationCAPortal/portal/certificate-request/trust-chain/upload
|
|
|
|
popd > /dev/null
|
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-06-07 10:28:25 +00:00
|
|
|
provisionOutput=$(docker exec $tpm2_container sh -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
|
|
|
|
else # provisioning succeeded
|
|
|
|
if [[ $expected_result == "fail" ]]; then
|
|
|
|
((failedTests++))
|
2024-06-07 10:28:25 +00:00
|
|
|
echo "!!! Provisioning passed, but was expected to fail"
|
2021-11-16 21:51:42 +00:00
|
|
|
else
|
2024-06-07 10:28:25 +00:00
|
|
|
echo "Provisioning passed as expected."
|
2021-11-16 21:51:42 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-01-10 18:36:38 +00:00
|
|
|
# Places platform cert(s) held in the test folder(s) in the provisioners tcg folder
|
|
|
|
# setPlatCert <profile> <test>
|
|
|
|
setPlatformCerts() {
|
2024-06-07 10:28:25 +00:00
|
|
|
docker exec $tpm2_container sh /hirs/.ci/system-tests/container/pc_setup.sh $1 $2
|
2022-01-12 15:26:52 +00:00
|
|
|
#docker exec $tpm2_container bash -c "find / -name oem_platform_v1_Base.cer"
|
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 <profile> <test>
|
|
|
|
setRims() {
|
2024-06-07 10:28:25 +00:00
|
|
|
docker exec $tpm2_container sh /hirs/.ci/system-tests/container/rim_setup.sh $1 $2 $3
|
2022-01-25 15:54:54 +00:00
|
|
|
#docker exec $tpm2_container bash -c "find / -name oem_platform_v1_Base.cer"
|
2022-01-10 18:36:38 +00:00
|
|
|
}
|
|
|
|
|
2024-06-07 10:28:25 +00:00
|
|
|
setPlatformOutput() {
|
|
|
|
docker exec $tpm2_container cp /usr/share/hirs/appsettings_hw.json /usr/share/hirs/appsettings.json
|
|
|
|
}
|
|
|
|
|
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-06-07 10:28:25 +00:00
|
|
|
docker exec $aca_container sh -c "cd .. && echo '$line' >> /var/log/hirs/HIRS_AttestationCA_Portal.log"
|
2022-01-25 15:54:54 +00:00
|
|
|
# docker exec $tpm2_container sh -c "echo '$line' >> /var/log/hirs/provisioner/HIRS_provisionerTPM2.log"
|
2022-01-21 16:26:23 +00:00
|
|
|
}
|