From bfeff6c867b2cc29df681eb153306694aed82454 Mon Sep 17 00:00:00 2001 From: Cyrus <24922493+cyrus-dev@users.noreply.github.com> Date: Mon, 30 Nov 2020 08:38:46 -0500 Subject: [PATCH] initial commit --- HIRS_ProvisionerTPM2/include/Utils.h | 2 +- HIRS_ProvisionerTPM2/package/rpm-post-install.sh | 12 +++++------- HIRS_ProvisionerTPM2/src/ProvisionerTpm2.proto | 4 ++-- HIRS_ProvisionerTPM2/src/TPM2_Provisioner.cpp | 14 +++++++++----- HIRS_ProvisionerTPM2/src/Utils.cpp | 8 ++++---- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/HIRS_ProvisionerTPM2/include/Utils.h b/HIRS_ProvisionerTPM2/include/Utils.h index acad7f60..39099750 100644 --- a/HIRS_ProvisionerTPM2/include/Utils.h +++ b/HIRS_ProvisionerTPM2/include/Utils.h @@ -33,7 +33,7 @@ namespace file_utils { std::string getFileAsOneLineOrEmptyString(const std::string& filename); - std::vector searchDirectory(const std::string& directory); + std::vector search_directory(const std::string& directory); void writeBinaryFile(const std::string& bytes, const std::string& filename); diff --git a/HIRS_ProvisionerTPM2/package/rpm-post-install.sh b/HIRS_ProvisionerTPM2/package/rpm-post-install.sh index 9622dc3d..ce08f17d 100644 --- a/HIRS_ProvisionerTPM2/package/rpm-post-install.sh +++ b/HIRS_ProvisionerTPM2/package/rpm-post-install.sh @@ -42,22 +42,20 @@ ln -s -f /etc/hirs/provisioner/hirs-provisioner.sh /usr/sbin/hirs-provisioner TCG_BOOT_FILE="/etc/hirs/tcg_boot.properties" TCG_DIRECTORY="/boot/tcg" -LOG_FILE_LOCATION="$TCG_DIRECTORY/manifest/rim/" -TAG_FILE_LOCATION="$TCG_DIRECTORY/manifest/swidtag/" +RIM_FILE_LOCATION="$TCG_DIRECTORY/manifest/rim/" +SWIDTAG_FILE_LOCATION="$TCG_DIRECTORY/manifest/swidtag/" CREDENTIALS_LOCATION="$TCG_DIRECTORY/cert/platform/" if [ ! -f "$TCG_BOOT_FILE" ]; then touch "$TCG_BOOT_FILE" fi -if [ -d "$LOG_FILE_LOCATION" ]; then - RIM_FILE=$(find "$LOG_FILE_LOCATION" -name '*.rimel' -or -name '*.bin' -or -name '*.rimpcr' -or -name '*.log') - echo "tcg.rim.file=$RIM_FILE" > "$TCG_BOOT_FILE" +if [ -d "$RIM_FILE_LOCATION" ]; then + echo "tcg.rim.dir=$RIM_FILE_LOCATION" > "$TCG_BOOT_FILE" fi if [ -d "$TAG_FILE_LOCATION" ]; then - SWID_FILE=$(find "$TAG_FILE_LOCATION" -name '*.swidtag') - echo "tcg.swidtag.file=$SWID_FILE" >> "$TCG_BOOT_FILE" + echo "tcg.swidtag.dir=$SWIDTAG_FILE_LOCATION" >> "$TCG_BOOT_FILE" fi if [ -d "$CREDENTIALS_LOCATION" ]; then diff --git a/HIRS_ProvisionerTPM2/src/ProvisionerTpm2.proto b/HIRS_ProvisionerTPM2/src/ProvisionerTpm2.proto index af38dbac..e8cd5766 100644 --- a/HIRS_ProvisionerTPM2/src/ProvisionerTpm2.proto +++ b/HIRS_ProvisionerTPM2/src/ProvisionerTpm2.proto @@ -58,8 +58,8 @@ message DeviceInfo { required NetworkInfo nw = 3; required OsInfo os = 4; optional bytes pcrslist = 5; - optional bytes logfile = 6; - optional bytes swidfile = 7; + repeated bytes logfile = 6; + repeated bytes swidfile = 7; optional bytes livelog = 8; } diff --git a/HIRS_ProvisionerTPM2/src/TPM2_Provisioner.cpp b/HIRS_ProvisionerTPM2/src/TPM2_Provisioner.cpp index 957759e7..cd86e0a1 100644 --- a/HIRS_ProvisionerTPM2/src/TPM2_Provisioner.cpp +++ b/HIRS_ProvisionerTPM2/src/TPM2_Provisioner.cpp @@ -70,7 +70,7 @@ int provision() { const std::string& cert_dir = props.get("tcg.cert.dir", ""); try { platformCredentials = - hirs::file_utils::searchDirectory(cert_dir); + hirs::file_utils::search_directory(cert_dir); } catch (HirsRuntimeException& hirsRuntimeException) { logger.error(hirsRuntimeException.what()); } @@ -83,15 +83,19 @@ int provision() { hirs::pb::DeviceInfo dv = DeviceInfoCollector::collectDeviceInfo(); dv.set_pcrslist(tpm2.getPcrList()); // collect TCG Boot files - const std::string& rim_file = props.get("tcg.rim.file", ""); - const std::string& swid_file = props.get("tcg.swidtag.file", ""); + std::vector rim_files; + std::vector swidtag_files; + const std::string& rim_dir = props.get("tcg.rim.dir", ""); + const std::string& swid_dir = props.get("tcg.swidtag.dir", ""); try { - dv.set_logfile(hirs::file_utils::fileToString(rim_file)); + rim_files = hirs::file_utils::search_directory(rim_dir); + dv.set_logfile(rim_files); } catch (HirsRuntimeException& hirsRuntimeException) { logger.error(hirsRuntimeException.what()); } try { - dv.set_swidfile(hirs::file_utils::fileToString(swid_file)); + swidtag_files = hirs::file_utils::search_directory(swid_dir); + dv.set_swidfile(swidtag_files); } catch (HirsRuntimeException& hirsRuntimeException) { logger.error(hirsRuntimeException.what()); } diff --git a/HIRS_ProvisionerTPM2/src/Utils.cpp b/HIRS_ProvisionerTPM2/src/Utils.cpp index 75aeccf8..d8f10b56 100644 --- a/HIRS_ProvisionerTPM2/src/Utils.cpp +++ b/HIRS_ProvisionerTPM2/src/Utils.cpp @@ -119,9 +119,9 @@ namespace file_utils { return string_utils::trimNewLines(fileToString(filename, "")); } - vector searchDirectory(const string& directory) { + vector search_directory(const string& directory) { DIR *dr; - std::vector platform_credentials; + std::vector files; dr = opendir(directory.c_str()); if (dr) { @@ -131,7 +131,7 @@ namespace file_utils { ss << directory.c_str(); ss << en->d_name; try { - platform_credentials.push_back(fileToString(ss.str())); + files.push_back(fileToString(ss.str())); } catch (HirsRuntimeException& hirsRuntimeException) { std::cout << hirsRuntimeException.what(); } @@ -140,7 +140,7 @@ namespace file_utils { closedir(dr); } - return platform_credentials; + return files; } /**