From 2f809d0330c2dccb9143ba0be6bbb84b66a202ab Mon Sep 17 00:00:00 2001 From: Deepika Rajani <35041528+deepikarajani24@users.noreply.github.com> Date: Wed, 2 Dec 2020 14:09:22 -0500 Subject: [PATCH] Deepikarajani24 patch 1 (#193) * tbs.dll to not initialize on start up so that it's not initialized when tpm support is not required Changed author to my google.com user * initialize tbs.dll and proc Tbsi_GetDeviceInfo during probeSystemTPMs initialization is done in probeSystemTPMs as it's called before openTPM which requires support of the dll changed author to my google.com user * tbs.dll to load once Changed the author to my google.com email * Tbsi_GetDeviceInfo check to happen once changed the author of the commit --- attest/pcp_windows.go | 4 ++-- attest/tpm_windows.go | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/attest/pcp_windows.go b/attest/pcp_windows.go index 99bcb6b..bb85ab1 100644 --- a/attest/pcp_windows.go +++ b/attest/pcp_windows.go @@ -58,8 +58,8 @@ var ( crypt32CertEnumCertificatesInStore = crypt32.MustFindProc("CertEnumCertificatesInStore") crypt32CertCloseStore = crypt32.MustFindProc("CertCloseStore") - tbs = windows.MustLoadDLL("Tbs.dll") - tbsGetDeviceInfo = tbs.MustFindProc("Tbsi_GetDeviceInfo") + tbs *windows.DLL + tbsGetDeviceInfo *windows.Proc ) // Error codes. diff --git a/attest/tpm_windows.go b/attest/tpm_windows.go index 31cbab2..d6f28c6 100644 --- a/attest/tpm_windows.go +++ b/attest/tpm_windows.go @@ -42,6 +42,12 @@ type windowsTPM struct { func (*windowsTPM) isTPMBase() {} func probeSystemTPMs() ([]probedTPM, error) { + // Initialize Tbs.dll here so that it's linked only when TPM support is required. + if tbs == nil { + tbs = windows.MustLoadDLL("Tbs.dll") + tbsGetDeviceInfo = tbs.MustFindProc("Tbsi_GetDeviceInfo") + } + // Windows systems appear to only support a single abstracted TPM. // If we fail to initialize the Platform Crypto Provider, we assume // a TPM is not present.