diff --git a/man/man8/swtpm_setup.8 b/man/man8/swtpm_setup.8 index 76d7f1e..a7ccf1d 100644 --- a/man/man8/swtpm_setup.8 +++ b/man/man8/swtpm_setup.8 @@ -129,7 +129,7 @@ .\" ======================================================================== .\" .IX Title "swtpm_setup 8" -.TH swtpm_setup 8 "2018-05-29" "swtpm" "" +.TH swtpm_setup 8 "2018-06-25" "swtpm" "" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -246,6 +246,11 @@ program ends without an error. Optional \s-1VM ID\s0 that can be used to keep track of certificates issued for VMs (or containers). This parameter will be passed through to the tool used for creating the certificates and may be required by that tool. +.IP "\fB\-\-pcr\-banks <\s-1PCR\s0 banks\fR>" 4 +.IX Item "--pcr-banks " +Optional comma-separated list of \s-1PCR\s0 banks to activate. Providing '\-' +allows to skip the selection and activates all \s-1PCR\s0 banks. By default +the sha1 and sha256 banks are activated. .IP "\fB\-\-swtpm_ioctl " 4 .IX Item "--swtpm_ioctl " Pass the path to the swtpm_ioctl executable. By default the swtpm_ioctl diff --git a/man/man8/swtpm_setup.pod b/man/man8/swtpm_setup.pod index eea004a..3ba2dff 100644 --- a/man/man8/swtpm_setup.pod +++ b/man/man8/swtpm_setup.pod @@ -140,6 +140,12 @@ Optional VM ID that can be used to keep track of certificates issued for VMs (or containers). This parameter will be passed through to the tool used for creating the certificates and may be required by that tool. +=item B<--pcr-banks > + +Optional comma-separated list of PCR banks to activate. Providing '-' +allows to skip the selection and activates all PCR banks. By default +the sha1 and sha256 banks are activated. + =item B<--swtpm_ioctl > Pass the path to the swtpm_ioctl executable. By default the swtpm_ioctl diff --git a/src/swtpm_setup/swtpm_setup.c b/src/swtpm_setup/swtpm_setup.c index 82d6ef0..fa39935 100644 --- a/src/swtpm_setup/swtpm_setup.c +++ b/src/swtpm_setup/swtpm_setup.c @@ -65,6 +65,7 @@ const char *one_arg_params[] = { "--keyfile", "--pwdfile", "--swtpm_ioctl", + "--pcr-banks", NULL }; diff --git a/src/swtpm_setup/swtpm_setup.sh.in b/src/swtpm_setup/swtpm_setup.sh.in index 24e48a6..12f3189 100755 --- a/src/swtpm_setup/swtpm_setup.sh.in +++ b/src/swtpm_setup/swtpm_setup.sh.in @@ -90,6 +90,9 @@ DEFAULT_SRK_PASSWORD=sss # default configuration file DEFAULT_CONFIG_FILE="${XDG_CONFIG_HOME:-/etc}/swtpm_setup.conf" +#default PCR banks to activate for TPM 2 +DEFAULT_PCR_BANKS="sha1,sha256" + # TPM constants TPM_NV_INDEX_D_BIT=$((0x10000000)) TPM_NV_INDEX_EKCert=$((0xF000)) @@ -1432,6 +1435,130 @@ tpm2_nv_writelock() return 0 } +# Get the list of all PCR banks +function tpm2_get_all_pcr_banks() +{ + local all_pcr_banks="" + local req rsp exp o l count c bank banks + + req='\x80\x01\x00\x00\x00\x16\x00\x00\x01\x7a' + req+='\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x40' + + rsp="$(tpm_transfer "$req")" + exp=' 80 01 00 00 00 .. 00 00 00 00' + if ! [[ "${rsp:0:30}" =~ $exp ]]; then + logerr "TPM2_Get_Capability() failed for getting PCR bank info" + logerr " expected: $exp [pattern]" + logerr " received: $rsp" + return 1 + fi + + # read the count byte's lower nibble + count=${rsp:56:1} + o=57 + for ((c=0; c + : Set of PCR banks to activate. Provide a comma separated list + like 'sha1,sha256'. '-' to skip and leave all banks active. + Default: $DEFAULT_PCR_BANKS + --version : Display version and exit --help,-h,-? : Display this help screen @@ -1779,6 +1922,7 @@ main() local ret local keyfile pwdfile local got_ownerpass=0 got_srkpass=0 + local pcr_banks="" while [ $# -ne 0 ]; do case "$1" in @@ -1811,6 +1955,7 @@ main() --not-overwrite) flags=$((flags | SETUP_STATE_NOT_OVERWRITE_F));; --allow-signing) flags=$((flags | SETUP_ALLOW_SIGNING_F));; --decryption) flags=$((flags | SETUP_DECRYPTION_F));; + --pcr-banks) shift; pcr_banks="${pcr_banks},$1";; --version) versioninfo $0; exit 0;; --help|-h|-?) usage $0; exit 0;; *) logerr "Unknown option $1"; usage $0; exit 1;; @@ -1821,6 +1966,12 @@ main() [ $got_ownerpass -eq 0 ] && flags=$((flags | SETUP_OWNERPASS_ZEROS_F)) [ $got_srkpass -eq 0 ] && flags=$((flags | SETUP_SRKPASS_ZEROS_F)) + pcr_banks="$(echo $pcr_banks | + tr -s ',' | + sed -e 's/^,//' -e 's/,$//' | + tr '[:upper:]' '[:lower:]')" + [ -z "$pcr_banks" ] && pcr_banks="$DEFAULT_PCR_BANKS" + # set owner password to default if user didn't provide any password wish # and wants to take ownership if [ $((flags & SETUP_TAKEOWN_F)) -ne 0 ] && \ @@ -1959,7 +2110,7 @@ main() else SWTPM="$SWTPM --tpm2" init_tpm2 $flags "$config_file" "$tpm_state_path" \ - "$ownerpass" "$srkpass" "$vmid" + "$ownerpass" "$srkpass" "$vmid" "$pcr_banks" fi ret=$? if [ $ret -eq 0 ]; then