| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
# For the license, see the LICENSE file in the root directory. |
| 4 |
|
| 5 |
ROOT=${abs_top_builddir:-$(dirname "$0")/..} |
| 6 |
TESTDIR=${abs_top_testdir:-$(dirname "$0")} |
| 7 |
|
| 8 |
source "${TESTDIR}/common" |
| 9 |
|
| 10 |
cert="$(mktemp)" || exit 1 |
| 11 |
|
| 12 |
trap "cleanup" SIGTERM EXIT |
| 13 |
|
| 14 |
|
| 15 |
function cleanup() |
| 16 |
{ |
| 17 |
rm -f "${cert}" |
| 18 |
} |
| 19 |
|
| 20 |
function check_cert_size() |
| 21 |
{ |
| 22 |
local cert="$1" |
| 23 |
local exp="$2" |
| 24 |
|
| 25 |
local size |
| 26 |
|
| 27 |
# Unfortunately different GnuTLS versions may create certs of different |
| 28 |
# sizes; deactivate this test for now |
| 29 |
return |
| 30 |
|
| 31 |
size=$(stat -c%s "${cert}" 2>/dev/null) |
| 32 |
if [ "$size" -ne "$exp" ]; then |
| 33 |
echo "Warning: Certificate file has unexpected size." |
| 34 |
echo " Expected: $exp; found: $size" |
| 35 |
fi |
| 36 |
} |
| 37 |
|
| 38 |
if ! ${SWTPM_CERT} \ |
| 39 |
--tpm2 \ |
| 40 |
--signkey "${TESTDIR}/data/signkey.pem" \ |
| 41 |
--issuercert "${TESTDIR}/data/issuercert.pem" \ |
| 42 |
--out-cert "${cert}" \ |
| 43 |
--ecc-x 61eaf811ea582656ca2a835dd1b9cd63eb196d7ff62711d6e9b8f85e580a47ca \ |
| 44 |
--ecc-y a51efdc71fd6c791a24a75beb50526aa81b44cc598e65b2d5e116084aea4cb5b \ |
| 45 |
--days 3650 \ |
| 46 |
--pem \ |
| 47 |
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 2.0 \ |
| 48 |
--tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0; then |
| 49 |
echo "Error: ${SWTPM_CERT} returned error code." |
| 50 |
exit 1 |
| 51 |
fi |
| 52 |
|
| 53 |
#expecting size to be constant |
| 54 |
check_cert_size "{$cert}" 948 |
| 55 |
|
| 56 |
#certtool --certificate-info --infile "${cert}" |
| 57 |
#openssl x509 -in "${cert}" -text |
| 58 |
|
| 59 |
# truncate result file |
| 60 |
echo -n > "${cert}" |
| 61 |
echo "Test 1: OK" |
| 62 |
|
| 63 |
if ! ${SWTPM_CERT} \ |
| 64 |
--tpm2 \ |
| 65 |
--signkey "${TESTDIR}/data/signkey.pem" \ |
| 66 |
--issuercert "${TESTDIR}/data/issuercert.pem" \ |
| 67 |
--out-cert "${cert}" \ |
| 68 |
--ecc-x 61eaf811ea582656ca2a835dd1b9cd63eb196d7ff62711d6e9b8f85e580a47ca \ |
| 69 |
--ecc-y a51efdc71fd6c791a24a75beb50526aa81b44cc598e65b2d5e116084aea4cb5b \ |
| 70 |
--days 3650 \ |
| 71 |
--subject "OU=foo,L=NewYork,ST=NY,C=US" \ |
| 72 |
--pem \ |
| 73 |
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2 \ |
| 74 |
--tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0; then |
| 75 |
echo "Error: ${SWTPM_CERT} returned error code." |
| 76 |
exit 1 |
| 77 |
fi |
| 78 |
|
| 79 |
#expecting size to be constant |
| 80 |
check_cert_size "{$cert}" 1025 |
| 81 |
|
| 82 |
# truncate result file |
| 83 |
echo -n > "${cert}" |
| 84 |
echo "Test 2: OK" |
| 85 |
|
| 86 |
if ! ${SWTPM_CERT} \ |
| 87 |
--tpm2 \ |
| 88 |
--signkey "${TESTDIR}/data/signkey.pem" \ |
| 89 |
--issuercert "${TESTDIR}/data/issuercert.pem" \ |
| 90 |
--out-cert "${cert}" \ |
| 91 |
--pubkey "${TESTDIR}/data/ecpubek.pem" \ |
| 92 |
--days 3650 \ |
| 93 |
--subject "OU=foo,L=NewYork,ST=NY,C=US" \ |
| 94 |
--pem \ |
| 95 |
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2 \ |
| 96 |
--tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0; then |
| 97 |
echo "Error: ${SWTPM_CERT} returned error code." |
| 98 |
exit 1 |
| 99 |
fi |
| 100 |
|
| 101 |
#expecting size to be constant |
| 102 |
check_cert_size "{$cert}" 1025 |
| 103 |
|
| 104 |
# truncate result file |
| 105 |
#certtool --certificate-info --infile ${cert} |
| 106 |
echo -n > "${cert}" |
| 107 |
echo "Test 3: OK" |
| 108 |
|
| 109 |
|
| 110 |
###################### Platform Certificate ##################### |
| 111 |
|
| 112 |
if ! ${SWTPM_CERT} \ |
| 113 |
--tpm2 \ |
| 114 |
--type platform \ |
| 115 |
--signkey "${TESTDIR}/data/signkey.pem" \ |
| 116 |
--issuercert "${TESTDIR}/data/issuercert.pem" \ |
| 117 |
--pubkey "${TESTDIR}/data/ecpubek.pem" \ |
| 118 |
--out-cert "${cert}" \ |
| 119 |
--days 3650 \ |
| 120 |
--subject "OU=foo,L=NewYork,ST=NY,C=US" \ |
| 121 |
--pem \ |
| 122 |
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2 \ |
| 123 |
--platform-manufacturer Fedora \ |
| 124 |
--platform-model QEMU \ |
| 125 |
--platform-version 2.1; then |
| 126 |
echo "Error: ${SWTPM_CERT} returned error code." |
| 127 |
exit 1 |
| 128 |
fi |
| 129 |
|
| 130 |
#expecting size to be constant |
| 131 |
check_cert_size "{$cert}" 1070 |
| 132 |
|
| 133 |
# truncate result file |
| 134 |
#certtool --certificate-info --infile ${cert} |
| 135 |
echo -n > "${cert}" |
| 136 |
echo "Test 4: OK" |