summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLans Zhang <jia.zhang@windriver.com>2017-06-22 15:22:01 +0800
committerLans Zhang <jia.zhang@windriver.com>2017-06-22 15:24:04 +0800
commit1b3e5944491c315ca99b832bc3afdb6a19d81430 (patch)
treeffb3469d58e8e203e4bc8a37adc9fe81a48558fb
downloadmeta-secure-core-1b3e5944491c315ca99b832bc3afdb6a19d81430.tar.gz
meta-secure-core: initial commit
Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
-rw-r--r--COPYING.MIT17
-rw-r--r--MAINTAINERS1
-rw-r--r--README60
-rw-r--r--README.md95
-rw-r--r--meta-efi-secure-boot/README.md463
-rw-r--r--meta-efi-secure-boot/conf/layer.conf16
-rw-r--r--meta-efi-secure-boot/recipes-base/packagegroups/packagegroup-efi-secure-boot.bb28
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools-native_git.bb11
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools.inc63
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools/Add-static-keyword-for-IsValidVariableHeader.patch38
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools/Allow-to-override-tools-for-target-build.patch94
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools/Build-DBX-by-default.patch44
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools/Don-t-build-PreLoader.efi.patch40
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools/Fix-for-the-cross-compilation.patch193
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools/Fix-help2man-error.patch28
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools/Fix-help2man-failure.patch25
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools/Fix-the-wrong-dependency-for-blacklist.esl.patch28
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools/Kill-all-the-build-warning-caused-by-implicit-declar.patch80
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools/LockDown-disable-the-entrance-into-BIOS-setup-to-re-.patch47
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools/LockDown-enable-the-enrollment-for-DBX.patch85
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools/LockDown-run-system-warm-reset-after-the-key-provisi.patch44
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools/LockDown-show-the-error-message-with-3-sec-timeout.patch94
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools/Makefile-do-not-build-signed-efi-image.patch33
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools/Reuse-xxdi.pl.patch51
-rw-r--r--meta-efi-secure-boot/recipes-bsp/efitools/efitools_git.bb83
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0001-pe32.h-add-header-structures-for-TE-and-DOS-executab.patch67
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0002-shim-add-needed-data-structures.patch161
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0003-efi-chainloader-implement-an-UEFI-Exit-service-for-s.patch81
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0004-efi-chainloader-port-shim-to-grub.patch582
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0005-efi-chainloader-use-shim-to-load-and-verify-an-image.patch98
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0006-efi-chainloader-boot-the-image-using-shim.patch63
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0007-efi-chainloader-take-care-of-unload-undershim.patch43
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/Fix-32-bit-build-failures.patch252
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/Grub-get-and-set-efi-variables.patch263
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/Work-around-the-failure-of-ExitBootServices.patch62
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/boot-menu.inc13
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/chainloader-Actually-find-the-relocations-correctly-.patch219
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/chainloader-Don-t-check-empty-section-in-file-like-..patch32
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/chainloader-handle-the-unauthenticated-image-by-shim.patch32
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/efi-secure-boot.inc38
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/grub-efi.cfg36
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/grub-enable-serial-console-by-default.patch30
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/mok2verify-support-to-verify-non-PE-file-with-PKCS-7.patch709
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/password.inc2
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi/serial-redirect-control-x-fix.patch22
-rw-r--r--meta-efi-secure-boot/recipes-bsp/grub/grub-efi_2.02.bbappend146
-rw-r--r--meta-efi-secure-boot/recipes-bsp/seloader/seloader_git.bb94
-rw-r--r--meta-efi-secure-boot/recipes-bsp/shim/shim/0001-shim-allow-to-verify-sha1-digest-for-Authenticode.patch156
-rw-r--r--meta-efi-secure-boot/recipes-bsp/shim/shim/0005-Fix-signing-failure-due-to-not-finding-certificate.patch36
-rw-r--r--meta-efi-secure-boot/recipes-bsp/shim/shim/0006-Prevent-from-removing-intermediate-.efi.patch33
-rw-r--r--meta-efi-secure-boot/recipes-bsp/shim/shim/0007-Use-sbsign-to-sign-MokManager-and-fallback.patch44
-rw-r--r--meta-efi-secure-boot/recipes-bsp/shim/shim/0008-Fix-the-world-build-failure-due-to-the-missing-rule-.patch35
-rw-r--r--meta-efi-secure-boot/recipes-bsp/shim/shim/0010-Makefile-do-not-sign-the-efi-file.patch35
-rw-r--r--meta-efi-secure-boot/recipes-bsp/shim/shim/0011-Update-verification_method-if-the-loaded-image-is-si.patch69
-rw-r--r--meta-efi-secure-boot/recipes-bsp/shim/shim/0012-netboot-replace-the-depreciated-EFI_PXE_BASE_CODE.patch28
-rw-r--r--meta-efi-secure-boot/recipes-bsp/shim/shim/LICENSE30
-rw-r--r--meta-efi-secure-boot/recipes-bsp/shim/shim_git.bb137
-rw-r--r--meta-efi-secure-boot/recipes-core/systemd/systemd_%.bbappend7
-rw-r--r--meta-efi-secure-boot/recipes-devtools/libsign/libsign_git.bb48
-rw-r--r--meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool-native_git.bb50
-rw-r--r--meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/Fix-for-multi-sign.patch41
-rw-r--r--meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/ccan.git.tar.bz2bin0 -> 13964172 bytes
-rw-r--r--meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/disable-man-page-creation.patch15
-rw-r--r--meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/fix-mixed-implicit-and-normal-rules.patch33
-rw-r--r--meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/image-fix-the-segment-fault-caused-by-the-uninitiali.patch30
-rw-r--r--meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/sbsign-add-x-option-to-avoid-overwrite-existing-sign.patch75
-rw-r--r--meta-efi-secure-boot/recipes-extended/mokutil/mokutil_git.bb24
-rw-r--r--meta-efi-secure-boot/recipes-kernel/linux/linux-yocto-efi-secure-boot.inc101
-rw-r--r--meta-efi-secure-boot/recipes-kernel/linux/linux-yocto-rt_%.bbappend1
-rw-r--r--meta-efi-secure-boot/recipes-kernel/linux/linux-yocto_%.bbappend1
-rw-r--r--meta-efi-secure-boot/recipes-perl/libfile-slurp/libfile-slurp-perl_9999.19.bb15
-rw-r--r--meta-efi-secure-boot/recipes-support/efivar/efivar/Remove-use-of-deprecated-readdir_r.patch44
-rw-r--r--meta-efi-secure-boot/recipes-support/efivar/efivar_0.24.bbappend13
-rw-r--r--meta-encrypted-storage/README.md179
-rw-r--r--meta-encrypted-storage/conf/layer.conf15
-rw-r--r--meta-encrypted-storage/recipes-base/packagegroups/packagegroup-encrypted-storage-initramfs.bb8
-rw-r--r--meta-encrypted-storage/recipes-base/packagegroups/packagegroup-encrypted-storage.bb14
-rw-r--r--meta-encrypted-storage/recipes-base/packagegroups/packagegroup-encrypted-storage.inc25
-rw-r--r--meta-encrypted-storage/recipes-kernel/linux/linux-yocto-encrypted-storage.inc6
-rw-r--r--meta-encrypted-storage/recipes-kernel/linux/linux-yocto-rt_%.bbappend1
-rw-r--r--meta-encrypted-storage/recipes-kernel/linux/linux-yocto/dmcrypt.cfg11
-rw-r--r--meta-encrypted-storage/recipes-kernel/linux/linux-yocto/dmcrypt.scc1
-rw-r--r--meta-encrypted-storage/recipes-kernel/linux/linux-yocto_%.bbappend1
-rw-r--r--meta-encrypted-storage/recipes-tpm/cryptfs-tpm2/cryptfs-tpm2_git.bb55
-rw-r--r--meta-integrity/COPYING.MIT17
-rw-r--r--meta-integrity/README.md166
-rw-r--r--meta-integrity/classes/rpm5-ima.bbclass156
-rw-r--r--meta-integrity/conf/layer.conf19
-rw-r--r--meta-integrity/files/ima_signing_blacklist1
-rw-r--r--meta-integrity/recipes-base/packagegroups/packagegroup-ima-initramfs.bb12
-rw-r--r--meta-integrity/recipes-base/packagegroups/packagegroup-ima.bb21
-rw-r--r--meta-integrity/recipes-base/packagegroups/packagegroup-ima.inc13
-rw-r--r--meta-integrity/recipes-core/base-files/base-files_%.bbappend4
-rwxr-xr-xmeta-integrity/recipes-core/initrdscripts/files/init.ima129
-rw-r--r--meta-integrity/recipes-core/initrdscripts/initrdscripts-ima.bb47
-rw-r--r--meta-integrity/recipes-core/util-linux/util-linux_%.bbappend16
-rw-r--r--meta-integrity/recipes-kernel/linux/linux-yocto-integrity.inc18
-rw-r--r--meta-integrity/recipes-kernel/linux/linux-yocto-rt_4.%.bbappend1
-rw-r--r--meta-integrity/recipes-kernel/linux/linux-yocto/ima.cfg35
-rw-r--r--meta-integrity/recipes-kernel/linux/linux-yocto/ima.scc4
-rw-r--r--meta-integrity/recipes-kernel/linux/linux-yocto_4.%.bbappend1
-rw-r--r--meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils/0001-Don-t-build-man-pages.patch27
-rw-r--r--meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils/0001-Install-evmctl-to-sbindir-rather-than-bindir.patch28
-rw-r--r--meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils_git.bb41
-rw-r--r--meta-integrity/recipes-support/ima-policy/files/ima_policy.default24
-rw-r--r--meta-integrity/recipes-support/ima-policy/ima-policy_0.1.bb18
-rw-r--r--meta-integrity/recipes-support/keyutils/keyutils/keyutils-fix-powerpc-cflags.patch28
-rw-r--r--meta-integrity/recipes-support/keyutils/keyutils/keyutils-fix-the-cflags-for-all-of-targets.patch32
-rw-r--r--meta-integrity/recipes-support/keyutils/keyutils/keyutils-remove-m32-m64.patch19
-rw-r--r--meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_library_install.patch30
-rw-r--r--meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_x86-64_cflags.patch24
-rw-r--r--meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_x86_cflags.patch24
-rw-r--r--meta-integrity/recipes-support/keyutils/keyutils_1.5.9.bb48
-rw-r--r--meta-signing-key/README.md73
-rw-r--r--meta-signing-key/classes/user-key-store.bbclass440
-rw-r--r--meta-signing-key/conf/layer.conf40
-rw-r--r--meta-signing-key/files/ima_keys/x509_ima.derbin0 -> 795 bytes
-rw-r--r--meta-signing-key/files/ima_keys/x509_ima.key28
-rw-r--r--meta-signing-key/files/mok_sb_keys/shim_cert.key28
-rw-r--r--meta-signing-key/files/mok_sb_keys/shim_cert.pem19
-rw-r--r--meta-signing-key/files/mok_sb_keys/vendor_cert.key28
-rw-r--r--meta-signing-key/files/mok_sb_keys/vendor_cert.pem19
-rw-r--r--meta-signing-key/files/mok_sb_keys/wosign_ev_cert.pem35
-rw-r--r--meta-signing-key/files/system_trusted_keys/system_trusted_key.key28
-rw-r--r--meta-signing-key/files/system_trusted_keys/system_trusted_key.pem19
-rw-r--r--meta-signing-key/files/uefi_sb_keys/DB.key28
-rw-r--r--meta-signing-key/files/uefi_sb_keys/DB.pem17
-rw-r--r--meta-signing-key/files/uefi_sb_keys/DBX/DBX.key28
-rw-r--r--meta-signing-key/files/uefi_sb_keys/DBX/DBX.pem19
-rw-r--r--meta-signing-key/files/uefi_sb_keys/KEK.key28
-rw-r--r--meta-signing-key/files/uefi_sb_keys/KEK.pem17
-rw-r--r--meta-signing-key/files/uefi_sb_keys/PK.key28
-rw-r--r--meta-signing-key/files/uefi_sb_keys/PK.pem19
-rw-r--r--meta-signing-key/files/uefi_sb_keys/ms-DB.pem35
-rw-r--r--meta-signing-key/files/uefi_sb_keys/ms-KEK.pem34
-rw-r--r--meta-signing-key/recipes-support/key-store/key-store_0.1.bb122
-rwxr-xr-xmeta-signing-key/scripts/create-user-key-store.sh144
-rw-r--r--meta-tpm/README.md59
-rw-r--r--meta-tpm/conf/layer.conf12
-rw-r--r--meta-tpm/recipes-base/packagegroups/packagegroup-tpm.bb19
-rw-r--r--meta-tpm/recipes-kernel/linux/linux-yocto-rt_4.%.bbappend1
-rw-r--r--meta-tpm/recipes-kernel/linux/linux-yocto-tpm.inc6
-rw-r--r--meta-tpm/recipes-kernel/linux/linux-yocto/tpm.cfg17
-rw-r--r--meta-tpm/recipes-kernel/linux/linux-yocto/tpm.scc4
-rw-r--r--meta-tpm/recipes-kernel/linux/linux-yocto_4.%.bbappend1
-rw-r--r--meta-tpm/recipes-tpm/openssl-tpm-engine/files/0001-create-tpm-key-support-well-known-key-option.patch99
-rw-r--r--meta-tpm/recipes-tpm/openssl-tpm-engine/files/0002-libtpm-support-env-TPM_SRK_PW.patch80
-rw-r--r--meta-tpm/recipes-tpm/openssl-tpm-engine/files/0003-Fix-not-building-libtpm.la.patch25
-rw-r--r--meta-tpm/recipes-tpm/openssl-tpm-engine/openssl-tpm-engine_0.4.2.bb54
-rw-r--r--meta-tpm/recipes-tpm/pcr-extend/pcr-extend_0.1.bb21
-rw-r--r--meta-tpm/recipes-tpm/tpm-quote-tools/tpm-quote-tools_1.0.1.bb26
-rw-r--r--meta-tpm/recipes-tpm/tpm-tools/tpm-tools-1.3.8/03-fix-bool-error-parseStringWithValues.patch30
-rw-r--r--meta-tpm/recipes-tpm/tpm-tools/tpm-tools-1.3.8/tpm-tools-extendpcr.patch244
-rw-r--r--meta-tpm/recipes-tpm/tpm-tools/tpm-tools-1.3.8/tpm-tools-gcc-6.patch21
-rw-r--r--meta-tpm/recipes-tpm/tpm-tools/tpm-tools_1.3.8.bb24
-rw-r--r--meta-tpm/recipes-tpm/trousers/files/Fix-segment-fault-if-client-hostname-cannot-be-retri.patch33
-rw-r--r--meta-tpm/recipes-tpm/trousers/files/fix-deadlock-and-potential-hung.patch82
-rw-r--r--meta-tpm/recipes-tpm/trousers/files/fix-event-log-parsing-problem.patch38
-rw-r--r--meta-tpm/recipes-tpm/trousers/files/fix-incorrect-report-of-insufficient-buffer.patch22
-rwxr-xr-xmeta-tpm/recipes-tpm/trousers/files/tcsd.conf170
-rw-r--r--meta-tpm/recipes-tpm/trousers/files/tcsd.service21
-rw-r--r--meta-tpm/recipes-tpm/trousers/files/trousers-conditional-compile-DES-related-code.patch38
-rw-r--r--meta-tpm/recipes-tpm/trousers/files/trousers-udev.rules2
-rw-r--r--meta-tpm/recipes-tpm/trousers/files/trousers.init.sh65
-rw-r--r--meta-tpm/recipes-tpm/trousers/trousers_0.3.14.bb114
-rw-r--r--meta-tpm/recipes-tpm/tss-testsuite/files/Tspi_TPM_CreateIdentityWithCallbacks_no_des.patch79
-rw-r--r--meta-tpm/recipes-tpm/tss-testsuite/files/Tspi_TPM_CreateIdentity_no_des.patch45
-rw-r--r--meta-tpm/recipes-tpm/tss-testsuite/files/Tspi_TPM_LoadMaintenancePubKey01.patch21
-rw-r--r--meta-tpm/recipes-tpm/tss-testsuite/files/common_c_no_des.patch36
-rw-r--r--meta-tpm/recipes-tpm/tss-testsuite/files/fix-failure-of-.so-LD-with-cortexa8t-neon-wrswrap-linux.patch33
-rw-r--r--meta-tpm/recipes-tpm/tss-testsuite/files/fix-hardcode-path-in-tsstests.sh.patch16
-rw-r--r--meta-tpm/recipes-tpm/tss-testsuite/files/fix-missing-LDFLAGS-in-compile-command-line.patch25
-rw-r--r--meta-tpm/recipes-tpm/tss-testsuite/files/testsuite-transport-init.patch38
-rw-r--r--meta-tpm/recipes-tpm/tss-testsuite/files/transport-Tspi_TPM_Delegate.patch2284
-rw-r--r--meta-tpm/recipes-tpm/tss-testsuite/tss-testsuite_0.3.bb58
-rw-r--r--meta-tpm2/README.md21
-rw-r--r--meta-tpm2/conf/layer.conf12
-rw-r--r--meta-tpm2/recipes-base/packagegroups/packagegroup-tpm2-initramfs.bb1
-rw-r--r--meta-tpm2/recipes-base/packagegroups/packagegroup-tpm2.bb11
-rw-r--r--meta-tpm2/recipes-base/packagegroups/packagegroup-tpm2.inc5
-rw-r--r--meta-tpm2/recipes-kernel/linux/linux-yocto-rt_4.%.bbappend1
-rw-r--r--meta-tpm2/recipes-kernel/linux/linux-yocto-tpm2.inc6
-rw-r--r--meta-tpm2/recipes-kernel/linux/linux-yocto/tpm2.cfg16
-rw-r--r--meta-tpm2/recipes-kernel/linux/linux-yocto/tpm2.scc4
-rw-r--r--meta-tpm2/recipes-kernel/linux/linux-yocto_4.%.bbappend1
-rw-r--r--meta-tpm2/recipes-tpm/tpm2-abrmd/files/Fix-build-failure-when-searching-tabrmd.h.patch293
-rw-r--r--meta-tpm2/recipes-tpm/tpm2-abrmd/files/tpm2-abrmd-init.sh65
-rw-r--r--meta-tpm2/recipes-tpm/tpm2-abrmd/files/tpm2-abrmd.default1
-rw-r--r--meta-tpm2/recipes-tpm/tpm2-abrmd/tpm2-abrmd_git.bb61
-rw-r--r--meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/0001-tpm2-tools-use-dynamic-linkage-with-tpm2-abrmd.patch80
-rw-r--r--meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/0002-Fix-build-failure-with-glib-2.0.patch39
-rw-r--r--meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/ax_check_compile_flag.m474
-rw-r--r--meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/ax_check_link_flag.m474
-rw-r--r--meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/ax_check_preproc_flag.m474
-rw-r--r--meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools_git.bb48
-rw-r--r--meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/0001-update-bootstrap.patch24
-rw-r--r--meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/ax_check_compile_flag.m474
-rw-r--r--meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/ax_check_link_flag.m474
-rw-r--r--meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/ax_check_preproc_flag.m474
-rw-r--r--meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/ax_pthread.m4332
-rw-r--r--meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/no-cmocka-configure-ac.diff10
-rw-r--r--meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss_git.bb109
-rw-r--r--meta/conf/layer.conf14
-rw-r--r--meta/recipes-core/images/secure-core-image.bb23
204 files changed, 14086 insertions, 0 deletions
diff --git a/COPYING.MIT b/COPYING.MIT
new file mode 100644
index 0000000..89de354
--- /dev/null
+++ b/COPYING.MIT
@@ -0,0 +1,17 @@
1Permission is hereby granted, free of charge, to any person obtaining a copy
2of this software and associated documentation files (the "Software"), to deal
3in the Software without restriction, including without limitation the rights
4to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5copies of the Software, and to permit persons to whom the Software is
6furnished to do so, subject to the following conditions:
7
8The above copyright notice and this permission notice shall be included in
9all copies or substantial portions of the Software.
10
11THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
17THE SOFTWARE.
diff --git a/MAINTAINERS b/MAINTAINERS
new file mode 100644
index 0000000..db348c9
--- /dev/null
+++ b/MAINTAINERS
@@ -0,0 +1 @@
Jia Zhang <lans.zhang2008@gmail.com>
diff --git a/README b/README
new file mode 100644
index 0000000..afbf854
--- /dev/null
+++ b/README
@@ -0,0 +1,60 @@
1This README file contains information on the contents of the
2meta-secure-core layer.
3
4Please see the corresponding sections below for details.
5
6
7Dependencies
8============
9
10This layer depends on:
11
12 URI: git://git.openembedded.org/bitbake
13 branch: master
14
15 URI: git://git.openembedded.org/openembedded-core
16 layers: meta
17 branch: master
18
19
20Patches
21=======
22
23Please submit any patches against the meta-secure-core layer to the
24maintainer:
25
26Maintainer: Jia Zhang <lans.zhang2008@gmail.com>
27
28
29Table of Contents
30=================
31
32 I. Adding the meta-secure-core layer to your build
33 II. Misc
34
35
36I. Adding the meta-secure-core layer to your build
37=================================================
38
39--- replace with specific instructions for the meta-secure-core layer ---
40
41In order to use this layer, you need to make the build system aware of
42it.
43
44Assuming the meta-secure-core layer exists at the top-level of your
45yocto build tree, you can add it to the build system by adding the
46location of the meta-secure-core layer to bblayers.conf, along with any
47other layers needed. e.g.:
48
49 BBLAYERS ?= " \
50 /path/to/yocto/meta \
51 /path/to/yocto/meta-poky \
52 /path/to/yocto/meta-yocto-bsp \
53 /path/to/yocto/meta-meta-secure-core \
54 "
55
56
57II. Misc
58========
59
60--- replace with specific information about the meta-secure-core layer ---
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..8cc9f32
--- /dev/null
+++ b/README.md
@@ -0,0 +1,95 @@
1### meta-secure-env
2This layer provides the following common and platform-specific security
3features:
4
5#### UEFI Secure Boot
6For x86 platform, UEFI secure boot is the industry standard defined in the
7UEFI spec, allowing images loaded by UEFI BIOS to be verified with the trusted
8key. Whenever this feature is enabled, the bootloader and kernel will be
9signed automatically during the build, implying the signed binaries are
10contained by the resulting RPM and rootfs image.
11
12Refer to [meta-efi-secure-boot](https://github.com/jiazhang0/meta-efi-secure-boot/blob/master/README.md) for more details.
13
14#### MOK Secure Boot
15For x86 platform, MOK secure boot is based on the UEFI secure boot, adding
16the shim loader to chainloader the second-stage bootloader. Meanwhile,
17the shim will also install a protocol which permits the second-stage bootloader
18to perform similar binary validation, e.g, for linux kernel.
19
20Refer to [meta-efi-secure-boot](https://github.com/jiazhang0/meta-efi-secure-boot/blob/master/README.md) for more details.
21
22#### User key store
23By default, the signing key used by UEFI/MOK secure boot is the sample key for
24the purposes of development and demonstration. It is not recommended that
25this sample key be used for a production device and should be replaced by
26a secret key owned by the user.
27
28Refer to [meta-signing-key](https://github.com/jiazhang0/meta-signing-key/blob/master/README.md)
29for more details about how to construct an user key store.
30
31#### TPM 1.x
32This feature enables Trusted Platform Module 1.x support, including
33kernel option changes to enable tpm drivers, and picking up TPM 1.x packages.
34
35Refer to [meta-tpm](https://github.com/jiazhang0/meta-tpm/blob/master/README.md)
36for more details.
37
38#### TPM 2.0
39This feature enables Trusted Platform Module 2.0 support, including
40kernel option changes to enable tpm drivers, and picking up TPM 2.0 packages.
41
42Trusted Platform Module (TPM 2.0) is a microcontroller that stores keys,
43passwords, and digital certificates. A discrete TPM 2.0 offers the
44capabilities as part of the overall platform security requirements.
45
46Refer to [meta-tpm2](https://github.com/jiazhang0/meta-tpm2/blob/master/README.md)
47for more details.
48
49#### Encrypted storage
50This feature gives 2 types of granularity for storage encryption. Data volume
51encryption allows the user to create encryption partition with a passphrase
52typed by the end user. Root filesystem encryption enables the data encryption on
53the entire rootfs except the boot partition.
54
55Both types of storage encryption are based on device-mapper crypt target,
56which provides transparent encryption of block devices using the kernel crypto
57API. Additionally, the utility cryptsetup is used to conveniently setup disk
58encryption based on device-mapper crypt target.
59
60Refer to [meta-encrypted-storage](https://github.com/jiazhang0/meta-encrypted-storage/blob/master/README.md) for more details.
61
62#### Integrity
63The Linux IMA subsystem introduces hooks within the Linux kernel to support
64measuring the integrity of files that are loaded (including application code)
65before it is executed or mmap()ed to memory. The measured value (hash) is then
66registered in a log that can be consulted by administrators.
67
68To support proven integrity of the files, the IMA subsystem can interact with
69the TPM chip within the system to protect the registered hashes from tampering
70by a rogue administrator or application. The IMA subsystem, as already
71supported by the Linux kernel, supports reporting on the hashes of files and
72commands ran by privileged accounts (and more if you create your own
73measurement policies).
74
75In addition, IMA appraisal can even register the measured value as an extended
76attribute, and after subsequent measurement(s) validate this extended attribute
77against the measured value and refuse to load the file (or execute the
78application) if the hash does not match. In that case, the IMA subsystem allows
79files and applications to be loaded if the hashes match (and will save the
80updated hash if the file is modified) but refuse to load it if it doesn't. This
81provides some protection against offline tampering of the files.
82
83Refer to [meta-integrity](https://github.com/jiazhang0/meta-efi-secure-boot/blob/master/README.md)
84for more details.
85
86#### RPM signing
87This feature provides the integrity verification for the RPM5 package.
88
89Refer to [meta-rpm-signing](https://github.com/jiazhang0/meta-rpm-signing/blob/master/README.md)
90for more details.
91
92
93### Building the meta-secure-env layer
94This layer should be added to the bblayers.conf file. To enable certain
95feature provided by this layer, add the feature to the local.conf file.
diff --git a/meta-efi-secure-boot/README.md b/meta-efi-secure-boot/README.md
new file mode 100644
index 0000000..6f32e7c
--- /dev/null
+++ b/meta-efi-secure-boot/README.md
@@ -0,0 +1,463 @@
1### EFI secure boot feature
2This feature consists of two widely used secure boot technologies: UEFI Secure
3Boot and MOK Secure Boot.
4
5- UEFI Secure Boot is the industry standard defined in the UEFI spec, allowing the
6images loaded by UEFI BIOS to be verified with the certificates corresponding to
7the trusted keys.
8- MOK (Machine Owner Key) Secure Boot is based on UEFI Secure Boot, adding
9the shim bootloader to chainloader the next stage bootloader with the integrity
10check using the shim-managed certificates corresponding to another set of
11trusted keys which may be different than the trusted keys used by UEFI Secure
12Boot.
13
14In addition, this feature introduces the SELoader as the second-stage bootloader
15and eventually chainliader to the third-stage bootloader "grub". With the
16extension provided by SELoader, grub configuration files, kernel (even without
17EFI stub support) and initrd can be authenticated. This capability is not
18available in the shim bootloader.
19
20Grub bootloader is enhanced to support lockdown mode. In this mode, the
21edit, rescue and command line are protected in order to prevent from
22tampering the kernel commandline or loading an unsigned boot component. Hence,
23this lockdown protection can effectively defeat the attempts to disable the
24kernel security mechanisms. The flexibility is also provided if the user
25authentication is enabled. The user authenticated by a password check can enter
26into edit and command line.
27
28Therefore, using UEFI Secure Boot, SELoader, and grub lockdown together, the
29boot process is completely trustworthy.
30
31A complete boot flow with this feature is:
32
33- UEFI BIOS boot manager (UEFI Secure Boot enabled) ->
34 - shim (verified by a DB certificate) ->
35 - SELoader (verified by a shim-managed certificate) ->
36 - grub (verified by a shim-managed certificate) ->
37 - grub.cfg (verified by a shim-managed certificate)
38 - kernel (verified by a shim-managed certificate)
39 - initramfs (verified by a shim-managed certificate)
40
41### Quick start for the first boot
42- Deploy the rootfs
43
44- Boot up the target board
45
46- Enter to BIOS setup and remove the enrolled certificates
47 * It is recommended to still turn on UEFI Secure Boot option if allowed.
48
49- Exit BIOS setup and automatically reboot
50
51- Manually launch a reboot via ctrl + alt + del again
52 * Otherwise, a misleading error message about the verification failure
53 will be displayed.
54
55- Automatically boot to the boot option "Automatic Certificate Provision" in
56 grub boot menu.
57
58- (Optional) Enter into BIOS setup to turn on UEFI Secure Boot option
59
60- Boot to the system with the protection provided by UEFI and MOK Secure Boot
61
62### Key Management
63Refer to meta-signing-key/README.md for the initial cognition about key
64management for UEFI Secure Boot.
65
66Note that the sample key and user key are the concepts in the key signing
67model according to the ownership and secrecy. In UEFI Secure Boot, a policy
68object such as PK, KEK, DB and DBX is mapped to a key managed by the key
69signing model.
70
71#### Sample Keys
72This feature, by default, use **the sample keys** to sign and verify images for
73the purpose of development and demonstration. **Please ensure you know what your
74risk is to use the sample keys in your product, because they are completely
75public.**
76
77The sample keys used for UEFI Secure Boot are centrally placed under
78meta-signing-key/files/uefi_sb_keys/.
79
80- PK.pem
81 The X509 certificate enrolled to UEFI BIOS, used to update/delete PK/KEK.
82
83- PK.key
84 The private key corresponding to PK.pem, used to sign the EFI signature
85 list for PK/KEK enrollment.
86
87- KEK.pem
88 The X509 certificate enrolled to UEFI BIOS, used to update/delete
89 DB/DBX.
90
91- KEK.key
92 The private key corresponding to KEK.pem, used to sign the EFI signature
93 list for DB/DBX enrollment.
94
95- DB.pem
96 The X509 certificate enrolled to UEFI BIOS, used to verify the images
97 directly loaded by UEFI BIOS.
98
99- DB.key
100 The private key corresponding to DB.pem, used to sign the images directly
101 loaded by UEFI BIOS.
102
103- DBX
104 This directory contains any number of X509 certificate enrolled to UEFI
105 BIOS, used to blacklist the revoked certificates. The revoked certificates
106 must be PEM-formatted.
107
108The sample keys used for MOK Secure Boot are centrally placed under
109`meta-signing-key/files/mok_sb_keys/`.
110
111- shim_cert.pem
112 The X509 certificate embedded in shim, used to verify the images either
113 directly or indirectly loaded by shim.
114
115- shim_cert.key
116 The private key corresponding to shim_cert.pem, used to sign the images
117 either directly or indirectly loaded by shim.
118
119- vendor_cert.pem
120 Used in the same way as shim_cert.pem. In addition, vendor certificate
121 is the switch to enable shim verification protocol, which facilitates
122 the verification for the SELoader.
123
124- vendor_cert.key
125 The private key corresponding to vendor_cert.pem, Same fuction as
126 shim_cert.key.
127
128- vendor_dbx
129 This directory contains any number of X509 certificate embedded in shim,
130 used to blacklist the revoked certificates.
131
132#### User Keys
133Refer to meta-signing-key/README.md for the details about how to generate/use
134the keys owned by the end user.
135
136#### Automatic Certificate Provision
137The certificate provision is required to enable UEFI Secure Boot. By default,
138the target may be provisioned with the default certificates enrolled during the
139manufacture.
140
141In order to use the bootloader and kernel signed by the sample or self-owned
142key to boot up the system, this feature provides a process of autmatic
143certificate provison for the convenience. Refer to the instructions listed in
144the section "Work Flow For The First Boot". The detailed descriptions are
145given below.
146
147##### Remove the enrolled certificates in BIOS setup
148The LockDown.efi application is used to run the provision. However,
149LockDown.efi cannot be launched if UEFI Secure Boot is already enabled. In
150addition, the enrolled certificates may be not the ones the user hopes to use.
151
152The provisioned certificates can be removed in BIOS setup. The detailed steps
153may vary between the boards. Refer to BIOS manual for the details.
154
155##### Launch the automatic provision
156Lockdown.efi will automatically provision UEFI Secure Boot after removing the
157the provisioned certificates in BIOS setup. More specifically, the PK, KEK,
158DB and DBX (if any) will be enrolled and begin to take affect after a reboot.
159
160##### Turn on UEFI Secure Boot option
161If UEFI Secure Boot option is turned off, the user has to enter into BIOS setup
162after provision to manually turn on the option.
163
164If the option is already enabled when removing the enrolled certificates in
165BIOS setup, this step can be ignored.
166
167##### Re-trigger automatic provision
168By default, the "Automatic Certificate Provision" option is hidden in boot
169menu for the first boot. If the user would like to clear the certificates
170provisioned by the "Automatic Certificate Provision" option in BIOS setup, this
171hidden boot option will be shown in boot menu, allowing to re-trigger it when
172necessary.
173
174### Signing
175By default, the build system uses DB.key to sign shim, and uses vendor_cert.key
176to sign SELoader, grub, grub configuration file, kernel and initramfs image
177during the build.
178
179### Verficiation
180
181#### UEFI Secure Boot Verification
182UEFI BIOS will validate the integrity of shim bootloader with a certificate in
183DB before running it.
184
185#### Bootloader Verification
186When the shim loads SELoader and SELoader loads grub, if both UEFI Secure Boot
187and MOK Secure Boot are already enabled, the upper bootloader uses a list of
188certificate to check the integrity of lower bootloader.
189
190- Blacklist check
191 If the lower bootloader is signed with a key corresponding to a certificate
192 within any of a policy object below, the boot failure will occur.
193
194 * Vendor DBX
195 * DBX
196 * MokListX (MOK certificate blacklist)
197
198- Whitelist check
199 If the lower bootloader is signed with a key corresponding to a certificate
200 within any of a policy object below, the boot success will occur.
201
202 * DB
203 * MokList (MOK certificate whitelist)
204 * Shim certificate (only for PE image)
205 * Vendor certificate
206
207If the lower bootloader is not signed or signed by a key not corresponding to
208any policy objects mentioned above, the boot failure will occur.
209
210The benefit of these behaviors allow the end user to regulate the secure boot
211even without the ownership of DB on Microsoft certificated hardware.
212
213##### SELoader Verification
214The SELoader is designed to authenticate the non-PE files, such as grub.cfg,
215kernel (without EFI stub support) and initrd, which cannot be verified by
216the verification protocol registered by the shim loader.
217
218In order to conveniently authenticate the PE file with gBS->LoadImage()
219and gBS->StartImage(), the SELoader hooks EFI Security2 Architectural
220Protocol and employs verification protocol provided by the shim loader to
221verify the PE file. If only UEFI Secure Boot is enabled, the SELoader just
222simplily calls gBS->LoadImage() and gBS->StartImage() to allow UEFI BIOS
223to verify the PE file.
224
225The SELoader publishes MOK2 verification protocol which provides a flexible
226interface to allow the bootloader to verify the file, file buffer or
227memory buffer without knowing the file format.
228
229In order to establish the chain of trust, the SELoader is required to be
230signed by a private key corresponding to a DB certificate, the shim
231certificate, the vendor certificate or a MOK certificate. The specific
232key is determined by the secure boot scheme you will use.
233
234See more details about the SELoader in its README file.
235
236#### Grub Configuration File Verification
237Grub can call the MOK2 verification protocol registered by the SELoader
238to validate the integrity of grub configuration file before parsing it.
239
240This protection prevents from tampering the grub configuration file from
241disabling certains kernel security mechanism such as selinux, IMA and so on.
242
243#### Kernel Verification
244When SELoader loads the kernel image with the linux command, if both UEFI
245Secure Boot and MOK Secure Boot are already enabled, grub will call the
246verification protocol installed by SELoader to validate the kernel image.
247
248Alternately, if grub loads the kernel image with the chainloader command,
249if both UEFI Secure Boot and MOK Secure Boot are already enabled, grub will
250call the verification protocol installed by shim to validate the kernel image.
251
252By default, the kernel image is signed by vendor certificate and then signed
253again to generate the .p7b signature file.
254
255#### Initramfs Verification
256When SELoader loads the kernel image with the initrd command, if both UEFI
257Secure Boot and MOK Secure Boot are already enabled, grub will call the
258verification protocol installed by SELoader to validate the initramfs image.
259
260#### Verification Failure
261Either situation will cause a failure of verification.
262- A boot component is not signed.
263- A boot component is signed by a key which doesn't correspond to any
264 certificate in whitelists such as DB and shim-managed certificates.
265- A boot component is signed by a key which corresponds to a certificate in
266 blacklist such as DBX and shim-managed certificates in MOKX.
267
268Each boot component may have different verification failure phenomenon.
269- If SELoader fails signature check, UEFI BIOS boot manager will print an error
270 message about the image authentication failure.
271- If grub fails signature check, an image authentication failure message is
272 printed and the system hangs.
273- If a grub configuration file fails the signature check, an authentication
274 failure message is printed and grub hangs.
275- If kernel image fails signature check, grub returns back to the boot menu.
276- If initrd fails signature check, grub returns back to the boot menu.
277
278### MOK Secure Boot and the shim bootloader
279MOK (Machine Owner Key) Secure Boot is based on UEFI Secure Boot, adding
280the shim bootloader to chainloader the second-stage bootloader
281"SELoader" and eventually chainliader to the third-stage bootloader "grub".
282
283[ Quoting: https://github.com/rhinstaller/shim ]
284shim is a trivial EFI application that, when run, attempts to open and
285execute another application. It will initially attempt to do this via the
286standard EFI LoadImage() and StartImage() calls. If these fail (because secure
287boot is enabled and the binary is not signed with an appropriate key, for
288instance) it will then validate the binary against a built-in certificate. If
289this succeeds and if the binary or signing key are not blacklisted then shim
290will relocate and execute the binary.
291
292shim will also install a protocol which permits the second-stage bootloader
293to perform similar binary validation. This protocol has a GUID as described
294in the shim.h header file and provides a single entry point. On 64-bit systems
295this entry point expects to be called with SysV ABI rather than MSABI, and
296so calls to it should not be wrapped.
297[ End of Quote ]
298
299In most cases, the hardware coming out of the factory is already provisioned
300with a default certificate used to verify the bootloader and issued by
301Microsoft Corporation UEFI CA 2011. This kind of hardware is so-called
302Microsoft certificated hardware.
303
304Obviously, this requirement needs a bootloader loaded by BIOS must be signed
305by Microsoft. Microsoft provides the signing service (not free), but only
306accept shim bootloader for Linux world. Refer to [Microsoft's signing policy](http://blogs.msdn.com/b/windows_hardware_certification/archive/2013/12/03/microsoft-uefi-ca-signing-policy-updates.aspx).
307
308It is allowed to remove all default certificates and use the self-owned keys to
309provision UEFI Secure Boot, but this is not practical for ODM/OEM devices
310during the manufacture phrase. See the section "Out-of-box Experience".
311
312For a good user experience, shim + SELoader + grub is an excellent combination
313to handle Microsoft certificated hardware. With this model, SELoader and grub
314are signed by a shim-managed certificate without being subject to the limit from
315Microsoft's signing policy, and the manual provision is thus unnecessary.
316
317#### mokutil and MOK Manager
318mokutil is a tool to import or delete the machines owner keys stored in the
319database of shim. mokutil creates the requests and MOK manager will be
320automatically launched by shim as long as it detects the pending requests.
321The physical present user will be prompted to run the operations corresponding
322to the requests. Note the operation is required to be authenticated by MOK
323management password set by mokutil.
324
325Refer to mokutil man page for the detailed usages.
326
327##### MOK Management Password
328MOK management password is the authentication information to allow MOK manager
329to grant the request regarding of MOK management. To set the password, run
330mokutil with the option --password. In addition, there are 4 input methods to
331provide the password. By default, mokutil prompts the user to input the
332password and then wraps the password to sha256 password hash. For other 3
333methods, refer to the uses of option --hash-file, --root-pw and --simple-hash.
334
335##### Enroll the MOK certificate
336Here is an example showing how to enroll a DER formatted X509 certificate to
337the database of shim.
338```
339# mokutil --import <cert.cer>
340```
341where `<cert.cer>` is the MOK certificate corresponding to the private key used
342to sign either grub or kernel.
343
344To convert a PEM, for exmaple, the shim_cert.pem, to a DER formatted X509
345certificate, type the command:
346```
347$ openssl x509 -in shim_cert.pem -inform PEM -out shim_cert.cer -outform DER
348```
349
350##### List the enrollment requests
351The several enrollment requests can be submitted before system reboot. Run the
352following command to check all enrollment requests.
353```
354# mokutil --list-new
355```
356
357##### Revoke the enrollment requests
358Note the revocation operation will remove all enrollment requests.
359```
360# mokutil --revoke-import
361```
362
363##### Test the MOK certificate
364If you cannot confirm whether a certificate has been enrolled or not, type the
365following command for a check:
366```
367# mokutil --test-key <cert.cer>
368```
369
370##### Delete the MOK certificate
371Removing an useless MOK certificate is also supported.
372```
373# mokutil --delete <cert.cer>
374```
375Refer to the options --list-delete and --revoke-delete to list and revoke the
376MOKs.
377
378##### Reset MOK certificates
379This request will clear all enrolled MOK certificates.
380```
381# mokutil --reset
382```
383
384##### Disable/Enable MOK Secure Boot
385MOK Secure Boot can be enabled or disabled regardless of the setting of UEFI
386Secure Boot.
387```
388# mokutil --disable-validation // disable MOK Secure Boot
389# mokutil --enable-validation // enable MOK Secure Boot
390```
391
392Note that MOK Secure Boot is based on UEFI Secure Boot. If UEFI Secure Boot
393is disabled, MOK Secure Boot will be automatically inactive. Type the
394following command to check the status of UEFI Secure Boot.
395```
396# mokutil --sb-state
397```
398
399##### Other options
400Refer to the options --import-hash and --delete-hash to manage hash-based
401signature. The options --pk, --kek, --db and --dbx are useful to check
402the content of the policy objects used in UEFI Secure Boot.
403
404##### Manage blacklist
405All above mentioned are talking MOK which is acting as whitelist to
406authenticate the verified image to launch. Actually, there is a contrary
407policy object called MOKX, acting as blacklist to deny the untrusted
408image to launch. Also, MOKX as blacklist is handled by shim prior to MOK
409as whitelist.
410
411For the management of blacklist, add the option --mokx with the following
412options to change the operation target from MOK to the following options.
413
414--list-enrolled
415--test-key
416--list-new
417--list-delete
418--import
419--delete
420--import-hash
421--delete-hash
422--reset
423--revoke-import
424--revoke-delete
425
426##### Handle MOK Secure Boot Failure with MOK Manager
427If either grub or SELoader is not signed or signed with an unauthorized
428certificate, the shim will prompt the end user a UI called MOK manager to
429guide the user to enroll the certificate or hash of the image.
430
431The policy of the selection between digest and certificate for next step is
432decided by whether the unauthorized grub or SELoader is signed or not.
433
434If the grub or SELoader is not signed at all, you have to always select
435the calculation of the digest based on the file. Note that once grub or SELoader
436is updated and its digest is changed, you have to relaunch the MOK manager
437to enroll the new digests.
438
439If the grub or SELoader is signed by an unauthorized certificate, enrolling the
440signing certificate is the preferred way. Copy the certificate to the boot
441drive and then select the certificate in MOK manager. Note that the
442certificate for the selection must be **DER formatted**.
443
444If doing so, the unauthorized grub or SELoader will be verified successfully
445after exiting MOK Manager.
446
447### Grub Lockdown
448In order to prevent from tampering the kernel command line or loading an
449unsigned boot component, grub is locked if UEFI Secure Boot is enabled. In this
450situation, the end user cannot enter into command or edit line via pressing 'c'
451and 'e'.
452
453If the user authentication is enabled, the access to command or edit line is
454protected by a password. In this situation, grub is unlockable.
455
456Rescue mode is always disabled as long as UEFI Secure Boot is enabled.
457
458### Known Issues
459- The 32-bit MOK Secure Boot is not validated. In other words, loading 32-bit
460shim, MOK manager, grub and kernel is not supported.
461
462### Reference
463[OpenEmbedded layer for EFI secure boot features](https://github.com/jiazhang0/meta-efi-secure-boot)
diff --git a/meta-efi-secure-boot/conf/layer.conf b/meta-efi-secure-boot/conf/layer.conf
new file mode 100644
index 0000000..f453a5c
--- /dev/null
+++ b/meta-efi-secure-boot/conf/layer.conf
@@ -0,0 +1,16 @@
1# We have a conf and classes directory, add to BBPATH
2BBPATH .= ":${LAYERDIR}"
3
4# We have recipes-* directories, add to BBFILES
5BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
6 ${LAYERDIR}/recipes-*/*/*.bbappend"
7
8BBFILE_COLLECTIONS += "efi-secure-boot"
9BBFILE_PATTERN_efi-secure-boot = "^${LAYERDIR}/"
10BBFILE_PRIORITY_efi-secure-boot = "10"
11
12LAYERDEPENDS_efi-secure-boot = "\
13 core \
14 openembedded-layer \
15 signing-key \
16"
diff --git a/meta-efi-secure-boot/recipes-base/packagegroups/packagegroup-efi-secure-boot.bb b/meta-efi-secure-boot/recipes-base/packagegroups/packagegroup-efi-secure-boot.bb
new file mode 100644
index 0000000..a2b35b1
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-base/packagegroups/packagegroup-efi-secure-boot.bb
@@ -0,0 +1,28 @@
1DESCRIPTION = "EFI Secure Boot packages for secure-environment."
2LICENSE = "MIT"
3LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \
4 file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
5
6S = "${WORKDIR}"
7
8ALLOW_EMPTY_${PN} = "1"
9
10pkgs = " \
11 grub-efi \
12 efitools \
13 efibootmgr \
14 mokutil \
15 seloader \
16 shim \
17"
18
19RDEPENDS_${PN}_x86 = "${pkgs}"
20RDEPENDS_${PN}_x86-64 = "${pkgs}"
21
22kmods = " \
23 kernel-module-efivarfs \
24 kernel-module-efivars \
25"
26
27RRECOMMENDS_${PN}_x86 += "${kmods}"
28RRECOMMENDS_${PN}_x86-64 += "${kmods}"
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools-native_git.bb b/meta-efi-secure-boot/recipes-bsp/efitools/efitools-native_git.bb
new file mode 100644
index 0000000..890abcf
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools-native_git.bb
@@ -0,0 +1,11 @@
1require efitools.inc
2
3inherit native
4
5DEPENDS_append = " gnu-efi-native"
6
7EXTRA_OEMAKE_append = " \
8 INCDIR_PREFIX='${STAGING_DIR_NATIVE}' \
9 CRTPATH_PREFIX='${STAGING_DIR_NATIVE}' \
10 EXTRA_LDFLAGS='-Wl,-rpath,${libdir}' \
11"
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools.inc b/meta-efi-secure-boot/recipes-bsp/efitools/efitools.inc
new file mode 100644
index 0000000..9a9888c
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools.inc
@@ -0,0 +1,63 @@
1SUMMARY = "Tools to support reading and manipulating the UEFI signature database"
2DESCRIPTION = "\
3From the EFI Tools package in the Linux user-space, it's now possible \
4to read and manipulate the UEFI signatures database via the new \
5efi-readvar and efi-updatevar commands. Aside from needing efitools \
61.4, the EFIVARFS file-system is also needed, which was only introduced \
7in the Linux 3.8 kernel. \
8"
9
10LICENSE = "GPLv2"
11LIC_FILES_CHKSUM = "file://COPYING;md5=e28f66b16cb46be47b20a4cdfe6e99a1"
12
13SRC_URI = " \
14 git://git.kernel.org/pub/scm/linux/kernel/git/jejb/efitools.git \
15 file://Fix-for-the-cross-compilation.patch \
16 file://Kill-all-the-build-warning-caused-by-implicit-declar.patch \
17 file://Fix-the-wrong-dependency-for-blacklist.esl.patch \
18 file://LockDown-run-system-warm-reset-after-the-key-provisi.patch \
19 file://Allow-to-override-tools-for-target-build.patch \
20 file://Fix-help2man-failure.patch \
21 file://Don-t-build-PreLoader.efi.patch \
22 file://Reuse-xxdi.pl.patch \
23 file://Add-static-keyword-for-IsValidVariableHeader.patch \
24"
25
26SRCREV = "0649468475d20d8ca5634433c4912467cef3ce93"
27PV = "1.7.0+git${SRCPV}"
28
29PARALLEL_MAKE = ""
30
31inherit perlnative
32
33DEPENDS_append += "\
34 help2man-native openssl-native sbsigntool-native \
35 libfile-slurp-perl-native \
36"
37
38S = "${WORKDIR}/git"
39
40EXTRA_OEMAKE = " \
41 HELP2MAN='${STAGING_BINDIR_NATIVE}/help2man' \
42 OPENSSL='${STAGING_BINDIR_NATIVE}/openssl' \
43 SBSIGN='${STAGING_BINDIR_NATIVE}/sbsign' \
44 OPENSSL_LIB='${STAGING_LIBDIR}' \
45 NM='${NM}' AR='${AR}' \
46"
47EXTRA_OEMAKE_append_x86 += " ARCH=ia32"
48EXTRA_OEMAKE_append_x86-64 += " ARCH=x86_64"
49
50# LDFLAGS is used by LD not CC, so remove '-Wl,'
51LDFLAGS := "${@oe_filter_out('-Wl,', '${LDFLAGS}', d)}"
52BUILD_LDFLAGS := "${@oe_filter_out('-Wl,', '${BUILD_LDFLAGS}', d)}"
53
54do_compile_prepend() {
55 sed -i -e "1s:#!.*:#!/usr/bin/env nativeperl:" xxdi.pl
56}
57
58EFI_BOOT_PATH = "/boot/efi/EFI/BOOT"
59FILES_${PN} += "${EFI_BOOT_PATH}"
60
61do_install() {
62 oe_runmake install DESTDIR='${D}${base_prefix}'
63}
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Add-static-keyword-for-IsValidVariableHeader.patch b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Add-static-keyword-for-IsValidVariableHeader.patch
new file mode 100644
index 0000000..f0b8246
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Add-static-keyword-for-IsValidVariableHeader.patch
@@ -0,0 +1,38 @@
1From 960a5fc7c58c875827797b6f4afed2684acc2cde Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Sun, 12 Jun 2016 13:45:54 +0800
4Subject: [PATCH] Add static keyword for IsValidVariableHeader()
5
6Upstream-Status: Pending
7
8GCC does not inline any functions when not optimizing (-O0 specified) unless
9you specify "always_inline" attribute for the function.
10
11By default, GCC complies with C89 standard for c code, which means
12"inline" equals to "extern inline" and thus the definition is used only for
13inlining with the assembly code actually generated.
14
15Therefore, "static inline" is used for both purposes. If -O0 is specified,
16GCC will generate the assembly code as long as the function is referred.
17
18Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
19---
20 include/variableformat.h | 2 +-
21 1 files changed, 1 insertions(+), 1 deletions(-)
22
23diff --git a/include/variableformat.h b/include/variableformat.h
24index 32cde05..45d0ebb 100644
25--- a/include/variableformat.h
26+++ b/include/variableformat.h
27@@ -109,7 +109,7 @@ typedef struct {
28
29 #pragma pack()
30
31-inline BOOLEAN
32+static inline BOOLEAN
33 IsValidVariableHeader (VARIABLE_HEADER *vh) {
34 if (vh == NULL || vh->StartId != VARIABLE_DATA)
35 return FALSE;
36--
371.7.1
38
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Allow-to-override-tools-for-target-build.patch b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Allow-to-override-tools-for-target-build.patch
new file mode 100644
index 0000000..e326c3c
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Allow-to-override-tools-for-target-build.patch
@@ -0,0 +1,94 @@
1From 1613bae3a9760b3cdcbf8f43e750c475d69ad8bb Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Wed, 23 Mar 2016 19:05:29 +0800
4Subject: [PATCH] Allow to override tools for target build
5
6Upstream-Status: Pending
7
8These tools should use the ones from native build.
9
10Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
11---
12 Make.rules | 22 +++++++++++++---------
13 Makefile | 4 ++--
14 2 files changed, 15 insertions(+), 11 deletions(-)
15
16diff --git a/Make.rules b/Make.rules
17index 5e8cb82..4aa7650 100644
18--- a/Make.rules
19+++ b/Make.rules
20@@ -34,6 +34,10 @@ AR = ar
21 OPENSSL = openssl
22 SBSIGN = sbsign
23 XXD = xxd
24+SIGN_EFI_SIG_LIST ?= ./sign-efi-sig-list
25+CERT_TO_EFI_SIG_LIST ?= ./cert-to-efi-sig-list
26+CERT_TO_EFI_HASH_LIST ?= ./cert-to-efi-hash-list
27+HASH_TO_EFI_SIG_LIST ?= ./hash-to-efi-sig-list
28 MYGUID = 11111111-2222-3333-4444-123456789abc
29 INSTALL = install
30 BINDIR = $(DESTDIR)/usr/bin
31@@ -75,34 +79,34 @@ endif
32 $(XXD) -i $< > $@
33
34 %.hash: %.efi hash-to-efi-sig-list
35- ./hash-to-efi-sig-list $< $@
36+ $(HASH_TO_EFI_SIG_LIST) $< $@
37
38 %-blacklist.esl: %.crt cert-to-efi-sig-list
39- ./cert-to-efi-sig-list $< $@
40+ $(CERT_TO_EFI_SIG_LIST) $< $@
41
42 %-hash-blacklist.esl: %.crt cert-to-efi-hash-list
43- ./cert-to-efi-hash-list $< $@
44+ $(CERT_TO_EFI_HASH_LIST) $< $@
45
46 %.esl: %.crt cert-to-efi-sig-list
47- ./cert-to-efi-sig-list -g $(MYGUID) $< $@
48+ $(CERT_TO_EFI_SIG_LIST) -g $(MYGUID) $< $@
49
50 getcert = $(shell if [ "$(1)" = "PK" -o "$(1)" = "KEK" ]; then echo "-c PK.crt -k PK.key"; else echo "-c KEK.crt -k KEK.key"; fi)
51 getvar = $(shell if [ "$(1)" = "PK" -o "$(1)" = "KEK" ]; then echo $(1); else echo db; fi)
52
53 %.auth: %.esl PK.crt KEK.crt sign-efi-sig-list
54- ./sign-efi-sig-list $(call getcert,$*) $(call getvar,$*) $< $@
55+ $(SIGN_EFI_SIG_LIST) $(call getcert,$*) $(call getvar,$*) $< $@
56
57 %-update.auth: %.esl PK.crt KEK.crt sign-efi-sig-list
58- ./sign-efi-sig-list -a $(call getcert,$*) $(call getvar,$*) $< $@
59+ $(SIGN_EFI_SIG_LIST) -a $(call getcert,$*) $(call getvar,$*) $< $@
60
61 %-pkupdate.auth: %.esl PK.crt sign-efi-sig-list
62- ./sign-efi-sig-list -a -c PK.crt -k PK.key $(call getvar,$*) $< $@
63+ $(SIGN_EFI_SIG_LIST) -a -c PK.crt -k PK.key $(call getvar,$*) $< $@
64
65 %-blacklist.auth: %-blacklist.esl KEK.crt sign-efi-sig-list
66- ./sign-efi-sig-list -a -c KEK.crt -k KEK.key dbx $< $@
67+ $(SIGN_EFI_SIG_LIST) -a -c KEK.crt -k KEK.key dbx $< $@
68
69 %-pkblacklist.auth: %-blacklist.esl PK.crt sign-efi-sig-list
70- ./sign-efi-sig-list -a -c PK.crt -k PK.key dbx $< $@
71+ $(SIGN_EFI_SIG_LIST) -a -c PK.crt -k PK.key dbx $< $@
72
73 %.o: %.c
74 $(CC) $(INCDIR) $(cflags) $(cppflags) -c $< -o $@
75diff --git a/Makefile b/Makefile
76index 15fc944..c4e0081 100644
77--- a/Makefile
78+++ b/Makefile
79@@ -66,10 +66,10 @@ noPK.esl:
80 > noPK.esl
81
82 noPK.auth: noPK.esl PK.crt sign-efi-sig-list
83- ./sign-efi-sig-list -t "$(shell date --date='1 second' +'%Y-%m-%d %H:%M:%S')" -c PK.crt -k PK.key PK $< $@
84+ $(SIGN_EFI_SIG_LIST) -t "$(shell date --date='1 second' +'%Y-%m-%d %H:%M:%S')" -c PK.crt -k PK.key PK $< $@
85
86 ms-%.esl: ms-%.crt cert-to-efi-sig-list
87- ./cert-to-efi-sig-list -g $(MSGUID) $< $@
88+ $(CERT_TO_EFI_SIG_LIST) -g $(MSGUID) $< $@
89
90 hashlist.h: HashTool.hash
91 cat $^ > /tmp/tmp.hash
92--
931.9.1
94
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Build-DBX-by-default.patch b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Build-DBX-by-default.patch
new file mode 100644
index 0000000..9c20c7a
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Build-DBX-by-default.patch
@@ -0,0 +1,44 @@
1From e909a2d4777a6fd2644ff89361539db141c0a67f Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Sat, 28 Jan 2017 13:42:28 +0800
4Subject: [PATCH] Build DBX by default
5
6Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
7---
8 Makefile | 6 +++---
9 1 file changed, 3 insertions(+), 3 deletions(-)
10
11diff --git a/Makefile b/Makefile
12index a1fc538..7f767c8 100644
13--- a/Makefile
14+++ b/Makefile
15@@ -26,7 +26,7 @@ include Make.rules
16
17 EFISIGNED = $(patsubst %.efi,%-signed.efi,$(EFIFILES))
18
19-all: $(EFIFILES) $(BINARIES) $(MANPAGES) noPK.auth $(KEYAUTH) \
20+all: $(EFIFILES) $(BINARIES) $(MANPAGES) noPK.auth $(KEYAUTH) DBX.auth \
21 $(KEYUPDATEAUTH) $(KEYBLACKLISTAUTH) $(KEYHASHBLACKLISTAUTH)
22
23
24@@ -49,7 +49,7 @@ lib/asn1/libasn1.a lib/asn1/libasn1-efi.a: FORCE
25
26 .SUFFIXES: .crt
27
28-.KEEP: PK.crt KEK.crt DB.crt PK.key KEK.key DB.key PK.esl DB.esl KEK.esl \
29+.KEEP: PK.crt KEK.crt DB.crt DBX.crt PK.key KEK.key DB.key PK.esl DB.esl KEK.esl DBX.esl \
30 $(EFIFILES)
31
32 LockDown.o: PK.h KEK.h DB.h DBX.h
33@@ -116,7 +116,7 @@ flash-var: flash-var.o lib/lib.a
34 $(CC) $(ARCH3264) -o $@ $< lib/lib.a
35
36 clean:
37- rm -f PK.* KEK.* DB.* $(EFIFILES) $(EFISIGNED) $(BINARIES) *.o *.so
38+ rm -f PK.* KEK.* DB.* DBX.* $(EFIFILES) $(EFISIGNED) $(BINARIES) *.o *.so
39 rm -f noPK.*
40 rm -f doc/*.1
41 $(MAKE) -C lib clean
42--
432.7.4
44
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Don-t-build-PreLoader.efi.patch b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Don-t-build-PreLoader.efi.patch
new file mode 100644
index 0000000..9874d71
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Don-t-build-PreLoader.efi.patch
@@ -0,0 +1,40 @@
1From 95e167f432f1a6d8c96aeca73871122806007c9f Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Thu, 28 Apr 2016 11:21:33 +0800
4Subject: [PATCH] Don't build PreLoader.efi
5
6Upstream-Status: Pending
7
8The upstream has an obvious build failure:
9| PreLoader.c:45:2: error: too few arguments to function 'security_policy_install'
10| status = security_policy_install();
11| ^
12| In file included from PreLoader.c:14:0:
13| /buildarea3/jzhang0/projects/wrl8/intel-x86-64-gwp-scp/bitbake_build/tmp/work/x86_64-linux/efitools-native/1.7.0+gitAUTOINC+20a8fdc4ec-r0/git/include/security_policy.h:4:1: note: declared here
14| security_policy_install(BOOLEAN (*override)(void), POLICY_FUNCTION allow, POLICY_FUNCTION deny);
15| ^
16
17We are waiting for the upstream fix and remove this workaround in next
18refresh.
19
20Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
21---
22 Makefile | 2 +-
23 1 file changed, 1 insertion(+), 1 deletion(-)
24
25diff --git a/Makefile b/Makefile
26index b3bb73a..da363a6 100644
27--- a/Makefile
28+++ b/Makefile
29@@ -5,7 +5,7 @@ BINARIES = cert-to-efi-sig-list sig-list-to-certs sign-efi-sig-list \
30 flash-var
31
32 ifeq ($(ARCH),x86_64)
33-EFIFILES += PreLoader.efi
34+#EFIFILES += PreLoader.efi
35 endif
36
37 MSGUID = 77FA9ABD-0359-4D32-BD60-28F4E78F784B
38--
391.9.1
40
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Fix-for-the-cross-compilation.patch b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Fix-for-the-cross-compilation.patch
new file mode 100644
index 0000000..75c64ae
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Fix-for-the-cross-compilation.patch
@@ -0,0 +1,193 @@
1From ab2eb06c1271e46e07add5a0b0a444353d45e055 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Tue, 15 Mar 2016 21:28:33 +0800
4Subject: [PATCH] Fix for the cross compilation
5
6Upstream-Status: Pending
7
8Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
9---
10 Make.rules | 52 +++++++++++++++++++++++++++++-----------------------
11 Makefile | 14 +++++++-------
12 2 files changed, 36 insertions(+), 30 deletions(-)
13
14diff --git a/Make.rules b/Make.rules
15index 88d5481..7e89332 100644
16--- a/Make.rules
17+++ b/Make.rules
18@@ -13,21 +13,27 @@ ARCH3264 =
19 else
20 $(error unknown architecture $(ARCH))
21 endif
22-INCDIR = -I$(TOPDIR)include/ -I/usr/include/efi -I/usr/include/efi/$(ARCH) -I/usr/include/efi/protocol
23-CPPFLAGS = -DCONFIG_$(ARCH)
24-CFLAGS = -O2 $(ARCH3264) -fpic -Wall -fshort-wchar -fno-strict-aliasing -fno-merge-constants -fno-stack-protector -ffreestanding -fno-stack-check
25-LDFLAGS = -nostdlib
26+INCDIR = -I$(TOPDIR)include/ -I$(INCDIR_PREFIX)/usr/include/efi -I$(INCDIR_PREFIX)/usr/include/efi/$(ARCH) -I$(INCDIR_PREFIX)/usr/include/efi/protocol
27+cppflags = -DCONFIG_$(ARCH)
28+cflags = -O2 $(ARCH3264) -fpic -Wall -fshort-wchar -fno-strict-aliasing -fno-merge-constants -fno-stack-protector -ffreestanding -fno-stack-check $(CFLAGS)
29+ldflags = -nostdlib $(LDFLAGS)
30 CRTOBJ = crt0-efi-$(ARCH).o
31 CRTPATHS = /lib /lib64 /lib/efi /lib64/efi /usr/lib /usr/lib64 /usr/lib/efi /usr/lib64/efi
32-CRTPATH = $(shell for f in $(CRTPATHS); do if [ -e $$f/$(CRTOBJ) ]; then echo $$f; break; fi; done)
33+CRTPATH = $(shell for f in $(CRTPATHS); do if [ -e $(CRTPATH_PREFIX)/$$f/$(CRTOBJ) ]; then echo $(CRTPATH_PREFIX)/$$f; break; fi; done)
34 CRTOBJS = $(CRTPATH)/$(CRTOBJ)
35 # there's a bug in the gnu tools ... the .reloc section has to be
36 # aligned otherwise the file alignment gets screwed up
37 LDSCRIPT = elf_$(ARCH)_efi.lds
38-LDFLAGS += -shared -Bsymbolic $(CRTOBJS) -L $(CRTPATH) -T $(LDSCRIPT)
39+ldflags += -shared -Bsymbolic $(CRTOBJS) -L $(CRTPATH) -T $(LDSCRIPT)
40+ldflags_openssl = $(addprefix -L$(CRTPATH_PREFIX),$(CRTPATHS))
41 LOADLIBES = -lefi -lgnuefi $(shell $(CC) $(ARCH3264) -print-libgcc-file-name)
42 FORMAT = --target=efi-app-$(ARCH)
43 OBJCOPY = objcopy
44+NM = nm
45+AR = ar
46+OPENSSL = openssl
47+SBSIGN = sbsign
48+XXD = xxd
49 MYGUID = 11111111-2222-3333-4444-123456789abc
50 INSTALL = install
51 BINDIR = $(DESTDIR)/usr/bin
52@@ -36,23 +42,23 @@ EFIDIR = $(DESTDIR)/usr/share/efitools/efi
53 DOCDIR = $(DESTDIR)/usr/share/efitools
54
55 # globally use EFI calling conventions (requires gcc >= 4.7)
56-CFLAGS += -DGNU_EFI_USE_MS_ABI
57+cflags += -DGNU_EFI_USE_MS_ABI
58
59 ifeq ($(ARCH),x86_64)
60- CFLAGS += -DEFI_FUNCTION_WRAPPER -mno-red-zone
61+ cflags += -DEFI_FUNCTION_WRAPPER -mno-red-zone
62 endif
63
64 ifeq ($(ARCH),ia32)
65- CFLAGS += -mno-red-zone
66+ cflags += -mno-red-zone
67 endif
68
69 ifeq ($(ARCH),arm)
70- LDFLAGS += --defsym=EFI_SUBSYSTEM=0x0a
71+ ldflags += --defsym=EFI_SUBSYSTEM=0x0a
72 FORMAT = -O binary
73 endif
74
75 ifeq ($(ARCH),aarch64)
76- LDFLAGS += --defsym=EFI_SUBSYSTEM=0x0a
77+ ldflags += --defsym=EFI_SUBSYSTEM=0x0a
78 FORMAT = -O binary
79 endif
80
81@@ -61,12 +67,12 @@ endif
82 -j .rel -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* \
83 -j .reloc $(FORMAT) $*.so $@
84 %.so: %.o
85- $(LD) $(LDFLAGS) $^ -o $@ $(LOADLIBES)
86+ $(LD) $(ldflags) $^ -o $@ $(LOADLIBES)
87 # check we have no undefined symbols
88- nm -D $@ | grep ' U ' && exit 1 || exit 0
89+ ${NM} -D $@ | grep ' U ' && exit 1 || exit 0
90
91 %.h: %.auth
92- ./xxdi.pl $< > $@
93+ $(XXD) -i $< > $@
94
95 %.hash: %.efi hash-to-efi-sig-list
96 ./hash-to-efi-sig-list $< $@
97@@ -99,28 +105,28 @@ getvar = $(shell if [ "$(1)" = "PK" -o "$(1)" = "KEK" ]; then echo $(1); else ec
98 ./sign-efi-sig-list -a -c PK.crt -k PK.key dbx $< $@
99
100 %.o: %.c
101- $(CC) $(INCDIR) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
102+ $(CC) $(INCDIR) $(cflags) $(cppflags) -c $< -o $@
103
104 %.efi.o: %.c
105- $(CC) $(INCDIR) $(CFLAGS) $(CPPFLAGS) -fno-toplevel-reorder -DBUILD_EFI -c $< -o $@
106+ $(CC) $(INCDIR) $(cflags) $(cppflags) -fno-toplevel-reorder -DBUILD_EFI -c $< -o $@
107
108 %.efi.s: %.c
109- $(CC) -S $(INCDIR) $(CFLAGS) $(CPPFLAGS) -fno-toplevel-reorder -DBUILD_EFI -c $< -o $@
110+ $(CC) -S $(INCDIR) $(cflags) $(cppflags) -fno-toplevel-reorder -DBUILD_EFI -c $< -o $@
111
112 %.crt:
113- openssl req -new -x509 -newkey rsa:2048 -subj "/CN=$*/" -keyout $*.key -out $@ -days 3650 -nodes -sha256
114+ $(OPENSSL) req -new -x509 -newkey rsa:2048 -subj "/CN=$*/" -keyout $*.key -out $@ -days 3650 -nodes -sha256
115
116 %.cer: %.crt
117- openssl x509 -in $< -out $@ -outform DER
118+ $(OPENSSL) x509 -in $< -out $@ -outform DER
119
120 %-subkey.csr:
121- openssl req -new -newkey rsa:2048 -keyout $*-subkey.key -subj "/CN=Subkey $* of KEK/" -out $@ -nodes
122+ $(OPENSSL) req -new -newkey rsa:2048 -keyout $*-subkey.key -subj "/CN=Subkey $* of KEK/" -out $@ -nodes
123
124 %-subkey.crt: %-subkey.csr KEK.crt
125- openssl x509 -req -in $< -CA DB.crt -CAkey DB.key -set_serial 1 -out $@ -days 365
126+ $(OPENSSL) x509 -req -in $< -CA DB.crt -CAkey DB.key -set_serial 1 -out $@ -days 365
127
128 %-signed.efi: %.efi DB.crt
129- sbsign --key DB.key --cert DB.crt --output $@ $<
130+ $(SBSIGN) --key DB.key --cert DB.crt --output $@ $<
131
132 ##
133 # No need for KEK signing
134@@ -129,7 +135,7 @@ getvar = $(shell if [ "$(1)" = "PK" -o "$(1)" = "KEK" ]; then echo $(1); else ec
135 # sbsign --key KEK.key --cert KEK.crt --output $@ $<
136
137 %.a:
138- ar rcv $@ $^
139+ $(AR) rcv $@ $^
140
141 doc/%.1: doc/%.1.in %
142 $(HELP2MAN) --no-info -i $< -o $@ ./$*
143diff --git a/Makefile b/Makefile
144index 774ee0a..46e4620 100644
145--- a/Makefile
146+++ b/Makefile
147@@ -73,7 +73,7 @@ ms-%.esl: ms-%.crt cert-to-efi-sig-list
148
149 hashlist.h: HashTool.hash
150 cat $^ > /tmp/tmp.hash
151- ./xxdi.pl /tmp/tmp.hash > $@
152+ $(XXD) -i /tmp/tmp.hash > $@
153 rm -f /tmp/tmp.hash
154
155
156@@ -88,28 +88,28 @@ HelloWorld.so: lib/lib-efi.a
157 ShimReplace.so: lib/lib-efi.a
158
159 cert-to-efi-sig-list: cert-to-efi-sig-list.o lib/lib.a
160- $(CC) $(ARCH3264) -o $@ $< -lcrypto lib/lib.a
161+ $(CC) $(ARCH3264) -o $@ $< $(ldflags_openssl) $(EXTRA_LDFLAGS) -lcrypto lib/lib.a
162
163 sig-list-to-certs: sig-list-to-certs.o lib/lib.a
164- $(CC) $(ARCH3264) -o $@ $< -lcrypto lib/lib.a
165+ $(CC) $(ARCH3264) -o $@ $< $(ldflags_openssl) $(EXTRA_LDFLAGS) -lcrypto lib/lib.a
166
167 sign-efi-sig-list: sign-efi-sig-list.o lib/lib.a
168- $(CC) $(ARCH3264) -o $@ $< -lcrypto lib/lib.a
169+ $(CC) $(ARCH3264) -o $@ $< $(ldflags_openssl) $(EXTRA_LDFLAGS) -lcrypto lib/lib.a
170
171 hash-to-efi-sig-list: hash-to-efi-sig-list.o lib/lib.a
172 $(CC) $(ARCH3264) -o $@ $< lib/lib.a
173
174 cert-to-efi-hash-list: cert-to-efi-hash-list.o lib/lib.a
175- $(CC) $(ARCH3264) -o $@ $< -lcrypto lib/lib.a
176+ $(CC) $(ARCH3264) -o $@ $< $(ldflags_openssl) $(EXTRA_LDFLAGS) -lcrypto lib/lib.a
177
178 efi-keytool: efi-keytool.o lib/lib.a
179 $(CC) $(ARCH3264) -o $@ $< lib/lib.a
180
181 efi-readvar: efi-readvar.o lib/lib.a
182- $(CC) $(ARCH3264) -o $@ $< -lcrypto lib/lib.a
183+ $(CC) $(ARCH3264) -o $@ $< $(ldflags_openssl) $(EXTRA_LDFLAGS) -lcrypto lib/lib.a
184
185 efi-updatevar: efi-updatevar.o lib/lib.a
186- $(CC) $(ARCH3264) -o $@ $< -lcrypto lib/lib.a
187+ $(CC) $(ARCH3264) -o $@ $< $(ldflags_openssl) $(EXTRA_LDFLAGS) -lcrypto lib/lib.a
188
189 flash-var: flash-var.o lib/lib.a
190 $(CC) $(ARCH3264) -o $@ $< lib/lib.a
191--
1921.9.1
193
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Fix-help2man-error.patch b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Fix-help2man-error.patch
new file mode 100644
index 0000000..eb61493
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Fix-help2man-error.patch
@@ -0,0 +1,28 @@
1From f2e4ff4e63f4a5f8a4452c970ca271091eeaec7d Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Sun, 18 Jun 2017 23:35:09 +0800
4Subject: [PATCH] Fix help2man error
5
6This issue may be caused by the poky compiler.
7
8Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
9---
10 Make.rules | 4 +++-
11 1 file changed, 3 insertions(+), 1 deletion(-)
12
13diff --git a/Make.rules b/Make.rules
14index 38c7a22..bda5518 100644
15--- a/Make.rules
16+++ b/Make.rules
17@@ -140,5 +140,7 @@ getvar = $(shell if [ "$(1)" = "PK" -o "$(1)" = "KEK" ]; then echo $(1); else ec
18 %.a:
19 $(AR) rcv $@ $^
20
21+HELP2MAN_PROG_PREFIX ?= .
22+
23 doc/%.1: doc/%.1.in %
24- $(HELP2MAN) --no-discard-stderr --no-info -i $< -o $@ ./$*
25+ $(HELP2MAN) --no-discard-stderr --no-info -i $< -o $@ $(HELP2MAN_PROG_PREFIX)/$*
26--
272.7.5
28
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Fix-help2man-failure.patch b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Fix-help2man-failure.patch
new file mode 100644
index 0000000..d5079da
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Fix-help2man-failure.patch
@@ -0,0 +1,25 @@
1From 546b8c36301bdcf540b3b027fd25baa9cff2abdc Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Wed, 23 Mar 2016 19:44:51 +0800
4Subject: [PATCH] Fix help2man failure
5
6Add --no-discard-stderr to work around the error.
7
8Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
9---
10 Make.rules | 2 +-
11 1 file changed, 1 insertion(+), 1 deletion(-)
12
13diff --git a/Make.rules b/Make.rules
14index 4aa7650..21926b0 100644
15--- a/Make.rules
16+++ b/Make.rules
17@@ -142,4 +142,4 @@ getvar = $(shell if [ "$(1)" = "PK" -o "$(1)" = "KEK" ]; then echo $(1); else ec
18 $(AR) rcv $@ $^
19
20 doc/%.1: doc/%.1.in %
21- $(HELP2MAN) --no-info -i $< -o $@ ./$*
22+ $(HELP2MAN) --no-discard-stderr --no-info -i $< -o $@ ./$*
23--
241.9.1
25
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Fix-the-wrong-dependency-for-blacklist.esl.patch b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Fix-the-wrong-dependency-for-blacklist.esl.patch
new file mode 100644
index 0000000..d5f863e
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Fix-the-wrong-dependency-for-blacklist.esl.patch
@@ -0,0 +1,28 @@
1From 52228c24af681463d73d5bd8454872b3e811855b Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Tue, 15 Mar 2016 21:07:31 +0800
4Subject: [PATCH] Fix the wrong dependency for %-blacklist.esl
5
6Upstream-Status: Pending
7
8Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
9---
10 Make.rules | 2 +-
11 1 file changed, 1 insertion(+), 1 deletion(-)
12
13diff --git a/Make.rules b/Make.rules
14index 48b02e4..08a2489 100644
15--- a/Make.rules
16+++ b/Make.rules
17@@ -77,7 +77,7 @@ endif
18 %.hash: %.efi hash-to-efi-sig-list
19 ./hash-to-efi-sig-list $< $@
20
21-%-blacklist.esl: %.crt cert-to-efi-hash-list
22+%-blacklist.esl: %.crt cert-to-efi-sig-list
23 ./cert-to-efi-sig-list $< $@
24
25 %-hash-blacklist.esl: %.crt cert-to-efi-hash-list
26--
271.9.1
28
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Kill-all-the-build-warning-caused-by-implicit-declar.patch b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Kill-all-the-build-warning-caused-by-implicit-declar.patch
new file mode 100644
index 0000000..f7f32c3
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Kill-all-the-build-warning-caused-by-implicit-declar.patch
@@ -0,0 +1,80 @@
1From 872a9d96386b819d2c5fd7581d2bdaf7ea61a5f8 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Tue, 15 Mar 2016 17:12:24 +0800
4Subject: [PATCH] Kill all the build warning caused by implicit declaration of
5 function
6
7Upstream-Status: Pending
8
9Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
10---
11 Loader.c | 1 +
12 cert-to-efi-hash-list.c | 2 +-
13 flash-var.c | 2 ++
14 lib/pecoff.c | 1 +
15 sign-efi-sig-list.c | 2 ++
16 5 files changed, 7 insertions(+), 1 deletion(-)
17
18diff --git a/Loader.c b/Loader.c
19index 1f9201a..044469a 100644
20--- a/Loader.c
21+++ b/Loader.c
22@@ -9,6 +9,7 @@
23 #include <efi.h>
24 #include <efilib.h>
25
26+#include <execute.h>
27 #include <simple_file.h>
28 #include <pecoff.h>
29 #include <sha256.h>
30diff --git a/cert-to-efi-hash-list.c b/cert-to-efi-hash-list.c
31index d4484f9..3792553 100644
32--- a/cert-to-efi-hash-list.c
33+++ b/cert-to-efi-hash-list.c
34@@ -3,7 +3,7 @@
35 *
36 * see COPYING file
37 */
38-
39+#define _GNU_SOURCE
40
41 #include <stdint.h>
42 #define __STDC_VERSION__ 199901L
43diff --git a/flash-var.c b/flash-var.c
44index aa10ae6..10429bc 100644
45--- a/flash-var.c
46+++ b/flash-var.c
47@@ -1,3 +1,5 @@
48+#define _GNU_SOURCE
49+
50 #include <stdlib.h>
51 #include <stdint.h>
52 #include <sys/types.h>
53diff --git a/lib/pecoff.c b/lib/pecoff.c
54index 26d9dcf..10b898a 100644
55--- a/lib/pecoff.c
56+++ b/lib/pecoff.c
57@@ -59,6 +59,7 @@
58 #endif
59 #endif
60
61+#include <execute.h>
62 #include <pecoff.h>
63 #include <guid.h>
64 #include <simple_file.h>
65diff --git a/sign-efi-sig-list.c b/sign-efi-sig-list.c
66index e19ef97..5abcf27 100644
67--- a/sign-efi-sig-list.c
68+++ b/sign-efi-sig-list.c
69@@ -3,6 +3,8 @@
70 *
71 * see COPYING file
72 */
73+#define _GNU_SOURCE
74+
75 #include <stdint.h>
76 #define __STDC_VERSION__ 199901L
77 #include <efi.h>
78--
791.9.1
80
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools/LockDown-disable-the-entrance-into-BIOS-setup-to-re-.patch b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/LockDown-disable-the-entrance-into-BIOS-setup-to-re-.patch
new file mode 100644
index 0000000..ec9849a
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/LockDown-disable-the-entrance-into-BIOS-setup-to-re-.patch
@@ -0,0 +1,47 @@
1From e259aecc645c6dd4c194a64d607124cd5a714f9a Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Wed, 15 Feb 2017 14:52:07 +0800
4Subject: [PATCH] LockDown: disable the entrance into BIOS setup to re-enable
5 secure boot
6
7In most cases, this step is not necessary.
8
9Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
10---
11 LockDown.c | 9 +++++++--
12 1 file changed, 7 insertions(+), 2 deletions(-)
13
14diff --git a/LockDown.c b/LockDown.c
15index 13c626f..fbde3f2 100644
16--- a/LockDown.c
17+++ b/LockDown.c
18@@ -20,6 +20,11 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
19 EFI_STATUS efi_status;
20 UINT8 SecureBoot, SetupMode;
21 UINTN DataSize = sizeof(SetupMode);
22+ /* This controls whether it is required to enter into BIOS setup in
23+ * order to re-enable UEFI secure boot. This operation is unnecessary
24+ * in most cases.
25+ */
26+ UINTN NeedSetAttempt = 0;
27
28 InitializeLib(image, systab);
29
30@@ -110,12 +115,12 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
31 * UEFI secure boot in BIOS setup.
32 */
33 Print(L"Prepare to execute system warm reset after 3 seconds ...\n");
34- if (!SecureBoot)
35+ if (NeedSetAttempt && !SecureBoot)
36 Print(L"After warm reset, enter to BIOS setup to enable UEFI Secure Boot.\n");
37
38 BS->Stall(3000000);
39
40- if (!SecureBoot)
41+ if (NeedSetAttempt && !SecureBoot)
42 SETOSIndicationsAndReboot(EFI_OS_INDICATIONS_BOOT_TO_FW_UI);
43 else
44 RT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
45--
462.7.4
47
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools/LockDown-enable-the-enrollment-for-DBX.patch b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/LockDown-enable-the-enrollment-for-DBX.patch
new file mode 100644
index 0000000..e0cb9b8
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/LockDown-enable-the-enrollment-for-DBX.patch
@@ -0,0 +1,85 @@
1From 49b6a0bf2b9c69d1fd682fbc9d2ad7a7f6abee77 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Fri, 22 Apr 2016 16:28:05 +0800
4Subject: [PATCH] LockDown: enable the enrollment for DBX
5
6Upstream-Status: Pending
7
8DBX acting as blacklist now is able to be enrolled.
9
10Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
11---
12 LockDown.c | 16 +++++++++++-----
13 Makefile | 4 +++-
14 2 files changed, 14 insertions(+), 6 deletions(-)
15
16diff --git a/LockDown.c b/LockDown.c
17index 821985c..fec2e79 100644
18--- a/LockDown.c
19+++ b/LockDown.c
20@@ -12,6 +12,7 @@
21 #include "PK.h"
22 #include "KEK.h"
23 #include "DB.h"
24+#include "DBX.h"
25
26 EFI_STATUS
27 efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
28@@ -47,6 +48,7 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
29 return efi_status;
30 }
31 Print(L"Created KEK Cert\n");
32+
33 efi_status = RT->SetVariable(L"db", &SIG_DB,
34 EFI_VARIABLE_NON_VOLATILE
35 | EFI_VARIABLE_RUNTIME_ACCESS
36@@ -58,15 +60,19 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
37 return efi_status;
38 }
39 Print(L"Created db Cert\n");
40-#if 0
41- /* testing revocation ... this will revoke the certificate
42- * we just enrolled in db */
43- efi_status = SetSecureVariable(L"dbx", DB_cer, DB_cer_len, SIG_DB, 0);
44+
45+ efi_status = RT->SetVariable(L"dbx", &SIG_DB,
46+ EFI_VARIABLE_NON_VOLATILE
47+ | EFI_VARIABLE_RUNTIME_ACCESS
48+ | EFI_VARIABLE_BOOTSERVICE_ACCESS
49+ | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS,
50+ DBX_auth_len, DBX_auth);
51 if (efi_status != EFI_SUCCESS) {
52 Print(L"Failed to enroll dbx: %d\n", efi_status);
53 return efi_status;
54 }
55-#endif
56+ Print(L"Created dbx Cert\n");
57+
58 /* PK must be updated with a signed copy of itself */
59 efi_status = RT->SetVariable(L"PK", &GV_GUID,
60 EFI_VARIABLE_NON_VOLATILE
61diff --git a/Makefile b/Makefile
62index b3bb73a..e189866 100644
63--- a/Makefile
64+++ b/Makefile
65@@ -53,7 +53,7 @@ lib/asn1/libasn1.a lib/asn1/libasn1-efi.a: FORCE
66 .KEEP: PK.crt KEK.crt DB.crt PK.key KEK.key DB.key PK.esl DB.esl KEK.esl \
67 $(EFIFILES)
68
69-LockDown.o: PK.h KEK.h DB.h
70+LockDown.o: PK.h KEK.h DB.h DBX.h
71 PreLoader.o: hashlist.h
72
73 PK.h: PK.auth
74@@ -62,6 +62,8 @@ KEK.h: KEK.auth
75
76 DB.h: DB.auth
77
78+DBX.h: DBX.auth
79+
80 noPK.esl:
81 > noPK.esl
82
83--
841.9.1
85
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools/LockDown-run-system-warm-reset-after-the-key-provisi.patch b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/LockDown-run-system-warm-reset-after-the-key-provisi.patch
new file mode 100644
index 0000000..4134bda
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/LockDown-run-system-warm-reset-after-the-key-provisi.patch
@@ -0,0 +1,44 @@
1From b2897e78c7910f0e55f4861542155d2817c15bf4 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Fri, 25 Mar 2016 10:52:34 +0800
4Subject: [PATCH] LockDown: run system warm reset after the key provision
5 success
6
7Upstream-Status: Pending
8
9In addition, BIOS would stop at its setup screen. The end user can thus
10enable UEFI secure boot immediately.
11
12Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
13---
14 LockDown.c | 15 +++++++++++++++
15 1 file changed, 15 insertions(+)
16
17diff --git a/LockDown.c b/LockDown.c
18index 29df9de..821985c 100644
19--- a/LockDown.c
20+++ b/LockDown.c
21@@ -99,5 +99,20 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
22 }
23 Print(L"Platform %s set to boot securely\n", SecureBoot ? L"is" : L"is not");
24
25+ /* Reset system to go back the real UEFI secure boot flow.
26+ * If SecureBoot is still false, the user needs to turn on
27+ * UEFI secure boot in BIOS setup.
28+ */
29+ Print(L"Prepare to execute system warm reset after 3 seconds ...\n");
30+ if (!SecureBoot)
31+ Print(L"After warm reset, enter to BIOS setup to enable UEFI Secure Boot.\n");
32+
33+ BS->Stall(3000000);
34+
35+ if (!SecureBoot)
36+ SETOSIndicationsAndReboot(EFI_OS_INDICATIONS_BOOT_TO_FW_UI);
37+ else
38+ RT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
39+
40 return EFI_SUCCESS;
41 }
42--
431.9.1
44
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools/LockDown-show-the-error-message-with-3-sec-timeout.patch b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/LockDown-show-the-error-message-with-3-sec-timeout.patch
new file mode 100644
index 0000000..8dc681f
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/LockDown-show-the-error-message-with-3-sec-timeout.patch
@@ -0,0 +1,94 @@
1From 28eb6a3118c3c843b41732ec3cf5167fe027daba Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Tue, 17 Jan 2017 12:48:27 +0800
4Subject: [PATCH] LockDown: show the error message with 3-sec timeout
5
6Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
7---
8 LockDown.c | 20 ++++++++++++--------
9 1 file changed, 12 insertions(+), 8 deletions(-)
10
11diff --git a/LockDown.c b/LockDown.c
12index fec2e79..13c626f 100644
13--- a/LockDown.c
14+++ b/LockDown.c
15@@ -27,12 +27,12 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
16
17 if (efi_status != EFI_SUCCESS) {
18 Print(L"No SetupMode variable ... is platform secure boot enabled?\n");
19- return EFI_SUCCESS;
20+ goto out;
21 }
22
23 if (!SetupMode) {
24 Print(L"Platform is not in Setup Mode, cannot install Keys\n");
25- return EFI_SUCCESS;
26+ goto out;
27 }
28
29 Print(L"Platform is in Setup Mode\n");
30@@ -45,7 +45,7 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
31 KEK_auth_len, KEK_auth);
32 if (efi_status != EFI_SUCCESS) {
33 Print(L"Failed to enroll KEK: %d\n", efi_status);
34- return efi_status;
35+ goto out;
36 }
37 Print(L"Created KEK Cert\n");
38
39@@ -57,7 +57,7 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
40 DB_auth_len, DB_auth);
41 if (efi_status != EFI_SUCCESS) {
42 Print(L"Failed to enroll db: %d\n", efi_status);
43- return efi_status;
44+ goto out;
45 }
46 Print(L"Created db Cert\n");
47
48@@ -69,7 +69,7 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
49 DBX_auth_len, DBX_auth);
50 if (efi_status != EFI_SUCCESS) {
51 Print(L"Failed to enroll dbx: %d\n", efi_status);
52- return efi_status;
53+ goto out;
54 }
55 Print(L"Created dbx Cert\n");
56
57@@ -84,14 +84,14 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
58
59 if (efi_status != EFI_SUCCESS) {
60 Print(L"Failed to enroll PK: %d\n", efi_status);
61- return efi_status;
62+ goto out;
63 }
64 Print(L"Created PK Cert\n");
65 /* enrolling the PK should put us in SetupMode; check this */
66 efi_status = RT->GetVariable(L"SetupMode", &GV_GUID, NULL, &DataSize, &SetupMode);
67 if (efi_status != EFI_SUCCESS) {
68 Print(L"Failed to get SetupMode variable: %d\n", efi_status);
69- return efi_status;
70+ goto out;
71 }
72 Print(L"Platform is in %s Mode\n", SetupMode ? L"Setup" : L"User");
73
74@@ -101,7 +101,7 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
75
76 if (efi_status != EFI_SUCCESS) {
77 Print(L"Failed to get SecureBoot variable: %d\n", efi_status);
78- return efi_status;
79+ goto out;
80 }
81 Print(L"Platform %s set to boot securely\n", SecureBoot ? L"is" : L"is not");
82
83@@ -121,4 +121,8 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
84 RT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
85
86 return EFI_SUCCESS;
87+
88+out:
89+ BS->Stall(3000000);
90+ return efi_status;
91 }
92--
932.7.4
94
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Makefile-do-not-build-signed-efi-image.patch b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Makefile-do-not-build-signed-efi-image.patch
new file mode 100644
index 0000000..43daeab
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Makefile-do-not-build-signed-efi-image.patch
@@ -0,0 +1,33 @@
1From 923b9cb2bfe81ff29a29d46bfc4e3fe172e0e5ae Mon Sep 17 00:00:00 2001
2From: Yunguo Wei <yunguo.wei@windriver.com>
3Date: Tue, 17 Jan 2017 17:24:51 +0800
4Subject: [PATCH] Makefile: do not build signed efi image
5
6Signed-off-by: Yunguo Wei <yunguo.wei@windriver.com>
7---
8 Makefile | 5 ++---
9 1 file changed, 2 insertions(+), 3 deletions(-)
10
11diff --git a/Makefile b/Makefile
12index addb593..a1fc538 100644
13--- a/Makefile
14+++ b/Makefile
15@@ -1,5 +1,4 @@
16-EFIFILES = HelloWorld.efi LockDown.efi Loader.efi ReadVars.efi UpdateVars.efi \
17- KeyTool.efi HashTool.efi SetNull.efi ShimReplace.efi
18+EFIFILES = LockDown.efi
19 BINARIES = cert-to-efi-sig-list sig-list-to-certs sign-efi-sig-list \
20 hash-to-efi-sig-list efi-readvar efi-updatevar cert-to-efi-hash-list \
21 flash-var
22@@ -27,7 +26,7 @@ include Make.rules
23
24 EFISIGNED = $(patsubst %.efi,%-signed.efi,$(EFIFILES))
25
26-all: $(EFISIGNED) $(BINARIES) $(MANPAGES) noPK.auth $(KEYAUTH) \
27+all: $(EFIFILES) $(BINARIES) $(MANPAGES) noPK.auth $(KEYAUTH) \
28 $(KEYUPDATEAUTH) $(KEYBLACKLISTAUTH) $(KEYHASHBLACKLISTAUTH)
29
30
31--
322.7.4
33
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Reuse-xxdi.pl.patch b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Reuse-xxdi.pl.patch
new file mode 100644
index 0000000..c382a99
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools/Reuse-xxdi.pl.patch
@@ -0,0 +1,51 @@
1From 959e4395b5524babb27c2bf95fa37b990d79b663 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Thu, 28 Apr 2016 12:52:22 +0800
4Subject: [PATCH] Reuse xxdi.pl
5
6The missing File::Slurp required by xxdi.pl is added. To avoid introducing
7an extra xxd package, remove the support of using xxd.
8
9Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
10---
11 Make.rules | 3 +--
12 Makefile | 2 +-
13 2 files changed, 2 insertions(+), 3 deletions(-)
14
15diff --git a/Make.rules b/Make.rules
16index 21926b0..38c7a22 100644
17--- a/Make.rules
18+++ b/Make.rules
19@@ -33,7 +33,6 @@ NM = nm
20 AR = ar
21 OPENSSL = openssl
22 SBSIGN = sbsign
23-XXD = xxd
24 SIGN_EFI_SIG_LIST ?= ./sign-efi-sig-list
25 CERT_TO_EFI_SIG_LIST ?= ./cert-to-efi-sig-list
26 CERT_TO_EFI_HASH_LIST ?= ./cert-to-efi-hash-list
27@@ -76,7 +75,7 @@ endif
28 ${NM} -D $@ | grep ' U ' && exit 1 || exit 0
29
30 %.h: %.auth
31- $(XXD) -i $< > $@
32+ ./xxdi.pl $< > $@
33
34 %.hash: %.efi hash-to-efi-sig-list
35 $(HASH_TO_EFI_SIG_LIST) $< $@
36diff --git a/Makefile b/Makefile
37index da363a6..2534b47 100644
38--- a/Makefile
39+++ b/Makefile
40@@ -73,7 +73,7 @@ ms-%.esl: ms-%.crt cert-to-efi-sig-list
41
42 hashlist.h: HashTool.hash
43 cat $^ > /tmp/tmp.hash
44- $(XXD) -i /tmp/tmp.hash > $@
45+ ./xxdi.pl /tmp/tmp.hash > $@
46 rm -f /tmp/tmp.hash
47
48
49--
501.9.1
51
diff --git a/meta-efi-secure-boot/recipes-bsp/efitools/efitools_git.bb b/meta-efi-secure-boot/recipes-bsp/efitools/efitools_git.bb
new file mode 100644
index 0000000..79b86a6
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/efitools/efitools_git.bb
@@ -0,0 +1,83 @@
1require efitools.inc
2
3SRC_URI_append += " \
4 file://LockDown-enable-the-enrollment-for-DBX.patch \
5 file://LockDown-show-the-error-message-with-3-sec-timeout.patch \
6 file://Makefile-do-not-build-signed-efi-image.patch \
7 file://Build-DBX-by-default.patch \
8 file://LockDown-disable-the-entrance-into-BIOS-setup-to-re-.patch \
9 file://Fix-help2man-error.patch \
10"
11
12COMPATIBLE_HOST = '(i.86|x86_64).*-linux'
13
14inherit user-key-store deploy
15
16# The generated native binaries are used during native and target build
17DEPENDS += "${BPN}-native gnu-efi openssl"
18
19RDEPENDS_${PN}_append += " \
20 parted mtools coreutils util-linux openssl libcrypto \
21"
22
23EXTRA_OEMAKE_append += " \
24 INCDIR_PREFIX='${STAGING_DIR_TARGET}' \
25 CRTPATH_PREFIX='${STAGING_DIR_TARGET}' \
26 SIGN_EFI_SIG_LIST='${STAGING_BINDIR_NATIVE}/sign-efi-sig-list' \
27 CERT_TO_EFI_SIG_LIST='${STAGING_BINDIR_NATIVE}/cert-to-efi-sig-list' \
28 CERT_TO_EFI_HASH_LIST='${STAGING_BINDIR_NATIVE}/cert-to-efi-hash-list' \
29 HASH_TO_EFI_SIG_LIST='${STAGING_BINDIR_NATIVE}/hash-to-efi-sig-list' \
30 MYGUID='${UEFI_SIG_OWNER_GUID}' \
31 HELP2MAN_PROG_PREFIX='${STAGING_BINDIR_NATIVE}' \
32"
33
34python do_prepare_signing_keys() {
35 if d.expand('${UEFI_SB}') != '1':
36 return
37
38 # Prepare PK, KEK and DB for LockDown.efi.
39 if uks_signing_model(d) in ('sample', 'user'):
40 dir = uefi_sb_keys_dir(d)
41 else:
42 dir = d.expand('${SAMPLE_UEFI_SB_KEYS_DIR}/')
43
44 import shutil
45
46 for _ in ('PK', 'KEK', 'DB'):
47 shutil.copyfile(dir + _ + '.pem', d.expand('${S}/') + _ + '.crt')
48 shutil.copyfile(dir + _ + '.key', d.expand('${S}/') + _ + '.key')
49
50 # Make sure LockDown.efi contains the DB and KEK from Microsoft.
51 if "${@bb.utils.contains('DISTRO_FEATURES', 'msft', '1', '0', d)}" == '1':
52 shutil.copyfile(d.expand('${MSFT_DB_CERT}'), d.expand('${S}/DB.crt'))
53 shutil.copyfile(d.expand('${MSFT_KEK_CERT}'), d.expand('${S}/KEK.crt'))
54
55 path = create_uefi_dbx(d)
56 if path:
57 with open(d.expand('${S}/DBX.crt'), 'w') as f:
58 pass
59
60 shutil.copyfile(path, d.expand('${S}/DBX.esl'))
61
62 # Cheat the Makefile to avoid running this rule:
63 # %.esl: %.crt cert-to-efi-sig-list
64 # $(CERT_TO_EFI_SIG_LIST) -g $(MYGUID) $< $@
65 import time, os
66 tm = time.strptime('2038-01-01 00:00:00', \
67 '%Y-%m-%d %H:%M:%S')
68 time_stamp = time.mktime(tm)
69 os.utime(d.expand('${S}/DBX.esl'), (time_stamp, time_stamp))
70}
71addtask prepare_signing_keys after do_configure before do_compile
72
73do_install_append() {
74 install -d ${D}${EFI_BOOT_PATH}
75 install -m 0755 ${D}${datadir}/efitools/efi/LockDown.efi ${D}${EFI_BOOT_PATH}
76}
77
78do_deploy() {
79 install -d ${DEPLOYDIR}
80
81 install -m 0600 ${D}${EFI_BOOT_PATH}/LockDown.efi "${DEPLOYDIR}"
82}
83addtask deploy after do_install before do_build
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0001-pe32.h-add-header-structures-for-TE-and-DOS-executab.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0001-pe32.h-add-header-structures-for-TE-and-DOS-executab.patch
new file mode 100644
index 0000000..249f66a
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0001-pe32.h-add-header-structures-for-TE-and-DOS-executab.patch
@@ -0,0 +1,67 @@
1From aecadf65c4d3dea68e55605ff5f0c3eb90206488 Mon Sep 17 00:00:00 2001
2From: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
3Date: Fri, 27 Mar 2015 08:01:41 -0700
4Subject: [PATCH 1/7] pe32.h: add header structures for TE and DOS executables
5
6Upstream-Status: Inappropriate [embedded specific]
7
8Add header structures to describe the Terse Executable format and
9the DOS header format for executable images.
10
11These definitions are needed in subsequent commits to parse and
12verify the identity of the executable image when utilizing a shim
13to boot LUV.
14
15Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
16---
17 include/grub/efi/pe32.h | 36 ++++++++++++++++++++++++++++++++++++
18 1 file changed, 36 insertions(+)
19
20diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h
21index c3efa9b..c1c3483 100644
22--- a/include/grub/efi/pe32.h
23+++ b/include/grub/efi/pe32.h
24@@ -313,4 +313,40 @@ struct grub_pe32_reloc
25 #define GRUB_PE32_REL_I386_DIR32 0x6
26 #define GRUB_PE32_REL_I386_REL32 0x14
27
28+struct grub_te_header
29+{
30+ grub_uint16_t signature;
31+ grub_uint16_t machine;
32+ grub_uint8_t num_sections;
33+ grub_uint8_t subsystem;
34+ grub_uint16_t stripped_size;
35+ grub_uint32_t entry_point;
36+ grub_uint32_t code_base;
37+ grub_uint64_t image_base;
38+ struct grub_pe32_data_directory data_directory[2];
39+};
40+
41+struct grub_dos_header
42+{
43+ grub_uint16_t magic;
44+ grub_uint16_t cblp;
45+ grub_uint16_t cp;
46+ grub_uint16_t crlc;
47+ grub_uint16_t cparhdr;
48+ grub_uint16_t minalloc;
49+ grub_uint16_t maxalloc;
50+ grub_uint16_t ss;
51+ grub_uint16_t sp;
52+ grub_uint16_t csum;
53+ grub_uint16_t ip;
54+ grub_uint16_t cs;
55+ grub_uint16_t lfarlc;
56+ grub_uint16_t ovno;
57+ grub_uint16_t res[4];
58+ grub_uint16_t oemid;
59+ grub_uint16_t oeminfo;
60+ grub_uint16_t res2[10];
61+ grub_uint32_t lfanew;
62+};
63+
64 #endif /* ! GRUB_EFI_PE32_HEADER */
65--
661.9.1
67
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0002-shim-add-needed-data-structures.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0002-shim-add-needed-data-structures.patch
new file mode 100644
index 0000000..d09550e
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0002-shim-add-needed-data-structures.patch
@@ -0,0 +1,161 @@
1From 2341c2d2cf2ee67b036d21aa9b12b71bea84495f Mon Sep 17 00:00:00 2001
2From: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
3Date: Fri, 27 Mar 2015 08:09:58 -0700
4Subject: [PATCH 2/7] shim: add needed data structures
5
6Upstream-Status: Inappropriate [embedded specific]
7
8Add the needed data structures for shim to load, parse, relocate and
9execute a binary. This includes file-parsing structures, an identifier for
10the UEFI protocol for image verification under secure boot provided by shim.
11
12Shim is thin loader developed by Matthew Garret
13(https://github.com/rhinstaller/shim). This code was ported from such project.
14
15Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
16---
17 include/grub/efi/shim.h | 132 ++++++++++++++++++++++++++++++++++++++++++++++++
18 1 file changed, 132 insertions(+)
19 create mode 100644 include/grub/efi/shim.h
20
21diff --git a/include/grub/efi/shim.h b/include/grub/efi/shim.h
22new file mode 100644
23index 0000000..4b92a00
24--- /dev/null
25+++ b/include/grub/efi/shim.h
26@@ -0,0 +1,132 @@
27+/*
28+ * shim.h - interface to shim: UEFI first-stage bootloader
29+ *
30+ * Copyright 2015 Intel Corporation.
31+ *
32+ * Redistribution and use in source and binary forms, with or without
33+ * modification, are permitted provided that the following conditions
34+ * are met:
35+ *
36+ * Redistributions of source code must retain the above copyright
37+ * notice, this list of conditions and the following disclaimer.
38+ *
39+ * Redistributions in binary form must reproduce the above copyright
40+ * notice, this list of conditions and the following disclaimer in the
41+ * documentation and/or other materials provided with the
42+ * distribution.
43+ *
44+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
45+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
46+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
47+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
48+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
49+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
50+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55+ * OF THE POSSIBILITY OF SUCH DAMAGE.
56+ *
57+ * Significant portions of this code are derived from Red Hat shim: UEFI
58+ * first-stage bootloader.
59+ * (https://github.com/rhinstaller/shim) and are Copyright 2012 Red Hat, Inc
60+ */
61+
62+#ifndef GRUB_SHIM_HEADER
63+#define GRUB_SHIM_HEADER 1
64+
65+#include <grub/efi/pe32.h>
66+
67+struct grub_nt_headers32
68+{
69+ grub_efi_uint32_t signature;
70+ struct grub_pe32_coff_header file_hdr;
71+ struct grub_pe32_optional_header opt_hdr;
72+};
73+
74+struct grub_nt_headers64
75+{
76+ grub_efi_uint32_t signature;
77+ struct grub_pe32_coff_header file_hdr;
78+ struct grub_pe64_optional_header opt_hdr;
79+};
80+
81+struct grub_image_base_relocation
82+{
83+ grub_efi_uint32_t virtual_address;
84+ grub_efi_uint32_t block_size;
85+};
86+
87+struct grub_shim_pe_coff_loader_image_context {
88+ grub_efi_uint64_t image_address;
89+ grub_efi_uint64_t image_size;
90+ grub_efi_uint64_t entry_point;
91+ grub_efi_uintn_t header_size;
92+ grub_efi_uint16_t image_type;
93+ grub_efi_uint16_t num_sections;
94+ struct grub_pe32_section_table *first_section;
95+ struct grub_pe32_data_directory *reloc_dir;
96+ struct grub_pe32_data_directory *sec_dir;
97+ grub_efi_uint64_t number_of_rva_and_sizes;
98+ union grub_shim_optional_header_union *pe_hdr;
99+};
100+
101+struct grub_shim_lock
102+{
103+ grub_efi_status_t
104+ (*verify) (void *buffer,
105+ grub_uint32_t size);
106+
107+ grub_efi_status_t
108+ (*hash) (grub_int8_t *data,
109+ grub_int32_t datasize,
110+ struct grub_shim_pe_coff_loader_image_context *context,
111+ grub_uint8_t sha256hash,
112+ grub_uint8_t sha1hash);
113+
114+ grub_efi_status_t
115+ (*context) (void *data,
116+ grub_uint32_t datasize,
117+ struct grub_shim_pe_coff_loader_image_context *context);
118+};
119+
120+union grub_shim_optional_header_union
121+{
122+ struct grub_nt_headers32 pe32;
123+ struct grub_nt_headers64 pe32plus;
124+ struct grub_te_header te;
125+};
126+
127+#define GRUB_EFI_SHIM_PROTOCOL_GUID \
128+ { 0x605dab50, 0xe046, 0x4300, \
129+ { 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23 } \
130+ }
131+
132+#define SIGNATURE_16(A, B) ((A) | (B << 8))
133+#define SIGNATURE_32(A, B, C, D) (SIGNATURE_16 (A, B) | (SIGNATURE_16 (C, D) << 16))
134+
135+#define EFI_IMAGE_DOS_SIGNATURE SIGNATURE_16('M', 'Z')
136+#define EFI_IMAGE_NT_SIGNATURE SIGNATURE_32('P', 'E', '\0', '\0')
137+
138+#define EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC 5
139+
140+#define ALIGN_VALUE(Value, Alignment) ((Value) + (((Alignment) - (Value)) & ((Alignment) - 1)))
141+#define ALIGN_POINTER(Pointer, Alignment) ((void *) (ALIGN_VALUE ((grub_efi_uintn_t)(Pointer), (Alignment))))
142+
143+/* Based relocation types. */
144+
145+#define EFI_IMAGE_REL_BASED_ABSOLUTE 0
146+#define EFI_IMAGE_REL_BASED_HIGH 1
147+#define EFI_IMAGE_REL_BASED_LOW 2
148+#define EFI_IMAGE_REL_BASED_HIGHLOW 3
149+#define EFI_IMAGE_REL_BASED_HIGHADJ 4
150+#define EFI_IMAGE_REL_BASED_MIPS_JMPADDR 5
151+#define EFI_IMAGE_REL_BASED_ARM_MOV32A 5
152+#define EFI_IMAGE_REL_BASED_ARM_MOV32T 7
153+#define EFI_IMAGE_REL_BASED_IA64_IMM64 9
154+#define EFI_IMAGE_REL_BASED_MIPS_JMPADDR16 9
155+#define EFI_IMAGE_REL_BASED_DIR64 10
156+
157+
158+#endif /* ! GRUB_SHIM_HEADER */
159--
1601.9.1
161
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0003-efi-chainloader-implement-an-UEFI-Exit-service-for-s.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0003-efi-chainloader-implement-an-UEFI-Exit-service-for-s.patch
new file mode 100644
index 0000000..cf13fc1
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0003-efi-chainloader-implement-an-UEFI-Exit-service-for-s.patch
@@ -0,0 +1,81 @@
1From 3b75fa5071e4b1a40510669119791928859b46e7 Mon Sep 17 00:00:00 2001
2From: Matt Fleming <matt.fleming@intel.com>
3Date: Fri, 27 Mar 2015 08:11:19 -0700
4Subject: [PATCH 3/7] efi: chainloader: implement an UEFI Exit service for shim
5 in grub
6
7Upstream-Status: Inappropriate [embedded specific]
8
9When exiting, grub will call the UEFI boot-time service Exit. The
10effect of this is that UEFI will jump to the entry point of the
11UEFI started image. If we execute an image using shim within grub,
12shim takes care of loading/parsing/relocating/executing the image.
13Under this scenario, we also need to take care of the Exit call. Thus,
14we need to reimplement the function to make sure we perform a jump
15to the instruction after which shim executed the image.
16
17Once we have taken care of the exit of the shim-executed image
18the system Exit call is restored.
19
20Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
21---
22 grub-core/kern/x86_64/efi/callwrap.S | 23 +++++++++++++++++++++++
23 include/grub/efi/api.h | 4 ++++
24 2 files changed, 27 insertions(+)
25
26diff --git a/grub-core/kern/x86_64/efi/callwrap.S b/grub-core/kern/x86_64/efi/callwrap.S
27index 2df95dd..f0f1dd8 100644
28--- a/grub-core/kern/x86_64/efi/callwrap.S
29+++ b/grub-core/kern/x86_64/efi/callwrap.S
30@@ -48,6 +48,26 @@ FUNCTION(efi_wrap_1)
31 addq $48, %rsp
32 ret
33
34+FUNCTION(efi_call_foo)
35+ pushq %rbp
36+ pushq %r12
37+ pushq %r13
38+ pushq %r14
39+ pushq %r15
40+ movq %rsp, saved_sp(%rip)
41+ subq $48, %rsp
42+ mov %rsi, %rcx
43+ call *%rdi
44+
45+FUNCTION(efi_shim_exit)
46+ movq saved_sp(%rip), %rsp
47+ popq %r15
48+ popq %r14
49+ popq %r13
50+ popq %r12
51+ popq %rbp
52+ ret
53+
54 FUNCTION(efi_wrap_2)
55 subq $48, %rsp
56 mov %rsi, %rcx
57@@ -127,3 +147,6 @@ FUNCTION(efi_wrap_10)
58 call *%rdi
59 addq $96, %rsp
60 ret
61+
62+ .data
63+saved_sp: .quad 0
64diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
65index 26127de..374d88b 100644
66--- a/include/grub/efi/api.h
67+++ b/include/grub/efi/api.h
68@@ -1437,6 +1437,10 @@ typedef struct grub_efi_block_io grub_efi_block_io_t;
69
70 grub_uint64_t EXPORT_FUNC(efi_wrap_0) (void *func);
71 grub_uint64_t EXPORT_FUNC(efi_wrap_1) (void *func, grub_uint64_t arg1);
72+grub_efi_status_t EXPORT_FUNC(efi_shim_exit) (grub_efi_handle_t handle, grub_efi_status_t exit_status,
73+ grub_efi_uintn_t exit_data_size, grub_efi_char16_t *exit_data) __attribute__((noreturn));
74+grub_uint64_t EXPORT_FUNC(efi_call_foo) (void *func, grub_uint64_t arg1,
75+ grub_uint64_t arg2);
76 grub_uint64_t EXPORT_FUNC(efi_wrap_2) (void *func, grub_uint64_t arg1,
77 grub_uint64_t arg2);
78 grub_uint64_t EXPORT_FUNC(efi_wrap_3) (void *func, grub_uint64_t arg1,
79--
801.9.1
81
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0004-efi-chainloader-port-shim-to-grub.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0004-efi-chainloader-port-shim-to-grub.patch
new file mode 100644
index 0000000..baa0986
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0004-efi-chainloader-port-shim-to-grub.patch
@@ -0,0 +1,582 @@
1From e097b4e25469aabdceac79c45cca27029824c1b5 Mon Sep 17 00:00:00 2001
2From: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
3Date: Fri, 27 Mar 2015 08:19:21 -0700
4Subject: [PATCH 4/7] efi: chainloader: port shim to grub
5
6Upstream-Status: Inappropriate [embedded specific]
7
8Shim is a thin loader to execute signed binaries under the
9chain of trust of UEFI secure boot. Before executing the image,
10shim verifies that such image is signed with any of the Machine
11Owner Keys (MOKs). If the verification is successful, shim will
12load, parse, relocate and execute the image.
13
14Shim is useful in case the user does not want to modify the UEFI
15database of valid certificates (DB).
16
17This commit ports Matthew Garret's code from shim to grub in order
18to provide to grub the capability of load and execute trusted
19binaries. This is useful in case we need to chainload two bootloaders.
20
21Shim can be found here: https://github.com/rhinstaller/shim
22
23Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
24---
25 grub-core/loader/efi/chainloader.c | 534 +++++++++++++++++++++++++++++++++++++
26 1 file changed, 534 insertions(+)
27
28diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
29index 3f3e6e3..bd83859 100644
30--- a/grub-core/loader/efi/chainloader.c
31+++ b/grub-core/loader/efi/chainloader.c
32@@ -32,6 +32,7 @@
33 #include <grub/efi/api.h>
34 #include <grub/efi/efi.h>
35 #include <grub/efi/disk.h>
36+#include <grub/efi/shim.h>
37 #include <grub/command.h>
38 #include <grub/i18n.h>
39 #include <grub/net.h>
40@@ -45,6 +46,539 @@ static grub_efi_uintn_t pages;
41 static grub_efi_device_path_t *file_path;
42 static grub_efi_handle_t image_handle;
43 static grub_efi_char16_t *cmdline;
44+static grub_int32_t shim_used;
45+static grub_efi_physical_address_t shim_buffer;
46+static grub_efi_uintn_t shim_pages;
47+static grub_efi_loaded_image_t shim_li_bak;
48+static grub_efi_status_t (*shim_entry_point) (grub_efi_handle_t image_handle,
49+ grub_efi_system_table_t *systab);
50+
51+static const grub_uint16_t
52+grub_shim_machine_type =
53+#if defined(__x86_64__)
54+ GRUB_PE32_MACHINE_X86_64;
55+#elif defined(__aarch64__)
56+ IMAGE_FILE_MACHINE_ARM64;
57+#elif defined(__arm__)
58+ IMAGE_FILE_MACHINE_ARMTHUMB_MIXED;
59+#elif defined(__i386__) || defined(__i486__) || defined(__i686__)
60+ GRUB_PE32_MACHINE_I386;
61+#elif defined(__ia64__)
62+ GRUB_PE32_MACHINE_IA64;
63+#else
64+#error this architecture is not supported by shim chainloader
65+#endif
66+
67+static grub_efi_guid_t grub_shim_protocol_guid = GRUB_EFI_SHIM_PROTOCOL_GUID;
68+
69+static grub_int32_t
70+grub_shim_allow_64_bit (void)
71+{
72+/* TODO: what is the definition for aarch64? */
73+#if defined(__x86_64__)
74+ return 1;
75+#elif defined(__i386__) || defined(__i686__)
76+/* TODO: find out what to do with in_protocol */
77+ return 0;
78+#else /* assuming everything else is 32-bit... */
79+ return 0;
80+#endif
81+}
82+
83+static grub_int32_t
84+grub_shim_allow_32_bit (void)
85+{
86+/* TODO: what is the definition for aarch64? */
87+#if defined(__x86_64__)
88+/* TODO: find out what to do with in_protocol */
89+ return 0;
90+#elif defined(__i386__) || defined(__i686__)
91+ return 1;
92+#else /* assuming everything else is 32-bit... */
93+ return 1;
94+#endif
95+}
96+
97+static grub_int32_t
98+grub_shim_image_is_64_bit (union grub_shim_optional_header_union *pe_hdr)
99+{
100+ /* .Magic is the same offset in all cases */
101+ if (pe_hdr->pe32plus.opt_hdr.magic == GRUB_PE32_PE64_MAGIC)
102+ return 1;
103+ return 0;
104+}
105+
106+static grub_int32_t
107+grub_shim_image_is_loadable (union grub_shim_optional_header_union *pe_hdr)
108+{
109+ /* If the machine type doesn't match the binary, bail, unless
110+ * we're in an allowed 64-on-32 scenario
111+ */
112+ if (pe_hdr->pe32.file_hdr.machine != grub_shim_machine_type)
113+ {
114+ if (!(grub_shim_machine_type == GRUB_PE32_MACHINE_I386
115+ && pe_hdr->pe32.file_hdr.machine == GRUB_PE32_MACHINE_X86_64
116+ && grub_shim_allow_64_bit ()))
117+ return 0;
118+ }
119+
120+ /* If it's not a header type we recognize at all, bail */
121+ switch (pe_hdr->pe32plus.opt_hdr.magic)
122+ {
123+ case GRUB_PE32_PE64_MAGIC:
124+ case GRUB_PE32_PE32_MAGIC:
125+ break;
126+ default:
127+ return 0;
128+ }
129+
130+ /* and now just check for general 64-vs-32 compatibility */
131+ if (grub_shim_image_is_64_bit(pe_hdr))
132+ {
133+ if (grub_shim_allow_64_bit ())
134+ return 1;
135+ }
136+ else
137+ {
138+ if (grub_shim_allow_32_bit ())
139+ return 1;
140+ }
141+ return 0;
142+}
143+
144+/*
145+ * Perform basic bounds checking of the intra-image pointers
146+ */
147+static grub_efi_uint64_t
148+grub_shim_image_address (grub_addr_t image, grub_uint32_t size, grub_uint32_t addr)
149+{
150+ if (addr > size)
151+ return 0;
152+ return image + addr;
153+}
154+
155+/*
156+ * Perform the actual relocation
157+ */
158+static grub_err_t
159+grub_shim_relocate_coff (struct grub_shim_pe_coff_loader_image_context *context,
160+ void *orig, void *data)
161+{
162+ struct grub_image_base_relocation *reloc_base, *reloc_base_end;
163+ grub_efi_uint64_t adjust;
164+ grub_efi_uint16_t *reloc, *reloc_end;
165+ grub_uint8_t *fixup, *fixup_base, *fixup_data = NULL;
166+ grub_efi_uint16_t *fixup16;
167+ grub_efi_uint32_t *fixup32;
168+ grub_efi_uint64_t *fixup64;
169+ grub_int32_t size = context->image_size;
170+ void *image_end = (char *)orig + size;
171+
172+ if (grub_shim_image_is_64_bit(context->pe_hdr))
173+ context->pe_hdr->pe32plus.opt_hdr.image_base = (grub_efi_uint64_t)(unsigned long)data;
174+ else
175+ context->pe_hdr->pe32.opt_hdr.image_base = (grub_efi_uint32_t)(unsigned long)data;
176+
177+ reloc_base = (struct grub_image_base_relocation *)
178+ grub_shim_image_address ((grub_efi_uint64_t)orig, size,
179+ context->reloc_dir->rva);
180+ reloc_base_end = (struct grub_image_base_relocation *)
181+ grub_shim_image_address ((grub_efi_uint64_t)orig, size,
182+ context->reloc_dir->rva
183+ + context->reloc_dir->size - 1);
184+
185+ if (!reloc_base || !reloc_base_end)
186+ {
187+ grub_printf("Reloc table overflows binary\n");
188+ return GRUB_ERR_BAD_FILE_TYPE;
189+ }
190+
191+ adjust = (grub_efi_uintn_t)data - context->image_address;
192+
193+ if (adjust == 0)
194+ return GRUB_EFI_SUCCESS;
195+
196+ while (reloc_base < reloc_base_end)
197+ {
198+ reloc = (grub_efi_uint16_t *) ((grub_int8_t *) reloc_base
199+ + sizeof (struct grub_image_base_relocation));
200+
201+ if ((reloc_base->block_size == 0)
202+ || (reloc_base->block_size > context->reloc_dir->size))
203+ {
204+ grub_printf("Reloc block size %d is invalid\n", reloc_base->block_size);
205+ return GRUB_ERR_FILE_READ_ERROR;
206+ }
207+
208+ reloc_end = (grub_efi_uint16_t *)
209+ ((grub_uint8_t *) reloc_base + reloc_base->block_size);
210+ if ((void *)reloc_end < orig || (void *)reloc_end > image_end)
211+ {
212+ grub_printf("Reloc entry overflows binary\n");
213+ return GRUB_ERR_FILE_READ_ERROR;
214+ }
215+
216+ fixup_base = (grub_uint8_t *)
217+ grub_shim_image_address ((grub_efi_uint64_t)data,
218+ size,
219+ reloc_base->virtual_address);
220+ if (!fixup_base)
221+ {
222+ grub_printf("Invalid fixup_base\n");
223+ return GRUB_ERR_FILE_READ_ERROR;
224+ }
225+
226+ while (reloc < reloc_end)
227+ {
228+ fixup = fixup_base + (*reloc & 0xFFF);
229+ switch ((*reloc) >> 12)
230+ {
231+ case EFI_IMAGE_REL_BASED_ABSOLUTE:
232+ break;
233+
234+ case EFI_IMAGE_REL_BASED_HIGH:
235+ fixup16 = (grub_efi_uint16_t *) fixup;
236+ *fixup16 = (grub_efi_uint16_t)
237+ (*fixup16
238+ + ((grub_efi_uint16_t) ((grub_efi_uint32_t) adjust >> 16)));
239+ if (fixup_data != NULL)
240+ {
241+ *(grub_efi_uint16_t *) fixup_data = *fixup16;
242+ fixup_data = fixup_data + sizeof (grub_efi_uint16_t);
243+ }
244+ break;
245+
246+ case EFI_IMAGE_REL_BASED_LOW:
247+ fixup16 = (grub_efi_uint16_t *) fixup;
248+ *fixup16 = (grub_efi_uint16_t)
249+ (*fixup16 + (grub_efi_uint16_t) adjust);
250+ if (fixup_data != NULL)
251+ {
252+ *(grub_efi_uint16_t *) fixup_data = *fixup16;
253+ fixup_data = fixup_data + sizeof (grub_efi_uint16_t);
254+ }
255+ break;
256+
257+ case EFI_IMAGE_REL_BASED_HIGHLOW:
258+ fixup32 = (grub_efi_uint32_t *) fixup;
259+ *fixup32 = *fixup32 + (grub_efi_uint32_t) adjust;
260+ if (fixup_data != NULL)
261+ {
262+ fixup_data = ALIGN_POINTER (fixup_data, sizeof (grub_efi_uint32_t));
263+ *(grub_efi_uint32_t *)fixup_data = *fixup32;
264+ fixup_data = fixup_data + sizeof (grub_efi_uint32_t);
265+ }
266+ break;
267+
268+ case EFI_IMAGE_REL_BASED_DIR64:
269+ fixup64 = (grub_efi_uint64_t *) fixup;
270+ *fixup64 = *fixup64 + (grub_efi_uint64_t) adjust;
271+ if (fixup_data != NULL)
272+ {
273+ fixup_data = ALIGN_POINTER (fixup_data, sizeof(grub_efi_uint64_t));
274+ *(grub_efi_uint64_t *)(fixup_data) = *fixup64;
275+ fixup_data = fixup_data + sizeof(grub_efi_uint64_t);
276+ }
277+ break;
278+
279+ default:
280+ grub_printf("Unknown relocation\n");
281+ return GRUB_ERR_FILE_READ_ERROR;
282+ }
283+ reloc += 1;
284+ }
285+ reloc_base = (struct grub_image_base_relocation *) reloc_end;
286+ }
287+
288+ return GRUB_EFI_SUCCESS;
289+}
290+
291+/*
292+ * Read the binary header and grab appropriate information from it
293+ */
294+static grub_err_t
295+grub_shim_read_header(grub_efi_physical_address_t data, grub_uint32_t datasize,
296+ struct grub_shim_pe_coff_loader_image_context *context)
297+{
298+ struct grub_dos_header *dos_hdr = (struct grub_dos_header *)data;
299+ union grub_shim_optional_header_union *pe_hdr = (union grub_shim_optional_header_union *)data;
300+ grub_uint64_t header_without_data_dir, section_header_offset, opt_hdr_size;
301+
302+ if (datasize < sizeof (pe_hdr->pe32))
303+ {
304+ grub_printf("Invalid image\n");
305+ return GRUB_ERR_BAD_FILE_TYPE;
306+ }
307+
308+ if (dos_hdr->magic == EFI_IMAGE_DOS_SIGNATURE)
309+ pe_hdr = (union grub_shim_optional_header_union *)((grub_uint8_t *)data
310+ + dos_hdr->lfanew);
311+
312+ if (!grub_shim_image_is_loadable(pe_hdr))
313+ {
314+ grub_printf("Platform does not support this image\n");
315+ return GRUB_ERR_BAD_FILE_TYPE;
316+ }
317+
318+ if (grub_shim_image_is_64_bit(pe_hdr))
319+ {
320+ context->number_of_rva_and_sizes = pe_hdr->pe32plus.opt_hdr.num_data_directories;
321+ context->header_size = pe_hdr->pe32plus.opt_hdr.header_size;
322+ context->image_size = pe_hdr->pe32plus.opt_hdr.image_size;
323+ opt_hdr_size = sizeof(struct grub_pe64_optional_header);
324+ } else
325+ {
326+ context->number_of_rva_and_sizes = pe_hdr->pe32.opt_hdr.num_data_directories;
327+ context->header_size = pe_hdr->pe32.opt_hdr.header_size;
328+ context->image_size = (grub_efi_uint64_t)pe_hdr->pe32.opt_hdr.header_size;
329+ opt_hdr_size = sizeof(struct grub_pe32_optional_header);
330+ }
331+
332+ context->num_sections = pe_hdr->pe32.file_hdr.num_sections;
333+
334+ if (GRUB_PE32_NUM_DATA_DIRECTORIES < context->number_of_rva_and_sizes)
335+ {
336+ grub_printf("Image header too small\n");
337+ return GRUB_ERR_FILE_READ_ERROR;
338+ }
339+
340+ header_without_data_dir = opt_hdr_size
341+ - sizeof (struct grub_pe32_data_directory)
342+ * GRUB_PE32_NUM_DATA_DIRECTORIES;
343+ if (((grub_efi_uint32_t)pe_hdr->pe32.file_hdr.optional_header_size
344+ - header_without_data_dir) !=
345+ context->number_of_rva_and_sizes * sizeof (struct grub_pe32_data_directory))
346+ {
347+ grub_printf("Image header overflows data directory\n");
348+ return GRUB_ERR_FILE_READ_ERROR;
349+ }
350+
351+ section_header_offset = dos_hdr->lfanew
352+ + sizeof (grub_efi_uint32_t)
353+ + sizeof (struct grub_pe32_coff_header)
354+ + pe_hdr->pe32.file_hdr.optional_header_size;
355+ if (((grub_efi_uint32_t)context->image_size - section_header_offset)
356+ / sizeof (struct grub_pe32_section_table)
357+ <= context->num_sections)
358+ {
359+ grub_printf("Image sections overflow image size\n");
360+ return GRUB_ERR_FILE_READ_ERROR;
361+ }
362+
363+ if ((context->header_size - section_header_offset)
364+ / sizeof (struct grub_pe32_section_table)
365+ < (grub_efi_uint32_t)context->num_sections)
366+ {
367+ grub_printf("Image sections overflow section headers\n");
368+ return GRUB_ERR_FILE_READ_ERROR;
369+ }
370+
371+ if ((((grub_efi_uint8_t *)pe_hdr
372+ - (grub_efi_uint8_t *)data)
373+ + sizeof(union grub_shim_optional_header_union )) > datasize)
374+ {
375+ grub_printf("Invalid image\n");
376+ return GRUB_ERR_BAD_FILE_TYPE;
377+ }
378+
379+ if (pe_hdr->te.signature != EFI_IMAGE_NT_SIGNATURE)
380+ {
381+ grub_printf("Unsupported image type\n");
382+ return GRUB_ERR_BAD_FILE_TYPE;
383+ }
384+
385+ if (pe_hdr->pe32.file_hdr.characteristics & GRUB_PE32_RELOCS_STRIPPED)
386+ {
387+ grub_printf("Unsupported image - Relocations have been stripped\n");
388+ return GRUB_ERR_BAD_FILE_TYPE;
389+ }
390+
391+ context->pe_hdr = pe_hdr;
392+
393+ if (grub_shim_image_is_64_bit(pe_hdr))
394+ {
395+ context->image_address = pe_hdr->pe32plus.opt_hdr.image_base;
396+ context->entry_point = pe_hdr->pe32plus.opt_hdr.entry_addr;
397+ context->reloc_dir = &pe_hdr->pe32plus.opt_hdr.base_relocation_table;
398+ context->sec_dir = &pe_hdr->pe32plus.opt_hdr.certificate_table;
399+ } else
400+ {
401+ context->image_address = pe_hdr->pe32.opt_hdr.image_base;
402+ context->entry_point = pe_hdr->pe32.opt_hdr.entry_addr;
403+ context->reloc_dir = &pe_hdr->pe32.opt_hdr.base_relocation_table;
404+ context->sec_dir = &pe_hdr->pe32.opt_hdr.certificate_table;
405+ }
406+
407+ context->first_section = (struct grub_pe32_section_table *)
408+ ((char *)pe_hdr
409+ + pe_hdr->pe32.file_hdr.optional_header_size
410+ + sizeof(grub_efi_uint32_t)
411+ + sizeof(struct grub_pe32_coff_header));
412+
413+ if (context->image_size < context->header_size)
414+ {
415+ grub_printf("Invalid image\n");
416+ return GRUB_ERR_BAD_FILE_TYPE;
417+ }
418+
419+ if ((unsigned long)((grub_efi_uint8_t *)context->sec_dir - (grub_efi_uint8_t *)data) >
420+ (datasize - sizeof(struct grub_pe32_data_directory)))
421+ {
422+ grub_printf("Invalid image\n");
423+ return GRUB_ERR_BAD_FILE_TYPE;
424+ }
425+
426+ if (context->sec_dir->rva >= datasize)
427+ {
428+ grub_printf("Malformed security header\n");
429+ return GRUB_ERR_BAD_FILE_TYPE;
430+ }
431+ return GRUB_ERR_NONE;
432+}
433+
434+static grub_efi_status_t
435+grub_shim_verify (grub_addr_t addr, grub_ssize_t size)
436+{
437+ struct grub_shim_lock *shim_lock;
438+ shim_lock = grub_efi_locate_protocol (&grub_shim_protocol_guid, 0);
439+ if (!shim_lock)
440+ {
441+ grub_error (GRUB_ERR_BAD_OS, "could not load shim protocol");
442+ return GRUB_EFI_UNSUPPORTED;
443+ }
444+
445+ return shim_lock->verify((void *) addr, size);
446+}
447+
448+static grub_err_t
449+grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
450+ struct grub_shim_pe_coff_loader_image_context *context)
451+{
452+ grub_err_t status;
453+ grub_efi_status_t efi_status;
454+ grub_uint32_t sect_size;
455+ /* TODO: can they be unsigned? */
456+ grub_int8_t *base, *end;
457+ grub_int32_t i;
458+ struct grub_pe32_section_table *section;
459+ grub_efi_boot_services_t *b;
460+
461+ shim_used = 0;
462+ shim_buffer = 0;
463+
464+ status = grub_shim_verify (addr, size);
465+ if (status != GRUB_ERR_NONE)
466+ {
467+ grub_error (GRUB_ERR_BAD_OS, "shim verification failed");
468+ return GRUB_ERR_BAD_OS;
469+ }
470+
471+ grub_memset(context, 0, sizeof(*context));
472+ status = grub_shim_read_header (addr, size, context);
473+ if (status != GRUB_ERR_NONE)
474+ {
475+ grub_error (GRUB_ERR_BAD_OS, "read header failed");
476+ return GRUB_ERR_BAD_OS;
477+ }
478+
479+ /* TODO: do we need to do this with efi_allocate? */
480+ shim_pages = (((grub_efi_uintn_t) context->image_size + ((1 << 12) - 1)) >> 12);
481+
482+ b = grub_efi_system_table->boot_services;
483+ efi_status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_ANY_PAGES,
484+ GRUB_EFI_LOADER_CODE, shim_pages, &shim_buffer);
485+ if (efi_status != GRUB_EFI_SUCCESS)
486+ {
487+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory for shim buffer"));
488+ return GRUB_ERR_OUT_OF_MEMORY;
489+ }
490+
491+ /* TODO: do we need the double cast? */
492+ grub_memcpy ((void *) ((grub_efi_physical_address_t) shim_buffer),
493+ (void *) ((grub_addr_t) addr), context->header_size);
494+ /*
495+ * Copy the executable's sections to their desired offsets
496+ */
497+ section = context->first_section;
498+ for (i = 0; i < context->num_sections; i++, section++)
499+ {
500+ if (section->characteristics & 0x02000000)
501+ /* section has EFI_IMAGE_SCN_MEM_DISCARDABLE attr set */
502+ continue;
503+
504+ sect_size = section->virtual_size;
505+
506+ if (sect_size > section->raw_data_size)
507+ sect_size = section->raw_data_size;
508+
509+ base = (grub_int8_t *)
510+ grub_shim_image_address (shim_buffer, context->image_size,
511+ section->virtual_address);
512+ end = (grub_int8_t *)
513+ grub_shim_image_address (shim_buffer, context->image_size,
514+ section->virtual_address
515+ + sect_size - 1);
516+ if (!base || !end)
517+ {
518+ grub_printf("Invalid section base\n");
519+ status = GRUB_ERR_BAD_FILE_TYPE;
520+ goto fail;
521+ }
522+
523+ if (section->virtual_address < context->header_size
524+ || section->raw_data_offset < context->header_size)
525+ {
526+ grub_printf("Section is inside image headers\n");
527+ status = GRUB_ERR_BAD_FILE_TYPE;
528+ goto fail;
529+ }
530+
531+ if (section->raw_data_size > 0)
532+ /* TODO: do we need the double cast? */
533+ grub_memcpy ((void *)base,
534+ (void *) (((grub_addr_t) addr)
535+ + section->raw_data_offset), sect_size);
536+
537+ if (sect_size < section->virtual_size)
538+ grub_memset ((void *)(base + sect_size), 0,
539+ section->virtual_size - sect_size);
540+ }
541+
542+ if (context->number_of_rva_and_sizes <= EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC)
543+ {
544+ grub_printf("Image has no relocation entry\n");
545+ status = GRUB_ERR_BAD_FILE_TYPE;
546+ goto fail;
547+ }
548+
549+ if (context->reloc_dir->size)
550+ {
551+ status = grub_shim_relocate_coff (context, (void *) addr,
552+ (void *) shim_buffer);
553+ if (status != GRUB_ERR_NONE)
554+ {
555+ grub_printf("Relocation failed: [%u]\n", status);
556+ status = GRUB_ERR_BAD_FILE_TYPE;
557+ goto fail;
558+ }
559+ }
560+ shim_entry_point = (void *)grub_shim_image_address (shim_buffer,
561+ context->image_size,
562+ context->entry_point);
563+ if (!shim_entry_point)
564+ {
565+ grub_printf("Invalid entry point\n");
566+ status = GRUB_ERR_BAD_FILE_TYPE;
567+ goto fail;
568+ }
569+
570+ shim_used = 1;
571+ return GRUB_ERR_NONE;
572+fail:
573+ efi_call_2 (b->free_pages, shim_buffer, shim_pages);
574+ shim_buffer = 0;
575+ return status;
576+}
577
578 static grub_err_t
579 grub_chainloader_unload (void)
580--
5811.9.1
582
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0005-efi-chainloader-use-shim-to-load-and-verify-an-image.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0005-efi-chainloader-use-shim-to-load-and-verify-an-image.patch
new file mode 100644
index 0000000..143a140
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0005-efi-chainloader-use-shim-to-load-and-verify-an-image.patch
@@ -0,0 +1,98 @@
1From f922ac74714d01972a3c291e15f0c316b67e40eb Mon Sep 17 00:00:00 2001
2From: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
3Date: Fri, 27 Mar 2015 08:26:08 -0700
4Subject: [PATCH 5/7] efi: chainloader: use shim to load and verify an image
5
6Upstream-Status: Inappropriate [embedded specific]
7
8The grub chainloader module uses the UEFI LoadImage service
9to load a chainloaded binary. However, if such binary is not
10signed by the UEFI certification authority, LoadImage will fail.
11Under shim, we can use Machine-Owned Keys (MOKs) to verify an
12image. Thus, in case LoadImage fails due to a security violation
13we rely on the shim verification service. If successful, the
14image is parsed and loaded.
15
16Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
17---
18 grub-core/loader/efi/chainloader.c | 49 +++++++++++++++++++++++++++++++-------
19 1 file changed, 40 insertions(+), 9 deletions(-)
20
21diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
22index bd83859..01d2ebe 100644
23--- a/grub-core/loader/efi/chainloader.c
24+++ b/grub-core/loader/efi/chainloader.c
25@@ -733,6 +733,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
26 grub_efi_loaded_image_t *loaded_image;
27 char *filename;
28 grub_efi_handle_t dev_handle = 0;
29+ struct grub_shim_pe_coff_loader_image_context context;
30
31 if (argc == 0)
32 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
33@@ -827,23 +828,53 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
34 if (status != GRUB_EFI_SUCCESS)
35 {
36 if (status == GRUB_EFI_OUT_OF_RESOURCES)
37- grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of resources");
38+ {
39+ grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of resources");
40+ goto fail;
41+ }
42+ /* try with shim */
43+ else if (status == GRUB_EFI_SECURITY_VIOLATION)
44+ {
45+ status = grub_shim_load_image (address, size, &context);
46+ if (status != GRUB_EFI_SUCCESS)
47+ {
48+ grub_error (GRUB_ERR_BAD_OS, "shim cannot load image");
49+ goto fail;
50+ }
51+ }
52 else
53- grub_error (GRUB_ERR_BAD_OS, "cannot load image");
54-
55- goto fail;
56+ {
57+ grub_error (GRUB_ERR_BAD_OS, "cannot load image");
58+ goto fail;
59+ }
60 }
61
62- /* LoadImage does not set a device handler when the image is
63- loaded from memory, so it is necessary to set it explicitly here.
64- This is a mess. */
65- loaded_image = grub_efi_get_loaded_image (image_handle);
66+ /* if we use shim, the UEFI load_image failed, thus, we borrow
67+ * grub_efi_image_handle and restore it later
68+ */
69+ if (shim_used)
70+ /* if we use shim, the UEFI load_image failed, thus, we borrow
71+ grub_efi_image_handle and restore it later */
72+ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
73+ else
74+ /* LoadImage does not set a device handler when the image is
75+ loaded from memory, so it is necessary to set it explicitly here.
76+ This is a mess. */
77+ loaded_image = grub_efi_get_loaded_image (image_handle);
78+
79 if (! loaded_image)
80 {
81 grub_error (GRUB_ERR_BAD_OS, "no loaded image available");
82 goto fail;
83 }
84- loaded_image->device_handle = dev_handle;
85+ if (shim_used)
86+ {
87+ grub_memcpy(&shim_li_bak, loaded_image, sizeof(shim_li_bak));
88+ loaded_image->image_base = (void *)shim_buffer;
89+ loaded_image->image_size = context.image_size;
90+ }
91+ else
92+ loaded_image->device_handle = dev_handle;
93
94 grub_file_close (file);
95
96--
971.9.1
98
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0006-efi-chainloader-boot-the-image-using-shim.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0006-efi-chainloader-boot-the-image-using-shim.patch
new file mode 100644
index 0000000..46ded18
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0006-efi-chainloader-boot-the-image-using-shim.patch
@@ -0,0 +1,63 @@
1From f25778620360ccff55f3d9c1bccba14249978502 Mon Sep 17 00:00:00 2001
2From: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
3Date: Fri, 27 Mar 2015 08:29:13 -0700
4Subject: [PATCH 6/7] efi: chainloader: boot the image using shim
5
6Upstream-Status: Inappropriate [embedded specific]
7
8If the image was loaded using shim, boot the image. Given that
9shim loaded the image, the UEFI firmware will not know where to
10jump after the execution completes. Thus, replace the UEFI boot
11service Exit with our own implementation to make sure we jump
12to the instruction after the call to the entry point.
13
14Replace the system Exit service when done.
15
16Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
17---
18 grub-core/loader/efi/chainloader.c | 27 ++++++++++++++++++++++++++-
19 1 file changed, 26 insertions(+), 1 deletion(-)
20
21diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
22index 01d2ebe..1c9795c 100644
23--- a/grub-core/loader/efi/chainloader.c
24+++ b/grub-core/loader/efi/chainloader.c
25@@ -605,9 +605,34 @@ grub_chainloader_boot (void)
26 grub_efi_status_t status;
27 grub_efi_uintn_t exit_data_size;
28 grub_efi_char16_t *exit_data = NULL;
29+ grub_efi_loaded_image_t *loaded_image = NULL;
30+ grub_efi_status_t
31+ (*saved_exit) (grub_efi_handle_t image_handle,
32+ grub_efi_status_t exit_status,
33+ grub_efi_uintn_t exit_data_size,
34+ grub_efi_char16_t *exit_data) __attribute__((noreturn));
35
36 b = grub_efi_system_table->boot_services;
37- status = efi_call_3 (b->start_image, image_handle, &exit_data_size, &exit_data);
38+
39+ if (!shim_used)
40+ status = efi_call_3 (b->start_image, image_handle, &exit_data_size, &exit_data);
41+ else
42+ {
43+ saved_exit = grub_efi_system_table->boot_services->exit;
44+ grub_efi_system_table->boot_services->exit = efi_shim_exit;
45+ status = efi_call_foo(shim_entry_point,
46+ (grub_efi_uint64_t)grub_efi_image_handle,
47+ (grub_efi_uint64_t)grub_efi_system_table);
48+ grub_efi_system_table->boot_services->exit = saved_exit;
49+
50+ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
51+ if (!loaded_image)
52+ /* TODO: this is serious, what to do? */
53+ grub_error (GRUB_ERR_BAD_OS, "GRUB loaded image not found");
54+ else
55+ /* restore loaded image */
56+ grub_memcpy(loaded_image, &shim_li_bak, sizeof(shim_li_bak));
57+ }
58 if (status != GRUB_EFI_SUCCESS)
59 {
60 if (exit_data)
61--
621.9.1
63
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0007-efi-chainloader-take-care-of-unload-undershim.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0007-efi-chainloader-take-care-of-unload-undershim.patch
new file mode 100644
index 0000000..6917b2f
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0007-efi-chainloader-take-care-of-unload-undershim.patch
@@ -0,0 +1,43 @@
1From 70a30826d1cfb7a90c34760896dfd92b9c396f52 Mon Sep 17 00:00:00 2001
2From: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
3Date: Fri, 27 Mar 2015 08:31:27 -0700
4Subject: [PATCH 7/7] efi: chainloader: take care of unload undershim
5
6Upstream-Status: Inappropriate [embedded specific]
7
8Under shim, we use a custom buffer to put the relocated image, make
9sure we free that memory when unloading.
10
11Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
12---
13 grub-core/loader/efi/chainloader.c | 14 ++++++++++++--
14 1 file changed, 12 insertions(+), 2 deletions(-)
15
16diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
17index 1c9795c..d0ceb6e 100644
18--- a/grub-core/loader/efi/chainloader.c
19+++ b/grub-core/loader/efi/chainloader.c
20@@ -586,8 +586,18 @@ grub_chainloader_unload (void)
21 grub_efi_boot_services_t *b;
22
23 b = grub_efi_system_table->boot_services;
24- efi_call_1 (b->unload_image, image_handle);
25- efi_call_2 (b->free_pages, address, pages);
26+ if (!shim_used)
27+ {
28+ efi_call_1 (b->unload_image, image_handle);
29+ efi_call_2 (b->free_pages, address, pages);
30+ }
31+ else
32+ {
33+ if (shim_buffer)
34+ {
35+ efi_call_2 (b->free_pages, shim_buffer, shim_pages);
36+ }
37+ }
38
39 grub_free (file_path);
40 grub_free (cmdline);
41--
421.9.1
43
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/Fix-32-bit-build-failures.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/Fix-32-bit-build-failures.patch
new file mode 100644
index 0000000..6ba5352
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/Fix-32-bit-build-failures.patch
@@ -0,0 +1,252 @@
1From e7b2efacc2d3acb48761aa2d62f943310fd70100 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Mon, 25 Apr 2016 11:35:14 +0800
4Subject: [PATCH] Fix 32-bit build failures
5
6Upstream-Status: Pending
7
8For 32-bit build, the 64-bit pointer should be replaced by grub_addr_t
9which is compatible between 32-bit and 64-bit build.
10
11In addition, the functions efi_shim_exit and efi_call_foo should be available
12for 32-bit build.
13
14Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
15---
16 grub-core/Makefile.core.def | 1 +
17 grub-core/kern/i386/efi/callwrap.S | 50 ++++++++++++++++++++++++++++++++++++++
18 grub-core/loader/efi/chainloader.c | 30 +++++++++++------------
19 include/grub/efi/api.h | 8 +++---
20 include/grub/efi/shim.h | 2 +-
21 5 files changed, 71 insertions(+), 20 deletions(-)
22 create mode 100644 grub-core/kern/i386/efi/callwrap.S
23
24diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
25index 39e77a4..0a78137 100644
26--- a/grub-core/Makefile.core.def
27+++ b/grub-core/Makefile.core.def
28@@ -135,6 +135,7 @@ kernel = {
29 efi = term/efi/console.c;
30
31 i386_efi = kern/i386/tsc.c;
32+ i386_efi = kern/i386/efi/callwrap.S;
33 i386_efi = kern/i386/efi/init.c;
34 i386_efi = bus/pci.c;
35
36diff --git a/grub-core/kern/i386/efi/callwrap.S b/grub-core/kern/i386/efi/callwrap.S
37new file mode 100644
38index 0000000..c683444
39--- /dev/null
40+++ b/grub-core/kern/i386/efi/callwrap.S
41@@ -0,0 +1,50 @@
42+/* callwrap.S - wrapper for i386 efi calls */
43+/*
44+ * GRUB -- GRand Unified Bootloader
45+ * Copyright (C) 2006,2007,2009 Free Software Foundation, Inc.
46+ *
47+ * GRUB is free software: you can redistribute it and/or modify
48+ * it under the terms of the GNU General Public License as published by
49+ * the Free Software Foundation, either version 3 of the License, or
50+ * (at your option) any later version.
51+ *
52+ * GRUB is distributed in the hope that it will be useful,
53+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
54+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55+ * GNU General Public License for more details.
56+ *
57+ * You should have received a copy of the GNU General Public License
58+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
59+ */
60+
61+#include <config.h>
62+#include <grub/symbol.h>
63+
64+ .file "callwrap.S"
65+ .text
66+
67+FUNCTION(efi_call_foo)
68+ movl 12(%esp), %eax
69+ movl 8(%esp), %edx
70+ movl 4(%esp), %ecx
71+ pushl %ebx
72+ pushl %esi
73+ pushl %edi
74+ pushl %ebp
75+ movl %esp, saved_sp
76+ subl $40, %esp
77+ pushl %eax
78+ pushl %edx
79+ call *%ecx
80+
81+FUNCTION(efi_shim_exit)
82+ addl $48, %esp
83+ movl saved_sp, %esp
84+ popl %ebp
85+ popl %edi
86+ popl %esi
87+ popl %ebx
88+ ret
89+
90+ .data
91+saved_sp: .long 0
92diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
93index 83769a2..e3d1138 100644
94--- a/grub-core/loader/efi/chainloader.c
95+++ b/grub-core/loader/efi/chainloader.c
96@@ -149,7 +149,7 @@ grub_shim_image_is_loadable (union grub_shim_optional_header_union *pe_hdr)
97 /*
98 * Perform basic bounds checking of the intra-image pointers
99 */
100-static grub_efi_uint64_t
101+static grub_addr_t
102 grub_shim_image_address (grub_addr_t image, grub_uint32_t size, grub_uint32_t addr)
103 {
104 if (addr > size)
105@@ -208,12 +208,12 @@ grub_shim_relocate_coff (struct grub_shim_pe_coff_loader_image_context *context,
106 * yield the next entry in the array.
107 */
108 reloc_base = (struct grub_image_base_relocation *)
109- grub_shim_image_address ((grub_efi_uint64_t)orig, size,
110+ grub_shim_image_address ((grub_addr_t)orig, size,
111 section->raw_data_offset);
112 /* reloc_base_end is the address of the first entry /past/ the
113 * table. */
114 reloc_base_end = (struct grub_image_base_relocation *)
115- grub_shim_image_address ((grub_efi_uint64_t)orig, size,
116+ grub_shim_image_address ((grub_addr_t)orig, size,
117 section->raw_data_offset
118 + section->virtual_size - 1);
119
120@@ -254,7 +254,7 @@ grub_shim_relocate_coff (struct grub_shim_pe_coff_loader_image_context *context,
121 }
122
123 fixup_base = (grub_uint8_t *)
124- grub_shim_image_address ((grub_efi_uint64_t)data,
125+ grub_shim_image_address ((grub_addr_t)data,
126 size,
127 reloc_base->virtual_address);
128 if (!fixup_base)
129@@ -333,12 +333,12 @@ grub_shim_relocate_coff (struct grub_shim_pe_coff_loader_image_context *context,
130 * Read the binary header and grab appropriate information from it
131 */
132 static grub_err_t
133-grub_shim_read_header(grub_efi_physical_address_t data, grub_uint32_t datasize,
134+grub_shim_read_header(grub_addr_t data, grub_uint32_t datasize,
135 struct grub_shim_pe_coff_loader_image_context *context)
136 {
137 struct grub_dos_header *dos_hdr = (struct grub_dos_header *)data;
138 union grub_shim_optional_header_union *pe_hdr = (union grub_shim_optional_header_union *)data;
139- grub_uint64_t header_without_data_dir, section_header_offset, opt_hdr_size;
140+ grub_efi_uintn_t header_without_data_dir, section_header_offset, opt_hdr_size;
141
142 if (datasize < sizeof (pe_hdr->pe32))
143 {
144@@ -393,7 +393,7 @@ grub_shim_read_header(grub_efi_physical_address_t data, grub_uint32_t datasize,
145 + sizeof (grub_efi_uint32_t)
146 + sizeof (struct grub_pe32_coff_header)
147 + pe_hdr->pe32.file_hdr.optional_header_size;
148- if (((grub_efi_uint32_t)context->image_size - section_header_offset)
149+ if ((context->image_size - section_header_offset)
150 / sizeof (struct grub_pe32_section_table)
151 <= context->num_sections)
152 {
153@@ -530,7 +530,7 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
154 }
155
156 /* TODO: do we need the double cast? */
157- grub_memcpy ((void *) ((grub_efi_physical_address_t) shim_buffer),
158+ grub_memcpy ((void *) ((grub_addr_t) shim_buffer),
159 (void *) ((grub_addr_t) addr), context->header_size);
160
161 reloc_base = (grub_int8_t *) grub_shim_image_address (shim_buffer, size,
162@@ -553,10 +553,10 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
163 sect_size = section->raw_data_size;
164
165 base = (grub_int8_t *)
166- grub_shim_image_address (shim_buffer, context->image_size,
167+ grub_shim_image_address ((grub_addr_t) shim_buffer, context->image_size,
168 section->virtual_address);
169 end = (grub_int8_t *)
170- grub_shim_image_address (shim_buffer, context->image_size,
171+ grub_shim_image_address ((grub_addr_t) shim_buffer, context->image_size,
172 section->virtual_address
173 + sect_size - 1);
174
175@@ -619,7 +619,7 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
176 if (context->reloc_dir->size && reloc_section)
177 {
178 status = grub_shim_relocate_coff (context, reloc_section,
179- (void *) addr, (void *) shim_buffer);
180+ (void *) addr, (void *) ((grub_addr_t) shim_buffer));
181 if (status != GRUB_ERR_NONE)
182 {
183 grub_printf("Relocation failed: [%u]\n", status);
184@@ -627,7 +627,7 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
185 goto fail;
186 }
187 }
188- shim_entry_point = (void *)grub_shim_image_address (shim_buffer,
189+ shim_entry_point = (void *)grub_shim_image_address ((grub_addr_t) shim_buffer,
190 context->image_size,
191 context->entry_point);
192 if (!shim_entry_point)
193@@ -696,8 +696,8 @@ grub_chainloader_boot (void)
194 saved_exit = grub_efi_system_table->boot_services->exit;
195 grub_efi_system_table->boot_services->exit = efi_shim_exit;
196 status = efi_call_foo(shim_entry_point,
197- (grub_efi_uint64_t)grub_efi_image_handle,
198- (grub_efi_uint64_t)grub_efi_system_table);
199+ grub_efi_image_handle,
200+ grub_efi_system_table);
201 grub_efi_system_table->boot_services->exit = saved_exit;
202
203 loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
204@@ -970,7 +970,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
205 if (shim_used)
206 {
207 grub_memcpy(&shim_li_bak, loaded_image, sizeof(shim_li_bak));
208- loaded_image->image_base = (void *)shim_buffer;
209+ loaded_image->image_base = (void *)(grub_addr_t) shim_buffer;
210 loaded_image->image_size = context.image_size;
211 }
212 else
213diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
214index 374d88b..22b3543 100644
215--- a/include/grub/efi/api.h
216+++ b/include/grub/efi/api.h
217@@ -1437,10 +1437,6 @@ typedef struct grub_efi_block_io grub_efi_block_io_t;
218
219 grub_uint64_t EXPORT_FUNC(efi_wrap_0) (void *func);
220 grub_uint64_t EXPORT_FUNC(efi_wrap_1) (void *func, grub_uint64_t arg1);
221-grub_efi_status_t EXPORT_FUNC(efi_shim_exit) (grub_efi_handle_t handle, grub_efi_status_t exit_status,
222- grub_efi_uintn_t exit_data_size, grub_efi_char16_t *exit_data) __attribute__((noreturn));
223-grub_uint64_t EXPORT_FUNC(efi_call_foo) (void *func, grub_uint64_t arg1,
224- grub_uint64_t arg2);
225 grub_uint64_t EXPORT_FUNC(efi_wrap_2) (void *func, grub_uint64_t arg1,
226 grub_uint64_t arg2);
227 grub_uint64_t EXPORT_FUNC(efi_wrap_3) (void *func, grub_uint64_t arg1,
228@@ -1467,4 +1463,8 @@ grub_uint64_t EXPORT_FUNC(efi_wrap_10) (void *func, grub_uint64_t arg1,
229 grub_uint64_t arg10);
230 #endif
231
232+grub_efi_status_t EXPORT_FUNC(efi_shim_exit) (grub_efi_handle_t handle, grub_efi_status_t exit_status,
233+ grub_efi_uintn_t exit_data_size, grub_efi_char16_t *exit_data) __attribute__((noreturn));
234+grub_efi_status_t EXPORT_FUNC(efi_call_foo) (void *func, void *arg1, void *arg2);
235+
236 #endif /* ! GRUB_EFI_API_HEADER */
237diff --git a/include/grub/efi/shim.h b/include/grub/efi/shim.h
238index 4b92a00..9fac90b 100644
239--- a/include/grub/efi/shim.h
240+++ b/include/grub/efi/shim.h
241@@ -60,7 +60,7 @@ struct grub_image_base_relocation
242
243 struct grub_shim_pe_coff_loader_image_context {
244 grub_efi_uint64_t image_address;
245- grub_efi_uint64_t image_size;
246+ grub_efi_uintn_t image_size;
247 grub_efi_uint64_t entry_point;
248 grub_efi_uintn_t header_size;
249 grub_efi_uint16_t image_type;
250--
2511.9.1
252
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/Grub-get-and-set-efi-variables.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/Grub-get-and-set-efi-variables.patch
new file mode 100644
index 0000000..7c30632
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/Grub-get-and-set-efi-variables.patch
@@ -0,0 +1,263 @@
1---
2 grub-core/Makefile.core.def | 8 +
3 grub-core/commands/efi/efivar.c | 238 ++++++++++++++++++++++++++++++++++++++++
4 2 files changed, 246 insertions(+)
5
6--- /dev/null
7+++ b/grub-core/commands/efi/efivar.c
8@@ -0,0 +1,238 @@
9+/* efivar.c - Read EFI global variables. */
10+/*
11+ * GRUB -- GRand Unified Bootloader
12+ * Copyright (C) 2015 Free Software Foundation, Inc.
13+ * Copyright (C) 2015 CloudFlare, Inc.
14+ *
15+ * GRUB is free software: you can redistribute it and/or modify
16+ * it under the terms of the GNU General Public License as published by
17+ * the Free Software Foundation, either version 3 of the License, or
18+ * (at your option) any later version.
19+ *
20+ * GRUB is distributed in the hope that it will be useful,
21+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23+ * GNU General Public License for more details.
24+ *
25+ * You should have received a copy of the GNU General Public License
26+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
27+ */
28+
29+#include <grub/types.h>
30+#include <grub/mm.h>
31+#include <grub/misc.h>
32+#include <grub/efi/api.h>
33+#include <grub/efi/efi.h>
34+#include <grub/extcmd.h>
35+#include <grub/env.h>
36+#include <grub/lib/hexdump.h>
37+
38+GRUB_MOD_LICENSE ("GPLv3+");
39+
40+static const struct grub_arg_option options[] = {
41+ {"format", 'f', GRUB_ARG_OPTION_OPTIONAL, N_("Parse EFI_VAR in specific format (hex, uint8, ascii, dump). Default: hex."), N_("FORMAT"), ARG_TYPE_STRING},
42+ {"set", 's', GRUB_ARG_OPTION_OPTIONAL, N_("Save parsed result to environment variable (does not work with dump)."), N_("ENV_VAR"), ARG_TYPE_STRING},
43+ {0, 0, 0, 0, 0, 0}
44+};
45+
46+enum efi_var_type
47+ {
48+ EFI_VAR_ASCII = 0,
49+ EFI_VAR_UINT8,
50+ EFI_VAR_HEX,
51+ EFI_VAR_DUMP,
52+ EFI_VAR_INVALID = -1
53+ };
54+
55+static enum efi_var_type
56+parse_efi_var_type (const char *type)
57+{
58+ if (!grub_strncmp (type, "ascii", sizeof("ascii")))
59+ return EFI_VAR_ASCII;
60+
61+ if (!grub_strncmp (type, "uint8", sizeof("uint8")))
62+ return EFI_VAR_UINT8;
63+
64+ if (!grub_strncmp (type, "hex", sizeof("hex")))
65+ return EFI_VAR_HEX;
66+
67+ if (!grub_strncmp (type, "dump", sizeof("dump")))
68+ return EFI_VAR_DUMP;
69+
70+ return EFI_VAR_INVALID;
71+}
72+
73+static int
74+grub_print_ascii (char *str, char c)
75+{
76+ if (grub_iscntrl (c))
77+ {
78+ switch (c)
79+ {
80+ case '\0':
81+ str[0] = '\\';
82+ str[1] = '0';
83+ return 2;
84+
85+ case '\a':
86+ str[0] = '\\';
87+ str[1] = 'a';
88+ return 2;
89+
90+ case '\b':
91+ str[0] = '\\';
92+ str[1] = 'b';
93+ return 2;
94+
95+ case '\f':
96+ str[0] = '\\';
97+ str[1] = 'f';
98+ return 2;
99+
100+ case '\n':
101+ str[0] = '\\';
102+ str[1] = 'n';
103+ return 2;
104+
105+ case '\r':
106+ str[0] = '\\';
107+ str[1] = 'r';
108+ return 2;
109+
110+ case '\t':
111+ str[0] = '\\';
112+ str[1] = 't';
113+ return 2;
114+
115+ case '\v':
116+ str[0] = '\\';
117+ str[1] = 'v';
118+ return 2;
119+
120+ default:
121+ str[0] = '.'; /* as in hexdump -C */
122+ return 1;
123+ }
124+ }
125+
126+ str[0] = c;
127+ return 1;
128+}
129+
130+static grub_err_t
131+grub_cmd_get_efi_var (struct grub_extcmd_context *ctxt,
132+ int argc, char **args)
133+{
134+ struct grub_arg_list *state = ctxt->state;
135+ grub_err_t status;
136+ void *efi_var = NULL;
137+ grub_size_t efi_var_size = 0;
138+ enum efi_var_type efi_type = EFI_VAR_HEX;
139+ grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
140+ char *env_var = NULL;
141+ grub_size_t i;
142+ char *ptr;
143+
144+ if (1 != argc)
145+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
146+
147+ if (state[0].set)
148+ efi_type = parse_efi_var_type (state[0].arg);
149+
150+ if (EFI_VAR_INVALID == efi_type)
151+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid format specifier"));
152+
153+ efi_var = grub_efi_get_variable (args[0], &global, &efi_var_size);
154+ if (!efi_var || !efi_var_size)
155+ {
156+ status = grub_error (GRUB_ERR_READ_ERROR, N_("cannot read variable"));
157+ goto err;
158+ }
159+
160+ switch (efi_type)
161+ {
162+ case EFI_VAR_ASCII:
163+ env_var = grub_malloc (efi_var_size * 2 + 1);
164+ if (!env_var)
165+ {
166+ status = grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
167+ break;
168+ }
169+
170+ ptr = env_var;
171+
172+ for (i = 0; i < efi_var_size; i++)
173+ ptr += grub_print_ascii (ptr, ((const char *)efi_var)[i]);
174+ *ptr = '\0';
175+ break;
176+
177+ case EFI_VAR_UINT8:
178+ env_var = grub_malloc (4);
179+ if (!env_var)
180+ {
181+ status = grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
182+ break;
183+ }
184+ grub_snprintf (env_var, 4, "%u", *((grub_uint8_t *)efi_var));
185+ break;
186+
187+ case EFI_VAR_HEX:
188+ env_var = grub_malloc (efi_var_size * 2 + 1);
189+ if (!env_var)
190+ {
191+ status = grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
192+ break;
193+ }
194+ for (i = 0; i < efi_var_size; i++)
195+ grub_snprintf (env_var + (i * 2), 3, "%02x", ((grub_uint8_t *)efi_var)[i]);
196+ break;
197+
198+ case EFI_VAR_DUMP:
199+ if (state[1].set)
200+ status = grub_error (GRUB_ERR_BAD_ARGUMENT, N_("cannot set variable with dump format specifier"));
201+ else
202+ {
203+ hexdump (0, (char *)efi_var, efi_var_size);
204+ status = GRUB_ERR_NONE;
205+ }
206+ break;
207+
208+ default:
209+ status = grub_error (GRUB_ERR_BUG, N_("should not happen (bug in module?)"));
210+ }
211+
212+ if (efi_type != EFI_VAR_DUMP)
213+ {
214+ if (state[1].set)
215+ status = grub_env_set (state[1].arg, env_var);
216+ else
217+ {
218+ grub_printf ("%s\n", (const char *)env_var);
219+ status = GRUB_ERR_NONE;
220+ }
221+ }
222+
223+err:
224+
225+ if (env_var)
226+ grub_free (env_var);
227+
228+ if (efi_var)
229+ grub_free (efi_var);
230+
231+ return status;
232+}
233+
234+static grub_extcmd_t cmd = NULL;
235+
236+GRUB_MOD_INIT (efivar)
237+{
238+ cmd = grub_register_extcmd ("get_efivar", grub_cmd_get_efi_var, 0, N_("[-f FORMAT] [-s ENV_VAR] EFI_VAR"),
239+ N_("Read EFI variable and print it or save its contents to environment variable."), options);
240+}
241+
242+GRUB_MOD_FINI (efivar)
243+{
244+ if (cmd)
245+ grub_unregister_extcmd (cmd);
246+}
247--- a/grub-core/Makefile.core.def
248+++ b/grub-core/Makefile.core.def
249@@ -539,6 +539,14 @@ module = {
250 };
251
252 module = {
253+ name = efivar;
254+
255+ common = commands/efi/efivar.c;
256+
257+ enable = efi;
258+};
259+
260+module = {
261 name = lsacpi;
262
263 common = commands/lsacpi.c;
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/Work-around-the-failure-of-ExitBootServices.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/Work-around-the-failure-of-ExitBootServices.patch
new file mode 100644
index 0000000..ca4ad75
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/Work-around-the-failure-of-ExitBootServices.patch
@@ -0,0 +1,62 @@
1From 9517b3173af961ea66721cfc48cd47e50a704388 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Wed, 4 Nov 2015 17:17:06 +0800
4Subject: [PATCH] Work around the failure of ExitBootServices()
5
6ExitBootServices() will fail if any of the event handlers change
7the memory map. In which case, we must be prepared to retry, but
8only once so that we're guaranteed to exit on repeated failures
9instead of spinning forever. This fix refers to the workaround
10made by Linux kernel.
11
12Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
13---
14 grub-core/kern/efi/mm.c | 18 +++++++++++++++++-
15 1 file changed, 17 insertions(+), 1 deletion(-)
16
17diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
18index 461deb0..7620a47 100644
19--- a/grub-core/kern/efi/mm.c
20+++ b/grub-core/kern/efi/mm.c
21@@ -158,6 +158,7 @@ grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf,
22 {
23 grub_efi_boot_services_t *b;
24 grub_efi_status_t status;
25+ int called_exit = 0;
26
27 #if defined (__i386__) || defined (__x86_64__)
28 const grub_uint16_t apple[] = { 'A', 'p', 'p', 'l', 'e' };
29@@ -167,6 +168,7 @@ grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf,
30 apple, sizeof (apple)) == 0);
31 #endif
32
33+get_mem_map:
34 if (grub_efi_get_memory_map (&finish_mmap_size, finish_mmap_buf, &finish_key,
35 &finish_desc_size, &finish_desc_version) < 0)
36 return grub_error (GRUB_ERR_IO, "couldn't retrieve memory map");
37@@ -186,7 +188,21 @@ grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf,
38 status = efi_call_2 (b->exit_boot_services, grub_efi_image_handle,
39 finish_key);
40 if (status != GRUB_EFI_SUCCESS)
41- return grub_error (GRUB_ERR_IO, "couldn't terminate EFI services");
42+ {
43+ /*
44+ * ExitBootServices() will fail if any of the event
45+ * handlers change the memory map. In which case, we
46+ * must be prepared to retry, but only once so that
47+ * we're guaranteed to exit on repeated failures instead
48+ * of spinning forever.
49+ */
50+ if (called_exit)
51+ return grub_error (GRUB_ERR_IO, "couldn't terminate EFI services");
52+
53+ called_exit = 1;
54+ grub_free (finish_mmap_buf);
55+ goto get_mem_map;
56+ }
57
58 grub_efi_is_finished = 1;
59 if (outbuf_size)
60--
611.9.1
62
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/boot-menu.inc b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/boot-menu.inc
new file mode 100644
index 0000000..9cc8726
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/boot-menu.inc
@@ -0,0 +1,13 @@
1# Note the initrd command becomes not working if the command for
2# loading image is changed to the chainloader command instead of
3# the linux command.
4
5menuentry "Sample EFI boot" --unrestricted {
6 savedefault
7 set fallback=1
8 chainloader /bzImage root=/dev/sda2 ro rootwait initrd=/initrd
9}
10
11menuentry "Sample EFI boot (Recovery)" --unrestricted {
12 chainloader /bzImage_bakup root=/dev/sda2 ro rootwait initrd=/initrd_bakup
13}
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/chainloader-Actually-find-the-relocations-correctly-.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/chainloader-Actually-find-the-relocations-correctly-.patch
new file mode 100644
index 0000000..e5a0ebb
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/chainloader-Actually-find-the-relocations-correctly-.patch
@@ -0,0 +1,219 @@
1From f6c412a240312a2be28b85905a0866288db9ffc8 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Sun, 24 Apr 2016 19:02:28 +0800
4Subject: [PATCH] chainloader: Actually find the relocations correctly and
5 process them that way.
6
7Upstream-Status: Pending
8
9Refer to a846aedd0e9dfe26ca6afaf6a1db8a54c20363c1 in shim.
10
11Find the relocations based on the *file* address in the old binary,
12because it's only the same as the virtual address some of the time.
13
14Also perform some extra validation before processing it, and don't bail
15out in /error/ if both ReloceBase and RelocEnd are null - that condition
16is fine.
17
18Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
19---
20 grub-core/loader/efi/chainloader.c | 97 +++++++++++++++++++++++++++++++-------
21 1 file changed, 81 insertions(+), 16 deletions(-)
22
23diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
24index 0e84100..83769a2 100644
25--- a/grub-core/loader/efi/chainloader.c
26+++ b/grub-core/loader/efi/chainloader.c
27@@ -162,6 +162,7 @@ grub_shim_image_address (grub_addr_t image, grub_uint32_t size, grub_uint32_t ad
28 */
29 static grub_err_t
30 grub_shim_relocate_coff (struct grub_shim_pe_coff_loader_image_context *context,
31+ struct grub_pe32_section_table *section,
32 void *orig, void *data)
33 {
34 struct grub_image_base_relocation *reloc_base, *reloc_base_end;
35@@ -173,19 +174,53 @@ grub_shim_relocate_coff (struct grub_shim_pe_coff_loader_image_context *context,
36 grub_efi_uint64_t *fixup64;
37 grub_int32_t size = context->image_size;
38 void *image_end = (char *)orig + size;
39+ int n = 0;
40
41 if (grub_shim_image_is_64_bit(context->pe_hdr))
42 context->pe_hdr->pe32plus.opt_hdr.image_base = (grub_efi_uint64_t)(unsigned long)data;
43 else
44 context->pe_hdr->pe32.opt_hdr.image_base = (grub_efi_uint32_t)(unsigned long)data;
45
46+
47+ /* Alright, so here's how this works:
48+ *
49+ * context->RelocDir gives us two things:
50+ * - the VA the table of base relocation blocks are (maybe) to be
51+ * mapped at (RelocDir->VirtualAddress)
52+ * - the virtual size (RelocDir->Size)
53+ *
54+ * The .reloc section (Section here) gives us some other things:
55+ * - the name! kind of. (Section->Name)
56+ * - the virtual size (Section->VirtualSize), which should be the same
57+ * as RelocDir->Size
58+ * - the virtual address (Section->VirtualAddress)
59+ * - the file section size (Section->SizeOfRawData), which is
60+ * a multiple of OptHdr->FileAlignment. Only useful for image
61+ * validation, not really useful for iteration bounds.
62+ * - the file address (Section->PointerToRawData)
63+ * - a bunch of stuff we don't use that's 0 in our binaries usually
64+ * - Flags (Section->Characteristics)
65+ *
66+ * and then the thing that's actually at the file address is an array
67+ * of EFI_IMAGE_BASE_RELOCATION structs with some values packed behind
68+ * them. The SizeOfBlock field of this structure includes the
69+ * structure itself, and adding it to that structure's address will
70+ * yield the next entry in the array.
71+ */
72 reloc_base = (struct grub_image_base_relocation *)
73 grub_shim_image_address ((grub_efi_uint64_t)orig, size,
74- context->reloc_dir->rva);
75+ section->raw_data_offset);
76+ /* reloc_base_end is the address of the first entry /past/ the
77+ * table. */
78 reloc_base_end = (struct grub_image_base_relocation *)
79 grub_shim_image_address ((grub_efi_uint64_t)orig, size,
80- context->reloc_dir->rva
81- + context->reloc_dir->size - 1);
82+ section->raw_data_offset
83+ + section->virtual_size - 1);
84+
85+ if (!reloc_base && !reloc_base_end)
86+ {
87+ return GRUB_EFI_SUCCESS;
88+ }
89
90 if (!reloc_base || !reloc_base_end)
91 {
92@@ -206,7 +241,7 @@ grub_shim_relocate_coff (struct grub_shim_pe_coff_loader_image_context *context,
93 if ((reloc_base->block_size == 0)
94 || (reloc_base->block_size > context->reloc_dir->size))
95 {
96- grub_printf("Reloc block size %d is invalid\n", reloc_base->block_size);
97+ grub_printf("Reloc %d block size %d is invalid\n", n, reloc_base->block_size);
98 return GRUB_ERR_FILE_READ_ERROR;
99 }
100
101@@ -214,7 +249,7 @@ grub_shim_relocate_coff (struct grub_shim_pe_coff_loader_image_context *context,
102 ((grub_uint8_t *) reloc_base + reloc_base->block_size);
103 if ((void *)reloc_end < orig || (void *)reloc_end > image_end)
104 {
105- grub_printf("Reloc entry overflows binary\n");
106+ grub_printf("Reloc %d entry overflows binary\n", n);
107 return GRUB_ERR_FILE_READ_ERROR;
108 }
109
110@@ -224,7 +259,7 @@ grub_shim_relocate_coff (struct grub_shim_pe_coff_loader_image_context *context,
111 reloc_base->virtual_address);
112 if (!fixup_base)
113 {
114- grub_printf("Invalid fixup_base\n");
115+ grub_printf("Reloc %d invalid fixup_base\n", n);
116 return GRUB_ERR_FILE_READ_ERROR;
117 }
118
119@@ -282,12 +317,13 @@ grub_shim_relocate_coff (struct grub_shim_pe_coff_loader_image_context *context,
120 break;
121
122 default:
123- grub_printf("Unknown relocation\n");
124+ grub_printf("Reloc %d unknown relocation\n", n);
125 return GRUB_ERR_FILE_READ_ERROR;
126 }
127 reloc += 1;
128 }
129 reloc_base = (struct grub_image_base_relocation *) reloc_end;
130+ n++;
131 }
132
133 return GRUB_EFI_SUCCESS;
134@@ -458,9 +494,9 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
135 grub_efi_status_t efi_status;
136 grub_uint32_t sect_size;
137 /* TODO: can they be unsigned? */
138- grub_int8_t *base, *end;
139+ grub_int8_t *base, *end, *reloc_base, *reloc_base_end;
140 grub_int32_t i;
141- struct grub_pe32_section_table *section;
142+ struct grub_pe32_section_table *section, *reloc_section;
143 grub_efi_boot_services_t *b;
144
145 shim_used = 0;
146@@ -496,16 +532,21 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
147 /* TODO: do we need the double cast? */
148 grub_memcpy ((void *) ((grub_efi_physical_address_t) shim_buffer),
149 (void *) ((grub_addr_t) addr), context->header_size);
150+
151+ reloc_base = (grub_int8_t *) grub_shim_image_address (shim_buffer, size,
152+ context->reloc_dir->rva);
153+ /* reloc_base_end here is the address of the last byte of the table */
154+ reloc_base_end = (grub_int8_t *) grub_shim_image_address (shim_buffer, size,
155+ context->reloc_dir->rva +
156+ context->reloc_dir->size - 1);
157+ reloc_section = NULL;
158+
159 /*
160 * Copy the executable's sections to their desired offsets
161 */
162 section = context->first_section;
163 for (i = 0; i < context->num_sections; i++, section++)
164 {
165- if (section->characteristics & 0x02000000)
166- /* section has EFI_IMAGE_SCN_MEM_DISCARDABLE attr set */
167- continue;
168-
169 sect_size = section->virtual_size;
170
171 if (sect_size > section->raw_data_size)
172@@ -518,6 +559,30 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
173 grub_shim_image_address (shim_buffer, context->image_size,
174 section->virtual_address
175 + sect_size - 1);
176+
177+ /* We do want to process .reloc, but it's often marked
178+ * discardable, so we don't want to memcpy it. */
179+ if (grub_memcmp (section->name, ".reloc\0\0", 8) == 0) {
180+ if (reloc_section) {
181+ grub_printf("Image has multiple relocation sections\n");
182+ status = GRUB_ERR_BAD_FILE_TYPE;
183+ goto fail;
184+ }
185+ /* If it has nonzero sizes, and our bounds check
186+ * made sense, and the VA and size match RelocDir's
187+ * versions, then we believe in this section table. */
188+ if (section->raw_data_size && section->virtual_size &&
189+ base && end &&
190+ reloc_base == base &&
191+ reloc_base_end == end) {
192+ reloc_section = section;
193+ }
194+ }
195+
196+ if (section->characteristics & 0x02000000)
197+ /* section has EFI_IMAGE_SCN_MEM_DISCARDABLE attr set */
198+ continue;
199+
200 if (!base || !end)
201 {
202 grub_printf("Invalid section base\n");
203@@ -551,10 +616,10 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
204 goto fail;
205 }
206
207- if (context->reloc_dir->size)
208+ if (context->reloc_dir->size && reloc_section)
209 {
210- status = grub_shim_relocate_coff (context, (void *) addr,
211- (void *) shim_buffer);
212+ status = grub_shim_relocate_coff (context, reloc_section,
213+ (void *) addr, (void *) shim_buffer);
214 if (status != GRUB_ERR_NONE)
215 {
216 grub_printf("Relocation failed: [%u]\n", status);
217--
2181.9.1
219
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/chainloader-Don-t-check-empty-section-in-file-like-..patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/chainloader-Don-t-check-empty-section-in-file-like-..patch
new file mode 100644
index 0000000..482ca5c
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/chainloader-Don-t-check-empty-section-in-file-like-..patch
@@ -0,0 +1,32 @@
1From d3a1198bfc671530ed77ad2b81b0ae4582f9378e Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Sun, 24 Apr 2016 15:56:38 +0800
4Subject: [PATCH] chainloader: Don't check empty section in file like .bss
5
6Upstream-Status: Pending
7
8Because this kind of section always has a zeroed PointerToRawData denoting
9the offset to file and a valid VirtualSize denoting the real size in the
10memory.
11
12Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
13---
14 grub-core/loader/efi/chainloader.c | 2 +-
15 1 file changed, 1 insertion(+), 1 deletion(-)
16
17diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
18index 2d8edc0..0e84100 100644
19--- a/grub-core/loader/efi/chainloader.c
20+++ b/grub-core/loader/efi/chainloader.c
21@@ -526,7 +526,7 @@ grub_shim_load_image(grub_addr_t addr, grub_ssize_t size,
22 }
23
24 if (section->virtual_address < context->header_size
25- || section->raw_data_offset < context->header_size)
26+ || (section->raw_data_offset && section->raw_data_offset < context->header_size))
27 {
28 grub_printf("Section is inside image headers\n");
29 status = GRUB_ERR_BAD_FILE_TYPE;
30--
311.9.1
32
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/chainloader-handle-the-unauthenticated-image-by-shim.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/chainloader-handle-the-unauthenticated-image-by-shim.patch
new file mode 100644
index 0000000..3a3a7a8
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/chainloader-handle-the-unauthenticated-image-by-shim.patch
@@ -0,0 +1,32 @@
1From b945262cdbad67e59f0d13725181862aa8a29561 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Sun, 24 Apr 2016 12:58:10 +0800
4Subject: [PATCH] chainloader: handle the unauthenticated image by shim
5
6Upstream-Status: Pending
7
8EFI_ACCESS_DENIED is another case whenever an unauthenticated image is loaded
9by UEFI LoadImage() boot service. Shim verification protocol should handle
10this case as EFI_SECURITY_VIOLATION.
11
12Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
13---
14 grub-core/loader/efi/chainloader.c | 2 +-
15 1 file changed, 1 insertion(+), 1 deletion(-)
16
17diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
18index 9f908c3..2850627 100644
19--- a/grub-core/loader/efi/chainloader.c
20+++ b/grub-core/loader/efi/chainloader.c
21@@ -868,7 +868,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
22 goto fail;
23 }
24 /* try with shim */
25- else if (status == GRUB_EFI_SECURITY_VIOLATION)
26+ else if ((status == GRUB_EFI_ACCESS_DENIED) || (status == GRUB_EFI_SECURITY_VIOLATION))
27 {
28 status = grub_shim_load_image (address, size, &context);
29 if (status != GRUB_EFI_SUCCESS)
30--
311.9.1
32
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/efi-secure-boot.inc b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/efi-secure-boot.inc
new file mode 100644
index 0000000..a1518e1
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/efi-secure-boot.inc
@@ -0,0 +1,38 @@
1get_efivar -f uint8 -s secured SecureBoot
2
3if [ "${secured}" = "1" ]; then
4 if [ -s "${prefix}/password.inc" ]; then
5 source "${prefix}/password.inc"
6 fi
7fi
8
9get_efivar -f uint8 -s unprovisioned SetupMode
10
11if [ "${unprovisioned}" = "1" ]; then
12 # Create a boot entry for Automatic Certificate Provision.
13 # This is especially useful for certain hardware, e.g,
14 # Intel NUC5i3MYHE, doedn't support to display a customized
15 # BIOS boot option used to launch LockDown.efi.
16
17 if [ ! "${provision_failed}" ]; then
18 # Secure boot was disabled in BIOS setup. Overwrite the
19 # behavior of normal boot.
20 set timeout=0
21 set default="Automatic Certificate Provision"
22 elif [ "${provision_failed}" = "0" ]; then
23 # The auto provision was reset in BIOS setup.
24 set default="Automatic Certificate Provision"
25 fi
26
27 # This menu will be hidden as long as the provision succeeds.
28 menuentry "Automatic Certificate Provision" --unrestricted {
29 set provision_failed="0"
30 save_env provision_failed
31
32 chainloader "${prefix}/LockDown.efi"
33
34 # Refuse to unlimitedly run into auto provision if failed.
35 set provision_failed="1"
36 save_env provision_failed
37 }
38fi
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/grub-efi.cfg b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/grub-efi.cfg
new file mode 100644
index 0000000..4093f59
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/grub-efi.cfg
@@ -0,0 +1,36 @@
1set timeout=3
2set color_normal="light-gray/black"
3set color_highlight="light-green/blue"
4
5# The first boot entry in normal boot.
6set first_boot="0"
7
8# The default boot entry after the first boot.
9set default_boot="0"
10
11function savedefault {
12 if [ "${chosen}" ]; then
13 next_boot="${chosen}"
14 save_env next_boot
15 fi
16}
17
18if [ -s "${prefix}/grubenv" ]; then
19 load_env
20fi
21
22if [ "${next_boot}" ]; then
23 set default="${next_boot}"
24else
25 set default="${first_boot}"
26 set next_boot="${default_boot}"
27 save_env next_boot
28fi
29
30if [ -s "${prefix}/efi-secure-boot.inc" ]; then
31 source "${prefix}/efi-secure-boot.inc"
32fi
33
34if [ -s "${prefix}/boot-menu.inc" ]; then
35 source "${prefix}/boot-menu.inc"
36fi
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/grub-enable-serial-console-by-default.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/grub-enable-serial-console-by-default.patch
new file mode 100644
index 0000000..6d00e4d
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/grub-enable-serial-console-by-default.patch
@@ -0,0 +1,30 @@
1From cd9fbf5dc00733f8e46966e67be85ff6f9d36e6e Mon Sep 17 00:00:00 2001
2From: Paul Gortmaker <paul.gortmaker@windriver.com>
3Date: Fri, 10 Apr 2015 18:38:23 -0400
4Subject: [PATCH] grub: enable serial console by default
5
6Have grub go to the serial console and the default VGA console.
7
8Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
9---
10 util/grub.d/00_header.in | 4 ++++
11 1 file changed, 4 insertions(+)
12
13diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in
14index 765bfdcd30e3..86b260a2c380 100644
15--- a/util/grub.d/00_header.in
16+++ b/util/grub.d/00_header.in
17@@ -27,6 +27,10 @@ grub_lang=`echo $LANG | cut -d . -f 1`
18 export TEXTDOMAIN=@PACKAGE@
19 export TEXTDOMAINDIR="@localedir@"
20
21+export GRUB_TERMINAL_INPUT="console serial"
22+export GRUB_TERMINAL_OUTPUT="console serial"
23+export GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
24+
25 . "@datadir@/@PACKAGE@/grub-mkconfig_lib"
26
27 # Do this as early as possible, since other commands might depend on it.
28--
292.3.1
30
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/mok2verify-support-to-verify-non-PE-file-with-PKCS-7.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/mok2verify-support-to-verify-non-PE-file-with-PKCS-7.patch
new file mode 100644
index 0000000..b5a0a52
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/mok2verify-support-to-verify-non-PE-file-with-PKCS-7.patch
@@ -0,0 +1,709 @@
1From 46873e2c5514bf6460a2f0f39ad8f8feb8f18f68 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Thu, 16 Mar 2017 14:49:41 +0800
4Subject: [PATCH] mok2verify: support to verify non-PE file with PKCS#7
5 signature
6
7MOK2 Verify Protocol is designed to verify non-PE file which cannot be
8verified by the MOK verify protocol supplied by shim loader, such as grub
9configuration, initrd, grub modules and so on.
10
11Each signed file has a .p7b PKCS#7 signature file for verification. For
12more details about signature format and singing tool, refer to
13https://github.com/jiazhang0/SELoader and https://github.com/jiazhang0/libsign
14
15If either kernel or initrd is not authenticated, just go to the failover
16boot to avoid a much worse failure.
17
18If any of grub config files is not authenticated, the boot process just
19stops there.
20
21In addition, the editor, rescue and cmdline modes are protected by the
22combination of settings of secure boot and user authentication in order
23to prevent from tampering the kernel commandline or booting unsigned
24kernel.
25
26Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
27---
28 grub-core/Makefile.core.def | 6 ++
29 grub-core/commands/boot.c | 14 +++-
30 grub-core/gfxmenu/gui_label.c | 39 ++++++++--
31 grub-core/lib/efi/mok2verify.c | 172 +++++++++++++++++++++++++++++++++++++++++
32 grub-core/loader/i386/linux.c | 80 +++++++++++++++++++
33 grub-core/normal/main.c | 55 ++++++++++++-
34 grub-core/normal/menu.c | 29 +++++--
35 grub-core/normal/menu_text.c | 32 ++++++--
36 include/grub/efi/mok2verify.h | 48 ++++++++++++
37 9 files changed, 447 insertions(+), 28 deletions(-)
38 create mode 100644 grub-core/lib/efi/mok2verify.c
39 create mode 100644 include/grub/efi/mok2verify.h
40
41diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
42index e9e1483..8e72251 100644
43--- a/grub-core/Makefile.core.def
44+++ b/grub-core/Makefile.core.def
45@@ -1434,6 +1434,12 @@ module = {
46 };
47
48 module = {
49+ name = mok2verify;
50+ efi = lib/efi/mok2verify.c;
51+ enable = efi;
52+};
53+
54+module = {
55 name = mmap;
56 common = mmap/mmap.c;
57 x86 = mmap/i386/uppermem.c;
58diff --git a/grub-core/commands/boot.c b/grub-core/commands/boot.c
59index 91ec87d..5cddbb6 100644
60--- a/grub-core/commands/boot.c
61+++ b/grub-core/commands/boot.c
62@@ -24,6 +24,9 @@
63 #include <grub/kernel.h>
64 #include <grub/mm.h>
65 #include <grub/i18n.h>
66+#ifdef GRUB_MACHINE_EFI
67+#include <grub/efi/mok2verify.h>
68+#endif
69
70 GRUB_MOD_LICENSE ("GPLv3+");
71
72@@ -143,8 +146,15 @@ grub_loader_boot (void)
73 struct grub_preboot *cur;
74
75 if (! grub_loader_loaded)
76- return grub_error (GRUB_ERR_NO_KERNEL,
77- N_("you need to load the kernel first"));
78+ {
79+#ifdef GRUB_MACHINE_EFI
80+ if (grub_is_secured () == 1)
81+ return grub_error (GRUB_ERR_BAD_OS,
82+ N_("you need to load the authenticated boot components"));
83+#endif
84+ return grub_error (GRUB_ERR_NO_KERNEL,
85+ N_("you need to load the kernel first"));
86+ }
87
88 if (grub_loader_flags & GRUB_LOADER_FLAG_NORETURN)
89 grub_machine_fini ();
90diff --git a/grub-core/gfxmenu/gui_label.c b/grub-core/gfxmenu/gui_label.c
91index 637578f..84bf7d4 100644
92--- a/grub-core/gfxmenu/gui_label.c
93+++ b/grub-core/gfxmenu/gui_label.c
94@@ -23,6 +23,9 @@
95 #include <grub/font.h>
96 #include <grub/gui_string_util.h>
97 #include <grub/i18n.h>
98+#ifdef GRUB_MACHINE_EFI
99+#include <grub/efi/mok2verify.h>
100+#endif
101
102 static const char *align_options[] =
103 {
104@@ -180,15 +183,37 @@ label_set_property (void *vself, const char *name, const char *value)
105 else
106 {
107 if (grub_strcmp (value, "@KEYMAP_LONG@") == 0)
108- value = _("Press enter to boot the selected OS, "
109- "`e' to edit the commands before booting "
110- "or `c' for a command-line. ESC to return previous menu.");
111+ {
112+#ifdef GRUB_MACHINE_EFI
113+ if (grub_is_locked () == 1)
114+ value = _("Press enter to boot the selected OS. "
115+ "ESC to return previous menu.");
116+ else
117+#endif
118+ value = _("Press enter to boot the selected OS, "
119+ "`e' to edit the commands before booting "
120+ "or `c' for a command-line. ESC to return previous menu.");
121+ }
122 else if (grub_strcmp (value, "@KEYMAP_MIDDLE@") == 0)
123- value = _("Press enter to boot the selected OS, "
124- "`e' to edit the commands before booting "
125- "or `c' for a command-line.");
126+ {
127+#ifdef GRUB_MACHINE_EFI
128+ if (grub_is_locked () == 1)
129+ value = _("Press enter to boot the selected OS.");
130+ else
131+#endif
132+ value = _("Press enter to boot the selected OS, "
133+ "`e' to edit the commands before booting "
134+ "or `c' for a command-line.");
135+ }
136 else if (grub_strcmp (value, "@KEYMAP_SHORT@") == 0)
137- value = _("enter: boot, `e': options, `c': cmd-line");
138+ {
139+#ifdef GRUB_MACHINE_EFI
140+ if (grub_is_locked () == 1)
141+ value = _("enter: boot");
142+ else
143+#endif
144+ value = _("enter: boot, `e': options, `c': cmd-line");
145+ }
146 /* FIXME: Add more templates here if needed. */
147 self->template = grub_strdup (value);
148 self->text = grub_xasprintf (value, self->value);
149diff --git a/grub-core/lib/efi/mok2verify.c b/grub-core/lib/efi/mok2verify.c
150new file mode 100644
151index 0000000..2e48ef9
152--- /dev/null
153+++ b/grub-core/lib/efi/mok2verify.c
154@@ -0,0 +1,172 @@
155+/* mok2verify.c - MOK2 Verify Protocol support
156+ *
157+ * BSD 2-clause "Simplified" License
158+ *
159+ * Copyright (c) 2017, Lans Zhang <jia.zhang@windriver.com>
160+ * All rights reserved.
161+ *
162+ * Redistribution and use in source and binary forms, with or without
163+ * modification, are permitted provided that the following conditions are met:
164+ *
165+ * * Redistributions of source code must retain the above copyright notice, this
166+ * list of conditions and the following disclaimer.
167+ *
168+ * * Redistributions in binary form must reproduce the above copyright notice,
169+ * this list of conditions and the following disclaimer in the documentation
170+ * and/or other materials provided with the distribution.
171+ *
172+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
173+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
174+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
175+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
176+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
177+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
178+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
179+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
180+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
181+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
182+ */
183+
184+#include <grub/loader.h>
185+#include <grub/file.h>
186+#include <grub/err.h>
187+#include <grub/misc.h>
188+#include <grub/charset.h>
189+#include <grub/types.h>
190+#include <grub/env.h>
191+#include <grub/mm.h>
192+#include <grub/efi/api.h>
193+#include <grub/efi/efi.h>
194+#include <grub/efi/mok2verify.h>
195+
196+GRUB_MOD_LICENSE ("GPLv2+");
197+
198+#define EFI_MOK2_VERIFY_PROTOCOL_GUID \
199+ { 0x4eda73ad, 0x07aa, 0x4b7a, \
200+ { 0xa1, 0x91, 0xd4, 0xd4, 0x10, 0xfb, 0x8c, 0xb4 } \
201+ }
202+
203+typedef struct efi_mok2_verify_protocol efi_mok2_verify_protocol_t;
204+
205+typedef grub_efi_status_t
206+(*grub_efi_mok2_verify_signature) (efi_mok2_verify_protocol_t *this,
207+ void *signature,
208+ grub_efi_uintn_t signature_size,
209+ void *data, grub_efi_uintn_t data_size);
210+
211+typedef grub_efi_status_t
212+(*grub_efi_mok2_verify_file_buffer) (efi_mok2_verify_protocol_t *this,
213+ void **data, grub_efi_uintn_t *data_size,
214+ const grub_efi_char16_t *path);
215+
216+typedef grub_efi_status_t
217+(*grub_efi_mok2_verify_file) (efi_mok2_verify_protocol_t *this,
218+ const grub_efi_char16_t *path);
219+
220+struct efi_mok2_verify_protocol {
221+ grub_efi_uint8_t revision;
222+ grub_efi_mok2_verify_signature verify_signature;
223+ grub_efi_mok2_verify_file_buffer verify_file_buffer;
224+ grub_efi_mok2_verify_file verify_file;
225+};
226+
227+static grub_efi_guid_t grub_efi_mok2_verify_protoco_guid = EFI_MOK2_VERIFY_PROTOCOL_GUID;
228+
229+int
230+grub_is_secured (void)
231+{
232+ grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
233+ void *efi_var;
234+ grub_size_t efi_var_size = 0;
235+ int secured = 0;
236+
237+ efi_var = grub_efi_get_variable ("SecureBoot", &global, &efi_var_size);
238+ if (!efi_var)
239+ return grub_error (GRUB_ERR_READ_ERROR, N_("cannot read variable"));
240+
241+ if (efi_var_size == 1 && *(grub_uint8_t *) efi_var == 1)
242+ secured = 1;
243+
244+ grub_free (efi_var);
245+
246+ return secured;
247+}
248+
249+int
250+grub_is_unlockable (void)
251+{
252+ return !! grub_env_get ("superusers");
253+}
254+
255+int
256+grub_is_locked (void)
257+{
258+ return ! grub_is_unlockable () && grub_is_secured ();
259+}
260+
261+grub_err_t
262+grub_verify_file (const char *path)
263+{
264+ efi_mok2_verify_protocol_t *mok2;
265+ grub_efi_char16_t *p;
266+ grub_size_t len = grub_strlen (path);
267+ grub_efi_char16_t file_path[(len + 1) * GRUB_MAX_UTF16_PER_UTF8];
268+ const char *root;
269+ const char *real_path;
270+ grub_efi_status_t status;
271+
272+ mok2 = grub_efi_locate_protocol (&grub_efi_mok2_verify_protoco_guid, 0);
273+ if (!mok2)
274+ {
275+ grub_dprintf ("mok2verify", "unable to load mok2 verify protocol\n");
276+ return GRUB_ERR_NONE;
277+ }
278+
279+ grub_dprintf ("mok2verify", "attempting to verify the file %s ...\n", path);
280+
281+ real_path = path;
282+ root = grub_env_get ("root");
283+ if (root)
284+ {
285+ char *pattern;
286+
287+ pattern = grub_xasprintf ("(%s)", root);
288+ if (!pattern)
289+ return grub_errno;
290+
291+ if (grub_strstr (path, pattern) == path)
292+ {
293+ real_path = path + grub_strlen (pattern);
294+ len -= grub_strlen (pattern);
295+ }
296+
297+ grub_free (pattern);
298+ }
299+
300+ len = grub_utf8_to_utf16 (file_path, len * GRUB_MAX_UTF16_PER_UTF8,
301+ (const grub_uint8_t *) real_path, len, 0);
302+ file_path[len] = 0;
303+ for (p = file_path; p < file_path + len; ++p)
304+ if (*p == '/')
305+ *p = '\\';
306+
307+ status = efi_call_2 (mok2->verify_file, mok2, file_path);
308+ if (status != GRUB_EFI_SUCCESS)
309+ {
310+ if (status == GRUB_EFI_NOT_FOUND)
311+ return grub_error (GRUB_ERR_FILE_NOT_FOUND, "the specified file %s is not found",
312+ path);
313+ else
314+ {
315+ grub_printf ("failed to verify file %s (err: 0x%lx)\n",
316+ path, status);
317+
318+ return grub_error (GRUB_ERR_ACCESS_DENIED, "the file %s is not verified",
319+ path);
320+ }
321+ }
322+
323+ grub_dprintf ("mok2verify", "succeeded to verify file %s\n", path);
324+
325+ return GRUB_ERR_NONE;
326+}
327diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
328index e2425c8..5a12444 100644
329--- a/grub-core/loader/i386/linux.c
330+++ b/grub-core/loader/i386/linux.c
331@@ -34,6 +34,9 @@
332 #include <grub/i386/relocator.h>
333 #include <grub/i18n.h>
334 #include <grub/lib/cmdline.h>
335+#ifdef GRUB_MACHINE_EFI
336+#include <grub/efi/mok2verify.h>
337+#endif
338
339 GRUB_MOD_LICENSE ("GPLv3+");
340
341@@ -664,6 +667,55 @@ grub_linux_unload (void)
342 return GRUB_ERR_NONE;
343 }
344
345+#ifdef GRUB_MACHINE_EFI
346+static grub_err_t
347+grub_verify_linux (const char *path)
348+{
349+ grub_file_t file;
350+ grub_ssize_t size;
351+ grub_uint8_t *buf = NULL;
352+
353+ grub_dprintf ("linux", "Verifying kernel %s\n", path);
354+
355+ file = grub_file_open (path);
356+ if (!file)
357+ return grub_errno;
358+
359+ size = grub_file_size (file);
360+
361+ buf = grub_malloc (size);
362+ if (!buf)
363+ goto fail;
364+
365+ if (grub_file_read (file, buf, size) != size)
366+ {
367+ if (!grub_errno)
368+ grub_error (GRUB_ERR_BAD_OS, N_("premature end of kernel file %s"),
369+ path);
370+ goto fail;
371+ }
372+
373+ if (grub_verify_file (path) == GRUB_ERR_NONE)
374+ grub_dprintf ("linux", "kernel %s verified\n", path);
375+ else
376+ grub_error (grub_errno, N_("failed to verify kernel %s"), path);
377+
378+fail:
379+ if (buf)
380+ grub_free (buf);
381+
382+ grub_file_close (file);
383+
384+ return grub_errno;
385+}
386+#else
387+static grub_err_t
388+grub_verify_linux (const char *path)
389+{
390+ return GRUB_ERR_NONE;
391+}
392+#endif
393+
394 static grub_err_t
395 grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
396 int argc, char *argv[])
397@@ -687,6 +739,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
398 goto fail;
399 }
400
401+ if (grub_verify_linux (argv[0]))
402+ goto fail;
403+
404 file = grub_file_open (argv[0]);
405 if (! file)
406 goto fail;
407@@ -1132,6 +1187,26 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
408 argv[i]);
409 goto fail;
410 }
411+
412+#ifdef GRUB_MACHINE_EFI
413+ grub_dprintf ("linux", "Verifying initrd %s, addr=0x%lx, size=0x%lx\n",
414+ argv[i], (unsigned long) ptr, (unsigned long) cursize);
415+
416+ /*
417+ * XXX: use grub_verify_file_buffer (argv[i], ptr, cursize) in future
418+ */
419+ err = grub_verify_file (argv[i]);
420+ if (err == GRUB_ERR_NONE)
421+ {
422+ grub_dprintf ("linux", "initrd %s verified\n", argv[i]);
423+ }
424+ else
425+ {
426+ grub_error (err, N_("failed to verify initrd %s"), argv[i]);
427+ goto fail;
428+ }
429+#endif
430+
431 ptr += cursize;
432 grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
433 ptr += ALIGN_UP_OVERHEAD (cursize, 4);
434@@ -1149,6 +1224,11 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
435 grub_file_close (files[i]);
436 grub_free (files);
437
438+#ifdef GRUB_MACHINE_EFI
439+ /* An unauthenticated initrd always causes a complete boot failure. */
440+ if (grub_is_secured () == 1 && grub_errno != GRUB_ERR_NONE)
441+ grub_loader_unset();
442+#endif
443 return grub_errno;
444 }
445
446diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
447index 13473ec..f11ce2a 100644
448--- a/grub-core/normal/main.c
449+++ b/grub-core/normal/main.c
450@@ -32,6 +32,9 @@
451 #include <grub/i18n.h>
452 #include <grub/charset.h>
453 #include <grub/script_sh.h>
454+#ifdef GRUB_MACHINE_EFI
455+#include <grub/efi/mok2verify.h>
456+#endif
457
458 GRUB_MOD_LICENSE ("GPLv3+");
459
460@@ -233,6 +236,16 @@ grub_normal_init_page (struct grub_term_output *term)
461
462 grub_term_cls (term);
463
464+#ifdef GRUB_MACHINE_EFI
465+ if (grub_is_secured () == 1)
466+ {
467+ if (grub_is_unlockable () == 1)
468+ msg = _("GNU GRUB version %s (UNLOCKABLE)");
469+ else
470+ msg = _("GNU GRUB version %s (LOCKED)");
471+ }
472+#endif
473+
474 msg_formatted = grub_xasprintf (msg, PACKAGE_VERSION);
475 if (!msg_formatted)
476 return;
477@@ -294,6 +307,24 @@ grub_normal_execute (const char *config, int nested, int batch)
478
479 if (config)
480 {
481+#ifdef GRUB_MACHINE_EFI
482+ grub_err_t err;
483+
484+ err = grub_verify_file (config);
485+ if (err != GRUB_ERR_NONE)
486+ {
487+ grub_error (err, "Security Violation: grub.cfg failed to load");
488+ grub_print_error ();
489+
490+ /* System halt. */
491+ asm volatile ("cli");
492+ while (1)
493+ {
494+ asm volatile ("hlt");
495+ }
496+ }
497+#endif
498+
499 menu = read_config_file (config);
500
501 /* Ignore any error. */
502@@ -317,7 +348,10 @@ grub_enter_normal_mode (const char *config)
503 {
504 nested_level++;
505 grub_normal_execute (config, 0, 0);
506- grub_cmdline_run (0);
507+#ifdef GRUB_MACHINE_EFI
508+ if (grub_is_locked () == 0)
509+#endif
510+ grub_cmdline_run (0);
511 nested_level--;
512 if (grub_normal_exit_level)
513 grub_normal_exit_level--;
514@@ -352,6 +386,18 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
515 grub_enter_normal_mode (argv[0]);
516
517 quit:
518+#ifdef GRUB_MACHINE_EFI
519+ if (grub_is_secured () == 1)
520+ {
521+ /* Never return back to the rescue mode */
522+ asm volatile ("cli");
523+
524+ while (1)
525+ {
526+ asm volatile ("hlt");
527+ }
528+ }
529+#endif
530 return 0;
531 }
532
533@@ -527,8 +573,11 @@ GRUB_MOD_INIT(normal)
534 /* Register a command "normal" for the rescue mode. */
535 grub_register_command ("normal", grub_cmd_normal,
536 0, N_("Enter normal mode."));
537- grub_register_command ("normal_exit", grub_cmd_normal_exit,
538- 0, N_("Exit from normal mode."));
539+#ifdef GRUB_MACHINE_EFI
540+ if (grub_is_secured () == 0)
541+#endif
542+ grub_register_command ("normal_exit", grub_cmd_normal_exit,
543+ 0, N_("Exit from normal mode."));
544
545 /* Reload terminal colors when these variables are written to. */
546 grub_register_variable_hook ("color_normal", NULL, grub_env_write_color_normal);
547diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
548index 7e0a158..5ed9670 100644
549--- a/grub-core/normal/menu.c
550+++ b/grub-core/normal/menu.c
551@@ -32,6 +32,9 @@
552 #include <grub/script_sh.h>
553 #include <grub/gfxterm.h>
554 #include <grub/dl.h>
555+#ifdef GRUB_MACHINE_EFI
556+#include <grub/efi/mok2verify.h>
557+#endif
558
559 /* Time to delay after displaying an error message about a default/fallback
560 entry failing to boot. */
561@@ -633,18 +636,28 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
562 break;
563
564 case 'c':
565- menu_fini ();
566- grub_cmdline_run (1);
567- goto refresh;
568+#ifdef GRUB_MACHINE_EFI
569+ if (grub_is_locked () == 0)
570+#endif
571+ {
572+ menu_fini ();
573+ grub_cmdline_run (1);
574+ goto refresh;
575+ }
576
577 case 'e':
578- menu_fini ();
579+#ifdef GRUB_MACHINE_EFI
580+ if (grub_is_locked () == 0)
581+#endif
582 {
583- grub_menu_entry_t e = grub_menu_get_entry (menu, current_entry);
584- if (e)
585- grub_menu_entry_run (e);
586+ menu_fini ();
587+ {
588+ grub_menu_entry_t e = grub_menu_get_entry (menu, current_entry);
589+ if (e)
590+ grub_menu_entry_run (e);
591+ }
592+ goto refresh;
593 }
594- goto refresh;
595
596 default:
597 {
598diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c
599index 1687c28..6e4fbfb 100644
600--- a/grub-core/normal/menu_text.c
601+++ b/grub-core/normal/menu_text.c
602@@ -27,6 +27,9 @@
603 #include <grub/menu_viewer.h>
604 #include <grub/i18n.h>
605 #include <grub/charset.h>
606+#ifdef GRUB_MACHINE_EFI
607+#include <grub/efi/mok2verify.h>
608+#endif
609
610 static grub_uint8_t grub_color_menu_normal;
611 static grub_uint8_t grub_color_menu_highlight;
612@@ -179,19 +182,32 @@ command-line or ESC to discard edits and return to the GRUB menu."),
613
614 if (nested)
615 {
616+#ifdef GRUB_MACHINE_EFI
617+ if (grub_is_locked () == 1)
618+ msg = _("Press enter to boot the selected OS. "
619+ "ESC to return previous menu.");
620+ else
621+#endif
622+ msg = _("Press enter to boot the selected OS, "
623+ "`e' to edit the commands before booting "
624+ "or `c' for a command-line. ESC to return previous menu.");
625+
626 ret += grub_print_message_indented_real
627- (_("Press enter to boot the selected OS, "
628- "`e' to edit the commands before booting "
629- "or `c' for a command-line. ESC to return previous menu."),
630- STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run);
631+ (msg, STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run);
632 }
633 else
634 {
635+#ifdef GRUB_MACHINE_EFI
636+ if (grub_is_locked () == 1)
637+ msg = _("Press enter to boot the selected OS.");
638+ else
639+#endif
640+ msg = _("Press enter to boot the selected OS, "
641+ "`e' to edit the commands before booting "
642+ "or `c' for a command-line.");
643+
644 ret += grub_print_message_indented_real
645- (_("Press enter to boot the selected OS, "
646- "`e' to edit the commands before booting "
647- "or `c' for a command-line."),
648- STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run);
649+ (msg, STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run);
650 }
651 }
652 return ret;
653diff --git a/include/grub/efi/mok2verify.h b/include/grub/efi/mok2verify.h
654new file mode 100644
655index 0000000..98ef2d4
656--- /dev/null
657+++ b/include/grub/efi/mok2verify.h
658@@ -0,0 +1,48 @@
659+/*
660+ * mok2verify.h - interface to MOK2 Verify Protocol
661+ *
662+ * BSD 2-clause "Simplified" License
663+ *
664+ * Copyright (c) 2017, Lans Zhang <jia.zhang@windriver.com>
665+ * All rights reserved.
666+ *
667+ * Redistribution and use in source and binary forms, with or without
668+ * modification, are permitted provided that the following conditions are met:
669+ *
670+ * * Redistributions of source code must retain the above copyright notice, this
671+ * list of conditions and the following disclaimer.
672+ *
673+ * * Redistributions in binary form must reproduce the above copyright notice,
674+ * this list of conditions and the following disclaimer in the documentation
675+ * and/or other materials provided with the distribution.
676+ *
677+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
678+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
679+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
680+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
681+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
682+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
683+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
684+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
685+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
686+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
687+ */
688+
689+#ifndef GRUB_EFI_MOK2_VERIFY_HEADER
690+#define GRUB_EFI_MOK2_VERIFY_HEADER 1
691+
692+#include <grub/types.h>
693+
694+int
695+EXPORT_FUNC (grub_is_secured) (void);
696+
697+int
698+EXPORT_FUNC (grub_is_locked) (void);
699+
700+int
701+EXPORT_FUNC (grub_is_unlockable) (void);
702+
703+grub_err_t
704+EXPORT_FUNC (grub_verify_file) (const char *path);
705+
706+#endif /* ! GRUB_EFI_MOK2_VERIFY_HEADER */
707--
7082.7.4
709
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/password.inc b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/password.inc
new file mode 100644
index 0000000..c0f4b39
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/password.inc
@@ -0,0 +1,2 @@
1set superusers="root"
2password_pbkdf2 root grub.pbkdf2.sha512.10000.4039B6F2AC3D0E349479D2573BC4B206E022E9308DBCBA8F42FBBBF64B699B79A5426CE58503ACBB37CA4116CA1B95C89BEC5F804CB91C8ED5A7381C9E03EDE8.69E763E475CF993A6B4954F9BA863E45E8DFAF2BCEBEAAB21319DC766287FA1A621807F6E2AAD9277A6BA3B9B56A14C0918C441EE47BE304D23ADA562CA018E9
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/serial-redirect-control-x-fix.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/serial-redirect-control-x-fix.patch
new file mode 100644
index 0000000..3ada2b0
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/serial-redirect-control-x-fix.patch
@@ -0,0 +1,22 @@
1---
2 grub-core/term/efi/console.c | 9 ++++++---
3 1 file changed, 6 insertions(+), 3 deletions(-)
4
5--- a/grub-core/term/efi/console.c
6+++ b/grub-core/term/efi/console.c
7@@ -124,9 +124,12 @@ grub_console_getkey (struct grub_term_in
8 if (status != GRUB_EFI_SUCCESS)
9 return GRUB_TERM_NO_KEY;
10
11- if (key.scan_code == 0)
12- return key.unicode_char;
13- else if (key.scan_code < ARRAY_SIZE (efi_codes))
14+ if (key.scan_code == 0) {
15+ if (key.unicode_char < 0x20 && key.unicode_char != 0 && key.unicode_char != '\t' && key.unicode_char != '\b' && key.unicode_char != '\n' && key.unicode_char != '\r')
16+ return GRUB_TERM_CTRL | (key.unicode_char - 1 + 'a');
17+ else
18+ return key.unicode_char;
19+ } else if (key.scan_code < ARRAY_SIZE (efi_codes))
20 return efi_codes[key.scan_code];
21
22 return GRUB_TERM_NO_KEY;
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi_2.02.bbappend b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi_2.02.bbappend
new file mode 100644
index 0000000..dd98968
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi_2.02.bbappend
@@ -0,0 +1,146 @@
1FILESEXTRAPATHS_prepend := "${THISDIR}/grub-efi:"
2
3EXTRA_SRC_URI = " \
4 ${@'file://efi-secure-boot.inc file://password.inc' if d.getVar('UEFI_SB', True) == '1' else ''} \
5"
6
7SRC_URI += " \
8 file://0001-pe32.h-add-header-structures-for-TE-and-DOS-executab.patch \
9 file://0002-shim-add-needed-data-structures.patch \
10 file://0003-efi-chainloader-implement-an-UEFI-Exit-service-for-s.patch \
11 file://0004-efi-chainloader-port-shim-to-grub.patch \
12 file://0005-efi-chainloader-use-shim-to-load-and-verify-an-image.patch \
13 file://0006-efi-chainloader-boot-the-image-using-shim.patch \
14 file://0007-efi-chainloader-take-care-of-unload-undershim.patch \
15 file://chainloader-handle-the-unauthenticated-image-by-shim.patch \
16 file://chainloader-Don-t-check-empty-section-in-file-like-..patch \
17 file://chainloader-Actually-find-the-relocations-correctly-.patch \
18 file://Grub-get-and-set-efi-variables.patch \
19 file://Fix-32-bit-build-failures.patch;apply=0 \
20 file://Work-around-the-failure-of-ExitBootServices.patch;apply=0 \
21 file://serial-redirect-control-x-fix.patch;apply=0 \
22 file://mok2verify-support-to-verify-non-PE-file-with-PKCS-7.patch;apply=0 \
23 file://grub-efi.cfg \
24 file://boot-menu.inc \
25 ${EXTRA_SRC_URI} \
26"
27
28EFI_BOOT_PATH = "/boot/efi/EFI/BOOT"
29
30#GRUB_BUILDIN_append = " chain ${@'efivar mok2verify password_pbkdf2' if d.getVar('UEFI_SB', True) == '1' else ''}"
31GRUB_BUILDIN_append += " chain ${@'efivar password_pbkdf2' if d.getVar('UEFI_SB', True) == '1' else ''}"
32
33# For efi_call_foo and efi_shim_exit
34CFLAGS_append = " -fno-toplevel-reorder"
35
36# Set a default root specifier.
37inherit user-key-store
38
39python __anonymous () {
40 if d.getVar('UEFI_SB', True) != "1":
41 return
42
43 # Override the default filename if efi-secure-boot enabled.
44 # grub-efi must be renamed as grub${arch}.efi for working with shim
45 # or SELoader.
46 import re
47
48 target = d.getVar('TARGET_ARCH', True)
49 if target == "x86_64":
50 grubimage = "grubx64.efi"
51 elif re.match('i.86', target):
52 grubimage = "grubia32.efi"
53 else:
54 raise bb.parse.SkipPackage("grub-efi is incompatible with target %s" % target)
55
56 d.setVar("GRUB_IMAGE", grubimage)
57}
58
59do_compile_append_class-native() {
60 make grub-editenv
61}
62
63do_install_append_class-native() {
64 install -m 0755 grub-editenv "${D}${bindir}"
65}
66
67do_install_append_class-target() {
68 local menu="${WORKDIR}/boot-menu.inc"
69
70 # Enable the default IMA rules if IMA is enabled and encrypted-storage is
71 # disabled. This is because unseal operation will fail when any PCR is
72 # extended due to updating the aggregate integrity value by the default
73 # IMA rules.
74 [ x"${IMA}" = x"1" -a x"${@bb.utils.contains('DISTRO_FEATURES', 'encrypted-storage', '1', '0', d)}" != x"1" ] && {
75 ! grep -q "ima_policy=tcb" "$menu" &&
76 sed -i 's/^\s*chainloader\s\+.*bzImage.*/& ima_policy=tcb/g' "$menu"
77 }
78
79 [ x"${UEFI_SB}" = x"1" ] && {
80 # Don't allow to load the detached initramfs if the bundled kernel used.
81 [ x"${INITRAMFS_IMAGE_BUNDLE}" = x"1" ] &&
82 sed -i 's/\(^\s*chainloader\s\+.*bzImage.*\)\s\+initrd=[^[:space:]]*\(.*\)/\1\2/g' "$menu"
83 }
84
85 # Install the stacked grub configs.
86 install -d "${D}${EFI_BOOT_PATH}"
87 install -m 0600 "${WORKDIR}/grub-efi.cfg" "${D}${EFI_BOOT_PATH}/grub.cfg"
88 install -m 0600 "$menu" "${D}${EFI_BOOT_PATH}"
89 [ x"${UEFI_SB}" = x"1" ] && {
90 install -m 0600 "${WORKDIR}/efi-secure-boot.inc" "${D}${EFI_BOOT_PATH}"
91 install -m 0600 "${WORKDIR}/password.inc" "${D}${EFI_BOOT_PATH}"
92 }
93
94 # Create the initial environment block with empty item.
95 grub-editenv "${D}${EFI_BOOT_PATH}/grubenv" create
96
97 install -d "${D}${EFI_BOOT_PATH}/${GRUB_TARGET}-efi"
98 grub-mkimage -p /EFI/BOOT -d "./grub-core" \
99 -O "${GRUB_TARGET}-efi" -o "${B}/${GRUB_IMAGE}" \
100 ${GRUB_BUILDIN}
101
102 install -m 0644 "${B}/${GRUB_IMAGE}" "${D}${EFI_BOOT_PATH}/${GRUB_IMAGE}"
103
104 # Install the modules to grub-efi's search path
105 make -C grub-core install DESTDIR="${D}${EFI_BOOT_PATH}" pkglibdir=""
106
107 # Remove .module
108 rm -f ${D}${EFI_BOOT_PATH}/${GRUB_TARGET}-efi/*.module
109}
110
111fakeroot python do_sign_class-target() {
112 image_dir = d.getVar('D', True)
113 efi_boot_path = d.getVar('EFI_BOOT_PATH', True)
114 grub_image = d.getVar('GRUB_IMAGE', True)
115 dir = image_dir + efi_boot_path + '/'
116
117 sb_sign(dir + grub_image, dir + grub_image, d)
118 uks_sel_sign(dir + 'grub.cfg', d)
119 uks_sel_sign(dir + 'boot-menu.inc', d)
120
121 if d.getVar('UEFI_SB', True) == "1":
122 uks_sel_sign(dir + 'efi-secure-boot.inc', d)
123 uks_sel_sign(dir + 'password.inc', d)
124}
125
126fakeroot python do_sign() {
127}
128addtask sign after do_install before do_deploy do_package
129
130# Override the do_deploy() in oe-core.
131do_deploy_class-target() {
132 install -m 0644 "${D}${EFI_BOOT_PATH}/${GRUB_IMAGE}" "${DEPLOYDIR}"
133
134 install -d "${DEPLOYDIR}/efi-unsigned"
135 install -m 0644 "${B}/${GRUB_IMAGE}" "${DEPLOYDIR}/efi-unsigned"
136 cp -af "${D}${EFI_BOOT_PATH}/${GRUB_TARGET}-efi" "${DEPLOYDIR}/efi-unsigned"
137}
138
139FILES_${PN} += "/boot/efi"
140
141CONFFILES_${PN} += " \
142 ${EFI_BOOT_PATH}/grub.cfg \
143 ${EFI_BOOT_PATH}/grubenv \
144 ${EFI_BOOT_PATH}/boot-menu.inc \
145 ${EFI_BOOT_PATH}/efi-secure-boot.inc \
146"
diff --git a/meta-efi-secure-boot/recipes-bsp/seloader/seloader_git.bb b/meta-efi-secure-boot/recipes-bsp/seloader/seloader_git.bb
new file mode 100644
index 0000000..76f2669
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/seloader/seloader_git.bb
@@ -0,0 +1,94 @@
1SUMMARY = "The bootloader capable of authenticating the PE and non-PE files."
2DESCRIPTION = "The SELoader is designed to authenticate the non-PE files, \
3such as grub configuration, initrd, grub modules, which cannot be verified \
4by the MOK Verify Protocol registered by shim loader. \
5\
6In order to conveniently authenticate the PE file with gBS->LoadImage() \
7and gBS->StartImage(), the SELoader hooks EFI Security2 Architectural \
8Protocol and employs MOK Verify Protocol to verify the PE file. If only \
9UEFI Secure Boot is enabled, the SELoader just simplily calls \
10gBS->LoadImage() and gBS->StartImage() to allow BIOS to verify PE file. \
11\
12The SELoader publishes MOK2 Verify Protocol which provides a flexible \
13interface to allow the bootloader to verify the file, file buffer or \
14memory buffer without knowing the file format. \
15"
16HOMEPAGE = "https://github.com/jiazhang0/SELoader.git"
17SECTION = "bootloaders"
18
19LICENSE = "BSD-3-Clause"
20LIC_FILES_CHKSUM = "file://LICENSE;md5=d9bf404642f21afb4ad89f95d7bc91ee"
21PR = "r0"
22SRC_URI = " \
23 git://github.com/jiazhang0/SELoader.git \
24"
25SRCREV = "32e3292c33603f319354aac273938fe63897a8da"
26PV = "0.4.5+git${SRCPV}"
27
28COMPATIBLE_HOST = '(i.86|x86_64).*-linux'
29
30inherit deploy user-key-store
31
32S = "${WORKDIR}/git"
33DEPENDS += " \
34 gnu-efi sbsigntool-native \
35"
36
37EFI_ARCH_x86 = "ia32"
38EFI_ARCH_x86-64 = "x64"
39
40EXTRA_OEMAKE = " \
41 CROSS_COMPILE="${TARGET_PREFIX}" \
42 SBSIGN=${STAGING_BINDIR_NATIVE}/sbsign \
43 gnuefi_libdir=${STAGING_LIBDIR} \
44 LIB_GCC="`${CC} -print-libgcc-file-name`" \
45"
46
47PARALLEL_MAKE = ""
48
49EFI_TARGET = "/boot/efi/EFI/BOOT"
50FILES_${PN} += "${EFI_TARGET}"
51
52python do_sign() {
53 sb_sign(d.expand('${B}/Src/Efi/SELoader.efi'), d.expand('${B}/Src/Efi/SELoader.efi.signed'), d)
54 sb_sign(d.expand('${B}/Bin/Hash2DxeCrypto.efi'), d.expand('${B}/Bin/Hash2DxeCrypto.efi.signed'), d)
55 sb_sign(d.expand('${B}/Bin/Pkcs7VerifyDxe.efi'), d.expand('${B}/Bin/Pkcs7VerifyDxe.efi.signed'), d)
56}
57addtask sign after do_compile before do_install
58
59do_install() {
60 install -d ${D}${EFI_TARGET}
61
62 oe_runmake install EFI_DESTDIR=${D}${EFI_TARGET}
63
64 if [ x"${UEFI_SB}" = x"1" ]; then
65 if [ x"${MOK_SB}" != x"1" ]; then
66 mv ${D}${EFI_TARGET}/SELoader${EFI_ARCH}.efi \
67 ${D}${EFI_TARGET}/boot${EFI_ARCH}.efi
68 fi
69 fi
70}
71
72do_deploy() {
73 # Deploy the unsigned images for manual signing
74 install -d ${DEPLOYDIR}/efi-unsigned
75
76 install -m 0600 ${B}/Src/Efi/SELoader.efi \
77 ${DEPLOYDIR}/efi-unsigned/SELoader${EFI_ARCH}.efi
78 install -m 0600 ${B}/Bin/Hash2DxeCrypto.efi ${DEPLOYDIR}/efi-unsigned/
79 install -m 0600 ${B}/Bin/Pkcs7VerifyDxe.efi ${DEPLOYDIR}/efi-unsigned/
80
81 # Deploy the signed images
82 if [ x"${UEFI_SB}" = x"1" -a x"${MOK_SB}" != x"1" ]; then
83 SEL_NAME=boot
84 else
85 SEL_NAME=SELoader
86 fi
87 install -m 0600 ${D}${EFI_TARGET}/${SEL_NAME}${EFI_ARCH}.efi \
88 ${DEPLOYDIR}/${SEL_NAME}${EFI_ARCH}.efi
89 install -m 0600 ${D}${EFI_TARGET}/Hash2DxeCrypto.efi \
90 ${DEPLOYDIR}/Hash2DxeCrypto.efi
91 install -m 0600 ${D}${EFI_TARGET}/Pkcs7VerifyDxe.efi \
92 ${DEPLOYDIR}/Pkcs7VerifyDxe.efi
93}
94addtask deploy after do_install before do_build
diff --git a/meta-efi-secure-boot/recipes-bsp/shim/shim/0001-shim-allow-to-verify-sha1-digest-for-Authenticode.patch b/meta-efi-secure-boot/recipes-bsp/shim/shim/0001-shim-allow-to-verify-sha1-digest-for-Authenticode.patch
new file mode 100644
index 0000000..f458515
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/shim/shim/0001-shim-allow-to-verify-sha1-digest-for-Authenticode.patch
@@ -0,0 +1,156 @@
1From 88806eaf9f1726d06eb4e88f12ca86537dbaab75 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Fri, 16 Jun 2017 15:16:35 +0800
4Subject: [PATCH] shim: allow to verify sha1 digest for Authenticode
5
6Upstream-Status: Pending
7
8The EV code signing cert sometimes doesn't comply the Authenticode spec to
9employ a sha256 digest.
10
11Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
12---
13 shim.c | 48 +++++++++++++++++++++++++++++++++++-------------
14 1 file changed, 35 insertions(+), 13 deletions(-)
15
16diff --git a/shim.c b/shim.c
17index 6e040c4..384ccd7 100644
18--- a/shim.c
19+++ b/shim.c
20@@ -428,7 +428,8 @@ static BOOLEAN verify_eku(UINT8 *Cert, UINTN CertSize)
21 static CHECK_STATUS check_db_cert_in_ram(EFI_SIGNATURE_LIST *CertList,
22 UINTN dbsize,
23 WIN_CERTIFICATE_EFI_PKCS *data,
24- UINT8 *hash)
25+ UINT8 *hash,
26+ UINTN hashsize)
27 {
28 EFI_SIGNATURE_DATA *Cert;
29 UINTN CertSize;
30@@ -445,7 +446,7 @@ static CHECK_STATUS check_db_cert_in_ram(EFI_SIGNATURE_LIST *CertList,
31 data->Hdr.dwLength - sizeof(data->Hdr),
32 Cert->SignatureData,
33 CertSize,
34- hash, SHA256_DIGEST_SIZE);
35+ hash, hashsize);
36 if (IsFound)
37 return DATA_FOUND;
38 }
39@@ -462,7 +463,7 @@ static CHECK_STATUS check_db_cert_in_ram(EFI_SIGNATURE_LIST *CertList,
40 }
41
42 static CHECK_STATUS check_db_cert(CHAR16 *dbname, EFI_GUID guid,
43- WIN_CERTIFICATE_EFI_PKCS *data, UINT8 *hash)
44+ WIN_CERTIFICATE_EFI_PKCS *data, UINT8 *hash, UINTN hashsize)
45 {
46 CHECK_STATUS rc;
47 EFI_STATUS efi_status;
48@@ -477,7 +478,7 @@ static CHECK_STATUS check_db_cert(CHAR16 *dbname, EFI_GUID guid,
49
50 CertList = (EFI_SIGNATURE_LIST *)db;
51
52- rc = check_db_cert_in_ram(CertList, dbsize, data, hash);
53+ rc = check_db_cert_in_ram(CertList, dbsize, data, hash, hashsize);
54
55 FreePool(db);
56
57@@ -571,7 +572,8 @@ static EFI_STATUS check_blacklist (WIN_CERTIFICATE_EFI_PKCS *cert,
58 DATA_FOUND)
59 return EFI_SECURITY_VIOLATION;
60 if (cert && check_db_cert_in_ram(dbx, vendor_dbx_size, cert,
61- sha256hash) == DATA_FOUND)
62+ sha256hash, SHA256_DIGEST_SIZE) ==
63+ DATA_FOUND)
64 return EFI_SECURITY_VIOLATION;
65
66 if (check_db_hash(L"dbx", secure_var, sha256hash, SHA256_DIGEST_SIZE,
67@@ -580,14 +582,14 @@ static EFI_STATUS check_blacklist (WIN_CERTIFICATE_EFI_PKCS *cert,
68 if (check_db_hash(L"dbx", secure_var, sha1hash, SHA1_DIGEST_SIZE,
69 EFI_CERT_SHA1_GUID) == DATA_FOUND)
70 return EFI_SECURITY_VIOLATION;
71- if (cert && check_db_cert(L"dbx", secure_var, cert, sha256hash) ==
72+ if (cert && check_db_cert(L"dbx", secure_var, cert, sha256hash, SHA256_DIGEST_SIZE) ==
73 DATA_FOUND)
74 return EFI_SECURITY_VIOLATION;
75 if (check_db_hash(L"MokListX", shim_var, sha256hash, SHA256_DIGEST_SIZE,
76 EFI_CERT_SHA256_GUID) == DATA_FOUND) {
77 return EFI_SECURITY_VIOLATION;
78 }
79- if (cert && check_db_cert(L"MokListX", shim_var, cert, sha256hash) ==
80+ if (cert && check_db_cert(L"MokListX", shim_var, cert, sha256hash, SHA256_DIGEST_SIZE) ==
81 DATA_FOUND) {
82 return EFI_SECURITY_VIOLATION;
83 }
84@@ -622,7 +624,7 @@ static EFI_STATUS check_whitelist (WIN_CERTIFICATE_EFI_PKCS *cert,
85 update_verification_method(VERIFIED_BY_HASH);
86 return EFI_SUCCESS;
87 }
88- if (cert && check_db_cert(L"db", secure_var, cert, sha256hash)
89+ if (cert && check_db_cert(L"db", secure_var, cert, sha256hash, SHA256_DIGEST_SIZE)
90 == DATA_FOUND) {
91 verification_method = VERIFIED_BY_CERT;
92 update_verification_method(VERIFIED_BY_CERT);
93@@ -636,7 +638,7 @@ static EFI_STATUS check_whitelist (WIN_CERTIFICATE_EFI_PKCS *cert,
94 update_verification_method(VERIFIED_BY_HASH);
95 return EFI_SUCCESS;
96 }
97- if (cert && check_db_cert(L"MokList", shim_var, cert, sha256hash) ==
98+ if (cert && check_db_cert(L"MokList", shim_var, cert, sha256hash, SHA256_DIGEST_SIZE) ==
99 DATA_FOUND) {
100 verification_method = VERIFIED_BY_CERT;
101 update_verification_method(VERIFIED_BY_CERT);
102@@ -1020,27 +1022,47 @@ static EFI_STATUS verify_buffer (char *data, int datasize,
103 /*
104 * Check against the shim build key
105 */
106- if (sizeof(shim_cert) &&
107- AuthenticodeVerify(cert->CertData,
108+ if (sizeof(shim_cert)) {
109+ if (AuthenticodeVerify(cert->CertData,
110 cert->Hdr.dwLength - sizeof(cert->Hdr),
111 shim_cert, sizeof(shim_cert), sha256hash,
112 SHA256_DIGEST_SIZE)) {
113 update_verification_method(VERIFIED_BY_CERT);
114 status = EFI_SUCCESS;
115 return status;
116+ }
117+
118+ if (AuthenticodeVerify(cert->CertData,
119+ cert->Hdr.dwLength - sizeof(cert->Hdr),
120+ shim_cert, sizeof(shim_cert), sha1hash,
121+ SHA1_DIGEST_SIZE)) {
122+ update_verification_method(VERIFIED_BY_CERT);
123+ status = EFI_SUCCESS;
124+ return status;
125+ }
126 }
127
128 /*
129 * And finally, check against shim's built-in key
130 */
131- if (vendor_cert_size &&
132- AuthenticodeVerify(cert->CertData,
133+ if (vendor_cert_size) {
134+ if (AuthenticodeVerify(cert->CertData,
135 cert->Hdr.dwLength - sizeof(cert->Hdr),
136 vendor_cert, vendor_cert_size,
137 sha256hash, SHA256_DIGEST_SIZE)) {
138 update_verification_method(VERIFIED_BY_CERT);
139 status = EFI_SUCCESS;
140 return status;
141+ }
142+
143+ if (AuthenticodeVerify(cert->CertData,
144+ cert->Hdr.dwLength - sizeof(cert->Hdr),
145+ vendor_cert, vendor_cert_size,
146+ sha1hash, SHA1_DIGEST_SIZE)) {
147+ update_verification_method(VERIFIED_BY_CERT);
148+ status = EFI_SUCCESS;
149+ return status;
150+ }
151 }
152 }
153
154--
1552.7.5
156
diff --git a/meta-efi-secure-boot/recipes-bsp/shim/shim/0005-Fix-signing-failure-due-to-not-finding-certificate.patch b/meta-efi-secure-boot/recipes-bsp/shim/shim/0005-Fix-signing-failure-due-to-not-finding-certificate.patch
new file mode 100644
index 0000000..f56aced
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/shim/shim/0005-Fix-signing-failure-due-to-not-finding-certificate.patch
@@ -0,0 +1,36 @@
1From 85e74fa95094175753e39acdd694f9c639069abf Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Fri, 18 Mar 2016 12:30:08 +0800
4Subject: [PATCH 05/11] Fix signing failure due to not finding certificate
5
6Upstream-Status: Pending
7
8The shim.p12 containing private sample key should be imported after
9importing the corresponding certificate shim.crt. Otherwise, the
10nick name of shim certificate cannot be used.
11
12Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
13---
14 Makefile | 4 ++--
15 1 file changed, 2 insertions(+), 2 deletions(-)
16
17diff --git a/Makefile b/Makefile
18index dcfa357..efab050 100644
19--- a/Makefile
20+++ b/Makefile
21@@ -124,10 +124,10 @@ version.c : version.c.in
22 -e "s,@@COMMIT@@,$(shell if [ -d .git ] ; then git log -1 --pretty=format:%H ; elif [ -f commit ]; then cat commit ; else echo commit id not available; fi)," \
23 < version.c.in > version.c
24
25-certdb/secmod.db: shim.crt
26+certdb/secmod.db: shim.crt shim.p12
27 -mkdir certdb
28- $(PK12UTIL) -d certdb/ -i shim.p12 -W "" -K ""
29 $(CERTUTIL) -d certdb/ -A -i shim.crt -n shim -t u
30+ $(PK12UTIL) -d certdb/ -i shim.p12 -W "" -K ""
31
32 shim.o: $(SOURCES) shim_cert.h
33 shim.o: $(wildcard *.h)
34--
352.11.0
36
diff --git a/meta-efi-secure-boot/recipes-bsp/shim/shim/0006-Prevent-from-removing-intermediate-.efi.patch b/meta-efi-secure-boot/recipes-bsp/shim/shim/0006-Prevent-from-removing-intermediate-.efi.patch
new file mode 100644
index 0000000..fbbf94b
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/shim/shim/0006-Prevent-from-removing-intermediate-.efi.patch
@@ -0,0 +1,33 @@
1From 1f03018aa0b7df2eab576d410ec88e8cf66b06e0 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Wed, 21 Sep 2016 11:25:14 +0800
4Subject: [PATCH 06/11] Prevent from removing intermediate .efi
5
6Upstream-Status: Pending
7
8Otherwise Make will delete the .efi during the build:
9sysroots/x86_64-linux/usr/bin/pesign -n certdb -i MokManager.efi -c "shim" -s -o MokManager.efi.signed -f
10rm fallback.efi MokManager.efi
11DEBUG: Shell function do_compile finished
12
13Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
14---
15 Makefile | 2 ++
16 1 file changed, 2 insertions(+)
17
18diff --git a/Makefile b/Makefile
19index efab050..7c71993 100644
20--- a/Makefile
21+++ b/Makefile
22@@ -100,6 +100,8 @@ MOK_SOURCES = MokManager.c shim.h include/console.h PasswordCrypt.c PasswordCryp
23 FALLBACK_OBJS = fallback.o
24 FALLBACK_SRCS = fallback.c
25
26+.PRECIOUS: $(MMNAME).efi $(FBNAME).efi
27+
28 ifneq ($(origin ENABLE_HTTPBOOT), undefined)
29 OBJS += httpboot.o
30 SOURCES += httpboot.c httpboot.h
31--
322.11.0
33
diff --git a/meta-efi-secure-boot/recipes-bsp/shim/shim/0007-Use-sbsign-to-sign-MokManager-and-fallback.patch b/meta-efi-secure-boot/recipes-bsp/shim/shim/0007-Use-sbsign-to-sign-MokManager-and-fallback.patch
new file mode 100644
index 0000000..14fae76
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/shim/shim/0007-Use-sbsign-to-sign-MokManager-and-fallback.patch
@@ -0,0 +1,44 @@
1From 04da6c928d5f15b7adb6c51e55b9aa0a8126063d Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Wed, 21 Sep 2016 11:31:02 +0800
4Subject: [PATCH 07/11] Use sbsign to sign MokManager and fallback
5
6Upstream-Status: Pending
7
8pesign is written with -std=gnu11 and thus the host gcc version lower
9than 4.7 cannot build out pesign.
10
11sbsign is another alternate used to sign efi binary and it works well.
12Therefore, drop to use sbsign to sign efi binary.
13
14Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
15---
16 Makefile | 5 +++--
17 1 file changed, 3 insertions(+), 2 deletions(-)
18
19diff --git a/Makefile b/Makefile
20index 7c71993..58b4b4c 100644
21--- a/Makefile
22+++ b/Makefile
23@@ -12,6 +12,7 @@ HEXDUMP ?= hexdump
24 PK12UTIL ?= pk12util
25 CERTUTIL ?= certutil
26 PESIGN ?= pesign
27+SBSIGN ?= sbsign
28
29 ARCH = $(shell $(CC) -dumpmachine | cut -f1 -d- | sed s,i[3456789]86,ia32,)
30 OBJCOPY_GTE224 = $(shell expr `$(OBJCOPY) --version |grep ^"GNU objcopy" | sed 's/^.*\((.*)\|version\) //g' | cut -f1-2 -d.` \>= 2.24)
31@@ -190,8 +191,8 @@ endif
32 -j .note.gnu.build-id \
33 $(FORMAT) $^ $@.debug
34
35-%.efi.signed: %.efi certdb/secmod.db
36- $(PESIGN) -n certdb -i $< -c "shim" -s -o $@ -f
37+%.efi.signed: %.efi shim.key shim.crt
38+ $(SBSIGN) --key shim.key --cert shim.crt --output $@ $<
39
40 clean:
41 $(MAKE) -C Cryptlib clean
42--
432.11.0
44
diff --git a/meta-efi-secure-boot/recipes-bsp/shim/shim/0008-Fix-the-world-build-failure-due-to-the-missing-rule-.patch b/meta-efi-secure-boot/recipes-bsp/shim/shim/0008-Fix-the-world-build-failure-due-to-the-missing-rule-.patch
new file mode 100644
index 0000000..ddaa9f9
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/shim/shim/0008-Fix-the-world-build-failure-due-to-the-missing-rule-.patch
@@ -0,0 +1,35 @@
1From 508a31905aff2d271f1b82a5a36a614113b7fe85 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Mon, 6 Jun 2016 16:28:09 +0800
4Subject: [PATCH 08/11] Fix the world build failure due to the missing rule of
5 generating shim.key
6
7Upstream-Status: Pending
8
9shim.key is not given without feature/mok-secure-boot, the script
10make-certs already integrated in shim is able to generate it and shim.crt
11for signing. However, the commit 79c0d3ab3964ff03483277a515aaf50016bbe786
12forgets to add the rule of generating shim.key, causing the world build
13failure.
14
15Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
16---
17 Makefile | 2 +-
18 1 file changed, 1 insertion(+), 1 deletion(-)
19
20diff --git a/Makefile b/Makefile
21index 58b4b4c..0da5e6c 100644
22--- a/Makefile
23+++ b/Makefile
24@@ -110,7 +110,7 @@ endif
25
26 all: $(TARGET)
27
28-shim.crt:
29+shim.crt shim.key:
30 ./make-certs shim shim@xn--u4h.net all codesign 1.3.6.1.4.1.311.10.3.1 </dev/null
31
32 shim.cer: shim.crt
33--
342.11.0
35
diff --git a/meta-efi-secure-boot/recipes-bsp/shim/shim/0010-Makefile-do-not-sign-the-efi-file.patch b/meta-efi-secure-boot/recipes-bsp/shim/shim/0010-Makefile-do-not-sign-the-efi-file.patch
new file mode 100644
index 0000000..4819a94
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/shim/shim/0010-Makefile-do-not-sign-the-efi-file.patch
@@ -0,0 +1,35 @@
1From b3d57a092d837fe8134e0b3ff408040fa33d4efc Mon Sep 17 00:00:00 2001
2From: Yunguo Wei <yunguo.wei@windriver.com>
3Date: Wed, 28 Dec 2016 11:08:37 +0800
4Subject: [PATCH 10/11] Makefile: do not sign the efi file
5
6Shim tries to sign all the efi binaries at build time, but is not
7suitable for us. Because the private key has to be supplied, and this
8doesn't make sense to EDSS key.
9
10We will use a seperated function in bitbake file to
11sign these efi binaries, so that we can freely use EDSS key, Wind
12River sample key or user key.
13
14Signed-off-by: Yunguo Wei <yunguo.wei@windriver.com>
15Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
16---
17 Makefile | 2 +-
18 1 file changed, 1 insertion(+), 1 deletion(-)
19
20diff --git a/Makefile b/Makefile
21index 24e21a8..0912cd0 100644
22--- a/Makefile
23+++ b/Makefile
24@@ -92,7 +92,7 @@ endif
25
26 LDFLAGS = --hash-style=sysv -nostdlib -znocombreloc -T $(EFI_LDS) -shared -Bsymbolic -L$(EFI_PATH) -L$(LIB_PATH) -LCryptlib -LCryptlib/OpenSSL $(EFI_CRT_OBJS) --build-id=sha1
27
28-TARGET = $(SHIMNAME).efi $(MMNAME).efi.signed $(FBNAME).efi.signed
29+TARGET = $(SHIMNAME).efi $(MMNAME).efi $(FBNAME).efi
30 OBJS = shim.o netboot.o cert.o replacements.o tpm.o version.o
31 KEYS = shim_cert.h ocsp.* ca.* shim.crt shim.csr shim.p12 shim.pem shim.key shim.cer
32 SOURCES = shim.c shim.h netboot.c include/PeImage.h include/wincert.h include/console.h replacements.c replacements.h tpm.c tpm.h version.c version.h
33--
342.11.0
35
diff --git a/meta-efi-secure-boot/recipes-bsp/shim/shim/0011-Update-verification_method-if-the-loaded-image-is-si.patch b/meta-efi-secure-boot/recipes-bsp/shim/shim/0011-Update-verification_method-if-the-loaded-image-is-si.patch
new file mode 100644
index 0000000..12cbecd
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/shim/shim/0011-Update-verification_method-if-the-loaded-image-is-si.patch
@@ -0,0 +1,69 @@
1From 62489adc36c5177f90ed16af936a4c0a992cea7e Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Wed, 21 Sep 2016 11:17:29 +0800
4Subject: [PATCH 11/11] Update verification_method if the loaded image is
5 signed by shim/vendor cert
6
7Upstream-Status: Pending
8
9Also, if the loaded image is not verfied by cert, the validation process
10should be allowed as well.
11
12Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
13---
14 replacements.c | 2 +-
15 shim.c | 4 ++++
16 2 files changed, 5 insertions(+), 1 deletion(-)
17
18diff --git a/replacements.c b/replacements.c
19index 01eda0e..9ed5a5d 100644
20--- a/replacements.c
21+++ b/replacements.c
22@@ -144,7 +144,7 @@ start_image(EFI_HANDLE image_handle, UINTN *exit_data_size, CHAR16 **exit_data)
23 static EFI_STATUS EFIAPI
24 exit_boot_services(EFI_HANDLE image_key, UINTN map_key)
25 {
26- if (loader_is_participating || verification_method == VERIFIED_BY_HASH) {
27+ if (loader_is_participating || verification_method != VERIFIED_BY_NOTHING) {
28 unhook_system_services();
29 EFI_STATUS status;
30 status = systab->BootServices->ExitBootServices(image_key, map_key);
31diff --git a/shim.c b/shim.c
32index 364784b..ef62145 100644
33--- a/shim.c
34+++ b/shim.c
35@@ -1029,6 +1029,7 @@ static EFI_STATUS verify_buffer (char *data, int datasize,
36 cert->Hdr.dwLength - sizeof(cert->Hdr),
37 shim_cert, sizeof(shim_cert), sha256hash,
38 SHA256_DIGEST_SIZE)) {
39+ update_verification_method(VERIFIED_BY_CERT);
40 status = EFI_SUCCESS;
41 return status;
42 }
43@@ -1037,6 +1038,7 @@ static EFI_STATUS verify_buffer (char *data, int datasize,
44 cert->Hdr.dwLength - sizeof(cert->Hdr),
45 shim_cert, sizeof(shim_cert), sha1hash,
46 SHA1_DIGEST_SIZE)) {
47+ update_verification_method(VERIFIED_BY_CERT);
48 status = EFI_SUCCESS;
49 return status;
50 }
51@@ -1050,6 +1052,7 @@ static EFI_STATUS verify_buffer (char *data, int datasize,
52 cert->Hdr.dwLength - sizeof(cert->Hdr),
53 vendor_cert, vendor_cert_size,
54 sha256hash, SHA256_DIGEST_SIZE)) {
55+ update_verification_method(VERIFIED_BY_CERT);
56 status = EFI_SUCCESS;
57 return status;
58 }
59@@ -1058,6 +1061,7 @@ static EFI_STATUS verify_buffer (char *data, int datasize,
60 cert->Hdr.dwLength - sizeof(cert->Hdr),
61 vendor_cert, vendor_cert_size,
62 sha1hash, SHA1_DIGEST_SIZE)) {
63+ update_verification_method(VERIFIED_BY_CERT);
64 status = EFI_SUCCESS;
65 return status;
66 }
67--
682.11.0
69
diff --git a/meta-efi-secure-boot/recipes-bsp/shim/shim/0012-netboot-replace-the-depreciated-EFI_PXE_BASE_CODE.patch b/meta-efi-secure-boot/recipes-bsp/shim/shim/0012-netboot-replace-the-depreciated-EFI_PXE_BASE_CODE.patch
new file mode 100644
index 0000000..19f6c2d
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/shim/shim/0012-netboot-replace-the-depreciated-EFI_PXE_BASE_CODE.patch
@@ -0,0 +1,28 @@
1From 1f22dc6be768b7032b73ea963901de270e3c99d9 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Sun, 18 Jun 2017 21:50:26 +0800
4Subject: [PATCH] netboot: replace the depreciated EFI_PXE_BASE_CODE
5
6The newer gnu-efi already uses EFI_PXE_BASE_CODE_PROTOCOL instead.
7
8Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
9---
10 netboot.c | 2 +-
11 1 file changed, 1 insertion(+), 1 deletion(-)
12
13diff --git a/netboot.c b/netboot.c
14index 1cc1a2b..32c9b0a 100644
15--- a/netboot.c
16+++ b/netboot.c
17@@ -43,7 +43,7 @@
18 #define ntohs(x) __builtin_bswap16(x) /* supported both by GCC and clang */
19 #define htons(x) ntohs(x)
20
21-static EFI_PXE_BASE_CODE *pxe;
22+static EFI_PXE_BASE_CODE_PROTOCOL *pxe;
23 static EFI_IP_ADDRESS tftp_addr;
24 static CHAR8 *full_path;
25
26--
272.7.5
28
diff --git a/meta-efi-secure-boot/recipes-bsp/shim/shim/LICENSE b/meta-efi-secure-boot/recipes-bsp/shim/shim/LICENSE
new file mode 100644
index 0000000..3b5a464
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/shim/shim/LICENSE
@@ -0,0 +1,30 @@
1Copyright 2012 Red Hat, Inc <mjg@redhat.com>
2
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6
7Redistributions of source code must retain the above copyright
8notice, this list of conditions and the following disclaimer.
9
10Redistributions in binary form must reproduce the above copyright
11notice, this list of conditions and the following disclaimer in the
12documentation and/or other materials provided with the
13distribution.
14
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
26OF THE POSSIBILITY OF SUCH DAMAGE.
27
28Significant portions of this code are derived from Tianocore
29(http://tianocore.sf.net) and are Copyright 2009-2012 Intel
30Corporation.
diff --git a/meta-efi-secure-boot/recipes-bsp/shim/shim_git.bb b/meta-efi-secure-boot/recipes-bsp/shim/shim_git.bb
new file mode 100644
index 0000000..83ba5b7
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-bsp/shim/shim_git.bb
@@ -0,0 +1,137 @@
1SUMMARY = "shim is a trivial EFI application."
2DESCRIPTION = "shim is a trivial EFI application that, when run, attempts to open and \
3execute another application. It will initially attempt to do this via the \
4standard EFI LoadImage() and StartImage() calls. If these fail (because secure \
5boot is enabled and the binary is not signed with an appropriate key, for \
6instance) it will then validate the binary against a built-in certificate. If \
7this succeeds and if the binary or signing key are not blacklisted then shim \
8will relocate and execute the binary."
9HOMEPAGE = "https://github.com/rhinstaller/shim.git"
10SECTION = "bootloaders"
11
12LICENSE = "BSD-2-Clause"
13LIC_FILES_CHKSUM = "file://COPYRIGHT;md5=b92e63892681ee4e8d27e7a7e87ef2bc"
14PR = "r0"
15
16COMPATIBLE_HOST = '(i.86|x86_64).*-linux'
17
18inherit deploy user-key-store
19
20SRC_URI = " \
21 git://github.com/rhinstaller/shim.git \
22 file://0001-shim-allow-to-verify-sha1-digest-for-Authenticode.patch \
23 file://0005-Fix-signing-failure-due-to-not-finding-certificate.patch;apply=0 \
24 file://0006-Prevent-from-removing-intermediate-.efi.patch \
25 file://0007-Use-sbsign-to-sign-MokManager-and-fallback.patch \
26 file://0008-Fix-the-world-build-failure-due-to-the-missing-rule-.patch \
27 file://0010-Makefile-do-not-sign-the-efi-file.patch \
28 file://0011-Update-verification_method-if-the-loaded-image-is-si.patch;apply=0 \
29 file://0012-netboot-replace-the-depreciated-EFI_PXE_BASE_CODE.patch \
30"
31SRC_URI_append_x86-64 = " \
32 ${@bb.utils.contains('DISTRO_FEATURES', 'msft', 'file://shim${EFI_ARCH}.efi.signed file://LICENSE' if uks_signing_model(d) == 'sample' else '', '', d)} \
33"
34
35SRCREV = "55c65546e46a78edbe41e88cb4ccbd2522e09625"
36PV = "12+git${SRCPV}"
37
38S = "${WORKDIR}/git"
39DEPENDS += "\
40 gnu-efi nss openssl util-linux-native openssl-native nss-native \
41"
42
43EFI_ARCH_x86 = "ia32"
44EFI_ARCH_x86-64 = "x64"
45
46EXTRA_OEMAKE = " \
47 CROSS_COMPILE="${TARGET_PREFIX}" \
48 LIB_GCC="`${CC} -print-libgcc-file-name`" \
49 LIB_PATH="${STAGING_LIBDIR}" \
50 EFI_PATH="${STAGING_LIBDIR}" \
51 EFI_INCLUDE="${STAGING_INCDIR}/efi" \
52 RELEASE="_${DISTRO}_${DISTRO_VERSION}" \
53 DEFAULT_LOADER=\\\\\\SELoader${EFI_ARCH}.efi \
54 OPENSSL=${STAGING_BINDIR_NATIVE}/openssl \
55 HEXDUMP=${STAGING_BINDIR_NATIVE}/hexdump \
56 PK12UTIL=${STAGING_BINDIR_NATIVE}/pk12util \
57 CERTUTIL=${STAGING_BINDIR_NATIVE}/certutil \
58 SBSIGN=${STAGING_BINDIR_NATIVE}/sbsign \
59 AR=${AR} \
60 ${@'VENDOR_CERT_FILE=${WORKDIR}/vendor_cert.cer' if d.getVar('MOK_SB', True) == '1' else ''} \
61 ${@'VENDOR_DBX_FILE=${WORKDIR}/vendor_dbx.esl' if uks_signing_model(d) == 'user' else ''} \
62"
63
64PARALLEL_MAKE = ""
65
66EFI_TARGET = "/boot/efi/EFI/BOOT"
67FILES_${PN} += "${EFI_TARGET}"
68
69MSFT = "${@bb.utils.contains('DISTRO_FEATURES', 'msft', '1', '0', d)}"
70
71# Prepare the signing certificate and keys
72python do_prepare_signing_keys() {
73 # For UEFI_SB, shim is not built
74 if d.getVar('MOK_SB', True) != '1':
75 return
76
77 path = create_mok_vendor_dbx(d)
78
79 # Prepare shim_cert and vendor_cert.
80 dir = mok_sb_keys_dir(d)
81
82 import shutil
83
84 shutil.copyfile(dir + 'shim_cert.pem', d.getVar('S', True) + '/shim.crt')
85 pem2der(dir + 'vendor_cert.pem', d.getVar('WORKDIR', True) + '/vendor_cert.cer', d)
86
87 # Replace the shim certificate with EV certificate for speeding up
88 # the progress of MSFT signing.
89 if d.expand('${MSFT}') == "1" and uks_signing_model(d) == "sample":
90 shutil.copyfile(d.expand('${EV_CERT}'), d.expand('${S}/shim.crt'))
91}
92addtask prepare_signing_keys after do_configure before do_compile
93
94python do_sign() {
95 # The pre-signed shim binary will override the one built from the
96 # scratch.
97 pre_signed = d.expand('${WORKDIR}/shim${EFI_ARCH}.efi.signed')
98 dst = d.expand('${B}/shim${EFI_ARCH}.efi.signed')
99 if d.expand('${MSFT}') == "1" and os.path.exists(pre_signed):
100 import shutil
101 shutil.copyfile(pre_signed, dst)
102 else:
103 if uks_signing_model(d) in ('sample', 'user'):
104 uefi_sb_sign(d.expand('${S}/shim${EFI_ARCH}.efi'), dst, d)
105 elif uks_signing_model(d) == 'edss':
106 edss_sign_efi_image(d.expand('${S}/shim${EFI_ARCH}.efi'), dst, d)
107
108 sb_sign(d.expand('${S}/mm${EFI_ARCH}.efi'), d.expand('${B}/mm${EFI_ARCH}.efi.signed'), d)
109 sb_sign(d.expand('${S}/fb${EFI_ARCH}.efi'), d.expand('${B}/fb${EFI_ARCH}.efi.signed'), d)
110}
111addtask sign after do_compile before do_install
112
113do_install() {
114 install -d ${D}${EFI_TARGET}
115
116 local shim_dst="${D}${EFI_TARGET}/boot${EFI_ARCH}.efi"
117 local mm_dst="${D}${EFI_TARGET}/mm${EFI_ARCH}.efi"
118 if [ x"${UEFI_SB}" = x"1" ]; then
119 install -m 0600 ${B}/shim${EFI_ARCH}.efi.signed $shim_dst
120 install -m 0600 ${B}/mm${EFI_ARCH}.efi.signed $mm_dst
121 else
122 install -m 0600 ${B}/shim${EFI_ARCH}.efi $shim_dst
123 install -m 0600 ${B}/mm${EFI_ARCH}.efi $mm_dst
124 fi
125}
126
127# Install the unsigned images for manual signing
128do_deploy() {
129 install -d ${DEPLOYDIR}/efi-unsigned
130
131 install -m 0600 ${B}/shim${EFI_ARCH}.efi ${DEPLOYDIR}/efi-unsigned/boot${EFI_ARCH}.efi
132 install -m 0600 ${B}/mm${EFI_ARCH}.efi ${DEPLOYDIR}/efi-unsigned/mm${EFI_ARCH}.efi
133
134 install -m 0600 "${D}${EFI_TARGET}/boot${EFI_ARCH}.efi" "${DEPLOYDIR}"
135 install -m 0600 "${D}${EFI_TARGET}/mm${EFI_ARCH}.efi" "${DEPLOYDIR}"
136}
137addtask deploy after do_install before do_build
diff --git a/meta-efi-secure-boot/recipes-core/systemd/systemd_%.bbappend b/meta-efi-secure-boot/recipes-core/systemd/systemd_%.bbappend
new file mode 100644
index 0000000..7b935b5
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-core/systemd/systemd_%.bbappend
@@ -0,0 +1,7 @@
1DEPENDS += " \
2 ${@bb.utils.contains('MACHINE_FEATURES', 'efi', 'gnu-efi', '', d)} \
3"
4
5EXTRA_OECONF += " \
6 ${@bb.utils.contains('MACHINE_FEATURES', 'efi', '--enable-efi --enable-gnuefi --with-efi-libdir=${STAGING_LIBDIR} --with-efi-ldsdir=${STAGING_LIBDIR} --with-efi-includedir=${STAGING_INCDIR}', '', d)} \
7"
diff --git a/meta-efi-secure-boot/recipes-devtools/libsign/libsign_git.bb b/meta-efi-secure-boot/recipes-devtools/libsign/libsign_git.bb
new file mode 100644
index 0000000..0984ec5
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-devtools/libsign/libsign_git.bb
@@ -0,0 +1,48 @@
1SUMMARY = "A generic signing tool framework"
2DESCRIPTION = " \
3This project targets to provide a generic signing framework. This framework \
4separates the signing request and signing process and correspondingly forms \
5the so-called signlet and signaturelet. \
6Each signaturelet only concerns about the details about how to construct the \
7layout of a signature format, and signlet only cares how to construct the \
8signing request. \
9"
10SECTION = "devel"
11LICENSE = "BSD-3-Clause"
12LIC_FILES_CHKSUM = "file://${S}/LICENSE;md5=d9bf404642f21afb4ad89f95d7bc91ee"
13
14SRC_URI = " \
15 git://github.com/jiazhang0/libsign.git \
16"
17SRCREV = "dfab84b4235a36bb395bc6663e50578bb2f9edca"
18PV = "0.3.2+git${SRCPV}"
19
20DEPENDS += "openssl"
21RDEPENDS_${PN}_class-target += "libcrypto"
22RDEPENDS_${PN}_class-native += "openssl"
23
24PARALLEL_MAKE = ""
25
26S = "${WORKDIR}/git"
27
28EXTRA_OEMAKE = " \
29 CC="${CC}" \
30 bindir="${STAGING_BINDIR}" \
31 libdir="${STAGING_LIBDIR}" \
32 includedir="${STAGING_INCDIR}" \
33 EXTRA_CFLAGS="${CFLAGS}" \
34 EXTRA_LDFLAGS="${LDFLAGS}" \
35 SIGNATURELET_DIR="${libdir}/signaturelet" \
36 BINDIR="${bindir}" \
37 LIBDIR="${libdir}" \
38"
39
40do_install() {
41 oe_runmake install DESTDIR="${D}"
42}
43
44FILES_${PN} += " \
45 ${libdir}/signaturelet \
46"
47
48BBCLASSEXTEND = "native"
diff --git a/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool-native_git.bb b/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool-native_git.bb
new file mode 100644
index 0000000..2d09a97
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool-native_git.bb
@@ -0,0 +1,50 @@
1SUMMARY = "Signing utility for UEFI secure boot"
2
3LICENSE = "GPLv3"
4LIC_FILES_CHKSUM = "file://LICENSE.GPLv3;md5=9eef91148a9b14ec7f9df333daebc746"
5
6SRC_URI = "git://kernel.ubuntu.com/jk/sbsigntool \
7 file://ccan.git.tar.bz2 \
8 file://disable-man-page-creation.patch \
9 file://Fix-for-multi-sign.patch \
10 file://sbsign-add-x-option-to-avoid-overwrite-existing-sign.patch \
11 file://fix-mixed-implicit-and-normal-rules.patch;apply=0 \
12 file://image-fix-the-segment-fault-caused-by-the-uninitiali.patch \
13"
14
15SRCREV="951ee95a301674c046f55330cd7460e1314deff2"
16PV = "0.6+git${SRCPV}"
17
18inherit autotools-brokensep pkgconfig native
19
20DEPENDS_append = " binutils-native openssl-native gnu-efi-native util-linux-native"
21
22S = "${WORKDIR}/git"
23
24do_configure() {
25 cd ${S}
26 rm -rf lib/ccan.git
27 git clone ${WORKDIR}/ccan.git lib/ccan.git
28 cd lib/ccan.git && git apply ${WORKDIR}/fix-mixed-implicit-and-normal-rules.patch && cd -
29
30 OLD_CC="${CC}"
31
32 if [ ! -e lib/ccan ]; then
33 export CC="${BUILD_CC}"
34 export TMPDIR=${B}
35 lib/ccan.git/tools/create-ccan-tree \
36 --build-type=automake lib/ccan \
37 talloc read_write_all build_assert array_size || exit 2
38 fi
39
40 export CC="${OLD_CC}"
41 ./autogen.sh --noconfigure
42 oe_runconf
43}
44
45EXTRA_OEMAKE += " \
46 INCLUDES='-I../lib/ccan.git/' \
47 EFI_CPPFLAGS='-DEFI_FUNCTION_WRAPPER \
48 -I${STAGING_INCDIR}/efi \
49 -I${STAGING_INCDIR}/efi/${BUILD_ARCH}' \
50"
diff --git a/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/Fix-for-multi-sign.patch b/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/Fix-for-multi-sign.patch
new file mode 100644
index 0000000..873ade0
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/Fix-for-multi-sign.patch
@@ -0,0 +1,41 @@
1From e58a528ef57e53008222f238cce7c326a14572e2 Mon Sep 17 00:00:00 2001
2From: James Bottomley <JBottomley@Parallels.com>
3Date: Mon, 30 Sep 2013 19:25:37 -0700
4Subject: [PATCH] Fix for multi-sign
5
6Upstream-Status: Inappropriate [embedded specific]
7
8The new Tianocore multi-sign code fails now for images signed with
9sbsigntools. The reason is that we don't actually align the signature table,
10we just slap it straight after the binary data. Unfortunately, the new
11multi-signature code checks that our alignment offsets are correct and fails
12the signature for this reason. Fix by adding junk to the end of the image to
13align the signature section.
14
15Signed-off-by: James Bottomley <JBottomley@Parallels.com>
16---
17 src/image.c | 8 +++++++-
18 1 file changed, 7 insertions(+), 1 deletion(-)
19
20diff --git a/src/image.c b/src/image.c
21index 10eba0e..519e288 100644
22--- a/src/image.c
23+++ b/src/image.c
24@@ -385,7 +385,13 @@ static int image_find_regions(struct image *image)
25
26 /* record the size of non-signature data */
27 r = &image->checksum_regions[image->n_checksum_regions - 1];
28- image->data_size = (r->data - (void *)image->buf) + r->size;
29+ /*
30+ * The new Tianocore multisign does a stricter check of the signatures
31+ * in particular, the signature table must start at an aligned offset
32+ * fix this by adding bytes to the end of the text section (which must
33+ * be included in the hash)
34+ */
35+ image->data_size = align_up((r->data - (void *)image->buf) + r->size, 8);
36
37 return 0;
38 }
39--
401.8.4
41
diff --git a/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/ccan.git.tar.bz2 b/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/ccan.git.tar.bz2
new file mode 100644
index 0000000..9a2994f
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/ccan.git.tar.bz2
Binary files differ
diff --git a/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/disable-man-page-creation.patch b/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/disable-man-page-creation.patch
new file mode 100644
index 0000000..9310628
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/disable-man-page-creation.patch
@@ -0,0 +1,15 @@
1Upstream-Status: Inappropriate [embedded specific]
2
3diff --git a/docs/Makefile.am b/docs/Makefile.am
4index 1b5a588..6918dd8 100644
5--- a/docs/Makefile.am
6+++ b/docs/Makefile.am
7@@ -1,8 +1,4 @@
8
9-man1_MANS = sbsign.1 sbverify.1 sbattach.1 sbvarsign.1 sbsiglist.1
10-
11-EXTRA_DIST = sbsign.1.in sbverify.1.in sbattach.1.in \
12- sbvarsign.1.in sbsiglist.1.in
13 CLEANFILES = $(man1_MANS)
14
15 $(builddir)/%.1: $(srcdir)/%.1.in $(top_builddir)/src/%
diff --git a/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/fix-mixed-implicit-and-normal-rules.patch b/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/fix-mixed-implicit-and-normal-rules.patch
new file mode 100644
index 0000000..3031e4a
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/fix-mixed-implicit-and-normal-rules.patch
@@ -0,0 +1,33 @@
1From 05e73dbe1f25600ad0dbb36b2d690560c5a36281 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Tue, 31 Mar 2015 15:34:38 +0800
4Subject: [PATCH] Fix mixed implicit and normal rules
5
6Upstream-Status: Inappropriate [embedded specific]
7
8This patch comes from upstream:
9http://git.yoctoproject.org/cgit/cgit.cgi/meta-luv/plain/recipes-devtools/sbsigntool/sbsigntool/fix-mixed-implicit-and-normal-rules.patch
10
11Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
12---
13 Makefile | 4 ----
14 1 file changed, 4 deletions(-)
15
16diff --git a/Makefile b/Makefile
17index 65d0d8f..a83185d 100644
18--- a/Makefile
19+++ b/Makefile
20@@ -39,10 +39,6 @@ $(SCOREDIR)/SUMMARY: $(MODS:%=$(SCOREDIR)/%.score)
21 $(CC) -v >> $@
22 cat $^ | grep 'Total score:' >> $@
23
24-$(SCOREDIR)/%.score: ccan/%/_info tools/ccanlint/ccanlint $(OBJFILES)
25- mkdir -p `dirname $@`
26- $(CCANLINT) -v -s ccan/$* > $@ || true
27-
28 $(ALL_DEPENDS): %/.depends: %/_info tools/ccan_depends
29 tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
30
31--
321.8.3.1
33
diff --git a/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/image-fix-the-segment-fault-caused-by-the-uninitiali.patch b/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/image-fix-the-segment-fault-caused-by-the-uninitiali.patch
new file mode 100644
index 0000000..6fef038
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/image-fix-the-segment-fault-caused-by-the-uninitiali.patch
@@ -0,0 +1,30 @@
1From a6862cb3bb3b00a1d6704b2bd1fedbd1374be861 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Thu, 6 Apr 2017 11:11:14 +0800
4Subject: [PATCH] image: fix the segment fault caused by the uninitialized
5 sigbuf
6
7The uninitialized struct image might contain a non-zeroed sigbuf and then
8it is wrongly freed by image_add_signature().
9
10Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
11---
12 src/image.c | 2 +-
13 1 file changed, 1 insertion(+), 1 deletion(-)
14
15diff --git a/src/image.c b/src/image.c
16index cc55791..644e8f1 100644
17--- a/src/image.c
18+++ b/src/image.c
19@@ -395,7 +395,7 @@ struct image *image_load(const char *filename)
20 struct image *image;
21 int rc;
22
23- image = talloc(NULL, struct image);
24+ image = talloc_zero(NULL, struct image);
25 if (!image) {
26 perror("talloc(image)");
27 return NULL;
28--
292.11.0
30
diff --git a/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/sbsign-add-x-option-to-avoid-overwrite-existing-sign.patch b/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/sbsign-add-x-option-to-avoid-overwrite-existing-sign.patch
new file mode 100644
index 0000000..b67f56a
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-devtools/sbsigntool/sbsigntool/sbsign-add-x-option-to-avoid-overwrite-existing-sign.patch
@@ -0,0 +1,75 @@
1From 0016a571a5ea1ab65817973f179800947e1aa8de Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Fri, 15 Jan 2016 09:40:56 +0800
4Subject: [PATCH] sbsign: add -x option to avoid overwrite existing signature
5
6Upstream-Status: Pending
7
8Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
9---
10 src/sbsign.c | 17 +++++++++++++++--
11 1 file changed, 15 insertions(+), 2 deletions(-)
12
13diff --git a/src/sbsign.c b/src/sbsign.c
14index dcf6eed..7dc101f 100644
15--- a/src/sbsign.c
16+++ b/src/sbsign.c
17@@ -66,6 +66,7 @@ struct sign_context {
18 };
19
20 static struct option options[] = {
21+ { "noresign", no_argument, NULL, 'x' },
22 { "output", required_argument, NULL, 'o' },
23 { "cert", required_argument, NULL, 'c' },
24 { "key", required_argument, NULL, 'k' },
25@@ -87,6 +88,7 @@ static void usage(void)
26 "\t--cert <certfile> certificate (x509 certificate)\n"
27 "\t--detached write a detached signature, instead of\n"
28 "\t a signed binary\n"
29+ "\t--noresign don't re-sign the binary if signed\n"
30 "\t--output <file> write signed data to <file>\n"
31 "\t (default <efi-boot-image>.signed,\n"
32 "\t or <efi-boot-image>.pk7 for detached\n"
33@@ -114,7 +116,7 @@ int main(int argc, char **argv)
34 const char *keyfilename, *certfilename;
35 struct sign_context *ctx;
36 uint8_t *buf, *tmp;
37- int rc, c, sigsize;
38+ int rc, c, sigsize, no_resign = 0;
39
40 ctx = talloc_zero(NULL, struct sign_context);
41
42@@ -123,11 +125,14 @@ int main(int argc, char **argv)
43
44 for (;;) {
45 int idx;
46- c = getopt_long(argc, argv, "o:c:k:dvVh", options, &idx);
47+ c = getopt_long(argc, argv, "xo:c:k:dvVh", options, &idx);
48 if (c == -1)
49 break;
50
51 switch (c) {
52+ case 'x':
53+ no_resign = 1;
54+ break;
55 case 'o':
56 ctx->outfilename = talloc_strdup(ctx, optarg);
57 break;
58@@ -178,6 +183,14 @@ int main(int argc, char **argv)
59 if (!ctx->image)
60 return EXIT_FAILURE;
61
62+ if (ctx->image->cert_table) {
63+ if (no_resign) {
64+ fprintf(stderr,
65+ "Don't overwrite existing signature\n");
66+ return EXIT_SUCCESS;
67+ }
68+ }
69+
70 talloc_steal(ctx, ctx->image);
71
72 ERR_load_crypto_strings();
73--
741.9.1
75
diff --git a/meta-efi-secure-boot/recipes-extended/mokutil/mokutil_git.bb b/meta-efi-secure-boot/recipes-extended/mokutil/mokutil_git.bb
new file mode 100644
index 0000000..0ea4c96
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-extended/mokutil/mokutil_git.bb
@@ -0,0 +1,24 @@
1SUMMARY = "The utility to manipulate machines owner keys which managed in shim"
2
3LICENSE = "GPLv3"
4LIC_FILES_CHKSUM = "file://COPYING;md5=d32239bcb673463ab874e80d47fae504"
5
6SRC_URI = "\
7 git://github.com/lcp/mokutil.git \
8"
9
10S = "${WORKDIR}/git"
11SRCREV = "e19adc575c1f9d8f08b7fbc594a0887ace63f83f"
12PV = "0.3.0+git${SRCPV}"
13
14inherit autotools pkgconfig
15
16DEPENDS += "openssl efivar"
17RDEPENDS_${PN} += "openssl efivar"
18
19EXTRA_OEMAKE += "\
20 EFIVAR_LIBS='-L${STAGING_LIBDIR} -lefivar' \
21 OPENSSL_LIBS='-L${STAGING_LIBDIR} -lssl -lcrypto' \
22"
23
24FILES_${PN} += "${datadir}/bash-completion/*"
diff --git a/meta-efi-secure-boot/recipes-kernel/linux/linux-yocto-efi-secure-boot.inc b/meta-efi-secure-boot/recipes-kernel/linux/linux-yocto-efi-secure-boot.inc
new file mode 100644
index 0000000..8c570a1
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-kernel/linux/linux-yocto-efi-secure-boot.inc
@@ -0,0 +1,101 @@
1FILESEXTRAPATHS_prepend := "${THISDIR}/linux-yocto:"
2
3sccs = " \
4 ${@bb.utils.contains('DISTRO_FEATURES', 'efi-secure-boot', \
5 'cfg/efi-ext.scc', '', d)} \
6"
7KERNEL_FEATURES_append_x86 += "${sccs}"
8KERNEL_FEATURES_append_x86-64 += "${sccs}"
9
10inherit user-key-store
11
12fakeroot python do_sign() {
13 import re
14
15 if (d.expand('${TARGET_ARCH}') != 'x86_64') and (not re.match('i.86', d.expand('${TARGET_ARCH}'))):
16 return
17
18 if d.expand('${UEFI_SB}') != '1':
19 return
20
21 import shutil
22
23 for type in d.expand('${KERNEL_IMAGETYPES}').split():
24 kernel = d.expand('${B}/${KERNEL_OUTPUT_DIR}/') + type
25
26 # Prepare the unsigned kernel image for manual signing.
27 shutil.copy(kernel, d.expand('${B}/') + type + '.unsigned')
28
29 # SELoader signature is always based on the unsigned kernel image,
30 # disallowing chainloader to kernel efi-stub.
31 uks_sel_sign(kernel, d)
32
33 shutil.copyfile(kernel, d.expand('${D}/boot/') + type + d.expand('-${KERNEL_RELEASE}'))
34 shutil.copyfile(kernel + '.p7b', d.expand('${D}/boot/') + type + d.expand('-${KERNEL_RELEASE}.p7b'))
35}
36
37# Make sure the kernel image has been signed before kernel_do_deploy()
38# which prepares the kernel image for creating usb/iso.
39addtask sign after do_install before do_package do_populate_sysroot do_deploy
40
41fakeroot python do_sign_bundled_kernel() {
42 import re
43
44 if (d.expand('${TARGET_ARCH}') != 'x86_64') and (not re.match('i.86', d.expand('${TARGET_ARCH}'))):
45 return
46
47 if d.expand('${UEFI_SB}') != '1':
48 return
49
50 if (d.expand('${INITRAMFS_IMAGE}') == '') or (d.expand('${INITRAMFS_IMAGE_BUNDLE}') != '1'):
51 return
52
53 import shutil
54
55 for type in d.expand('${KERNEL_IMAGETYPES}').split():
56 kernel = d.expand('${B}/${KERNEL_OUTPUT_DIR}/') + type + '.initramfs'
57
58 # Prepare the unsigned kernel image for manual signing.
59 shutil.copy(kernel, d.expand('${B}/') + type + '.initramfs.unsigned')
60
61 # SELoader signature is always based on the unsigned kernel image,
62 # disallowing chainloader to kernel efi-stub.
63 uks_sel_sign(kernel, d)
64
65 shutil.copyfile(kernel, d.expand('${D}/boot/') + type + d.expand('-initramfs-${MACHINE}.bin'))
66 shutil.copyfile(kernel + '.p7b', d.expand('${D}/boot/') + type + d.expand('-initramfs-${MACHINE}.bin.p7b'))
67}
68addtask sign_bundled_kernel after do_bundle_initramfs before do_deploy
69
70do_deploy_append() {
71 install -d "${DEPLOYDIR}/efi-unsigned"
72
73 for type in ${KERNEL_IMAGETYPES}; do
74 if [ -f "${B}/$type.unsigned" ]; then
75 install -m 0644 "${B}/$type.unsigned" "${DEPLOYDIR}/efi-unsigned/$type"
76 fi
77
78 if [ -f "${B}/$type.initramfs.unsigned" ]; then
79 install -m 0644 "${B}/$type.initramfs.unsigned" "${DEPLOYDIR}/efi-unsigned/type.initramfs"
80 fi
81
82 if [ -f "${D}/boot/$type-initramfs-${MACHINE}.bin.p7b" ]; then
83 install -m 0644 "${D}/boot/$type-initramfs-${MACHINE}.bin.p7b" "${DEPLOYDIR}"
84 fi
85
86 if [ -f "${B}/${KERNEL_OUTPUT_DIR}/$type.p7b" ]; then
87 base_name="${type}-${KERNEL_IMAGE_BASE_NAME}.bin.p7b"
88
89 install -m 0644 "${B}/${KERNEL_OUTPUT_DIR}/$type.p7b" "${DEPLOYDIR}/$base_name"
90 ln -sf "$base_name" "${DEPLOYDIR}/$type-${KERNEL_IMAGE_SYMLINK_NAME}.bin.p7b"
91 ln -sf "$base_name" "${DEPLOYDIR}/$type.p7b"
92 fi
93 done
94}
95
96# Ship *.p7b files to related packages
97python do_package_prepend() {
98 for type in d.expand('${KERNEL_IMAGETYPES}').split():
99 typelower = type.lower()
100 d.appendVar('FILES_kernel-image-' + typelower, ' /boot/' + type + d.expand('-${KERNEL_VERSION_NAME}.p7b'))
101}
diff --git a/meta-efi-secure-boot/recipes-kernel/linux/linux-yocto-rt_%.bbappend b/meta-efi-secure-boot/recipes-kernel/linux/linux-yocto-rt_%.bbappend
new file mode 100644
index 0000000..956a35c
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-kernel/linux/linux-yocto-rt_%.bbappend
@@ -0,0 +1 @@
require linux-yocto-efi-secure-boot.inc
diff --git a/meta-efi-secure-boot/recipes-kernel/linux/linux-yocto_%.bbappend b/meta-efi-secure-boot/recipes-kernel/linux/linux-yocto_%.bbappend
new file mode 100644
index 0000000..956a35c
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-kernel/linux/linux-yocto_%.bbappend
@@ -0,0 +1 @@
require linux-yocto-efi-secure-boot.inc
diff --git a/meta-efi-secure-boot/recipes-perl/libfile-slurp/libfile-slurp-perl_9999.19.bb b/meta-efi-secure-boot/recipes-perl/libfile-slurp/libfile-slurp-perl_9999.19.bb
new file mode 100644
index 0000000..142a2f7
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-perl/libfile-slurp/libfile-slurp-perl_9999.19.bb
@@ -0,0 +1,15 @@
1DESCRIPTION = "Slurp entire files into variables."
2SECTION = "libs"
3LICENSE = "Artistic-1.0 | GPL-1.0+"
4
5LIC_FILES_CHKSUM = "file://README;beginline=37;endline=41;md5=255fbd5f98a90d51d9908d31271ae4d4"
6SRC_URI = "http://search.cpan.org/CPAN/authors/id/U/UR/URI/File-Slurp-9999.19.tar.gz"
7
8S = "${WORKDIR}/File-Slurp-${PV}"
9
10inherit cpan
11BBCLASSEXTEND="native"
12PACKAGE_ARCH = "all"
13
14SRC_URI[md5sum] = "7d584cd15c4f8b9547765eff8c4ef078"
15SRC_URI[sha256sum] = "ce29ebe995097ebd6e9bc03284714cdfa0c46dc94f6b14a56980747ea3253643"
diff --git a/meta-efi-secure-boot/recipes-support/efivar/efivar/Remove-use-of-deprecated-readdir_r.patch b/meta-efi-secure-boot/recipes-support/efivar/efivar/Remove-use-of-deprecated-readdir_r.patch
new file mode 100644
index 0000000..af58c22
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-support/efivar/efivar/Remove-use-of-deprecated-readdir_r.patch
@@ -0,0 +1,44 @@
1From 7078852e4a89f5ba27e7a70bc69641e01a6bff7a Mon Sep 17 00:00:00 2001
2From: Yunguo Wei <yunguo.wei@windriver.com>
3Date: Thu, 19 Jan 2017 15:11:25 +0800
4Subject: [PATCH] Remove use of deprecated readdir_r
5
6Backport 1dc6d576fa4(Remove use of deprecated readdir_r) from
7https://github.com/rhinstaller/efivar.git
8
9Signed-off-by: Yunguo Wei <yunguo.wei@windriver.com>
10---
11 src/vars.c | 12 ++++--------
12 1 file changed, 4 insertions(+), 8 deletions(-)
13
14diff --git a/src/vars.c b/src/vars.c
15index 2a276de..ec0d6bf 100644
16--- a/src/vars.c
17+++ b/src/vars.c
18@@ -126,19 +126,15 @@ is_64bit(void)
19 if (dfd < 0)
20 goto err;
21
22- struct dirent entry;
23- struct dirent *result = NULL;
24 while (1) {
25- int rc = readdir_r(dir, &entry, &result);
26- if (rc != 0)
27- break;
28- if (result == NULL)
29+ struct dirent *entry = readdir(dir);
30+ if (entry == NULL)
31 break;
32
33- if (!strcmp(entry.d_name, "..") || !strcmp(entry.d_name, "."))
34+ if (!strcmp(entry->d_name, "..") || !strcmp(entry->d_name, "."))
35 continue;
36
37- ssize_t size = get_file_data_size(dfd, entry.d_name);
38+ ssize_t size = get_file_data_size(dfd, entry->d_name);
39 if (size < 0) {
40 continue;
41 } else if (size == 2084) {
42--
432.7.4
44
diff --git a/meta-efi-secure-boot/recipes-support/efivar/efivar_0.24.bbappend b/meta-efi-secure-boot/recipes-support/efivar/efivar_0.24.bbappend
new file mode 100644
index 0000000..6d415bb
--- /dev/null
+++ b/meta-efi-secure-boot/recipes-support/efivar/efivar_0.24.bbappend
@@ -0,0 +1,13 @@
1FILESEXTRAPATHS_prepend := "${THISDIR}/efivar:"
2
3SRC_URI += "\
4 file://Remove-use-of-deprecated-readdir_r.patch \
5"
6
7# In dp.h, 'for' loop initial declarations are used
8CFLAGS_append = " -std=gnu99"
9
10# In order to install headers and libraries to sysroot
11do_install_append() {
12 oe_runmake DESTDIR=${D} install
13}
diff --git a/meta-encrypted-storage/README.md b/meta-encrypted-storage/README.md
new file mode 100644
index 0000000..989c8be
--- /dev/null
+++ b/meta-encrypted-storage/README.md
@@ -0,0 +1,179 @@
1### Storage Encryption
2This feature provides secure storage for application data. Some applications
3need secure storage for sensitive data which must not be accessible to another
4device. For example, only an application with the right signature can update
5the data on an encrypted SD card. If you move that SD card to another device,
6the data cannot be either read or updated. One application of this capability
7is a POS application. The application keeps tax information in secure storage
8that cannot be modified by another device.
9
10This feature gives 2 types of granularity for storage encryption. Data volume
11encryption allows the user to create encryption partition with a passphrase
12typed by the end user. Root filesystem encryption enables the data encryption
13on the entire rootfs except the boot partition.
14
15Both types of storage encryption are based on device-mapper crypt target,
16which provides transparent encryption of block devices using the kernel crypto
17API. Additionally, the utility cryptsetup is used to conveniently set up disk
18encryption, aka LUKS partition, based on device-mapper crypt target.
19
20Due to the use of TPM state to seal the passphrase used to encrypt the storage,
21the encrypted storage cannot be accessed on another machine, preventing from
22the so-called offline attack.
23
24### Dependency
25This feature depends on meta-tpm2.
26
27Note:
28Even though the hardware doesn't have a TPM 2.0 device, this feature can still
29run on it, although without the guarantee of compromise detection.
30
31### Limit
32- TPM 2.0 is validated and officially supported. But TPM 1.2 device is not
33 supported by this feature.
34
35### Data Volume Encryption
36#### Use case 1: manual operation
37##### Create the LUKS partition
38```
39# cryptsetup --type luks --cipher aes-xts-plain --hash sha256 \
40 --use-random luksFormat /dev/$dev
41```
42where $dev is the device node of the partition to be encrypted.
43
44This command initializes a LUKS partition and prompts to input an initial
45passphrase used to encrypt the data. Don't disclose the passphrase used for
46product.
47
48##### Open the LUKS partition
49```
50# cryptsetup luksOpen /dev/$dev $name
51```
52This command opens the LUKS device $dev and sets up a mapping $name after
53successful verification of the supplied passphrase typed interactively. From
54now on, the data written to /dev/mapper/$name is encrypted and the data
55read back from /dev/mapper/$name is decrypted transparently and automatically.
56
57##### Create the filesystem on top of the LUKS partition
58The user can run any available filesytem formatting program on
59/dev/mapper/$name to create the filesytem with the data encryption.
60
61##### Close the LUKS partition
62```
63# cryptsetup luksClose $name
64```
65This command removes the existing mapping $name and wipes the key from kernel
66memory.
67
68To access the encryped partition, follow the instruction "Open the LUKS partition"
69and then manually mount /dev/mapper/$name to a mount point.
70
71#### Use case 2: luks-setup.sh
72This script provides a semi automatic method to set up LUKS partition. The user
73still needs to manually create the filesystem on top of the newly created LUKS
74partition.
75
76##### LUKS partition creation
77In runtime, for example, create LUKS partition on /dev/sdb1 with the
78name "my_luks_part":
79```
80# luks-setup.sh -d /dev/sdb1 -n my_luks_name -e
81```
82Note: if TPM is detected, the passphrase will be generated automatically.
83
84For more uses about luks-setup.sh, run it with -h option.
85
86##### Retrieve the passphrase
87```
88# cryptfs-tpm2 -q unseal passphrase -P sha1 -o /tmp/passphrase
89```
90This command will unseal the passphrase from TPM device and save the content
91of passphrase to the file /tmp/passphrase.
92
93The passphrase should not be disclosed and needs to be backed up to a off-line
94storage.
95
96##### Open the LUKS partition
97```
98# cryptsetup luksOpen --key-file /tmp/passphrase /dev/$dev $name
99```
100##### Mount the LUKS partition
101```
102# mount /dev/mapper/$name $mount_point
103```
104The remaining operations are left to the user. Don't forget to close the LUKS
105partition if not used.
106
107Note:
108If TPM device exists in the system, the passphrase will be bound to PCR 7,
109gating the unseal operation. If the value of PCR 7 when unsealing the
110passphrase doesn't match up the value when creating the passphrase, the
111passphrase cannot be unsealed. The value of PCR 7 is usually affected by the
112status of UEFI secure boot.
113
114### Root Filesystem Encryption
115This enables the data encryption on the rootfs without the need of a human
116entering an user passphrase. Therefore, it is required to employ an initramfs
117where the unique identity from the platform is collected from the devices on
118the platform and used to unlock the root filesystem encryption. Meanwhile, use
119TPM to protect the user passphrase for volume decryption to avoid disclosing
120the user passphrase. If the TPM device is not detected, the end user will be
121prompted to type the user passphrase.
122
123#### Operations
124Note:
125The instructions below with the prefix "[TPM]" indicate the operation
126requires TPM device. Oppositely, the prefix "[Non-TPM]" indicates this
127operation is required if the target board doesn't have a TPM device.
128
129- Ensure a hard drive is attached on target board
130 WARNNING: the following instructions will wipe all data in the hard drive.
131
132- Create overc installer on a USB device
133 Refer to layers/meta-overc/README.install for the details about how to
134 run cubeit to install overc installer to a USB device.
135
136- Attach the USB device to the board
137
138- Power on
139
140- [TPM] Clear TPM
141 Refer to meta-tpm2/README.md for the details.
142
143- Boot to Linux
144
145- Install overc runtime on the hard drive
146 Refer to layers/meta-overc/README.install for the details about how to
147 run cubeit-installer to install overc runtime to a hard drive. In
148 addition, beware of specifying "--encrypt" option to set up an
149 encrypted rootfs.
150
151- Reboot
152 After reboot to initramfs, it employs a init script to transparently
153 unseal the passphrase and mount the rootfs without any interaction.
154
155### Best Practice
156- The benefit of anchoring the TPM is that the machine status cannot be
157 compromised by any attack. If compromised, the system cannot boot up
158 due to the failure when mouting the rootfs, or access the encrypted partition
159 when mounting the LUKS partition. This is caused by the fact that the content
160 of PCR 7 is different with the value when creating the encrypted storage.
161 Usually, the content of PCR 7 is calculated based on the status of UEFI
162 secure boot.
163
164 Based on the above conclusion, it is recommended to provision UEFI secure
165 boot and turn on it prior to setting up the encrypted storage.
166
167- The non-default seal secret is supported to provide extra protection, and it
168 is user configurable. Modify the values of CRYPTFS_TPM2_PRIMARY_KEY_SECRET
169 and CRYPTFS_TPM2_PASSPHRASE_SECRET in cryptfs-tpm2 with your preference.
170
171### Known Issues
172- The default IMA rules provides the ability of measuring the boot components
173 and calculating the aggregate integrity value for attesting. However, this
174 function conflicts with this feature which employs PCR policy session to
175 retrieve the passphrase in a safe way. If the installer enables both of
176 them, the default IMA rules will be not used.
177
178### Reference
179- [OpenEmbedded layer for TPM 2.0 enablement](https://github.com/jiazhang0/meta-tpm2)
diff --git a/meta-encrypted-storage/conf/layer.conf b/meta-encrypted-storage/conf/layer.conf
new file mode 100644
index 0000000..b24954c
--- /dev/null
+++ b/meta-encrypted-storage/conf/layer.conf
@@ -0,0 +1,15 @@
1# We have a conf and classes directory, add to BBPATH
2BBPATH .= ":${LAYERDIR}"
3
4# We have recipes-* directories, add to BBFILES
5BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
6 ${LAYERDIR}/recipes-*/*/*.bbappend"
7
8BBFILE_COLLECTIONS += "encrypted-storage"
9BBFILE_PATTERN_encrypted-storage = "^${LAYERDIR}/"
10BBFILE_PRIORITY_encrypted-storage = "10"
11
12LAYERDEPENDS_encrypted-storage = "\
13 core \
14 tpm2 \
15"
diff --git a/meta-encrypted-storage/recipes-base/packagegroups/packagegroup-encrypted-storage-initramfs.bb b/meta-encrypted-storage/recipes-base/packagegroups/packagegroup-encrypted-storage-initramfs.bb
new file mode 100644
index 0000000..88e8f7f
--- /dev/null
+++ b/meta-encrypted-storage/recipes-base/packagegroups/packagegroup-encrypted-storage-initramfs.bb
@@ -0,0 +1,8 @@
1include packagegroup-encrypted-storage.inc
2
3DESCRIPTION = "The packages used for encrypted storage in initramfs."
4
5RDEPENDS_${PN} += " \
6 cryptfs-tpm2-initramfs \
7 packagegroup-tpm2-initramfs \
8"
diff --git a/meta-encrypted-storage/recipes-base/packagegroups/packagegroup-encrypted-storage.bb b/meta-encrypted-storage/recipes-base/packagegroups/packagegroup-encrypted-storage.bb
new file mode 100644
index 0000000..225eb6a
--- /dev/null
+++ b/meta-encrypted-storage/recipes-base/packagegroups/packagegroup-encrypted-storage.bb
@@ -0,0 +1,14 @@
1include packagegroup-encrypted-storage.inc
2
3DESCRIPTION = "The packages used for encrypted storage."
4
5# Install the minimal stuffs only for the linux rootfs.
6# The common packages shared between initramfs and rootfs
7# are listed in the .inc.
8# @util-linux: fdisk
9# @parted: parted
10RDEPENDS_${PN} += " \
11 util-linux-fdisk \
12 parted \
13 packagegroup-tpm2 \
14"
diff --git a/meta-encrypted-storage/recipes-base/packagegroups/packagegroup-encrypted-storage.inc b/meta-encrypted-storage/recipes-base/packagegroups/packagegroup-encrypted-storage.inc
new file mode 100644
index 0000000..ab4b778
--- /dev/null
+++ b/meta-encrypted-storage/recipes-base/packagegroups/packagegroup-encrypted-storage.inc
@@ -0,0 +1,25 @@
1LICENSE = "MIT"
2LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \
3 file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
4
5ALLOW_EMPTY_${PN} = "1"
6
7S = "${WORKDIR}"
8
9# Install the minimal stuffs for the common uses between initramfs
10# and linux rootfs.
11# @util-linux: mount, umount
12# @cryptsetup: cryptsetup
13# @cryptfs-tpm: tpm_gen_dmcrypt_key, tpm_unwrap_dmcrypt_key
14# @kmod: modprobe
15# @coreutils: cat, mkdir, mknod, cp, rm
16# @trousers: tcsd
17RDEPENDS_${PN} = " \
18 util-linux-mount \
19 util-linux-umount \
20 cryptsetup \
21 kmod \
22 coreutils \
23 cryptfs-tpm2 \
24 procps \
25"
diff --git a/meta-encrypted-storage/recipes-kernel/linux/linux-yocto-encrypted-storage.inc b/meta-encrypted-storage/recipes-kernel/linux/linux-yocto-encrypted-storage.inc
new file mode 100644
index 0000000..198c972
--- /dev/null
+++ b/meta-encrypted-storage/recipes-kernel/linux/linux-yocto-encrypted-storage.inc
@@ -0,0 +1,6 @@
1FILESEXTRAPATHS_prepend := "${THISDIR}/linux-yocto:"
2
3SRC_URI += " \
4 ${@bb.utils.contains('DISTRO_FEATURES', 'encrypted-storage', \
5 'file://dmcrypt.scc file://dmcrypt.cfg', '', d)} \
6"
diff --git a/meta-encrypted-storage/recipes-kernel/linux/linux-yocto-rt_%.bbappend b/meta-encrypted-storage/recipes-kernel/linux/linux-yocto-rt_%.bbappend
new file mode 100644
index 0000000..fc85431
--- /dev/null
+++ b/meta-encrypted-storage/recipes-kernel/linux/linux-yocto-rt_%.bbappend
@@ -0,0 +1 @@
include linux-yocto-encrypted-storage.inc
diff --git a/meta-encrypted-storage/recipes-kernel/linux/linux-yocto/dmcrypt.cfg b/meta-encrypted-storage/recipes-kernel/linux/linux-yocto/dmcrypt.cfg
new file mode 100644
index 0000000..cedfcea
--- /dev/null
+++ b/meta-encrypted-storage/recipes-kernel/linux/linux-yocto/dmcrypt.cfg
@@ -0,0 +1,11 @@
1# Enable device-mapper crypt target
2CONFIG_DM_CRYPT=y
3
4# Enable the default cipher-spec for LUKS
5CONFIG_CRYPTO_AES=y
6CONFIG_CRYPTO_AES_NI_INTEL=y
7CONFIG_CRYPTO_XTS=y
8
9# Use entropy-strong source for RNG
10CONFIG_HW_RANDOM=y
11CONFIG_HW_RANDOM_TPM=m
diff --git a/meta-encrypted-storage/recipes-kernel/linux/linux-yocto/dmcrypt.scc b/meta-encrypted-storage/recipes-kernel/linux/linux-yocto/dmcrypt.scc
new file mode 100644
index 0000000..c549edd
--- /dev/null
+++ b/meta-encrypted-storage/recipes-kernel/linux/linux-yocto/dmcrypt.scc
@@ -0,0 +1 @@
kconf non-hardware dmcrypt.cfg
diff --git a/meta-encrypted-storage/recipes-kernel/linux/linux-yocto_%.bbappend b/meta-encrypted-storage/recipes-kernel/linux/linux-yocto_%.bbappend
new file mode 100644
index 0000000..fc85431
--- /dev/null
+++ b/meta-encrypted-storage/recipes-kernel/linux/linux-yocto_%.bbappend
@@ -0,0 +1 @@
include linux-yocto-encrypted-storage.inc
diff --git a/meta-encrypted-storage/recipes-tpm/cryptfs-tpm2/cryptfs-tpm2_git.bb b/meta-encrypted-storage/recipes-tpm/cryptfs-tpm2/cryptfs-tpm2_git.bb
new file mode 100644
index 0000000..2ad7ed1
--- /dev/null
+++ b/meta-encrypted-storage/recipes-tpm/cryptfs-tpm2/cryptfs-tpm2_git.bb
@@ -0,0 +1,55 @@
1SUMMARY = "A tool used to create, persist, evict a passphrase \
2for full-disk-encryption with TPM 2.0"
3DESCRIPTION = " \
4This project provides with an implementation for \
5creating, persisting and evicting a passphrase with TPM 2.0. \
6The passphrase and its associated primary key are automatically \
7created by RNG engine in TPM. In order to avoid saving the \
8context file, the created passphrase and primary key are always \
9persistent in TPM. \
10"
11SECTION = "devel"
12LICENSE = "BSD-3-Clause"
13LIC_FILES_CHKSUM = "file://${S}/LICENSE;md5=89c8ce1346a3dfe75379e84f3ba9d641"
14
15SRC_URI = " \
16 git://github.com/WindRiver-OpenSourceLabs/cryptfs-tpm2.git \
17"
18SRCREV = "32b49092d54b3d59c482d77d5eb1e36993912e89"
19PV = "0.6.0+git${SRCPV}"
20
21DEPENDS += "tpm2.0-tss tpm2-abrmd pkgconfig-native"
22RDEPENDS_${PN} += "libtss2 libtctidevice libtctisocket"
23
24PACKAGES =+ " \
25 ${PN}-initramfs \
26"
27
28PARALLEL_MAKE = ""
29
30S = "${WORKDIR}/git"
31
32EXTRA_OEMAKE = " \
33 sbindir="${sbindir}" \
34 libdir="${libdir}" \
35 includedir="${includedir}" \
36 tpm2_tss_includedir="${STAGING_INCDIR}/sapi" \
37 tpm2_tss_libdir="${STAGING_LIBDIR}" \
38 tpm2_tabrmd_includedir="${STAGING_INCDIR}" \
39 CC="${CC}" \
40 PKG_CONFIG="${STAGING_BINDIR_NATIVE}/pkg-config" \
41 EXTRA_CFLAGS="${CFLAGS}" \
42 EXTRA_LDFLAGS="${LDFLAGS}" \
43"
44
45do_install() {
46 oe_runmake install DESTDIR="${D}"
47
48 if [ x"${@bb.utils.contains('DISTRO_FEATURES', 'encrypted-storage', '1', '0', d)}" = x"1" ]; then
49 install -m 0500 ${S}/script/init.cryptfs ${D}
50 fi
51}
52
53FILES_${PN}-initramfs = "\
54 /init.cryptfs \
55"
diff --git a/meta-integrity/COPYING.MIT b/meta-integrity/COPYING.MIT
new file mode 100644
index 0000000..fb950dc
--- /dev/null
+++ b/meta-integrity/COPYING.MIT
@@ -0,0 +1,17 @@
1Permission is hereby granted, free of charge, to any person obtaining a copy
2of this software and associated documentation files (the "Software"), to deal
3in the Software without restriction, including without limitation the rights
4to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5copies of the Software, and to permit persons to whom the Software is
6furnished to do so, subject to the following conditions:
7
8The above copyright notice and this permission notice shall be included in
9all copies or substantial portions of the Software.
10
11THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
17THE SOFTWARE.
diff --git a/meta-integrity/README.md b/meta-integrity/README.md
new file mode 100644
index 0000000..2efb494
--- /dev/null
+++ b/meta-integrity/README.md
@@ -0,0 +1,166 @@
1### meta-integrity
2OpenEmbedded layer for Linux integrity support
3
4#### Integrity Measurement Architecture (IMA)
5The Linux IMA subsystem introduces hooks within the Linux kernel to support
6measuring the integrity of files that are loaded (including application code)
7before it is executed or mmap()ed to memory. The measured value (hash) is then
8registered in a log that can be consulted by administrators.
9
10To support proven integrity of the files, the IMA subsystem can interact with
11the TPM chip within the system to protect the registered hashes from tampering
12by a rogue administrator or application. The IMA subsystem, as already
13supported by the Linux kernel, supports reporting on the hashes of files and
14commands ran by privileged accounts (and more if you create your own
15measurement policies).
16
17In addition, IMA appraisal can even register the measured value as an extended
18attribute, and after subsequent measurement(s) validate this extended attribute
19against the measured value and refuse to load the file (or execute the
20application) if the hash does not match. In that case, the IMA subsystem allows
21files and applications to be loaded if the hashes match (and will save the
22updated hash if the file is modified) but refuse to load it if it doesn't. This
23provides some protection against offline tampering of the files.
24
25NOTE: Extended file system attribute is required for IMA appraisal, but not
26all file systems can support it. Typically, the pseudo file systems, such as
27sysfs, proc, tmpfs and ramfs, certain disk-based file systems, such as FAT,
28and network file systems, such as NFS, don't support extended attribute,
29meaning IMA appraisal is not available with them.
30
31##### Dependency
32- meta-tpm
33 This layer provides the kernel configurations for TPM 1.x enablement.
34
35- meta-tpm2
36 This layer provides the kernel configurations for TPM 2.0 enablement.
37
38##### Use The External IMA Policy
39initramfs is a good place to run some IMA initializations, such as loading
40the IMA policy, as well as the public keys used to verify IMA signatures.
41
42###### The default external IMA policy
43The default external IMA policy enforces appraising all the executable, shared
44library, kernel modules and firmwares with the digital signature in the
45effective root identity (euid=0). Hence, the opportunity of loading the default
46external IMA policy occurs at the end of initramfs initializations, just before
47switch_root.
48
49Instead of running switch_root directly from initramfs, a statically linked
50switch_root from the real rootfs is called and it must be already signed
51properly. Otherwise, switch_root will fail to mount the real rootfs and kernel
52panic will happen due to this failure.
53
54The default external IMA policy is located at `/etc/ima_policy.default` in
55initramfs. If a custom external IMA policy file exists, the default external
56IMA policy file won't be used any more.
57
58The default external IMA policy enables the following constraint conditions:
59- Appraise the files for exec'd (the executables), files mmap'd for exec
60 (shared libraries), kernel modules and firmwares in effective root identity
61 (euid=0).
62- Enforce verifying the IMA signature when running the executables, shared
63 libraries, kernel modules and firmwares.
64- Deny to run the newly created executables, shared libraries, kernel modules
65 and firmwares.
66- Deny to run the tampered executables, shared libraries, kernel modules and
67 firmwares.
68- Deny to run any executables, shared libraries, kernel modules and firmwares
69 in the filesystems without file extended attribute supported.
70- Allow to run the manually signed executables, shared libraries, kernel
71 modules and firmwares.
72- Allow to run the updated executables, shared libraries, kernel modules and
73 firmwares during RPM installation.
74- Note the different behaviors when executing a script.
75 e.g, launching a python script with "./test.py" is allowed only when test.py
76 is signed, and launching a python script with "python test.py" is always
77 allowed as long as the python interpreter is signed.
78
79###### The custom external IMA policy
80If the default external IMA policy cannot meet the protection requirement, it
81is allowed to define the custom external IMA policy.
82
83- Deploy the custom policy file to installer image
84
85- Create `/opt/installer/sbin/config-installer.sh` in installer image
86 Define the IMA_POLICY variable, pointing to the path of policy file.
87
88The custom external IMA policy file is eventually installed to `/etc/ima_policy`
89in initramfs.
90
91##### IMA certificate & private Key
92The private key come in two flavors; one used by an installer to sign all
93regular files in rootfs and one used by RPM to re-sign the executable, shared
94library, kernel module and firmware during RPM installation. Correspondingly,
95the IMA certificate is used to verify the IMA signature signed by the private
96key.
97
98In addition, initramfs is a good place to import the IMA certificate likewise.
99
100###### The default IMA certificate & private key
101The default IMA certificate & private key are generated by the build system. By
102default, the sample keys are used for the purpose of development and
103demonstration. Please ensure you know what your risk is to use the sample keys
104in your product, because they are completely public.
105
106### Best practice
107The following best practices should be applied with using IMA.
108
109- Enable UEFI/MOK secure boot
110 UEFI/MOK secure boot can verify the integrity of initramfs, providing the
111 protection against tampering of the external IMA policy files and IMA public
112 keys stored in initramfs.
113
114- Moderate measuring
115 Measuring the files owned by non-root user may introduce malicious attack.
116 Malicious user may create lots of files with different names or trigger
117 violation conditions to generate a mass of event logs recorded in the runtime
118 measurement list, and thus exhaust the persistent kernel memory.
119
120- Performance influence
121 Moderate policy can make a good balance between the performance and security.
122 Tune the default external policy (`/etc/ima_policy.default`) and modulate the
123 custom policy for the product requirement.
124
125- Use IMA digital signature to protect the executable
126 Using the digital signature scheme DIGSIG is safer than digest-based scheme.
127 Meanwhile, use `appraise_type=imasig` in your IMA policy to enforce running
128 this.
129
130- Use the measurement and audit rules together
131 The runtime measurement list is unable to track down the order of changes for
132 a file, e.g, a file content varies in order of X -> Y -> X. However, audit log
133 can record these changes in the right order.
134
135##### Known Issues
136- The following operations may break the behavior of appraisal and cause the
137 failure of launching the executables, shared libraries, kernel modules and
138 firmwares:
139 - the syscalls used to set file last access and modification times.
140 - the syscalls used to set ownership of a file.
141 - the syscalls used to set permissions of a file.
142
143 To fix the failure, manually re-sign the affected file.
144
145 Note: RPM installation violates the IMA appraisal but its post_install
146 operation will always re-sign the affected files.
147
148- Overwriting an existing file with the same content is deemed as tampering of
149 the file.
150
151- The default IMA rules provides the ability of measuring the boot components
152 and calculating the aggregate integrity value for attesting. However, this
153 function conflicts with encrypted-storage feature which employs PCR policy
154 session to retrieve the passphrase in a safe way. If the installer enables
155 both of them, the default IMA rules will be not used.
156
157### Reference
158[IMA wiki page](https://sourceforge.net/p/linux-ima/wiki/Home/)
159
160[OpenEmbedded layer for EFI Secure Boot](https://github.com/jiazhang0/meta-efi-secure-boot)
161
162[OpenEmbedded layer for signing key management](https://github.com/jiazhang0/meta-signing-key)
163
164[OpenEmbedded layer for TPM 1.x](https://github.com/jiazhang0/meta-tpm)
165
166[OpenEmbedded layer for TPM 2.0](https://github.com/jiazhang0/meta-tpm2)
diff --git a/meta-integrity/classes/rpm5-ima.bbclass b/meta-integrity/classes/rpm5-ima.bbclass
new file mode 100644
index 0000000..fbdefeb
--- /dev/null
+++ b/meta-integrity/classes/rpm5-ima.bbclass
@@ -0,0 +1,156 @@
1inherit package
2
3PACKAGEFUNCS =+ "package_ima_hook"
4
5# security.ima is generated during the RPM build, and the base64-encoded
6# value is written during RPM installation. In addition, if the private
7# key is deployed on board, re-sign the updated files during RPM
8# installation in higher priority.
9python package_ima_hook() {
10 packages = d.getVar('PACKAGES', True)
11 pkgdest = d.getVar('PKGDEST', True)
12 ima_signing_blacklist = d.getVar('IMA_SIGNING_BLACKLIST', True)
13 ima_keys_dir = d.getVar('IMA_KEYS_DIR', True)
14
15 pkg_suffix_blacklist = ('dbg', 'dev', 'doc', 'locale', 'staticdev')
16
17 pkg_blacklist = ()
18 with open(ima_signing_blacklist, 'r') as f:
19 pkg_blacklist = [ _.strip() for _ in f.readlines() ]
20 pkg_blacklist = tuple(pkg_blacklist)
21
22 import base64, pipes, stat
23
24 for pkg in packages.split():
25 if (pkg.split('-')[-1] in pkg_suffix_blacklist) is True:
26 continue
27
28 if pkg.startswith(pkg_blacklist) is True:
29 continue
30
31 bb.note("Writing IMA %%post hook for %s ..." % pkg)
32
33 pkgdestpkg = os.path.join(pkgdest, pkg)
34
35 cmd = 'evmctl ima_sign --hashalgo sha256 -n --sigfile --key %s/x509_ima.key ' % (ima_keys_dir)
36 sig_list = []
37 pkg_sig_list = []
38
39 for _ in pkgfiles[pkg]:
40 # Ignore the symbol links.
41 if os.path.islink(_):
42 continue
43
44 # IMA appraisal is only applied to the regular file.
45 if not stat.S_ISREG(os.stat(_)[stat.ST_MODE]):
46 continue
47
48 bb.note("Preparing to sign %s ..." % _)
49
50 sh_name = pipes.quote(_)
51 print("Signing command: %s" % cmd + sh_name)
52 rc, res = oe.utils.getstatusoutput(cmd + sh_name + " >/dev/null")
53 if rc:
54 bb.fatal('Calculate IMA signature for %s failed with exit code %s:\n%s' % \
55 (_, rc, res if res else ""))
56
57 with open(_ + '.sig', 'rb') as f:
58 s = str(base64.b64encode(f.read()).decode('ascii')) + '|'
59 sig_list.append(s + os.sep + os.path.relpath(_, pkgdestpkg))
60
61 os.remove(_ + '.sig')
62
63 ima_sig_list = '&'.join(sig_list)
64
65 # When the statically linked binary is updated, use the
66 # dynamically linked one to resign or set. This situation
67 # occurs in runtime only.
68 setfattr_bin = 'setfattr.static'
69 evmctl_bin = 'evmctl.static'
70 # We don't want to create a statically linked echo program
71 # any more.
72 safe_echo = '1'
73 if pkg == 'attr-setfattr.static':
74 setfattr_bin = 'setfattr'
75 elif pkg == 'ima-evm-utils-evmctl.static':
76 evmctl_bin = 'evmctil'
77 elif pkg == 'coreutils':
78 safe_echo = '0'
79
80 # The %post is dynamically constructed according to the currently
81 # installed package and enviroment.
82 postinst = r'''#!/bin/sh
83
84# %post hook for IMA appraisal
85ima_resign=0
86sig_list="''' + ima_sig_list + r'''"
87
88if [ -z "$D" ]; then
89 evmctl_bin="${sbindir}/''' + evmctl_bin + r'''"
90 setfattr_bin="${bindir}/''' + setfattr_bin + r'''"
91
92 [ -f "/etc/keys/privkey_evm.pem" -a -x "$evmctl_bin" ] && \
93 ima_resign=1
94
95 safe_echo="''' + safe_echo + r'''"
96
97 cond_print()
98 {
99 [ $safe_echo = "1" ] && echo $1
100 }
101
102 saved_IFS="$IFS"
103 IFS="&"
104 for entry in $sig_list; do
105 IFS="|"
106
107 tokens=""
108 for token in $entry; do
109 tokens="$tokens$token|"
110 done
111
112 for sig in $tokens; do
113 break
114 done
115
116 IFS="$saved_IFS"
117
118 f="$token"
119
120 # If the filesystem doesn't support xattr, skip the following steps.
121 res=`"$setfattr_bin" -x security.ima "$f" 2>&1 | grep "Operation not supported$"`
122 [ x"$res" != x"" ] && {
123 cond_print "Current file system doesn't support to set xattr"
124 break
125 }
126
127 if [ $ima_resign -eq 0 ]; then
128 cond_print "Setting up security.ima for $f ..."
129
130 "$setfattr_bin" -n security.ima -v "0s$sig" "$f" || {
131 err=$?
132 cond_print "Unable to set up security.ima for $f (err: $err)"
133 exit 1
134 }
135 else
136 cond_print "IMA signing for $f ..."
137
138 "$evmctl_bin" ima_sign --hashalgo sha256 "$f" || {
139 err=$?
140 cond_print "Unable to sign $f (err: $err)"
141 exit 1
142 }
143 fi
144
145 IFS="&"
146 done
147
148 IFS="$saved_IFS"
149fi
150
151'''
152 postinst = postinst + (d.getVar('pkg_postinst_%s' % pkg, True) or '')
153 d.setVar('pkg_postinst_%s' % pkg, postinst)
154}
155
156do_package[depends] += "ima-evm-utils-native:do_populate_sysroot"
diff --git a/meta-integrity/conf/layer.conf b/meta-integrity/conf/layer.conf
new file mode 100644
index 0000000..f3c00e0
--- /dev/null
+++ b/meta-integrity/conf/layer.conf
@@ -0,0 +1,19 @@
1# We have a conf and classes directory, add to BBPATH
2BBPATH .= ":${LAYERDIR}"
3
4# We have recipes-* directories, add to BBFILES
5BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
6 ${LAYERDIR}/recipes-*/*/*.bbappend"
7
8BBFILE_COLLECTIONS += "integrity"
9BBFILE_PATTERN_integrity = "^${LAYERDIR}/"
10BBFILE_PRIORITY_integrity = "10"
11
12IMA_SIGNING_BLACKLIST ??= "${LAYERDIR}/files/ima_signing_blacklist"
13
14LAYERDEPENDS_integrity = "\
15 core \
16 signing-key \
17 tpm2 \
18 tpm \
19"
diff --git a/meta-integrity/files/ima_signing_blacklist b/meta-integrity/files/ima_signing_blacklist
new file mode 100644
index 0000000..276a7bc
--- /dev/null
+++ b/meta-integrity/files/ima_signing_blacklist
@@ -0,0 +1 @@
kernel-devsrc
diff --git a/meta-integrity/recipes-base/packagegroups/packagegroup-ima-initramfs.bb b/meta-integrity/recipes-base/packagegroups/packagegroup-ima-initramfs.bb
new file mode 100644
index 0000000..89cb120
--- /dev/null
+++ b/meta-integrity/recipes-base/packagegroups/packagegroup-ima-initramfs.bb
@@ -0,0 +1,12 @@
1DESCRIPTION = "Linux Integrity Measurement Architecture (IMA) subsystem for initramfs"
2
3include packagegroup-ima.inc
4
5RDEPENDS_${PN} += " \
6 util-linux-mount \
7 util-linux-umount \
8 gawk \
9 ima-policy \
10 key-store-ima-cert \
11 initrdscripts-ima \
12"
diff --git a/meta-integrity/recipes-base/packagegroups/packagegroup-ima.bb b/meta-integrity/recipes-base/packagegroups/packagegroup-ima.bb
new file mode 100644
index 0000000..e10300e
--- /dev/null
+++ b/meta-integrity/recipes-base/packagegroups/packagegroup-ima.bb
@@ -0,0 +1,21 @@
1DESCRIPTION = "Linux Integrity Measurement Architecture (IMA) subsystem"
2
3include packagegroup-ima.inc
4
5DEPENDS += " \
6 ima-evm-utils-native \
7 attr-native \
8"
9
10RDEPENDS_${PN} += " \
11 attr \
12 util-linux-switch_root.static \
13 attr-setfattr.static \
14 ima-evm-utils-evmctl.static \
15"
16
17# Note any private key is not available if user key signing model used.
18RRECOMMENDS_${PN} += " \
19 key-store-ima-privkey \
20 key-store-system-trusted-privkey \
21"
diff --git a/meta-integrity/recipes-base/packagegroups/packagegroup-ima.inc b/meta-integrity/recipes-base/packagegroups/packagegroup-ima.inc
new file mode 100644
index 0000000..64829dc
--- /dev/null
+++ b/meta-integrity/recipes-base/packagegroups/packagegroup-ima.inc
@@ -0,0 +1,13 @@
1LICENSE = "MIT"
2LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \
3 file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
4
5S = "${WORKDIR}"
6
7ALLOW_EMPTY_${PN} = "1"
8
9RDEPENDS_${PN} = " \
10 ima-evm-utils \
11 coreutils \
12 grep \
13"
diff --git a/meta-integrity/recipes-core/base-files/base-files_%.bbappend b/meta-integrity/recipes-core/base-files/base-files_%.bbappend
new file mode 100644
index 0000000..2636dad
--- /dev/null
+++ b/meta-integrity/recipes-core/base-files/base-files_%.bbappend
@@ -0,0 +1,4 @@
1# Append iversion option for auto types
2do_install_append() {
3 sed -i 's/\s*auto\s*defaults/&,iversion/' ${D}${sysconfdir}/fstab
4}
diff --git a/meta-integrity/recipes-core/initrdscripts/files/init.ima b/meta-integrity/recipes-core/initrdscripts/files/init.ima
new file mode 100755
index 0000000..1e92ba2
--- /dev/null
+++ b/meta-integrity/recipes-core/initrdscripts/files/init.ima
@@ -0,0 +1,129 @@
1#!/bin/sh
2
3# Initramfs script for IMA initialzation
4#
5# This script is a halper used to load the external
6# IMA policy and public keys used to verify the IMA
7# signature.
8#
9# Copyright (c) 2017, Jia Zhang <lans.zhang2008@gmail.com>
10# All rights reserved.
11#
12# See "LICENSE" for license terms.
13
14# Exit code:
15# 0 - IMA initialiazation complete
16# 1 - Kernel doesn't support securityfs
17# 2 - Kernel doesn't support IMA
18# 3 - There is no public key to load
19# 4 - There is no IMA policy file defined
20# 5 - Unable to load IMA policy file
21
22# If root directory is not specified, the root of
23# initramfs assumed.
24ROOT_DIR="${1}"
25
26SECURITYFS_DIR="${ROOT_DIR}/sys/kernel/security"
27
28# The policy files are always placed in initramfs
29IMA_POLICY=/etc/ima_policy
30
31SECURITYFS_MOUNTED=0
32
33function print_critical
34{
35 printf "\033[1;35m"
36 echo "$@"
37 printf "\033[0m"
38}
39
40function print_error
41{
42 printf "\033[1;31m"
43 echo "$@"
44 printf "\033[0m"
45}
46
47function print_warning
48{
49 printf "\033[1;33m"
50 echo "$@"
51 printf "\033[0m"
52}
53
54function print_info
55{
56 printf "\033[1;32m"
57 echo "$@"
58 printf "\033[0m"
59}
60
61function print_verbose
62{
63 printf "\033[1;36m"
64 echo "$@"
65 printf "\033[0m"
66}
67
68function trap_handler
69{
70 local err=$?
71
72 print_verbose "Cleaning up with exit code $err ..."
73
74 [ $SECURITYFS_MOUNTED -eq 1 ] &&
75 umount "$SECURITYFS_DIR" 2>"${ROOT_DIR}/dev/null"
76}
77
78trap "trap_handler $?" SIGINT EXIT
79
80if grep -q "ima_appraise=off" "${ROOT_DIR}/proc/cmdline"; then
81 print_info "Skip to load the public key and IMA policy"
82 exit 0
83fi
84
85if ! grep -q securityfs "${ROOT_DIR}/proc/mounts"; then
86 ! mount -t securityfs none "$SECURITYFS_DIR" 2>"${ROOT_DIR}/dev/null" && {
87 print_error "Unable to mount securityfs filesystem"
88 exit 1
89 }
90 SECURITYFS_MOUNTED=1
91 securityfs_dir="$SECURITYFS_DIR"
92else
93 securityfs_dirs="$(grep securityfs ${ROOT_DIR}/proc/mounts | awk '{print $2}')"
94
95 # Use the first one.
96 for securityfs_dir in "$securityfs_dirs"; do
97 break
98 done
99fi
100
101[ ! -d "$securityfs_dir/ima" ] &&
102 print_info "IMA is not enabled. Exiting ..." && exit 2
103
104keyring_id=0x`grep '\skeyring\s*\.ima: ' "${ROOT_DIR}/proc/keys" | awk '{ print $1 }'`
105
106for key in ${ROOT_DIR}/etc/keys/x509_evm*.pem; do
107 [ ! -s "$key" ] && continue
108
109 if ! evmctl import "$key" "$keyring_id" >"${ROOT_DIR}/dev/null"; then
110 print_critical "Unable to load the public key $key for IMA appraisal"
111 else
112 print_verbose "The external public key $key loaded for IMA appraisal"
113 fi
114done
115
116# Attempt to load the default policy.
117[ ! -f "${IMA_POLICY}" ] && IMA_POLICY="${IMA_POLICY}.default"
118
119[ ! -f "${IMA_POLICY}" ] && {
120 print_warning "No IMA policy file defined"
121 exit 4
122}
123
124cat "${IMA_POLICY}" > "$securityfs_dir/ima/policy" && {
125 exit 0
126} || {
127 print_critical "Unable to load the IMA policy ${IMA_POLICY}"
128 exit 5
129}
diff --git a/meta-integrity/recipes-core/initrdscripts/initrdscripts-ima.bb b/meta-integrity/recipes-core/initrdscripts/initrdscripts-ima.bb
new file mode 100644
index 0000000..3860be2
--- /dev/null
+++ b/meta-integrity/recipes-core/initrdscripts/initrdscripts-ima.bb
@@ -0,0 +1,47 @@
1DESCRIPTION = "The initrd script for Linux Integrity Measurement Architecture (IMA)"
2LICENSE = "MIT"
3LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \
4 file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
5
6S = "${WORKDIR}"
7
8ALLOW_EMPTY_${PN} = "1"
9
10SRC_URI = "\
11 file://init.ima \
12"
13
14do_install() {
15 if [ x"${@bb.utils.contains('DISTRO_FEATURES', 'ima', '1', '0', d)}" = x"1" ]; then
16 install -m 0500 ${WORKDIR}/init.ima ${D}
17 fi
18}
19
20FILES_${PN} += " \
21 ${@bb.utils.contains('DISTRO_FEATURES', 'ima', '/init.ima', '', d)} \
22"
23
24# Install the minimal stuffs only, and don't care how the external
25# environment is configured.
26# @bash: sh
27# @coreutils: echo, mkdir, mknod, dirname, basename, cp, rm, sleep
28# seq, printf, cut
29# @grep: grep
30# @gawk: awk
31# @kmod: modprobe, depmod
32# @net-tools: ifconfig
33# @trousers: tcsd
34# @procps: pkill
35# @util-linux: blkid, mount, umount
36RDEPENDS_${PN} += "\
37 bash \
38 coreutils \
39 grep \
40 gawk \
41 kmod \
42 net-tools \
43 procps \
44 util-linux-blkid \
45 util-linux-mount \
46 util-linux-umount \
47"
diff --git a/meta-integrity/recipes-core/util-linux/util-linux_%.bbappend b/meta-integrity/recipes-core/util-linux/util-linux_%.bbappend
new file mode 100644
index 0000000..1728f2e
--- /dev/null
+++ b/meta-integrity/recipes-core/util-linux/util-linux_%.bbappend
@@ -0,0 +1,16 @@
1PACKAGES =+ "${PN}-switch_root.static"
2
3CFLAGS_remove += "-pie -fpie"
4
5do_compile_append_class-target() {
6 ${CC} ${CFLAGS} ${LDFLAGS} -static \
7 sys-utils/switch_root.o \
8 -o switch_root.static
9}
10
11do_install_append_class-target() {
12 install -d ${D}${sbindir}
13 install -m 0700 ${B}/switch_root.static ${D}${sbindir}/switch_root.static
14}
15
16FILES_${PN}-switch_root.static = "${sbindir}/switch_root.static"
diff --git a/meta-integrity/recipes-kernel/linux/linux-yocto-integrity.inc b/meta-integrity/recipes-kernel/linux/linux-yocto-integrity.inc
new file mode 100644
index 0000000..8c08a45
--- /dev/null
+++ b/meta-integrity/recipes-kernel/linux/linux-yocto-integrity.inc
@@ -0,0 +1,18 @@
1FILESEXTRAPATHS_prepend := "${THISDIR}/linux-yocto:"
2
3IMA_ENABLED = "${@bb.utils.contains('DISTRO_FEATURES', 'ima', '1', '0', d)}"
4
5DEPENDS += "${@'key-store openssl-native' if d.getVar('IMA_ENABLED', True) == '1' else ''}"
6# key-store-ima-cert is required in runtime but we hope it is available
7# in initramfs only. So we don't add it to RDEPENDS_${PN} here.
8
9SRC_URI += " \
10 ${@'file://ima.scc file://ima.cfg' if d.getVar('IMA_ENABLED', True) == '1' else ''} \
11"
12
13do_configure_append() {
14 [ -f "${STAGING_DIR_TARGET}${sysconfdir}/keys/system_trusted_key.pem" ] &&
15 openssl x509 -in "${STAGING_DIR_TARGET}${sysconfdir}/keys/system_trusted_key.pem" \
16 -outform DER -out "${B}/system_trusted_cert.x509" ||
17 true
18}
diff --git a/meta-integrity/recipes-kernel/linux/linux-yocto-rt_4.%.bbappend b/meta-integrity/recipes-kernel/linux/linux-yocto-rt_4.%.bbappend
new file mode 100644
index 0000000..685d15c
--- /dev/null
+++ b/meta-integrity/recipes-kernel/linux/linux-yocto-rt_4.%.bbappend
@@ -0,0 +1 @@
include linux-yocto-integrity.inc
diff --git a/meta-integrity/recipes-kernel/linux/linux-yocto/ima.cfg b/meta-integrity/recipes-kernel/linux/linux-yocto/ima.cfg
new file mode 100644
index 0000000..073197a
--- /dev/null
+++ b/meta-integrity/recipes-kernel/linux/linux-yocto/ima.cfg
@@ -0,0 +1,35 @@
1..........................................................................
2. WARNING
3.
4. This file is a kernel configuration fragment, and not a full kernel
5. configuration file. The final kernel configuration is made up of
6. an assembly of processed fragments, each of which is designed to
7. capture a specific part of the final configuration (e.g. platform
8. configuration, feature configuration, and board specific hardware
9. configuration). For more information on kernel configuration, please
10. consult the product documentation.
11.
12..........................................................................
13
14CONFIG_IMA=y
15CONFIG_IMA_MEASURE_PCR_IDX=10
16# CONFIG_IMA_TEMPLATE is not set
17# CONFIG_IMA_NG_TEMPLATE=y is not set
18CONFIG_IMA_SIG_TEMPLATE=y
19CONFIG_IMA_DEFAULT_TEMPLATE="ima-sig"
20# CONFIG_IMA_DEFAULT_HASH_SHA1 is not set
21CONFIG_IMA_DEFAULT_HASH_SHA256=y
22# CONFIG_IMA_DEFAULT_HASH_SHA512 is not set
23# CONFIG_IMA_DEFAULT_HASH_WP512 is not set
24CONFIG_IMA_DEFAULT_HASH="sha256"
25CONFIG_IMA_APPRAISE=y
26CONFIG_INTEGRITY_SIGNATURE=y
27CONFIG_INTEGRITY_ASYMMETRIC_KEYS=y
28CONFIG_INTEGRITY_TRUSTED_KEYRING=y
29CONFIG_SYSTEM_TRUSTED_KEYRING=y
30CONFIG_IMA_LOAD_X509=y
31CONFIG_IMA_TRUSTED_KEYRING=y
32CONFIG_IMA_X509_PATH="/etc/keys/x509_evm.der"
33# CONFIG_IMA_APPRAISE_SIGNED_INIT is not set
34CONFIG_AUDIT=y
35CONFIG_INTEGRITY_AUDIT=y
diff --git a/meta-integrity/recipes-kernel/linux/linux-yocto/ima.scc b/meta-integrity/recipes-kernel/linux/linux-yocto/ima.scc
new file mode 100644
index 0000000..c43e1c4
--- /dev/null
+++ b/meta-integrity/recipes-kernel/linux/linux-yocto/ima.scc
@@ -0,0 +1,4 @@
1define KFEATURE_DESCRIPTION "Integrity Measurement Architecture (IMA) enablement"
2define KFEATURE_COMPATIBILITY board
3
4kconf non-hardware ima.cfg
diff --git a/meta-integrity/recipes-kernel/linux/linux-yocto_4.%.bbappend b/meta-integrity/recipes-kernel/linux/linux-yocto_4.%.bbappend
new file mode 100644
index 0000000..685d15c
--- /dev/null
+++ b/meta-integrity/recipes-kernel/linux/linux-yocto_4.%.bbappend
@@ -0,0 +1 @@
include linux-yocto-integrity.inc
diff --git a/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils/0001-Don-t-build-man-pages.patch b/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils/0001-Don-t-build-man-pages.patch
new file mode 100644
index 0000000..db006c0
--- /dev/null
+++ b/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils/0001-Don-t-build-man-pages.patch
@@ -0,0 +1,27 @@
1From b5bc04d9062a69e116ed60ad540b56cd057d47d1 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Tue, 27 Dec 2016 14:25:58 +0800
4Subject: [PATCH] Don't build man pages
5
6Too many external tools are required to build the man pages. We don't
7need them anyway.
8
9Signed-off-by: George McCollister <george.mccollister@gmail.com>
10Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
11---
12 Makefile.am | 1 -
13 1 file changed, 1 deletion(-)
14
15diff --git a/Makefile.am b/Makefile.am
16index 06ebf59..e527f34 100644
17--- a/Makefile.am
18+++ b/Makefile.am
19@@ -1,5 +1,4 @@
20 SUBDIRS = src
21-dist_man_MANS = evmctl.1
22
23 doc_DATA = examples/ima-genkey-self.sh examples/ima-genkey.sh examples/ima-gen-local-ca.sh
24 EXTRA_DIST = autogen.sh $(doc_DATA)
25--
262.7.4
27
diff --git a/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils/0001-Install-evmctl-to-sbindir-rather-than-bindir.patch b/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils/0001-Install-evmctl-to-sbindir-rather-than-bindir.patch
new file mode 100644
index 0000000..545be42
--- /dev/null
+++ b/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils/0001-Install-evmctl-to-sbindir-rather-than-bindir.patch
@@ -0,0 +1,28 @@
1From 412f60bbd5a7ed1eac7051bd2947d5fc0c95e86b Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Thu, 12 Jan 2017 16:55:03 +0800
4Subject: [PATCH] Install evmctl to $sbindir rather than $bindir
5
6Setting security.ima requires sys_admin capability.
7
8Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
9---
10 src/Makefile.am | 2 +-
11 1 file changed, 1 insertion(+), 1 deletion(-)
12
13diff --git a/src/Makefile.am b/src/Makefile.am
14index deb18fb..aa8f666 100644
15--- a/src/Makefile.am
16+++ b/src/Makefile.am
17@@ -9,7 +9,7 @@ libimaevm_la_LIBADD = $(OPENSSL_LIBS)
18
19 include_HEADERS = imaevm.h
20
21-bin_PROGRAMS = evmctl
22+sbin_PROGRAMS = evmctl
23
24 evmctl_SOURCES = evmctl.c
25 evmctl_CPPFLAGS = $(OPENSSL_CFLAGS)
26--
272.7.4
28
diff --git a/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils_git.bb b/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils_git.bb
new file mode 100644
index 0000000..c1278a9
--- /dev/null
+++ b/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils_git.bb
@@ -0,0 +1,41 @@
1LICENSE = "GPLv2"
2LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263"
3
4SRC_URI = " \
5 git://git.code.sf.net/p/linux-ima/ima-evm-utils \
6 file://0001-Don-t-build-man-pages.patch \
7 file://0001-Install-evmctl-to-sbindir-rather-than-bindir.patch \
8"
9SRCREV = "3e2a67bdb0673581a97506262e62db098efef6d7"
10PV = "1.0+git${SRCPV}"
11
12S = "${WORKDIR}/git"
13
14PACKAGES =+ "${PN}-evmctl.static"
15
16DEPENDS += "openssl attr keyutils"
17RDEPENDS_${PN}_class-target += "libcrypto libattr keyutils"
18
19inherit pkgconfig autotools
20
21# Specify any options you want to pass to the configure script using EXTRA_OECONF:
22EXTRA_OECONF = ""
23
24CFLAGS_remove += "-pie -fpie"
25
26do_compile_append_class-target() {
27 ${CC} ${CFLAGS} ${LDFLAGS} -static \
28 -include config.h -L=${libdir} \
29 -Wl,--start-group -lcrypto -lkeyutils -ldl \
30 ${S}/src/evmctl.c ${S}/src/libimaevm.c \
31 -Wl,--end-group -o ${B}/src/evmctl.static
32}
33
34do_install_append_class-target() {
35 install -m 0700 ${B}/src/evmctl.static ${D}${sbindir}/evmctl.static
36}
37
38FILES_${PN}-dev += "${includedir}"
39FILES_${PN}-evmctl.static = "${sbindir}/evmctl.static"
40
41BBCLASSEXTEND = "native nativesdk"
diff --git a/meta-integrity/recipes-support/ima-policy/files/ima_policy.default b/meta-integrity/recipes-support/ima-policy/files/ima_policy.default
new file mode 100644
index 0000000..5d4ae47
--- /dev/null
+++ b/meta-integrity/recipes-support/ima-policy/files/ima_policy.default
@@ -0,0 +1,24 @@
1# The default external IMA policy
2
3# Don't appraise any file opened.
4# However, we cannot write down such a rule,
5# dont_appraise func=FILE_CHECK
6#
7# because this rule will accidently cause the security.ima
8# being deleted in post_setattr() path. In fact, this is a
9# real bug in policy engine when handling post_setattr()
10# hook. The failure can be triggered in such a way:
11# touch /bin/ls
12# /bin/ls <- permission denied
13
14# Reduce performance loss
15# audit func=FILE_CHECK fowner=0 mask=^MAY_READ
16# measure func=FILE_CHECK fowner=0 mask=^MAY_READ
17
18appraise func=MMAP_CHECK euid=0 appraise_type=imasig
19
20appraise func=BPRM_CHECK euid=0 appraise_type=imasig
21
22appraise func=MODULE_CHECK euid=0 appraise_type=imasig
23
24appraise func=FIRMWARE_CHECK euid=0 appraise_type=imasig
diff --git a/meta-integrity/recipes-support/ima-policy/ima-policy_0.1.bb b/meta-integrity/recipes-support/ima-policy/ima-policy_0.1.bb
new file mode 100644
index 0000000..982717a
--- /dev/null
+++ b/meta-integrity/recipes-support/ima-policy/ima-policy_0.1.bb
@@ -0,0 +1,18 @@
1DESCRIPTION = "The default external IMA policy"
2LICENSE = "MIT"
3LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \
4 file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
5
6SRC_URI = " \
7 file://ima_policy.default \
8 "
9
10S = "${WORKDIR}"
11
12do_install() {
13 install -d "${D}${sysconfdir}"
14 install -m 0400 "${WORKDIR}/ima_policy.default" \
15 "${D}${sysconfdir}"
16}
17
18FILES_${PN} = "${sysconfdir}"
diff --git a/meta-integrity/recipes-support/keyutils/keyutils/keyutils-fix-powerpc-cflags.patch b/meta-integrity/recipes-support/keyutils/keyutils/keyutils-fix-powerpc-cflags.patch
new file mode 100644
index 0000000..11be1e1
--- /dev/null
+++ b/meta-integrity/recipes-support/keyutils/keyutils/keyutils-fix-powerpc-cflags.patch
@@ -0,0 +1,28 @@
1From 1cc17e3c8b1f73db43011775292396338f932a20 Mon Sep 17 00:00:00 2001
2From: Lei Maohui <leimaohui at cn.fujitsu.com>
3Date: Mon, 17 Aug 2015 15:30:40 +0900
4Subject: [PATCH] keyutils fix powerpc cflags
5
6---
7 Makefile | 2 --
8 1 file changed, 2 deletions(-)
9
10diff --git a/Makefile b/Makefile
11index 82e1a0f..0746c82 100644
12--- a/Makefile
13+++ b/Makefile
14@@ -65,12 +65,10 @@ BUILDFOR := $(shell file /usr/bin/make | sed -e 's!.*ELF \(32\|64\)-bit.*!\1!')-
15 LNS := ln -sf
16
17 ifeq ($(BUILDFOR),32-bit)
18-CFLAGS += -m32
19 LIBDIR := /usr/lib
20 USRLIBDIR := /usr/lib
21 else
22 ifeq ($(BUILDFOR),64-bit)
23-CFLAGS += -m64
24 LIBDIR := /usr/lib
25 USRLIBDIR := /usr/lib
26 endif
27--
281.8.4.2
diff --git a/meta-integrity/recipes-support/keyutils/keyutils/keyutils-fix-the-cflags-for-all-of-targets.patch b/meta-integrity/recipes-support/keyutils/keyutils/keyutils-fix-the-cflags-for-all-of-targets.patch
new file mode 100644
index 0000000..77cf528
--- /dev/null
+++ b/meta-integrity/recipes-support/keyutils/keyutils/keyutils-fix-the-cflags-for-all-of-targets.patch
@@ -0,0 +1,32 @@
1From 8a1331d4abf9a96ee65e5fb31a00c7a2e0eed7c8 Mon Sep 17 00:00:00 2001
2From: Lei Maohui <leimaohui at cn.fujitsu.com>
3Date: Mon, 17 Aug 2015 13:53:28 +0900
4Subject: [PATCH] fix the cflags for all of targets.
5
6Signed-off-by: Lei Maohui <leimaohui at cn.fujitsu.com>
7---
8 Makefile | 2 --
9 1 file changed, 2 deletions(-)
10
11diff --git a/Makefile b/Makefile
12index e2d7e2d..82e1a0f 100644
13--- a/Makefile
14+++ b/Makefile
15@@ -64,7 +64,6 @@ BUILDFOR := $(shell file /usr/bin/make | sed -e 's!.*ELF \(32\|64\)-bit.*!\1!')-
16
17 LNS := ln -sf
18
19-ifeq ($(origin CFLAGS),undefined)
20 ifeq ($(BUILDFOR),32-bit)
21 CFLAGS += -m32
22 LIBDIR := /usr/lib
23@@ -76,7 +75,6 @@ LIBDIR := /usr/lib
24 USRLIBDIR := /usr/lib
25 endif
26 endif
27-endif
28
29 ###############################################################################
30 #
31--
321.8.4.2
diff --git a/meta-integrity/recipes-support/keyutils/keyutils/keyutils-remove-m32-m64.patch b/meta-integrity/recipes-support/keyutils/keyutils/keyutils-remove-m32-m64.patch
new file mode 100644
index 0000000..a049fd2
--- /dev/null
+++ b/meta-integrity/recipes-support/keyutils/keyutils/keyutils-remove-m32-m64.patch
@@ -0,0 +1,19 @@
1Index: keyutils-1.5.5/Makefile
2===================================================================
3--- keyutils-1.5.5.orig/Makefile 2011-12-20 11:05:10.000000000 +0200
4+++ keyutils-1.5.5/Makefile 2011-12-20 11:06:27.000000000 +0200
5@@ -58,12 +58,12 @@
6 LNS := ln -sf
7
8 ifeq ($(BUILDFOR),32-bit)
9-CFLAGS += -m32
10+#CFLAGS += -m32
11 LIBDIR := /usr/lib
12 USRLIBDIR := /usr/lib
13 else
14 ifeq ($(BUILDFOR),64-bit)
15-CFLAGS += -m64
16+#CFLAGS += -m64
17 LIBDIR := /usr/lib
18 USRLIBDIR := /usr/lib
19 endif
diff --git a/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_library_install.patch b/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_library_install.patch
new file mode 100644
index 0000000..adf0643
--- /dev/null
+++ b/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_library_install.patch
@@ -0,0 +1,30 @@
1Index: keyutils-1.5.5/Makefile
2===================================================================
3--- keyutils-1.5.5.orig/Makefile 2011-11-30 17:27:43.000000000 +0200
4+++ keyutils-1.5.5/Makefile 2011-12-21 16:05:53.000000000 +0200
5@@ -59,13 +59,13 @@
6
7 ifeq ($(BUILDFOR),32-bit)
8 CFLAGS += -m32
9-LIBDIR := /lib
10+LIBDIR := /usr/lib
11 USRLIBDIR := /usr/lib
12 else
13 ifeq ($(BUILDFOR),64-bit)
14 CFLAGS += -m64
15-LIBDIR := /lib64
16-USRLIBDIR := /usr/lib64
17+LIBDIR := /usr/lib
18+USRLIBDIR := /usr/lib
19 endif
20 endif
21
22@@ -152,7 +152,7 @@
23 $(INSTALL) -D $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(LIBNAME)
24 $(LNS) $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SONAME)
25 mkdir -p $(DESTDIR)$(USRLIBDIR)
26- $(LNS) $(LIBDIR)/$(SONAME) $(DESTDIR)$(USRLIBDIR)/$(DEVELLIB)
27+ $(LNS) $(SONAME) $(DESTDIR)$(USRLIBDIR)/$(DEVELLIB)
28 $(INSTALL) -D keyctl $(DESTDIR)$(BINDIR)/keyctl
29 $(INSTALL) -D request-key $(DESTDIR)$(SBINDIR)/request-key
30 $(INSTALL) -D request-key-debug.sh $(DESTDIR)$(SHAREDIR)/request-key-debug.sh
diff --git a/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_x86-64_cflags.patch b/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_x86-64_cflags.patch
new file mode 100644
index 0000000..b0c2d92
--- /dev/null
+++ b/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_x86-64_cflags.patch
@@ -0,0 +1,24 @@
1From d3b6b98984a28e782cb22dc6c7bd0ea9a0e74f15 Mon Sep 17 00:00:00 2001
2From: Lei Maohui <leimaohui at cn.fujitsu.com>
3Date: Mon, 17 Aug 2015 15:53:02 +0900
4Subject: [PATCH] keyutils fix x86-64 cflags
5
6---
7 Makefile | 2 +-
8 1 file changed, 1 insertion(+), 1 deletion(-)
9
10diff --git a/Makefile b/Makefile
11index 82e1a0f..23aa466 100644
12--- a/Makefile
13+++ b/Makefile
14@@ -60,7 +60,7 @@ endif
15 ifeq ($(origin USRLIBDIR),undefined)
16 USRLIBDIR := $(patsubst /lib/%,/usr/lib/%,$(LIBDIR))
17 endif
18-BUILDFOR := $(shell file /usr/bin/make | sed -e 's!.*ELF \(32\|64\)-bit.*!\1!')-bit
19+BUILDFOR := 64-bit
20
21 LNS := ln -sf
22
23--
241.8.4.2
diff --git a/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_x86_cflags.patch b/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_x86_cflags.patch
new file mode 100644
index 0000000..f5d5f70
--- /dev/null
+++ b/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_x86_cflags.patch
@@ -0,0 +1,24 @@
1From 3263917382af02e61f12f3774c32d3324a57059f Mon Sep 17 00:00:00 2001
2From: Lei Maohui <leimaohui at cn.fujitsu.com>
3Date: Mon, 17 Aug 2015 11:48:22 +0900
4Subject: [PATCH] keyutils fix x86 cflags
5
6---
7 Makefile | 2 +-
8 1 file changed, 1 insertion(+), 1 deletion(-)
9
10diff --git a/Makefile b/Makefile
11index e2d7e2d..f05bada 100644
12--- a/Makefile
13+++ b/Makefile
14@@ -60,7 +60,7 @@ endif
15 ifeq ($(origin USRLIBDIR),undefined)
16 USRLIBDIR := $(patsubst /lib/%,/usr/lib/%,$(LIBDIR))
17 endif
18-BUILDFOR := $(shell file /usr/bin/make | sed -e 's!.*ELF \(32\|64\)-bit.*!\1!')-bit
19+BUILDFOR := 32-bit
20
21 LNS := ln -sf
22
23--
241.8.4.2
diff --git a/meta-integrity/recipes-support/keyutils/keyutils_1.5.9.bb b/meta-integrity/recipes-support/keyutils/keyutils_1.5.9.bb
new file mode 100644
index 0000000..64e0365
--- /dev/null
+++ b/meta-integrity/recipes-support/keyutils/keyutils_1.5.9.bb
@@ -0,0 +1,48 @@
1SUMMARY = "Linux Key Management Utilities"
2DESCRIPTION = "Keyutils is a set of utilities for managing the key retention \
3facility in the kernel, which can be used by filesystems, block devices and \
4more to gain and retain the authorization and encryption keys required to \
5perform secure operations."
6SECTION = "base"
7LICENSE = "GPLv2"
8LIC_FILES_CHKSUM = "file://LICENCE.GPL;md5=5f6e72824f5da505c1f4a7197f004b45"
9
10PR = "r1"
11
12SRCREV = "9209a0c8fd63afc59f644e078b40cec531409c30"
13
14SRC_URI = "git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/keyutils.git;protocol=git \
15 file://keyutils_fix_library_install.patch \
16 file://keyutils-fix-the-cflags-for-all-of-targets.patch \
17 "
18SRC_URI_append_arm = " file://keyutils-remove-m32-m64.patch"
19SRC_URI_append_aarch64 = " file://keyutils-remove-m32-m64.patch"
20SRC_URI_append_mips = " file://keyutils-remove-m32-m64.patch"
21SRC_URI_append_mips64 = " file://keyutils-remove-m32-m64.patch"
22SRC_URI_append_x86 = " file://keyutils_fix_x86_cflags.patch"
23SRC_URI_append_x86-64 = " file://keyutils_fix_x86-64_cflags.patch"
24SRC_URI_append_powerpc = "file://keyutils-fix-powerpc-cflags.patch"
25
26S = "${WORKDIR}/git"
27
28inherit autotools-brokensep
29
30INSTALL_FLAGS = " \
31 LIBDIR=${libdir} \
32 USRLIBDIR=${libdir} \
33 BINDIR=${bindir} \
34 SBINDIR=${sbindir} \
35 ETCDIR=${sysconfdir} \
36 SHAREDIR=${datadir} \
37 MANDIR=${mandir} \
38 INCLUDEDIR=${includedir} \
39 DESTDIR=${D} \
40"
41
42do_install() {
43 cd ${S} && oe_runmake ${INSTALL_FLAGS} install
44}
45
46FILES_${PN} += "${datadir}/request-key-debug.sh"
47
48BBCLASSEXTEND = "native nativesdk"
diff --git a/meta-signing-key/README.md b/meta-signing-key/README.md
new file mode 100644
index 0000000..2b26599
--- /dev/null
+++ b/meta-signing-key/README.md
@@ -0,0 +1,73 @@
1### User Key Store
2The sample keys, by default, are used by build system to sign bootloader,
3kernel, IMA signature, RPM and so on. It is used for development and
4demonstration. The user must know what te risk is to use the sample
5keys in the product.
6
7The user key in a general sense is able to be used in the product with
8contrary of the sample key. This document defines the definitions for
9the uses of various keys.
10
11In addition, the scripts/create-user-key-store.sh provides a reference
12to the creation of user key store, stored in such a layout:
13```
14user-keys
15├── ima_keys
16│   ├── x509_ima.der
17│   └── x509_ima.key
18├── mok_sb_keys
19│   ├── shim_cert.key
20│   ├── shim_cert.pem
21│   ├── vendor_cert.key
22│   └── vendor_cert.pem
23└── uefi_sb_keys
24 ├── DB.key
25 ├── KEK.key
26 ├── KEK.pem
27 ├── PK.key
28 └── PK.pem
29```
30If the user plans to create the user keys by self, please consider to
31define the necessary variables mentioned below in local.conf, or construct
32a layer for the user key store. Eventually, the build system will copy the
33user key store to `$project/tmp/deploy/images/*/user-keys/` for further use.
34
35The vital definitions include:
36
37- `SIGNING_MODEL := "user"`
38 Prohibit using the sample keys for signing the images.
39
40- `UEFI_SB_KEYS_DIR := "<path>"`
41 Point to the location of user keys used for UEFI secure boot. If not defined,
42 the user keys for UEFI secure boot will be automatically generated.
43
44- `MOK_SB_KEYS_DIR := "<path>"`
45 Point to the location of user keys used for MOK secure boot. Note that
46 MOK secure boot is on top of UEFI secure boot so creating the user keys
47 for MOK secure boot only will still introduce the security risk in your
48 product. If not defined, the user keys for MOK secure boot will be
49 automatically generated.
50
51- `IMA_KEYS_DIR := "<path>"`
52 Point to the location of user keys used for IMA appraisal. If not defined,
53 the user keys for IMA appraisal will be automatically generated.
54
55- `USER_KEY_SHOW_VERBOSE = "1"`
56 Optional. Used to enable the verbose output for debugging purpose.
57
58To ensure a image signed by the untrustworthy sample key cannot be loaded, e.g,
59preventing the shim signed by the user key from loading the grub signed by the
60sample key, certain sample keys are added to the blacklists during the build,
61meaning the following precautions:
62
63- Blacklist the sample DB and DBX in DBX database for UEFI secure boot.
64- Blacklist the sample DB, shim_cert and vendor_cert in vendor_dbx database
65 for MOK secure boot.
66- Cascade the default blacklist mentioned above and the user specified
67 blacklist if any.
68
69For the details about UEFI secure boot and MOK secure boot, please refer
70to meta-efi-secure-boot/README.md.
71
72### Reference
73[meta-efi-secure-boot](https://github.com/jiazhang0/meta-efi-secure-boot)
diff --git a/meta-signing-key/classes/user-key-store.bbclass b/meta-signing-key/classes/user-key-store.bbclass
new file mode 100644
index 0000000..da99064
--- /dev/null
+++ b/meta-signing-key/classes/user-key-store.bbclass
@@ -0,0 +1,440 @@
1DEPENDS_append_class-target += " \
2 sbsigntool-native \
3 libsign-native \
4 openssl-native \
5 efitools-native \
6"
7
8USER_KEY_SHOW_VERBOSE = "1"
9
10UEFI_SB = '${@bb.utils.contains("DISTRO_FEATURES", "efi-secure-boot", "1", "0", d)}'
11MOK_SB = '${@bb.utils.contains("DISTRO_FEATURES", "efi-secure-boot", "1", "0", d)}'
12IMA = '${@bb.utils.contains("DISTRO_FEATURES", "ima", "1", "0", d)}'
13SYSTEM_TRUSTED = '1'
14
15def vprint(str, d):
16 if d.getVar('USER_KEY_SHOW_VERBOSE', True) == '1':
17 bb.note(str)
18
19def uks_signing_model(d):
20 return d.getVar('SIGNING_MODEL', True)
21
22def uks_system_trusted_keys_dir(d):
23 set_keys_dir('SYSTEM_TRUSTED', d)
24 return d.getVar('SYSTEM_TRUSTED_KEYS_DIR', True) + '/'
25
26def uks_ima_keys_dir(d):
27 set_keys_dir('IMA', d)
28 return d.getVar('IMA_KEYS_DIR', True) + '/'
29
30def uks_rpm_keys_dir(d):
31 # XXX: currently the user rpm pubkey is not supported.
32 if uks_signing_model(d) != 'sample':
33 return ''
34
35 return d.getVar('RPM_KEYS_DIR', True) + '/'
36
37def sign_efi_image(key, cert, input, output, d):
38 import bb.process
39
40 cmd = (' '.join((d.getVar('STAGING_BINDIR_NATIVE', True) + '/sbsign',
41 '--key', key, '--cert', cert,
42 '--output', output, input)))
43 vprint("Signing %s with the key %s ..." % (input, key), d)
44 vprint("Running: %s" % cmd, d)
45 try:
46 result, _ = bb.process.run(cmd)
47 except bb.process.ExecutionError:
48 raise bb.build.FuncFailed('ERROR: Unable to sign %s' % input)
49
50def edss_sign_efi_image(input, output, d):
51 # This function will be overloaded in pulsar-binary-release
52 pass
53
54def uefi_sb_keys_dir(d):
55 set_keys_dir('UEFI_SB', d)
56 return d.getVar('UEFI_SB_KEYS_DIR', True) + '/'
57
58def check_uefi_sb_user_keys(d):
59 dir = uefi_sb_keys_dir(d)
60
61 for _ in ('PK', 'KEK', 'DB'):
62 if not os.path.exists(dir + _ + '.key'):
63 vprint("%s.key is unavailable" % _, d)
64 return False
65
66 if not os.path.exists(dir + _ + '.pem'):
67 vprint("%s.pem is unavailable" % _, d)
68 return False
69
70def uefi_sb_sign(input, output, d):
71 if d.getVar('UEFI_SB', True) != '1':
72 return
73
74 _ = uefi_sb_keys_dir(d)
75 sign_efi_image(_ + 'DB.key', _ + 'DB.pem', input, output, d)
76
77def mok_sb_keys_dir(d):
78 if d.getVar('MOK_SB', True) != '1':
79 return
80
81 set_keys_dir('MOK_SB', d)
82 return d.getVar('MOK_SB_KEYS_DIR', True) + '/'
83
84def sb_sign(input, output, d):
85 if d.getVar('UEFI_SB', True) != '1':
86 return
87
88 if uks_signing_model(d) in ('sample', 'user'):
89 # Deal with MOK_SB firstly, as MOK_SB implies UEFI_SB == 1.
90 # On this scenario, bootloader is verified by shim_cert.pem
91 if d.getVar('MOK_SB', True) == '1':
92 mok_sb_sign(input, output, d)
93 # UEFI_SB is defined, but MOK_SB is not defined
94 # On this scenario, shim is not used, and DB.pem is used to
95 # verify bootloader directly.
96 else:
97 uefi_sb_sign(input, output, d)
98 elif uks_signing_model(d) == 'edss':
99 edss_sign_efi_image(input, output, d)
100
101def check_mok_sb_user_keys(d):
102 dir = mok_sb_keys_dir(d)
103
104 for _ in ('shim_cert', 'vendor_cert'):
105 if not os.path.exists(dir + _ + '.key'):
106 vprint("%s.key is unavailable" % _, d)
107 return False
108
109 if not os.path.exists(dir + _ + '.pem'):
110 vprint("%s.pem is unavailable" % _, d)
111 return False
112
113def mok_sb_sign(input, output, d):
114 if d.getVar('MOK_SB', True) != '1':
115 return
116
117 _ = mok_sb_keys_dir(d)
118 sign_efi_image(_ + 'vendor_cert.key', _ + 'vendor_cert.pem', input, output, d)
119
120def sel_sign(key, cert, input, d):
121 import bb.process
122
123 cmd = (' '.join(('LD_LIBRARY_PATH=' + d.getVar('STAGING_LIBDIR_NATIVE', True) +
124 ':$LD_LIBRARY_PATH', d.getVar('STAGING_BINDIR_NATIVE', True) + '/selsign',
125 '--key', key, '--cert', cert, input)))
126 vprint("Signing %s with the key %s ..." % (input, key), d)
127 vprint("Running cmd: %s" % cmd, d)
128 try:
129 result, _ = bb.process.run(cmd)
130 except bb.process.ExecutionError:
131 raise bb.build.FuncFailed('ERROR: Unable to sign %s' % input)
132
133def uks_sel_sign(input, d):
134 if d.getVar('UEFI_SB', True) != '1':
135 return
136
137 if d.getVar('MOK_SB', True) == '1':
138 _ = mok_sb_keys_dir(d)
139 key = _ + 'vendor_cert.key'
140 cert = _ + 'vendor_cert.pem'
141 else:
142 _ = uefi_sb_keys_dir(d)
143 key = _ + 'DB.key'
144 cert = _ + 'DB.pem'
145
146 sel_sign(key, cert, input, d)
147
148def check_ima_user_keys(d):
149 dir = uks_ima_keys_dir(d)
150
151 for _ in ('key', 'der'):
152 if not os.path.exists(dir + 'x509_ima.' + _):
153 vprint("%s.pem is unavailable" % _, d)
154 return False
155
156def check_system_trusted_keys(d):
157 dir = uks_system_trusted_keys_dir(d)
158
159 _ = 'system_trusted_key'
160 if not os.path.exists(dir + _ + '.key'):
161 vprint("%s.key is unavailable" % _, d)
162 return False
163
164 if not os.path.exists(dir + _ + '.pem'):
165 vprint("%s.pem is unavailable" % _, d)
166 return False
167
168# Convert the PEM to DER format.
169def pem2der(input, output, d):
170 import bb.process
171
172 cmd = (' '.join((d.getVar('STAGING_BINDIR_NATIVE', True) + '/openssl',
173 'x509', '-inform', 'PEM', '-outform', 'DER',
174 '-in', input, '-out', output)))
175 try:
176 result, _ = bb.process.run(cmd)
177 except bb.process.ExecutionError:
178 raise bb.build.FuncFailed('ERROR: Unable to convert %s to %s' % (input, output))
179
180# Convert the certificate (PEM formatted) to ESL.
181__pem2esl() {
182 "${STAGING_BINDIR_NATIVE}/cert-to-efi-sig-list" \
183 -g ${UEFI_SIG_OWNER_GUID} "$1" "$2"
184}
185
186# Blacklist the sample DB, shim_cert, vendor_cert by default.
187__create_default_mok_sb_blacklist() {
188 __pem2esl "${SAMPLE_MOK_SB_KEYS_DIR}/shim_cert.pem" \
189 "${TMPDIR}/sample_shim_cert.esl"
190
191 __pem2esl "${SAMPLE_MOK_SB_KEYS_DIR}/vendor_cert.pem" \
192 "${TMPDIR}/sample_vendor_cert.esl"
193
194 # Cascade the sample DB, shim_cert and vendor_cert to
195 # the default vendor_dbx.
196 cat "${TMPDIR}/sample_shim_cert.esl" \
197 "${TMPDIR}/sample_vendor_cert.esl" >> "${TMPDIR}/blacklist.esl"
198}
199
200__create_default_uefi_sb_blacklist() {
201 __pem2esl "${SAMPLE_UEFI_SB_KEYS_DIR}/DB.pem" \
202 "${TMPDIR}/sample_DB.esl"
203
204 cat "${TMPDIR}/sample_DB.esl" > "${TMPDIR}/blacklist.esl"
205}
206
207# Cascade the default blacklist and user specified blacklist if any.
208def __create_blacklist(d):
209 tmp_dir = d.getVar('TMPDIR', True)
210
211 vprint('Preparing to create the default blacklist %s' % tmp_dir + '/blacklist.esl', d)
212
213 bb.build.exec_func('__create_default_uefi_sb_blacklist', d)
214 if d.getVar('MOK_SB', True) == '1':
215 bb.build.exec_func('__create_default_mok_sb_blacklist', d)
216
217 def __pem2esl_dir (dir):
218 if not os.path.isdir(dir):
219 return
220
221 dst = open(tmp_dir + '/blacklist.esl', 'wb+')
222
223 for _ in os.listdir(dir):
224 fn = os.path.join(dir, _)
225 if not os.path.isfile(fn):
226 continue
227
228 cmd = (' '.join((d.getVar('STAGING_BINDIR_NATIVE', True) + '/cert-to-efi-sig-list',
229 '-g', d.getVar('UEFI_SIG_OWNER_GUID', True), fn,
230 tmp_dir + '/' + _ + '.esl')))
231 try:
232 result, _ = bb.process.run(cmd)
233 except bb.process.ExecutionError:
234 vprint('Unable to convert %s' % fn)
235 continue
236
237 with open(fn) as src:
238 shutil.copyfileobj(src, dst)
239 src.close()
240
241 dst.close()
242
243 # Cascade the user specified blacklists.
244 __pem2esl_dir(uefi_sb_keys_dir(d) + 'DBX')
245
246 if d.getVar('MOK_SB', True) == '1':
247 __pem2esl_dir(mok_sb_keys_dir(d) + 'vendor_dbx')
248
249# To ensure a image signed by the sample key cannot be loaded by a image
250# signed by the user key, e.g, preventing the shim signed by the user key
251# from loading the grub signed by the sample key, certain sample keys are
252# added to the blacklist.
253def create_mok_vendor_dbx(d):
254 if d.getVar('MOK_SB', True) != '1' or d.getVar('SIGNING_MODEL', True) != 'user':
255 return None
256
257 src = d.getVar('TMPDIR', True) + '/blacklist.esl'
258 import os
259 if os.path.exists(src):
260 os.remove(src)
261
262 __create_blacklist(d)
263
264 dst = d.getVar('WORKDIR', True) + '/vendor_dbx.esl'
265 import shutil
266 shutil.copyfile(src, dst)
267
268 return dst
269
270def create_uefi_dbx(d):
271 if d.getVar('UEFI_SB', True) != '1' or d.getVar('SIGNING_MODEL', True) != 'user':
272 return None
273
274 src = d.getVar('TMPDIR', True) + '/blacklist.esl'
275 import os
276 if os.path.exists(src):
277 os.remove(src)
278
279 __create_blacklist(d)
280
281 dst = d.getVar('WORKDIR', True) + '/DBX.esl'
282 import shutil
283 shutil.copyfile(src, dst)
284
285 return dst
286
287create_uefi_sb_user_keys() {
288 local deploy_dir="${DEPLOY_DIR_IMAGE}/user-keys/uefi_sb_keys"
289
290 install -d "$deploy_dir"
291
292 # PK is self-signed.
293 "${STAGING_BINDIR_NATIVE}/openssl" req -new -x509 -newkey rsa:2048 \
294 -sha256 -nodes -days 3650 \
295 -subj "/CN=PK Certificate for $USER@`hostname`/" \
296 -keyout "$deploy_dir/PK.key" \
297 -out "$deploy_dir/PK.pem"
298
299 # KEK is signed by PK.
300 "${STAGING_BINDIR_NATIVE}/openssl" req -new -newkey rsa:2048 \
301 -sha256 -nodes \
302 -subj "/CN=KEK Certificate for $USER@`hostname`" \
303 -keyout "$deploy_dir/KEK.key" \
304 -out "${TMPDIR}/KEK.csr"
305
306 "${STAGING_BINDIR_NATIVE}/openssl" x509 -req -in "${TMPDIR}/KEK.csr" \
307 -CA "$deploy_dir/PK.pem" -CAkey "$deploy_dir/PK.key" \
308 -set_serial 1 -days 3650 -out "$deploy_dir/KEK.pem"
309
310 # DB is signed by KEK.
311 "${STAGING_BINDIR_NATIVE}/openssl" req -new -newkey rsa:2048 \
312 -sha256 -nodes \
313 -subj "/CN=DB Certificate for $USER@`hostname`" \
314 -keyout "$deploy_dir/DB.key" \
315 -out "${TMPDIR}/DB.csr"
316
317 "${STAGING_BINDIR_NATIVE}/openssl" x509 -req -in "${TMPDIR}/DB.csr" \
318 -CA "$deploy_dir/KEK.pem" -CAkey "$deploy_dir/KEK.key" \
319 -set_serial 1 -days 3650 -out "$deploy_dir/DB.pem"
320}
321
322create_mok_sb_user_keys() {
323 local deploy_dir="${DEPLOY_DIR_IMAGE}/user-keys/mok_sb_keys"
324
325 install -d "$deploy_dir"
326
327 "${STAGING_BINDIR_NATIVE}/openssl" req -new -x509 -newkey rsa:2048 \
328 -sha256 -nodes -days 3650 -subj "/CN=Shim Certificate for $USER@`hostname`/" \
329 -keyout "$deploy_dir/shim_cert.key" -out "$deploy_dir/shim_cert.pem"
330
331 "${STAGING_BINDIR_NATIVE}/openssl" req -new -x509 -newkey rsa:2048 \
332 -sha256 -nodes -days 3650 -subj "/CN=Vendor Certificate for $USER@`hostname`/" \
333 -keyout "$deploy_dir/vendor_cert.key" -out "$deploy_dir/vendor_cert.pem" \
334}
335
336create_ima_user_keys() {
337 local deploy_dir="${DEPLOY_DIR_IMAGE}/user-keys/ima_keys"
338
339 install -d "$deploy_dir"
340
341 "${STAGING_BINDIR_NATIVE}/openssl" genrsa -out "$deploy_dir/ima_privkey.pem" 2048
342
343 "${STAGING_BINDIR_NATIVE}/openssl" rsa -in "$deploy_dir/ima_privkey.pem" -pubout \
344 -out "$deploy_dir/ima_pubkey.pem"
345}
346
347def create_user_keys(name, d):
348 vprint('Creating the user keys for %s ...' % name, d)
349 bb.build.exec_func('create_' + name.lower() + '_user_keys', d)
350
351deploy_uefi_sb_keys() {
352 local deploy_dir="${DEPLOY_KEYS_DIR}/uefi_sb_keys"
353
354 if [ x"${UEFI_SB_KEYS_DIR}" != x"$deploy_dir" ]; then
355 install -d "$deploy_dir"
356
357 cp -af "${UEFI_SB_KEYS_DIR}"/* "$deploy_dir"
358 fi
359}
360
361deploy_mok_sb_keys() {
362 local deploy_dir="${DEPLOY_KEYS_DIR}/mok_sb_keys"
363
364 if [ x"${MOK_SB_KEYS_DIR}" != x"$deploy_dir" ]; then
365 install -d "$deploy_dir"
366
367 cp -af "${MOK_SB_KEYS_DIR}"/* "$deploy_dir"
368 fi
369}
370
371deploy_ima_keys() {
372 local deploy_dir="${DEPLOY_KEYS_DIR}/ima_keys"
373
374 if [ x"${IMA_KEYS_DIR}" != x"$deploy_dir" ]; then
375 install -d "$deploy_dir"
376
377 cp -af "${IMA_KEYS_DIR}"/* "$deploy_dir"
378 fi
379}
380
381deploy_system_trusted_keys() {
382 local deploy_dir="${DEPLOY_KEYS_DIR}/system_trusted_keys"
383
384 if [ x"${SYSTEM_TRUSTED_KEYS_DIR}" != x"$deploy_dir" ]; then
385 install -d "$deploy_dir"
386
387 cp -af "${SYSTEM_TRUSTED_KEYS_DIR}"/* "$deploy_dir"
388 fi
389}
390
391def deploy_keys(name, d):
392 d.setVar('DEPLOY_KEYS_DIR', d.getVar('DEPLOY_DIR_IMAGE', True) + '/' + \
393 d.getVar('SIGNING_MODEL', True) + '-keys')
394 bb.build.exec_func('deploy_' + name.lower() + '_keys', d)
395
396def sanity_check_user_keys(name, may_exit, d):
397 if name == 'UEFI_SB':
398 _ = check_uefi_sb_user_keys(d)
399 elif name == 'MOK_SB':
400 _ = check_mok_sb_user_keys(d)
401 elif name == 'IMA':
402 _ = check_ima_user_keys(d)
403 elif name == 'SYSTEM_TRUSTED':
404 _ = check_system_trusted_keys(d)
405 else:
406 _ = False
407 may_exit = True
408
409 if _ == False:
410 if may_exit:
411 raise bb.build.FuncFailed('ERROR: Unable to find user key for %s ...' % name)
412
413 vprint('Failed to check the user keys for %s ...' % name, d)
414
415 return _
416
417# *_KEYS_DIR need to be updated whenever reading them.
418def set_keys_dir(name, d):
419 if (d.getVar(name, True) != "1") or (d.getVar('SIGNING_MODEL', True) != "user"):
420 return
421
422 if d.getVar(name + '_KEYS_DIR', True) == d.getVar('SAMPLE_' + name + '_KEYS_DIR', True):
423 d.setVar(name + '_KEYS_DIR', d.getVar('DEPLOY_DIR_IMAGE', True) + '/user-keys/' + name.lower() + '_keys')
424
425python () {
426 # XXX: the user key for rpm signing is necessary but not required.
427 for _ in ('UEFI_SB', 'MOK_SB', 'IMA', 'SYSTEM_TRUSTED'):
428 if d.getVar(_, True) != "1":
429 continue
430
431 # Intend to use user key?
432 if not d.getVar('SIGNING_MODEL', True) in ("sample", "user"):
433 continue
434
435 # Raise error if not specifying the location of the
436 # user keys.
437 sanity_check_user_keys(_, True, d)
438
439 deploy_keys(_, d)
440}
diff --git a/meta-signing-key/conf/layer.conf b/meta-signing-key/conf/layer.conf
new file mode 100644
index 0000000..ed83abd
--- /dev/null
+++ b/meta-signing-key/conf/layer.conf
@@ -0,0 +1,40 @@
1# We have a conf and classes directory, add to BBPATH
2BBPATH .= ":${LAYERDIR}"
3
4# We have recipes-* directories, add to BBFILES
5BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
6 ${LAYERDIR}/recipes-*/*/*.bbappend"
7
8BBFILE_COLLECTIONS += "signing-key"
9BBFILE_PATTERN_signing-key = "^${LAYERDIR}/"
10BBFILE_PRIORITY_signing-key = "10"
11
12SIGNING_MODEL ??= "sample"
13SAMPLE_MOK_SB_KEYS_DIR = "${LAYERDIR}/files/mok_sb_keys"
14SAMPLE_UEFI_SB_KEYS_DIR = "${LAYERDIR}/files/uefi_sb_keys"
15SAMPLE_SYSTEM_TRUSTED_KEYS_DIR = "${LAYERDIR}/files/system_trusted_keys"
16SAMPLE_IMA_KEYS_DIR = "${LAYERDIR}/files/ima_keys"
17SAMPLE_RPM_KEYS_DIR = "${LAYERDIR}/files/rpm_keys"
18
19# Microsoft certificates
20MSFT_DB_CERT = "${LAYERDIR}/files/uefi_sb_keys/ms-DB.pem"
21MSFT_KEK_CERT = "${LAYERDIR}/files/uefi_sb_keys/ms-KEK.pem"
22
23# EV certificate
24EV_CERT ??= "${LAYERDIR}/files/mok_sb_keys/wosign_ev_cert.pem"
25
26# By default the sample keys are used
27MOK_SB_KEYS_DIR ??= "${SAMPLE_MOK_SB_KEYS_DIR}"
28UEFI_SB_KEYS_DIR ??= "${SAMPLE_UEFI_SB_KEYS_DIR}"
29SYSTEM_TRUSTED_KEYS_DIR ??= "${SAMPLE_SYSTEM_TRUSTED_KEYS_DIR}"
30IMA_KEYS_DIR ??= "${SAMPLE_IMA_KEYS_DIR}"
31RPM_KEYS_DIR ??= "${SAMPLE_RPM_KEYS_DIR}"
32
33# Define the identification of vendor
34VENDOR_UUID = "1f7b9654-2107-4697-8f1c-0cbc38874588"
35
36# User configurable identification of signature owner
37UEFI_SIG_OWNER_GUID ??= "${VENDOR_UUID}"
38
39SAMPLE_RPM_KEYNAME ??= "SecureCoreSample"
40RPM_GPG_NAME ??= "${SAMPLE_RPM_KEYNAME}"
diff --git a/meta-signing-key/files/ima_keys/x509_ima.der b/meta-signing-key/files/ima_keys/x509_ima.der
new file mode 100644
index 0000000..ae0e098
--- /dev/null
+++ b/meta-signing-key/files/ima_keys/x509_ima.der
Binary files differ
diff --git a/meta-signing-key/files/ima_keys/x509_ima.key b/meta-signing-key/files/ima_keys/x509_ima.key
new file mode 100644
index 0000000..2f5bf14
--- /dev/null
+++ b/meta-signing-key/files/ima_keys/x509_ima.key
@@ -0,0 +1,28 @@
1-----BEGIN PRIVATE KEY-----
2MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDYwkDsMkB4HUdT
3uHsrmvzeuHbxrgdUa7WVjFL3cC7+KzJFnVgXP4U7BZQpeufbAjOMTJIPik0mDNMe
4UtYLSVxHFyL17ccAfyZ2JckuV2pJrYr7O9MQCLtb/ttUO3ANPM9UqUG+KCsAAPPW
5RYz7BjsWV1oj5ctMDtCjV58uhDYz6CQdqxbE2Zbe8dtRSlUBuyx3OxXV9p/LDg1t
64421dhhKpAM2t+OGaC0ZGquHtBfoAIx6nzufhHp7q561T9l/xtrq/kOKiDCawS38
7MTqlNjG7adN1rB0TK52bvMfMABZPyGeS0YhFrDExOVvynOqwcPS6yTKKcC7EsqM3
83GO6Mk3tAgMBAAECggEBANO+p5dU27+6slPpsoD9barQvnkHTWe9tGw74UyQjYeD
9gR+aPlSvm6H1qDABPX+nnd2fa0u9CfJyssY7m5b4+ikERAXEWxN0IolmDiq0AEOr
10QUp9vYg7T3Pl+jJFwgdccRk+Itf0+1SMmaam2Lrb8lq3yHmq4LcS/eOjFABn7V8z
11yXsxTQNH2K9YAoeLnsF66IprHR+dyj1TXpiTaLyS/DF/OmReLtHDd9zQUN2wWQuA
12VHLDSKCueY0to7mMt/EGJ934hC51bydJYLifZPDKVleqB8NsHA30I5FF3RVlV2/a
13/FSKSjuy3xntb5GtwhPMKXaFZJBJzfAnkQ3X+ogyfe0CgYEA9X6R/NymqpPuR2F7
14u8l3cxrZt82BDkXV2LX0FlvfzQPSxZL/ogKkAXeHxa/fCpdOx7yJwz3aTY1luWKR
15WgDwVkMB4r7TTL3Cbvg6jFsm1mh4ImDMt9wN56ThIMdOaLimm8bvTijxum+x6RQA
16Xq0iV1Zfxb0D3le3UwM+nZDD1JsCgYEA4gjhVa1VtS6uNNZ1cEXXaFN+HZ+N1Dzv
171HpxjeUFvxSo/YzYTwO2DnrGGjCdP1TW7K5YmkdNDZo4R9icRXOX4AuzGPitaPwV
18MNWJ0oEyYHA1gfy3kg5rruGG/Jz7fZPLoKsgwmdOt06+nuDxAhiQKxMz+mvWcD1L
19miTE9a9/3BcCgYBCaiWQpRkp2K+D/Cl/WjfImiEAisY5WEdMQ51vVxeq3TfuX6Bs
208g3wn6fJoZTTxq93ddhHS7p9dJ1qk/ICyXI7xBEEiN+dSVEKuHkOc7KEGus1Ub7Q
21luXkH0UQmxrpVdstFZq0KHuNFp6pEdIvyuMZgbKTSll7k3tzJ9OOyRVRtQKBgQCr
22PbMI56KQ+uZ7nSWngyHoJajb5G7cpbXEMWcp6qHp20sTm8qcQeGBIr5GRSI8Qpf5
23AzSY3P+hGH8e3xm0/BfJYtOyTWOCr8eWEZCya7KwoRHIgp7IBijKeo17f6p/vqJ7
24/Gl7HizibsO3Ng8gWV+PYqL0SxJQQf+urcCRqP2izQKBgQCA+I/VOmyfTiGGz8Q9
25dj4EnFw2CmPawNmqFuASvEcB4VqWMaYswiM3DOP31K4hDnuQUdS/BY8++OVesQ1t
26VrNG+cbkVXpRDgsRdr9/S2ZBKBT1+gCzoHyfrbpV+1U9ZTkng8EBuO1clsc7crjz
27Z5OTFNej0ldJ9zquU8ZjvRNV2Q==
28-----END PRIVATE KEY-----
diff --git a/meta-signing-key/files/mok_sb_keys/shim_cert.key b/meta-signing-key/files/mok_sb_keys/shim_cert.key
new file mode 100644
index 0000000..77e8f4b
--- /dev/null
+++ b/meta-signing-key/files/mok_sb_keys/shim_cert.key
@@ -0,0 +1,28 @@
1-----BEGIN PRIVATE KEY-----
2MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC9o6BF9wUJxJRb
34eAbc6lyIaSkhAs/XTR9nIwIlSAgKLJs6btBdi76AmOHB5qa4nS609dZtJl5rz11
4S/RUEh3uUoqdlPATFSlyZehpER54u6AVS8ZaJpJhYHNztzMdwn8IOYiR3+dwveH8
5HeSGZYyOoujTNcmPx9MCcsSrvHYIRZBC6kFRosVVKgU5FZfskd3/ITv9BXaLSgzr
6jeCTaawI7gzIvAnNwqR5xb7qIfwG5Gnity1Zy0wKEgiA3MhkdEn72Amn5hKn37gG
7vQcqhyMvS7Dr/J4H9Fwx5+1//tufti7DWDRfJhIFcIA45z1GUPxFQdZ4RMlqyeoW
8cC5TG84VAgMBAAECggEAZe786H6lw6FZyaW5C6h5DTMOR6v+S7nyzA4Iq1hVI1Qc
9zDQ6hi5bg+Ei1GL+9IADFKVn3P0ZffH3DASeuU3frsnJXni/LtKyK56hdVBRW74m
10hyvq22xeRF9Oz4VKwZVZKPeb9CUxR0WZoiYDP0Z4bfcdROJljJZxUqCUHGe53ilv
114BSl1sOF1l3ZWvAL60KPcsZ+DX7UGD79c+vdPe1fXfsPORZ6hT9wpedQej7av4q0
124Hoe2Gp2bbDzyBJJF6S8iESlw8VuDVuDthpXyXahB9lD7uvVrrSguodAqQsB52WY
13zrknbeCZOeRsATjCmSiC96wYhrnI/Uo+khUQZKIeJQKBgQD1wso5a0btnpqoTuux
14a0I2THAL9+u0wipig1qi09FN7fKWShwFFJdjZKeIlh5KSnVtskCjBnnHQtnuotJZ
15ND32kGu5+U5USqMsYilj33/rhxSxgBE+uu45Ys6PDAXpb0XCpIdGoiFiOt5OhBei
16uVzUtr50ySW0P6UhfYjRVvqASwKBgQDFikJNp3zs9LBuNkqcZHi7K+p7qe9e4uvl
17il418BAInosw7q/OOL5+qW8BcsRAiGIEePerBDhyt9xi2ee/PI2Wq3l27clX3NCE
18zMzNVcBhgVGiKSwcZx45Mqx73Gz3buOxQ9exepio4klOLKBPda76QlpdRFXqWZQ/
19iVGA+VmvHwKBgG56O1gmjoMBOnsQx0lBc0lfgTsQHyhp5I3WiKcL21pR7ix7ci8i
20e4+Vzu5KtaEl6bX/XKksnw/hUIDDNxYcswIlGBhJJ1ojF0k7c2nPLf0eA0Jr1NTD
21SZYIgdyyRfITMGP4fEtXVPSIjCj1nn5rH30MDYAIcGef+MaeXSPmGsQTAoGBALfs
22z2c2Nx75hPxZGIcdFTxQ23Zg9ztF1ZZXivh1mLgtxjO9SXudYeDVKUIT9Z6QXZME
23frWArH5DqrNvaFOqsbpD1khhhkKEmrHLbjURTpp6qeNuql+Xs5BWGjsJNXv8h4wZ
24Os9I8rLsXoynCGxzioQBG9oTMluNJHc0B+sqP9LJAoGBAKKSOPYMj8vyRAiOV8d2
254sWG0Jq3bVENK0NmB8q5hV8+bzY9gh9MZC/NwZYkC//LwBSxo0RvjTyfVZ/2LuQT
26A1KkhKT3/mp5YWWkCX9jBCCg+vpSBoTeLG7E+MNEyLKsTs/ib/1QguFoHmQoa6G+
27gwfYmI1EgW07xbXpw00AsDYN
28-----END PRIVATE KEY-----
diff --git a/meta-signing-key/files/mok_sb_keys/shim_cert.pem b/meta-signing-key/files/mok_sb_keys/shim_cert.pem
new file mode 100644
index 0000000..f6c0e23
--- /dev/null
+++ b/meta-signing-key/files/mok_sb_keys/shim_cert.pem
@@ -0,0 +1,19 @@
1-----BEGIN CERTIFICATE-----
2MIIDCTCCAfGgAwIBAgIJAMsUVTZv3GSuMA0GCSqGSIb3DQEBCwUAMBsxGTAXBgNV
3BAMMEFNoaW0gQ2VydGlmaWNhdGUwHhcNMTcwNTE4MDE1MTIyWhcNMjcwNTE2MDE1
4MTIyWjAbMRkwFwYDVQQDDBBTaGltIENlcnRpZmljYXRlMIIBIjANBgkqhkiG9w0B
5AQEFAAOCAQ8AMIIBCgKCAQEAvaOgRfcFCcSUW+HgG3OpciGkpIQLP100fZyMCJUg
6ICiybOm7QXYu+gJjhweamuJ0utPXWbSZea89dUv0VBId7lKKnZTwExUpcmXoaREe
7eLugFUvGWiaSYWBzc7czHcJ/CDmIkd/ncL3h/B3khmWMjqLo0zXJj8fTAnLEq7x2
8CEWQQupBUaLFVSoFORWX7JHd/yE7/QV2i0oM643gk2msCO4MyLwJzcKkecW+6iH8
9BuRp4rctWctMChIIgNzIZHRJ+9gJp+YSp9+4Br0HKocjL0uw6/yeB/RcMeftf/7b
10n7Yuw1g0XyYSBXCAOOc9RlD8RUHWeETJasnqFnAuUxvOFQIDAQABo1AwTjAdBgNV
11HQ4EFgQULvuvKMYuVLG+sHbjUrMqnfxzLZwwHwYDVR0jBBgwFoAULvuvKMYuVLG+
12sHbjUrMqnfxzLZwwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAGSHY
132iKYUO7Xnvn82lgcBdkI4s8ZmpqF8ETQox9C8Nz7Kz43vstAKacw2CRTZYKhElGA
14GjCLaPGMRXZWLHaqaxkYR957lvmxKCv7geDk8bzLo5r4ppgjMwDGvcBMW8syNR9A
15bIrIc2G1j5SmPbBOgwrnqxgoiV2IojO+B/OKUsbMNTqjmpOBHJmFspOLMxYbbuHa
16JLB8QRvLVZf92+Kc0QKYlBbyPwtHuDCImtsWndo5zNbu0ZBmZdoc3c/fLBA2Umig
170OWmJqSY7B9zVbXCY/FjZRZMcqPVAFp0UjF1eQ7PKmtAXUuomXWt3ygmIYa1biQO
18KEVY96hZLWVtfYKgMw==
19-----END CERTIFICATE-----
diff --git a/meta-signing-key/files/mok_sb_keys/vendor_cert.key b/meta-signing-key/files/mok_sb_keys/vendor_cert.key
new file mode 100644
index 0000000..5187666
--- /dev/null
+++ b/meta-signing-key/files/mok_sb_keys/vendor_cert.key
@@ -0,0 +1,28 @@
1-----BEGIN PRIVATE KEY-----
2MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCvQVgl3kSAZUkR
34jfomHUZqkngdoxStDCbsldW0itmGBLqFF3ZcH26igNvA4U/nk6a8oKbFJIhAlNK
45BONOXxBs5HO49PIe92bMKkiaYaabxpwNBX4Lz8b7SC1SoDHWeebEvkcoclqkOUK
5GAf/ZP4gr2T0Hh3baxst0kO0nE6ftAQvWONfgZFmjtIANW1//4CQyC9v5+IK2Igp
62Aum6EIPmlv3Ui+7e0MGAk6oMvr2C43puKX0VVfOE+2o3ABYV+cFXToUHSjWznIm
7EeFbY354dgah01e3iXvgigDeiINXvkODOAbkCuXvRbIfdQNd0f6u5B9R1E3j3q18
8jWqj9b9xAgMBAAECggEAM9Mq8efMcfuBpBw1VD7hQfmtZwcnb72BMkmGslHsK4Cq
99zWWmxo809DEOyvbV3jE3eUg4iMvIzvAzcCsV3LMX9FuKLQOiJa4bY/yNA7okvqP
104uZEKOQv0V5J8dJaSpk3eBAgQmtFWJIIaPe6Rbfjvl6fh+DwC1ac7uviwaIHTgo8
11XUQHghkNOIDJs9PaIXBXwaZMaiiMkQwqTFNxm+PVv/RgpwlXGUayS1VlUOMaswlg
12NB3Lv6Idm9wdvJTExhnLwG1qRYslM+MVJlrXzUUhKE7TkkI4/iep8x6ZH31Tlf29
138QRUIg1Xenn6mITaUWxxFHceTrtcF5STaORS4H0NkQKBgQDdYSsYz6Zcv2pUVWuf
14WYrXHdRhb7qFpAHduK8Ip6+fYWMSG5d2pPJsWy4dC92h6xMqFV7YIwr+zE9pWhTL
15pRkZePPgkh9pq+L3ezxEBIL4L7LuUEWhgiyMuOroep1+e1OHwrx9Z859ekvOwoEC
16uce4hw2h2g3crIjBhCJbCBmxawKBgQDKqZwbUrcgV7NV7MMstpCmdrrD5xEA+I5W
172IqGae9T2VtDXfLcj4KA7/Hu2J2wQATDmuO2f0LhkSWqLu/EfLxExkDyHhvT/6RK
1874YeKCft7vAPzB0tP1c578O1czVtVKibiYBG+9H43ZN5Vk2GgIylJXUgPLutyFBw
19oI1bGoNdkwKBgEYEjZTzWDLNd9vkiH2F3JvdG2cV53CNRunRl8qs/qbyLltzzpv/
2034zV6efV8OtdZlpRGAZUTw33oMY5b4pZVW7xCnFkxfquGsMbfxwkMSg+LeGiEePb
21QCvh8KpG3bk7WFgAB43CX1TgcUmbyyIJkFmUnYMrbGb3Sump2RPho/6xAoGAFWPD
22Yyrewx4egnIjw2NdbwRW//gyVjzloQrny/oAVYQ6WqjeyiKnbn5ktYXNVt3a4t5F
23LGzQHUiZhhXAHqffow6dqjA9VanEqFgRertYQ4eVdMVhSvZFeYrxyAPp3qkxxoDD
24tjo71h1kxEi0k/6bWY7ThtyCHnxm6Qw4/yWUOdsCgYA8pAPJ43T2f0rRN5iYoJOz
25xK94z7+xtfU8iM+he0KoOwBMvg+FPLyq4lHt44qqgk6pL13scbMcwabyg2bUimSq
26jkt0LzOM+xB9AF1myK4hJv0/DCt++EC+xNupbTUR91F/TR11yurIO0aXWOsb58JN
27490nl5BP5yqcfN+cZu6kFQ==
28-----END PRIVATE KEY-----
diff --git a/meta-signing-key/files/mok_sb_keys/vendor_cert.pem b/meta-signing-key/files/mok_sb_keys/vendor_cert.pem
new file mode 100644
index 0000000..0200779
--- /dev/null
+++ b/meta-signing-key/files/mok_sb_keys/vendor_cert.pem
@@ -0,0 +1,19 @@
1-----BEGIN CERTIFICATE-----
2MIIDDTCCAfWgAwIBAgIJAOxbh118EZp9MA0GCSqGSIb3DQEBCwUAMB0xGzAZBgNV
3BAMMElZlbmRvciBDZXJ0aWZpY2F0ZTAeFw0xNzA1MTgwMTUxMjhaFw0yNzA1MTYw
4MTUxMjhaMB0xGzAZBgNVBAMMElZlbmRvciBDZXJ0aWZpY2F0ZTCCASIwDQYJKoZI
5hvcNAQEBBQADggEPADCCAQoCggEBAK9BWCXeRIBlSRHiN+iYdRmqSeB2jFK0MJuy
6V1bSK2YYEuoUXdlwfbqKA28DhT+eTprygpsUkiECU0rkE405fEGzkc7j08h73Zsw
7qSJphppvGnA0FfgvPxvtILVKgMdZ55sS+RyhyWqQ5QoYB/9k/iCvZPQeHdtrGy3S
8Q7ScTp+0BC9Y41+BkWaO0gA1bX//gJDIL2/n4grYiCnYC6boQg+aW/dSL7t7QwYC
9Tqgy+vYLjem4pfRVV84T7ajcAFhX5wVdOhQdKNbOciYR4Vtjfnh2BqHTV7eJe+CK
10AN6Ig1e+Q4M4BuQK5e9Fsh91A13R/q7kH1HUTePerXyNaqP1v3ECAwEAAaNQME4w
11HQYDVR0OBBYEFCNxnVlIojl6HEQLYUZtzDi4aJaZMB8GA1UdIwQYMBaAFCNxnVlI
12ojl6HEQLYUZtzDi4aJaZMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEB
13ABozA60FTXVJ48baYLR8NNuEoT/oZPhWyd5rWfRVAAYNOLAb0Csu1NtzadmMap0j
143rVK4Rvv4Cf0cjrZsGWUXWJIY4Gp3qbgxk085WPFVq3fmKp5i10c4WR1x39cSeWF
15QuzyQdt/+XFim1RsuLzAWUSaHuIYfZTQe42r0ar/xYKg0/7VdRNiqVYhWeWzYtKj
16QZnHVSytF9xqHBUBl/f/EDejQjnsbYZ2tOSRe4f7SDyoUlBTEf/uFcquaGC7aLN5
17aejyVSlksmelP3fuUKugWGEIPMTzYOZMEfzYzdL2gdQtMFO7H4a36h0mWGCmnhcY
18/datDO9Rtg9/wkuSG8DoVO8=
19-----END CERTIFICATE-----
diff --git a/meta-signing-key/files/mok_sb_keys/wosign_ev_cert.pem b/meta-signing-key/files/mok_sb_keys/wosign_ev_cert.pem
new file mode 100644
index 0000000..a1fd851
--- /dev/null
+++ b/meta-signing-key/files/mok_sb_keys/wosign_ev_cert.pem
@@ -0,0 +1,35 @@
1-----BEGIN CERTIFICATE-----
2MIIGHDCCBQSgAwIBAgIQLbtRUsXGAdcMmhrabBAVBDANBgkqhkiG9w0BAQsFADBT
3MQswCQYDVQQGEwJDTjEaMBgGA1UEChMRV29TaWduIENBIExpbWl0ZWQxKDAmBgNV
4BAMMH0NBIOayg+mAmiBFViDku6PnoIHnrb7lkI3or4HkuaYwHhcNMTUwOTMwMDgx
5MzI4WhcNMTcxMTMwMDgxMzI4WjCCAaIxEzARBgsrBgEEAYI3PAIBAwwCQ04xGDAW
6BgsrBgEEAYI3PAIBAgwHQmVpamluZzEYMBYGCysGAQQBgjc8AgEBDAdCZWlqaW5n
7MR0wGwYDVQQPDBRQcml2YXRlIE9yZ2FuaXphdGlvbjEYMBYGA1UEBRMPMTEwMDAw
8NDUwMDM0MTI2MQswCQYDVQQGEwJDTjESMBAGA1UECAwJ5YyX5Lqs5biCMRIwEAYD
9VQQHDAnljJfkuqzluIIxDzANBgNVBBEMBjEwMDEwMjFGMEQGA1UECQw95YyX5Lqs
105biC5pyd6Ziz5Yy65pyb5Lqs5Lit546v5Y2X6LevOeWPt+acm+S6rOWkp+WOpkLl
11uqcxNeWxgjEzMDEGA1UECgwq6aOO5rKz6L2v5Lu256CU5Y+R77yI5YyX5Lqs77yJ
125pyJ6ZmQ5YWs5Y+4MSYwJAYJKoZIhvcNAQkBFhdqaWEuemhhbmdAd2luZHJpdmVy
13LmNvbTEzMDEGA1UEAwwq6aOO5rKz6L2v5Lu256CU5Y+R77yI5YyX5Lqs77yJ5pyJ
146ZmQ5YWs5Y+4MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqvi3zCGT
154JfzNi3f8GsiAeDcnNxDtq3WUeC19YMOuDJe6i7E4EZhF29gBlsAVowmQUU+AWFA
16RehMpBtIe3ZV55luI9SOU9cXd89hB3uYuK8fwU0tEnJrzoT0H0oXGLp8Zk6jIA6c
1735s7PEgknj34nqo1zJ96xJYL3a8RCASqtdAGZsNoQRkaDIgAFMrPd6nqzOKTaiMg
18hRKpF732AsXoVoknVzsbPVc+3WhRjxksfgdcyKmeggvnisyV8kBQGFsjlCLFLENF
196chSLLXXwLDGs7tI9AoeD8BjOcIdMX2wOadDYu4fSQq4fuoMW5v13feH5AyoRY35
208ZaLPIzRB5lRVwIDAQABo4IBmTCCAZUwDgYDVR0PAQH/BAQDAgeAMBMGA1UdJQQM
21MAoGCCsGAQUFBwMDMAkGA1UdEwQCMAAwHQYDVR0OBBYEFBVbHhL0x538UGntIcgw
22HcJrYpySMB8GA1UdIwQYMBaAFBVBV5kt2EOSOn0PsmjUIQU3X2GjMGkGCCsGAQUF
23BwEBBF0wWzAqBggrBgEFBQcwAYYeaHR0cDovL29jc3AyLndvc2lnbi5jbi9jYTIv
24Y3M0MC0GCCsGAQUFBzAChiFodHRwOi8vYWlhMi53b3NpZ24uY24vY2EyLmNzNC5j
25ZXIwMwYDVR0fBCwwKjAooCagJIYiaHR0cDovL2NybHMyLndvc2lnbi5jbi9jYTIt
26Y3M0LmNybDA1BgNVHREELjAsoCoGCCsGAQUFBwgDoB4wHAwaQ04tQmVpamluZy0x
27MTAwMDA0NTAwMzQxMjYwTAYDVR0gBEUwQzALBgkrBgEEAYKbUQIwNAYFZ4EMAQMw
28KzApBggrBgEFBQcCARYdaHR0cDovL3d3dy53b3NpZ24uY29tL3BvbGljeS8wDQYJ
29KoZIhvcNAQELBQADggEBABo0pAyUNJIlRgkL2gMrUkLcOcq+7rr5UsOLiabLBg+M
30P7K+AB6+/wSz2J0jqQiaWFl9cZasq3KgTPMo2zs3QH3Qgyd6/B30GgLLSvU5xXxU
311yRkJpZSIsSo5g7SoXA3FNQz63fN0BLF+WnKqCU11kKTAegCtK57lErx5vRlBNIH
32/MJ7BI25T37w+ZERKa2Ugt0FukWvCWLLN2x2PwNaSY9ztmKdeLzTrtSy0X49jXVn
33juzT0NhmYwJaKhYADgvMUP+pGn3Aj/Ie64vkEjFS+m7HpnL/vbmgffH6lwa6oXxL
3401mxv7R9SkyuWq9gtdGJ+prDT0dPrHeXb3M6uQeE0x0=
35-----END CERTIFICATE-----
diff --git a/meta-signing-key/files/system_trusted_keys/system_trusted_key.key b/meta-signing-key/files/system_trusted_keys/system_trusted_key.key
new file mode 100644
index 0000000..e63900a
--- /dev/null
+++ b/meta-signing-key/files/system_trusted_keys/system_trusted_key.key
@@ -0,0 +1,28 @@
1-----BEGIN PRIVATE KEY-----
2MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC7aRl34d6FNFwN
3/J9OuDG0vh7aOM4Acs46/4lDKzxeSGxfNCmxXWhEG6M3rDU6nfy09vqMhuLyLgMP
4kMum47yFqufP4XRIb3aJYkjRYRUtzHo8CoZR80SoG778RlnvMekIE51yps/wR9/9
5AjY21PejZvXppkVXNtaiB4BP0tIu+a/5D8+jmiBus5ZtzkmFghUfTRuT+QdoQuC4
6gtqDBbz7WQTzryqESbIL9kkPLQFbOwETJwfur40hmkH+yDxlBURuod8A4Ne0jJt7
7gfFZBk3cgwlP/EOsJndlIAsnC8lgNfvji1lx9XOQGCj5X24wqRFstvkmpi/Ha7uJ
8UEjn59KjAgMBAAECggEACGJnVUmxntv80lNe/TKYZrGqx7CK5tI8D7+m8G5awQ0U
9bB31T44SQBnMb40wxHKU/7Oc+fR+6r7MPEIKGmlN4d0HifFYNnVmJDdVcqiZPfdL
108Ku33qq3g53aKYcsNttQxZ+7B4oW+3T7vGIA8usMOS8+CTn7GC/H4m/bebbA2IEX
11cF9RfypsDoI1vHJ5w6S9g+Y+/DaiOWUoYHu5N6aNJbWmuGskpoRiPWrNY2t9mm9G
127HHLxz6/6g2OCbHH7zXXYdkMoF9sCiTrc9IaMttQ1hrPdVf/OVAK9QkO9+Si+iFv
13hNTrfoSB3QQG0pbxlI/g2lNj15mr/gPiZpshAVXWIQKBgQD4wX4kIuVvF5+2TAoh
14qURtyllNpjinHl1CGHoHLvJbhVksNnRAjmrtWNHUOEE5Z8ClRdouo1+RYVTMfMRl
1510m+Il8fZxmeIKnKDfVSuN/qfNBDrHP24VBIfN2T6RDHXQG/VLjAKEmWiBaMsq3z
16BtCOsAAXAPacCGyV7FOxnacobwKBgQDA3kUFZGx3SI99D++ea5BTG1jVvyjwLU/8
17bhU//+0+KffGvym1FCoj4z9z8m9b3WX7yFkNlzpnP/fq69p8AuzkRe/CnqnaGIRh
18mnd9A43K+hj3OALWSEgD2vydk5TGv2nggdyy1QWWWZDRIjeUANsuYCRbxjVgFZ8R
19I6naTjILDQKBgD0dJIVyQVXiwu1Bjzen41Tp4rjN/psoPZcwdkJviUFs6HSRSExX
208PMw4BQ4YeXdlJnGKI1Ou/r2o6O9f27Zzpc00JPhe4y6z5wBg+T34KM2WOBXbQIZ
21ZuT4MGPXXbTtJ7G++cjT3QhrlMaqW0wav4BewxbjuLKq6yqGLiWz6s5nAoGBAJJt
22LcG2SJMXR7kPTEDeMSinbn55Lz+JZ1yixwdb6mZzvmXp5GRR9txgP2BsAxefsznB
23Fbs3wWN6MWLtxWa5Ydi9MBZ2F0Y5rufbOjRzakdcMXAf2ieNoP8sVvXbgeySjnOg
24pEoxaJiJT2U3sTJwo/dFjtUOWp+kSqvcg6v2ChBRAoGBANVyxieM/eG9qkOjVRi+
25KxZTR0VuouL6elwGnZp3WzdCv1Q3AJSe3EhDI0eJzQJzF11Ultl0qGRyIQfjmWwj
26vwN97ImedeD9L8K+9O4NCbBjpb68i1zQN8Nt/g6DJYOU7ygoUSZEVNfZFpt7Ni9O
27n/XCHesfBriZhlv7n6gkmFZy
28-----END PRIVATE KEY-----
diff --git a/meta-signing-key/files/system_trusted_keys/system_trusted_key.pem b/meta-signing-key/files/system_trusted_keys/system_trusted_key.pem
new file mode 100644
index 0000000..b730c97
--- /dev/null
+++ b/meta-signing-key/files/system_trusted_keys/system_trusted_key.pem
@@ -0,0 +1,19 @@
1-----BEGIN CERTIFICATE-----
2MIIDHTCCAgWgAwIBAgIJALu1KPLxuKZTMA0GCSqGSIb3DQEBCwUAMCUxIzAhBgNV
3BAMMGlN5c3RlbSBUcnVzdGVkIENlcnRpZmljYXRlMB4XDTE3MDYxMjAzNDU1OVoX
4DTI3MDYxMDAzNDU1OVowJTEjMCEGA1UEAwwaU3lzdGVtIFRydXN0ZWQgQ2VydGlm
5aWNhdGUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC7aRl34d6FNFwN
6/J9OuDG0vh7aOM4Acs46/4lDKzxeSGxfNCmxXWhEG6M3rDU6nfy09vqMhuLyLgMP
7kMum47yFqufP4XRIb3aJYkjRYRUtzHo8CoZR80SoG778RlnvMekIE51yps/wR9/9
8AjY21PejZvXppkVXNtaiB4BP0tIu+a/5D8+jmiBus5ZtzkmFghUfTRuT+QdoQuC4
9gtqDBbz7WQTzryqESbIL9kkPLQFbOwETJwfur40hmkH+yDxlBURuod8A4Ne0jJt7
10gfFZBk3cgwlP/EOsJndlIAsnC8lgNfvji1lx9XOQGCj5X24wqRFstvkmpi/Ha7uJ
11UEjn59KjAgMBAAGjUDBOMB0GA1UdDgQWBBQ+XtkvfIaRyIHPnU2eTlTgClRKZjAf
12BgNVHSMEGDAWgBQ+XtkvfIaRyIHPnU2eTlTgClRKZjAMBgNVHRMEBTADAQH/MA0G
13CSqGSIb3DQEBCwUAA4IBAQBtUkdB4iPnBXvJY9O68canmzryOby/RE5PLQiMvCy4
141zY9vH+VBZunAyijLkfP9jzuIIxBBU2QPVzAocOxoS2ie2lvfmbxRzX1d72mKdib
15Oq7BJ8wyscbsSFhAb4UcTsfwYyzM2IIa5uh8nG7caiMPv93XVWdu7KWA4xM0BqIU
16p1fV9+iUxdWrXDMQJPy+2qWdMTMo6hinyOx0CE7Hh9aTaH33C8/Tq6lDoSmVINog
1783+/bcbGObfkkFukhu2uynnkt7txxBQqdBkYGpvUpvF2CxZPhjwVjDx9W4Gujfqm
18QpBhMoXL0b1JhwsJE9EWsaLRXmP+RTKdt0F8PYOqOT0g
19-----END CERTIFICATE-----
diff --git a/meta-signing-key/files/uefi_sb_keys/DB.key b/meta-signing-key/files/uefi_sb_keys/DB.key
new file mode 100644
index 0000000..499fba1
--- /dev/null
+++ b/meta-signing-key/files/uefi_sb_keys/DB.key
@@ -0,0 +1,28 @@
1-----BEGIN PRIVATE KEY-----
2MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDCEEXcSeC4C6Zd
30fVak+6IooUG9OKF0iEJAc+5juFi7Ly7k5v0LnvMPleCASSYbiHc4wSRaIxcr60v
41pDyf1XQW+gqQ4AI4YyinAt0CLZxTiXsykeyqsBYq54ABFnEfj2I6ztBucGCjIJc
5OY07IMZhCESN4IRNs13hUFHN0cMfSgE1fYboCDy6fbyaeOLhZwOOfiWp4A2f7a2O
6NLa1v9iJmO3Ps7BVYqa7N5OrOJr2voekq3ziCWqNibPaIeyLPSQuWShotgoUFEeP
7ejGp7fUC0dVkWPf4OefCftC4zmvRiyIeIzo4JXF8K5NaPeHakWgvRko+xD5A0sCy
8AFq3JJaxAgMBAAECggEAWqDa30upJIpcQYhh+tEHHsw3L86BU1mUj+5GojO10ksY
9wMjolhp3OiULHO2Ht6AHNG7YnUej9U0dpi+gNX9+BfZF8CbhzkP3N6GEP8Yp3bRP
10RcwZu7i+ZyqOeRePDJKgDic83y7uzhbsckF2UVy3CG2iBlgJsXfIqgamjWYep6dJ
11T1CgizWH4pJmruFw5MPGSsVnbo5OCNnJ51z1y8aozVfA9X+KTPPR5eG0DXb7ok+m
12aC4s5OSHrEuYhKDKb5axdVMOqim2VM+8ghRKsqe8ccyIOS7/5Oahp5vzHFB4ZRcH
13lV+Yew8Q1xdAAQ+0BVwQqvZv12QkZbCe75887mLBIQKBgQDuRQsN+/heoHE9SkG/
14+oSxKKPFWa5HSnolOFw3PjC7c0eD4RgcOHJbjII3EvvPrxDCjGV0yGhQeT6UGS2t
15iDrN42E+r1atzOin3JtxX0sEorOtp4B/BXPHYswv//VJOnsIzlMOuqgbmPjPRM+o
16CQgCg+e3U+xYBS8I15dnRv4ZPQKBgQDQgR4taPECuFm9e74Wyd7vDtlwDisUC770
17xzWM3E/9wRSV5sZFomZKiFPiQ6o9teTNLRzaa/TOywLMgnYV9MwG3VczNAqO7aM5
18K3YBhpazeFDtQaDOkR+0SZGmQc9XxkJuFvWCeWUUZKUDnexATOTNg0t6y8Lwo8Av
19bZ8Y5ZsChQKBgQDLnkkyLDA2fZoILJs/upEG7Jn4HwmmduknQaDcvNLcfkmRVB1M
20kJh5z/u/oQN8mjkSaPSS9mjezJ5D5bh5YcAPDs+dyC2k3UW9nfNg0XTEg15Vep1+
2172Pf8nhYVL6DU+ysu9WS8sSSwQlv53gmO4GS1LKCor+JAPUO8165rZucaQKBgH69
22jbdyq9XIc5xPhKvbh+zurNOFeUAVJ70o/m8iWGlaHYZFIk6fuegiWEMYeHpMf8kM
23XBaVOtkc5BWmU9ti00Z08xWH08cvwmD0/yVMR3zObPrbQsFty8TOV3+lT0D+ndDH
24mfL2ka/Ewd2h+ELZutcFsTLyewvFrgPmcagzoXb1AoGBAJcp2UyWWxwkn2TI5A95
25vhcH1lNLYG+KCZd4iR8Ynj6tRjNFFsZwiTaxuRdWI7PSm41GMnJVdrx7qlsPUnDb
261FYUVCB3aR93+TEgsVXrMSKGZ97f4MP8nJE5Ml2vFkKAXWHX5FtIxtS/Vd/LPAZa
27JtMPM2x3OiIj3MeQfCK6q9tD
28-----END PRIVATE KEY-----
diff --git a/meta-signing-key/files/uefi_sb_keys/DB.pem b/meta-signing-key/files/uefi_sb_keys/DB.pem
new file mode 100644
index 0000000..3517ddc
--- /dev/null
+++ b/meta-signing-key/files/uefi_sb_keys/DB.pem
@@ -0,0 +1,17 @@
1-----BEGIN CERTIFICATE-----
2MIICpzCCAY8CAQEwDQYJKoZIhvcNAQELBQAwGjEYMBYGA1UEAwwPS0VLIENlcnRp
3ZmljYXRlMB4XDTE3MDUxODAxNTM1N1oXDTI3MDUxNjAxNTM1N1owGTEXMBUGA1UE
4AwwOREIgQ2VydGlmaWNhdGUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB
5AQDCEEXcSeC4C6Zd0fVak+6IooUG9OKF0iEJAc+5juFi7Ly7k5v0LnvMPleCASSY
6biHc4wSRaIxcr60v1pDyf1XQW+gqQ4AI4YyinAt0CLZxTiXsykeyqsBYq54ABFnE
7fj2I6ztBucGCjIJcOY07IMZhCESN4IRNs13hUFHN0cMfSgE1fYboCDy6fbyaeOLh
8ZwOOfiWp4A2f7a2ONLa1v9iJmO3Ps7BVYqa7N5OrOJr2voekq3ziCWqNibPaIeyL
9PSQuWShotgoUFEePejGp7fUC0dVkWPf4OefCftC4zmvRiyIeIzo4JXF8K5NaPeHa
10kWgvRko+xD5A0sCyAFq3JJaxAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAF24d314
11tT5RC22vouFCwfaqQgMlejs/nAg1NIZU/PL2r7HtXsB18K+vT3zdslvtzDlSnI7L
12UTg+z7VBg3lCnH6wfJbnuLEUKJH3rdb5x83M+C6lPIc4lrxgjl+n1RrlaUOwUlBp
134rd8OcqLFmnuX36gfQ1Z5yYjfcAI/vStptrQjQ0kKmTRdqS2//0aKURkouvZeJOx
14ddbdAyzANordmdWorqhSrHt+nj4pm5btlPGw5lSw1G0nm+3weYC7YNbs0SvRXomW
15RwsEy5BpFbtGTH1pe9MBMpJXYL9lJ7Kd76DIFBEGy7wyR63ggKyEq7cd3o0cT6VR
16yFY0sjzcS3llwfs=
17-----END CERTIFICATE-----
diff --git a/meta-signing-key/files/uefi_sb_keys/DBX/DBX.key b/meta-signing-key/files/uefi_sb_keys/DBX/DBX.key
new file mode 100644
index 0000000..9001f0b
--- /dev/null
+++ b/meta-signing-key/files/uefi_sb_keys/DBX/DBX.key
@@ -0,0 +1,28 @@
1-----BEGIN PRIVATE KEY-----
2MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCcmAgStdSkmQrg
3bxa2bNmIP5hWQcbMGB5XNuZ3AnlCR9jjU/OatFTaTonfgiRq1UyTgeVnshHEbciF
4/Auz7QCJiKArM5qCWnnfQXj3DHOW0uznMmkFGkovpzYMDHxr6Gx6TZfYCyQt8R+N
5u5mg/6hl9JWIXRM3fCTyGIp/zo3Yj9Q6JXLUuyRcHKFEpUSErrGtC0yizUNiTu38
6GPTxS5I8zvs6gFW9KKQa8X4d+f+1WuXXrEj4WqybGNdf4SzoPlkau8haXEDuAabE
7/sQwj+bQNTvWDiMGEEY6l/WpFXEEdSnbBDOhoJnlWNaU8hbu7eRH/BE8WBVSs8Kw
8TLlqJ+8XAgMBAAECggEAFjxYWR/MtBqvOrNLjFfkg75UCVuJuQ1rsYKwMxH82faN
9y6nuG3ej3OPuG/jE5w6mswNs6c6VS0kzgiMKHmB3BRCLfdb0B7KFP7hyTtJLz4zf
106uxzkS/sfNvHhup2+HOmg69k8l6SoptsmZmb9QqYhPG4Egb1ZZmRPXdSo1dXOPrq
11jeofrH6ZrVXxKmHhZYPZ0VE8jjVKaNzQuAb15KyEb/vYf6fUFKBDm/b1myOCy06c
12WUs78nqgX3iW9P+4mL2CuuI6Dq1/Ja97qA+iepzF8SJte8HMVHfom8iI1dWrg5mr
13UiTyGlVpwvwGdqnhXwXGLyFK0VUNLuB5RIFpaNvnoQKBgQDMjjp4OTvDdoSgcIY+
14VRlpCe9VuageHbyMUybQfrCBgubNnWZcU8VI+n8f8Rj6xfIZlVNBNROmdUqWWGPE
15tkh2n5bsfSgV452uR48QelsH5TDcgTjJRtJry+9zOOgFPKrH6mNidl6PWiPPM7ga
16skch43tbqog40IAb39tNRmFYOQKBgQDD+epGZ9Pv1gi4zP68CbI94F7exeHzhvH1
17sOCX/wBEtGW3crp4RXOiiL7o+9O06odz2PG6FbvqFe8WkQRSq5pZT0SiLhfIlJQ9
18Yql00a5kEJWahqUKydqEAcz4ON7DR5DAy+x128UXknm08YerjigvI4pk1zGPQ9IL
19lKyt7yRhzwKBgA+EytLMJMiTeURixQx9kEvzwQCT8Tk3sFJFDLDMq79nmvMGefmP
20MWxz9KkLtYVw9wkR1xsfV7pNM7dsRUVrPtwhB2YxqJTgi9no++WYIsfaj3ZrJ0+9
2128Dp2+S18IRVMe+wzJFvwYTGpejWV6VO2S6s/3LY4TTOPKngtdaK/F+hAoGASbPI
22dpf/rbgZ6Z42wvMGlJy4MSHMezCp+JN/s8oUCMKralV8aVT9SwgQfECQ+v4k2N2i
238y/PTxbWpu786DZfQu07y554FVhDc96SCjv9UOanzMiMc0U8p96hfkytAlX8y3Ul
24xaFUOyw8F1+qfUtmM2wzVP9VRSLlcLOGSZehYCMCgYA1saH1W+X4VFVUZMPBKirP
25UldaTtUtyNfarAJwEq4rqLkhJfQoVsxjNcuUEqzpJXUihhny6XYvmb7QDv48P5Fn
2683a2UEdasMfTN+zqvT273vn6zrSbNzJ1f/e1Z4T0h4ntwaQ/W0f197nWEWz6Mq+U
27P9YtEC1cRbX6RPM5BereZA==
28-----END PRIVATE KEY-----
diff --git a/meta-signing-key/files/uefi_sb_keys/DBX/DBX.pem b/meta-signing-key/files/uefi_sb_keys/DBX/DBX.pem
new file mode 100644
index 0000000..b62663e
--- /dev/null
+++ b/meta-signing-key/files/uefi_sb_keys/DBX/DBX.pem
@@ -0,0 +1,19 @@
1-----BEGIN CERTIFICATE-----
2MIIDBzCCAe+gAwIBAgIJAKJQcC+EJo1hMA0GCSqGSIb3DQEBCwUAMBoxGDAWBgNV
3BAMMD0RCWCBDZXJ0aWZpY2F0ZTAeFw0xNzA1MTgwMTU0MzNaFw0yNzA1MTYwMTU0
4MzNaMBoxGDAWBgNVBAMMD0RCWCBDZXJ0aWZpY2F0ZTCCASIwDQYJKoZIhvcNAQEB
5BQADggEPADCCAQoCggEBAJyYCBK11KSZCuBvFrZs2Yg/mFZBxswYHlc25ncCeUJH
62ONT85q0VNpOid+CJGrVTJOB5WeyEcRtyIX8C7PtAImIoCszmoJaed9BePcMc5bS
77OcyaQUaSi+nNgwMfGvobHpNl9gLJC3xH427maD/qGX0lYhdEzd8JPIYin/OjdiP
81DolctS7JFwcoUSlRISusa0LTKLNQ2JO7fwY9PFLkjzO+zqAVb0opBrxfh35/7Va
95desSPharJsY11/hLOg+WRq7yFpcQO4BpsT+xDCP5tA1O9YOIwYQRjqX9akVcQR1
10KdsEM6GgmeVY1pTyFu7t5Ef8ETxYFVKzwrBMuWon7xcCAwEAAaNQME4wHQYDVR0O
11BBYEFOtvhQzmM47hXRy34LGHwxCepaMMMB8GA1UdIwQYMBaAFOtvhQzmM47hXRy3
124LGHwxCepaMMMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAGcaSshH
13NmzvPVRPUsQPXnnnAfFT2/SUACChxQvV6Cdv2ZTsnfSeq5Qic1XBI4w0qGfevv69
14pE6tMjg3t9H3+WFUsGugjkRB2i6oyDI3d7okFXRKPYP0Zagm64HAGG+p76j694Rj
15cnKL85wXmkY1X5sE/pxCBOiAsLH8yhC8jJCUCRKPxpLC3iD6bOLO57DNSYaucIke
16BNqf2NQaQFTEeE8ELqArPVpi9iTRQotfmpoUrt/zt0l7kKe38qOZD1WwwoFJB7eY
17OpPS/8sxxx5ym8YKd9I5HF2MwzDHNZZNOIRXPFkVVgDLTWsrQjHI2ppxXcZHVPhp
183FQb+KhWL0nkb5M=
19-----END CERTIFICATE-----
diff --git a/meta-signing-key/files/uefi_sb_keys/KEK.key b/meta-signing-key/files/uefi_sb_keys/KEK.key
new file mode 100644
index 0000000..3759464
--- /dev/null
+++ b/meta-signing-key/files/uefi_sb_keys/KEK.key
@@ -0,0 +1,28 @@
1-----BEGIN PRIVATE KEY-----
2MIIEwAIBADANBgkqhkiG9w0BAQEFAASCBKowggSmAgEAAoIBAQDTGE3U05B+weQu
37XQ4aX4y99pn/kjs4+Kq6BYOX2+gaaisxW7ZO4okeXwRGD0h/LGjN6hfqXhTl0Il
44ztx/ofIuB4nklVhTolsFrqvILBleoNo/gSK3oUXJvqbrfHNLWBLaaIpznQk+Rmf
55mqUJ2EdXuakF5jfNFLICRMi3Mt8+SQfSbZf1EVb16h79GvyHd/Lx3rKU0cAmGJK
62Idg3lFdfZ4IuX96PTf1oH/MpYvgJnJU7+OpfgT1Oeq7d/lXAm/wevERfkQ77kyb
7cYQPg+upfQKXprM3oq+HAqcbwZg3F2q++QeO62Z8DtYDpzWdCOz142bSHojUnzaV
81ZdjNz9LAgMBAAECggEBAKuk4nyAfsijDdCeodbQ6J227W+L025TqlZ/mpebQF/2
9KgI6E3UttZkM8zXPOL4vA54MvqryWPXXUyENkKOTbINoOpTApw4VVyZ9oNSPxv7s
10zHeNvNHSN/PobPQzTx8fm2IWhZZq2gPKTOy45caL8qp4JSAeU96CZCFlR5scX5XA
11YQHOEctofv4r+TZRWoNFKylUZ9y+bPc8VXPi4dEdbnv/IkT3TOJE+vthsYLOh0eN
12ankKDtBviK7/0PNXCQ4mthss67e+SquSd+JBGIgcTL231s+18LkyiIWETuO07fip
13dpk1lBg2QybjhaarIRhvdD4vuwTKnUqlJthBcqUCgbECgYEA9ARigUFQIHsQxLLT
14TCkmSFeEcCqsvp91g7xcUnasDAnk4Ju6gwZYu3r+nKozXClLUUJkwMjdePYSSfj7
15LVnWskE0jjw1uWGIwcivexBo7G1JqJiuj+7MOhYxagUnfEpYU/Zp5auBGn9+/531
160L1NWFz7c0usyEYrLK/xHVPF4AMCgYEA3XYLTUQ+z5brpK8OLs3atnYm5NvVZGxV
17N3o5omcUbO70brd2/Zkei81R/NzCVfaaBAe1O/2H9Z6aC3+3g57l/s7ilWgJJGE5
18kHgj7B5jzpqwAzuz20lSWuc3pfCvWCKcjUVMevXO2PMNMLdY9CLMdCD6s0Tt4w/y
19lUY5vkyBdRkCgYEAnn7anKoXqYFF+v1MUYPI4eQ2mcSeP5LDebW3IbkDNy6WA24j
20T0eoCt5w0sGaappH2ZgOaUoO0KrEZlfajjJ0SYQg5uIk4yx+75+ym3SlMiwqU+AY
21QlURQgl4Pyzp4MlJZf//+LXVPajijJXFPLg4rNR4XwMgT1WEZZpCOpJXTJECgYEA
22oxGltspWucK2VvgzqFEaCBqt/vzEf4KpqQUN5UCjsKavQ8tCCfAyptyTz266hlPk
23Cq2mTLsd3sVfRrJPbdKWJm8uNrd5a9lPasqcIOQrt9j9XBQdFo5B3v+8YSr94hby
24Ua/CZhQTsHofr0yCapopFCWolFJgHD8E79fa8v4goRkCgYEAnxS6k4NfnzjQholq
25Sbb19bJUdUW6Go01mAqZ66DBQYV4run6elB7sGLkwgyo3GrriNFK1miIzS+J9jXb
26j79yhiDjMUPj0L6dzHVdeqgienFbOhRY4s5ArpPgNGPO77A4H/02qe4vbcCY1OK3
27FeovKglic0lRsV0YObbujiatznk=
28-----END PRIVATE KEY-----
diff --git a/meta-signing-key/files/uefi_sb_keys/KEK.pem b/meta-signing-key/files/uefi_sb_keys/KEK.pem
new file mode 100644
index 0000000..c27b01a
--- /dev/null
+++ b/meta-signing-key/files/uefi_sb_keys/KEK.pem
@@ -0,0 +1,17 @@
1-----BEGIN CERTIFICATE-----
2MIICpzCCAY8CAQEwDQYJKoZIhvcNAQELBQAwGTEXMBUGA1UEAwwOUEsgQ2VydGlm
3aWNhdGUwHhcNMTcwNTE4MDE1MzQ4WhcNMjcwNTE2MDE1MzQ4WjAaMRgwFgYDVQQD
4DA9LRUsgQ2VydGlmaWNhdGUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB
5AQDTGE3U05B+weQu7XQ4aX4y99pn/kjs4+Kq6BYOX2+gaaisxW7ZO4okeXwRGD0h
6/LGjN6hfqXhTl0Il4ztx/ofIuB4nklVhTolsFrqvILBleoNo/gSK3oUXJvqbrfHN
7LWBLaaIpznQk+Rmf5mqUJ2EdXuakF5jfNFLICRMi3Mt8+SQfSbZf1EVb16h79Gvy
8Hd/Lx3rKU0cAmGJK2Idg3lFdfZ4IuX96PTf1oH/MpYvgJnJU7+OpfgT1Oeq7d/lX
9Am/wevERfkQ77kybcYQPg+upfQKXprM3oq+HAqcbwZg3F2q++QeO62Z8DtYDpzWd
10COz142bSHojUnzaV1ZdjNz9LAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAGDBZKxx
11yMoEi5tkX11o0SYGOZu/ESsb5Py1PB7owbDBZpcjXqr6PdC3MKcSz1TkLRVGNiAn
12SOVeToT4GU662fhbqI1M+n/gIrcxSjs/U2ijbGyJZH9wRJFxuHZAaow3x6kPapFA
13sF3EWr6obp3PQaLmOvRcJXgvCy7Zq31pwoCdSLuSRaRbtb7ltMgf7OqYb47QKrdg
14U6opykf3h8rK9iopuuj1tfBzWqG0FYlctkHg9W4ehOy3da1kwoeFIikuACYZrqMN
15L8ABjseUtQut/yrTEcMRm0t/6Z13599xM6eORdGgv/zCE0OxtMiJoRceE9cBHABa
16y2K1leYM/Bz9ciY=
17-----END CERTIFICATE-----
diff --git a/meta-signing-key/files/uefi_sb_keys/PK.key b/meta-signing-key/files/uefi_sb_keys/PK.key
new file mode 100644
index 0000000..80288a3
--- /dev/null
+++ b/meta-signing-key/files/uefi_sb_keys/PK.key
@@ -0,0 +1,28 @@
1-----BEGIN PRIVATE KEY-----
2MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC3/v2TZgaYSy+s
3mDAkkfRgdsjasqx8q5jPUqjlxci35s8Mcj0uKnNSfoF3lKZnk7nN4mQshEEyFrP0
4dZt0NZhxsNBl7kutFDa88ETkwJIEhGSFzNFvw4bCAa+Ut9M+3coxt5mqFz06T1vU
5TQdY4BN7tZwEmXc2RftrNxEIb+y+P0XgXC9mfLLi0Au0fSUbOMQU/yYyLMrTuwvL
67+i8kxuK8iItoezge6P7RBmt56gVZT9QawY4urNcdxXHpLfBLmF9XmoOpr77/l/g
7KXWOQdX3XNym31xnlRucbmAziUnQd+ok8YKBGhe4O3Y8jrUY9s8YGDbdxfHxmjTP
84fyGHD6bAgMBAAECggEAZFzurIwmZMP+SULqX8hNaKDihoiXlZl0TQJlpo/wIIAB
9yGQ4AwqcxQ7ESBoJes4Vt7wZsD6j4VKI7nuIRCdH9BviUPdeyBYSlZTpv21bOKOO
10wX0rcK9Svlh1EcYDsHMCa4Qeia0LdNb83Bz4OP5hIkW5yLh9Ullx/tWWsOd8V3j2
11f7nrLQLmfxdcDMT/nnkgQH1IMDwaaVuKxnul0PY1UV6keiBcKW702WxTOx/ZrF09
12gbqEdu6nifQJAZ2+luC7EOw2QD4PHmSVPZrEwM5dcMn0Lg9yS6Ep7Nd4vRKPc1iB
13IqePP16ufZ4doj79i3Cd7H7RY2dQda6yoihb2hrsIQKBgQDqzjfZ3QMjQ751WyyU
14N7w929GOkV1liIOqCpgNx9lcmIE45JJzobBblOKwaTpctX3jIswnByfPgl5wCM5R
1589P1yFXG56JeuEdhNGKTYw76kRoXkwP0vMXkrd6Biq/CD/uLnl8BqhDSlIngK0Q3
162stDpbS8TqtdxeNF3prJTDKxhwKBgQDImrCAdG9AmrONUyYGgjPrIML4jUWuL01a
17AbDpC3+F46kZdfDr9JwlP/WO6WRb0LcjH/TvKsqO4vqxOGMSU4fzyZsiMIZma4E7
18GKCuz7aFldDXhlqHWuwp2vzLlABP0sL5wjwYsdAGLPhm4v8KN0eiuirkNt9QN8Bi
19SiRaexafTQKBgDRczpm4LtXzaorTTUq0bzdASShJBJH68pm+CRCxq6h5nf+pAXvl
205+VUe4UpwkkgdDVt8icV8mvVP+guHoyqGm+qQG6+AziqUci8nOsPYSzBpRbywyQV
214O/RUliDLBTT6Z3GMJu3aE79rw2duHXYRhIM5xRDWvXrhnZzYQNZCckLAoGAGwTS
22vwpvrZjolCFd3sSMr5+jAw0sFHDkjznpFQpqa6MlNHuxLmas3UuHDG+dB8zNzdpR
23CCGQVLx3nYUFuwMrLYe68Fju0T6rkkUX51OstsNd9Jlw+ggiBOUs5VKS1C2D+1XQ
24+FaCuUI3Vsw+I6cca+t9OW22mDxaGiL4UIOBoYUCgYA58IXBablXY8Va1o9b+RqJ
25sKMK/22hpunTbbfjDO2z6v8VR/ScLLGkeXnTquPoU5nVgh38Y61etAVLLBf0dw0r
26iDH9OQ4g+el6+mnRa9IqzznDhNF6XERkJ/pQC0EIz4lMejNl4vnDsxb25RVejY7f
27Ez0iGfy8zAgiaAhZM45JUQ==
28-----END PRIVATE KEY-----
diff --git a/meta-signing-key/files/uefi_sb_keys/PK.pem b/meta-signing-key/files/uefi_sb_keys/PK.pem
new file mode 100644
index 0000000..db659a5
--- /dev/null
+++ b/meta-signing-key/files/uefi_sb_keys/PK.pem
@@ -0,0 +1,19 @@
1-----BEGIN CERTIFICATE-----
2MIIDBTCCAe2gAwIBAgIJANpjqQyCduqsMA0GCSqGSIb3DQEBCwUAMBkxFzAVBgNV
3BAMMDlBLIENlcnRpZmljYXRlMB4XDTE3MDUxODAxNTMzOVoXDTI3MDUxNjAxNTMz
4OVowGTEXMBUGA1UEAwwOUEsgQ2VydGlmaWNhdGUwggEiMA0GCSqGSIb3DQEBAQUA
5A4IBDwAwggEKAoIBAQC3/v2TZgaYSy+smDAkkfRgdsjasqx8q5jPUqjlxci35s8M
6cj0uKnNSfoF3lKZnk7nN4mQshEEyFrP0dZt0NZhxsNBl7kutFDa88ETkwJIEhGSF
7zNFvw4bCAa+Ut9M+3coxt5mqFz06T1vUTQdY4BN7tZwEmXc2RftrNxEIb+y+P0Xg
8XC9mfLLi0Au0fSUbOMQU/yYyLMrTuwvL7+i8kxuK8iItoezge6P7RBmt56gVZT9Q
9awY4urNcdxXHpLfBLmF9XmoOpr77/l/gKXWOQdX3XNym31xnlRucbmAziUnQd+ok
108YKBGhe4O3Y8jrUY9s8YGDbdxfHxmjTP4fyGHD6bAgMBAAGjUDBOMB0GA1UdDgQW
11BBRAjBvvXvZI0+DrDAhBXG9PgvzocDAfBgNVHSMEGDAWgBRAjBvvXvZI0+DrDAhB
12XG9PgvzocDAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQCUiNwz1BGg
13KR82WfqIMB95uGOSo2aw91NM8lcBZgie/tH4BCjxGaJsoJJUs5+2Xj/COZRL6Z4K
14Jz6M3UdL5Gpdidx5wzHmhP0tlaD/Qq0e20Jlx2VBDniBdXP3EOmdxgPnjQIZxufB
15Vtft2woSYeu+1oz6Ahss8fiMlGYEV/EhCnd9Zxo9ErwiW8Jr49Ks9JcqvKj48uNJ
16JKyFxZkmIcWhhCIIoXVsfUEh/mKs/vuy0NIF3gStuwg2tJSIc58ut/bUtFKD5zoT
17AFglbbWY1fDa5IPtFPGKfMXnIXiEl+GXebuX+s36RLUffrnltfgVmqjLSwhTqymD
188mY8m0zY7h5V
19-----END CERTIFICATE-----
diff --git a/meta-signing-key/files/uefi_sb_keys/ms-DB.pem b/meta-signing-key/files/uefi_sb_keys/ms-DB.pem
new file mode 100644
index 0000000..d7c29ef
--- /dev/null
+++ b/meta-signing-key/files/uefi_sb_keys/ms-DB.pem
@@ -0,0 +1,35 @@
1-----BEGIN CERTIFICATE-----
2MIIGEDCCA/igAwIBAgIKYQjTxAAAAAAABDANBgkqhkiG9w0BAQsFADCBkTELMAkG
3A1UEBhMCVVMxEzARBgNVBAgTCldhc2hpbmd0b24xEDAOBgNVBAcTB1JlZG1vbmQx
4HjAcBgNVBAoTFU1pY3Jvc29mdCBDb3Jwb3JhdGlvbjE7MDkGA1UEAxMyTWljcm9z
5b2Z0IENvcnBvcmF0aW9uIFRoaXJkIFBhcnR5IE1hcmtldHBsYWNlIFJvb3QwHhcN
6MTEwNjI3MjEyMjQ1WhcNMjYwNjI3MjEzMjQ1WjCBgTELMAkGA1UEBhMCVVMxEzAR
7BgNVBAgTCldhc2hpbmd0b24xEDAOBgNVBAcTB1JlZG1vbmQxHjAcBgNVBAoTFU1p
8Y3Jvc29mdCBDb3Jwb3JhdGlvbjErMCkGA1UEAxMiTWljcm9zb2Z0IENvcnBvcmF0
9aW9uIFVFRkkgQ0EgMjAxMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
10AKUIbEzHRQlqSwykwId/BnUMQwFUZOAWfwftkn0LsnO/DArGSkVhoMUWLZbT9Sug
11+01Jm0GAkDy5VP3mvNGdxKQYin9BilxZg2gyu4xHye5xvCFPmop8/0Q/jY8ysiZI
12rnW17slMHkoZfuSCmh14d00MsL32D9MW07z6K6VROF31+7rbeALb/+wKG5bVg7gZ
13E+m2wHtAe+EfKCfJ+u9WXhzmfpR+wPBEsnk55dqyYotNvzhw4mgkFMkzpAg31Vhp
14XtN87cEEUwjnTrAqh2MIYW9jFVnqsit51wxhZ4pb/V6th3+6hmdPcVgSIgQiIs6L
1571RxAM5QNVh2lQjuarGiAdUCAwEAAaOCAXYwggFyMBIGCSsGAQQBgjcVAQQFAgMB
16AAEwIwYJKwYBBAGCNxUCBBYEFPjBa7d/d1NK8yU3HU6hJnsPIHCAMB0GA1UdDgQW
17BBQTrb9DCb2CcJyM1U8xbtUimIob1DAZBgkrBgEEAYI3FAIEDB4KAFMAdQBiAEMA
18QTALBgNVHQ8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAfBgNVHSMEGDAWgBRFZlJD
194X5YEb/WTp4jVQg7OiJqqDBcBgNVHR8EVTBTMFGgT6BNhktodHRwOi8vY3JsLm1p
20Y3Jvc29mdC5jb20vcGtpL2NybC9wcm9kdWN0cy9NaWNDb3JUaGlQYXJNYXJSb29f
21MjAxMC0xMC0wNS5jcmwwYAYIKwYBBQUHAQEEVDBSMFAGCCsGAQUFBzAChkRodHRw
22Oi8vd3d3Lm1pY3Jvc29mdC5jb20vcGtpL2NlcnRzL01pY0NvclRoaVBhck1hclJv
23b18yMDEwLTEwLTA1LmNydDANBgkqhkiG9w0BAQsFAAOCAgEANQhC/zDMzvd2DK0Q
24aFg1KUYydid87xJBJ0IbSqptgThIWRNV8+lYNKYWC4KqXa2C2oCDQQaPtB3yA7nz
25Gl0b8VCQ+bNVhEIoHCC9sq5RFMXArJeVIRyQ2w/8d56Vc5GIyr29UrkFUA3fV56g
26Ye0N5W0l2UAPF0DIzqNKwk2vmhIdCFSPvce8uSs9SSsfMvxqIWlPm8h+QjT8NgYX
27i48gQMCzmiV1J83JA6P2XdHnNlR6uVC10xLRB7+7dN/cHo+A1e0Y9C8UFmsv3maM
28sCPlx4TY7erBM4KtVksYLfFolQfNz/By8K673YaFmCwhTDMr8A9K8GiHtZJVMnWh
29aoJqPKMlEaTtrdcErsvYQFmghNGVTGKRIhp0HYw9Rw5EpuSwmzQ1sfq2U6gsgeyk
30BXHInbi66BtEZuRHVA6OVn+znxaYsobQaD6QI7UvXo9QhY3GjYJfQaH0Lg3gmdJs
31deS2abUhhvoH0fbiTdHarSx3Ux4lMjfHbFJylYaw8TVhahn1sjuBUFamMi3+oon5
32QoYnGFWhgspam/gwmFQUpkeWJS/IJuRBlBpcAj/lluOFWzw+P7tHFnJV4iUisdl7
335wMGKqP3HpBGwwAN1hmJ4w41J2IDcRWm79AnoKBZN2D4OJS44Hhw+LpMhoeU9uCu
34AkXuZcK2o35pFnUHkpv1prxZg1g=
35-----END CERTIFICATE-----
diff --git a/meta-signing-key/files/uefi_sb_keys/ms-KEK.pem b/meta-signing-key/files/uefi_sb_keys/ms-KEK.pem
new file mode 100644
index 0000000..37c814a
--- /dev/null
+++ b/meta-signing-key/files/uefi_sb_keys/ms-KEK.pem
@@ -0,0 +1,34 @@
1-----BEGIN CERTIFICATE-----
2MIIF6DCCA9CgAwIBAgIKYQrRiAAAAAAAAzANBgkqhkiG9w0BAQsFADCBkTELMAkG
3A1UEBhMCVVMxEzARBgNVBAgTCldhc2hpbmd0b24xEDAOBgNVBAcTB1JlZG1vbmQx
4HjAcBgNVBAoTFU1pY3Jvc29mdCBDb3Jwb3JhdGlvbjE7MDkGA1UEAxMyTWljcm9z
5b2Z0IENvcnBvcmF0aW9uIFRoaXJkIFBhcnR5IE1hcmtldHBsYWNlIFJvb3QwHhcN
6MTEwNjI0MjA0MTI5WhcNMjYwNjI0MjA1MTI5WjCBgDELMAkGA1UEBhMCVVMxEzAR
7BgNVBAgTCldhc2hpbmd0b24xEDAOBgNVBAcTB1JlZG1vbmQxHjAcBgNVBAoTFU1p
8Y3Jvc29mdCBDb3Jwb3JhdGlvbjEqMCgGA1UEAxMhTWljcm9zb2Z0IENvcnBvcmF0
9aW9uIEtFSyBDQSAyMDExMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
10xOi1ir+tVyawJsPq5/tXekQCXQcN2krldCrmsA/sbevsf7njWmMyfBEXTw7jC6c4
11FZOOxvXghLGamyzn9beR1gnh4sAEqKwwHN9I8wZQmmSnUX/IhU+PIIbO/i/hn/+C
12wO3pzc70U2piOgtDueIl/f4F+dTEFKsR4iOJjXC3pB1N7K7lnPoWwtfBy9ToxC/l
13me4kiwPsjfKL6sNK+0MREgt+tUeSbNzmBInr9TME6xABKnHl+YMTPP8lCS9odkb/
14uk++3K1xKliq+w7SeT3km2U7zCkqn/xyWaLrrpLv9jUTgMYC7ORfzJ12ze9jksGv
15eUCEeYd/41Ko6J17B2mPFQIDAQABo4IBTzCCAUswEAYJKwYBBAGCNxUBBAMCAQAw
16HQYDVR0OBBYEFGL8Q82gPqTLZxLSW9lVrHvMtopfMBkGCSsGAQQBgjcUAgQMHgoA
17UwB1AGIAQwBBMAsGA1UdDwQEAwIBhjAPBgNVHRMBAf8EBTADAQH/MB8GA1UdIwQY
18MBaAFEVmUkPhflgRv9ZOniNVCDs6ImqoMFwGA1UdHwRVMFMwUaBPoE2GS2h0dHA6
19Ly9jcmwubWljcm9zb2Z0LmNvbS9wa2kvY3JsL3Byb2R1Y3RzL01pY0NvclRoaVBh
20ck1hclJvb18yMDEwLTEwLTA1LmNybDBgBggrBgEFBQcBAQRUMFIwUAYIKwYBBQUH
21MAKGRGh0dHA6Ly93d3cubWljcm9zb2Z0LmNvbS9wa2kvY2VydHMvTWljQ29yVGhp
22UGFyTWFyUm9vXzIwMTAtMTAtMDUuY3J0MA0GCSqGSIb3DQEBCwUAA4ICAQDUhIj1
23FJQYAsoqPPsqkhwM16DR8ehSZqjuorV1epAAqi2kdlrqebe5N2pRexBk9uFk8gJn
24vveoG3i9us6IWGQM1lfIGaNfBdbbxtBpzkhLMrfrXdIw9cD1uLp4B6Mr/pvbNFaE
257ILKrkElcJxr6f6QD9eWH+XnlB+yKgyNS/8oKRB799d8pdF2uQXIee0PkJKcwv7f
26b35sD3vUwUXdNFGWOQ/lXlbYGAWW9AemQrOgd/0IGfJxVsyfhiOkh8um/Vh+1Gln
27FZF+gfJ/E+UNi4o8h4Tr4869Q+WtLYSTjmorWnxE+lKqgcgtHLvgUt8AEfiaPcFg
28sOEztaOI0WUZChrnrHykwYKHTjixLw3FFIdv/Y0uvDm25+bD4OTNJ4TvlELvKYuQ
29RkE7gRtn2PlDWWXLDbz9AJJP9HU7p6kk/FBBQHngLU8Kaid2blLtlml7rw/3hwXQ
30RcKtUxSBH/swBKo3NmHaSmkbNNho7dYCz2yUDNPPbCJ5rbHwvAOiRmCpxAfCIYLx
31/fLoeTJgv9ispSIUS8rB2EvrfT9XNbLmT3W0sGADIlOukXkd1ptBHxWGVHCy3g01
32D3ywNHK6l2A78HnrorIcXaIWuIfF6Rv2tZclbzif45H6inmYw2kOt6McIAWX+MoU
33rgDXxPPAFBB1azSgG7WZYPNcsMVXTjbSMoS/ng==
34-----END CERTIFICATE-----
diff --git a/meta-signing-key/recipes-support/key-store/key-store_0.1.bb b/meta-signing-key/recipes-support/key-store/key-store_0.1.bb
new file mode 100644
index 0000000..7b9572e
--- /dev/null
+++ b/meta-signing-key/recipes-support/key-store/key-store_0.1.bb
@@ -0,0 +1,122 @@
1DESCRIPTION = "Key store for key installation"
2LICENSE = "MIT"
3LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \
4 file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
5
6inherit user-key-store
7
8S = "${WORKDIR}"
9
10ALLOW_EMPTY_${PN} = "1"
11
12PACKAGES =+ " \
13 ${PN}-system-trusted-cert \
14 ${PN}-ima-cert \
15 "
16
17# Note any private key is not available if user key signing model used.
18PACKAGES_DYNAMIC += " \
19 ${PN}-ima-privkey \
20 ${PN}-system-trusted-privkey \
21 ${PN}-rpm-pubkey \
22 "
23
24KEY_DIR = "${sysconfdir}/keys"
25# For RPM verification
26RPM_KEY_DIR = "${sysconfdir}/pki/rpm-gpg"
27
28# For ${PN}-system-trusted-privkey
29SYSTEM_PRIV_KEY = "${KEY_DIR}/system_trusted_key.key"
30
31# For ${PN}-ima-privkey
32IMA_PRIV_KEY = "${KEY_DIR}/privkey_evm.pem"
33
34# For ${PN}-system-trusted-cert
35SYSTEM_CERT = "${KEY_DIR}/system_trusted_key.pem"
36FILES_${PN}-system-trusted-cert = "${SYSTEM_CERT}"
37CONFFILES_${PN}-system-trusted-cert = "${SYSTEM_CERT}"
38
39# For ${PN}-ima-cert
40IMA_CERT = "${KEY_DIR}/x509_evm.der"
41FILES_${PN}-ima-cert = "${IMA_CERT}"
42CONFFILES_${PN}-ima-cert = "${IMA_CERT}"
43
44python () {
45 if uks_signing_model(d) != "sample":
46 return
47
48 pn = d.getVar('PN', True) + '-system-trusted-privkey'
49 d.setVar('PACKAGES_prepend', pn + ' ')
50 d.setVar('FILES_' + pn, d.getVar('SYSTEM_PRIV_KEY', True))
51 d.setVar('CONFFILES_' + pn, d.getVar('SYSTEM_PRIV_KEY', True))
52
53 pn = d.getVar('PN', True) + '-ima-privkey'
54 d.setVar('PACKAGES_prepend', pn + ' ')
55 d.setVar('FILES_' + pn, d.getVar('IMA_PRIV_KEY', True))
56 d.setVar('CONFFILES_' + pn, d.getVar('IMA_PRIV_KEY', True))
57
58 pn = d.getVar('PN', True) + '-rpm-pubkey'
59 d.setVar('PACKAGES_prepend', pn + ' ')
60 d.setVar('FILES_' + pn, d.getVar(d.getVar('RPM_KEY_DIR', True) + '/RPM-GPG-KEY-*', True))
61 d.setVar('CONFFILES_' + pn, d.getVar(d.getVar('RPM_KEY_DIR', True) + 'RPM-GPG-KEY-*', True))
62 d.appendVar('RDEPENDS_' + pn, ' rpm')
63}
64
65do_install() {
66 install -d "${D}${RPM_KEY_DIR}"
67
68 for f in `ls ${WORKDIR}/RPM-GPG-KEY-* 2>/dev/null`; do
69 [ ! -f "$f" ] && continue
70
71 install -m 0644 "$f" "${D}${RPM_KEY_DIR}"
72 done
73
74 key_dir="${@uks_rpm_keys_dir(d)}"
75 if [ -n "$key_dir" ]; then
76 for f in `ls $key_dir/RPM-GPG-KEY-* 2>/dev/null`; do
77 [ ! -s "$f" ] && continue
78
79 install -m 0644 "$f" "${D}${RPM_KEY_DIR}"
80 done
81 fi
82
83 install -d "${D}${KEY_DIR}"
84
85 key_dir="${@uks_system_trusted_keys_dir(d)}"
86 install -m 0644 "$key_dir/system_trusted_key.pem" "${D}${SYSTEM_CERT}"
87
88 if [ "${@uks_signing_model(d)}" = "sample" ]; then
89 install -m 0400 "$key_dir/system_trusted_key.key" "${D}${SYSTEM_PRIV_KEY}"
90 fi
91
92 key_dir="${@uks_ima_keys_dir(d)}"
93 install -m 0644 "$key_dir/x509_ima.der" "${D}${IMA_CERT}"
94
95 if [ "${@uks_signing_model(d)}" = "sample" ]; then
96 install -m 0400 "$key_dir/x509_ima.key" "${D}${IMA_PRIV_KEY}"
97 fi
98}
99
100SYSROOT_PREPROCESS_FUNCS += "key_store_sysroot_preprocess"
101
102key_store_sysroot_preprocess() {
103 sysroot_stage_dir "${D}${sysconfdir}" "${SYSROOT_DESTDIR}${sysconfdir}"
104}
105
106pkg_postinst_${PN}-rpm-pubkey() {
107 if [ -z "$D" ]; then
108 keydir="${RPM_KEY_DIR}"
109
110 [ ! -d "$keydir" ] && mkdir -p "$keydir"
111
112 # XXX: only import the new key
113 for keyfile in `ls $keydir/RPM-GPG-KEY-*`; do
114 [ ! -f "$keyfile" ] && continue
115
116 ! rpm --import "$keyfile" && {
117 echo "Unable to import the public key $keyfile"
118 exit 1
119 }
120 done
121 fi
122}
diff --git a/meta-signing-key/scripts/create-user-key-store.sh b/meta-signing-key/scripts/create-user-key-store.sh
new file mode 100755
index 0000000..1d0803c
--- /dev/null
+++ b/meta-signing-key/scripts/create-user-key-store.sh
@@ -0,0 +1,144 @@
1#!/bin/bash
2
3KEYS_DIR="`pwd`/user-keys"
4
5function show_help()
6{
7 cat <<EOF
8$1 - creation tool for user key store
9
10(C)Copyright 2017, Jia Zhang <lans.zhang2008@gmail.com>
11
12Usage: $1 options...
13
14Options:
15 -d <dir>
16 Set the path to save the generated user keys.
17 Default: `pwd`/user-keys
18
19 -h|--help
20 Show this help information.
21
22EOF
23}
24
25while [ $# -gt 0 ]; do
26 opt=$1
27 case $opt in
28 -d)
29 shift && KEYS_DIR="$1"
30 ;;
31 -h|--help)
32 show_help `basename $0`
33 exit 0
34 ;;
35 *)
36 echo "Unsupported option $opt"
37 exit 1
38 ;;
39 esac
40 shift
41done
42
43echo "KEYS_DIR: $KEYS_DIR"
44
45UEFI_SB_KEYS_DIR="$KEYS_DIR/uefi_sb_keys"
46MOK_SB_KEYS_DIR="$KEYS_DIR/mok_sb_keys"
47SYSTEM_KEYS_DIR="$KEYS_DIR/system_trusted_keys"
48IMA_KEYS_DIR="$KEYS_DIR/ima_keys"
49
50create_uefi_sb_user_keys() {
51 local key_dir="$UEFI_SB_KEYS_DIR"
52
53 [ ! -d "$key_dir" ] && mkdir -p "$key_dir"
54
55 # PK is self-signed.
56 openssl req -new -x509 -newkey rsa:2048 \
57 -sha256 -nodes -days 3650 \
58 -subj "/CN=PK Certificate for $USER@`hostname`/" \
59 -keyout "$key_dir/PK.key" \
60 -out "$key_dir/PK.pem"
61
62 # KEK is signed by PK.
63 openssl req -new -newkey rsa:2048 \
64 -sha256 -nodes \
65 -subj "/CN=KEK Certificate for $USER@`hostname`" \
66 -keyout "$key_dir/KEK.key" \
67 -out "$key_dir/KEK.csr"
68
69 openssl x509 -req -in "$key_dir/KEK.csr" \
70 -CA "$key_dir/PK.pem" -CAkey "$key_dir/PK.key" \
71 -set_serial 1 -days 3650 -out "$key_dir/KEK.pem"
72
73 rm -f "$key_dir/KEK.csr"
74
75 # DB is signed by KEK.
76 openssl req -new -newkey rsa:2048 \
77 -sha256 -nodes \
78 -subj "/CN=DB Certificate for $USER@`hostname`" \
79 -keyout "$key_dir/DB.key" \
80 -out "$key_dir/DB.csr"
81
82 openssl x509 -req -in "key_dir/DB.csr" \
83 -CA "$key_dir/KEK.pem" -CAkey "$key_dir/KEK.key" \
84 -set_serial 1 -days 3650 -out "$key_dir/DB.pem"
85
86 rm -f "$key_dir/DB.csr"
87}
88
89create_mok_sb_user_keys() {
90 local key_dir="$MOK_SB_KEYS_DIR"
91
92 [ ! -d "$key_dir" ] && mkdir -p "$key_dir"
93
94 openssl req -new -x509 -newkey rsa:2048 \
95 -sha256 -nodes -days 3650 \
96 -subj "/CN=Shim Certificate for $USER@`hostname`/" \
97 -keyout "$key_dir/shim_cert.key" -out "$key_dir/shim_cert.pem"
98
99 openssl req -new -x509 -newkey rsa:2048 \
100 -sha256 -nodes -days 3650 \
101 -subj "/CN=Vendor Certificate for $USER@`hostname`/" \
102 -keyout "$key_dir/vendor_cert.key" -out "$key_dir/vendor_cert.pem"
103}
104
105create_system_trusted_keys() {
106 local key_dir="$SYSTEM_KEYS_DIR"
107
108 [ ! -d "$key_dir" ] && mkdir -p "$key_dir"
109
110 openssl req -new -x509 -newkey rsa:2048 \
111 -sha256 -nodes -days 3650 \
112 -subj "/CN=System Trusted Certificate/" \
113 -keyout "$key_dir/system_trusted_key.key" \
114 -out "$key_dir/system_trusted_key.pem"
115}
116
117create_ima_user_keys() {
118 local key_dir="$IMA_KEYS_DIR"
119
120 [ ! -d "$key_dir" ] && mkdir -p "$key_dir"
121
122 openssl req -new -x509 -newkey rsa:2048 \
123 -sha256 -nodes -days 3650 \
124 -subj "/CN=IMA Trusted Certificate/" \
125 -keyout "$key_dir/x509_ima.key" \
126 -outform DER -out "$key_dir/x509_ima.der"
127}
128
129create_user_keys() {
130 echo "Creating the user keys for UEFI Secure Boot"
131 create_uefi_sb_user_keys
132
133 echo "Creating the user keys for MOK Secure Boot"
134 create_mok_sb_user_keys
135
136 echo "Creating the system trusted keys"
137 create_system_trusted_keys
138
139 echo "Creating the user keys for IMA appraisal"
140 create_ima_user_keys
141}
142
143create_user_keys
144
diff --git a/meta-tpm/README.md b/meta-tpm/README.md
new file mode 100644
index 0000000..11cff2a
--- /dev/null
+++ b/meta-tpm/README.md
@@ -0,0 +1,59 @@
1### TPM 1.2
2This feature enables tpm 1.2 support, including kernel option changes to
3enable tpm drivers, and picking up packages trousers, tpm-tools,
4openssl-tpm-engine, tpm-quote-tools.
5
6### How to use TPM 1.2
7For TPM 1.2, the following typical steps can be performed to get the TPM
8ready for use:
9
10- Clear and enable TPM from the BIOS.
11- Take TPM ownership.
12 ```
13 # tpm_takeownership -y -z
14 ```
15- Change owner and SRK passwords. These password are used for the
16 access permission to other functions including generate keys.
17 ```
18 # tpm_changeownerauth -z -s -o
19 ```
20Then, you can use the TPM for a specific need, such as key generation,
21sealing encrypted data, etc.
22
23### openssl tpm engine for TPM 1.2
24openssl-tpm-engine package provides tpm engine lib for openssl applications.
25It is an interface between openssl applications and TPM hardware.
26
27- Wrap software key using the TPM engine
28 - If tpm is not owned, run "tpm_takeownership -y -z".
29 This also set tpm SRK and Owner password to well-known key.
30 You can then run tpm_changeownerauth to set new SRK and Owner password.
31 To reset SRK and Owner password to well-known key, run "tpm_changeownerauth -r -s -o".
32 - Generate tpm hardware key: (add -z for using well-known key)
33 ```
34 $ create_tpm_key rootkey.pem [-z]
35 ```
36 - Wrap software key into TPM storage:
37 $ openssl genrsa -out softkey.pem 1024
38 $ create_tpm_key -w softkey.pem -s 1024 rootkey.pem [-z]
39- Create a self-signed cert using the TPM engine
40 - Generate a TPM key and write it to a file:
41 ```
42 $ create_tpm_key <keyfilename>
43 ```
44- Make the openssl certificate request:
45 ```
46 $ openssl req -keyform engine -engine tpm -key <keyfilename> -new -x509 -days 365 -out <certfilename>
47 ```
48- How to use tpm engine lib
49The name of tpm engine library is libtpm.so.
50There is an enhencement to the original opensource code.
51Add an additional way to pass SRK passwork to libtpm.so,
52that is using environment variable "TPM_SRK_PW".
53For example:
54```
55 env TPM_SRK_PW=xxx openssl s_server ...
56```
57Note:
58- "env TPM_SRK_PW=#WELLKNOWN#" is used to pass well-known key.
59- Detail description about openssl-tpm-engine, please refer to the README in source code.
diff --git a/meta-tpm/conf/layer.conf b/meta-tpm/conf/layer.conf
new file mode 100644
index 0000000..e425b92
--- /dev/null
+++ b/meta-tpm/conf/layer.conf
@@ -0,0 +1,12 @@
1# We have a conf and classes directory, add to BBPATH
2BBPATH .= ":${LAYERDIR}"
3
4# We have recipes-* directories, add to BBFILES
5BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
6 ${LAYERDIR}/recipes-*/*/*.bbappend"
7
8BBFILE_COLLECTIONS += "tpm"
9BBFILE_PATTERN_tpm = "^${LAYERDIR}/"
10BBFILE_PRIORITY_tpm = "10"
11
12LAYERDEPENDS_tpm = "core"
diff --git a/meta-tpm/recipes-base/packagegroups/packagegroup-tpm.bb b/meta-tpm/recipes-base/packagegroups/packagegroup-tpm.bb
new file mode 100644
index 0000000..684a392
--- /dev/null
+++ b/meta-tpm/recipes-base/packagegroups/packagegroup-tpm.bb
@@ -0,0 +1,19 @@
1DESCRIPTION = "Basic packagegroup for TCG TSS and utilities that use it."
2LICENSE = "MIT"
3PR = "r0"
4
5inherit packagegroup
6
7RDEPENDS_${PN} = "\
8 trousers \
9 tpm-tools \
10 openssl-tpm-engine \
11 rng-tools \
12"
13
14RRECOMMENDS_${PN} = "\
15 kernel-module-tpm-rng \
16 kernel-module-tpm-tis \
17 kernel-module-tpm-atmel \
18 kernel-module-tpm-infineon \
19"
diff --git a/meta-tpm/recipes-kernel/linux/linux-yocto-rt_4.%.bbappend b/meta-tpm/recipes-kernel/linux/linux-yocto-rt_4.%.bbappend
new file mode 100644
index 0000000..8fbd7ba
--- /dev/null
+++ b/meta-tpm/recipes-kernel/linux/linux-yocto-rt_4.%.bbappend
@@ -0,0 +1 @@
include linux-yocto-tpm.inc
diff --git a/meta-tpm/recipes-kernel/linux/linux-yocto-tpm.inc b/meta-tpm/recipes-kernel/linux/linux-yocto-tpm.inc
new file mode 100644
index 0000000..276e154
--- /dev/null
+++ b/meta-tpm/recipes-kernel/linux/linux-yocto-tpm.inc
@@ -0,0 +1,6 @@
1FILESEXTRAPATHS_prepend := "${THISDIR}/linux-yocto:"
2
3SRC_URI += " \
4 ${@bb.utils.contains('DISTRO_FEATURES', 'tpm', \
5 'file://tpm.scc file://tpm.cfg', '', d)} \
6"
diff --git a/meta-tpm/recipes-kernel/linux/linux-yocto/tpm.cfg b/meta-tpm/recipes-kernel/linux/linux-yocto/tpm.cfg
new file mode 100644
index 0000000..ac18405
--- /dev/null
+++ b/meta-tpm/recipes-kernel/linux/linux-yocto/tpm.cfg
@@ -0,0 +1,17 @@
1..........................................................................
2. WARNING
3.
4. This file is a kernel configuration fragment, and not a full kernel
5. configuration file. The final kernel configuration is made up of
6. an assembly of processed fragments, each of which is designed to
7. capture a specific part of the final configuration (e.g. platform
8. configuration, feature configuration, and board specific hardware
9. configuration). For more information on kernel configuration, please
10. consult the product documentation.
11.
12..........................................................................
13
14CONFIG_TCG_TPM=y
15CONFIG_TCG_TIS=y
16CONFIG_TCG_ATMEL=y
17CONFIG_TCG_INFINEON=y
diff --git a/meta-tpm/recipes-kernel/linux/linux-yocto/tpm.scc b/meta-tpm/recipes-kernel/linux/linux-yocto/tpm.scc
new file mode 100644
index 0000000..90cfe56
--- /dev/null
+++ b/meta-tpm/recipes-kernel/linux/linux-yocto/tpm.scc
@@ -0,0 +1,4 @@
1define KFEATURE_DESCRIPTION "TPM 1.x enablement"
2
3kconf hardware tpm.cfg
4
diff --git a/meta-tpm/recipes-kernel/linux/linux-yocto_4.%.bbappend b/meta-tpm/recipes-kernel/linux/linux-yocto_4.%.bbappend
new file mode 100644
index 0000000..8fbd7ba
--- /dev/null
+++ b/meta-tpm/recipes-kernel/linux/linux-yocto_4.%.bbappend
@@ -0,0 +1 @@
include linux-yocto-tpm.inc
diff --git a/meta-tpm/recipes-tpm/openssl-tpm-engine/files/0001-create-tpm-key-support-well-known-key-option.patch b/meta-tpm/recipes-tpm/openssl-tpm-engine/files/0001-create-tpm-key-support-well-known-key-option.patch
new file mode 100644
index 0000000..67071b6
--- /dev/null
+++ b/meta-tpm/recipes-tpm/openssl-tpm-engine/files/0001-create-tpm-key-support-well-known-key-option.patch
@@ -0,0 +1,99 @@
1commit 16dac0cb7b73b8a7088300e45b98ac20819b03ed
2Author: Junxian.Xiao <Junxian.Xiao@windriver.com>
3Date: Wed Jun 19 18:57:13 2013 +0800
4
5support well-known password in openssl-tpm-engine.
6
7Add "-z" option to select well known password in create_tpm_key tool.
8
9Signed-off-by: Junxian.Xiao <Junxian.Xiao@windriver.com>
10
11diff --git a/create_tpm_key.c b/create_tpm_key.c
12index fee917f..7b94d62 100644
13--- a/create_tpm_key.c
14+++ b/create_tpm_key.c
15@@ -46,6 +46,8 @@
16 #include <trousers/tss.h>
17 #include <trousers/trousers.h>
18
19+#define TPM_WELL_KNOWN_KEY_LEN 20 /*well know key length is 20 bytes zero*/
20+
21 #define print_error(a,b) \
22 fprintf(stderr, "%s:%d %s result: 0x%x (%s)\n", __FILE__, __LINE__, \
23 a, b, Trspi_Error_String(b))
24@@ -70,6 +72,7 @@ usage(char *argv0)
25 "\t\t-e|--enc-scheme encryption scheme to use [PKCSV15] or OAEP\n"
26 "\t\t-q|--sig-scheme signature scheme to use [DER] or SHA1\n"
27 "\t\t-s|--key-size key size in bits [2048]\n"
28+ "\t\t-z|--zerokey use well known 20 bytes zero as SRK password.\n"
29 "\t\t-a|--auth require a password for the key [NO]\n"
30 "\t\t-p|--popup use TSS GUI popup dialogs to get the password "
31 "for the\n\t\t\t\t key [NO] (implies --auth)\n"
32@@ -147,6 +150,7 @@ int main(int argc, char **argv)
33 int asn1_len;
34 char *filename, c, *openssl_key = NULL;
35 int option_index, auth = 0, popup = 0, wrap = 0;
36+ int wellknownkey = 0;
37 UINT32 enc_scheme = TSS_ES_RSAESPKCSV15;
38 UINT32 sig_scheme = TSS_SS_RSASSAPKCS1V15_DER;
39 UINT32 key_size = 2048;
40@@ -154,12 +158,15 @@ int main(int argc, char **argv)
41
42 while (1) {
43 option_index = 0;
44- c = getopt_long(argc, argv, "pe:q:s:ahw:",
45+ c = getopt_long(argc, argv, "pe:q:s:zahw:",
46 long_options, &option_index);
47 if (c == -1)
48 break;
49
50 switch (c) {
51+ case 'z':
52+ wellknownkey = 1;
53+ break;
54 case 'a':
55 initFlags |= TSS_KEY_AUTHORIZATION;
56 auth = 1;
57@@ -293,6 +300,8 @@ int main(int argc, char **argv)
58
59 if (srk_authusage) {
60 char *authdata = calloc(1, 128);
61+ TSS_FLAG secretMode = TSS_SECRET_MODE_PLAIN;
62+ int authlen = 0;
63
64 if (!authdata) {
65 fprintf(stderr, "malloc failed.\n");
66@@ -309,17 +318,26 @@ int main(int argc, char **argv)
67 exit(result);
68 }
69
70- if (EVP_read_pw_string(authdata, 128, "SRK Password: ", 0)) {
71- Tspi_Context_CloseObject(hContext, hKey);
72- Tspi_Context_Close(hContext);
73- free(authdata);
74- exit(result);
75+ if (wellknownkey) {
76+ memset(authdata, 0, TPM_WELL_KNOWN_KEY_LEN);
77+ secretMode = TSS_SECRET_MODE_SHA1;
78+ authlen = TPM_WELL_KNOWN_KEY_LEN;
79+ }
80+ else {
81+ if (EVP_read_pw_string(authdata, 128, "SRK Password: ", 0)) {
82+ Tspi_Context_CloseObject(hContext, hKey);
83+ Tspi_Context_Close(hContext);
84+ free(authdata);
85+ exit(result);
86+ }
87+ secretMode = TSS_SECRET_MODE_PLAIN;
88+ authlen = strlen(authdata);
89 }
90
91 //Set Secret
92 if ((result = Tspi_Policy_SetSecret(srkUsagePolicy,
93- TSS_SECRET_MODE_PLAIN,
94- strlen(authdata),
95+ secretMode,
96+ authlen,
97 (BYTE *)authdata))) {
98 print_error("Tspi_Policy_SetSecret", result);
99 free(authdata);
diff --git a/meta-tpm/recipes-tpm/openssl-tpm-engine/files/0002-libtpm-support-env-TPM_SRK_PW.patch b/meta-tpm/recipes-tpm/openssl-tpm-engine/files/0002-libtpm-support-env-TPM_SRK_PW.patch
new file mode 100644
index 0000000..f718f2e
--- /dev/null
+++ b/meta-tpm/recipes-tpm/openssl-tpm-engine/files/0002-libtpm-support-env-TPM_SRK_PW.patch
@@ -0,0 +1,80 @@
1commit 16dac0cb7b73b8a7088300e45b98ac20819b03ed
2Author: Junxian.Xiao <Junxian.Xiao@windriver.com>
3Date: Wed Jun 19 18:57:13 2013 +0800
4
5support reading SRK password from env TPM_SRK_PW
6
7Add "env TPM_SRK_PW=xxxx" to set password for libtpm.so. Specially,
8use "env TPM_SRK_PW=#WELLKNOWN#" to set well known password.
9
10Signed-off-by: Junxian.Xiao <Junxian.Xiao@windriver.com>
11
12diff --git a/e_tpm.c b/e_tpm.c
13index f3e8bcf..7dcb75a 100644
14--- a/e_tpm.c
15+++ b/e_tpm.c
16@@ -38,6 +38,8 @@
17
18 #include "e_tpm.h"
19
20+#define TPM_WELL_KNOWN_KEY_LEN 20 /*well know key length is 20 bytes zero*/
21+
22 //#define DLOPEN_TSPI
23
24 #ifndef OPENSSL_NO_HW
25@@ -248,6 +250,10 @@ int tpm_load_srk(UI_METHOD *ui, void *cb_data)
26 TSS_RESULT result;
27 UINT32 authusage;
28 BYTE *auth;
29+ char *srkPasswd = NULL;
30+ TSS_FLAG secretMode = secret_mode;
31+ int authlen = 0;
32+
33
34 if (hSRK != NULL_HKEY) {
35 DBGFN("SRK is already loaded.");
36@@ -299,18 +305,36 @@ int tpm_load_srk(UI_METHOD *ui, void *cb_data)
37 return 0;
38 }
39
40- if (!tpm_engine_get_auth(ui, (char *)auth, 128, "SRK authorization: ",
41- cb_data)) {
42- Tspi_Context_CloseObject(hContext, hSRK);
43- free(auth);
44- TSSerr(TPM_F_TPM_LOAD_SRK, TPM_R_REQUEST_FAILED);
45- return 0;
46+ srkPasswd = getenv("TPM_SRK_PW");
47+ if (NULL != srkPasswd) {
48+ if (0 == strcmp(srkPasswd, "#WELLKNOWN#")) {
49+ memset(auth, 0, TPM_WELL_KNOWN_KEY_LEN);
50+ secretMode = TSS_SECRET_MODE_SHA1;
51+ authlen = TPM_WELL_KNOWN_KEY_LEN;
52+ } else {
53+ int authbuflen = 128;
54+ memset(auth, 0, authbuflen);
55+ strncpy(auth, srkPasswd, authbuflen-1);
56+ secretMode = TSS_SECRET_MODE_PLAIN;
57+ authlen = strlen(auth);
58+ }
59+ }
60+ else {
61+ if (!tpm_engine_get_auth(ui, (char *)auth, 128,
62+ "SRK authorization: ", cb_data)) {
63+ Tspi_Context_CloseObject(hContext, hSRK);
64+ free(auth);
65+ TSSerr(TPM_F_TPM_LOAD_SRK, TPM_R_REQUEST_FAILED);
66+ return 0;
67+ }
68+ secretMode = secret_mode;
69+ authlen = strlen(auth);
70 }
71
72 /* secret_mode is a global that may be set by engine ctrl
73 * commands. By default, its set to TSS_SECRET_MODE_PLAIN */
74- if ((result = Tspi_Policy_SetSecret(hSRKPolicy, secret_mode,
75- strlen((char *)auth), auth))) {
76+ if ((result = Tspi_Policy_SetSecret(hSRKPolicy, secretMode,
77+ authlen, auth))) {
78 Tspi_Context_CloseObject(hContext, hSRK);
79 free(auth);
80 TSSerr(TPM_F_TPM_LOAD_SRK, TPM_R_REQUEST_FAILED);
diff --git a/meta-tpm/recipes-tpm/openssl-tpm-engine/files/0003-Fix-not-building-libtpm.la.patch b/meta-tpm/recipes-tpm/openssl-tpm-engine/files/0003-Fix-not-building-libtpm.la.patch
new file mode 100644
index 0000000..d24a150
--- /dev/null
+++ b/meta-tpm/recipes-tpm/openssl-tpm-engine/files/0003-Fix-not-building-libtpm.la.patch
@@ -0,0 +1,25 @@
1From 7848445a1f4c750ef73bf96f5e89d402f87a1756 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Mon, 19 Jun 2017 14:54:28 +0800
4Subject: [PATCH] Fix not building libtpm.la
5
6Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
7---
8 Makefile.am | 4 +++-
9 1 file changed, 3 insertions(+), 1 deletion(-)
10
11diff --git a/Makefile.am b/Makefile.am
12index 6695656..634a7e6 100644
13--- a/Makefile.am
14+++ b/Makefile.am
15@@ -10,4 +10,6 @@ libtpm_la_LIBADD=-lcrypto -lc -ltspi
16 libtpm_la_SOURCES=e_tpm.c e_tpm.h e_tpm_err.c
17
18 create_tpm_key_SOURCES=create_tpm_key.c
19-create_tpm_key_LDADD=-ltspi
20+create_tpm_key_LDFLAGS=-ltspi
21+
22+LDADD=libtpm.la
23--
242.7.5
25
diff --git a/meta-tpm/recipes-tpm/openssl-tpm-engine/openssl-tpm-engine_0.4.2.bb b/meta-tpm/recipes-tpm/openssl-tpm-engine/openssl-tpm-engine_0.4.2.bb
new file mode 100644
index 0000000..acb79bd
--- /dev/null
+++ b/meta-tpm/recipes-tpm/openssl-tpm-engine/openssl-tpm-engine_0.4.2.bb
@@ -0,0 +1,54 @@
1DESCRIPTION = " OpenSSL secure engine based on TPM hardware"
2HOMEPAGE = "http://www.openssl.org/"
3SECTION = "libs/network"
4LICENSE = "openssl"
5
6DEPENDS += "openssl trousers"
7RDEPENDS_${PN} += "libcrypto libtspi"
8
9SRC_URI = "\
10 http://sourceforge.net/projects/trousers/files/OpenSSL%20TPM%20Engine/0.4.2/openssl_tpm_engine-0.4.2.tar.gz \
11 file://0001-create-tpm-key-support-well-known-key-option.patch \
12 file://0002-libtpm-support-env-TPM_SRK_PW.patch \
13 file://0003-Fix-not-building-libtpm.la.patch \
14"
15SRC_URI[md5sum] = "5bc8d66399e517dde25ff55ce4c6560f"
16SRC_URI[sha256sum] = "2df697e583053f7047a89daa4585e21fc67cf4397ee34ece94cf2d4b4f7ab49c"
17LIC_FILES_CHKSUM = "file://LICENSE;md5=11f0ee3af475c85b907426e285c9bb52"
18
19inherit autotools-brokensep
20
21S = "${WORKDIR}/openssl_tpm_engine-${PV}"
22
23do_configure_prepend() {
24 cd "${S}"
25 cp LICENSE COPYING
26 touch NEWS AUTHORS ChangeLog
27}
28
29FILES_${PN}-staticdev += "${libdir}/ssl/engines/libtpm.la"
30FILES_${PN}-dbg += "${libdir}/ssl/engines/.debug \
31 ${libdir}/engines/.debug \
32 ${prefix}/local/ssl/lib/engines/.debug \
33"
34FILES_${PN} += "${libdir}/ssl/engines/libtpm.so* \
35 ${libdir}/engines/libtpm.so* \
36 ${libdir}/libtpm.so* \
37 ${prefix}/local/ssl/lib/engines/libtpm.so* \
38"
39
40do_install_append() {
41 install -m 0755 -d "${D}${libdir}/engines"
42 install -m 0755 -d "${D}${prefix}/local/ssl/lib/engines"
43 install -m 0755 -d "${D}${libdir}/ssl/engines"
44
45 cp -f "${D}${libdir}/openssl/engines/libtpm.so.0.0.0" "${D}${libdir}/libtpm.so.0"
46 cp -f "${D}${libdir}/openssl/engines/libtpm.so.0.0.0" "${D}${libdir}/engines/libtpm.so"
47 cp -f "${D}${libdir}/openssl/engines/libtpm.so.0.0.0" "${D}${prefix}/local/ssl/lib/engines/libtpm.so"
48 mv -f "${D}${libdir}/openssl/engines/libtpm.so.0.0.0" "${D}${libdir}/ssl/engines/libtpm.so"
49 mv -f "${D}${libdir}/openssl/engines/libtpm.la" "${D}${libdir}/ssl/engines/libtpm.la"
50 rm -rf "${D}${libdir}/openssl"
51}
52
53INSANE_SKIP_${PN} = "libdir"
54INSANE_SKIP_${PN}-dbg = "libdir"
diff --git a/meta-tpm/recipes-tpm/pcr-extend/pcr-extend_0.1.bb b/meta-tpm/recipes-tpm/pcr-extend/pcr-extend_0.1.bb
new file mode 100644
index 0000000..6f4611a
--- /dev/null
+++ b/meta-tpm/recipes-tpm/pcr-extend/pcr-extend_0.1.bb
@@ -0,0 +1,21 @@
1SUMMARY = " \
2 "
3DESCRIPTION = " \
4 "
5SECTION = "tpm"
6PR = "r0"
7LICENSE = "PD"
8LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263"
9DEPENDS = "libtspi"
10
11S = "${WORKDIR}/${BPN}_${PV}"
12
13SRC_URI += " \
14 http://twobit.us/${BPN}/${BPN}_${PV}.tar.bz2 \
15"
16
17SRC_URI[md5sum] = "98d2a3b816e54bdb17fe97a4294928bc"
18SRC_URI[sha256sum] = "0ee784b252537bde4e195bfdedb20efd01ccf106a2b86beae6c8c02b3f7b1470"
19
20inherit autotools
21B = "${WORKDIR}/${BPN}_${PV}"
diff --git a/meta-tpm/recipes-tpm/tpm-quote-tools/tpm-quote-tools_1.0.1.bb b/meta-tpm/recipes-tpm/tpm-quote-tools/tpm-quote-tools_1.0.1.bb
new file mode 100644
index 0000000..f20d17d
--- /dev/null
+++ b/meta-tpm/recipes-tpm/tpm-quote-tools/tpm-quote-tools_1.0.1.bb
@@ -0,0 +1,26 @@
1SUMMARY = " \
2 The TPM Quote Tools is a collection of programs that provide support \
3 for TPM based attestation using the TPM quote mechanism. \
4 "
5DESCRIPTION = " \
6 The TPM Quote Tools is a collection of programs that provide support \
7 for TPM based attestation using the TPM quote mechanism. The manual \
8 page for tpm_quote_tools provides a usage overview. \
9 \
10 TPM Quote Tools has been tested with TrouSerS on Linux and NTRU on \
11 Windows XP. It was ported to Windows using MinGW and MSYS. \
12 "
13SECTION = "tpm"
14PR = "r0"
15LICENSE = "PD"
16LIC_FILES_CHKSUM = "file://COPYING;md5=8ec30b01163d242ecf07d9cd84e3611f"
17DEPENDS = "libtspi tpm-tools"
18
19SRC_URI += " \
20 http://downloads.sourceforge.net/project/tpmquotetools/1.0.1/tpm-quote-tools-1.0.1.tar.gz \
21"
22
23SRC_URI[md5sum] = "bea00c7d5c9bd78bfa42e4e69428de80"
24SRC_URI[sha256sum] = "40a6987c009cc24677a7e13a6c4121c0a165e37a588c019ae417d66a3bdfa0b5"
25
26inherit autotools
diff --git a/meta-tpm/recipes-tpm/tpm-tools/tpm-tools-1.3.8/03-fix-bool-error-parseStringWithValues.patch b/meta-tpm/recipes-tpm/tpm-tools/tpm-tools-1.3.8/03-fix-bool-error-parseStringWithValues.patch
new file mode 100644
index 0000000..9497e89
--- /dev/null
+++ b/meta-tpm/recipes-tpm/tpm-tools/tpm-tools-1.3.8/03-fix-bool-error-parseStringWithValues.patch
@@ -0,0 +1,30 @@
1Title: Fix boolean comparison error (and FTBFS with gcc-5)
2Date: 2015-06-28
3Author: Pierre Chifflier <pollux@debian.org>
4Bug-Debian: http://bugs.debian.org/778147
5Index: tpm-tools/src/tpm_mgmt/tpm_nvcommon.c
6===================================================================
7--- tpm-tools.orig/src/tpm_mgmt/tpm_nvcommon.c
8+++ tpm-tools/src/tpm_mgmt/tpm_nvcommon.c
9@@ -140,8 +140,8 @@ int parseStringWithValues(const char *aA
10 aArg);
11 return -1;
12 }
13- if (!aArg[offset+numbytes] == '|' &&
14- !aArg[offset+numbytes] == 0) {
15+ if (!(aArg[offset+numbytes] == '|' ||
16+ aArg[offset+numbytes] == 0)) {
17 logError(_("Illegal character following "
18 "hexadecimal number in %s\n"),
19 aArg + offset);
20@@ -164,8 +164,8 @@ int parseStringWithValues(const char *aA
21 return -1;
22 }
23
24- if (!aArg[offset+numbytes] == '|' &&
25- !aArg[offset+numbytes] == 0) {
26+ if (!(aArg[offset+numbytes] == '|' ||
27+ aArg[offset+numbytes] == 0)) {
28 logError(_("Illegal character following decimal "
29 "number in %s\n"),
30 aArg + offset);
diff --git a/meta-tpm/recipes-tpm/tpm-tools/tpm-tools-1.3.8/tpm-tools-extendpcr.patch b/meta-tpm/recipes-tpm/tpm-tools/tpm-tools-1.3.8/tpm-tools-extendpcr.patch
new file mode 100644
index 0000000..ab5e683
--- /dev/null
+++ b/meta-tpm/recipes-tpm/tpm-tools/tpm-tools-1.3.8/tpm-tools-extendpcr.patch
@@ -0,0 +1,244 @@
1Index: tpm-tools-1.3.8/include/tpm_tspi.h
2===================================================================
3--- tpm-tools-1.3.8.orig/include/tpm_tspi.h 2011-08-17 08:20:35.000000000 -0400
4+++ tpm-tools-1.3.8/include/tpm_tspi.h 2013-01-05 23:26:31.571598217 -0500
5@@ -117,6 +117,10 @@
6 UINT32 *a_PcrSize, BYTE **a_PcrValue);
7 TSS_RESULT pcrcompositeSetPcrValue(TSS_HPCRS a_hPcrs, UINT32 a_Idx,
8 UINT32 a_PcrSize, BYTE *a_PcrValue);
9+TSS_RESULT tpmPcrExtend(TSS_HTPM a_hTpm, UINT32 a_Idx,
10+ UINT32 a_DataSize, BYTE *a_Data,
11+ TSS_PCR_EVENT *a_Event,
12+ UINT32 *a_PcrSize, BYTE **a_PcrValue);
13 #ifdef TSS_LIB_IS_12
14 TSS_RESULT unloadVersionInfo(UINT64 *offset, BYTE *blob, TPM_CAP_VERSION_INFO *v);
15 TSS_RESULT pcrcompositeSetPcrLocality(TSS_HPCRS a_hPcrs, UINT32 localityValue);
16Index: tpm-tools-1.3.8/lib/tpm_tspi.c
17===================================================================
18--- tpm-tools-1.3.8.orig/lib/tpm_tspi.c 2011-08-17 08:20:35.000000000 -0400
19+++ tpm-tools-1.3.8/lib/tpm_tspi.c 2013-01-05 23:27:37.731593490 -0500
20@@ -594,6 +594,20 @@
21 return result;
22 }
23
24+TSS_RESULT
25+tpmPcrExtend(TSS_HTPM a_hTpm, UINT32 a_Idx,
26+ UINT32 a_DataSize, BYTE *a_Data,
27+ TSS_PCR_EVENT *a_Event,
28+ UINT32 *a_PcrSize, BYTE **a_PcrValue)
29+{
30+ TSS_RESULT result =
31+ Tspi_TPM_PcrExtend(a_hTpm, a_Idx, a_DataSize, a_Data, a_Event,
32+ a_PcrSize, a_PcrValue);
33+ tspiResult("Tspi_TPM_PcrExtend", result);
34+
35+ return result;
36+}
37+
38 #ifdef TSS_LIB_IS_12
39 /*
40 * These getPasswd functions will wrap calls to the other functions and check to see if the TSS
41Index: tpm-tools-1.3.8/src/cmds/Makefile.am
42===================================================================
43--- tpm-tools-1.3.8.orig/src/cmds/Makefile.am 2011-08-15 13:52:08.000000000 -0400
44+++ tpm-tools-1.3.8/src/cmds/Makefile.am 2013-01-05 23:30:46.223593698 -0500
45@@ -22,6 +22,7 @@
46 #
47
48 bin_PROGRAMS = tpm_sealdata \
49+ tpm_extendpcr \
50 tpm_unsealdata
51
52 if TSS_LIB_IS_12
53@@ -33,4 +34,5 @@
54 LDADD = $(top_builddir)/lib/libtpm_tspi.la -ltspi $(top_builddir)/lib/libtpm_unseal.la -ltpm_unseal -lcrypto
55
56 tpm_sealdata_SOURCES = tpm_sealdata.c
57+tpm_extendpcr_SOURCES = tpm_extendpcr.c
58 tpm_unsealdata_SOURCES = tpm_unsealdata.c
59Index: tpm-tools-1.3.8/src/cmds/tpm_extendpcr.c
60===================================================================
61--- /dev/null 1970-01-01 00:00:00.000000000 +0000
62+++ tpm-tools-1.3.8/src/cmds/tpm_extendpcr.c 2013-01-05 23:37:43.403585514 -0500
63@@ -0,0 +1,181 @@
64+/*
65+ * The Initial Developer of the Original Code is International
66+ * Business Machines Corporation. Portions created by IBM
67+ * Corporation are Copyright (C) 2005, 2006 International Business
68+ * Machines Corporation. All Rights Reserved.
69+ *
70+ * This program is free software; you can redistribute it and/or modify
71+ * it under the terms of the Common Public License as published by
72+ * IBM Corporation; either version 1 of the License, or (at your option)
73+ * any later version.
74+ *
75+ * This program is distributed in the hope that it will be useful,
76+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
77+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
78+ * Common Public License for more details.
79+ *
80+ * You should have received a copy of the Common Public License
81+ * along with this program; if not, a copy can be viewed at
82+ * http://www.opensource.org/licenses/cpl1.0.php.
83+ */
84+#include <openssl/evp.h>
85+#include <openssl/sha.h>
86+#include <limits.h>
87+#include "tpm_tspi.h"
88+#include "tpm_utils.h"
89+#include "tpm_seal.h"
90+
91+// #define TPM_EXTENDPCR_DEBUG
92+
93+static void help(const char *aCmd)
94+{
95+ logCmdHelp(aCmd);
96+ logCmdOption("-i, --infile FILE",
97+ _
98+ ("Filename containing data to extend PCRs with. Default is STDIN."));
99+ logCmdOption("-p, --pcr NUMBER",
100+ _("PCR to extend."));
101+
102+}
103+
104+static char in_filename[PATH_MAX] = "";
105+static TSS_HPCRS hPcrs = NULL_HPCRS;
106+static TSS_HTPM hTpm;
107+static UINT32 selectedPcrs[24];
108+static UINT32 selectedPcrsLen = 0;
109+TSS_HCONTEXT hContext = 0;
110+
111+static int parse(const int aOpt, const char *aArg)
112+{
113+ int rc = -1;
114+
115+ switch (aOpt) {
116+ case 'i':
117+ if (aArg) {
118+ strncpy(in_filename, aArg, PATH_MAX);
119+ rc = 0;
120+ }
121+ break;
122+ case 'p':
123+ if (aArg) {
124+ selectedPcrs[selectedPcrsLen++] = atoi(aArg);
125+ rc = 0;
126+ }
127+ break;
128+ default:
129+ break;
130+ }
131+ return rc;
132+
133+}
134+
135+int main(int argc, char **argv)
136+{
137+
138+ int iRc = -1;
139+ struct option opts[] = {
140+ {"infile", required_argument, NULL, 'i'},
141+ {"pcr", required_argument, NULL, 'p'},
142+ };
143+ unsigned char line[EVP_MD_block_size(EVP_sha1()) * 16];
144+ int lineLen;
145+ UINT32 i;
146+
147+ BIO *bin = NULL;
148+
149+ initIntlSys();
150+
151+ if (genericOptHandler(argc, argv, "i:p:", opts,
152+ sizeof(opts) / sizeof(struct option), parse,
153+ help) != 0)
154+ goto out;
155+
156+ if (contextCreate(&hContext) != TSS_SUCCESS)
157+ goto out;
158+
159+ if (contextConnect(hContext) != TSS_SUCCESS)
160+ goto out_close;
161+
162+ if (contextGetTpm(hContext, &hTpm) != TSS_SUCCESS)
163+ goto out_close;
164+
165+ /* Create a BIO for the input file */
166+ if ((bin = BIO_new(BIO_s_file())) == NULL) {
167+ logError(_("Unable to open input BIO\n"));
168+ goto out_close;
169+ }
170+
171+ /* Assign the input file to the BIO */
172+ if (strlen(in_filename) == 0)
173+ BIO_set_fp(bin, stdin, BIO_NOCLOSE);
174+ else if (!BIO_read_filename(bin, in_filename)) {
175+ logError(_("Unable to open input file: %s\n"),
176+ in_filename);
177+ goto out_close;
178+ }
179+
180+ /* Create the PCRs object. If any PCRs above 15 are selected, this will need to be
181+ * a 1.2 TSS/TPM */
182+ if (selectedPcrsLen) {
183+ TSS_FLAG initFlag = 0;
184+ UINT32 pcrSize;
185+ BYTE *pcrValue;
186+
187+ for (i = 0; i < selectedPcrsLen; i++) {
188+ if (selectedPcrs[i] > 15) {
189+#ifdef TSS_LIB_IS_12
190+ initFlag |= TSS_PCRS_STRUCT_INFO_LONG;
191+#else
192+ logError(_("This version of %s was compiled for a v1.1 TSS, which "
193+ "can only seal\n data to PCRs 0-15. PCR %u is out of range"
194+ "\n"), argv[0], selectedPcrs[i]);
195+ goto out_close;
196+#endif
197+ }
198+ }
199+
200+ unsigned char msg[EVP_MAX_MD_SIZE];
201+ unsigned int msglen;
202+ EVP_MD_CTX ctx;
203+ EVP_DigestInit(&ctx, EVP_sha1());
204+ while ((lineLen = BIO_read(bin, line, sizeof(line))) > 0)
205+ EVP_DigestUpdate(&ctx, line, lineLen);
206+ EVP_DigestFinal(&ctx, msg, &msglen);
207+
208+ if (contextCreateObject(hContext, TSS_OBJECT_TYPE_PCRS, initFlag,
209+ &hPcrs) != TSS_SUCCESS)
210+ goto out_close;
211+
212+ for (i = 0; i < selectedPcrsLen; i++) {
213+#ifdef TPM_EXTENDPCR_DEBUG
214+ if (tpmPcrRead(hTpm, selectedPcrs[i], &pcrSize, &pcrValue) != TSS_SUCCESS)
215+ goto out_close;
216+
217+ unsigned int j;
218+ for (j = 0; j < pcrSize; j++)
219+ printf("%02X ", pcrValue[j]);
220+ printf("\n");
221+#endif
222+
223+ if (tpmPcrExtend(hTpm, selectedPcrs[i], msglen, msg, NULL, &pcrSize, &pcrValue) != TSS_SUCCESS)
224+ goto out_close;
225+
226+#ifdef TPM_EXTENDPCR_DEBUG
227+ for (j = 0; j < pcrSize; j++)
228+ printf("%02X ", pcrValue[j]);
229+ printf("\n");
230+#endif
231+ }
232+ }
233+
234+ iRc = 0;
235+ logSuccess(argv[0]);
236+
237+out_close:
238+ contextClose(hContext);
239+
240+out:
241+ if (bin)
242+ BIO_free(bin);
243+ return iRc;
244+}
diff --git a/meta-tpm/recipes-tpm/tpm-tools/tpm-tools-1.3.8/tpm-tools-gcc-6.patch b/meta-tpm/recipes-tpm/tpm-tools/tpm-tools-1.3.8/tpm-tools-gcc-6.patch
new file mode 100644
index 0000000..eb4373d
--- /dev/null
+++ b/meta-tpm/recipes-tpm/tpm-tools/tpm-tools-1.3.8/tpm-tools-gcc-6.patch
@@ -0,0 +1,21 @@
1--- a/src/tpm_mgmt/tpm_present.c
2+++ b/src/tpm_mgmt/tpm_present.c
3@@ -349,13 +349,13 @@
4 }
5 } while (flags[++i].name);
6
7- out_success:
8+out_success:
9 logSuccess(argv[0]);
10 iRc = 0;
11- out_close:
12+out_close:
13 contextClose(hContext);
14- out:
15- if (szTpmPasswd && !isWellKnown)
16- shredPasswd( szTpmPasswd );
17+out:
18+ if (szTpmPasswd && !isWellKnown)
19+ shredPasswd( szTpmPasswd );
20 return iRc;
21 }
diff --git a/meta-tpm/recipes-tpm/tpm-tools/tpm-tools_1.3.8.bb b/meta-tpm/recipes-tpm/tpm-tools/tpm-tools_1.3.8.bb
new file mode 100644
index 0000000..5b5bbd8
--- /dev/null
+++ b/meta-tpm/recipes-tpm/tpm-tools/tpm-tools_1.3.8.bb
@@ -0,0 +1,24 @@
1SUMMARY = "The tpm-tools package contains commands to allow the platform administrator the ability to manage and diagnose the platform's TPM."
2DESCRIPTION = " \
3 The tpm-tools package contains commands to allow the platform administrator \
4 the ability to manage and diagnose the platform's TPM. Additionally, the \
5 package contains commands to utilize some of the capabilities available \
6 in the TPM PKCS#11 interface implemented in the openCryptoki project. \
7 "
8SECTION = "tpm"
9PR = "r0"
10LICENSE = "CPL-1.0"
11LIC_FILES_CHKSUM = "file://LICENSE;md5=059e8cd6165cb4c31e351f2b69388fd9"
12DEPENDS = "libtspi openssl"
13
14SRC_URI += " \
15 http://downloads.sourceforge.net/project/trousers/tpm-tools/1.3.8/tpm-tools-1.3.8.tar.gz \
16 file://tpm-tools-extendpcr.patch \
17 file://03-fix-bool-error-parseStringWithValues.patch \
18 file://tpm-tools-gcc-6.patch \
19"
20
21SRC_URI[md5sum] = "85a978c4e03fefd4b73cbeadde7c4d0b"
22SRC_URI[sha256sum] = "66eb4ff095542403db6b4bd4b574e8a5c08084fe4e9e5aa9a829ee84e20bea83"
23
24inherit autotools gettext
diff --git a/meta-tpm/recipes-tpm/trousers/files/Fix-segment-fault-if-client-hostname-cannot-be-retri.patch b/meta-tpm/recipes-tpm/trousers/files/Fix-segment-fault-if-client-hostname-cannot-be-retri.patch
new file mode 100644
index 0000000..ea6d609
--- /dev/null
+++ b/meta-tpm/recipes-tpm/trousers/files/Fix-segment-fault-if-client-hostname-cannot-be-retri.patch
@@ -0,0 +1,33 @@
1From cdc4828ea44e8cb6f8c62f9021ce37b0c1636aa4 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Thu, 12 May 2016 23:55:44 +0800
4Subject: [PATCH] Fix segment fault if client hostname cannot be retrieve
5
6Upstream-Status: Pending
7
8When tcsd cannot resolve the hostname of client, the constant C string
9INVALID_ADDR_STR is used to identify the client. The host name eventually
10be freed by calling free(), which will violate the memory protection for
11sure. To fix this issue, always create a freeable INVALID_ADDR_STR.
12
13Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
14---
15 src/tcsd/svrside.c | 2 +-
16 1 file changed, 1 insertion(+), 1 deletion(-)
17
18diff --git a/src/tcsd/svrside.c b/src/tcsd/svrside.c
19index 1ae1636..692211c 100644
20--- a/src/tcsd/svrside.c
21+++ b/src/tcsd/svrside.c
22@@ -557,7 +557,7 @@ main(int argc, char **argv)
23
24 hostname = fetch_hostname(&client_addr, client_len);
25 if (hostname == NULL)
26- hostname=INVALID_ADDR_STR;
27+ hostname=strdup(INVALID_ADDR_STR);
28
29 tcsd_thread_create(newsd, hostname);
30 hostname = NULL;
31--
321.9.1
33
diff --git a/meta-tpm/recipes-tpm/trousers/files/fix-deadlock-and-potential-hung.patch b/meta-tpm/recipes-tpm/trousers/files/fix-deadlock-and-potential-hung.patch
new file mode 100644
index 0000000..1bf1a7e
--- /dev/null
+++ b/meta-tpm/recipes-tpm/trousers/files/fix-deadlock-and-potential-hung.patch
@@ -0,0 +1,82 @@
1commit dbd71905ba3183e53bcc699813f6061779001c62
2Author: Genli Pan <genli.pan@windriver.com>
3Date: Mon Dec 15 10:54:04 2014 +0800
4
5obj_list_get_obj() uses a mutex lock to exclusively access to list.
6And the lock is released in function obj_list_put(). Usage of this
7couple of functions in the following code path cause deadlock.
8 --------
9 obj_context_transport_close
10 obj_list_get_obj
11 secret_PerformAuth_OIAP
12 obj_context_get_tcs_api
13 obj_list_get_obj
14 ...
15 obj_list_put
16 Transport_OIAP
17 obj_context_transport_init
18 obj_list_get_obj
19 ...
20 obj_list_put
21 RPC_ReleaseTransportSigned
22 obj_list_put
23 --------
24
25Also fix a potential hung situation, that authorization session didn't been
26released even if establish transport session failed. And retrying will
27takes up more authorization sessions, until the thread being forced waiting.
28
29Signed-off-by: Genli Pan <genli.pan@windriver.com>
30
31diff --git a/src/tspi/obj_context.c b/src/tspi/obj_context.c
32index cb2091e..bcbc4da 100644
33--- a/src/tspi/obj_context.c
34+++ b/src/tspi/obj_context.c
35@@ -1330,6 +1334,7 @@ obj_context_transport_close(TSS_HCONTEXT tspContext,
36 return TSPERR(TSS_E_INVALID_HANDLE);
37
38 context = (struct tr_context_obj *)obj->data;
39+ obj_list_put(&context_list);
40
41 /* return immediately if we're not in a transport session */
42 if (!(context->flags & TSS_CONTEXT_FLAGS_TRANSPORT_ENABLED)) {
43@@ -1431,7 +1436,7 @@ obj_context_transport_close(TSS_HCONTEXT tspContext,
44 done_disabled:
45 context->flags &= ~TSS_CONTEXT_FLAGS_TRANSPORT_ESTABLISHED;
46 done:
47- obj_list_put(&context_list);
48+ //obj_list_put(&context_list);
49
50 return result;
51 }
52diff --git a/src/tcs/tcsi_transport.c b/src/tcs/tcsi_transport.c
53index ce47e09..98a9d40 100644
54--- a/src/tcs/tcsi_transport.c
55+++ b/src/tcs/tcsi_transport.c
56@@ -77,11 +77,16 @@ TCSP_EstablishTransport_Internal(TCS_CONTEXT_HANDLE hContext,
57 } else
58 LoadBlob_Header(TPM_TAG_RQU_COMMAND, offset, TPM_ORD_EstablishTransport, txBlob);
59
60- if ((result = req_mgr_submit_req(txBlob)))
61+ if ((result = req_mgr_submit_req(txBlob))) {
62+ if (pEncKeyAuth)
63+ pEncKeyAuth->fContinueAuthSession = FALSE;
64 goto done;
65+ }
66
67 if ((result = UnloadBlob_Header(txBlob, &paramSize))) {
68 LogDebugFn("UnloadBlob_Header failed: rc=0x%x", result);
69+ if (pEncKeyAuth)
70+ pEncKeyAuth->fContinueAuthSession = FALSE;
71 goto done;
72 }
73
74@@ -97,6 +102,8 @@ TCSP_EstablishTransport_Internal(TCS_CONTEXT_HANDLE hContext,
75 *prgbCurrentTicks = malloc(*ulCurrentTicks);
76 if (*prgbCurrentTicks == NULL) {
77 result = TCSERR(TSS_E_OUTOFMEMORY);
78+ if (pEncKeyAuth)
79+ pEncKeyAuth->fContinueAuthSession = FALSE;
80 goto done;
81 }
82
diff --git a/meta-tpm/recipes-tpm/trousers/files/fix-event-log-parsing-problem.patch b/meta-tpm/recipes-tpm/trousers/files/fix-event-log-parsing-problem.patch
new file mode 100644
index 0000000..578e0bf
--- /dev/null
+++ b/meta-tpm/recipes-tpm/trousers/files/fix-event-log-parsing-problem.patch
@@ -0,0 +1,38 @@
1commit 3545a0675ee3cfee6297f968276b5a9b64799057
2Author: Genli Pan <genli.pan@windriver.com>
3Date: Tue Aug 25 15:12:36 2015 +0800
4
5trousers: fix event log parsing problem
6
7Due to the change of format of kernel ima event log, trousers
8failed to parse the log to extract information. this commit adjust
9trousers to adapt the change.
10
11Signed-off-by: Genli Pan <genli.pan@windriver.com>
12
13--- a/src/tcs/tcs_evlog_imaem.c 2014-04-25 02:05:44.000000000 +0800
14+++ b/src/tcs/tcs_evlog_imaem.c 2015-08-24 14:16:46.000000000 +0800
15@@ -145,11 +145,6 @@
16 result = TCSERR(TSS_E_INTERNAL_ERROR);
17 goto free_list;
18 }
19- if (fread(digest, 1, sizeof digest, fp) != (sizeof(digest))) {
20- LogError("Failed to read event log file");
21- result = TCSERR(TSS_E_INTERNAL_ERROR);
22- goto free_list;
23- }
24 }
25 /* Get the template data namelen and data */
26 if (fread(&cur->event.ulEventLength, 1, sizeof(int), fp) != sizeof(int)) {
27@@ -286,11 +281,6 @@
28 LogError("Failed to read event log file");
29 result = TCSERR(TSS_E_INTERNAL_ERROR);
30 goto done;
31- }
32- if (fread(digest, 1, sizeof(digest), fp) != sizeof(digest)) {
33- LogError("Failed to read event log file");
34- result = TCSERR(TSS_E_INTERNAL_ERROR);
35- goto done;
36 }
37 }
38 /* Get the template data namelen and data */
diff --git a/meta-tpm/recipes-tpm/trousers/files/fix-incorrect-report-of-insufficient-buffer.patch b/meta-tpm/recipes-tpm/trousers/files/fix-incorrect-report-of-insufficient-buffer.patch
new file mode 100644
index 0000000..d9a3e31
--- /dev/null
+++ b/meta-tpm/recipes-tpm/trousers/files/fix-incorrect-report-of-insufficient-buffer.patch
@@ -0,0 +1,22 @@
1commit 3452971ba08ced886db7a9adcfc2d977b07d1410
2Author: Genli Pan <genli.pan@windriver.com>
3Date: Thu Jul 30 10:43:25 2015 +0800
4
5trousers: fix incorrect report of insufficient buffer
6
7"size" as the size of buffer, is also used as returned size of result,
8and so would be modified after "Tddli_TransmitData" function call.
9So has to set it back in every loop.
10
11Signed-off-by: Genli Pan <genli.pan@windriver.com>
12
13--- a/src/tcs/tcs_req_mgr.c 2014-04-25 02:05:44.000000000 +0800
14+++ b/src/tcs/tcs_req_mgr.c 2015-07-22 16:38:49.000000000 +0800
15@@ -45,6 +45,7 @@
16 #endif
17
18 do {
19+ size = TSS_TPM_TXBLOB_SIZE;
20 result = Tddli_TransmitData(blob, Decode_UINT32(&blob[2]), loc_buf, &size);
21 } while (!result && (Decode_UINT32(&loc_buf[6]) == TCPA_E_RETRY) && --retry);
22
diff --git a/meta-tpm/recipes-tpm/trousers/files/tcsd.conf b/meta-tpm/recipes-tpm/trousers/files/tcsd.conf
new file mode 100755
index 0000000..1adf7aa
--- /dev/null
+++ b/meta-tpm/recipes-tpm/trousers/files/tcsd.conf
@@ -0,0 +1,170 @@
1
2#
3# This is the configuration file for the trousers tcsd. (The Trusted Computing
4# Software Stack Core Services Daemon).
5#
6# Defaults are listed below, commented out
7#
8# Send questions to: trousers-users@lists.sourceforge.net
9#
10
11# Option: port
12# Values: 1 - 65535
13# Description: The port that the tcsd will listen on.
14#
15port = 30003
16#
17
18# Option: num_threads
19# Values: 1 - 65535
20# Description: The number of threads that the tcsd will spawn internally.
21#
22num_threads = 10
23#
24
25# Option: system_ps_file
26# Values: Any absolute directory path
27# Description: Path where the tcsd creates its persistent storage file.
28#
29system_ps_file = /var/lib/tpm/system.data
30#
31
32# Option: firmware_log_file
33# Values: Any absolute directory path
34# Description: Path to the file containing the current firmware PCR event
35# log data. The interface to this log is usually provided by the TPM
36# device driver.
37#
38firmware_log_file = /sys/kernel/security/tpm0/binary_bios_measurements
39#
40
41# Option: kernel_log_file
42# Values: Any absolute directory path
43# Description: Path to the file containing the current kernel PCR event
44# log data. By default, this data will be parsed in the format provided
45# by the Integrity Measurement Architecture LSM. See
46# http://sf.net/projects/linux-ima for more info on getting IMA.
47#
48#
49kernel_log_file = /sys/kernel/security/ima/binary_runtime_measurements
50#
51
52# Option: firmware_pcrs
53# Values: PCR indices, separated by commas
54# Description: A list of PCR indices that are manipulated only by the system
55# firmware and therefore are not extended or logged by the TCSD.
56#
57firmware_pcrs = 0, 1, 2, 3, 4, 5, 6, 7
58#
59
60# Option: kernel_pcrs
61# Values: PCR indices, separated by commas
62# Description: A list of PCR indices that are manipulated only by the kernel
63# and therefore are not extended or logged by the TCSD.
64#
65kernel_pcrs = 10
66#
67
68# Option: platform_cred
69# Values: Any absolute directory path (example: /path/to/platform.cert)
70# Description: Path to the file containing your TPM's platform credential.
71# The platform credential may have been provided to you by your TPM
72# manufacturer. If so, set platform_cred to the path to the file on disk.
73# Whenever a new TPM identity is created, the credential will be used. See
74# Tspi_TPM_CollateIdentityRequest(3) for more information.
75#
76# platform_cred =
77#
78
79# Option: conformance_cred
80# Values: Any absolute directory path (example: /path/to/conformance.cert)
81# Description: Path to the file containing your TPM's conformance credential.
82# The conformance credential may have been provided to you by your TPM
83# manufacturer. If so, set conformance_cred to the path to the file on disk.
84# Whenever a new TPM identity is created, the credential will be used. See
85# Tspi_TPM_CollateIdentityRequest(3) for more information.
86#
87# conformance_cred =
88#
89
90# Option: endorsement_cred
91# Values: Any absolute directory path (example: /path/to/endorsement.cert)
92# Description: Path to the file containing your TPM's endorsement credential.
93# The endorsement credential may have been provided to you by your TPM
94# manufacturer. If so, set endorsement_cred to the path to the file on disk.
95# Whenever a new TPM identity is created, the credential will be used. See
96# Tspi_TPM_CollateIdentityRequest(3) for more information.
97#
98# endorsement_cred =
99#
100
101# Option: remote_ops
102# Values: TCS operation names, separated by commas (no whitespace)
103# Description: A list of TCS commands which will be allowed to be executed
104# on this machine's TCSD by TSP's on non-local hosts (over the internet).
105# By default, access to all operations is denied.
106#
107# possible values: seal - encrypt data bound to PCR values
108# unseal - decrypt data bound to PCR values
109# registerkey - store keys in system persistent storage [Disk write access!]
110# unregisterkey - remove keys from system persistent storage [Disk write access!]
111# loadkey - load a key into the TPM
112# createkey - create a key using the TPM
113# sign - encrypt data using a private key
114# random - generate random numbers
115# getcapability - query the TCS/TPM for its capabilities
116# unbind - decrypt data
117# quote - request a signed blob containing all PCR values
118# readpubek - access the TPM's Public EndorsementKey
119# getregisteredkeybypublicinfo - Search system persistent storage for a public key
120# getpubkey - Retrieve a loaded key's public data from inside the TPM
121# selftest - execute selftest and test results ordinals
122#
123# remote_ops =
124#
125
126# Option: enforce_exclusive_transport
127# Values: 0 or 1
128# Description: When an application opens a transport session with the TPM, one
129# of the options available is an "exclusive" session, meaning that the TPM
130# will not execute any commands other than those coming through the transport
131# session for the lifetime of the session. The TCSD can choose to enforce this
132# option or not. By default, exclusive sessions are not enforced, since this
133# could allow for a denial of service to the TPM.
134#
135# enforce_exclusive_transport = 0
136#
137
138# Option: host_platform_class
139# Values: One of the TCG platform class specifications
140# PC_11 - PC Client System, version 1.1
141# PC_12 - PC Client System, version 1.2
142# PDA_12 - PDA System, version 1.2
143# SERVER_12 - Server System, version 1.2
144# MOBILE_12 - Mobile Phone System, version 1.2
145#
146# Description: This option determines the host platform (host the TCS system
147# is running on) class, among those specified by the Trusted Computing group
148# on https://www.trustedcomputinggroup.org/specs/. This class will be reported
149# by the TCS daemon when an application queries it using the
150# TSS_TCSCAP_PROP_HOST_PLATFORM sub-capability. The default is PC_12.
151#
152host_platform_class = PC_12
153#
154
155# Option: all_platform_classes
156# Values: TCG Platform class names, separated by commas (no whitespaces)
157# PC_11 - PC Client System, version 1.1
158# PC_12 - PC Client System, version 1.2
159# PDA_12 - PDA System, version 1.2
160# SERVER_12 - Server System, version 1.2
161# MOBILE_12 - Mobile Phone System, version 1.2
162#
163# Description: This option determines all the platform classes supported by the
164# TCS daemon. This list must not include the value set as "host_platform_class"
165# specified above. Since by default TrouSerS supports all TPM 1.2 functionality,
166# the default is all 1.2 and 1.1 platform classes.
167#
168# all_platform_classes = PC_11,PDA_12,SERVER_12,MOBILE_12
169#
170
diff --git a/meta-tpm/recipes-tpm/trousers/files/tcsd.service b/meta-tpm/recipes-tpm/trousers/files/tcsd.service
new file mode 100644
index 0000000..59f573b
--- /dev/null
+++ b/meta-tpm/recipes-tpm/trousers/files/tcsd.service
@@ -0,0 +1,21 @@
1[Unit]
2Description=TrouSerS TCG Core Services daemon
3After=syslog.target network.target
4ConditionPathExists=|/dev/tpm0
5ConditionPathExists=|/udev/tpm0
6ConditionPathExists=|/dev/tpm
7ConditionPathExistsGlob=/sys/class/*/tpm0/@TPM_CAPS@
8
9[Service]
10Type=forking
11ExecStartPre=/bin/sh -c "fgrep '@FAMILY_MAJOR@' /sys/class/*/tpm0/@TPM_CAPS@"
12ExecStart=/usr/sbin/tcsd
13
14TimeoutSec=30s
15Restart=on-failure
16RestartSec=4
17StartLimitInterval=25
18StartLimitBurst=5
19
20[Install]
21WantedBy=multi-user.target
diff --git a/meta-tpm/recipes-tpm/trousers/files/trousers-conditional-compile-DES-related-code.patch b/meta-tpm/recipes-tpm/trousers/files/trousers-conditional-compile-DES-related-code.patch
new file mode 100644
index 0000000..6e54586
--- /dev/null
+++ b/meta-tpm/recipes-tpm/trousers/files/trousers-conditional-compile-DES-related-code.patch
@@ -0,0 +1,38 @@
1From 8140d73d63383f22c9d88e5f3207b201cddebff2 Mon Sep 17 00:00:00 2001
2From: Haiqing Bai <Haiqing.Bai@windriver.com>
3Date: Wed, 6 Apr 2016 18:38:25 +0800
4Subject: [PATCH] trousers: Conditional compile DES related code.
5
6Added "OPENSSL_NO_DES" checking for DES related
7code in trousers.
8
9Upstream-Status: Pending
10
11Signed-off-by: Haiqing Bai <Haiqing.Bai@windriver.com>
12---
13 src/trspi/crypto/openssl/symmetric.c | 2 ++
14 1 file changed, 2 insertions(+)
15
16diff --git a/src/trspi/crypto/openssl/symmetric.c b/src/trspi/crypto/openssl/symmetric.c
17index f5c3836..8ba183d 100644
18--- a/src/trspi/crypto/openssl/symmetric.c
19+++ b/src/trspi/crypto/openssl/symmetric.c
20@@ -162,6 +162,7 @@ get_openssl_cipher(UINT16 alg, UINT16 mode)
21 break;
22 }
23 break;
24+#ifndef OPENSSL_NO_DES
25 case TSS_ALG_DES:
26 case TCPA_ALG_DES:
27 switch (mode) {
28@@ -202,6 +203,7 @@ get_openssl_cipher(UINT16 alg, UINT16 mode)
29 break;
30 }
31 break;
32+#endif /* OPENSSL_NO_DES */
33 case TPM_ALG_AES192:
34 case TSS_ALG_AES192:
35 switch (mode) {
36--
371.9.1
38
diff --git a/meta-tpm/recipes-tpm/trousers/files/trousers-udev.rules b/meta-tpm/recipes-tpm/trousers/files/trousers-udev.rules
new file mode 100644
index 0000000..256babd
--- /dev/null
+++ b/meta-tpm/recipes-tpm/trousers/files/trousers-udev.rules
@@ -0,0 +1,2 @@
1# trousers daemon expects tpm device to be owned by tss user & group
2KERNEL=="tpm[0-9]*", MODE="0600", OWNER="tss", GROUP="tss"
diff --git a/meta-tpm/recipes-tpm/trousers/files/trousers.init.sh b/meta-tpm/recipes-tpm/trousers/files/trousers.init.sh
new file mode 100644
index 0000000..0ecf7cc
--- /dev/null
+++ b/meta-tpm/recipes-tpm/trousers/files/trousers.init.sh
@@ -0,0 +1,65 @@
1#!/bin/sh
2
3### BEGIN INIT INFO
4# Provides: tcsd trousers
5# Required-Start: $local_fs $remote_fs $network
6# Required-Stop: $local_fs $remote_fs $network
7# Should-Start:
8# Should-Stop:
9# Default-Start: 2 3 4 5
10# Default-Stop: 0 1 6
11# Short-Description: starts tcsd
12# Description: tcsd belongs to the TrouSerS TCG Software Stack
13### END INIT INFO
14
15PATH=/sbin:/bin:/usr/sbin:/usr/bin
16DAEMON=/usr/sbin/tcsd
17NAME=tcsd
18DESC="Trusted Computing daemon"
19USER="tss"
20
21test -x "${DAEMON}" || exit 0
22
23# Read configuration variable file if it is present
24[ -r /etc/default/$NAME ] && . /etc/default/$NAME
25
26case "${1}" in
27 start)
28 echo "Starting $DESC: "
29
30 if [ ! -e /dev/tpm* ]
31 then
32 echo "device driver not loaded, skipping."
33 exit 0
34 fi
35
36 start-stop-daemon --start --quiet --oknodo --pidfile /var/run/${NAME}.pid --user ${USER} --chuid ${USER} --exec ${DAEMON} -- ${DAEMON_OPTS}
37 RETVAL="$?"
38 echo "$NAME."
39 [ "$RETVAL" = 0 ] && pidof $DAEMON > /var/run/${NAME}.pid
40 exit $RETVAL
41 ;;
42
43 stop)
44 echo "Stopping $DESC: "
45
46 start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/${NAME}.pid --user ${USER} --exec ${DAEMON}
47 RETVAL="$?"
48 echo "$NAME."
49 rm -f /var/run/${NAME}.pid
50 exit $RETVAL
51 ;;
52
53 restart|force-reload)
54 "${0}" stop
55 sleep 1
56 "${0}" start
57 exit $?
58 ;;
59 *)
60 echo "Usage: ${NAME} {start|stop|restart|force-reload|status}" >&2
61 exit 3
62 ;;
63esac
64
65exit 0
diff --git a/meta-tpm/recipes-tpm/trousers/trousers_0.3.14.bb b/meta-tpm/recipes-tpm/trousers/trousers_0.3.14.bb
new file mode 100644
index 0000000..e12543f
--- /dev/null
+++ b/meta-tpm/recipes-tpm/trousers/trousers_0.3.14.bb
@@ -0,0 +1,114 @@
1SUMMARY = "TrouSerS - An open-source TCG Software Stack implementation."
2DESCRIPTION = " \
3Trousers is an open-source TCG Software Stack (TSS), released under the \
4Common Public License. Trousers aims to be compliant with the current (1.1b) \
5and upcoming (1.2) TSS specifications available from the Trusted Computing \
6Group website: http://www.trustedcomputinggroup.org. \
7"
8HOMEPAGE = "https://sourceforge.net/projects/trousers"
9SECTION = "security/tpm"
10
11LICENSE = "BSD"
12LIC_FILES_CHKSUM = "file://LICENSE;md5=8031b2ae48ededc9b982c08620573426"
13
14SRC_URI = " \
15 http://sourceforge.net/projects/trousers/files/trousers/0.3.14/trousers-0.3.14.tar.gz;subdir=${PN}-${PV} \
16 file://fix-deadlock-and-potential-hung.patch \
17 file://trousers.init.sh \
18 file://fix-event-log-parsing-problem.patch \
19 file://fix-incorrect-report-of-insufficient-buffer.patch \
20 file://trousers-conditional-compile-DES-related-code.patch \
21 file://Fix-segment-fault-if-client-hostname-cannot-be-retri.patch \
22 file://trousers-udev.rules \
23 file://tcsd.service \
24 file://tcsd.conf \
25 "
26
27SRC_URI[md5sum] = "4a476b4f036dd20a764fb54fc24edbec"
28SRC_URI[sha256sum] = "ce50713a261d14b735ec9ccd97609f0ad5ce69540af560e8c3ce9eb5f2d28f47"
29
30S = "${WORKDIR}/${PN}-${PV}"
31
32DEPENDS = "openssl"
33
34inherit autotools pkgconfig useradd update-rc.d
35inherit ${@bb.utils.contains('VIRTUAL-RUNTIME_init_manager', 'systemd', 'systemd', '', d)}
36
37PACKAGECONFIG ?= "gmp "
38PACKAGECONFIG[gmp] = "--with-gmp, --with-gmp=no, gmp"
39PACKAGECONFIG[gtk] = "--with-gui=gtk, --with-gui=none, gtk+"
40
41PROVIDES = "${PACKAGES}"
42PACKAGES =+ " \
43 libtspi \
44 libtspi-dbg \
45 libtspi-dev \
46 libtspi-doc \
47 libtspi-staticdev \
48 "
49
50FILES_libtspi = " \
51 ${libdir}/libtspi.so.* \
52 "
53FILES_libtspi-dbg = " \
54 ${prefix}/src/debug/${PN}/${PV}-${PR}/${PN}-${PV}/src/tspi \
55 ${prefix}/src/debug/${PN}/${PV}-${PR}/${PN}-${PV}/src/trspi \
56 ${prefix}/src/debug/${PN}/${PV}-${PR}/${PN}-${PV}/src/include/*.h \
57 ${prefix}/src/debug/${PN}/${PV}-${PR}/${PN}-${PV}/src/include/tss \
58 "
59FILES_libtspi-dev = " \
60 ${includedir} \
61 ${libdir}/*.so \
62 ${libdir}/*.so.1 \
63 "
64FILES_libtspi-doc = " \
65 ${mandir}/man3 \
66 "
67FILES_libtspi-staticdev = " \
68 ${libdir}/*.la \
69 ${libdir}/*.a \
70 "
71FILES_${PN}-dbg = " \
72 ${prefix}/src/debug/${PN}/${PV}-${PR}/${PN}-${PV}/src/tcs \
73 ${prefix}/src/debug/${PN}/${PV}-${PR}/${PN}-${PV}/src/tcsd \
74 ${prefix}/src/debug/${PN}/${PV}-${PR}/${PN}-${PV}/src/tddl \
75 ${prefix}/src/debug/${PN}/${PV}-${PR}/${PN}-${PV}/src/trousers \
76 ${prefix}/src/debug/${PN}/${PV}-${PR}/${PN}-${PV}/src/include/trousers \
77 "
78FILES_${PN}-dev += "${libdir}/trousers"
79FILES_${PN} += "${systemd_unitdir}/system/tcsd.service"
80CONFFILES_${PN} += "${sysconfig}/tcsd.conf"
81
82INITSCRIPT_NAME = "trousers"
83INITSCRIPT_PARAMS = "start 99 2 3 4 5 . stop 19 0 1 6 ."
84
85USERADD_PACKAGES = "${PN}"
86GROUPADD_PARAM_${PN} = "tss"
87USERADD_PARAM_${PN} = "-M -d /var/lib/tpm -s /bin/false -g tss tss"
88
89SYSTEMD_PACKAGES = "${PN}"
90SYSTEMD_SERVICE_${PN} = "tcsd.service"
91SYSTEMD_AUTO_ENABLE = "enable"
92
93TPM_CAPS_x86 = 'device/caps'
94FAMILY_MAJOR_x86 = 'TCG version: 1.2'
95TPM_CAPS_x86-64 = 'device/caps'
96FAMILY_MAJOR_x86-64 = 'TCG version: 1.2'
97
98do_install_append() {
99 install -d "${D}${sysconfdir}/init.d"
100 install -m 0600 "${WORKDIR}/tcsd.conf" "${D}${sysconfdir}"
101 chown tss:tss "${D}${sysconfdir}/tcsd.conf"
102 install -m 0755 "${WORKDIR}/trousers.init.sh" "${D}${sysconfdir}/init.d/trousers"
103
104 install -d "${D}${sysconfdir}/udev/rules.d"
105 install -m 0644 "${WORKDIR}/trousers-udev.rules" \
106 "${D}${sysconfdir}/udev/rules.d/45-trousers.rules"
107
108 install -d "${D}${systemd_unitdir}/system"
109 install -m 0644 "${WORKDIR}/tcsd.service" "${D}${systemd_unitdir}/system"
110 sed -i 's:@TPM_CAPS@:${TPM_CAPS}:' "${D}${systemd_unitdir}/system/tcsd.service"
111 sed -i 's/@FAMILY_MAJOR@/${FAMILY_MAJOR}/' "${D}${systemd_unitdir}/system/tcsd.service"
112}
113
114BBCLASSEXTEND = "native"
diff --git a/meta-tpm/recipes-tpm/tss-testsuite/files/Tspi_TPM_CreateIdentityWithCallbacks_no_des.patch b/meta-tpm/recipes-tpm/tss-testsuite/files/Tspi_TPM_CreateIdentityWithCallbacks_no_des.patch
new file mode 100644
index 0000000..6d43068
--- /dev/null
+++ b/meta-tpm/recipes-tpm/tss-testsuite/files/Tspi_TPM_CreateIdentityWithCallbacks_no_des.patch
@@ -0,0 +1,79 @@
1diff --git a/tcg/highlevel/tpm/Tspi_TPM_CreateIdentityWithCallbacks.c b/tcg/highlevel/tpm/Tspi_TPM_CreateIdentityWithCallbacks.c
2index b5704f3..12fbd56 100644
3--- a/tcg/highlevel/tpm/Tspi_TPM_CreateIdentityWithCallbacks.c
4+++ b/tcg/highlevel/tpm/Tspi_TPM_CreateIdentityWithCallbacks.c
5@@ -66,8 +66,8 @@
6
7 #define CERT_VERIFY_BYTE 0x5a
8
9-TCPA_ALGORITHM_ID symAlg = TCPA_ALG_3DES;
10-TSS_ALGORITHM_ID tssSymAlg = TSS_ALG_3DES;
11+TCPA_ALGORITHM_ID symAlg = TCPA_ALG_AES;
12+TSS_ALGORITHM_ID tssSymAlg = TSS_ALG_AES;
13
14 /* globals to make callbacks easier */
15 TSS_HTPM hTPM = 0;
16@@ -114,6 +114,7 @@ collate_cb(PVOID myArgs, UINT32 proofSize, BYTE *proof, TSS_ALGORITHM_ID algID,
17 symKey.size = 128/8;
18 memcpy(iv, "&%@)*%%$&#)%&#*$", 16);
19 break;
20+#ifndef OPENSSL_NO_DES
21 case TSS_ALG_DES:
22 symKey.algId = TCPA_ALG_DES;
23 symKey.size = 64/8;
24@@ -124,6 +125,7 @@ collate_cb(PVOID myArgs, UINT32 proofSize, BYTE *proof, TSS_ALGORITHM_ID algID,
25 symKey.size = 192/8;
26 memcpy(iv, "&%@)*%%)", 8);
27 break;
28+#endif /* OPENSSL_NO_DES */
29 default:
30 return TSS_E_BAD_PARAMETER;
31 break;
32@@ -194,6 +196,7 @@ activate_cb(PVOID myArgs, UINT32 symBlobLen, BYTE *symBlob, UINT32 symAttestBlob
33 case TCPA_ALG_AES:
34 memcpy(iv, "&%@)*%%$&#)%&#*$", 16);
35 break;
36+#ifndef OPENSSL_NO_DES
37 case TSS_ALG_DES:
38 case TCPA_ALG_DES:
39 memcpy(iv, "&*$#%)$&", 8);
40@@ -202,6 +205,7 @@ activate_cb(PVOID myArgs, UINT32 symBlobLen, BYTE *symBlob, UINT32 symAttestBlob
41 case TCPA_ALG_3DES:
42 memcpy(iv, "&%@)*%%)", 8);
43 break;
44+#endif /* OPENSSL_NO_DES */
45 default:
46 fprintf(stderr, "Bad algorithm ID: 0x%x\n", symKey.algId);
47 free(symKey.data);
48@@ -438,6 +442,7 @@ ca_create_credential(TSS_HCONTEXT hContext, TSS_HTPM hTPM,
49 asymContents.sessionKey.size = 128/8;
50 memcpy(iv, "&%@)*%%$&#)%&#*$", 16);
51 break;
52+#ifndef OPENSSL_NO_DES
53 case TCPA_ALG_DES:
54 asymContents.sessionKey.size = 64/8;
55 memcpy(iv, "&*$#%)$&", 8);
56@@ -446,6 +451,7 @@ ca_create_credential(TSS_HCONTEXT hContext, TSS_HTPM hTPM,
57 asymContents.sessionKey.size = 192/8;
58 memcpy(iv, "&%@)*%%)", 8);
59 break;
60+#endif /* OPENSSL_NO_DES */
61 default:
62 print_error("Invalid symmetric algorithm!", -1);
63 return TSS_E_INTERNAL_ERROR;
64@@ -727,6 +733,7 @@ main_v1_1(void){
65 }
66
67 switch (symKey.algId) {
68+#ifndef OPENSSL_NO_DES
69 case TCPA_ALG_DES:
70 algID = TSS_ALG_DES;
71 iv = "&*$#%)$&";
72@@ -735,6 +742,7 @@ main_v1_1(void){
73 algID = TSS_ALG_3DES;
74 iv = "&%@)*%%)";
75 break;
76+#endif /* OPENSSL_NO_DES */
77 case TCPA_ALG_AES:
78 algID = TSS_ALG_AES;
79 iv = "&%@)*%%$&#)%&#*$";
diff --git a/meta-tpm/recipes-tpm/tss-testsuite/files/Tspi_TPM_CreateIdentity_no_des.patch b/meta-tpm/recipes-tpm/tss-testsuite/files/Tspi_TPM_CreateIdentity_no_des.patch
new file mode 100644
index 0000000..98b5fad
--- /dev/null
+++ b/meta-tpm/recipes-tpm/tss-testsuite/files/Tspi_TPM_CreateIdentity_no_des.patch
@@ -0,0 +1,45 @@
1diff --git a/tcg/highlevel/tpm/Tspi_TPM_CreateIdentity.c b/tcg/highlevel/tpm/Tspi_TPM_CreateIdentity.c
2index 01a8aca..128f238 100644
3--- a/tcg/highlevel/tpm/Tspi_TPM_CreateIdentity.c
4+++ b/tcg/highlevel/tpm/Tspi_TPM_CreateIdentity.c
5@@ -66,8 +66,8 @@
6
7 #define CERT_VERIFY_BYTE 0x5a
8
9-TCPA_ALGORITHM_ID symAlg = TCPA_ALG_3DES;
10-TSS_ALGORITHM_ID tssSymAlg = TSS_ALG_3DES;
11+TCPA_ALGORITHM_ID symAlg = TCPA_ALG_AES;
12+TSS_ALGORITHM_ID tssSymAlg = TSS_ALG_AES;
13
14 /* substitute this for TPM_IDENTITY_CREDENTIAL in the TPM docs */
15 struct trousers_ca_tpm_identity_credential
16@@ -299,12 +299,14 @@ ca_create_credential(TSS_HCONTEXT hContext, TSS_HTPM hTPM,
17 case TCPA_ALG_AES:
18 asymContents.sessionKey.size = 128/8;
19 break;
20+#ifndef OPENSSL_NO_DES
21 case TCPA_ALG_DES:
22 asymContents.sessionKey.size = 64/8;
23 break;
24 case TCPA_ALG_3DES:
25 asymContents.sessionKey.size = 192/8;
26 break;
27+#endif /* OPENSSL_NO_DES */
28 default:
29 print_error("Invalid symmetric algorithm!", -1);
30 return TSS_E_INTERNAL_ERROR;
31@@ -569,12 +571,14 @@ main_v1_1(void){
32 }
33
34 switch (symKey.algId) {
35+#ifndef OPENSSL_NO_DES
36 case TCPA_ALG_DES:
37 algID = TSS_ALG_DES;
38 break;
39 case TCPA_ALG_3DES:
40 algID = TSS_ALG_3DES;
41 break;
42+#endif /* OPENSSL_NO_DES */
43 case TCPA_ALG_AES:
44 algID = TSS_ALG_AES;
45 break;
diff --git a/meta-tpm/recipes-tpm/tss-testsuite/files/Tspi_TPM_LoadMaintenancePubKey01.patch b/meta-tpm/recipes-tpm/tss-testsuite/files/Tspi_TPM_LoadMaintenancePubKey01.patch
new file mode 100644
index 0000000..213797e
--- /dev/null
+++ b/meta-tpm/recipes-tpm/tss-testsuite/files/Tspi_TPM_LoadMaintenancePubKey01.patch
@@ -0,0 +1,21 @@
1commit e9f5c326e6b2020300d897dd5a75301b54991ca1
2Author: Genli Pan <genli.pan@windriver.com>
3Date: Tue May 12 15:27:48 2015 +0800
4
5fix bug in Tspi_TPM_LoadMaintenancePubKey01.c, assign to the right variable.
6
7Signed-off-by: Genli Pan <genli.pan@windriver.com>
8
9diff --git a/tcg/tpm/Tspi_TPM_LoadMaintenancePubKey01.c b/tcg/tpm/Tspi_TPM_LoadMaintenancePubKey01.c
10index b141d34..e8b18a5 100644
11--- a/tcg/tpm/Tspi_TPM_LoadMaintenancePubKey01.c
12+++ b/tcg/tpm/Tspi_TPM_LoadMaintenancePubKey01.c
13@@ -194,7 +194,7 @@ main_v1_1( void )
14 exit( result );
15 }
16
17- ValidationData.ulDataLength = 20;
18+ ValidationData.ulExternalDataLength = 20;
19 ValidationData.rgbExternalData = data;
20
21 //Load Key Blob
diff --git a/meta-tpm/recipes-tpm/tss-testsuite/files/common_c_no_des.patch b/meta-tpm/recipes-tpm/tss-testsuite/files/common_c_no_des.patch
new file mode 100644
index 0000000..e2ffb7d
--- /dev/null
+++ b/meta-tpm/recipes-tpm/tss-testsuite/files/common_c_no_des.patch
@@ -0,0 +1,36 @@
1diff --git a/tcg/common/common.c b/tcg/common/common.c
2index bafe54c..eda1be5 100644
3--- a/tcg/common/common.c
4+++ b/tcg/common/common.c
5@@ -1729,6 +1729,7 @@ TestSuite_SymEncrypt(UINT16 alg, BYTE mode, BYTE *key, BYTE *iv, BYTE *in, UINT3
6 case TCPA_ALG_AES:
7 cipher = (EVP_CIPHER *)EVP_aes_128_cbc();
8 break;
9+#ifndef OPENSSL_NO_DES
10 case TSS_ALG_DES:
11 case TCPA_ALG_DES:
12 cipher = (EVP_CIPHER *)EVP_des_cbc();
13@@ -1737,6 +1738,7 @@ TestSuite_SymEncrypt(UINT16 alg, BYTE mode, BYTE *key, BYTE *iv, BYTE *in, UINT3
14 case TCPA_ALG_3DES:
15 cipher = (EVP_CIPHER *)EVP_des_ede3_cbc();
16 break;
17+#endif /* OPENSSL_NO_DES */
18 default:
19 return TSS_E_INTERNAL_ERROR;
20 break;
21@@ -1826,6 +1828,7 @@ TestSuite_SymDecrypt(UINT16 alg, BYTE mode, BYTE *key, BYTE *iv, BYTE *in, UINT3
22 case TCPA_ALG_AES:
23 cipher = (EVP_CIPHER *)EVP_aes_128_cbc();
24 break;
25+#ifndef OPENSSL_NO_DES
26 case TSS_ALG_DES:
27 case TCPA_ALG_DES:
28 cipher = (EVP_CIPHER *)EVP_des_cbc();
29@@ -1834,6 +1837,7 @@ TestSuite_SymDecrypt(UINT16 alg, BYTE mode, BYTE *key, BYTE *iv, BYTE *in, UINT3
30 case TCPA_ALG_3DES:
31 cipher = (EVP_CIPHER *)EVP_des_ede3_cbc();
32 break;
33+#endif /* OPENSSL_NO_DES */
34 default:
35 return TSS_E_INTERNAL_ERROR;
36 break;
diff --git a/meta-tpm/recipes-tpm/tss-testsuite/files/fix-failure-of-.so-LD-with-cortexa8t-neon-wrswrap-linux.patch b/meta-tpm/recipes-tpm/tss-testsuite/files/fix-failure-of-.so-LD-with-cortexa8t-neon-wrswrap-linux.patch
new file mode 100644
index 0000000..3aa8bd0
--- /dev/null
+++ b/meta-tpm/recipes-tpm/tss-testsuite/files/fix-failure-of-.so-LD-with-cortexa8t-neon-wrswrap-linux.patch
@@ -0,0 +1,33 @@
1commit 545f6773fcaf7aeff6de84f9e7594bd4c28eaa61
2Author: Yang, Xiao <xiao.yang@windriver.com>
3Date: Wed Mar 27 19:58:26 2013 +0800
4
5Fix package testsuite's compilation failure with ARM cross CC
6
7missing -fPIC flags in ${CFLAGS}, will cause compilation errors
8when compile with cortexa8t-neon-wrswrap-linux-gnueabi-gcc.
9While it appears didn't cause problem when cross compiled for ATOM.
10
11Signed-off-by: Yang, Xiao <xiao.yang@windriver.com>
12Signed-off-by: Genli Pan <genli.pan@windriver.com>
13
14---
15 tcg/common/Makefile | 2 +-
16 1 files changed, 1 insertions(+), 1 deletions(-)
17
18diff --git a/tcg/common/Makefile b/tcg/common/Makefile
19index f389ac0..c6c12db 100644
20--- a/tcg/common/Makefile
21+++ b/tcg/common/Makefile
22@@ -24,7 +24,7 @@ CC = gcc
23 CFLAGS += -g -I../include
24
25 .c.o:
26- $(CC) $(CFLAGS) -c -o $@ $<
27+ $(CC) $(CFLAGS) -fPIC -c -o $@ $<
28
29 all: common.o
30
31--
321.7.0.4
33
diff --git a/meta-tpm/recipes-tpm/tss-testsuite/files/fix-hardcode-path-in-tsstests.sh.patch b/meta-tpm/recipes-tpm/tss-testsuite/files/fix-hardcode-path-in-tsstests.sh.patch
new file mode 100644
index 0000000..a9e6680
--- /dev/null
+++ b/meta-tpm/recipes-tpm/tss-testsuite/files/fix-hardcode-path-in-tsstests.sh.patch
@@ -0,0 +1,16 @@
1diff --git a/tsstests.sh b/tsstests.sh
2index 6a1a5e5..ebaf6c3 100755
3--- a/tsstests.sh
4+++ b/tsstests.sh
5@@ -54,9 +54,9 @@ TEST_OUTPUT=
6 OUTPUT_FORMAT="standard"
7
8 # this variable needs to be changed to testcases/tcg/ for ltp compatibility
9-TESTCASEDIR=testsuite/tcg/
10+TESTCASEDIR=tcg/
11
12-cd ..
13+cd `dirname $0`
14
15 export LTPTSSROOT=$PWD
16
diff --git a/meta-tpm/recipes-tpm/tss-testsuite/files/fix-missing-LDFLAGS-in-compile-command-line.patch b/meta-tpm/recipes-tpm/tss-testsuite/files/fix-missing-LDFLAGS-in-compile-command-line.patch
new file mode 100644
index 0000000..3c11371
--- /dev/null
+++ b/meta-tpm/recipes-tpm/tss-testsuite/files/fix-missing-LDFLAGS-in-compile-command-line.patch
@@ -0,0 +1,25 @@
1From 93f3d150cc1147997be4401b5a14c5bb3120bf0a Mon Sep 17 00:00:00 2001
2From: Yang, Xiao <xiao.yang@windriver.com>
3Date: Thu, 21 Mar 2013 14:24:24 +0800
4Subject: [PATCH] fix missing LDFLAGS in compile command line to locate libs
5
6---
7 tcg/transport/Makefile | 2 +-
8 1 files changed, 1 insertions(+), 1 deletions(-)
9
10diff --git a/tcg/transport/Makefile b/tcg/transport/Makefile
11index 7b511a0..21568dc 100644
12--- a/tcg/transport/Makefile
13+++ b/tcg/transport/Makefile
14@@ -27,7 +27,7 @@ else
15 OPTS =
16 endif
17 ALL = $(shell ls *.c | sed "s/\.c//g")
18-LIBS = ../common/common.o -ltspi
19+LIBS = ../common/common.o -ltspi $(LDFLAGS)
20 CFLAGS += -g -I../include
21
22 .c:
23--
241.7.0.4
25
diff --git a/meta-tpm/recipes-tpm/tss-testsuite/files/testsuite-transport-init.patch b/meta-tpm/recipes-tpm/tss-testsuite/files/testsuite-transport-init.patch
new file mode 100644
index 0000000..d25fabb
--- /dev/null
+++ b/meta-tpm/recipes-tpm/tss-testsuite/files/testsuite-transport-init.patch
@@ -0,0 +1,38 @@
1commit 6110b3e5c9cb0e56319d5000e9785171ec9b9559
2Author: Genli Pan <genli.pan@windriver.com>
3Date: Mon Dec 15 11:18:49 2014 +0800
4
5testsuite: fix transport session not released problem
6
7According to TPM Spec v1.2, TPM_ReleaseTransportSigned command uses two
8authorization sessions, but testsuite use one authorization session when
9release transport session, this causes transport session actually not be
10released in TPM unit, even though TPM return success, in haswell. Fix
11testsuite_transport_init() in testsuite. After this fix, transport testcases
12works both on haswell and crosshill.
13
14Signed-off-by: Genli Pan <genli.pan@windriver.com>
15
16--- testsuite-0.3.orig/tcg/common/common.c 2014-10-15 19:04:50.000000000 +0800
17+++ testsuite-0.3/tcg/common/common.c 2014-12-11 15:59:01.000000000 +0800
18@@ -2124,12 +2124,19 @@
19 // Create the key used to sign the transport session
20 result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_RSAKEY,
21 TSS_KEY_SIZE_512 | TSS_KEY_TYPE_SIGNING |
22- TSS_KEY_NO_AUTHORIZATION, hSigningKey);
23+ TSS_KEY_AUTHORIZATION, hSigningKey);
24 if (result != TSS_SUCCESS) {
25 print_error("Tspi_Context_CreateObject", result);
26 return result;
27 }
28
29+ result = Tspi_Policy_AssignToObject(hPolicy, *hSigningKey);
30+ if ( result != TSS_SUCCESS )
31+ {
32+ print_error("Tspi_Policy_AssignToObject", result);
33+ return result;
34+ }
35+
36 result = Tspi_Key_CreateKey(*hSigningKey, hSRK, 0);
37 if (result != TSS_SUCCESS) {
38 print_error("Tspi_Key_CreateKey", result);
diff --git a/meta-tpm/recipes-tpm/tss-testsuite/files/transport-Tspi_TPM_Delegate.patch b/meta-tpm/recipes-tpm/tss-testsuite/files/transport-Tspi_TPM_Delegate.patch
new file mode 100644
index 0000000..61235ed
--- /dev/null
+++ b/meta-tpm/recipes-tpm/tss-testsuite/files/transport-Tspi_TPM_Delegate.patch
@@ -0,0 +1,2284 @@
1commit ed7a8f0a0c31c20d35e567e1625c0edfe77b8276
2Author: Genli Pan <genli.pan@windriver.com>
3Date: Mon Jul 6 18:03:15 2015 +0800
4
5fix logical errors in transport delegate testcases
6
7There are obvious logical errors and redundant code in these testcases.
8Resouces are not been released properly. they didn't cause errors in some
9TPM chips because these TPMs have enough resouces to be abused.
10But in Atmel TPM resource is so limited that allows no abusing.
11
12Signed-off-by: Genli Pan <genli.pan@windriver.com>
13
14diff --git a/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans01.c b/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans01.c
15index fd59e47..12ebd69 100644
16--- a/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans01.c
17+++ b/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans01.c
18@@ -86,8 +86,6 @@ main_v1_2( char version )
19 if ( result != TSS_SUCCESS )
20 {
21 print_error("connect_load_all", result);
22- Tspi_Context_FreeMemory( hContext, NULL );
23- Tspi_Context_Close( hContext );
24 exit( result );
25 }
26
27@@ -99,33 +97,20 @@ main_v1_2( char version )
28 exit(result);
29 }
30
31- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
32- if ( result != TSS_SUCCESS )
33- {
34- print_error( "Tspi_GetPolicyObject", result );
35- goto done;
36- }
37-
38- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
39- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
40- if ( result != TSS_SUCCESS )
41- {
42- print_error( "Tspi_Policy_SetSecret", result );
43- goto done;
44- }
45-
46 result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
47 if ( result != TSS_SUCCESS )
48 {
49 print_error( "Tspi_TPM_Delegate_AddFamily", result );
50- goto done;
51- }
52+ } else {
53
54+ /* Invalidate the family to avoid resource exhaustion */
55+ if (hFamily != NULL_HDELFAMILY)
56+ Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
57+ }
58 result = Testsuite_Transport_Final(hContext, hSigningKey);
59 if ( result != TSS_SUCCESS )
60 {
61 print_error("Testsuite_Transport_Final", result);
62- goto done;
63 }
64 else
65 {
66@@ -133,11 +118,6 @@ main_v1_2( char version )
67 }
68
69 print_end_test( function );
70-done:
71- /* Invalidate the family to avoid resource exhaustion */
72- if (hFamily != NULL_HDELFAMILY)
73- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
74- Tspi_Context_FreeMemory( hContext, NULL );
75 Tspi_Context_Close( hContext );
76- exit( 0 );
77+ exit( result );
78 }
79diff --git a/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans02.c b/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans02.c
80index 3dd3299..3fe8cff 100644
81--- a/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans02.c
82+++ b/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans02.c
83@@ -86,8 +86,6 @@ main_v1_2( char version )
84 if ( result != TSS_SUCCESS )
85 {
86 print_error("connect_load_all", result);
87- Tspi_Context_FreeMemory( hContext, NULL );
88- Tspi_Context_Close( hContext );
89 exit( result );
90 }
91
92@@ -99,33 +97,20 @@ main_v1_2( char version )
93 exit(result);
94 }
95
96- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
97- if ( result != TSS_SUCCESS )
98- {
99- print_error( "Tspi_GetPolicyObject", result );
100- goto done;
101- }
102-
103- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
104- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
105- if ( result != TSS_SUCCESS )
106- {
107- print_error( "Tspi_Policy_SetSecret", result );
108- goto done;
109- }
110-
111 result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
112 if ( result != TSS_SUCCESS )
113 {
114 print_error( "Tspi_TPM_Delegate_AddFamily", result );
115- goto done;
116- }
117+ } else {
118
119+ /* Invalidate the family to avoid resource exhaustion */
120+ if (hFamily != NULL_HDELFAMILY)
121+ Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
122+ }
123 result = Testsuite_Transport_Final(hContext, hSigningKey);
124 if ( result != TSS_SUCCESS )
125 {
126 print_error("Testsuite_Transport_Final", result);
127- goto done;
128 }
129 else
130 {
131@@ -133,11 +118,6 @@ main_v1_2( char version )
132 }
133
134 print_end_test( function );
135-done:
136- /* Invalidate the family to avoid resource exhaustion */
137- if (hFamily != NULL_HDELFAMILY)
138- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
139- Tspi_Context_FreeMemory( hContext, NULL );
140 Tspi_Context_Close( hContext );
141- exit( 0 );
142+ exit( result );
143 }
144diff --git a/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans03.c b/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans03.c
145index 8b149d2..98c6127 100644
146--- a/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans03.c
147+++ b/tcg/transport/Tspi_TPM_Delegate_AddFamily-trans03.c
148@@ -86,8 +86,6 @@ main_v1_2( char version )
149 if ( result != TSS_SUCCESS )
150 {
151 print_error("connect_load_all", result);
152- Tspi_Context_FreeMemory( hContext, NULL );
153- Tspi_Context_Close( hContext );
154 exit( result );
155 }
156
157@@ -99,33 +97,20 @@ main_v1_2( char version )
158 exit(result);
159 }
160
161- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
162- if ( result != TSS_SUCCESS )
163- {
164- print_error( "Tspi_GetPolicyObject", result );
165- goto done;
166- }
167-
168- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
169- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
170- if ( result != TSS_SUCCESS )
171- {
172- print_error( "Tspi_Policy_SetSecret", result );
173- goto done;
174- }
175-
176 result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
177 if ( result != TSS_SUCCESS )
178 {
179 print_error( "Tspi_TPM_Delegate_AddFamily", result );
180- goto done;
181- }
182+ } else {
183
184+ /* Invalidate the family to avoid resource exhaustion */
185+ if (hFamily != NULL_HDELFAMILY)
186+ Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
187+ }
188 result = Testsuite_Transport_Final(hContext, 0);
189 if ( result != TSS_SUCCESS )
190 {
191 print_error("Testsuite_Transport_Final", result);
192- goto done;
193 }
194 else
195 {
196@@ -133,11 +118,6 @@ main_v1_2( char version )
197 }
198
199 print_end_test( function );
200-done:
201- /* Invalidate the family to avoid resource exhaustion */
202- if (hFamily != NULL_HDELFAMILY)
203- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
204- Tspi_Context_FreeMemory( hContext, NULL );
205 Tspi_Context_Close( hContext );
206- exit( 0 );
207+ exit( result );
208 }
209diff --git a/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans01.c b/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans01.c
210index 663c6eb..ef9cac1 100644
211--- a/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans01.c
212+++ b/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans01.c
213@@ -89,7 +89,7 @@ main_v1_2( char version )
214 if ( result != TSS_SUCCESS )
215 {
216 print_error("connect_load_all", result);
217- goto done;
218+ exit(result);
219 }
220
221 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, FALSE, &hWrappingKey,
222@@ -100,21 +100,20 @@ main_v1_2( char version )
223 exit(result);
224 }
225
226- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
227+ result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
228 if ( result != TSS_SUCCESS )
229 {
230- print_error( "Tspi_GetPolicyObject", result );
231- goto done;
232+ print_error( "Tspi_TPM_Delegate_AddFamily", result );
233+ goto done_trans;
234 }
235
236- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
237- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
238+ result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
239+ TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
240 if ( result != TSS_SUCCESS )
241 {
242- print_error( "Tspi_Policy_SetSecret", result );
243+ print_error( "Tspi_SetAttribUint32", result );
244 goto done;
245 }
246-
247 result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation);
248 if ( result != TSS_SUCCESS )
249 {
250@@ -154,21 +153,6 @@ main_v1_2( char version )
251 goto done;
252 }
253
254- result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
255- if ( result != TSS_SUCCESS )
256- {
257- print_error( "Tspi_TPM_Delegate_AddFamily", result );
258- goto done;
259- }
260-
261- result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
262- TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
263- if ( result != TSS_SUCCESS )
264- {
265- print_error( "Tspi_SetAttribUint32", result );
266- goto done;
267- }
268-
269 result = Tspi_TPM_Delegate_CreateDelegation(hTPM, 'b', 0, NULL_HPCRS, hFamily, hDelegation);
270 if ( result != TSS_SUCCESS )
271 {
272@@ -182,27 +166,22 @@ main_v1_2( char version )
273 if ( result != TSS_SUCCESS )
274 {
275 print_error( "Tspi_TPM_Delegate_CacheOwnerDelegation", result );
276- goto done;
277- }
278-
279- result = Testsuite_Transport_Final(hContext, hSigningKey);
280- if ( result != TSS_SUCCESS )
281- {
282- print_error( "Testsuite_Transport_Final", result );
283- goto done;
284 }
285 else
286 {
287 print_success( function, result );
288 }
289-
290- print_end_test( function );
291 done:
292 /* Invalidate the family to avoid resource exhaustion */
293 if (hFamily != NULL_HDELFAMILY)
294 Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
295- Tspi_Context_FreeMemory( hContext, NULL );
296+done_trans:
297+ result = Testsuite_Transport_Final(hContext, hSigningKey);
298+ if ( result != TSS_SUCCESS )
299+ {
300+ print_error( "Testsuite_Transport_Final", result);
301+ }
302 Tspi_Context_Close( hContext );
303-
304+ print_end_test( function );
305 exit( result );
306 }
307diff --git a/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans02.c b/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans02.c
308index eaed650..d3c19e8 100644
309--- a/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans02.c
310+++ b/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans02.c
311@@ -88,8 +88,8 @@ main_v1_2( char version )
312 result = connect_load_all(&hContext, &hSRK, &hTPM);
313 if ( result != TSS_SUCCESS )
314 {
315- print_error( "connect_load_all", result );
316- goto done;
317+ print_error( "connect_load_all", result);
318+ exit(result);
319 }
320
321 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
322@@ -100,21 +100,20 @@ main_v1_2( char version )
323 exit(result);
324 }
325
326- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
327+ result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
328 if ( result != TSS_SUCCESS )
329 {
330- print_error( "Tspi_GetPolicyObject", result );
331- goto done;
332+ print_error( "Tspi_TPM_Delegate_AddFamily", result );
333+ goto done_trans;
334 }
335
336- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
337- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
338+ result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
339+ TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
340 if ( result != TSS_SUCCESS )
341 {
342- print_error( "Tspi_Policy_SetSecret", result );
343+ print_error( "Tspi_SetAttribUint32", result );
344 goto done;
345 }
346-
347 result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation);
348 if ( result != TSS_SUCCESS )
349 {
350@@ -154,21 +153,6 @@ main_v1_2( char version )
351 goto done;
352 }
353
354- result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
355- if ( result != TSS_SUCCESS )
356- {
357- print_error( "Tspi_TPM_Delegate_AddFamily", result );
358- goto done;
359- }
360-
361- result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
362- TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
363- if ( result != TSS_SUCCESS )
364- {
365- print_error( "Tspi_SetAttribUint32", result );
366- goto done;
367- }
368-
369 result = Tspi_TPM_Delegate_CreateDelegation(hTPM, 'b', 0, NULL_HPCRS, hFamily, hDelegation);
370 if ( result != TSS_SUCCESS )
371 {
372@@ -182,27 +166,22 @@ main_v1_2( char version )
373 if ( result != TSS_SUCCESS )
374 {
375 print_error( "Tspi_TPM_Delegate_CacheOwnerDelegation", result );
376- goto done;
377- }
378-
379- result = Testsuite_Transport_Final(hContext, hSigningKey);
380- if ( result != TSS_SUCCESS )
381- {
382- print_error( "Testsuite_Transport_Final", result );
383- goto done;
384 }
385 else
386 {
387 print_success( function, result );
388 }
389-
390- print_end_test( function );
391 done:
392 /* Invalidate the family to avoid resource exhaustion */
393 if (hFamily != NULL_HDELFAMILY)
394 Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
395- Tspi_Context_FreeMemory( hContext, NULL );
396+done_trans:
397+ result = Testsuite_Transport_Final(hContext, hSigningKey);
398+ if ( result != TSS_SUCCESS )
399+ {
400+ print_error( "Testsuite_Transport_Final", result);
401+ }
402 Tspi_Context_Close( hContext );
403-
404+ print_end_test( function );
405 exit( result );
406 }
407diff --git a/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans03.c b/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans03.c
408index 0585386..b84fd55 100644
409--- a/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans03.c
410+++ b/tcg/transport/Tspi_TPM_Delegate_CacheOwnerDelegation-trans03.c
411@@ -89,7 +89,7 @@ main_v1_2( char version )
412 if ( result != TSS_SUCCESS )
413 {
414 print_error( "connect_load_all", result );
415- goto done;
416+ exit(result);
417 }
418
419 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
420@@ -100,18 +100,18 @@ main_v1_2( char version )
421 exit(result);
422 }
423
424- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
425+ result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
426 if ( result != TSS_SUCCESS )
427 {
428- print_error( "Tspi_GetPolicyObject", result );
429- goto done;
430+ print_error( "Tspi_TPM_Delegate_AddFamily", result );
431+ goto done_trans;
432 }
433
434- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
435- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
436+ result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
437+ TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
438 if ( result != TSS_SUCCESS )
439 {
440- print_error( "Tspi_Policy_SetSecret", result );
441+ print_error( "Tspi_SetAttribUint32", result );
442 goto done;
443 }
444
445@@ -154,21 +154,6 @@ main_v1_2( char version )
446 goto done;
447 }
448
449- result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
450- if ( result != TSS_SUCCESS )
451- {
452- print_error( "Tspi_TPM_Delegate_AddFamily", result );
453- goto done;
454- }
455-
456- result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
457- TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
458- if ( result != TSS_SUCCESS )
459- {
460- print_error( "Tspi_SetAttribUint32", result );
461- goto done;
462- }
463-
464 result = Tspi_TPM_Delegate_CreateDelegation(hTPM, 'b', 0, NULL_HPCRS, hFamily, hDelegation);
465 if ( result != TSS_SUCCESS )
466 {
467@@ -182,27 +167,23 @@ main_v1_2( char version )
468 if ( result != TSS_SUCCESS )
469 {
470 print_error( "Tspi_TPM_Delegate_CacheOwnerDelegation", result );
471- goto done;
472- }
473-
474- result = Testsuite_Transport_Final(hContext, 0);
475- if ( result != TSS_SUCCESS )
476- {
477- print_error( "Testsuite_Transport_Final", result );
478- goto done;
479 }
480 else
481 {
482 print_success( function, result );
483 }
484-
485- print_end_test( function );
486 done:
487 /* Invalidate the family to avoid resource exhaustion */
488 if (hFamily != NULL_HDELFAMILY)
489 Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
490- Tspi_Context_FreeMemory( hContext, NULL );
491- Tspi_Context_Close( hContext );
492+done_trans:
493+ result = Testsuite_Transport_Final(hContext, 0);
494+ if ( result != TSS_SUCCESS )
495+ {
496+ print_error( "Testsuite_Transport_Final", result);
497+ }
498
499+ Tspi_Context_Close( hContext );
500+ print_end_test( function );
501 exit( result );
502 }
503diff --git a/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans01.c b/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans01.c
504index 66708e2..51a59c2 100644
505--- a/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans01.c
506+++ b/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans01.c
507@@ -89,7 +89,7 @@ main_v1_2( char version )
508 if ( result != TSS_SUCCESS )
509 {
510 print_error( "connect_load_all", (result) );
511- goto done;
512+ exit(result);
513 }
514
515 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, FALSE, &hWrappingKey,
516@@ -99,19 +99,12 @@ main_v1_2( char version )
517 Tspi_Context_Close(hContext);
518 exit(result);
519 }
520- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
521- if ( result != TSS_SUCCESS )
522- {
523- print_error( "Tspi_GetPolicyObject", result );
524- goto done;
525- }
526
527- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
528- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
529+ result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
530 if ( result != TSS_SUCCESS )
531 {
532- print_error( "Tspi_Policy_SetSecret", result );
533- goto done;
534+ print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
535+ goto done_trans;
536 }
537
538 result = create_load_key(hContext, TSS_KEY_TYPE_STORAGE | TSS_KEY_AUTHORIZATION, hSRK, &hKey);
539@@ -160,38 +153,27 @@ main_v1_2( char version )
540 goto done;
541 }
542
543- result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
544- if ( result != TSS_SUCCESS )
545- {
546- print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
547- goto done;
548- }
549-
550 result = Tspi_TPM_Delegate_CreateDelegation(hKey, 'b', 0, NULL_HPCRS, hFamily, hDelegation);
551 if ( result != TSS_SUCCESS )
552 {
553 print_error( "Tspi_TPM_Delegate_CreateDelegation", (result) );
554- goto done;
555- }
556-
557- result = Testsuite_Transport_Final(hContext, hSigningKey);
558- if ( result != TSS_SUCCESS )
559- {
560- print_error( function, (result) );
561- goto done;
562 }
563 else
564 {
565 print_success( function, result );
566 }
567-
568- print_end_test( function );
569 done:
570 /* Invalidate the family to avoid resource exhaustion */
571- if (hFamily != NULL_HDELFAMILY)
572- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
573- Tspi_Context_FreeMemory( hContext, NULL );
574+ Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
575+done_trans:
576+ result = Testsuite_Transport_Final(hContext, hSigningKey);
577+ if ( result != TSS_SUCCESS )
578+ {
579+ print_error( "Testsuite_Transport_Final", result);
580+ }
581+
582 Tspi_Context_Close( hContext );
583+ print_end_test( function );
584
585 exit( result );
586 }
587diff --git a/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans02.c b/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans02.c
588index 42b5709..8263422 100644
589--- a/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans02.c
590+++ b/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans02.c
591@@ -89,7 +89,7 @@ main_v1_2( char version )
592 if ( result != TSS_SUCCESS )
593 {
594 print_error( "connect_load_all", (result) );
595- goto done;
596+ exit(result);
597 }
598
599 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
600@@ -100,19 +100,11 @@ main_v1_2( char version )
601 exit(result);
602 }
603
604- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
605- if ( result != TSS_SUCCESS )
606- {
607- print_error( "Tspi_GetPolicyObject", result );
608- goto done;
609- }
610-
611- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
612- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
613+ result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
614 if ( result != TSS_SUCCESS )
615 {
616- print_error( "Tspi_Policy_SetSecret", result );
617- goto done;
618+ print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
619+ goto done_trans;
620 }
621
622 result = create_load_key(hContext, TSS_KEY_TYPE_STORAGE | TSS_KEY_AUTHORIZATION, hSRK, &hKey);
623@@ -161,38 +153,27 @@ main_v1_2( char version )
624 goto done;
625 }
626
627- result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
628- if ( result != TSS_SUCCESS )
629- {
630- print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
631- goto done;
632- }
633-
634 result = Tspi_TPM_Delegate_CreateDelegation(hKey, 'b', 0, NULL_HPCRS, hFamily, hDelegation);
635 if ( result != TSS_SUCCESS )
636 {
637 print_error( "Tspi_TPM_Delegate_CreateDelegation", (result) );
638- goto done;
639- }
640-
641- result = Testsuite_Transport_Final(hContext, hSigningKey);
642- if ( result != TSS_SUCCESS )
643- {
644- print_error( function, (result) );
645- goto done;
646 }
647 else
648 {
649 print_success( function, result );
650 }
651-
652- print_end_test( function );
653 done:
654 /* Invalidate the family to avoid resource exhaustion */
655- if (hFamily != NULL_HDELFAMILY)
656- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
657- Tspi_Context_FreeMemory( hContext, NULL );
658+ Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
659+done_trans:
660+ result = Testsuite_Transport_Final(hContext, hSigningKey);
661+ if ( result != TSS_SUCCESS )
662+ {
663+ print_error( "Testsuite_Transport_Final", result);
664+ }
665+
666 Tspi_Context_Close( hContext );
667+ print_end_test( function );
668
669 exit( result );
670 }
671diff --git a/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans03.c b/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans03.c
672index bdfa2f2..1a139e0 100644
673--- a/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans03.c
674+++ b/tcg/transport/Tspi_TPM_Delegate_CreateKeyDelegation-trans03.c
675@@ -75,7 +75,7 @@ main_v1_2( char version )
676 {
677 char * function = "Tspi_TPM_Delegate_CreateKeyDelegation-trans03";
678 TSS_HCONTEXT hContext;
679- TSS_HKEY hSRK, hWrappingKey;
680+ TSS_HKEY hSRK, hSigningKey, hWrappingKey;
681 TSS_HTPM hTPM;
682 TSS_HPOLICY hTPMPolicy;
683 TSS_HKEY hKey;
684@@ -89,7 +89,7 @@ main_v1_2( char version )
685 if ( result != TSS_SUCCESS )
686 {
687 print_error( "connect_load_all", (result) );
688- goto done;
689+ exit(result);
690 }
691
692 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
693@@ -100,19 +100,11 @@ main_v1_2( char version )
694 exit(result);
695 }
696
697- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
698- if ( result != TSS_SUCCESS )
699- {
700- print_error( "Tspi_GetPolicyObject", result );
701- goto done;
702- }
703-
704- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
705- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
706+ result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
707 if ( result != TSS_SUCCESS )
708 {
709- print_error( "Tspi_Policy_SetSecret", result );
710- goto done;
711+ print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
712+ goto done_trans;
713 }
714
715 result = create_load_key(hContext, TSS_KEY_TYPE_STORAGE | TSS_KEY_AUTHORIZATION, hSRK, &hKey);
716@@ -161,38 +153,27 @@ main_v1_2( char version )
717 goto done;
718 }
719
720- result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
721- if ( result != TSS_SUCCESS )
722- {
723- print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
724- goto done;
725- }
726-
727 result = Tspi_TPM_Delegate_CreateDelegation(hKey, 'b', 0, NULL_HPCRS, hFamily, hDelegation);
728 if ( result != TSS_SUCCESS )
729 {
730 print_error( "Tspi_TPM_Delegate_CreateDelegation", (result) );
731- goto done;
732- }
733-
734- result = Testsuite_Transport_Final(hContext, 0);
735- if ( result != TSS_SUCCESS )
736- {
737- print_error( function, (result) );
738- goto done;
739 }
740 else
741 {
742 print_success( function, result );
743 }
744-
745- print_end_test( function );
746 done:
747 /* Invalidate the family to avoid resource exhaustion */
748- if (hFamily != NULL_HDELFAMILY)
749- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
750- Tspi_Context_FreeMemory( hContext, NULL );
751+ Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
752+done_trans:
753+ result = Testsuite_Transport_Final(hContext, NULL);
754+ if ( result != TSS_SUCCESS )
755+ {
756+ print_error( "Testsuite_Transport_Final", result);
757+ }
758+
759 Tspi_Context_Close( hContext );
760+ print_end_test( function );
761
762 exit( result );
763 }
764diff --git a/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans01.c b/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans01.c
765index e8e225e..e714e13 100644
766--- a/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans01.c
767+++ b/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans01.c
768@@ -88,7 +88,7 @@ main_v1_2( char version )
769 if ( result != TSS_SUCCESS )
770 {
771 print_error( "connect_load_all", (result) );
772- goto done;
773+ exit(result);
774 }
775
776 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, FALSE, &hWrappingKey,
777@@ -98,20 +98,6 @@ main_v1_2( char version )
778 Tspi_Context_Close(hContext);
779 exit(result);
780 }
781- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
782- if ( result != TSS_SUCCESS )
783- {
784- print_error( "Tspi_GetPolicyObject", result );
785- goto done;
786- }
787-
788- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
789- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
790- if ( result != TSS_SUCCESS )
791- {
792- print_error( "Tspi_Policy_SetSecret", result );
793- goto done;
794- }
795
796 result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation);
797 if ( result != TSS_SUCCESS )
798@@ -163,26 +149,22 @@ main_v1_2( char version )
799 if ( result != TSS_SUCCESS )
800 {
801 print_error( "Tspi_TPM_Delegate_CreateDelegation", (result) );
802- goto done;
803+ }
804+ else
805+ {
806+ print_success( function, result );
807 }
808
809+ /* Invalidate the family to avoid resource exhaustion */
810+ Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
811+done:
812 result = Testsuite_Transport_Final(hContext, hSigningKey);
813 if ( result != TSS_SUCCESS )
814 {
815- print_error( function, (result) );
816- goto done;
817- }
818- else
819- {
820- print_success( function, result );
821+ print_error( "Testsuite_Transport_Final", (result) );
822 }
823
824 print_end_test( function );
825-done:
826- /* Invalidate the family to avoid resource exhaustion */
827- if (hFamily != NULL_HDELFAMILY)
828- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
829- Tspi_Context_FreeMemory( hContext, NULL );
830 Tspi_Context_Close( hContext );
831
832 exit( result );
833diff --git a/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans02.c b/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans02.c
834index d372cb5..66a75ec 100644
835--- a/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans02.c
836+++ b/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans02.c
837@@ -88,7 +88,7 @@ main_v1_2( char version )
838 if ( result != TSS_SUCCESS )
839 {
840 print_error( "connect_load_all", (result) );
841- goto done;
842+ exit(result);
843 }
844
845 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
846@@ -98,20 +98,6 @@ main_v1_2( char version )
847 Tspi_Context_Close(hContext);
848 exit(result);
849 }
850- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
851- if ( result != TSS_SUCCESS )
852- {
853- print_error( "Tspi_GetPolicyObject", result );
854- goto done;
855- }
856-
857- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
858- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
859- if ( result != TSS_SUCCESS )
860- {
861- print_error( "Tspi_Policy_SetSecret", result );
862- goto done;
863- }
864
865 result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation);
866 if ( result != TSS_SUCCESS )
867@@ -163,26 +149,22 @@ main_v1_2( char version )
868 if ( result != TSS_SUCCESS )
869 {
870 print_error( "Tspi_TPM_Delegate_CreateDelegation", (result) );
871- goto done;
872+ }
873+ else
874+ {
875+ print_success( function, result );
876 }
877
878+ /* Invalidate the family to avoid resource exhaustion */
879+ Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
880+done:
881 result = Testsuite_Transport_Final(hContext, hSigningKey);
882 if ( result != TSS_SUCCESS )
883 {
884- print_error( function, (result) );
885- goto done;
886- }
887- else
888- {
889- print_success( function, result );
890+ print_error( "Testsuite_Transport_Final", (result) );
891 }
892
893 print_end_test( function );
894-done:
895- /* Invalidate the family to avoid resource exhaustion */
896- if (hFamily != NULL_HDELFAMILY)
897- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
898- Tspi_Context_FreeMemory( hContext, NULL );
899 Tspi_Context_Close( hContext );
900
901 exit( result );
902diff --git a/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans03.c b/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans03.c
903index 18246de..89eca65 100644
904--- a/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans03.c
905+++ b/tcg/transport/Tspi_TPM_Delegate_CreateOwnerDelegation-trans03.c
906@@ -75,7 +75,7 @@ main_v1_2( char version )
907 {
908 char * function = "Tspi_TPM_Delegate_CreateOwnerDelegation-trans03";
909 TSS_HCONTEXT hContext;
910- TSS_HKEY hSRK, hWrappingKey;
911+ TSS_HKEY hSRK, hSigningKey, hWrappingKey;
912 TSS_HTPM hTPM;
913 TSS_HPOLICY hTPMPolicy;
914 TSS_HPOLICY hDelegation = NULL_HPOLICY;
915@@ -88,7 +88,7 @@ main_v1_2( char version )
916 if ( result != TSS_SUCCESS )
917 {
918 print_error( "connect_load_all", (result) );
919- goto done;
920+ exit(result);
921 }
922
923 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
924@@ -98,20 +98,6 @@ main_v1_2( char version )
925 Tspi_Context_Close(hContext);
926 exit(result);
927 }
928- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
929- if ( result != TSS_SUCCESS )
930- {
931- print_error( "Tspi_GetPolicyObject", result );
932- goto done;
933- }
934-
935- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
936- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
937- if ( result != TSS_SUCCESS )
938- {
939- print_error( "Tspi_Policy_SetSecret", result );
940- goto done;
941- }
942
943 result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation);
944 if ( result != TSS_SUCCESS )
945@@ -163,26 +149,22 @@ main_v1_2( char version )
946 if ( result != TSS_SUCCESS )
947 {
948 print_error( "Tspi_TPM_Delegate_CreateDelegation", (result) );
949- goto done;
950- }
951-
952- result = Testsuite_Transport_Final(hContext, 0);
953- if ( result != TSS_SUCCESS )
954- {
955- print_error( function, (result) );
956- goto done;
957 }
958 else
959 {
960 print_success( function, result );
961 }
962
963- print_end_test( function );
964-done:
965 /* Invalidate the family to avoid resource exhaustion */
966- if (hFamily != NULL_HDELFAMILY)
967- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
968- Tspi_Context_FreeMemory( hContext, NULL );
969+ Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
970+done:
971+ result = Testsuite_Transport_Final(hContext, NULL);
972+ if ( result != TSS_SUCCESS )
973+ {
974+ print_error( "Testsuite_Transport_Final", (result) );
975+ }
976+
977+ print_end_test( function );
978 Tspi_Context_Close( hContext );
979
980 exit( result );
981diff --git a/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans01.c b/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans01.c
982index f5a376d..8c190a6 100644
983--- a/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans01.c
984+++ b/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans01.c
985@@ -88,7 +88,7 @@ main_v1_2( char version )
986 if ( result != TSS_SUCCESS )
987 {
988 print_error( "connect_load_all", (result) );
989- goto done;
990+ exit(result);
991 }
992
993 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, FALSE, &hWrappingKey,
994@@ -99,27 +99,11 @@ main_v1_2( char version )
995 exit(result);
996 }
997
998- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
999- if ( result != TSS_SUCCESS )
1000- {
1001- print_error( "Tspi_GetPolicyObject", result );
1002- goto done;
1003- }
1004-
1005- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
1006- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
1007- if ( result != TSS_SUCCESS )
1008- {
1009- print_error( "Tspi_Policy_SetSecret", result );
1010- goto done;
1011- }
1012-
1013 result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
1014 if ( result != TSS_SUCCESS )
1015 {
1016 print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
1017- goto done;
1018- }
1019+ } else {
1020
1021 result = Tspi_GetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_INFO,
1022 TSS_TSPATTRIB_DELFAMILYINFO_FAMILYID, &familyID);
1023@@ -151,7 +135,6 @@ main_v1_2( char version )
1024 goto done;
1025 }
1026
1027- result = Testsuite_Transport_Final(hContext, hSigningKey);
1028 if ( result != TSS_SUCCESS )
1029 {
1030 if( !(checkNonAPI(result)) )
1031@@ -178,13 +161,13 @@ main_v1_2( char version )
1032 }
1033 }
1034
1035- print_end_test( function );
1036 done:
1037 /* Invalidate the family to avoid resource exhaustion */
1038- if (hFamily != NULL_HDELFAMILY)
1039- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1040- Tspi_Context_FreeMemory( hContext, NULL );
1041+ Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1042+ }
1043+ result = Testsuite_Transport_Final(hContext, hSigningKey);
1044 Tspi_Context_Close( hContext );
1045
1046+ print_end_test( function );
1047 exit( result );
1048 }
1049diff --git a/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans02.c b/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans02.c
1050index 2249727..ddd1af0 100644
1051--- a/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans02.c
1052+++ b/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans02.c
1053@@ -88,7 +88,7 @@ main_v1_2( char version )
1054 if ( result != TSS_SUCCESS )
1055 {
1056 print_error( "connect_load_all", (result) );
1057- goto done;
1058+ exit(result);
1059 }
1060
1061 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
1062@@ -99,27 +99,11 @@ main_v1_2( char version )
1063 exit(result);
1064 }
1065
1066- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
1067- if ( result != TSS_SUCCESS )
1068- {
1069- print_error( "Tspi_GetPolicyObject", result );
1070- goto done;
1071- }
1072-
1073- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
1074- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
1075- if ( result != TSS_SUCCESS )
1076- {
1077- print_error( "Tspi_Policy_SetSecret", result );
1078- goto done;
1079- }
1080-
1081 result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
1082 if ( result != TSS_SUCCESS )
1083 {
1084 print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
1085- goto done;
1086- }
1087+ } else {
1088
1089 result = Tspi_GetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_INFO,
1090 TSS_TSPATTRIB_DELFAMILYINFO_FAMILYID, &familyID);
1091@@ -151,7 +135,6 @@ main_v1_2( char version )
1092 goto done;
1093 }
1094
1095- result = Testsuite_Transport_Final(hContext, hSigningKey);
1096 if ( result != TSS_SUCCESS )
1097 {
1098 if( !(checkNonAPI(result)) )
1099@@ -178,13 +161,13 @@ main_v1_2( char version )
1100 }
1101 }
1102
1103- print_end_test( function );
1104 done:
1105 /* Invalidate the family to avoid resource exhaustion */
1106- if (hFamily != NULL_HDELFAMILY)
1107- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1108- Tspi_Context_FreeMemory( hContext, NULL );
1109+ Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1110+ }
1111+ result = Testsuite_Transport_Final(hContext, hSigningKey);
1112 Tspi_Context_Close( hContext );
1113
1114+ print_end_test( function );
1115 exit( result );
1116 }
1117diff --git a/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans03.c b/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans03.c
1118index d45c5f2..aa07e69 100644
1119--- a/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans03.c
1120+++ b/tcg/transport/Tspi_TPM_Delegate_GetFamily-trans03.c
1121@@ -88,7 +88,7 @@ main_v1_2( char version )
1122 if ( result != TSS_SUCCESS )
1123 {
1124 print_error( "connect_load_all", (result) );
1125- goto done;
1126+ exit(result);
1127 }
1128
1129 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
1130@@ -99,27 +99,11 @@ main_v1_2( char version )
1131 exit(result);
1132 }
1133
1134- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
1135- if ( result != TSS_SUCCESS )
1136- {
1137- print_error( "Tspi_GetPolicyObject", result );
1138- goto done;
1139- }
1140-
1141- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
1142- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
1143- if ( result != TSS_SUCCESS )
1144- {
1145- print_error( "Tspi_Policy_SetSecret", result );
1146- goto done;
1147- }
1148-
1149 result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
1150 if ( result != TSS_SUCCESS )
1151 {
1152 print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
1153- goto done;
1154- }
1155+ } else {
1156
1157 result = Tspi_GetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_INFO,
1158 TSS_TSPATTRIB_DELFAMILYINFO_FAMILYID, &familyID);
1159@@ -147,13 +131,6 @@ main_v1_2( char version )
1160 TSS_TSPATTRIB_DELFAMILYINFO_FAMILYID, &returnedID);
1161 if ( result != TSS_SUCCESS )
1162 {
1163- print_error( "Tspi_GetAttribUint32", (result) );
1164- goto done;
1165- }
1166-
1167- result = Testsuite_Transport_Final(hContext, 0);
1168- if ( result != TSS_SUCCESS )
1169- {
1170 if( !(checkNonAPI(result)) )
1171 {
1172 print_error( "Tspi_TPM_GetAttribUint32", result );
1173@@ -162,7 +139,6 @@ main_v1_2( char version )
1174 {
1175 print_error_nonapi( "Tspi_TPM_GetAttribUint32", result );
1176 }
1177- goto done;
1178 }
1179 else
1180 {
1181@@ -170,7 +146,6 @@ main_v1_2( char version )
1182 {
1183 print_error( "Tspi_GetAttribUint32: Family IDs do not match", TSS_E_FAIL );
1184 result = 1;
1185- goto done;
1186 }
1187 else
1188 {
1189@@ -178,13 +153,13 @@ main_v1_2( char version )
1190 }
1191 }
1192
1193- print_end_test( function );
1194 done:
1195 /* Invalidate the family to avoid resource exhaustion */
1196- if (hFamily != NULL_HDELFAMILY)
1197- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1198- Tspi_Context_FreeMemory( hContext, NULL );
1199+ Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1200+ }
1201+ result = Testsuite_Transport_Final(hContext, 0);
1202 Tspi_Context_Close( hContext );
1203
1204+ print_end_test( function );
1205 exit( result );
1206 }
1207diff --git a/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans01.c b/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans01.c
1208index e9ccac7..7406c3d 100644
1209--- a/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans01.c
1210+++ b/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans01.c
1211@@ -87,7 +87,7 @@ main_v1_2( char version )
1212 if ( result != TSS_SUCCESS )
1213 {
1214 print_error( "connect_load_all", (result) );
1215- goto done;
1216+ exit(result);
1217 }
1218
1219 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, FALSE, &hWrappingKey,
1220@@ -98,21 +98,6 @@ main_v1_2( char version )
1221 exit(result);
1222 }
1223
1224- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
1225- if ( result != TSS_SUCCESS )
1226- {
1227- print_error( "Tspi_GetPolicyObject", result );
1228- goto done;
1229- }
1230-
1231- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
1232- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
1233- if ( result != TSS_SUCCESS )
1234- {
1235- print_error( "Tspi_Policy_SetSecret", result );
1236- goto done;
1237- }
1238-
1239 result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
1240 if ( result != TSS_SUCCESS )
1241 {
1242@@ -124,26 +109,20 @@ main_v1_2( char version )
1243 if ( result != TSS_SUCCESS )
1244 {
1245 print_error( "Tspi_TPM_Delegate_InvalidateFamily", (result) );
1246- goto done;
1247 }
1248-
1249+ else
1250+ {
1251+ print_success( function, result );
1252+ }
1253+done:
1254 result = Testsuite_Transport_Final(hContext, hSigningKey);
1255 if ( result != TSS_SUCCESS )
1256 {
1257 print_error( "Testsuite_Transport_Final", (result) );
1258- goto done;
1259- }
1260- else
1261- {
1262- print_success( function, result );
1263 }
1264
1265- print_end_test( function );
1266-done:
1267- /* Invalidate the family to avoid resource exhaustion */
1268- if (hFamily != NULL_HDELFAMILY)
1269- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1270- Tspi_Context_FreeMemory( hContext, NULL );
1271 Tspi_Context_Close( hContext );
1272- exit( 0 );
1273+ print_end_test( function );
1274+
1275+ exit( result );
1276 }
1277diff --git a/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans02.c b/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans02.c
1278index 146c735..af5fd66 100644
1279--- a/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans02.c
1280+++ b/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans02.c
1281@@ -87,7 +87,7 @@ main_v1_2( char version )
1282 if ( result != TSS_SUCCESS )
1283 {
1284 print_error( "connect_load_all", (result) );
1285- goto done;
1286+ exit(result);
1287 }
1288
1289 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
1290@@ -98,21 +98,6 @@ main_v1_2( char version )
1291 exit(result);
1292 }
1293
1294- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
1295- if ( result != TSS_SUCCESS )
1296- {
1297- print_error( "Tspi_GetPolicyObject", result );
1298- goto done;
1299- }
1300-
1301- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
1302- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
1303- if ( result != TSS_SUCCESS )
1304- {
1305- print_error( "Tspi_Policy_SetSecret", result );
1306- goto done;
1307- }
1308-
1309 result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
1310 if ( result != TSS_SUCCESS )
1311 {
1312@@ -124,26 +109,20 @@ main_v1_2( char version )
1313 if ( result != TSS_SUCCESS )
1314 {
1315 print_error( "Tspi_TPM_Delegate_InvalidateFamily", (result) );
1316- goto done;
1317 }
1318-
1319+ else
1320+ {
1321+ print_success( function, result );
1322+ }
1323+done:
1324 result = Testsuite_Transport_Final(hContext, hSigningKey);
1325 if ( result != TSS_SUCCESS )
1326 {
1327 print_error( "Testsuite_Transport_Final", (result) );
1328- goto done;
1329- }
1330- else
1331- {
1332- print_success( function, result );
1333 }
1334
1335- print_end_test( function );
1336-done:
1337- /* Invalidate the family to avoid resource exhaustion */
1338- if (hFamily != NULL_HDELFAMILY)
1339- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1340- Tspi_Context_FreeMemory( hContext, NULL );
1341 Tspi_Context_Close( hContext );
1342- exit( 0 );
1343+ print_end_test( function );
1344+
1345+ exit( result );
1346 }
1347diff --git a/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans03.c b/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans03.c
1348index 510c197..b09a717 100644
1349--- a/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans03.c
1350+++ b/tcg/transport/Tspi_TPM_Delegate_InvalidateFamily-trans03.c
1351@@ -75,7 +75,7 @@ main_v1_2( char version )
1352 {
1353 char * function = "Tspi_TPM_Delegate_InvalidateFamily-trans03";
1354 TSS_HCONTEXT hContext;
1355- TSS_HKEY hSRK, hWrappingKey;
1356+ TSS_HKEY hSRK, hSigningKey, hWrappingKey;
1357 TSS_HTPM hTPM;
1358 TSS_HPOLICY hTPMPolicy;
1359 TSS_HDELFAMILY hFamily = NULL_HDELFAMILY;
1360@@ -87,7 +87,7 @@ main_v1_2( char version )
1361 if ( result != TSS_SUCCESS )
1362 {
1363 print_error( "connect_load_all", (result) );
1364- goto done;
1365+ exit(result);
1366 }
1367
1368 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
1369@@ -98,21 +98,6 @@ main_v1_2( char version )
1370 exit(result);
1371 }
1372
1373- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
1374- if ( result != TSS_SUCCESS )
1375- {
1376- print_error( "Tspi_GetPolicyObject", result );
1377- goto done;
1378- }
1379-
1380- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
1381- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
1382- if ( result != TSS_SUCCESS )
1383- {
1384- print_error( "Tspi_Policy_SetSecret", result );
1385- goto done;
1386- }
1387-
1388 result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
1389 if ( result != TSS_SUCCESS )
1390 {
1391@@ -124,26 +109,20 @@ main_v1_2( char version )
1392 if ( result != TSS_SUCCESS )
1393 {
1394 print_error( "Tspi_TPM_Delegate_InvalidateFamily", (result) );
1395- goto done;
1396- }
1397-
1398- result = Testsuite_Transport_Final(hContext, 0);
1399- if ( result != TSS_SUCCESS )
1400- {
1401- print_error( "Testsuite_Transport_Final", (result) );
1402- goto done;
1403 }
1404 else
1405 {
1406 print_success( function, result );
1407 }
1408-
1409- print_end_test( function );
1410 done:
1411- /* Invalidate the family to avoid resource exhaustion */
1412- if (hFamily != NULL_HDELFAMILY)
1413- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1414- Tspi_Context_FreeMemory( hContext, NULL );
1415+ result = Testsuite_Transport_Final(hContext, NULL);
1416+ if ( result != TSS_SUCCESS )
1417+ {
1418+ print_error( "Testsuite_Transport_Final", (result) );
1419+ }
1420+
1421 Tspi_Context_Close( hContext );
1422- exit( 0 );
1423+ print_end_test( function );
1424+
1425+ exit( result );
1426 }
1427diff --git a/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans01.c b/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans01.c
1428index 594beba..a64445e 100644
1429--- a/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans01.c
1430+++ b/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans01.c
1431@@ -90,7 +90,6 @@ main_v1_2( char version )
1432 if ( result != TSS_SUCCESS )
1433 {
1434 print_error( "connect_load_all", (result) );
1435- Tspi_Context_FreeMemory( hContext, NULL );
1436 Tspi_Context_Close( hContext );
1437 exit( result );
1438 }
1439@@ -103,26 +102,11 @@ main_v1_2( char version )
1440 exit(result);
1441 }
1442
1443- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
1444- if ( result != TSS_SUCCESS )
1445- {
1446- print_error( "Tspi_GetPolicyObject", result );
1447- goto done;
1448- }
1449-
1450- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
1451- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
1452- if ( result != TSS_SUCCESS )
1453- {
1454- print_error( "Tspi_Policy_SetSecret", result );
1455- goto done;
1456- }
1457-
1458 result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
1459 if ( result != TSS_SUCCESS )
1460 {
1461 print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
1462- goto done;
1463+ goto done_trans;
1464 }
1465
1466 result = Tspi_TPM_Delegate_ReadTables(hContext, &familyTableSize, &familyTable,
1467@@ -132,40 +116,32 @@ main_v1_2( char version )
1468 print_error( "Tspi_TPM_Delegate_ReadTables", (result) );
1469 goto done;
1470 }
1471+ else
1472+ {
1473+ print_success( function, result );
1474+ }
1475
1476- result = Testsuite_Transport_Final(hContext, hSigningKey);
1477- if ( result != TSS_SUCCESS )
1478+ result = Tspi_Context_FreeMemory(hContext, (BYTE *)familyTable);
1479+ if (result != TSS_SUCCESS)
1480 {
1481- print_error( function, (result) );
1482- goto done;
1483+ print_error( "Tspi_Context_FreeMemory", result );
1484 }
1485- else
1486+ result = Tspi_Context_FreeMemory(hContext, (BYTE *)delegateTable);
1487+ if (result != TSS_SUCCESS)
1488 {
1489- result = Tspi_Context_FreeMemory(hContext, (BYTE *)familyTable);
1490- if (result != TSS_SUCCESS)
1491- {
1492- print_error( "Tspi_Context_FreeMemory", result );
1493- goto done;
1494- }
1495-
1496- result = Tspi_Context_FreeMemory(hContext, (BYTE *)delegateTable);
1497- if (result != TSS_SUCCESS)
1498- {
1499- print_error( "Tspi_Context_FreeMemory", result );
1500- goto done;
1501- }
1502- else
1503- {
1504- print_success( function, result );
1505- }
1506+ print_error( "Tspi_Context_FreeMemory", result );
1507 }
1508-
1509- print_end_test( function );
1510 done:
1511 /* Invalidate the family to avoid resource exhaustion */
1512- if (hFamily != NULL_HDELFAMILY)
1513- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1514- Tspi_Context_FreeMemory( hContext, NULL );
1515+ Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1516+done_trans:
1517+ result = Testsuite_Transport_Final(hContext, hSigningKey);
1518+ if ( result != TSS_SUCCESS )
1519+ {
1520+ print_error( function, (result) );
1521+ }
1522 Tspi_Context_Close( hContext );
1523- exit( 0 );
1524+ print_end_test( function );
1525+
1526+ exit( result );
1527 }
1528diff --git a/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans02.c b/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans02.c
1529index 25b6010..7a72693 100644
1530--- a/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans02.c
1531+++ b/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans02.c
1532@@ -90,7 +90,6 @@ main_v1_2( char version )
1533 if ( result != TSS_SUCCESS )
1534 {
1535 print_error( "connect_load_all", (result) );
1536- Tspi_Context_FreeMemory( hContext, NULL );
1537 Tspi_Context_Close( hContext );
1538 exit( result );
1539 }
1540@@ -103,26 +102,11 @@ main_v1_2( char version )
1541 exit(result);
1542 }
1543
1544- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
1545- if ( result != TSS_SUCCESS )
1546- {
1547- print_error( "Tspi_GetPolicyObject", result );
1548- goto done;
1549- }
1550-
1551- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
1552- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
1553- if ( result != TSS_SUCCESS )
1554- {
1555- print_error( "Tspi_Policy_SetSecret", result );
1556- goto done;
1557- }
1558-
1559 result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
1560 if ( result != TSS_SUCCESS )
1561 {
1562 print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
1563- goto done;
1564+ goto done_trans;
1565 }
1566
1567 result = Tspi_TPM_Delegate_ReadTables(hContext, &familyTableSize, &familyTable,
1568@@ -132,40 +116,32 @@ main_v1_2( char version )
1569 print_error( "Tspi_TPM_Delegate_ReadTables", (result) );
1570 goto done;
1571 }
1572+ else
1573+ {
1574+ print_success( function, result );
1575+ }
1576
1577- result = Testsuite_Transport_Final(hContext, hSigningKey);
1578- if ( result != TSS_SUCCESS )
1579+ result = Tspi_Context_FreeMemory(hContext, (BYTE *)familyTable);
1580+ if (result != TSS_SUCCESS)
1581 {
1582- print_error( "Testsuite_Transport_Final", (result) );
1583- goto done;
1584+ print_error( "Tspi_Context_FreeMemory", result );
1585 }
1586- else
1587+ result = Tspi_Context_FreeMemory(hContext, (BYTE *)delegateTable);
1588+ if (result != TSS_SUCCESS)
1589 {
1590- result = Tspi_Context_FreeMemory(hContext, (BYTE *)familyTable);
1591- if (result != TSS_SUCCESS)
1592- {
1593- print_error( "Tspi_Context_FreeMemory", result );
1594- goto done;
1595- }
1596-
1597- result = Tspi_Context_FreeMemory(hContext, (BYTE *)delegateTable);
1598- if (result != TSS_SUCCESS)
1599- {
1600- print_error( "Tspi_Context_FreeMemory", result );
1601- goto done;
1602- }
1603- else
1604- {
1605- print_success( function, result );
1606- }
1607+ print_error( "Tspi_Context_FreeMemory", result );
1608 }
1609-
1610- print_end_test( function );
1611 done:
1612 /* Invalidate the family to avoid resource exhaustion */
1613- if (hFamily != NULL_HDELFAMILY)
1614- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1615- Tspi_Context_FreeMemory( hContext, NULL );
1616+ Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1617+done_trans:
1618+ result = Testsuite_Transport_Final(hContext, hSigningKey);
1619+ if ( result != TSS_SUCCESS )
1620+ {
1621+ print_error( function, (result) );
1622+ }
1623 Tspi_Context_Close( hContext );
1624- exit( 0 );
1625+ print_end_test( function );
1626+
1627+ exit( result );
1628 }
1629diff --git a/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans03.c b/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans03.c
1630index 4d3c355..678617b 100644
1631--- a/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans03.c
1632+++ b/tcg/transport/Tspi_TPM_Delegate_ReadTables-trans03.c
1633@@ -75,7 +75,7 @@ main_v1_2( char version )
1634 {
1635 char * function = "Tspi_TPM_Delegate_ReadTables-trans03";
1636 TSS_HCONTEXT hContext;
1637- TSS_HKEY hSRK, hWrappingKey;
1638+ TSS_HKEY hSRK, hSigningKey, hWrappingKey;
1639 TSS_HTPM hTPM;
1640 TSS_HPOLICY hTPMPolicy;
1641 TSS_HDELFAMILY hFamily = NULL_HDELFAMILY;
1642@@ -90,7 +90,6 @@ main_v1_2( char version )
1643 if ( result != TSS_SUCCESS )
1644 {
1645 print_error( "connect_load_all", (result) );
1646- Tspi_Context_FreeMemory( hContext, NULL );
1647 Tspi_Context_Close( hContext );
1648 exit( result );
1649 }
1650@@ -103,26 +102,11 @@ main_v1_2( char version )
1651 exit(result);
1652 }
1653
1654- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
1655- if ( result != TSS_SUCCESS )
1656- {
1657- print_error( "Tspi_GetPolicyObject", result );
1658- goto done;
1659- }
1660-
1661- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
1662- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
1663- if ( result != TSS_SUCCESS )
1664- {
1665- print_error( "Tspi_Policy_SetSecret", result );
1666- goto done;
1667- }
1668-
1669 result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
1670 if ( result != TSS_SUCCESS )
1671 {
1672 print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
1673- goto done;
1674+ goto done_trans;
1675 }
1676
1677 result = Tspi_TPM_Delegate_ReadTables(hContext, &familyTableSize, &familyTable,
1678@@ -132,40 +116,32 @@ main_v1_2( char version )
1679 print_error( "Tspi_TPM_Delegate_ReadTables", (result) );
1680 goto done;
1681 }
1682+ else
1683+ {
1684+ print_success( function, result );
1685+ }
1686
1687- result = Testsuite_Transport_Final(hContext, 0);
1688- if ( result != TSS_SUCCESS )
1689+ result = Tspi_Context_FreeMemory(hContext, (BYTE *)familyTable);
1690+ if (result != TSS_SUCCESS)
1691 {
1692- print_error( "Testsuite_Transport_Final", (result) );
1693- goto done;
1694+ print_error( "Tspi_Context_FreeMemory", result );
1695 }
1696- else
1697+ result = Tspi_Context_FreeMemory(hContext, (BYTE *)delegateTable);
1698+ if (result != TSS_SUCCESS)
1699 {
1700- result = Tspi_Context_FreeMemory(hContext, (BYTE *)familyTable);
1701- if (result != TSS_SUCCESS)
1702- {
1703- print_error( "Tspi_Context_FreeMemory", result );
1704- goto done;
1705- }
1706-
1707- result = Tspi_Context_FreeMemory(hContext, (BYTE *)delegateTable);
1708- if (result != TSS_SUCCESS)
1709- {
1710- print_error( "Tspi_Context_FreeMemory", result );
1711- goto done;
1712- }
1713- else
1714- {
1715- print_success( function, result );
1716- }
1717+ print_error( "Tspi_Context_FreeMemory", result );
1718 }
1719-
1720- print_end_test( function );
1721 done:
1722 /* Invalidate the family to avoid resource exhaustion */
1723- if (hFamily != NULL_HDELFAMILY)
1724- Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1725- Tspi_Context_FreeMemory( hContext, NULL );
1726+ Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1727+done_trans:
1728+ result = Testsuite_Transport_Final(hContext, NULL);
1729+ if ( result != TSS_SUCCESS )
1730+ {
1731+ print_error( function, (result) );
1732+ }
1733 Tspi_Context_Close( hContext );
1734- exit( 0 );
1735+ print_end_test( function );
1736+
1737+ exit( result );
1738 }
1739diff --git a/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans01.c b/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans01.c
1740index 4bb015c..b3e1339 100644
1741--- a/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans01.c
1742+++ b/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans01.c
1743@@ -92,7 +92,7 @@ main_v1_2( char version )
1744 if ( result != TSS_SUCCESS )
1745 {
1746 print_error( "connect_load_all", (result) );
1747- goto done;
1748+ exit(result);
1749 }
1750
1751 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, FALSE, &hWrappingKey,
1752@@ -103,19 +103,11 @@ main_v1_2( char version )
1753 exit(result);
1754 }
1755
1756- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
1757- if ( result != TSS_SUCCESS )
1758- {
1759- print_error( "Tspi_GetPolicyObject", result );
1760- goto done;
1761- }
1762-
1763- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
1764- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
1765+ result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
1766 if ( result != TSS_SUCCESS )
1767 {
1768- print_error( "Tspi_Policy_SetSecret", result );
1769- goto done;
1770+ print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
1771+ goto done_trans;
1772 }
1773
1774 result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation1);
1775@@ -157,13 +149,6 @@ main_v1_2( char version )
1776 goto done;
1777 }
1778
1779- result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
1780- if ( result != TSS_SUCCESS )
1781- {
1782- print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
1783- goto done;
1784- }
1785-
1786 result = Tspi_TPM_Delegate_CreateDelegation(hTPM, 'b', 0, NULL_HPCRS, hFamily, hDelegation1);
1787 if ( result != TSS_SUCCESS )
1788 {
1789@@ -222,27 +207,24 @@ main_v1_2( char version )
1790 if ( result != TSS_SUCCESS )
1791 {
1792 print_error( "Tspi_TPM_Delegate_UpdateVerificationCount", (result) );
1793- goto done;
1794- }
1795-
1796- result = Testsuite_Transport_Final(hContext, hSigningKey);
1797- if ( result != TSS_SUCCESS )
1798- {
1799- print_error( "Testsuite_Transport_Final", (result) );
1800- goto done;
1801 }
1802 else
1803 {
1804 print_success( function, result );
1805 }
1806
1807- print_end_test( function );
1808 done:
1809 /* Invalidate the family to avoid resource exhaustion */
1810 if (hFamily != NULL_HDELFAMILY)
1811 Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1812- Tspi_Context_FreeMemory( hContext, NULL );
1813+done_trans:
1814+ result = Testsuite_Transport_Final(hContext, hSigningKey);
1815+ if ( result != TSS_SUCCESS )
1816+ {
1817+ print_error( "Testsuite_Transport_Final", (result) );
1818+ }
1819 Tspi_Context_Close( hContext );
1820+ print_end_test( function );
1821
1822 exit( result );
1823 }
1824diff --git a/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans02.c b/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans02.c
1825index 5e9db88..119d023 100644
1826--- a/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans02.c
1827+++ b/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans02.c
1828@@ -92,7 +92,7 @@ main_v1_2( char version )
1829 if ( result != TSS_SUCCESS )
1830 {
1831 print_error( "connect_load_all", (result) );
1832- goto done;
1833+ exit(result);
1834 }
1835
1836 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
1837@@ -103,19 +103,11 @@ main_v1_2( char version )
1838 exit(result);
1839 }
1840
1841- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
1842- if ( result != TSS_SUCCESS )
1843- {
1844- print_error( "Tspi_GetPolicyObject", result );
1845- goto done;
1846- }
1847-
1848- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
1849- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
1850+ result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
1851 if ( result != TSS_SUCCESS )
1852 {
1853- print_error( "Tspi_Policy_SetSecret", result );
1854- goto done;
1855+ print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
1856+ goto done_trans;
1857 }
1858
1859 result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation1);
1860@@ -157,13 +149,6 @@ main_v1_2( char version )
1861 goto done;
1862 }
1863
1864- result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
1865- if ( result != TSS_SUCCESS )
1866- {
1867- print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
1868- goto done;
1869- }
1870-
1871 result = Tspi_TPM_Delegate_CreateDelegation(hTPM, 'b', 0, NULL_HPCRS, hFamily, hDelegation1);
1872 if ( result != TSS_SUCCESS )
1873 {
1874@@ -222,27 +207,24 @@ main_v1_2( char version )
1875 if ( result != TSS_SUCCESS )
1876 {
1877 print_error( "Tspi_TPM_Delegate_UpdateVerificationCount", (result) );
1878- goto done;
1879- }
1880-
1881- result = Testsuite_Transport_Final(hContext, hSigningKey);
1882- if ( result != TSS_SUCCESS )
1883- {
1884- print_error( "Testsuite_Transport_Final", (result) );
1885- goto done;
1886 }
1887 else
1888 {
1889 print_success( function, result );
1890 }
1891
1892- print_end_test( function );
1893 done:
1894 /* Invalidate the family to avoid resource exhaustion */
1895 if (hFamily != NULL_HDELFAMILY)
1896 Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1897- Tspi_Context_FreeMemory( hContext, NULL );
1898+done_trans:
1899+ result = Testsuite_Transport_Final(hContext, hSigningKey);
1900+ if ( result != TSS_SUCCESS )
1901+ {
1902+ print_error( "Testsuite_Transport_Final", (result) );
1903+ }
1904 Tspi_Context_Close( hContext );
1905+ print_end_test( function );
1906
1907 exit( result );
1908 }
1909diff --git a/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans03.c b/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans03.c
1910index 140c896..87e9f9f 100644
1911--- a/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans03.c
1912+++ b/tcg/transport/Tspi_TPM_Delegate_UpdateVerificationCount-trans03.c
1913@@ -78,7 +78,7 @@ main_v1_2( char version )
1914 {
1915 char * function = "Tspi_TPM_Delegate_UpdateVerificationCount-trans03";
1916 TSS_HCONTEXT hContext;
1917- TSS_HKEY hSRK, hWrappingKey;
1918+ TSS_HKEY hSRK, hSigningKey, hWrappingKey;
1919 TSS_HTPM hTPM;
1920 TSS_HPOLICY hTPMPolicy;
1921 TSS_HPOLICY hDelegation1 = NULL_HPOLICY;
1922@@ -92,7 +92,7 @@ main_v1_2( char version )
1923 if ( result != TSS_SUCCESS )
1924 {
1925 print_error( "connect_load_all", (result) );
1926- goto done;
1927+ exit(result);
1928 }
1929
1930 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
1931@@ -103,19 +103,11 @@ main_v1_2( char version )
1932 exit(result);
1933 }
1934
1935- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
1936- if ( result != TSS_SUCCESS )
1937- {
1938- print_error( "Tspi_GetPolicyObject", result );
1939- goto done;
1940- }
1941-
1942- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
1943- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
1944+ result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
1945 if ( result != TSS_SUCCESS )
1946 {
1947- print_error( "Tspi_Policy_SetSecret", result );
1948- goto done;
1949+ print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
1950+ goto done_trans;
1951 }
1952
1953 result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation1);
1954@@ -157,13 +149,6 @@ main_v1_2( char version )
1955 goto done;
1956 }
1957
1958- result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
1959- if ( result != TSS_SUCCESS )
1960- {
1961- print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
1962- goto done;
1963- }
1964-
1965 result = Tspi_TPM_Delegate_CreateDelegation(hTPM, 'b', 0, NULL_HPCRS, hFamily, hDelegation1);
1966 if ( result != TSS_SUCCESS )
1967 {
1968@@ -222,27 +207,24 @@ main_v1_2( char version )
1969 if ( result != TSS_SUCCESS )
1970 {
1971 print_error( "Tspi_TPM_Delegate_UpdateVerificationCount", (result) );
1972- goto done;
1973- }
1974-
1975- result = Testsuite_Transport_Final(hContext, 0);
1976- if ( result != TSS_SUCCESS )
1977- {
1978- print_error( "Testsuite_Transport_Final", (result) );
1979- goto done;
1980 }
1981 else
1982 {
1983 print_success( function, result );
1984 }
1985
1986- print_end_test( function );
1987 done:
1988 /* Invalidate the family to avoid resource exhaustion */
1989 if (hFamily != NULL_HDELFAMILY)
1990 Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
1991- Tspi_Context_FreeMemory( hContext, NULL );
1992+done_trans:
1993+ result = Testsuite_Transport_Final(hContext, NULL);
1994+ if ( result != TSS_SUCCESS )
1995+ {
1996+ print_error( "Testsuite_Transport_Final", (result) );
1997+ }
1998 Tspi_Context_Close( hContext );
1999+ print_end_test( function );
2000
2001 exit( result );
2002 }
2003diff --git a/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans01.c b/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans01.c
2004index cd18449..c3789dd 100644
2005--- a/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans01.c
2006+++ b/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans01.c
2007@@ -92,7 +92,7 @@ main_v1_2( char version )
2008 if ( result != TSS_SUCCESS )
2009 {
2010 print_error( "connect_load_all", (result) );
2011- goto done;
2012+ exit(result);
2013 }
2014
2015 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, FALSE, &hWrappingKey,
2016@@ -103,19 +103,11 @@ main_v1_2( char version )
2017 exit(result);
2018 }
2019
2020- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
2021- if ( result != TSS_SUCCESS )
2022- {
2023- print_error( "Tspi_GetPolicyObject", result );
2024- goto done;
2025- }
2026-
2027- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
2028- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
2029+ result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
2030 if ( result != TSS_SUCCESS )
2031 {
2032- print_error( "Tspi_Policy_SetSecret", result );
2033- goto done;
2034+ print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
2035+ goto done_trans;
2036 }
2037
2038 result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation1);
2039@@ -157,13 +149,6 @@ main_v1_2( char version )
2040 goto done;
2041 }
2042
2043- result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
2044- if ( result != TSS_SUCCESS )
2045- {
2046- print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
2047- goto done;
2048- }
2049-
2050 result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
2051 TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
2052 if ( result != TSS_SUCCESS )
2053@@ -238,27 +223,23 @@ main_v1_2( char version )
2054 if ( TSS_ERROR_CODE( result ) != TPM_E_FAMILYCOUNT )
2055 {
2056 print_error( "Tspi_TPM_Delegate_VerifyDelegation", (result) );
2057- goto done;
2058- }
2059-
2060- result = Testsuite_Transport_Final(hContext, hSigningKey);
2061- if ( result == TSS_SUCCESS )
2062- {
2063- print_error( "Testsuite_Transport_Final", (result) );
2064- goto done;
2065 }
2066 else
2067 {
2068 print_success( function, result );
2069 }
2070-
2071- print_end_test( function );
2072 done:
2073 /* Invalidate the family to avoid resource exhaustion */
2074 if (hFamily != NULL_HDELFAMILY)
2075 Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
2076- Tspi_Context_FreeMemory( hContext, NULL );
2077+done_trans:
2078+ result = Testsuite_Transport_Final(hContext, hSigningKey);
2079+ if ( result != TSS_SUCCESS )
2080+ {
2081+ print_error( "Testsuite_Transport_Final", (result) );
2082+ }
2083 Tspi_Context_Close( hContext );
2084+ print_end_test( function );
2085
2086 exit( result );
2087 }
2088diff --git a/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans02.c b/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans02.c
2089index 50aa5d7..ad2cae7 100644
2090--- a/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans02.c
2091+++ b/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans02.c
2092@@ -92,7 +92,7 @@ main_v1_2( char version )
2093 if ( result != TSS_SUCCESS )
2094 {
2095 print_error( "connect_load_all", (result) );
2096- goto done;
2097+ exit(result);
2098 }
2099
2100 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
2101@@ -103,19 +103,11 @@ main_v1_2( char version )
2102 exit(result);
2103 }
2104
2105- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
2106- if ( result != TSS_SUCCESS )
2107- {
2108- print_error( "Tspi_GetPolicyObject", result );
2109- goto done;
2110- }
2111-
2112- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
2113- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
2114+ result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
2115 if ( result != TSS_SUCCESS )
2116 {
2117- print_error( "Tspi_Policy_SetSecret", result );
2118- goto done;
2119+ print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
2120+ goto done_trans;
2121 }
2122
2123 result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation1);
2124@@ -157,13 +149,6 @@ main_v1_2( char version )
2125 goto done;
2126 }
2127
2128- result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
2129- if ( result != TSS_SUCCESS )
2130- {
2131- print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
2132- goto done;
2133- }
2134-
2135 result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
2136 TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
2137 if ( result != TSS_SUCCESS )
2138@@ -183,7 +168,7 @@ main_v1_2( char version )
2139 result = Tspi_TPM_Delegate_VerifyDelegation(hDelegation1);
2140 if ( result != TSS_SUCCESS )
2141 {
2142- print_error( "Tspi_TPM_Delegate_VerifyDelegation", (result) );
2143+ print_error( function, (result) );
2144 goto done;
2145 }
2146
2147@@ -238,27 +223,23 @@ main_v1_2( char version )
2148 if ( TSS_ERROR_CODE( result ) != TPM_E_FAMILYCOUNT )
2149 {
2150 print_error( "Tspi_TPM_Delegate_VerifyDelegation", (result) );
2151- goto done;
2152- }
2153-
2154- result = Testsuite_Transport_Final(hContext, hSigningKey);
2155- if ( result == TSS_SUCCESS )
2156- {
2157- print_error( function, (result) );
2158- goto done;
2159 }
2160 else
2161 {
2162 print_success( function, result );
2163 }
2164-
2165- print_end_test( function );
2166 done:
2167 /* Invalidate the family to avoid resource exhaustion */
2168 if (hFamily != NULL_HDELFAMILY)
2169 Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
2170- Tspi_Context_FreeMemory( hContext, NULL );
2171+done_trans:
2172+ result = Testsuite_Transport_Final(hContext, hSigningKey);
2173+ if ( result != TSS_SUCCESS )
2174+ {
2175+ print_error( "Testsuite_Transport_Final", (result) );
2176+ }
2177 Tspi_Context_Close( hContext );
2178+ print_end_test( function );
2179
2180 exit( result );
2181 }
2182diff --git a/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans03.c b/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans03.c
2183index 33159a2..2cdabef 100644
2184--- a/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans03.c
2185+++ b/tcg/transport/Tspi_TPM_Delegate_VerifyDelegation-trans03.c
2186@@ -78,7 +78,7 @@ main_v1_2( char version )
2187 {
2188 char * function = "Tspi_TPM_Delegate_VerifyDelegation-trans03";
2189 TSS_HCONTEXT hContext;
2190- TSS_HKEY hSRK, hWrappingKey;
2191+ TSS_HKEY hSRK, hSigningKey, hWrappingKey;
2192 TSS_HTPM hTPM;
2193 TSS_HPOLICY hTPMPolicy;
2194 TSS_HPOLICY hDelegation1 = NULL_HPOLICY;
2195@@ -92,7 +92,7 @@ main_v1_2( char version )
2196 if ( result != TSS_SUCCESS )
2197 {
2198 print_error( "connect_load_all", (result) );
2199- goto done;
2200+ exit(result);
2201 }
2202
2203 result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, TRUE, &hWrappingKey,
2204@@ -103,19 +103,11 @@ main_v1_2( char version )
2205 exit(result);
2206 }
2207
2208- result = Tspi_GetPolicyObject( hTPM, TSS_POLICY_USAGE, &hTPMPolicy );
2209- if ( result != TSS_SUCCESS )
2210- {
2211- print_error( "Tspi_GetPolicyObject", result );
2212- goto done;
2213- }
2214-
2215- result = Tspi_Policy_SetSecret( hTPMPolicy, TESTSUITE_OWNER_SECRET_MODE,
2216- TESTSUITE_OWNER_SECRET_LEN, TESTSUITE_OWNER_SECRET );
2217+ result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
2218 if ( result != TSS_SUCCESS )
2219 {
2220- print_error( "Tspi_Policy_SetSecret", result );
2221- goto done;
2222+ print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
2223+ goto done_trans;
2224 }
2225
2226 result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_POLICY, TSS_POLICY_USAGE, &hDelegation1);
2227@@ -157,13 +149,6 @@ main_v1_2( char version )
2228 goto done;
2229 }
2230
2231- result = Tspi_TPM_Delegate_AddFamily(hTPM, 'a', &hFamily);
2232- if ( result != TSS_SUCCESS )
2233- {
2234- print_error( "Tspi_TPM_Delegate_AddFamily", (result) );
2235- goto done;
2236- }
2237-
2238 result = Tspi_SetAttribUint32(hFamily, TSS_TSPATTRIB_DELFAMILY_STATE,
2239 TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED, TRUE);
2240 if ( result != TSS_SUCCESS )
2241@@ -183,7 +168,7 @@ main_v1_2( char version )
2242 result = Tspi_TPM_Delegate_VerifyDelegation(hDelegation1);
2243 if ( result != TSS_SUCCESS )
2244 {
2245- print_error( "Tspi_TPM_Delegate_VerifyDelegation", (result) );
2246+ print_error( function, (result) );
2247 goto done;
2248 }
2249
2250@@ -238,27 +223,23 @@ main_v1_2( char version )
2251 if ( TSS_ERROR_CODE( result ) != TPM_E_FAMILYCOUNT )
2252 {
2253 print_error( "Tspi_TPM_Delegate_VerifyDelegation", (result) );
2254- goto done;
2255- }
2256-
2257- result = Testsuite_Transport_Final(hContext, 0);
2258- if ( result == TSS_SUCCESS )
2259- {
2260- print_error( function, (result) );
2261- goto done;
2262 }
2263 else
2264 {
2265 print_success( function, result );
2266 }
2267-
2268- print_end_test( function );
2269 done:
2270 /* Invalidate the family to avoid resource exhaustion */
2271 if (hFamily != NULL_HDELFAMILY)
2272 Tspi_TPM_Delegate_InvalidateFamily(hTPM, hFamily);
2273- Tspi_Context_FreeMemory( hContext, NULL );
2274+done_trans:
2275+ result = Testsuite_Transport_Final(hContext, NULL);
2276+ if ( result != TSS_SUCCESS )
2277+ {
2278+ print_error( "Testsuite_Transport_Final", (result) );
2279+ }
2280 Tspi_Context_Close( hContext );
2281+ print_end_test( function );
2282
2283 exit( result );
2284 }
diff --git a/meta-tpm/recipes-tpm/tss-testsuite/tss-testsuite_0.3.bb b/meta-tpm/recipes-tpm/tss-testsuite/tss-testsuite_0.3.bb
new file mode 100644
index 0000000..81b8542
--- /dev/null
+++ b/meta-tpm/recipes-tpm/tss-testsuite/tss-testsuite_0.3.bb
@@ -0,0 +1,58 @@
1SUMMARY = "Testcases to exercise the TSS stack/TSS API"
2HOMEPAGE = "${SOURCEFORGE_MIRROR}/projects/trousers/files"
3SECTION = "console/utils"
4DESCRIPTION = "\
5 These are the testcases that exercise the TSS stack. They can be run \
6 either through the the LTP framework or standalone. The testcases \
7 have been tested against the 20040304 version of LTP. \
8 \
9 Please do not execute these testcases on a machine where you are actively \
10 using the TPM. \
11"
12
13LICENSE = "GPLv2"
14LIC_FILES_CHKSUM = "file://LICENSE;md5=751419260aa954499f7abaabaa882bbe"
15
16SRC_URI = "\
17 https://sourceforge.net/projects/trousers/files/TSS%20API%20test%20suite/0.3/testsuite-${PV}.tar.gz; \
18 file://fix-missing-LDFLAGS-in-compile-command-line.patch; \
19 file://fix-failure-of-.so-LD-with-cortexa8t-neon-wrswrap-linux.patch; \
20 file://fix-hardcode-path-in-tsstests.sh.patch \
21 file://testsuite-transport-init.patch \
22 file://Tspi_TPM_LoadMaintenancePubKey01.patch \
23 file://transport-Tspi_TPM_Delegate.patch \
24 file://common_c_no_des.patch \
25 file://Tspi_TPM_CreateIdentity_no_des.patch \
26 file://Tspi_TPM_CreateIdentityWithCallbacks_no_des.patch \
27"
28SRC_URI[md5sum] = "1ebd0e7783178abdfc8c40bc8cb8875f"
29SRC_URI[sha256sum] = "5382539fa69cf480d44f924e54a0f2718134b26baa29137ba351a0eef4873c98"
30
31DEPENDS = "trousers"
32RDEPENDS_${PN} = "tpm-tools openssl bash"
33
34CFLAGS += "-DOPENSSL_NO_DES"
35EXTRA_OEMAKE = " -C tcg 'CC=${CC}' "
36LDFLAGS += "-L${STAGING_LIBDIR} -lcrypto -lpthread"
37
38S = "${WORKDIR}/testsuite-${PV}"
39
40do_configure_prepend () {
41 cp ${S}/tcg/Makefile ${S}
42 cp ${S}/tcg/init/makefile ${S}/tcg/init/Makefile
43 # remove test case about DES
44 rm -rf ${S}/tcg/context/Tspi_Context_GetCapability13.c
45}
46
47testsuite_SUBDIRS = "cmk context data delegation hash highlevel init key nv pcrcomposite policy tpm transport tspi"
48do_install () {
49 install -d ${D}/opt/tss-testsuite/tcg
50 for i in ${testsuite_SUBDIRS}; do \
51 echo "Installing ${i}"; \
52 cp -rf tcg/${i} ${D}/opt/tss-testsuite/tcg/; \
53 done;
54 install -m 0755 tsstests.sh ${D}/opt/tss-testsuite
55}
56
57FILES_${PN} += "/opt/*"
58FILES_${PN}-dbg += "/opt/tss-testsuite/tcg/*/.debug /opt/tss-testsuite/tcg/*/*/.debug"
diff --git a/meta-tpm2/README.md b/meta-tpm2/README.md
new file mode 100644
index 0000000..fbad353
--- /dev/null
+++ b/meta-tpm2/README.md
@@ -0,0 +1,21 @@
1### TPM 2.0
2This feature enables Trusted Platform Module (TPM 2.0) support, including
3kernel option changes to enable tpm drivers, and picking up TPM 2.0 packages.
4
5Trusted Platform Module (TPM 2.0) is a microcontroller that stores keys,
6passwords, and digital certificates. A TPM 2.0 offers the capabilities as
7part of the overall platform security requirements.
8
9### Clear TPM
10For TPM 2.0, the following typical steps can be performed to get the TPM
11ready for use:
12
13- Clear and enable TPM from the BIOS or set the security jumper on the board.
14- Take TPM ownership, setting Owner/Endorsement/Lockout passwords if
15 necessary. These passwords are used for the authorization to certain
16 TPM 2.0 commands.
17```
18 # tpm2_takeownership -o <ownerPasswd> -e <endorsePasswd> -l <lockPasswd>
19```
20Then, you can use the TPM for a specific need, such as key generation,
21sealing encrypted data, etc.
diff --git a/meta-tpm2/conf/layer.conf b/meta-tpm2/conf/layer.conf
new file mode 100644
index 0000000..0b8656e
--- /dev/null
+++ b/meta-tpm2/conf/layer.conf
@@ -0,0 +1,12 @@
1# We have a conf and classes directory, add to BBPATH
2BBPATH .= ":${LAYERDIR}"
3
4# We have recipes-* directories, add to BBFILES
5BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
6 ${LAYERDIR}/recipes-*/*/*.bbappend"
7
8BBFILE_COLLECTIONS += "tpm2"
9BBFILE_PATTERN_tpm2 = "^${LAYERDIR}/"
10BBFILE_PRIORITY_tpm2 = "10"
11
12LAYERDEPENDS_tpm2 = "core"
diff --git a/meta-tpm2/recipes-base/packagegroups/packagegroup-tpm2-initramfs.bb b/meta-tpm2/recipes-base/packagegroups/packagegroup-tpm2-initramfs.bb
new file mode 100644
index 0000000..87c811a
--- /dev/null
+++ b/meta-tpm2/recipes-base/packagegroups/packagegroup-tpm2-initramfs.bb
@@ -0,0 +1 @@
include packagegroup-tpm2.inc
diff --git a/meta-tpm2/recipes-base/packagegroups/packagegroup-tpm2.bb b/meta-tpm2/recipes-base/packagegroups/packagegroup-tpm2.bb
new file mode 100644
index 0000000..b0dc843
--- /dev/null
+++ b/meta-tpm2/recipes-base/packagegroups/packagegroup-tpm2.bb
@@ -0,0 +1,11 @@
1include packagegroup-tpm2.inc
2
3RDEPENDS_${PN} += "\
4 tpm2-abrmd \
5 tpm2.0-tools \
6 rng-tools \
7"
8
9RRECOMMENDS_${PN} += "\
10 kernel-module-tpm-rng \
11"
diff --git a/meta-tpm2/recipes-base/packagegroups/packagegroup-tpm2.inc b/meta-tpm2/recipes-base/packagegroups/packagegroup-tpm2.inc
new file mode 100644
index 0000000..9ffca61
--- /dev/null
+++ b/meta-tpm2/recipes-base/packagegroups/packagegroup-tpm2.inc
@@ -0,0 +1,5 @@
1DESCRIPTION = "Packagegroup for TPM2 TCG TSS userspace and utilities."
2LICENSE = "MIT"
3PR = "r0"
4
5inherit packagegroup
diff --git a/meta-tpm2/recipes-kernel/linux/linux-yocto-rt_4.%.bbappend b/meta-tpm2/recipes-kernel/linux/linux-yocto-rt_4.%.bbappend
new file mode 100644
index 0000000..edaf7f3
--- /dev/null
+++ b/meta-tpm2/recipes-kernel/linux/linux-yocto-rt_4.%.bbappend
@@ -0,0 +1 @@
include linux-yocto-tpm2.inc
diff --git a/meta-tpm2/recipes-kernel/linux/linux-yocto-tpm2.inc b/meta-tpm2/recipes-kernel/linux/linux-yocto-tpm2.inc
new file mode 100644
index 0000000..32456ca
--- /dev/null
+++ b/meta-tpm2/recipes-kernel/linux/linux-yocto-tpm2.inc
@@ -0,0 +1,6 @@
1FILESEXTRAPATHS_prepend := "${THISDIR}/linux-yocto:"
2
3SRC_URI += " \
4 ${@bb.utils.contains('DISTRO_FEATURES', 'tpm2', \
5 'file://tpm2.scc file://tpm2.cfg', '', d)} \
6"
diff --git a/meta-tpm2/recipes-kernel/linux/linux-yocto/tpm2.cfg b/meta-tpm2/recipes-kernel/linux/linux-yocto/tpm2.cfg
new file mode 100644
index 0000000..d175fb5
--- /dev/null
+++ b/meta-tpm2/recipes-kernel/linux/linux-yocto/tpm2.cfg
@@ -0,0 +1,16 @@
1..........................................................................
2. WARNING
3.
4. This file is a kernel configuration fragment, and not a full kernel
5. configuration file. The final kernel configuration is made up of
6. an assembly of processed fragments, each of which is designed to
7. capture a specific part of the final configuration (e.g. platform
8. configuration, feature configuration, and board specific hardware
9. configuration). For more information on kernel configuration, please
10. consult the product documentation.
11.
12..........................................................................
13
14CONFIG_TCG_TPM=y
15CONFIG_TCG_TIS=y
16CONFIG_TCG_CRB=y
diff --git a/meta-tpm2/recipes-kernel/linux/linux-yocto/tpm2.scc b/meta-tpm2/recipes-kernel/linux/linux-yocto/tpm2.scc
new file mode 100644
index 0000000..b369daa
--- /dev/null
+++ b/meta-tpm2/recipes-kernel/linux/linux-yocto/tpm2.scc
@@ -0,0 +1,4 @@
1define KFEATURE_DESCRIPTION "TPM 2.x enablement"
2
3kconf hardware tpm2.cfg
4
diff --git a/meta-tpm2/recipes-kernel/linux/linux-yocto_4.%.bbappend b/meta-tpm2/recipes-kernel/linux/linux-yocto_4.%.bbappend
new file mode 100644
index 0000000..edaf7f3
--- /dev/null
+++ b/meta-tpm2/recipes-kernel/linux/linux-yocto_4.%.bbappend
@@ -0,0 +1 @@
include linux-yocto-tpm2.inc
diff --git a/meta-tpm2/recipes-tpm/tpm2-abrmd/files/Fix-build-failure-when-searching-tabrmd.h.patch b/meta-tpm2/recipes-tpm/tpm2-abrmd/files/Fix-build-failure-when-searching-tabrmd.h.patch
new file mode 100644
index 0000000..24dc022
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2-abrmd/files/Fix-build-failure-when-searching-tabrmd.h.patch
@@ -0,0 +1,293 @@
1From 034e9cd7e539e1feda2fbe9a3646e28156856594 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Thu, 15 Jun 2017 10:21:02 +0800
4Subject: [PATCH] Fix build failure when searching tabrmd.h
5
6Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
7---
8 Makefile.am | 2 +-
9 src/access-broker.c | 2 +-
10 src/include/tabrmd.h | 56 ---------------------------
11 src/include/tcti-tabrmd.h | 2 +-
12 src/include/tss2/tabrmd.h | 56 +++++++++++++++++++++++++++
13 src/resource-manager.c | 2 +-
14 src/tabrmd-error.c | 2 +-
15 src/tabrmd.c | 2 +-
16 src/tcti-tabrmd.c | 2 +-
17 test/integration/hash-sequence.int.c | 2 +-
18 test/integration/password-authorization.int.c | 2 +-
19 test/integration/tcti-cancel.int.c | 2 +-
20 test/integration/tcti-set-locality.int.c | 2 +-
21 13 files changed, 67 insertions(+), 67 deletions(-)
22 delete mode 100644 src/include/tabrmd.h
23 create mode 100644 src/include/tss2/tabrmd.h
24
25diff --git a/Makefile.am b/Makefile.am
26index 5f88429..4733d4f 100644
27--- a/Makefile.am
28+++ b/Makefile.am
29@@ -90,7 +90,7 @@ install-data-hook:
30 $(DESTDIR)$(mandir)/man3/tss2_tcti_tabrmd_init_full.3
31
32 tpm2_abrmddir = $(includedir)/tss2
33-tpm2_abrmd_HEADERS = $(srcdir)/src/include/tabrmd.h
34+tpm2_abrmd_HEADERS = $(srcdir)/src/include/tss2/tabrmd.h
35 libtcti_tabrmddir = $(includedir)/tcti
36 libtcti_tabrmd_HEADERS = $(srcdir)/src/include/tcti-tabrmd.h
37
38diff --git a/src/access-broker.c b/src/access-broker.c
39index d21113d..f357101 100644
40--- a/src/access-broker.c
41+++ b/src/access-broker.c
42@@ -28,7 +28,7 @@
43 #include <inttypes.h>
44 #include <stdbool.h>
45
46-#include "tabrmd.h"
47+#include <tss2/tabrmd.h>
48
49 #include "access-broker.h"
50 #include "tcti.h"
51diff --git a/src/include/tabrmd.h b/src/include/tabrmd.h
52deleted file mode 100644
53index 42d41a2..0000000
54--- a/src/include/tabrmd.h
55+++ /dev/null
56@@ -1,56 +0,0 @@
57-/*
58- * Copyright (c) 2017, Intel Corporation
59- * All rights reserved.
60- *
61- * Redistribution and use in source and binary forms, with or without
62- * modification, are permitted provided that the following conditions are met:
63- *
64- * 1. Redistributions of source code must retain the above copyright notice,
65- * this list of conditions and the following disclaimer.
66- *
67- * 2. Redistributions in binary form must reproduce the above copyright notice,
68- * this list of conditions and the following disclaimer in the documentation
69- * and/or other materials provided with the distribution.
70- *
71- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
72- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
73- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
74- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
75- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
76- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
77- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
78- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
79- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
80- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
81- * THE POSSIBILITY OF SUCH DAMAGE.
82- */
83-#ifndef TSS2_TABD_H
84-#define TSS2_TABD_H
85-
86-#include <gio/gio.h>
87-#include <tpm20.h>
88-
89-#define TABRMD_DBUS_INTERFACE "com.intel.tss2.TctiTabrmd"
90-#define TABRMD_DBUS_NAME_DEFAULT "com.intel.tss2.Tabrmd"
91-#define TABRMD_DBUS_PATH "/com/intel/tss2/Tabrmd/Tcti"
92-#define TABRMD_DBUS_METHOD_CREATE_CONNECTION "CreateConnection"
93-#define TABRMD_DBUS_METHOD_CANCEL "Cancel"
94-#define TABRMD_DBUS_TYPE_DEFAULT G_BUS_TYPE_SYSTEM
95-
96-/* implementation specific RCs */
97-#define TSS2_RESMGR_RC_INTERNAL_ERROR (TSS2_RC)(TSS2_RESMGR_ERROR_LEVEL | (1 << TSS2_LEVEL_IMPLEMENTATION_SPECIFIC_SHIFT))
98-#define TSS2_RESMGR_RC_SAPI_INIT (TSS2_RC)(TSS2_RESMGR_ERROR_LEVEL | (2 << TSS2_LEVEL_IMPLEMENTATION_SPECIFIC_SHIFT))
99-#define TSS2_RESMGR_RC_OUT_OF_MEMORY (TSS2_RC)(TSS2_RESMGR_ERROR_LEVEL | (3 << TSS2_LEVEL_IMPLEMENTATION_SPECIFIC_SHIFT))
100-/* RCs in the RESMGR layer */
101-#define TSS2_RESMGR_RC_BAD_VALUE (TSS2_RC)(TSS2_RESMGR_ERROR_LEVEL | TSS2_BASE_RC_BAD_VALUE)
102-#define TSS2_RESMGR_RC_NOT_PERMITTED (TSS2_RC)(TSS2_RESMGR_ERROR_LEVEL | TSS2_BASE_RC_NOT_PERMITTED)
103-#define TSS2_RESMGR_RC_NOT_IMPLEMENTED (TSS2_RC)(TSS2_RESMGR_ERROR_LEVEL | TSS2_BASE_RC_NOT_IMPLEMENTED)
104-#define TSS2_RESMGR_RC_GENERAL_FAILURE (TSS2_RC)(TSS2_RESMGR_ERROR_LEVEL | TSS2_BASE_RC_GENERAL_FAILURE)
105-#define TSS2_RESMGR_RC_OBJECT_MEMORY (TSS2_RC)(TSS2_RESMGR_ERROR_LEVEL | TPM_RC_OBJECT_MEMORY)
106-
107-#define TABRMD_ERROR tabrmd_error_quark ()
108-GQuark tabrmd_error_quark (void);
109-
110-TSS2_RC tss2_tcti_tabrmd_dump_trans_state (TSS2_TCTI_CONTEXT *tcti_context);
111-
112-#endif /* TSS2_TABD_H */
113diff --git a/src/include/tcti-tabrmd.h b/src/include/tcti-tabrmd.h
114index c145eb5..e8e0c7f 100644
115--- a/src/include/tcti-tabrmd.h
116+++ b/src/include/tcti-tabrmd.h
117@@ -35,7 +35,7 @@ extern "C" {
118 #include <sapi/tpm20.h>
119 #include <sapi/tss2_tcti.h>
120
121-#include "tabrmd.h"
122+#include <tss2/tabrmd.h>
123
124 #define TCTI_TABRMD_DBUS_TYPE_DEFAULT TABRMD_DBUS_TYPE_DEFAULT
125 #define TCTI_TABRMD_DBUS_NAME_DEFAULT TABRMD_DBUS_NAME_DEFAULT
126diff --git a/src/include/tss2/tabrmd.h b/src/include/tss2/tabrmd.h
127new file mode 100644
128index 0000000..42d41a2
129--- /dev/null
130+++ b/src/include/tss2/tabrmd.h
131@@ -0,0 +1,56 @@
132+/*
133+ * Copyright (c) 2017, Intel Corporation
134+ * All rights reserved.
135+ *
136+ * Redistribution and use in source and binary forms, with or without
137+ * modification, are permitted provided that the following conditions are met:
138+ *
139+ * 1. Redistributions of source code must retain the above copyright notice,
140+ * this list of conditions and the following disclaimer.
141+ *
142+ * 2. Redistributions in binary form must reproduce the above copyright notice,
143+ * this list of conditions and the following disclaimer in the documentation
144+ * and/or other materials provided with the distribution.
145+ *
146+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
147+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
148+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
149+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
150+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
151+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
152+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
153+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
154+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
155+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
156+ * THE POSSIBILITY OF SUCH DAMAGE.
157+ */
158+#ifndef TSS2_TABD_H
159+#define TSS2_TABD_H
160+
161+#include <gio/gio.h>
162+#include <tpm20.h>
163+
164+#define TABRMD_DBUS_INTERFACE "com.intel.tss2.TctiTabrmd"
165+#define TABRMD_DBUS_NAME_DEFAULT "com.intel.tss2.Tabrmd"
166+#define TABRMD_DBUS_PATH "/com/intel/tss2/Tabrmd/Tcti"
167+#define TABRMD_DBUS_METHOD_CREATE_CONNECTION "CreateConnection"
168+#define TABRMD_DBUS_METHOD_CANCEL "Cancel"
169+#define TABRMD_DBUS_TYPE_DEFAULT G_BUS_TYPE_SYSTEM
170+
171+/* implementation specific RCs */
172+#define TSS2_RESMGR_RC_INTERNAL_ERROR (TSS2_RC)(TSS2_RESMGR_ERROR_LEVEL | (1 << TSS2_LEVEL_IMPLEMENTATION_SPECIFIC_SHIFT))
173+#define TSS2_RESMGR_RC_SAPI_INIT (TSS2_RC)(TSS2_RESMGR_ERROR_LEVEL | (2 << TSS2_LEVEL_IMPLEMENTATION_SPECIFIC_SHIFT))
174+#define TSS2_RESMGR_RC_OUT_OF_MEMORY (TSS2_RC)(TSS2_RESMGR_ERROR_LEVEL | (3 << TSS2_LEVEL_IMPLEMENTATION_SPECIFIC_SHIFT))
175+/* RCs in the RESMGR layer */
176+#define TSS2_RESMGR_RC_BAD_VALUE (TSS2_RC)(TSS2_RESMGR_ERROR_LEVEL | TSS2_BASE_RC_BAD_VALUE)
177+#define TSS2_RESMGR_RC_NOT_PERMITTED (TSS2_RC)(TSS2_RESMGR_ERROR_LEVEL | TSS2_BASE_RC_NOT_PERMITTED)
178+#define TSS2_RESMGR_RC_NOT_IMPLEMENTED (TSS2_RC)(TSS2_RESMGR_ERROR_LEVEL | TSS2_BASE_RC_NOT_IMPLEMENTED)
179+#define TSS2_RESMGR_RC_GENERAL_FAILURE (TSS2_RC)(TSS2_RESMGR_ERROR_LEVEL | TSS2_BASE_RC_GENERAL_FAILURE)
180+#define TSS2_RESMGR_RC_OBJECT_MEMORY (TSS2_RC)(TSS2_RESMGR_ERROR_LEVEL | TPM_RC_OBJECT_MEMORY)
181+
182+#define TABRMD_ERROR tabrmd_error_quark ()
183+GQuark tabrmd_error_quark (void);
184+
185+TSS2_RC tss2_tcti_tabrmd_dump_trans_state (TSS2_TCTI_CONTEXT *tcti_context);
186+
187+#endif /* TSS2_TABD_H */
188diff --git a/src/resource-manager.c b/src/resource-manager.c
189index 6efdd82..8ad4e46 100644
190--- a/src/resource-manager.c
191+++ b/src/resource-manager.c
192@@ -35,7 +35,7 @@
193 #include "resource-manager.h"
194 #include "sink-interface.h"
195 #include "source-interface.h"
196-#include "tabrmd.h"
197+#include <tss2/tabrmd.h>
198 #include "tpm2-header.h"
199 #include "tpm2-command.h"
200 #include "tpm2-response.h"
201diff --git a/src/tabrmd-error.c b/src/tabrmd-error.c
202index 5ff5a7d..41a561d 100644
203--- a/src/tabrmd-error.c
204+++ b/src/tabrmd-error.c
205@@ -1,6 +1,6 @@
206 #include <gio/gio.h>
207 #include <glib.h>
208-#include "tabrmd.h"
209+#include <tss2/tabrmd.h>
210
211 static const GDBusErrorEntry tabrmd_error_entries[] = {
212 {
213diff --git a/src/tabrmd.c b/src/tabrmd.c
214index 2275aa5..7156cdf 100644
215--- a/src/tabrmd.c
216+++ b/src/tabrmd.c
217@@ -34,7 +34,7 @@
218 #include <unistd.h>
219
220 #include <sapi/tpm20.h>
221-#include "tabrmd.h"
222+#include <tss2/tabrmd.h>
223 #include "access-broker.h"
224 #include "connection.h"
225 #include "connection-manager.h"
226diff --git a/src/tcti-tabrmd.c b/src/tcti-tabrmd.c
227index d6d78ea..52418de 100644
228--- a/src/tcti-tabrmd.c
229+++ b/src/tcti-tabrmd.c
230@@ -35,7 +35,7 @@
231
232 #include <sapi/tpm20.h>
233
234-#include "tabrmd.h"
235+#include <tss2/tabrmd.h>
236 #include "tcti-tabrmd.h"
237 #include "tcti-tabrmd-priv.h"
238 #include "tpm2-header.h"
239diff --git a/test/integration/hash-sequence.int.c b/test/integration/hash-sequence.int.c
240index cf8331d..fd489f9 100644
241--- a/test/integration/hash-sequence.int.c
242+++ b/test/integration/hash-sequence.int.c
243@@ -34,7 +34,7 @@
244
245 #include <sapi/tpm20.h>
246
247-#include "tabrmd.h"
248+#include <tss2/tabrmd.h>
249 #include "tcti-tabrmd.h"
250 #include "common.h"
251
252diff --git a/test/integration/password-authorization.int.c b/test/integration/password-authorization.int.c
253index e6298ef..5416eaa 100644
254--- a/test/integration/password-authorization.int.c
255+++ b/test/integration/password-authorization.int.c
256@@ -32,7 +32,7 @@
257 #include <glib.h>
258 #include <inttypes.h>
259
260-#include "tabrmd.h"
261+#include <tss2/tabrmd.h>
262 #include "tcti-tabrmd.h"
263 #include "common.h"
264
265diff --git a/test/integration/tcti-cancel.int.c b/test/integration/tcti-cancel.int.c
266index 31f0f9a..c2a808b 100644
267--- a/test/integration/tcti-cancel.int.c
268+++ b/test/integration/tcti-cancel.int.c
269@@ -27,7 +27,7 @@
270 #include <glib.h>
271 #include <inttypes.h>
272
273-#include "tabrmd.h"
274+#include <tss2/tabrmd.h>
275 #include "tcti-tabrmd.h"
276 #include "common.h"
277
278diff --git a/test/integration/tcti-set-locality.int.c b/test/integration/tcti-set-locality.int.c
279index 6b7509b..0a54b6a 100644
280--- a/test/integration/tcti-set-locality.int.c
281+++ b/test/integration/tcti-set-locality.int.c
282@@ -27,7 +27,7 @@
283 #include <glib.h>
284 #include <inttypes.h>
285
286-#include "tabrmd.h"
287+#include <tss2/tabrmd.h>
288 #include "tcti-tabrmd.h"
289 #include "common.h"
290
291--
2922.7.5
293
diff --git a/meta-tpm2/recipes-tpm/tpm2-abrmd/files/tpm2-abrmd-init.sh b/meta-tpm2/recipes-tpm/tpm2-abrmd/files/tpm2-abrmd-init.sh
new file mode 100644
index 0000000..c8dfb7d
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2-abrmd/files/tpm2-abrmd-init.sh
@@ -0,0 +1,65 @@
1#!/bin/sh
2
3### BEGIN INIT INFO
4# Provides: tpm2-abrmd
5# Required-Start: $local_fs $remote_fs $network
6# Required-Stop: $local_fs $remote_fs $network
7# Should-Start:
8# Should-Stop:
9# Default-Start: 2 3 4 5
10# Default-Stop: 0 1 6
11# Short-Description: starts tpm2-abrmd
12# Description: tpm2-abrmd implements the TCG resource manager
13### END INIT INFO
14
15PATH=/sbin:/bin:/usr/sbin:/usr/bin
16DAEMON=/usr/sbin/tpm2-abrmd
17NAME=tpm2-abrmd
18DESC="TCG TSS2 Access Broker and Resource Management daemon"
19USER="tss"
20
21test -x "${DAEMON}" || exit 0
22
23# Read configuration variable file if it is present
24[ -r /etc/default/$NAME ] && . /etc/default/$NAME
25
26case "${1}" in
27 start)
28 echo -n "Starting $DESC: "
29
30 if [ ! -e /dev/tpm* ]
31 then
32 echo "device driver not loaded, skipping."
33 exit 0
34 fi
35
36 start-stop-daemon --start --quiet --oknodo --background --pidfile /var/run/${NAME}.pid --user ${USER} --chuid ${USER} --exec ${DAEMON} -- ${DAEMON_OPTS}
37 RETVAL="$?"
38 echo "$NAME."
39 [ "$RETVAL" = 0 ] && pidof $DAEMON > /var/run/${NAME}.pid
40 exit $RETVAL
41 ;;
42
43 stop)
44 echo -n "Stopping $DESC: "
45
46 start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/${NAME}.pid --user ${USER} --exec ${DAEMON}
47 RETVAL="$?"
48 echo "$NAME."
49 rm -f /var/run/${NAME}.pid
50 exit $RETVAL
51 ;;
52
53 restart|force-reload)
54 "${0}" stop
55 sleep 1
56 "${0}" start
57 exit $?
58 ;;
59 *)
60 echo "Usage: ${NAME} {start|stop|restart|force-reload|status}" >&2
61 exit 3
62 ;;
63esac
64
65exit 0
diff --git a/meta-tpm2/recipes-tpm/tpm2-abrmd/files/tpm2-abrmd.default b/meta-tpm2/recipes-tpm/tpm2-abrmd/files/tpm2-abrmd.default
new file mode 100644
index 0000000..987978a
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2-abrmd/files/tpm2-abrmd.default
@@ -0,0 +1 @@
DAEMON_OPTS="--tcti=device --logger=syslog --max-connections=20 --max-transient-objects=20 --fail-on-loaded-trans"
diff --git a/meta-tpm2/recipes-tpm/tpm2-abrmd/tpm2-abrmd_git.bb b/meta-tpm2/recipes-tpm/tpm2-abrmd/tpm2-abrmd_git.bb
new file mode 100644
index 0000000..17dc449
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2-abrmd/tpm2-abrmd_git.bb
@@ -0,0 +1,61 @@
1SUMMARY = ""
2DESCRIPTION = ""
3SECTION = "tpm"
4
5# This is a lie. The source for this project is covered by several licenses.
6# We're currently working on a way to make this clear for those consuming the
7# project. Till then I'm using 'BSD' as a place holder since the Intel license
8# is "BSD-like".
9LICENSE = "BSD"
10LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/BSD;md5=3775480a712fc46a69647678acb234cb"
11
12DEPENDS += "autoconf-archive dbus glib-2.0 pkgconfig tpm2.0-tss glib-2.0-native"
13RDEPENDS_${PN} += "libgcc dbus-glib"
14
15SRC_URI = " \
16 git://github.com/01org/tpm2-abrmd.git;branch=master;name=tpm2-abrmd;destsuffix=tpm2-abrmd \
17 file://tpm2-abrmd-init.sh \
18 file://tpm2-abrmd.default \
19 "
20
21SRCREV = "4f0bd204d07176084b245d005df665fbfdf68db5"
22PV = "1.0.0+git${SRCPV}"
23S = "${WORKDIR}/${BPN}"
24
25inherit autotools pkgconfig systemd update-rc.d useradd
26
27SYSTEMD_PACKAGES += "${PN}"
28SYSTEMD_SERVICE_${PN} = "tpm2-abrmd.service"
29SYSTEMD_AUTO_ENABLE_${PN} = "enable"
30
31INITSCRIPT_NAME = "tpm2-abrmd"
32INITSCRIPT_PARAMS = "start 99 2 3 4 5 . stop 19 0 1 6 ."
33
34USERADD_PACKAGES = "${PN}"
35GROUPADD_PARAM_${PN} = "tss"
36USERADD_PARAM_${PN} = "-M -d /var/lib/tpm -s /bin/false -g tss tss"
37
38# break out tcti into a package: libtcti-tabrmd
39# package up the service file
40
41EXTRA_OECONF += " \
42 --with-systemdsystemunitdir=${systemd_system_unitdir} \
43 --with-udevrulesdir=${sysconfdir}/udev/rules.d \
44 "
45
46do_configure_prepend() {
47 # execute the bootstrap script
48 currentdir=$(pwd)
49 cd "${S}"
50 ACLOCAL="aclocal --system-acdir=${STAGING_DATADIR}/aclocal" ./bootstrap --force
51 cd "${currentdir}"
52}
53
54do_install_append() {
55 install -d "${D}${sysconfdir}/init.d"
56 install -m 0755 "${WORKDIR}/tpm2-abrmd-init.sh" "${D}${sysconfdir}/init.d/tpm2-abrmd"
57 install -d "${D}${sysconfdir}/default"
58 install -m 0644 "${WORKDIR}/tpm2-abrmd.default" "${D}${sysconfdir}/default/tpm2-abrmd"
59}
60
61BBCLASSEXTEND = "native"
diff --git a/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/0001-tpm2-tools-use-dynamic-linkage-with-tpm2-abrmd.patch b/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/0001-tpm2-tools-use-dynamic-linkage-with-tpm2-abrmd.patch
new file mode 100644
index 0000000..8d91ca0
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/0001-tpm2-tools-use-dynamic-linkage-with-tpm2-abrmd.patch
@@ -0,0 +1,80 @@
1From 9aee7b2bc400a336f0a938ce80eba51707662612 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Mon, 19 Jun 2017 13:52:53 +0800
4Subject: [PATCH 1/2] tpm2-tools: use dynamic linkage with tpm2-abrmd
5
6tpm2-abrmd has huge dependencies and they are not necessary to be involved
7in initramfs.
8
9Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
10---
11 Makefile.am | 2 +-
12 lib/context-util.c | 22 ++++++++++++++++++++--
13 2 files changed, 21 insertions(+), 3 deletions(-)
14
15diff --git a/Makefile.am b/Makefile.am
16index a3c43f8..68ba044 100644
17--- a/Makefile.am
18+++ b/Makefile.am
19@@ -38,7 +38,7 @@ LIB_COMMON := lib/libcommon.a
20 AM_CFLAGS := $(INCLUDE_DIRS) $(TPM20_TSS_CFLAGS) $(EXTRA_CFLAGS) $(TCTI_TABRMD_CFLAGS)
21 AM_LDFLAGS := $(EXTRA_LDFLAGS)
22
23-LDADD = $(LIB_COMMON) $(TPM20_TSS_LIBS) $(TCTI_SOCK_LIBS) $(TCTI_DEV_LIBS) $(TCTI_TABRMD_LIBS)
24+LDADD = $(LIB_COMMON) $(TPM20_TSS_LIBS) $(TCTI_SOCK_LIBS) $(TCTI_DEV_LIBS) $(TCTI_TABRMD_LIBS) -ldl
25
26 sbin_PROGRAMS = \
27 tools/tpm2_create \
28diff --git a/lib/context-util.c b/lib/context-util.c
29index 7de22ac..2ef181d 100644
30--- a/lib/context-util.c
31+++ b/lib/context-util.c
32@@ -38,6 +38,7 @@
33 #include <tcti/tcti_socket.h>
34 #endif
35 #ifdef HAVE_TCTI_TABRMD
36+#include <dlfcn.h>
37 #include <tcti/tcti-tabrmd.h>
38 #endif
39
40@@ -134,10 +135,27 @@ TSS2_TCTI_CONTEXT*
41 tcti_tabrmd_init (void)
42 {
43 TSS2_TCTI_CONTEXT *tcti_ctx;
44+ TSS2_RC (*init)(TSS2_TCTI_CONTEXT *, size_t *);
45+ /*
46+ * Intend to "forget" the handle in order to make sure libtcti-tabrmd
47+ * is unloaded along with the deconstructed functions.
48+ */
49+ void *tabrmd_handle;
50 TSS2_RC rc;
51 size_t size;
52
53- rc = tss2_tcti_tabrmd_init(NULL, &size);
54+ tabrmd_handle = dlopen("libtcti-tabrmd.so.0", RTLD_LAZY);
55+ if (!tabrmd_handle) {
56+ fprintf (stderr,
57+ "Unable to find out the tabrmd tcti library\n");
58+ return NULL;
59+ }
60+
61+ init = dlsym(tabrmd_handle, "tss2_tcti_tabrmd_init");
62+ if (!init)
63+ return NULL;
64+
65+ rc = init(NULL, &size);
66 if (rc != TSS2_RC_SUCCESS) {
67 LOG_ERR ("Failed to get size for TABRMD TCTI context: 0x%" PRIx32, rc);
68 return NULL;
69@@ -148,7 +166,7 @@ tcti_tabrmd_init (void)
70 strerror (errno));
71 return NULL;
72 }
73- rc = tss2_tcti_tabrmd_init (tcti_ctx, &size);
74+ rc = init (tcti_ctx, &size);
75 if (rc != TSS2_RC_SUCCESS) {
76 LOG_ERR ("Failed to initialize TABRMD TCTI context: 0x%" PRIx32, rc);
77 free (tcti_ctx);
78--
792.7.5
80
diff --git a/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/0002-Fix-build-failure-with-glib-2.0.patch b/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/0002-Fix-build-failure-with-glib-2.0.patch
new file mode 100644
index 0000000..faeaf2a
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/0002-Fix-build-failure-with-glib-2.0.patch
@@ -0,0 +1,39 @@
1From 53f9b2f63c5370f4d269bf08d940cc8576fcbbf4 Mon Sep 17 00:00:00 2001
2From: Lans Zhang <jia.zhang@windriver.com>
3Date: Mon, 19 Jun 2017 13:54:34 +0800
4Subject: [PATCH 2/2] Fix build failure with glib-2.0
5
6Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
7---
8 Makefile.am | 2 +-
9 configure.ac | 1 +
10 2 files changed, 2 insertions(+), 1 deletion(-)
11
12diff --git a/Makefile.am b/Makefile.am
13index 68ba044..e792049 100644
14--- a/Makefile.am
15+++ b/Makefile.am
16@@ -35,7 +35,7 @@ ACLOCAL_AMFLAGS = -I m4
17 INCLUDE_DIRS = -I$(srcdir)/src -I$(srcdir)/lib
18 LIB_COMMON := lib/libcommon.a
19
20-AM_CFLAGS := $(INCLUDE_DIRS) $(TPM20_TSS_CFLAGS) $(EXTRA_CFLAGS) $(TCTI_TABRMD_CFLAGS)
21+AM_CFLAGS := $(INCLUDE_DIRS) $(GLIB_CFLAGS) $(TPM20_TSS_CFLAGS) $(EXTRA_CFLAGS) $(TCTI_TABRMD_CFLAGS)
22 AM_LDFLAGS := $(EXTRA_LDFLAGS)
23
24 LDADD = $(LIB_COMMON) $(TPM20_TSS_LIBS) $(TCTI_SOCK_LIBS) $(TCTI_DEV_LIBS) $(TCTI_TABRMD_LIBS) -ldl
25diff --git a/configure.ac b/configure.ac
26index ce781ea..08fa81c 100644
27--- a/configure.ac
28+++ b/configure.ac
29@@ -6,6 +6,7 @@ LT_INIT
30 AM_INIT_AUTOMAKE([foreign
31 subdir-objects])
32 AC_CONFIG_FILES([Makefile])
33+PKG_CHECK_MODULES([GLIB], [glib-2.0])
34 PKG_CHECK_MODULES([SAPI],[sapi])
35 # disable libtcti-device selectively (enabled by default)
36 AC_ARG_WITH(
37--
382.7.5
39
diff --git a/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/ax_check_compile_flag.m4 b/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/ax_check_compile_flag.m4
new file mode 100644
index 0000000..dcabb92
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/ax_check_compile_flag.m4
@@ -0,0 +1,74 @@
1# ===========================================================================
2# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
8#
9# DESCRIPTION
10#
11# Check whether the given FLAG works with the current language's compiler
12# or gives an error. (Warnings, however, are ignored)
13#
14# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
15# success/failure.
16#
17# If EXTRA-FLAGS is defined, it is added to the current language's default
18# flags (e.g. CFLAGS) when the check is done. The check is thus made with
19# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
20# force the compiler to issue an error when a bad flag is given.
21#
22# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
23#
24# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
25# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
26#
27# LICENSE
28#
29# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
30# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
31#
32# This program is free software: you can redistribute it and/or modify it
33# under the terms of the GNU General Public License as published by the
34# Free Software Foundation, either version 3 of the License, or (at your
35# option) any later version.
36#
37# This program is distributed in the hope that it will be useful, but
38# WITHOUT ANY WARRANTY; without even the implied warranty of
39# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
40# Public License for more details.
41#
42# You should have received a copy of the GNU General Public License along
43# with this program. If not, see <https://www.gnu.org/licenses/>.
44#
45# As a special exception, the respective Autoconf Macro's copyright owner
46# gives unlimited permission to copy, distribute and modify the configure
47# scripts that are the output of Autoconf when processing the Macro. You
48# need not follow the terms of the GNU General Public License when using
49# or distributing such scripts, even though portions of the text of the
50# Macro appear in them. The GNU General Public License (GPL) does govern
51# all other use of the material that constitutes the Autoconf Macro.
52#
53# This special exception to the GPL applies to versions of the Autoconf
54# Macro released by the Autoconf Archive. When you make and distribute a
55# modified version of the Autoconf Macro, you may extend this special
56# exception to the GPL to apply to your modified version as well.
57
58#serial 5
59
60AC_DEFUN([AX_CHECK_COMPILE_FLAG],
61[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
62AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
63AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
64 ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
65 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
66 AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
67 [AS_VAR_SET(CACHEVAR,[yes])],
68 [AS_VAR_SET(CACHEVAR,[no])])
69 _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
70AS_VAR_IF(CACHEVAR,yes,
71 [m4_default([$2], :)],
72 [m4_default([$3], :)])
73AS_VAR_POPDEF([CACHEVAR])dnl
74])dnl AX_CHECK_COMPILE_FLAGS
diff --git a/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/ax_check_link_flag.m4 b/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/ax_check_link_flag.m4
new file mode 100644
index 0000000..819409a
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/ax_check_link_flag.m4
@@ -0,0 +1,74 @@
1# ===========================================================================
2# https://www.gnu.org/software/autoconf-archive/ax_check_link_flag.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7# AX_CHECK_LINK_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
8#
9# DESCRIPTION
10#
11# Check whether the given FLAG works with the linker or gives an error.
12# (Warnings, however, are ignored)
13#
14# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
15# success/failure.
16#
17# If EXTRA-FLAGS is defined, it is added to the linker's default flags
18# when the check is done. The check is thus made with the flags: "LDFLAGS
19# EXTRA-FLAGS FLAG". This can for example be used to force the linker to
20# issue an error when a bad flag is given.
21#
22# INPUT gives an alternative input source to AC_LINK_IFELSE.
23#
24# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
25# macro in sync with AX_CHECK_{PREPROC,COMPILE}_FLAG.
26#
27# LICENSE
28#
29# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
30# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
31#
32# This program is free software: you can redistribute it and/or modify it
33# under the terms of the GNU General Public License as published by the
34# Free Software Foundation, either version 3 of the License, or (at your
35# option) any later version.
36#
37# This program is distributed in the hope that it will be useful, but
38# WITHOUT ANY WARRANTY; without even the implied warranty of
39# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
40# Public License for more details.
41#
42# You should have received a copy of the GNU General Public License along
43# with this program. If not, see <https://www.gnu.org/licenses/>.
44#
45# As a special exception, the respective Autoconf Macro's copyright owner
46# gives unlimited permission to copy, distribute and modify the configure
47# scripts that are the output of Autoconf when processing the Macro. You
48# need not follow the terms of the GNU General Public License when using
49# or distributing such scripts, even though portions of the text of the
50# Macro appear in them. The GNU General Public License (GPL) does govern
51# all other use of the material that constitutes the Autoconf Macro.
52#
53# This special exception to the GPL applies to versions of the Autoconf
54# Macro released by the Autoconf Archive. When you make and distribute a
55# modified version of the Autoconf Macro, you may extend this special
56# exception to the GPL to apply to your modified version as well.
57
58#serial 5
59
60AC_DEFUN([AX_CHECK_LINK_FLAG],
61[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
62AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_ldflags_$4_$1])dnl
63AC_CACHE_CHECK([whether the linker accepts $1], CACHEVAR, [
64 ax_check_save_flags=$LDFLAGS
65 LDFLAGS="$LDFLAGS $4 $1"
66 AC_LINK_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
67 [AS_VAR_SET(CACHEVAR,[yes])],
68 [AS_VAR_SET(CACHEVAR,[no])])
69 LDFLAGS=$ax_check_save_flags])
70AS_VAR_IF(CACHEVAR,yes,
71 [m4_default([$2], :)],
72 [m4_default([$3], :)])
73AS_VAR_POPDEF([CACHEVAR])dnl
74])dnl AX_CHECK_LINK_FLAGS
diff --git a/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/ax_check_preproc_flag.m4 b/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/ax_check_preproc_flag.m4
new file mode 100644
index 0000000..4850ff3
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools/ax_check_preproc_flag.m4
@@ -0,0 +1,74 @@
1# ===========================================================================
2# https://www.gnu.org/software/autoconf-archive/ax_check_preproc_flag.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7# AX_CHECK_PREPROC_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
8#
9# DESCRIPTION
10#
11# Check whether the given FLAG works with the current language's
12# preprocessor or gives an error. (Warnings, however, are ignored)
13#
14# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
15# success/failure.
16#
17# If EXTRA-FLAGS is defined, it is added to the preprocessor's default
18# flags when the check is done. The check is thus made with the flags:
19# "CPPFLAGS EXTRA-FLAGS FLAG". This can for example be used to force the
20# preprocessor to issue an error when a bad flag is given.
21#
22# INPUT gives an alternative input source to AC_PREPROC_IFELSE.
23#
24# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
25# macro in sync with AX_CHECK_{COMPILE,LINK}_FLAG.
26#
27# LICENSE
28#
29# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
30# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
31#
32# This program is free software: you can redistribute it and/or modify it
33# under the terms of the GNU General Public License as published by the
34# Free Software Foundation, either version 3 of the License, or (at your
35# option) any later version.
36#
37# This program is distributed in the hope that it will be useful, but
38# WITHOUT ANY WARRANTY; without even the implied warranty of
39# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
40# Public License for more details.
41#
42# You should have received a copy of the GNU General Public License along
43# with this program. If not, see <https://www.gnu.org/licenses/>.
44#
45# As a special exception, the respective Autoconf Macro's copyright owner
46# gives unlimited permission to copy, distribute and modify the configure
47# scripts that are the output of Autoconf when processing the Macro. You
48# need not follow the terms of the GNU General Public License when using
49# or distributing such scripts, even though portions of the text of the
50# Macro appear in them. The GNU General Public License (GPL) does govern
51# all other use of the material that constitutes the Autoconf Macro.
52#
53# This special exception to the GPL applies to versions of the Autoconf
54# Macro released by the Autoconf Archive. When you make and distribute a
55# modified version of the Autoconf Macro, you may extend this special
56# exception to the GPL to apply to your modified version as well.
57
58#serial 5
59
60AC_DEFUN([AX_CHECK_PREPROC_FLAG],
61[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
62AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]cppflags_$4_$1])dnl
63AC_CACHE_CHECK([whether _AC_LANG preprocessor accepts $1], CACHEVAR, [
64 ax_check_save_flags=$CPPFLAGS
65 CPPFLAGS="$CPPFLAGS $4 $1"
66 AC_PREPROC_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
67 [AS_VAR_SET(CACHEVAR,[yes])],
68 [AS_VAR_SET(CACHEVAR,[no])])
69 CPPFLAGS=$ax_check_save_flags])
70AS_VAR_IF(CACHEVAR,yes,
71 [m4_default([$2], :)],
72 [m4_default([$3], :)])
73AS_VAR_POPDEF([CACHEVAR])dnl
74])dnl AX_CHECK_PREPROC_FLAGS
diff --git a/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools_git.bb b/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools_git.bb
new file mode 100644
index 0000000..a914c3b
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2.0-tools/tpm2.0-tools_git.bb
@@ -0,0 +1,48 @@
1SUMMARY = "Tools for TPM2."
2DESCRIPTION = "tpm2.0-tools"
3SECTION = "tpm"
4
5LICENSE = "BSD"
6LIC_FILES_CHKSUM = "file://${S}/LICENSE;md5=91b7c548d73ea16537799e8060cea819"
7
8DEPENDS += "tpm2.0-tss tpm2-abrmd openssl curl autoconf-archive pkgconfig"
9RDEPENDS_${PN} += "libtss2 libtctidevice"
10
11SRC_URI = " \
12 git://github.com/01org/tpm2.0-tools.git;branch=master;name=tpm2.0-tools;destsuffix=tpm2.0-tools \
13 file://ax_check_compile_flag.m4 \
14 file://ax_check_preproc_flag.m4 \
15 file://ax_check_link_flag.m4 \
16 file://0001-tpm2-tools-use-dynamic-linkage-with-tpm2-abrmd.patch \
17 file://0002-Fix-build-failure-with-glib-2.0.patch \
18"
19
20S = "${WORKDIR}/${BPN}"
21SRCREV = "ada4c20d23d99b4b489c6c793e4132c1d5234b66"
22PV = "2.0.0+git${SRCPV}"
23
24inherit autotools pkgconfig
25
26EXTRA_OECONF += " \
27 --with-tcti-device \
28 --without-tcti-socket \
29 --with-tcti-tabrmd \
30"
31
32EXTRA_OEMAKE += " \
33 CFLAGS="${CFLAGS} -Wno-implicit-fallthrough" \
34"
35
36do_configure_prepend() {
37 mkdir -p "${S}/m4"
38 cp "${WORKDIR}/ax_check_compile_flag.m4" "${S}/m4"
39 cp "${WORKDIR}/ax_check_preproc_flag.m4" "${S}/m4"
40 cp "${WORKDIR}/ax_check_link_flag.m4" "${S}/m4"
41
42 # execute the bootstrap script
43 currentdir=$(pwd)
44 cd "${S}"
45 ACLOCAL="aclocal --system-acdir=${STAGING_DATADIR}/aclocal" \
46 ./bootstrap --force
47 cd "${currentdir}"
48}
diff --git a/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/0001-update-bootstrap.patch b/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/0001-update-bootstrap.patch
new file mode 100644
index 0000000..3f5fa81
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/0001-update-bootstrap.patch
@@ -0,0 +1,24 @@
1Index: TPM2.0-TSS/bootstrap
2===================================================================
3--- TPM2.0-TSS.orig/bootstrap
4+++ TPM2.0-TSS/bootstrap
5@@ -13,6 +13,7 @@ src_listvar () {
6 }
7
8 VARS_FILE=src_vars.mk
9+AUTORECONF=${AUTORECONF:-autoreconf}
10
11 echo "Generating file lists: ${VARS_FILE}"
12 (
13@@ -30,11 +31,3 @@ echo "Generating file lists: ${VARS_FILE
14 printf "SAMPLE_SRC = \$(SAMPLE_C) \$(SAMPLE_H)\n"
15 ) > ${VARS_FILE}
16
17-printf "Running libtoolize ...\n"
18-libtoolize --install
19-printf "Running aclocal ...\n"
20-aclocal
21-printf "Running autoconf ...\n"
22-autoconf
23-printf "Running automake ...\n"
24-automake --add-missing
diff --git a/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/ax_check_compile_flag.m4 b/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/ax_check_compile_flag.m4
new file mode 100644
index 0000000..dcabb92
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/ax_check_compile_flag.m4
@@ -0,0 +1,74 @@
1# ===========================================================================
2# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
8#
9# DESCRIPTION
10#
11# Check whether the given FLAG works with the current language's compiler
12# or gives an error. (Warnings, however, are ignored)
13#
14# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
15# success/failure.
16#
17# If EXTRA-FLAGS is defined, it is added to the current language's default
18# flags (e.g. CFLAGS) when the check is done. The check is thus made with
19# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
20# force the compiler to issue an error when a bad flag is given.
21#
22# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
23#
24# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
25# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
26#
27# LICENSE
28#
29# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
30# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
31#
32# This program is free software: you can redistribute it and/or modify it
33# under the terms of the GNU General Public License as published by the
34# Free Software Foundation, either version 3 of the License, or (at your
35# option) any later version.
36#
37# This program is distributed in the hope that it will be useful, but
38# WITHOUT ANY WARRANTY; without even the implied warranty of
39# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
40# Public License for more details.
41#
42# You should have received a copy of the GNU General Public License along
43# with this program. If not, see <https://www.gnu.org/licenses/>.
44#
45# As a special exception, the respective Autoconf Macro's copyright owner
46# gives unlimited permission to copy, distribute and modify the configure
47# scripts that are the output of Autoconf when processing the Macro. You
48# need not follow the terms of the GNU General Public License when using
49# or distributing such scripts, even though portions of the text of the
50# Macro appear in them. The GNU General Public License (GPL) does govern
51# all other use of the material that constitutes the Autoconf Macro.
52#
53# This special exception to the GPL applies to versions of the Autoconf
54# Macro released by the Autoconf Archive. When you make and distribute a
55# modified version of the Autoconf Macro, you may extend this special
56# exception to the GPL to apply to your modified version as well.
57
58#serial 5
59
60AC_DEFUN([AX_CHECK_COMPILE_FLAG],
61[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
62AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
63AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
64 ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
65 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
66 AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
67 [AS_VAR_SET(CACHEVAR,[yes])],
68 [AS_VAR_SET(CACHEVAR,[no])])
69 _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
70AS_VAR_IF(CACHEVAR,yes,
71 [m4_default([$2], :)],
72 [m4_default([$3], :)])
73AS_VAR_POPDEF([CACHEVAR])dnl
74])dnl AX_CHECK_COMPILE_FLAGS
diff --git a/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/ax_check_link_flag.m4 b/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/ax_check_link_flag.m4
new file mode 100644
index 0000000..819409a
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/ax_check_link_flag.m4
@@ -0,0 +1,74 @@
1# ===========================================================================
2# https://www.gnu.org/software/autoconf-archive/ax_check_link_flag.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7# AX_CHECK_LINK_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
8#
9# DESCRIPTION
10#
11# Check whether the given FLAG works with the linker or gives an error.
12# (Warnings, however, are ignored)
13#
14# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
15# success/failure.
16#
17# If EXTRA-FLAGS is defined, it is added to the linker's default flags
18# when the check is done. The check is thus made with the flags: "LDFLAGS
19# EXTRA-FLAGS FLAG". This can for example be used to force the linker to
20# issue an error when a bad flag is given.
21#
22# INPUT gives an alternative input source to AC_LINK_IFELSE.
23#
24# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
25# macro in sync with AX_CHECK_{PREPROC,COMPILE}_FLAG.
26#
27# LICENSE
28#
29# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
30# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
31#
32# This program is free software: you can redistribute it and/or modify it
33# under the terms of the GNU General Public License as published by the
34# Free Software Foundation, either version 3 of the License, or (at your
35# option) any later version.
36#
37# This program is distributed in the hope that it will be useful, but
38# WITHOUT ANY WARRANTY; without even the implied warranty of
39# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
40# Public License for more details.
41#
42# You should have received a copy of the GNU General Public License along
43# with this program. If not, see <https://www.gnu.org/licenses/>.
44#
45# As a special exception, the respective Autoconf Macro's copyright owner
46# gives unlimited permission to copy, distribute and modify the configure
47# scripts that are the output of Autoconf when processing the Macro. You
48# need not follow the terms of the GNU General Public License when using
49# or distributing such scripts, even though portions of the text of the
50# Macro appear in them. The GNU General Public License (GPL) does govern
51# all other use of the material that constitutes the Autoconf Macro.
52#
53# This special exception to the GPL applies to versions of the Autoconf
54# Macro released by the Autoconf Archive. When you make and distribute a
55# modified version of the Autoconf Macro, you may extend this special
56# exception to the GPL to apply to your modified version as well.
57
58#serial 5
59
60AC_DEFUN([AX_CHECK_LINK_FLAG],
61[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
62AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_ldflags_$4_$1])dnl
63AC_CACHE_CHECK([whether the linker accepts $1], CACHEVAR, [
64 ax_check_save_flags=$LDFLAGS
65 LDFLAGS="$LDFLAGS $4 $1"
66 AC_LINK_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
67 [AS_VAR_SET(CACHEVAR,[yes])],
68 [AS_VAR_SET(CACHEVAR,[no])])
69 LDFLAGS=$ax_check_save_flags])
70AS_VAR_IF(CACHEVAR,yes,
71 [m4_default([$2], :)],
72 [m4_default([$3], :)])
73AS_VAR_POPDEF([CACHEVAR])dnl
74])dnl AX_CHECK_LINK_FLAGS
diff --git a/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/ax_check_preproc_flag.m4 b/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/ax_check_preproc_flag.m4
new file mode 100644
index 0000000..4850ff3
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/ax_check_preproc_flag.m4
@@ -0,0 +1,74 @@
1# ===========================================================================
2# https://www.gnu.org/software/autoconf-archive/ax_check_preproc_flag.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7# AX_CHECK_PREPROC_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
8#
9# DESCRIPTION
10#
11# Check whether the given FLAG works with the current language's
12# preprocessor or gives an error. (Warnings, however, are ignored)
13#
14# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
15# success/failure.
16#
17# If EXTRA-FLAGS is defined, it is added to the preprocessor's default
18# flags when the check is done. The check is thus made with the flags:
19# "CPPFLAGS EXTRA-FLAGS FLAG". This can for example be used to force the
20# preprocessor to issue an error when a bad flag is given.
21#
22# INPUT gives an alternative input source to AC_PREPROC_IFELSE.
23#
24# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
25# macro in sync with AX_CHECK_{COMPILE,LINK}_FLAG.
26#
27# LICENSE
28#
29# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
30# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
31#
32# This program is free software: you can redistribute it and/or modify it
33# under the terms of the GNU General Public License as published by the
34# Free Software Foundation, either version 3 of the License, or (at your
35# option) any later version.
36#
37# This program is distributed in the hope that it will be useful, but
38# WITHOUT ANY WARRANTY; without even the implied warranty of
39# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
40# Public License for more details.
41#
42# You should have received a copy of the GNU General Public License along
43# with this program. If not, see <https://www.gnu.org/licenses/>.
44#
45# As a special exception, the respective Autoconf Macro's copyright owner
46# gives unlimited permission to copy, distribute and modify the configure
47# scripts that are the output of Autoconf when processing the Macro. You
48# need not follow the terms of the GNU General Public License when using
49# or distributing such scripts, even though portions of the text of the
50# Macro appear in them. The GNU General Public License (GPL) does govern
51# all other use of the material that constitutes the Autoconf Macro.
52#
53# This special exception to the GPL applies to versions of the Autoconf
54# Macro released by the Autoconf Archive. When you make and distribute a
55# modified version of the Autoconf Macro, you may extend this special
56# exception to the GPL to apply to your modified version as well.
57
58#serial 5
59
60AC_DEFUN([AX_CHECK_PREPROC_FLAG],
61[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
62AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]cppflags_$4_$1])dnl
63AC_CACHE_CHECK([whether _AC_LANG preprocessor accepts $1], CACHEVAR, [
64 ax_check_save_flags=$CPPFLAGS
65 CPPFLAGS="$CPPFLAGS $4 $1"
66 AC_PREPROC_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
67 [AS_VAR_SET(CACHEVAR,[yes])],
68 [AS_VAR_SET(CACHEVAR,[no])])
69 CPPFLAGS=$ax_check_save_flags])
70AS_VAR_IF(CACHEVAR,yes,
71 [m4_default([$2], :)],
72 [m4_default([$3], :)])
73AS_VAR_POPDEF([CACHEVAR])dnl
74])dnl AX_CHECK_PREPROC_FLAGS
diff --git a/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/ax_pthread.m4 b/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/ax_pthread.m4
new file mode 100644
index 0000000..d383ad5
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/ax_pthread.m4
@@ -0,0 +1,332 @@
1# ===========================================================================
2# http://www.gnu.org/software/autoconf-archive/ax_pthread.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
8#
9# DESCRIPTION
10#
11# This macro figures out how to build C programs using POSIX threads. It
12# sets the PTHREAD_LIBS output variable to the threads library and linker
13# flags, and the PTHREAD_CFLAGS output variable to any special C compiler
14# flags that are needed. (The user can also force certain compiler
15# flags/libs to be tested by setting these environment variables.)
16#
17# Also sets PTHREAD_CC to any special C compiler that is needed for
18# multi-threaded programs (defaults to the value of CC otherwise). (This
19# is necessary on AIX to use the special cc_r compiler alias.)
20#
21# NOTE: You are assumed to not only compile your program with these flags,
22# but also link it with them as well. e.g. you should link with
23# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
24#
25# If you are only building threads programs, you may wish to use these
26# variables in your default LIBS, CFLAGS, and CC:
27#
28# LIBS="$PTHREAD_LIBS $LIBS"
29# CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
30# CC="$PTHREAD_CC"
31#
32# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant
33# has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name
34# (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
35#
36# Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the
37# PTHREAD_PRIO_INHERIT symbol is defined when compiling with
38# PTHREAD_CFLAGS.
39#
40# ACTION-IF-FOUND is a list of shell commands to run if a threads library
41# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it
42# is not found. If ACTION-IF-FOUND is not specified, the default action
43# will define HAVE_PTHREAD.
44#
45# Please let the authors know if this macro fails on any platform, or if
46# you have any other suggestions or comments. This macro was based on work
47# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help
48# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by
49# Alejandro Forero Cuervo to the autoconf macro repository. We are also
50# grateful for the helpful feedback of numerous users.
51#
52# Updated for Autoconf 2.68 by Daniel Richard G.
53#
54# LICENSE
55#
56# Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
57# Copyright (c) 2011 Daniel Richard G. <skunk@iSKUNK.ORG>
58#
59# This program is free software: you can redistribute it and/or modify it
60# under the terms of the GNU General Public License as published by the
61# Free Software Foundation, either version 3 of the License, or (at your
62# option) any later version.
63#
64# This program is distributed in the hope that it will be useful, but
65# WITHOUT ANY WARRANTY; without even the implied warranty of
66# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
67# Public License for more details.
68#
69# You should have received a copy of the GNU General Public License along
70# with this program. If not, see <http://www.gnu.org/licenses/>.
71#
72# As a special exception, the respective Autoconf Macro's copyright owner
73# gives unlimited permission to copy, distribute and modify the configure
74# scripts that are the output of Autoconf when processing the Macro. You
75# need not follow the terms of the GNU General Public License when using
76# or distributing such scripts, even though portions of the text of the
77# Macro appear in them. The GNU General Public License (GPL) does govern
78# all other use of the material that constitutes the Autoconf Macro.
79#
80# This special exception to the GPL applies to versions of the Autoconf
81# Macro released by the Autoconf Archive. When you make and distribute a
82# modified version of the Autoconf Macro, you may extend this special
83# exception to the GPL to apply to your modified version as well.
84
85#serial 21
86
87AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
88AC_DEFUN([AX_PTHREAD], [
89AC_REQUIRE([AC_CANONICAL_HOST])
90AC_LANG_PUSH([C])
91ax_pthread_ok=no
92
93# We used to check for pthread.h first, but this fails if pthread.h
94# requires special compiler flags (e.g. on True64 or Sequent).
95# It gets checked for in the link test anyway.
96
97# First of all, check if the user has set any of the PTHREAD_LIBS,
98# etcetera environment variables, and if threads linking works using
99# them:
100if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
101 save_CFLAGS="$CFLAGS"
102 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
103 save_LIBS="$LIBS"
104 LIBS="$PTHREAD_LIBS $LIBS"
105 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
106 AC_TRY_LINK_FUNC([pthread_join], [ax_pthread_ok=yes])
107 AC_MSG_RESULT([$ax_pthread_ok])
108 if test x"$ax_pthread_ok" = xno; then
109 PTHREAD_LIBS=""
110 PTHREAD_CFLAGS=""
111 fi
112 LIBS="$save_LIBS"
113 CFLAGS="$save_CFLAGS"
114fi
115
116# We must check for the threads library under a number of different
117# names; the ordering is very important because some systems
118# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
119# libraries is broken (non-POSIX).
120
121# Create a list of thread flags to try. Items starting with a "-" are
122# C compiler flags, and other items are library names, except for "none"
123# which indicates that we try without any flags at all, and "pthread-config"
124# which is a program returning the flags for the Pth emulation library.
125
126ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
127
128# The ordering *is* (sometimes) important. Some notes on the
129# individual items follow:
130
131# pthreads: AIX (must check this before -lpthread)
132# none: in case threads are in libc; should be tried before -Kthread and
133# other compiler flags to prevent continual compiler warnings
134# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
135# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
136# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
137# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
138# -pthreads: Solaris/gcc
139# -mthreads: Mingw32/gcc, Lynx/gcc
140# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
141# doesn't hurt to check since this sometimes defines pthreads too;
142# also defines -D_REENTRANT)
143# ... -mt is also the pthreads flag for HP/aCC
144# pthread: Linux, etcetera
145# --thread-safe: KAI C++
146# pthread-config: use pthread-config program (for GNU Pth library)
147
148case ${host_os} in
149 solaris*)
150
151 # On Solaris (at least, for some versions), libc contains stubbed
152 # (non-functional) versions of the pthreads routines, so link-based
153 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
154 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
155 # a function called by this macro, so we could check for that, but
156 # who knows whether they'll stub that too in a future libc.) So,
157 # we'll just look for -pthreads and -lpthread first:
158
159 ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags"
160 ;;
161
162 darwin*)
163 ax_pthread_flags="-pthread $ax_pthread_flags"
164 ;;
165esac
166
167# Clang doesn't consider unrecognized options an error unless we specify
168# -Werror. We throw in some extra Clang-specific options to ensure that
169# this doesn't happen for GCC, which also accepts -Werror.
170
171AC_MSG_CHECKING([if compiler needs -Werror to reject unknown flags])
172save_CFLAGS="$CFLAGS"
173ax_pthread_extra_flags="-Werror"
174CFLAGS="$CFLAGS $ax_pthread_extra_flags -Wunknown-warning-option -Wsizeof-array-argument"
175AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int foo(void);],[foo()])],
176 [AC_MSG_RESULT([yes])],
177 [ax_pthread_extra_flags=
178 AC_MSG_RESULT([no])])
179CFLAGS="$save_CFLAGS"
180
181if test x"$ax_pthread_ok" = xno; then
182for flag in $ax_pthread_flags; do
183
184 case $flag in
185 none)
186 AC_MSG_CHECKING([whether pthreads work without any flags])
187 ;;
188
189 -*)
190 AC_MSG_CHECKING([whether pthreads work with $flag])
191 PTHREAD_CFLAGS="$flag"
192 ;;
193
194 pthread-config)
195 AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no])
196 if test x"$ax_pthread_config" = xno; then continue; fi
197 PTHREAD_CFLAGS="`pthread-config --cflags`"
198 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
199 ;;
200
201 *)
202 AC_MSG_CHECKING([for the pthreads library -l$flag])
203 PTHREAD_LIBS="-l$flag"
204 ;;
205 esac
206
207 save_LIBS="$LIBS"
208 save_CFLAGS="$CFLAGS"
209 LIBS="$PTHREAD_LIBS $LIBS"
210 CFLAGS="$CFLAGS $PTHREAD_CFLAGS $ax_pthread_extra_flags"
211
212 # Check for various functions. We must include pthread.h,
213 # since some functions may be macros. (On the Sequent, we
214 # need a special flag -Kthread to make this header compile.)
215 # We check for pthread_join because it is in -lpthread on IRIX
216 # while pthread_create is in libc. We check for pthread_attr_init
217 # due to DEC craziness with -lpthreads. We check for
218 # pthread_cleanup_push because it is one of the few pthread
219 # functions on Solaris that doesn't have a non-functional libc stub.
220 # We try pthread_create on general principles.
221 AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>
222 static void routine(void *a) { a = 0; }
223 static void *start_routine(void *a) { return a; }],
224 [pthread_t th; pthread_attr_t attr;
225 pthread_create(&th, 0, start_routine, 0);
226 pthread_join(th, 0);
227 pthread_attr_init(&attr);
228 pthread_cleanup_push(routine, 0);
229 pthread_cleanup_pop(0) /* ; */])],
230 [ax_pthread_ok=yes],
231 [])
232
233 LIBS="$save_LIBS"
234 CFLAGS="$save_CFLAGS"
235
236 AC_MSG_RESULT([$ax_pthread_ok])
237 if test "x$ax_pthread_ok" = xyes; then
238 break;
239 fi
240
241 PTHREAD_LIBS=""
242 PTHREAD_CFLAGS=""
243done
244fi
245
246# Various other checks:
247if test "x$ax_pthread_ok" = xyes; then
248 save_LIBS="$LIBS"
249 LIBS="$PTHREAD_LIBS $LIBS"
250 save_CFLAGS="$CFLAGS"
251 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
252
253 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
254 AC_MSG_CHECKING([for joinable pthread attribute])
255 attr_name=unknown
256 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
257 AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
258 [int attr = $attr; return attr /* ; */])],
259 [attr_name=$attr; break],
260 [])
261 done
262 AC_MSG_RESULT([$attr_name])
263 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
264 AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE], [$attr_name],
265 [Define to necessary symbol if this constant
266 uses a non-standard name on your system.])
267 fi
268
269 AC_MSG_CHECKING([if more special flags are required for pthreads])
270 flag=no
271 case ${host_os} in
272 aix* | freebsd* | darwin*) flag="-D_THREAD_SAFE";;
273 osf* | hpux*) flag="-D_REENTRANT";;
274 solaris*)
275 if test "$GCC" = "yes"; then
276 flag="-D_REENTRANT"
277 else
278 # TODO: What about Clang on Solaris?
279 flag="-mt -D_REENTRANT"
280 fi
281 ;;
282 esac
283 AC_MSG_RESULT([$flag])
284 if test "x$flag" != xno; then
285 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
286 fi
287
288 AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT],
289 [ax_cv_PTHREAD_PRIO_INHERIT], [
290 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]],
291 [[int i = PTHREAD_PRIO_INHERIT;]])],
292 [ax_cv_PTHREAD_PRIO_INHERIT=yes],
293 [ax_cv_PTHREAD_PRIO_INHERIT=no])
294 ])
295 AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes"],
296 [AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], [1], [Have PTHREAD_PRIO_INHERIT.])])
297
298 LIBS="$save_LIBS"
299 CFLAGS="$save_CFLAGS"
300
301 # More AIX lossage: compile with *_r variant
302 if test "x$GCC" != xyes; then
303 case $host_os in
304 aix*)
305 AS_CASE(["x/$CC"],
306 [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6],
307 [#handle absolute path differently from PATH based program lookup
308 AS_CASE(["x$CC"],
309 [x/*],
310 [AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])],
311 [AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])])
312 ;;
313 esac
314 fi
315fi
316
317test -n "$PTHREAD_CC" || PTHREAD_CC="$CC"
318
319AC_SUBST([PTHREAD_LIBS])
320AC_SUBST([PTHREAD_CFLAGS])
321AC_SUBST([PTHREAD_CC])
322
323# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
324if test x"$ax_pthread_ok" = xyes; then
325 ifelse([$1],,[AC_DEFINE([HAVE_PTHREAD],[1],[Define if you have POSIX threads libraries and header files.])],[$1])
326 :
327else
328 ax_pthread_ok=no
329 $2
330fi
331AC_LANG_POP
332])dnl AX_PTHREAD
diff --git a/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/no-cmocka-configure-ac.diff b/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/no-cmocka-configure-ac.diff
new file mode 100644
index 0000000..9e5f2f5
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss/no-cmocka-configure-ac.diff
@@ -0,0 +1,10 @@
1Index: TPM2.0-TSS/configure.ac
2===================================================================
3--- TPM2.0-TSS.orig/configure.ac
4+++ TPM2.0-TSS/configure.ac
5@@ -11,5 +11,4 @@ AX_PTHREAD([], [AC_MSG_ERROR([requires p
6 AM_INIT_AUTOMAKE([foreign
7 subdir-objects])
8 AC_CONFIG_FILES([Makefile])
9-PKG_CHECK_MODULES([CMOCKA],[cmocka])
10 AC_OUTPUT
diff --git a/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss_git.bb b/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss_git.bb
new file mode 100644
index 0000000..cda3b30
--- /dev/null
+++ b/meta-tpm2/recipes-tpm/tpm2.0-tss/tpm2.0-tss_git.bb
@@ -0,0 +1,109 @@
1SUMMARY = "Software stack for TPM2."
2DESCRIPTION = "tpm2.0-tss like woah."
3SECTION = "tpm"
4
5# This is a lie. The source for this project is covered by several licenses.
6# We're currently working on a way to make this clear for those consuming the
7# project. Till then I'm using 'BSD' as a place holder since the Intel license
8# is "BSD-like".
9LICENSE = "BSD"
10LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/BSD;md5=3775480a712fc46a69647678acb234cb"
11
12# This doesn't seem to work. Keeping it here for completeness. Remove once
13# it's fixed upstream.
14DEPENDS += "autoconf-archive pkgconfig"
15#RDEPENDS_libtss2 += "libmarshal"
16#RDEPENDS_libtctidevice += "libmarshal"
17
18SRC_URI = " \
19 git://github.com/01org/TPM2.0-TSS.git;protocol=http;branch=1.x;name=TPM2.0-TSS;destsuffix=TPM2.0-TSS \
20"
21
22# CAPS? SRSLY?
23S = "${WORKDIR}/${@d.getVar('BPN',d).upper()}"
24
25SRCREV = "1fa2f4d12449d5d639032fee28d922fe9d4877b5"
26PV = "1.1.0+git${SRCPV}"
27
28RRECOMMENDS_${PN} += "\
29 kernel-module-tpm-crb \
30 kernel-module-tpm-tis \
31"
32
33TPM_DESCRIPTION = 'device/description'
34FAMILY_MAJOR = 'TPM 2.0'
35
36PACKAGES = " \
37 ${PN}-dbg \
38 libtss2 \
39 libtss2-dev \
40 libtss2-staticdev \
41 libtss2-doc \
42 libtctidevice \
43 libtctidevice-dev \
44 libtctidevice-staticdev \
45 libtctisocket \
46 libtctisocket-dev \
47 libtctisocket-staticdev \
48 libmarshal \
49 libmarshal-dev \
50 libmarshal-staticdev \
51"
52
53FILES_libtss2 = "${libdir}/libsapi.so.*"
54FILES_libtss2-dev = " \
55 ${includedir}/sapi \
56 ${includedir}/tcti/common.h \
57 ${libdir}/libsapi.so \
58 ${libdir}/pkgconfig/sapi.pc \
59 ${libdir}/libsapi.la \
60"
61FILES_libtss2-staticdev = " \
62 ${libdir}/libsapi.a \
63"
64FILES_libtss2-doc = " \
65 ${mandir} \
66"
67FILES_libtctidevice = "${libdir}/libtcti-device.so.*"
68FILES_libtctidevice-dev = " \
69 ${includedir}/tcti/tcti_device.h \
70 ${libdir}/libtcti-device.so \
71 ${libdir}/pkgconfig/tcti-device.pc \
72 ${libdir}/libtcti-device.la \
73"
74FILES_libtctidevice-staticdev = "${libdir}/libtcti-device.a"
75FILES_libtctisocket = "${libdir}/libtcti-socket.so.*"
76FILES_libtctisocket-dev = " \
77 ${includedir}/tcti/tcti_socket.h \
78 ${libdir}/libtcti-socket.so \
79 ${libdir}/pkgconfig/tcti-socket.pc \
80 ${libdir}/libtcti-socket.la \
81"
82FILES_libtctisocket-staticdev = "${libdir}/libtcti-socket.a"
83FILES_libmarshal = "${libdir}/libmarshal.so.*"
84FILES_libmarshal-dev = "${libdir}/libmarshal.la ${libdir}/libmarshal.so"
85FILES_libmarshal-staticdev = "${libdir}/libmarshal.a"
86
87inherit autotools
88
89# the autotools / autoconf-archive don't work as expected so we include the
90# pthread macro ourselves for now
91SRC_URI += " \
92 file://ax_pthread.m4 \
93 file://ax_check_compile_flag.m4 \
94 file://ax_check_preproc_flag.m4 \
95 file://ax_check_link_flag.m4 \
96"
97do_configure_prepend () {
98 mkdir -p ${S}/m4
99 cp ${WORKDIR}/ax_pthread.m4 ${S}/m4
100 cp ${WORKDIR}/ax_check_compile_flag.m4 ${S}/m4
101 cp ${WORKDIR}/ax_check_preproc_flag.m4 ${S}/m4
102 cp ${WORKDIR}/ax_check_link_flag.m4 ${S}/m4
103 # execute the bootstrap script
104 currentdir=$(pwd)
105 cd ${S}
106 ACLOCAL="aclocal --system-acdir=${STAGING_DATADIR}/aclocal" ./bootstrap --force
107 cd ${currentdir}
108}
109
diff --git a/meta/conf/layer.conf b/meta/conf/layer.conf
new file mode 100644
index 0000000..1e20761
--- /dev/null
+++ b/meta/conf/layer.conf
@@ -0,0 +1,14 @@
1# We have a conf and classes directory, add to BBPATH
2BBPATH .= ":${LAYERDIR}"
3
4# We have recipes-* directories, add to BBFILES
5BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
6 ${LAYERDIR}/recipes-*/*/*.bbappend"
7
8BBFILE_COLLECTIONS += "secure-core"
9BBFILE_PATTERN_secure-core = "^${LAYERDIR}/"
10BBFILE_PRIORITY_secure-core = "10"
11
12LAYERDEPENDS_secure-core = "\
13 core \
14"
diff --git a/meta/recipes-core/images/secure-core-image.bb b/meta/recipes-core/images/secure-core-image.bb
new file mode 100644
index 0000000..9fe73c5
--- /dev/null
+++ b/meta/recipes-core/images/secure-core-image.bb
@@ -0,0 +1,23 @@
1SUMMARY = "The root image of SecureCore."
2
3SECURE_CORE_IMAGE_EXTRA_INSTALL_append += "\
4 ${@bb.utils.contains("DISTRO_FEATURES", "efi-secure-boot", \
5 "packagegroup-efi-secure-boot", "", d)} \
6 ${@bb.utils.contains("DISTRO_FEATURES", "tpm", \
7 "packagegroup-tpm", "", d)} \
8 ${@bb.utils.contains("DISTRO_FEATURES", "tpm2", \
9 "packagegroup-tpm2", "", d)} \
10 ${@bb.utils.contains("DISTRO_FEATURES", "encrypted-storage", \
11 "packagegroup-encrypted-storage", "", d)} \
12"
13
14IMAGE_INSTALL = "packagegroup-core-boot ${SECURE_CORE_IMAGE_EXTRA_INSTALL}"
15
16IMAGE_LINGUAS = " "
17
18LICENSE = "MIT"
19
20inherit core-image
21
22IMAGE_ROOTFS_SIZE ?= "8192"
23IMAGE_ROOTFS_EXTRA_SPACE_append = "${@bb.utils.contains("DISTRO_FEATURES", "systemd", " + 4096", "" ,d)}"