From a2062e3cc866194f559baedbc42833bf1a137076 Mon Sep 17 00:00:00 2001 From: iadgovuser29 <33426478+iadgovuser29@users.noreply.github.com> Date: Tue, 12 Jan 2021 10:31:12 -0500 Subject: [PATCH] [#93] Identifiers collected using the SMBIOS Component Class Registry --- build.gradle | 4 +- scripts/allcomponents.sh | 475 ++++++++++------------------- scripts/componentlist.sh | 403 +++++++++++++++++++++++++ scripts/json.sh | 252 ++++++++++++++++ scripts/pc_certgen.sh | 4 +- scripts/smbios.sh | 246 ++++++++++++++- scripts/windows/SMBios.ps1 | 293 +++++++++++++++++- scripts/windows/allcomponents.ps1 | 481 +++++++++--------------------- scripts/windows/componentlist.ps1 | 360 ++++++++++++++++++++++ scripts/windows/json.ps1 | 267 +++++++++++++++++ scripts/windows/pc_certgen.ps1 | 2 +- 11 files changed, 2121 insertions(+), 666 deletions(-) create mode 100644 scripts/componentlist.sh create mode 100644 scripts/json.sh create mode 100644 scripts/windows/componentlist.ps1 create mode 100644 scripts/windows/json.ps1 diff --git a/build.gradle b/build.gradle index 4b9c714..973905b 100644 --- a/build.gradle +++ b/build.gradle @@ -116,8 +116,8 @@ ospackage { packageName='paccor' os=LINUX arch=NOARCH - version='1.1.4' - release='3' + version='1.1.5' + release='1' into '/opt/paccor' user 'root' diff --git a/scripts/allcomponents.sh b/scripts/allcomponents.sh index fbc6958..0c8c9f8 100755 --- a/scripts/allcomponents.sh +++ b/scripts/allcomponents.sh @@ -1,296 +1,130 @@ #!/bin/bash +### allcomponents.sh +### gathers identifiers for all components using every available component class registry +### One component may end up having multiple componentIdentifiers in the resulting JSON output + ### User customizable values APP_HOME="`dirname "$0"`" COMPONENTS_URI="" # Specify the optional components URI field COMPONENTS_URI_LOCAL_COPY_FOR_HASH="" # If empty, the optional hashAlgorithm and hashValue fields will not be included for the URI PROPERTIES_URI="" # Specify the optional properties URI field PROPERTIES_URI_LOCAL_COPY_FOR_HASH="" # If empty, the optional hashAlgorithm and hashValue fields will not be included for the URI -ENTERPRISE_NUMBERS_FILE="$APP_HOME""/enterprise-numbers" -PEN_ROOT="1.3.6.1.4.1." # OID root for the private enterprise numbers -SMBIOS_SCRIPT="$APP_HOME""/smbios.sh" -HW_SCRIPT="$APP_HOME""/hw.sh" # For components not covered by SMBIOS -NVME_SCRIPT="$APP_HOME""/nvme.sh" # For nvme components, until lshw supports them - -### SMBIOS Type Constants -source $SMBIOS_SCRIPT -SMBIOS_TYPE_PLATFORM="1" -SMBIOS_TYPE_CHASSIS="3" -SMBIOS_TYPE_BIOS="0" -SMBIOS_TYPE_BASEBOARD="2" -SMBIOS_TYPE_CPU="4" -SMBIOS_TYPE_RAM="17" +JSON_SCRIPT="$APP_HOME""/json.sh" # Defines JSON structure and provides methods for producing relevant JSON +SMBIOS_SCRIPT="$APP_HOME""/smbios.sh" # Handles parsing of SMBIOS data +HW_SCRIPT="$APP_HOME""/hw.sh" # Handles parsing of lshw +NVME_SCRIPT="$APP_HOME""/nvme.sh" # For nvme components + +### JSON +source $JSON_SCRIPT + +### SMBIOS +source $SMBIOS_SCRIPT # See the TCG SMBIOS Component Class Registry specification. +COMPCLASS_REGISTRY_SMBIOS="2.23.133.18.3.3" # See the TCG OID Registry. ### hw source $HW_SCRIPT source $NVME_SCRIPT -### ComponentClass values -COMPCLASS_REGISTRY_TCG="2.23.133.18.3.1" # switch off values within SMBIOS to reveal accurate component classes -COMPCLASS_BASEBOARD="00030003" # these values are meant to be an example. check the component class registry. +### TCG ComponentClass values +COMPCLASS_REGISTRY_TCG="2.23.133.18.3.1" +COMPCLASS_BASEBOARD="00030003" # these values are meant to be an example. check the TCG component class registry. COMPCLASS_BIOS="00130003" COMPCLASS_UEFI="00130002" -COMPCLASS_CHASSIS="00020001" # TODO: chassis type is included in SMBIOS +COMPCLASS_CHASSIS="00020001" COMPCLASS_CPU="00010002" COMPCLASS_HDD="00070002" COMPCLASS_NIC="00090002" -COMPCLASS_RAM="00060001" # TODO: memory type is included in SMBIOS +COMPCLASS_RAM="00060001" COMPCLASS_GFX="00050002" -### JSON Structure Keywords -JSON_COMPONENTS="COMPONENTS" -JSON_COMPONENTSURI="COMPONENTSURI" -JSON_PROPERTIES="PROPERTIES" -JSON_PROPERTIESURI="PROPERTIESURI" -JSON_PLATFORM="PLATFORM" -#### JSON Component Keywords -JSON_COMPONENTCLASS="COMPONENTCLASS" -JSON_COMPONENTCLASSREGISTRY="COMPONENTCLASSREGISTRY" -JSON_COMPONENTCLASSVALUE="COMPONENTCLASSVALUE" -JSON_MANUFACTURER="MANUFACTURER" -JSON_MODEL="MODEL" -JSON_SERIAL="SERIAL" -JSON_REVISION="REVISION" -JSON_MANUFACTURERID="MANUFACTURERID" -JSON_FIELDREPLACEABLE="FIELDREPLACEABLE" -JSON_ADDRESSES="ADDRESSES" -JSON_ETHERNETMAC="ETHERNETMAC" -JSON_WLANMAC="WLANMAC" -JSON_BLUETOOTHMAC="BLUETOOTHMAC" -JSON_COMPONENTPLATFORMCERT="PLATFORMCERT" -JSON_ATTRIBUTECERTIDENTIFIER="ATTRIBUTECERTIDENTIFIER" -JSON_GENERICCERTIDENTIFIER="GENERICCERTIDENTIFIER" -JSON_ISSUER="ISSUER" -JSON_COMPONENTPLATFORMCERTURI="PLATFORMCERTURI" -JSON_STATUS="STATUS" -#### JSON Platform Keywords (Subject Alternative Name) -JSON_PLATFORMMODEL="PLATFORMMODEL" -JSON_PLATFORMMANUFACTURERSTR="PLATFORMMANUFACTURERSTR" -JSON_PLATFORMVERSION="PLATFORMVERSION" -JSON_PLATFORMSERIAL="PLATFORMSERIAL" -JSON_PLATFORMMANUFACTURERID="PLATFORMMANUFACTURERID" -#### JSON Platform URI Keywords -JSON_URI="UNIFORMRESOURCEIDENTIFIER" -JSON_HASHALG="HASHALGORITHM" -JSON_HASHVALUE="HASHVALUE" -#### JSON Properties Keywords -JSON_NAME="NAME" -JSON_VALUE="VALUE" -NOT_SPECIFIED="Not Specified" - - -### JSON Structure Format -JSON_INTERMEDIATE_FILE_OBJECT='{ - %s -}' -JSON_PLATFORM_TEMPLATE=' - \"'"$JSON_PLATFORM"'\": { - %s - }' -JSON_PROPERTIESURI_TEMPLATE=' - \"'"$JSON_PROPERTIESURI"'\": { - %s - }' -JSON_COMPONENTSURI_TEMPLATE=' - \"'"$JSON_COMPONENTSURI"'\": { - %s - }' -JSON_PROPERTY_ARRAY_TEMPLATE=' - \"'"$JSON_PROPERTIES"'\": [%s - ]' -JSON_COMPONENT_ARRAY_TEMPLATE=' - \"'"$JSON_COMPONENTS"'\": [%s - ]' -JSON_COMPONENT_TEMPLATE=' - { - %s - }' -JSON_PROPERTY_TEMPLATE=' - { - \"'"$JSON_NAME"'\": \"%s\", - \"'"$JSON_VALUE"'\": \"%s\" - } -' -JSON_ADDRESSES_TEMPLATE=' \"'"$JSON_ADDRESSES"'\": [%s]' -JSON_ETHERNETMAC_TEMPLATE=' { - \"'"$JSON_ETHERNETMAC"'\": \"%s\" } ' -JSON_WLANMAC_TEMPLATE=' { - \"'"$JSON_WLANMAC"'\": \"%s\" } ' -JSON_BLUETOOTHMAC_TEMPLATE=' { - \"'"$JSON_BLUETOOTHMAC"'\": \"%s\" } ' -JSON_COMPONENTCLASS_TEMPLATE=' \"'"$JSON_COMPONENTCLASS"'\": { - \"'"$JSON_COMPONENTCLASSREGISTRY"'\": \"%s\", - \"'"$JSON_COMPONENTCLASSVALUE"'\": \"%s\" - }' -JSON_ATTRIBUTECERTIDENTIFIER_TEMPLATE=' \"'"$JSON_ATTRIBUTECERTIDENTIFIER"'\": { - \"'"$JSON_HASHALG"'\": \"%s\", - \"'"$JSON_HASHVALUE"'\": \"%s\" - },' -JSON_GENERICCERTIDENTIFIER_TEMPLATE=' \"'"$JSON_GENERICCERTIDENTIFIER"'\": { - \"'"$JSON_ISSUER"'\": \"%s\", - \"'"$JSON_SERIAL"'\": \"%s\" - },' -JSON_COMPONENTPLATFORMCERT_TEMPLATE=' - \"'"$JSON_COMPONENTPLATFORMCERT"'\": { - %s - }' -JSON_COMPONENTPLATFORMCERTURI_TEMPLATE=' - \"'"$JSON_COMPONENTPLATFORMCERTURI"'\": { - %s - }' -JSON_STATUS_TEMPLATE=' - \"'"$JSON_STATUS"'\": { - - }' - -### JSON Constructor Aides -jsonComponentClass () { - printf "$JSON_COMPONENTCLASS_TEMPLATE" "${1}" "${2}" -} -jsonManufacturer () { - manufacturer=$(printf '\"'"$JSON_MANUFACTURER"'\": \"%s\"' "${1}") - #tmpManufacturerId=$(queryForPen "${1}") - #if [ -n "$tmpManufacturerId" ] && [ "$tmpManufacturerId" != "$PEN_ROOT" ]; then - # tmpManufacturerId=$(jsonManufacturerId "$tmpManufacturerId") - # manufacturer="$manufacturer"",""$tmpManufacturerId" - #fi - printf "$manufacturer" -} -jsonModel () { - printf '\"'"$JSON_MODEL"'\": \"%s\"' "${1}" -} -jsonSerial () { - printf '\"'"$JSON_SERIAL"'\": \"%s\"' "${1}" -} -jsonRevision () { - printf '\"'"$JSON_REVISION"'\": \"%s\"' "${1}" -} -jsonManufacturerId () { - printf '\"'"$JSON_MANUFACTURERID"'\": \"%s\"' "${1}" -} -jsonFieldReplaceable () { - printf '\"'"$JSON_FIELDREPLACEABLE"'\": \"%s\"' "${1}" -} -jsonEthernetMac () { - printf "$JSON_ETHERNETMAC_TEMPLATE" "${1}" -} -jsonWlanMac () { - printf "$JSON_WLANMAC_TEMPLATE" "${1}" -} -jsonBluetoothMac () { - printf "$JSON_BLUETOOTHMAC_TEMPLATE" "${1}" -} -jsonPlatformModel () { - printf '\"'"$JSON_PLATFORMMODEL"'\": \"%s\"' "${1}" -} -jsonPlatformManufacturerStr () { - manufacturer=$(printf '\"'"$JSON_PLATFORMMANUFACTURERSTR"'\": \"%s\"' "${1}") - #tmpManufacturerId=$(queryForPen "${1}") - #if [ -n "$tmpManufacturerId" ] && [ "$tmpManufacturerId" != "$PEN_ROOT" ]; then - # tmpManufacturerId=$(jsonPlatformManufacturerId "$tmpManufacturerId") - # manufacturer="$manufacturer"",""$tmpManufacturerId" - #fi - printf "$manufacturer" -} -jsonPlatformVersion () { - printf '\"'"$JSON_PLATFORMVERSION"'\": \"%s\"' "${1}" -} -jsonPlatformSerial () { - printf '\"'"$JSON_PLATFORMSERIAL"'\": \"%s\"' "${1}" -} -jsonPlatformManufacturerId () { - printf '\"'"$JSON_PLATFORMMANUFACTURERID"'\": \"%s\"' "${1}" -} -queryForPen () { - pen=$(grep -B 1 "^[ \t]*""${1}""$" "$ENTERPRISE_NUMBERS_FILE" | sed -n '1p' | tr -d [:space:]) - printf "%s%s" "$PEN_ROOT" "$pen" -} -jsonProperty () { - if [ -n "${1}" ] && [ -n "${2}" ]; then - if [ -n "${3}" ]; then - printf "$JSON_PROPERTY_TEMPLATE" "${1}" "${2}" "${3}" - else - printf "$JSON_PROPERTY_TEMPLATE" "${1}" "${2}" - fi - fi -} -jsonUri () { - printf '\"'"$JSON_URI"'\": \"%s\"' "${1}" -} -jsonHashAlg () { - printf '\"'"$JSON_HASHALG"'\": \"%s\"' "${1}" -} -jsonHashValue () { - printf '\"'"$JSON_HASHVALUE"'\": \"%s\"' "${1}" -} -toCSV () { - old="$IFS" - IFS=',' - value="$*" - value=$(printf "$value" | tr -s , | sed -e '1s/^[,]*//' | sed -e '$s/[,]*$//') - printf "$value" -} -jsonAddress () { - printf "$JSON_ADDRESSES_TEMPLATE" "$(toCSV "$@")" -} -jsonComponent () { - printf "$JSON_COMPONENT_TEMPLATE" "$(toCSV "$@")" -} -jsonComponentArray () { - printf "$JSON_COMPONENT_ARRAY_TEMPLATE" "$(toCSV "$@")" -} -jsonPropertyArray () { - if [ "$#" -ne 0 ]; then - printf "$JSON_PROPERTY_ARRAY_TEMPLATE" "$(toCSV "$@")" - fi -} -jsonPlatformObject () { - printf "$JSON_PLATFORM_TEMPLATE" "$(toCSV "$@")" -} -jsonComponentsUri () { - if [ -n "$COMPONENTS_URI" ]; then - componentsUri=$(jsonUri "$COMPONENTS_URI") - componentsUriDetails="" - if [ -n "$PROPERTIES_URI_LOCAL_COPY_FOR_HASH" ]; then - hashAlg="2.16.840.1.101.3.4.2.1" # SHA256, see https://tools.ietf.org/html/rfc5754 for other common hash algorithm IDs - hashValue=$(sha256sum "$COMPONENTS_URI_LOCAL_COPY_FOR_HASH" | sed -r 's/^([0-9a-f]+).*/\1/' | tr -d [:space:] | xxd -r -p | base64 -w 0) - hashAlgStr=$(jsonHashAlg "$hashAlg") - hashValueStr=$(jsonHashValue "$hashValue") - propertiesUriDetails="$hashAlgStr"",""$hashValueStr" - fi - printf "$JSON_COMPONENTSURI_TEMPLATE" "$(toCSV "$componentsUri" "$componentsUriDetails")" - fi -} -jsonPropertiesUri () { - if [ -n "$PROPERTIES_URI" ]; then - propertiesUri=$(jsonUri "$PROPERTIES_URI") - propertiesUriDetails="" - if [ -n "$PROPERTIES_URI_LOCAL_COPY_FOR_HASH" ]; then - hashAlg="2.16.840.1.101.3.4.2.1" # SHA256, see https://tools.ietf.org/html/rfc5754 for other common hash algorithm IDs - hashValue=$(sha256sum "$PROPERTIES_URI_LOCAL_COPY_FOR_HASH" | sed -r 's/^([0-9a-f]+).*/\1/' | tr -d [:space:] | xxd -r -p | base64 -w 0) - hashAlgStr=$(jsonHashAlg "$hashAlg") - hashValueStr=$(jsonHashValue "$hashValue") - propertiesUriDetails="$hashAlgStr"",""$hashValueStr" - fi| sed 's/^[ \t]*//;s/[ \t]*$//' - printf "$JSON_PROPERTIESURI_TEMPLATE" "$(toCSV "$propertiesUri" "$propertiesUriDetails")" - fi -} -jsonIntermediateFile () { - printf "$JSON_INTERMEDIATE_FILE_OBJECT" "$(toCSV "$@")" -} -standardizeMACAddr () { - mac=$(printf "${1}" | tr -d "[[:space:]]:-" | awk '{ print toupper($0) }') - printf "$mac" -} - - - ## Some of the commands below require root. if [ "$EUID" -ne 0 ] then echo "Please run as root" exit fi +### Gather platform details for the subject alternative name +### Platform attributes in the SAN only need to be consistent between base and delta platform certificates +gatherSmbiosSystemForSubjectAlternativeName () { + dmidecodeParseTypeAssumeOneHandle "$SMBIOS_TYPE_SYSTEM" + platformManufacturer=$(dmidecodeGetString $(dmidecodeGetByte "0x4")) + platformModel=$(dmidecodeGetString $(dmidecodeGetByte "0x5")) + platformVersion=$(dmidecodeGetString $(dmidecodeGetByte "0x6")) + platformSerial=$(dmidecodeGetString $(dmidecodeGetByte "0x7")) + + if [[ -z "${platformManufacturer// }" ]]; then + platformManufacturer="$NOT_SPECIFIED" + fi + platformManufacturer=$(echo "$platformManufacturer" | sed 's/^[ ]*//;s/[ ]*$//') + platformManufacturer=$(jsonPlatformManufacturerStr "$platformManufacturer") + + if [[ -z "${platformModel// }" ]]; then + platformModel="$NOT_SPECIFIED" + fi + platformModel=$(echo "$platformModel" | sed 's/^[ ]*//;s/[ ]*$//') + platformModel=$(jsonPlatformModel "$platformModel") + + if [[ -z "${platformVersion// }" ]]; then + platformVersion="$NOT_SPECIFIED" + fi + platformVersion=$(echo "$platformVersion" | sed 's/^[ ]*//;s/[ ]*$//') + platformVersion=$(jsonPlatformVersion "$platformVersion") + + if ! [[ -z "${platformSerial// }" ]]; then + platformSerial=$(echo "$platformSerial" | sed 's/^[ ]*//;s/[ ]*$//') + platformSerial=$(jsonPlatformSerial "$platformSerial") + fi + platform=$(jsonPlatformObject "$platformManufacturer" "$platformModel" "$platformVersion" "$platformSerial") + platform=$(printf "$platform" | cut -c2-) + printf "$platform" +} + +### Gather data from SMBIOS +gatherSmbiosData () { + components="" + for type in $SMBIOS_TYPE_BASEBOARD $SMBIOS_TYPE_BIOS $SMBIOS_TYPE_CHASSIS $SMBIOS_TYPE_PROCESSOR $SMBIOS_TYPE_RAM $SMBIOS_TYPE_SYSTEM $SMBIOS_TYPE_POWERSUPPLY $SMBIOS_TYPE_TPM + do + dmidecodeHandles "$type" + numHandles=$(dmidecodeNumHandles) + + for ((i = 0 ; i < numHandles ; i++ )); + do + component="" + dmidecodeParseHandle "${tableHandles[$i]}" + + componentClassValue=$(dmidecodeGetComponentClassValue) + manufacturer=$(dmidecodeGetManufacturer) + model=$(dmidecodeGetModel) + serialNumber=$(dmidecodeGetSerialNumber) + revision=$(dmidecodeGetRevision) + fieldReplaceable=$(dmidecodeGetFieldReplaceable) + + # Do not include empty slots + if [[ -z "$manufacturer" ]] && [[ -z "$model" ]] && [[ -z "$serialNumber" ]] && [[ -z "$revision" ]]; then + continue + fi + + componentClass=$(jsonComponentClass "$COMPCLASS_REGISTRY_SMBIOS" "$componentClassValue") + manufacturer=$(jsonManufacturer "$manufacturer") + model=$(jsonModel "$model") + if ! [[ -z "$serialNumber" ]]; then + serialNumber=$(jsonSerial "$serialNumber") + fi + if ! [[ -z "$revision" ]]; then + revision=$(jsonRevision "$revision") + fi + if ! [[ -z "$fieldReplaceable" ]]; then + fieldReplaceable=$(jsonFieldReplaceable "$fieldReplaceable") + fi + component=$(jsonComponent "$componentClass" "$manufacturer" "$model" "$serialNumber" "$revision" "$fieldReplaceable") + components="$components"",""$component" + done # handles for loop + done # type for loop + components=$(printf "$components" | cut -c2-) + printf "$components" +} + ### Gather platform details for the subject alternative name dmidecodeParseTypeAssumeOneHandle "$SMBIOS_TYPE_PLATFORM" platformManufacturer=$(dmidecodeGetString $(dmidecodeGetByte "0x4")) @@ -587,23 +421,23 @@ parseNicData () { if [[ -z "${manufacturer// }" ]]; then manufacturer="$NOT_SPECIFIED" fi - manufacturer=$(echo "$manufacturer" | sed 's/^[ \t]*//;s/[ \t]*$//') + manufacturer=$(echo "$manufacturer" | sed 's/^[ ]*//;s/[ ]*$//') manufacturer=$(jsonManufacturer "$manufacturer") if [[ -z "${model// }" ]]; then model="$NOT_SPECIFIED" fi - model=$(echo "$model" | sed 's/^[ \t]*//;s/[ \t]*$//') + model=$(echo "$model" | sed 's/^[ ]*//;s/[ ]*$//') model=$(jsonModel "$model") optional="" if ! [[ -z "${serialConstant// }" ]]; then - serial=$(echo "$serialConstant" | sed 's/^[ \t]*//;s/[ \t]*$//') + serial=$(echo "$serialConstant" | sed 's/^[ ]*//;s/[ ]*$//') serial=$(jsonSerial "$serialConstant") optional="$optional"",""$serial" fi if ! [[ -z "${revision// }" ]]; then - revision=$(echo "$revision" | sed 's/^[ \t]*//;s/[ \t]*$//' | awk '{ print toupper($0) }') + revision=$(echo "$revision" | sed 's/^[ ]*//;s/[ ]*$//' | awk '{ print toupper($0) }') revision=$(jsonRevision "$revision") optional="$optional"",""$revision" fi @@ -660,23 +494,23 @@ parseHddData () { if [[ -z "${manufacturer// }" ]]; then manufacturer="$NOT_SPECIFIED" fi - manufacturer=$(echo "$manufacturer" | sed 's/^[ \t]*//;s/[ \t]*$//') + manufacturer=$(echo "$manufacturer" | sed 's/^[ ]*//;s/[ ]*$//') manufacturer=$(jsonManufacturer "$manufacturer") if [[ -z "${model// }" ]]; then model="$NOT_SPECIFIED" fi - model=$(echo "$model" | sed 's/^[ \t]*//;s/[ \t]*$//') + model=$(echo "$model" | sed 's/^[ ]*//;s/[ ]*$//') model=$(jsonModel "$model") optional="" if ! [[ -z "${serial// }" ]]; then - serial=$(echo "$serial" | sed 's/^[ \t]*//;s/[ \t]*$//') + serial=$(echo "$serial" | sed 's/^[ ]*//;s/[ ]*$//') serial=$(jsonSerial "$serial") optional="$optional"",""$serial" fi if ! [[ -z "${revision// }" ]]; then - revision=$(echo "$revision" | sed 's/^[ \t]*//;s/[ \t]*$//' | awk '{ print toupper($0) }') + revision=$(echo "$revision" | sed 's/^[ ]*//;s/[ ]*$//' | awk '{ print toupper($0) }') revision=$(jsonRevision "$revision") optional="$optional"",""$revision" fi @@ -692,6 +526,7 @@ parseHddData () { printf "$tmpData" } +### Gather data from NVMe CLI parseNvmeData () { nvmeParse @@ -712,18 +547,18 @@ parseNvmeData () { if [[ -z "${manufacturer// }" ]]; then manufacturer="$NOT_SPECIFIED" fi - manufacturer=$(echo "$manufacturer" | sed 's/^[ \t]*//;s/[ \t]*$//') + manufacturer=$(echo "$manufacturer" | sed 's/^[ ]*//;s/[ ]*$//') manufacturer=$(jsonManufacturer "$manufacturer") if [[ -z "${model// }" ]]; then model="$NOT_SPECIFIED" fi - model=$(echo "${model:0:16}" | sed 's/^[ \t]*//;s/[ \t]*$//') # limited to 16 characters for compatibility to windows, then trimmed + model=$(echo "${model:0:16}" | sed 's/^[ ]*//;s/[ ]*$//') # limited to 16 characters for compatibility to windows, then trimmed model=$(jsonModel "$model") optional="" if ! [[ -z "${serial// }" ]]; then - serial=$(echo "${serial^^}" | sed 's/^[ \t]*//;s/[ \t]*$//' | sed 's/.\{4\}/&_/g' | sed 's/_$/\./') + serial=$(echo "${serial^^}" | sed 's/^[ ]*//;s/[ ]*$//' | sed 's/.\{4\}/&_/g' | sed 's/_$/\./') serial=$(jsonSerial "$serial") optional="$optional"",""$serial" fi @@ -739,6 +574,7 @@ parseNvmeData () { printf "$tmpData" } +### Gather GFX details parseGfxData () { lshwDisplay @@ -749,63 +585,64 @@ parseGfxData () { for ((i = 0 ; i < numHandles ; i++ )); do manufacturer=$(lshwGetVendorIDFromBusItem "$i") - model=$(lshwGetProductIDFromBusItem "$i") - serial=$(lshwGetSerialFromBusItem "$i") - revision=$(lshwGetVersionFromBusItem "$i") - - if [[ -z "${manufacturer// }" ]] && [[ -z "${model// }" ]] && (! [[ -z "${serial// }" ]] || ! [[ -z "${revision// }" ]]); then - manufacturer=$(lshwGetVendorNameFromBusItem "$i") - model=$(lshwGetProductNameFromBusItem "$i") - fi + model=$(lshwGetProductIDFromBusItem "$i") + serial=$(lshwGetSerialFromBusItem "$i") + revision=$(lshwGetVersionFromBusItem "$i") - if [[ -z "${manufacturer// }" ]]; then - manufacturer="$NOT_SPECIFIED" - fi - manufacturer=$(echo "$manufacturer" | sed 's/^[ \t]*//;s/[ \t]*$//') - manufacturer=$(jsonManufacturer "$manufacturer") + if [[ -z "${manufacturer// }" ]] && [[ -z "${model// }" ]] && (! [[ -z "${serial// }" ]] || ! [[ -z "${revision// }" ]]); then + manufacturer=$(lshwGetVendorNameFromBusItem "$i") + model=$(lshwGetProductNameFromBusItem "$i") + fi - if [[ -z "${model// }" ]]; then - model="$NOT_SPECIFIED" - fi - model=$(echo "$model" | sed 's/^[ \t]*//;s/[ \t]*$//') - model=$(jsonModel "$model") + if [[ -z "${manufacturer// }" ]]; then + manufacturer="$NOT_SPECIFIED" + fi + manufacturer=$(echo "$manufacturer" | sed 's/^[ ]*//;s/[ ]*$//') + manufacturer=$(jsonManufacturer "$manufacturer") - optional="" - if ! [[ -z "${serial// }" ]]; then - serial=$(echo "$serial" | sed 's/^[ \t]*//;s/[ \t]*$//') - serial=$(jsonSerial "$serial") - optional="$optional"",""$serial" - fi - if ! [[ -z "${revision// }" ]]; then - revision=$(echo "$revision" | sed 's/^[ \t]*//;s/[ \t]*$//' | awk '{ print toupper($0) }') - revision=$(jsonRevision "$revision") - optional="$optional"",""$revision" - fi - optional=$(printf "$optional" | cut -c2-) + if [[ -z "${model// }" ]]; then + model="$NOT_SPECIFIED" + fi + model=$(echo "$model" | sed 's/^[ ]*//;s/[ ]*$//') + model=$(jsonModel "$model") + + optional="" + if ! [[ -z "${serial// }" ]]; then + serial=$(echo "$serial" | sed 's/^[ ]*//;s/[ ]*$//') + serial=$(jsonSerial "$serial") + optional="$optional"",""$serial" + fi + if ! [[ -z "${revision// }" ]]; then + revision=$(echo "$revision" | sed 's/^[ ]*//;s/[ ]*$//' | awk '{ print toupper($0) }') + revision=$(jsonRevision "$revision") + optional="$optional"",""$revision" + fi + optional=$(printf "$optional" | cut -c2-) - newGfxData=$(jsonComponent "$class" "$manufacturer" "$model" "$replaceable" "$optional") - tmpData="$tmpData"",""$newGfxData" - done + newGfxData=$(jsonComponent "$class" "$manufacturer" "$model" "$replaceable" "$optional") + tmpData="$tmpData"",""$newGfxData" + done - # remove leading comma - tmpData=$(printf "$tmpData" | cut -c2-) + # remove leading comma + tmpData=$(printf "$tmpData" | cut -c2-) - printf "$tmpData" + printf "$tmpData" } - ### Gather property details property1=$(jsonProperty "uname -r" "$(uname -r)") ## Example1 property2=$(jsonProperty "OS Release" "$(grep 'PRETTY_NAME=' /etc/os-release | sed 's/[^=]*=//' | sed -e 's/^[[:space:]\"]*//' | sed -e 's/[[:space:]\"]*$//')") ## Example2 ### Collate the component details -componentsCPU=$(parseCpuData) -componentsRAM=$(parseRamData) +platform=$(gatherSmbiosSystemForSubjectAlternativeName) +componentsSMBIOS=$(gatherSmbiosData) componentsNIC=$(parseNicData) componentsHDD=$(parseHddData) componentsNVMe=$(parseNvmeData) componentsGFX=$(parseGfxData) -componentArray=$(jsonComponentArray "$componentChassis" "$componentBaseboard" "$componentBios" "$componentsCPU" "$componentsRAM" "$componentsNIC" "$componentsHDD" "$componentsNVMe" "$componentsGFX") +componentsCPU=$(parseCpuData) +componentsRAM=$(parseRamData) +componentArray=$(jsonComponentArray "$componentsSMBIOS" "$componentsNIC" "$componentsHDD" "$componentsNVMe" "$componentsGFX" "$componentChassis" "$componentBaseboard" "$componentBios" "$componentsCPU" "$componentsRAM") ### Collate the property details propertyArray=$(jsonPropertyArray "$property1" "$property2") @@ -824,5 +661,3 @@ if [ -n "$PROPERTIES_URI" ]; then fi printf "$FINAL_JSON_OBJECT""\n\n" - - diff --git a/scripts/componentlist.sh b/scripts/componentlist.sh new file mode 100644 index 0000000..1676958 --- /dev/null +++ b/scripts/componentlist.sh @@ -0,0 +1,403 @@ +#!/bin/bash + +### componentlist.sh +### gathers identifiers for all components on the system for creation of a platform certificate +### multiple component class registries are used, and each component on the system will +### have one componentIdentifier in the resulting JSON output + +### User customizable values +APP_HOME="`dirname "$0"`" +COMPONENTS_URI="" # Specify the optional components URI field +COMPONENTS_URI_LOCAL_COPY_FOR_HASH="" # If empty, the optional hashAlgorithm and hashValue fields will not be included for the URI +PROPERTIES_URI="" # Specify the optional properties URI field +PROPERTIES_URI_LOCAL_COPY_FOR_HASH="" # If empty, the optional hashAlgorithm and hashValue fields will not be included for the URI +JSON_SCRIPT="$APP_HOME""/json.sh" # Defines JSON structure and provides methods for producing relevant JSON +SMBIOS_SCRIPT="$APP_HOME""/smbios.sh" # Handles parsing of SMBIOS data +HW_SCRIPT="$APP_HOME""/hw.sh" # Handles parsing of lshw +NVME_SCRIPT="$APP_HOME""/nvme.sh" # For nvme components + +### JSON +source $JSON_SCRIPT + +### SMBIOS +source $SMBIOS_SCRIPT # See the TCG SMBIOS Component Class Registry specification. +COMPCLASS_REGISTRY_SMBIOS="2.23.133.18.3.3" # See the TCG OID Registry. + +### hw +source $HW_SCRIPT +source $NVME_SCRIPT + +### TCG ComponentClass values +COMPCLASS_REGISTRY_TCG="2.23.133.18.3.1" +COMPCLASS_BASEBOARD="00030003" # these values are meant to be an example. check the TCG component class registry. +COMPCLASS_BIOS="00130003" +COMPCLASS_UEFI="00130002" +COMPCLASS_CHASSIS="00020001" +COMPCLASS_CPU="00010002" +COMPCLASS_HDD="00070002" +COMPCLASS_NIC="00090002" +COMPCLASS_RAM="00060001" +COMPCLASS_GFX="00050002" + +## Some of the commands below require root. +if [ "$EUID" -ne 0 ] + then echo "Please run as root" + exit +fi + +### Gather platform details for the subject alternative name +### Platform attributes in the SAN only need to be consistent between base and delta platform certificates +gatherSmbiosSystemForSubjectAlternativeName () { + dmidecodeParseTypeAssumeOneHandle "$SMBIOS_TYPE_SYSTEM" + platformManufacturer=$(dmidecodeGetString $(dmidecodeGetByte "0x4")) + platformModel=$(dmidecodeGetString $(dmidecodeGetByte "0x5")) + platformVersion=$(dmidecodeGetString $(dmidecodeGetByte "0x6")) + platformSerial=$(dmidecodeGetString $(dmidecodeGetByte "0x7")) + + if [[ -z "${platformManufacturer// }" ]]; then + platformManufacturer="$NOT_SPECIFIED" + fi + platformManufacturer=$(echo "$platformManufacturer" | sed 's/^[ ]*//;s/[ ]*$//') + platformManufacturer=$(jsonPlatformManufacturerStr "$platformManufacturer") + + if [[ -z "${platformModel// }" ]]; then + platformModel="$NOT_SPECIFIED" + fi + platformModel=$(echo "$platformModel" | sed 's/^[ ]*//;s/[ ]*$//') + platformModel=$(jsonPlatformModel "$platformModel") + + if [[ -z "${platformVersion// }" ]]; then + platformVersion="$NOT_SPECIFIED" + fi + platformVersion=$(echo "$platformVersion" | sed 's/^[ ]*//;s/[ ]*$//') + platformVersion=$(jsonPlatformVersion "$platformVersion") + + if ! [[ -z "${platformSerial// }" ]]; then + platformSerial=$(echo "$platformSerial" | sed 's/^[ ]*//;s/[ ]*$//') + platformSerial=$(jsonPlatformSerial "$platformSerial") + fi + platform=$(jsonPlatformObject "$platformManufacturer" "$platformModel" "$platformVersion" "$platformSerial") + platform=$(printf "$platform" | cut -c2-) + printf "$platform" +} + +### Gather data from SMBIOS +gatherSmbiosData () { + components="" + for type in $SMBIOS_TYPE_BASEBOARD $SMBIOS_TYPE_BIOS $SMBIOS_TYPE_CHASSIS $SMBIOS_TYPE_PROCESSOR $SMBIOS_TYPE_RAM $SMBIOS_TYPE_SYSTEM $SMBIOS_TYPE_POWERSUPPLY $SMBIOS_TYPE_TPM + do + dmidecodeHandles "$type" + numHandles=$(dmidecodeNumHandles) + + for ((i = 0 ; i < numHandles ; i++ )); + do + component="" + dmidecodeParseHandle "${tableHandles[$i]}" + + componentClassValue=$(dmidecodeGetComponentClassValue) + manufacturer=$(dmidecodeGetManufacturer) + model=$(dmidecodeGetModel) + serialNumber=$(dmidecodeGetSerialNumber) + revision=$(dmidecodeGetRevision) + fieldReplaceable=$(dmidecodeGetFieldReplaceable) + + # Do not include empty slots + if [[ -z "$manufacturer" ]] && [[ -z "$model" ]] && [[ -z "$serialNumber" ]] && [[ -z "$revision" ]]; then + continue + fi + + componentClass=$(jsonComponentClass "$COMPCLASS_REGISTRY_SMBIOS" "$componentClassValue") + manufacturer=$(jsonManufacturer "$manufacturer") + model=$(jsonModel "$model") + if ! [[ -z "$serialNumber" ]]; then + serialNumber=$(jsonSerial "$serialNumber") + fi + if ! [[ -z "$revision" ]]; then + revision=$(jsonRevision "$revision") + fi + if ! [[ -z "$fieldReplaceable" ]]; then + fieldReplaceable=$(jsonFieldReplaceable "$fieldReplaceable") + fi + component=$(jsonComponent "$componentClass" "$manufacturer" "$model" "$serialNumber" "$revision" "$fieldReplaceable") + components="$components"",""$component" + done # handles for loop + done # type for loop + components=$(printf "$components" | cut -c2-) + printf "$components" +} + +# Write script to parse multiple responses +# Network: +# lshw description: type of address. +# : Ethernet interface, Wireless interface, Bluetooth wireless interface +# vendor: manufacturer +# product: model +# serial: address & serial number +# version: revision +# +# Example: +# ADDRESS1=$(jsonEthernetMac "AB:CD:EE:EE:DE:34") +# ADDR_LIST=$(jsonAddress "$ADDRESS1" "$ADDRESS2") +parseNicData () { + lshwNetwork + + replaceable=$(jsonFieldReplaceable "true") + tmpData="" + numHandles=$(lshwNumBusItems) + class=$(jsonComponentClass "$COMPCLASS_REGISTRY_TCG" "$COMPCLASS_NIC") + + for ((i = 0 ; i < numHandles ; i++ )); do + manufacturer=$(lshwGetVendorIDFromBusItem "$i") + model=$(lshwGetProductIDFromBusItem "$i") + serialConstant=$(lshwGetLogicalNameFromBusItem "$i") + serialConstant=$(ethtoolPermAddr "$serialConstant") + serialConstant=$(standardizeMACAddr "${serialConstant}") + serial="" + revision=$(lshwGetVersionFromBusItem "$i") + + if [[ -z "${manufacturer// }" ]] && [[ -z "${model// }" ]] && (! [[ -z "${serialConstant// }" ]] || ! [[ -z "${revision// }" ]]); then + manufacturer=$(lshwGetVendorNameFromBusItem "$i") + model=$(lshwGetProductNameFromBusItem "$i") + fi + + if [[ -z "${manufacturer// }" ]]; then + manufacturer="$NOT_SPECIFIED" + fi + manufacturer=$(echo "$manufacturer" | sed 's/^[ ]*//;s/[ ]*$//') + manufacturer=$(jsonManufacturer "$manufacturer") + + if [[ -z "${model// }" ]]; then + model="$NOT_SPECIFIED" + fi + model=$(echo "$model" | sed 's/^[ ]*//;s/[ ]*$//') + model=$(jsonModel "$model") + + optional="" + if ! [[ -z "${serialConstant// }" ]]; then + serial=$(echo "$serialConstant" | sed 's/^[ ]*//;s/[ ]*$//') + serial=$(jsonSerial "$serialConstant") + optional="$optional"",""$serial" + fi + if ! [[ -z "${revision// }" ]]; then + revision=$(echo "$revision" | sed 's/^[ ]*//;s/[ ]*$//' | awk '{ print toupper($0) }') + revision=$(jsonRevision "$revision") + optional="$optional"",""$revision" + fi + bluetoothCap=$(lshwBusItemBluetoothCap "$i") + ethernetCap=$(lshwBusItemEthernetCap "$i") + wirelessCap=$(lshwBusItemWirelessCap "$i") + + if ([ -n "$bluetoothCap" ] || [ -n "$ethernetCap" ] || [ -n "$wirelessCap" ]) && ! [[ -z "${serialConstant// }" ]]; then + thisAddress= + if [ -n "$wirelessCap" ]; then + thisAddress=$(jsonWlanMac "$serialConstant") + elif [ -n "$bluetoothCap" ]; then + thisAddress=$(jsonBluetoothMac "$serialConstant") + elif [ -n "$ethernetCap" ]; then + thisAddress=$(jsonEthernetMac "$serialConstant") + fi + if [ -n "$thisAddress" ]; then + thisAddress=$(jsonAddress "$thisAddress") + optional="$optional"",""$thisAddress" + fi + fi + optional=$(printf "$optional" | cut -c2-) + + newNicData=$(jsonComponent "$class" "$manufacturer" "$model" "$replaceable" "$optional") + tmpData="$tmpData"",""$newNicData" + done + + # remove leading comma + tmpData=$(printf "$tmpData" | cut -c2-) + + printf "$tmpData" +} + +parseHddData () { + lshwDisk + + replaceable=$(jsonFieldReplaceable "true") + tmpData="" + numHandles=$(lshwNumBusItems) + class=$(jsonComponentClass "$COMPCLASS_REGISTRY_TCG" "$COMPCLASS_HDD") + + for ((i = 0 ; i < numHandles ; i++ )); do + manufacturer=$(lshwGetVendorIDFromBusItem "$i") + model=$(lshwGetProductIDFromBusItem "$i") + serial=$(lshwGetSerialFromBusItem "$i") + revision=$(lshwGetVersionFromBusItem "$i") + + if [[ -z "${manufacturer// }" ]] && [[ -z "${model// }" ]] && (! [[ -z "${serial// }" ]] || ! [[ -z "${revision// }" ]]); then + model=$(lshwGetProductNameFromBusItem "$i") + manufacturer="" + revision="" # Seeing inconsistent behavior cross-OS for this case, will return + fi + + if [[ -z "${manufacturer// }" ]]; then + manufacturer="$NOT_SPECIFIED" + fi + manufacturer=$(echo "$manufacturer" | sed 's/^[ ]*//;s/[ ]*$//') + manufacturer=$(jsonManufacturer "$manufacturer") + + if [[ -z "${model// }" ]]; then + model="$NOT_SPECIFIED" + fi + model=$(echo "$model" | sed 's/^[ ]*//;s/[ ]*$//') + model=$(jsonModel "$model") + + optional="" + if ! [[ -z "${serial// }" ]]; then + serial=$(echo "$serial" | sed 's/^[ ]*//;s/[ ]*$//') + serial=$(jsonSerial "$serial") + optional="$optional"",""$serial" + fi + if ! [[ -z "${revision// }" ]]; then + revision=$(echo "$revision" | sed 's/^[ ]*//;s/[ ]*$//' | awk '{ print toupper($0) }') + revision=$(jsonRevision "$revision") + optional="$optional"",""$revision" + fi + optional=$(printf "$optional" | cut -c2-) + + newHddData=$(jsonComponent "$class" "$manufacturer" "$model" "$replaceable" "$optional") + tmpData="$tmpData"",""$newHddData" + done + + # remove leading comma + tmpData=$(printf "$tmpData" | cut -c2-) + + printf "$tmpData" +} + +### Gather data from NVMe CLI +parseNvmeData () { + nvmeParse + + replaceable=$(jsonFieldReplaceable "true") + tmpData="" + numHandles=$(nvmeNumDevices) + class=$(jsonComponentClass "$COMPCLASS_REGISTRY_TCG" "$COMPCLASS_HDD") + + for ((i = 0 ; i < numHandles ; i++ )); do + manufacturer="" # Making this appear as it does on windows, lshw doesn't see nvme drives and nvme-cli doesn't return a manufacturer field + model=$(nvmeGetModelNumberForDevice "$i") + serial=$(nvmeGetNguidForDevice "$i") + if [[ $serial =~ ^[0]+$ ]]; then + serial=$(nvmeGetEuiForDevice "$i") + fi + revision="" # empty for a similar reason to the manufacturer field + + if [[ -z "${manufacturer// }" ]]; then + manufacturer="$NOT_SPECIFIED" + fi + manufacturer=$(echo "$manufacturer" | sed 's/^[ ]*//;s/[ ]*$//') + manufacturer=$(jsonManufacturer "$manufacturer") + + if [[ -z "${model// }" ]]; then + model="$NOT_SPECIFIED" + fi + model=$(echo "${model:0:16}" | sed 's/^[ ]*//;s/[ ]*$//') # limited to 16 characters for compatibility to windows, then trimmed + model=$(jsonModel "$model") + + optional="" + if ! [[ -z "${serial// }" ]]; then + serial=$(echo "${serial^^}" | sed 's/^[ ]*//;s/[ ]*$//' | sed 's/.\{4\}/&_/g' | sed 's/_$/\./') + serial=$(jsonSerial "$serial") + optional="$optional"",""$serial" + fi + optional=$(printf "$optional" | cut -c2-) + + newHddData=$(jsonComponent "$class" "$manufacturer" "$model" "$replaceable" "$optional") + tmpData="$tmpData"",""$newHddData" + done + + # remove leading comma + tmpData=$(printf "$tmpData" | cut -c2-) + + printf "$tmpData" +} + +### Gather GFX details +parseGfxData () { + lshwDisplay + + replaceable=$(jsonFieldReplaceable "true") + tmpData="" + numHandles=$(lshwNumBusItems) + class=$(jsonComponentClass "$COMPCLASS_REGISTRY_TCG" "$COMPCLASS_GFX") + + for ((i = 0 ; i < numHandles ; i++ )); do + manufacturer=$(lshwGetVendorIDFromBusItem "$i") + model=$(lshwGetProductIDFromBusItem "$i") + serial=$(lshwGetSerialFromBusItem "$i") + revision=$(lshwGetVersionFromBusItem "$i") + + if [[ -z "${manufacturer// }" ]] && [[ -z "${model// }" ]] && (! [[ -z "${serial// }" ]] || ! [[ -z "${revision// }" ]]); then + manufacturer=$(lshwGetVendorNameFromBusItem "$i") + model=$(lshwGetProductNameFromBusItem "$i") + fi + + if [[ -z "${manufacturer// }" ]]; then + manufacturer="$NOT_SPECIFIED" + fi + manufacturer=$(echo "$manufacturer" | sed 's/^[ ]*//;s/[ ]*$//') + manufacturer=$(jsonManufacturer "$manufacturer") + + if [[ -z "${model// }" ]]; then + model="$NOT_SPECIFIED" + fi + model=$(echo "$model" | sed 's/^[ ]*//;s/[ ]*$//') + model=$(jsonModel "$model") + + optional="" + if ! [[ -z "${serial// }" ]]; then + serial=$(echo "$serial" | sed 's/^[ ]*//;s/[ ]*$//') + serial=$(jsonSerial "$serial") + optional="$optional"",""$serial" + fi + if ! [[ -z "${revision// }" ]]; then + revision=$(echo "$revision" | sed 's/^[ ]*//;s/[ ]*$//' | awk '{ print toupper($0) }') + revision=$(jsonRevision "$revision") + optional="$optional"",""$revision" + fi + optional=$(printf "$optional" | cut -c2-) + + newGfxData=$(jsonComponent "$class" "$manufacturer" "$model" "$replaceable" "$optional") + tmpData="$tmpData"",""$newGfxData" + done + + # remove leading comma + tmpData=$(printf "$tmpData" | cut -c2-) + + printf "$tmpData" +} + +### Gather property details +property1=$(jsonProperty "uname -r" "$(uname -r)") ## Example1 +property2=$(jsonProperty "OS Release" "$(grep 'PRETTY_NAME=' /etc/os-release | sed 's/[^=]*=//' | sed -e 's/^[[:space:]\"]*//' | sed -e 's/[[:space:]\"]*$//')") ## Example2 + +### Collate the component details +platform=$(gatherSmbiosSystemForSubjectAlternativeName) +componentsSMBIOS=$(gatherSmbiosData) +componentsNIC=$(parseNicData) +componentsHDD=$(parseHddData) +componentsNVMe=$(parseNvmeData) +componentsGFX=$(parseGfxData) +componentArray=$(jsonComponentArray "$componentsSMBIOS" "$componentsNIC" "$componentsHDD" "$componentsNVMe" "$componentsGFX") + +### Collate the property details +propertyArray=$(jsonPropertyArray "$property1" "$property2") + +### Construct the final JSON object +FINAL_JSON_OBJECT=$(jsonIntermediateFile "$platform" "$componentArray" "$propertyArray") + +### Collate the URI details, if parameters above are blank, the fields will be excluded from the final JSON structure +if [ -n "$COMPONENTS_URI" ]; then + componentsUri=$(jsonComponentsUri) + FINAL_JSON_OBJECT="$FINAL_JSON_OBJECT"",""$componentsUri" +fi +if [ -n "$PROPERTIES_URI" ]; then + propertiesUri=$(jsonPropertiesUri) + FINAL_JSON_OBJECT="$FINAL_JSON_OBJECT"",""$propertiesUri" +fi + +printf "$FINAL_JSON_OBJECT""\n\n" diff --git a/scripts/json.sh b/scripts/json.sh new file mode 100644 index 0000000..13c2c1f --- /dev/null +++ b/scripts/json.sh @@ -0,0 +1,252 @@ +#!/bin/bash + +### User customizable values +APP_HOME="`dirname "$0"`" +ENTERPRISE_NUMBERS_FILE="$APP_HOME""/enterprise-numbers" +PEN_ROOT="1.3.6.1.4.1." # OID root for the private enterprise numbers + +### JSON Structure Keywords +JSON_COMPONENTS="COMPONENTS" +JSON_COMPONENTSURI="COMPONENTSURI" +JSON_PROPERTIES="PROPERTIES" +JSON_PROPERTIESURI="PROPERTIESURI" +JSON_PLATFORM="PLATFORM" +#### JSON Component Keywords +JSON_COMPONENTCLASS="COMPONENTCLASS" +JSON_COMPONENTCLASSREGISTRY="COMPONENTCLASSREGISTRY" +JSON_COMPONENTCLASSVALUE="COMPONENTCLASSVALUE" +JSON_MANUFACTURER="MANUFACTURER" +JSON_MODEL="MODEL" +JSON_SERIAL="SERIAL" +JSON_REVISION="REVISION" +JSON_MANUFACTURERID="MANUFACTURERID" +JSON_FIELDREPLACEABLE="FIELDREPLACEABLE" +JSON_ADDRESSES="ADDRESSES" +JSON_ETHERNETMAC="ETHERNETMAC" +JSON_WLANMAC="WLANMAC" +JSON_BLUETOOTHMAC="BLUETOOTHMAC" +JSON_COMPONENTPLATFORMCERT="PLATFORMCERT" +JSON_ATTRIBUTECERTIDENTIFIER="ATTRIBUTECERTIDENTIFIER" +JSON_GENERICCERTIDENTIFIER="GENERICCERTIDENTIFIER" +JSON_ISSUER="ISSUER" +JSON_COMPONENTPLATFORMCERTURI="PLATFORMCERTURI" +JSON_STATUS="STATUS" +#### JSON Platform Keywords (Subject Alternative Name) +JSON_PLATFORMMODEL="PLATFORMMODEL" +JSON_PLATFORMMANUFACTURERSTR="PLATFORMMANUFACTURERSTR" +JSON_PLATFORMVERSION="PLATFORMVERSION" +JSON_PLATFORMSERIAL="PLATFORMSERIAL" +JSON_PLATFORMMANUFACTURERID="PLATFORMMANUFACTURERID" +#### JSON Platform URI Keywords +JSON_URI="UNIFORMRESOURCEIDENTIFIER" +JSON_HASHALG="HASHALGORITHM" +JSON_HASHVALUE="HASHVALUE" +#### JSON Properties Keywords +JSON_NAME="NAME" +JSON_VALUE="VALUE" +NOT_SPECIFIED="Not Specified" + + +### JSON Structure Format +JSON_INTERMEDIATE_FILE_OBJECT='{ + %s +}' +JSON_PLATFORM_TEMPLATE=' + \"'"$JSON_PLATFORM"'\": { + %s + }' +JSON_PROPERTIESURI_TEMPLATE=' + \"'"$JSON_PROPERTIESURI"'\": { + %s + }' +JSON_COMPONENTSURI_TEMPLATE=' + \"'"$JSON_COMPONENTSURI"'\": { + %s + }' +JSON_PROPERTY_ARRAY_TEMPLATE=' + \"'"$JSON_PROPERTIES"'\": [%s + ]' +JSON_COMPONENT_ARRAY_TEMPLATE=' + \"'"$JSON_COMPONENTS"'\": [%s + ]' +JSON_COMPONENT_TEMPLATE=' + { + %s + }' +JSON_PROPERTY_TEMPLATE=' + { + \"'"$JSON_NAME"'\": \"%s\", + \"'"$JSON_VALUE"'\": \"%s\" + } +' +JSON_ADDRESSES_TEMPLATE=' \"'"$JSON_ADDRESSES"'\": [%s]' +JSON_ETHERNETMAC_TEMPLATE=' { + \"'"$JSON_ETHERNETMAC"'\": \"%s\" } ' +JSON_WLANMAC_TEMPLATE=' { + \"'"$JSON_WLANMAC"'\": \"%s\" } ' +JSON_BLUETOOTHMAC_TEMPLATE=' { + \"'"$JSON_BLUETOOTHMAC"'\": \"%s\" } ' +JSON_COMPONENTCLASS_TEMPLATE=' \"'"$JSON_COMPONENTCLASS"'\": { + \"'"$JSON_COMPONENTCLASSREGISTRY"'\": \"%s\", + \"'"$JSON_COMPONENTCLASSVALUE"'\": \"%s\" + }' +JSON_ATTRIBUTECERTIDENTIFIER_TEMPLATE=' \"'"$JSON_ATTRIBUTECERTIDENTIFIER"'\": { + \"'"$JSON_HASHALG"'\": \"%s\", + \"'"$JSON_HASHVALUE"'\": \"%s\" + },' +JSON_GENERICCERTIDENTIFIER_TEMPLATE=' \"'"$JSON_GENERICCERTIDENTIFIER"'\": { + \"'"$JSON_ISSUER"'\": \"%s\", + \"'"$JSON_SERIAL"'\": \"%s\" + },' +JSON_COMPONENTPLATFORMCERT_TEMPLATE=' + \"'"$JSON_COMPONENTPLATFORMCERT"'\": { + %s + }' +JSON_COMPONENTPLATFORMCERTURI_TEMPLATE=' + \"'"$JSON_COMPONENTPLATFORMCERTURI"'\": { + %s + }' +JSON_STATUS_TEMPLATE=' + \"'"$JSON_STATUS"'\": { + + }' + +### JSON Constructor Aides +jsonComponentClass () { + printf "$JSON_COMPONENTCLASS_TEMPLATE" "${1}" "${2}" +} +jsonManufacturer () { + manufacturer=$(printf '\"'"$JSON_MANUFACTURER"'\": \"%s\"' "${1}") + #tmpManufacturerId=$(queryForPen "${1}") + #if [ -n "$tmpManufacturerId" ] && [ "$tmpManufacturerId" != "$PEN_ROOT" ]; then + # tmpManufacturerId=$(jsonManufacturerId "$tmpManufacturerId") + # manufacturer="$manufacturer"",""$tmpManufacturerId" + #fi + printf "$manufacturer" +} +jsonModel () { + printf '\"'"$JSON_MODEL"'\": \"%s\"' "${1}" +} +jsonSerial () { + printf '\"'"$JSON_SERIAL"'\": \"%s\"' "${1}" +} +jsonRevision () { + printf '\"'"$JSON_REVISION"'\": \"%s\"' "${1}" +} +jsonManufacturerId () { + printf '\"'"$JSON_MANUFACTURERID"'\": \"%s\"' "${1}" +} +jsonFieldReplaceable () { + printf '\"'"$JSON_FIELDREPLACEABLE"'\": \"%s\"' "${1}" +} +jsonEthernetMac () { + printf "$JSON_ETHERNETMAC_TEMPLATE" "${1}" +} +jsonWlanMac () { + printf "$JSON_WLANMAC_TEMPLATE" "${1}" +} +jsonBluetoothMac () { + printf "$JSON_BLUETOOTHMAC_TEMPLATE" "${1}" +} +jsonPlatformModel () { + printf '\"'"$JSON_PLATFORMMODEL"'\": \"%s\"' "${1}" +} +jsonPlatformManufacturerStr () { + manufacturer=$(printf '\"'"$JSON_PLATFORMMANUFACTURERSTR"'\": \"%s\"' "${1}") + #tmpManufacturerId=$(queryForPen "${1}") + #if [ -n "$tmpManufacturerId" ] && [ "$tmpManufacturerId" != "$PEN_ROOT" ]; then + # tmpManufacturerId=$(jsonPlatformManufacturerId "$tmpManufacturerId") + # manufacturer="$manufacturer"",""$tmpManufacturerId" + #fi + printf "$manufacturer" +} +jsonPlatformVersion () { + printf '\"'"$JSON_PLATFORMVERSION"'\": \"%s\"' "${1}" +} +jsonPlatformSerial () { + printf '\"'"$JSON_PLATFORMSERIAL"'\": \"%s\"' "${1}" +} +jsonPlatformManufacturerId () { + printf '\"'"$JSON_PLATFORMMANUFACTURERID"'\": \"%s\"' "${1}" +} +queryForPen () { + pen=$(grep -B 1 "^[ ]*""${1}""$" "$ENTERPRISE_NUMBERS_FILE" | sed -n '1p' | tr -d [:space:]) + printf "%s%s" "$PEN_ROOT" "$pen" +} +jsonProperty () { + if [ -n "${1}" ] && [ -n "${2}" ]; then + if [ -n "${3}" ]; then + printf "$JSON_PROPERTY_TEMPLATE" "${1}" "${2}" "${3}" + else + printf "$JSON_PROPERTY_TEMPLATE" "${1}" "${2}" + fi + fi +} +jsonUri () { + printf '\"'"$JSON_URI"'\": \"%s\"' "${1}" +} +jsonHashAlg () { + printf '\"'"$JSON_HASHALG"'\": \"%s\"' "${1}" +} +jsonHashValue () { + printf '\"'"$JSON_HASHVALUE"'\": \"%s\"' "${1}" +} +toCSV () { + old="$IFS" + IFS=',' + value="$*" + value=$(printf "$value" | tr -s , | sed -e '1s/^[,]*//' | sed -e '$s/[,]*$//') + printf "$value" +} +jsonAddress () { + printf "$JSON_ADDRESSES_TEMPLATE" "$(toCSV "$@")" +} +jsonComponent () { + printf "$JSON_COMPONENT_TEMPLATE" "$(toCSV "$@")" +} +jsonComponentArray () { + printf "$JSON_COMPONENT_ARRAY_TEMPLATE" "$(toCSV "$@")" +} +jsonPropertyArray () { + if [ "$#" -ne 0 ]; then + printf "$JSON_PROPERTY_ARRAY_TEMPLATE" "$(toCSV "$@")" + fi +} +jsonPlatformObject () { + printf "$JSON_PLATFORM_TEMPLATE" "$(toCSV "$@")" +} +jsonComponentsUri () { + if [ -n "$COMPONENTS_URI" ]; then + componentsUri=$(jsonUri "$COMPONENTS_URI") + componentsUriDetails="" + if [ -n "$PROPERTIES_URI_LOCAL_COPY_FOR_HASH" ]; then + hashAlg="2.16.840.1.101.3.4.2.1" # SHA256, see https://tools.ietf.org/html/rfc5754 for other common hash algorithm IDs + hashValue=$(sha256sum "$COMPONENTS_URI_LOCAL_COPY_FOR_HASH" | sed -r 's/^([0-9a-f]+).*/\1/' | tr -d [:space:] | xxd -r -p | base64 -w 0) + hashAlgStr=$(jsonHashAlg "$hashAlg") + hashValueStr=$(jsonHashValue "$hashValue") + propertiesUriDetails="$hashAlgStr"",""$hashValueStr" + fi + printf "$JSON_COMPONENTSURI_TEMPLATE" "$(toCSV "$componentsUri" "$componentsUriDetails")" + fi +} +jsonPropertiesUri () { + if [ -n "$PROPERTIES_URI" ]; then + propertiesUri=$(jsonUri "$PROPERTIES_URI") + propertiesUriDetails="" + if [ -n "$PROPERTIES_URI_LOCAL_COPY_FOR_HASH" ]; then + hashAlg="2.16.840.1.101.3.4.2.1" # SHA256, see https://tools.ietf.org/html/rfc5754 for other common hash algorithm IDs + hashValue=$(sha256sum "$PROPERTIES_URI_LOCAL_COPY_FOR_HASH" | sed -r 's/^([0-9a-f]+).*/\1/' | tr -d [:space:] | xxd -r -p | base64 -w 0) + hashAlgStr=$(jsonHashAlg "$hashAlg") + hashValueStr=$(jsonHashValue "$hashValue") + propertiesUriDetails="$hashAlgStr"",""$hashValueStr" + fi| sed 's/^[ ]*//;s/[ ]*$//' + printf "$JSON_PROPERTIESURI_TEMPLATE" "$(toCSV "$propertiesUri" "$propertiesUriDetails")" + fi +} +jsonIntermediateFile () { + printf "$JSON_INTERMEDIATE_FILE_OBJECT" "$(toCSV "$@")" +} +standardizeMACAddr () { + mac=$(printf "${1}" | tr -d "[[:space:]]:-" | awk '{ print toupper($0) }') + printf "$mac" +} \ No newline at end of file diff --git a/scripts/pc_certgen.sh b/scripts/pc_certgen.sh index 78ce795..b4b94ac 100755 --- a/scripts/pc_certgen.sh +++ b/scripts/pc_certgen.sh @@ -9,14 +9,14 @@ toolpath="`dirname "$0"`" timestamp=$(date +%Y%m%d%H%M%S) #### Scripts and executable -componentlister_script="$toolpath""/allcomponents.sh" +componentlister_script="$toolpath""/componentlist.sh" policymaker_script="$toolpath""/referenceoptions.sh" get_ek_script="$toolpath""/get_ek.sh" extensions_script="$toolpath""/otherextensions.sh" signer_bin="$toolpath""/../bin/signer" validator_bin="$toolpath""/../bin/validator" #### Files -workspace=$toolpath"/pc_testgen" +workspace="$toolpath""/pc_testgen" tmpspace="/tmp" componentlist="$workspace""/localhost-componentlist.json" policyreference="$workspace""/localhost-policyreference.json" diff --git a/scripts/smbios.sh b/scripts/smbios.sh index a3e0e74..bc0e26a 100644 --- a/scripts/smbios.sh +++ b/scripts/smbios.sh @@ -45,6 +45,17 @@ dmidecodeGetByte () { index=$(printf "%d" $index) printf "${tableData[$index]}" } +dmidecodeGetByteRange () { + first="${1}" + last="${2}" + firstDec=$(printf "%d" $first) + lastDec=$(printf "%d" $last) + str="" + for ((i = firstDec ; i <= lastDec ; i++ )); do + str="$str""${tableData[$i]}" + done + printf "$str" +} dmidecodeGetString () { strref="${1}" str="" @@ -59,7 +70,239 @@ dmidecodeGetString () { printf "$str" } - +SMBIOS_TYPE_SYSTEM="1" +SMBIOS_TYPE_CHASSIS="3" +SMBIOS_TYPE_BIOS="0" +SMBIOS_TYPE_BASEBOARD="2" +SMBIOS_TYPE_PROCESSOR="4" +SMBIOS_TYPE_RAM="17" +SMBIOS_TYPE_POWERSUPPLY="39" +SMBIOS_TYPE_TPM="43" +dmidecodeGetType () { + type="${tableData[0]}" + printf "%s" "$type" +} +dmidecodeGetComponentClassValue () { + class="" + type=$(dmidecodeGetType) + typeDec=$(printf "%d" "0x""$type") # Convert to decimal + case $typeDec in + $SMBIOS_TYPE_BASEBOARD) + lsb=$(dmidecodeGetByte "0xD") # least significant byte + class=$(printf "00%s00%s" "$type" "$lsb") + ;; + $SMBIOS_TYPE_BIOS) + lsw=$(dmidecodeGetByteRange "0x12" "0x13") # least significant word + class=$(printf "00%s%s" "$type" "$lsw") + ;; + $SMBIOS_TYPE_CHASSIS) + lsb=$(dmidecodeGetByte "0x5") + class=$(printf "00%s00%s" "$type" "$lsb") + ;; + $SMBIOS_TYPE_PROCESSOR) + lsb=$(dmidecodeGetByte "0x5") + class=$(printf "00%s00%s" "$type" "$lsb") + ;; + $SMBIOS_TYPE_RAM) + lsb=$(dmidecodeGetByte "0x12") + class=$(printf "00%s00%s" "$type" "$lsb") + ;; + $SMBIOS_TYPE_SYSTEM) + class=$(printf "00%s0000" "$type") + ;; + $SMBIOS_TYPE_POWERSUPPLY) + class=$(printf "00%s0000" "$type") + ;; + $SMBIOS_TYPE_TPM) + class=$(printf "00%s0000" "$type") + ;; + esac + printf "$class" +} +dmidecodeGetManufacturer () { + manufacturer="" + type=$(dmidecodeGetType) + typeDec=$(printf "%d" "0x""$type") # Convert to decimal + case $typeDec in + $SMBIOS_TYPE_BASEBOARD) + manufacturer=$(dmidecodeGetString $(dmidecodeGetByte "0x4")) + ;; + $SMBIOS_TYPE_BIOS) + manufacturer=$(dmidecodeGetString $(dmidecodeGetByte "0x4")) + ;; + $SMBIOS_TYPE_CHASSIS) + manufacturer=$(dmidecodeGetString $(dmidecodeGetByte "0x4")) + ;; + $SMBIOS_TYPE_PROCESSOR) + manufacturer=$(dmidecodeGetString $(dmidecodeGetByte "0x7")) + ;; + $SMBIOS_TYPE_RAM) + manufacturer=$(dmidecodeGetString $(dmidecodeGetByte "0x17")) + ;; + $SMBIOS_TYPE_SYSTEM) + manufacturer=$(dmidecodeGetString $(dmidecodeGetByte "0x4")) + ;; + $SMBIOS_TYPE_POWERSUPPLY) + manufacturer=$(dmidecodeGetString $(dmidecodeGetByte "0x7")) + ;; + $SMBIOS_TYPE_TPM) + value=$(dmidecodeGetByteRange "0x4" "0x7") + manufacturer=$(printf "%s" "$value") + ;; + esac + printf "$manufacturer" +} +dmidecodeGetModel () { + model="" + type=$(dmidecodeGetType) + typeDec=$(printf "%d" "0x""$type") # Convert to decimal + case $typeDec in + $SMBIOS_TYPE_BASEBOARD) + model=$(dmidecodeGetString $(dmidecodeGetByte "0x5")) + ;; + $SMBIOS_TYPE_BIOS) + model=$(dmidecodeGetString $(dmidecodeGetByte "0x5")) + ;; + $SMBIOS_TYPE_CHASSIS) + value=$(dmidecodeGetByte "0x5") + model=$(printf "%s" "$value") + ;; + $SMBIOS_TYPE_PROCESSOR) + value=$(dmidecodeGetByte "0x6") + model=$(printf "%s" "$value") + ;; + $SMBIOS_TYPE_RAM) + model=$(dmidecodeGetString $(dmidecodeGetByte "0x1A")) + ;; + $SMBIOS_TYPE_SYSTEM) + model=$(dmidecodeGetString $(dmidecodeGetByte "0x5")) + ;; + $SMBIOS_TYPE_POWERSUPPLY) + model=$(dmidecodeGetString $(dmidecodeGetByte "0xA")) + ;; + $SMBIOS_TYPE_TPM) + value=$(dmidecodeGetByteRange "0x8" "0x9") + model=$(printf "%s" "$value") + ;; + esac + printf "$model" +} +dmidecodeGetSerialNumber() { + serialNumber="" + type=$(dmidecodeGetType) + typeDec=$(printf "%d" "0x""$type") # Convert to decimal + case $typeDec in + $SMBIOS_TYPE_BASEBOARD) + serialNumber=$(dmidecodeGetString $(dmidecodeGetByte "0x7")) + ;; + ### $SMBIOS_TYPE_BIOS + ### N/A + ### + $SMBIOS_TYPE_CHASSIS) + serialNumber=$(dmidecodeGetString $(dmidecodeGetByte "0x7")) + ;; + $SMBIOS_TYPE_PROCESSOR) + serialNumber=$(dmidecodeGetString $(dmidecodeGetByte "0x20")) + ;; + $SMBIOS_TYPE_RAM) + serialNumber=$(dmidecodeGetString $(dmidecodeGetByte "0x18")) + ;; + $SMBIOS_TYPE_SYSTEM) + serialNumber=$(dmidecodeGetString $(dmidecodeGetByte "0x7")) + ;; + $SMBIOS_TYPE_POWERSUPPLY) + serialNumber=$(dmidecodeGetString $(dmidecodeGetByte "0x8")) + ;; + ### $SMBIOS_TYPE_TPM + ### N/A + ### + esac + printf "$serialNumber" +} +dmidecodeGetRevision () { + revision="" + type=$(dmidecodeGetType) + typeDec=$(printf "%d" "0x""$type") # Convert to decimal + case $typeDec in + $SMBIOS_TYPE_BASEBOARD) + revision=$(dmidecodeGetString $(dmidecodeGetByte "0x6")) + ;; + $SMBIOS_TYPE_BIOS) + value=$(dmidecodeGetByteRange "0x14" "0x15") + revision=$(printf "%s" "$value") + ;; + $SMBIOS_TYPE_CHASSIS) + revision=$(dmidecodeGetString $(dmidecodeGetByte "0x6")) + ;; + $SMBIOS_TYPE_PROCESSOR) + revision=$(dmidecodeGetString $(dmidecodeGetByte "0x10")) + ;; + $SMBIOS_TYPE_RAM) + revision=$(dmidecodeGetString $(dmidecodeGetByte "0x2B")) + ;; + $SMBIOS_TYPE_SYSTEM) + revision=$(dmidecodeGetString $(dmidecodeGetByte "0x6")) + ;; + $SMBIOS_TYPE_POWERSUPPLY) + revision=$(dmidecodeGetString $(dmidecodeGetByte "0xB")) + ;; + $SMBIOS_TYPE_TPM) + value=$(dmidecodeGetByteRange "0xA" "0x11") + revision=$(printf "%s" "$value") + ;; + esac + printf "$revision" +} +dmidecodeGetFieldReplaceable () { + fieldReplaceable="" + type=$(dmidecodeGetType) + typeDec=$(printf "%d" "0x""$type") # Convert to decimal + case $typeDec in + $SMBIOS_TYPE_BASEBOARD) + bitField=$(dmidecodeGetByte "0x9") + bitFieldDec=$(printf "%d" "0x""$bitField") # Convert to decimal + mask="28" # 0x1C + fieldReplaceable="false" + if (((bitFieldDec&mask)!=0)); then + fieldReplaceable="true" + fi + ;; + ### $SMBIOS_TYPE_BIOS + ### N/A + ### + ### $SMBIOS_TYPE_CHASSIS + ### N/A + ### + $SMBIOS_TYPE_PROCESSOR) + bitField=$(dmidecodeGetByte "0x19") + bitFieldDec=$(printf "%d" "0x""$bitField") # Convert to decimal + mask="6" + fieldReplaceable="true" + if [ $bitFieldDec -eq $mask ]; then + fieldReplaceable="false" + fi + ;; + ### $SMBIOS_TYPE_RAM + ### N/A + ### + ### $SMBIOS_TYPE_SYSTEM + ### N/A + ### + $SMBIOS_TYPE_POWERSUPPLY) + bitField=$(dmidecodeGetByteRange "0xE" "0xF") + bitFieldDec=$(printf "%d" "0x""$bitField") # Convert to decimal + mask="256" # 0x0100 + fieldReplaceable="false" + if (((bitFieldDec&mask)!=0)); then + fieldReplaceable="true" + fi + ;; + ### $SMBIOS_TYPE_TPM + ### N/A + ### + esac + printf "$fieldReplaceable" +} # Examples: #dmidecodeHandles "1" #numHandles=$(dmidecodeNumHandles) @@ -82,3 +325,4 @@ dmidecodeGetString () { #echo $model #echo $serial #echo $revision + diff --git a/scripts/windows/SMBios.ps1 b/scripts/windows/SMBios.ps1 index 7a61ab1..575bae7 100644 --- a/scripts/windows/SMBios.ps1 +++ b/scripts/windows/SMBios.ps1 @@ -7,6 +7,7 @@ # Adapted from SysToolsLib Powershell Library released under Apache 2.0 License # https://github.com/JFLarvoire/SysToolsLib/blob/master/PowerShell/Library.ps1#Get-SMBiosStructures # +$SMBIOS_VERSION=(Get-WmiObject -Class MSSMBios_RawSMBiosTables -Namespace root\wmi -ErrorAction SilentlyContinue).SMBiosMajorVersion + ((Get-WmiObject -Class MSSMBios_RawSMBiosTables -Namespace root\wmi -ErrorAction SilentlyContinue).SMBiosMinorVersion/10) Function Get-SMBiosStructures() { $structs = @{} $data = (Get-WmiObject -Class MSSMBios_RawSMBiosTables -Namespace root\wmi -ErrorAction SilentlyContinue).SMBiosData @@ -18,6 +19,7 @@ Function Get-SMBiosStructures() { $i += $l # Count bytes from the start of the structure to the beginning of the strings section if ($data[$i] -eq 0) {$i++} # If there's no trailing string, count the extra NUL $strings=@() + $strings += "" # Index 0 of the string array should be blocked so that string references match array indicies while ($data[$i] -ne 0) { # Count the size of the string section $s = "" while ($data[$i] -ne 0) { $s += [char]$data[$i++] } # Count the byte length of each string @@ -49,12 +51,282 @@ Function Get-SMBiosString($struct, $type, $refbyte) { $strref=$struct[$type].data[$refbyte] $len=@($struct[$type].strings).Count if ($strref -le $len -and $strref -gt 0) { - $str=@($struct[$type].strings)[$struct[$type].data[$refbyte]-1] + $str=@($struct[$type].strings)[$struct[$type].data[$refbyte]] } } return $str } +$SMBIOS_TYPE_SYSTEM="1" +$SMBIOS_TYPE_CHASSIS="3" +$SMBIOS_TYPE_BIOS="0" +$SMBIOS_TYPE_BASEBOARD="2" +$SMBIOS_TYPE_PROCESSOR="4" +$SMBIOS_TYPE_RAM="17" +$SMBIOS_TYPE_POWERSUPPLY="39" +$SMBIOS_TYPE_TPM="43" + +Function GetType($struct) { + $type=$struct.data[0x0] + return $type +} +Function GetComponentClassValue($struct) { + $class="" + $type=(GetType $struct) + + switch($type) { + $SMBIOS_TYPE_BASEBOARD { + $lsb=$struct.data[0xD] # least significant byte + $class="00{0:X2}00{1:X2}" -f $type,$lsb + break; + } + $SMBIOS_TYPE_BIOS { + $lsw=$struct.data[0x12..0x13] # least significant word + $lsw=($lsw|ForEach-Object ToString X2) -join '' + $class="00{0:X2}{1}" -f $type,$lsw + break; + } + $SMBIOS_TYPE_CHASSIS { + $lsb=$struct.data[0x5] + $class="00{0:X2}00{1:X2}" -f $type,$lsb + break; + } + $SMBIOS_TYPE_PROCESSOR { + $lsb=$struct.data[0x5] + $class="00{0:X2}00{1:X2}" -f $type,$lsb + break; + } + $SMBIOS_TYPE_RAM { + $lsb=$struct.data[0x12] + $class="00{0:X2}00{1:X2}" -f $type,$lsb + break; + } + $SMBIOS_TYPE_SYSTEM { + $class="00{0:X2}0000" -f $type + break; + } + $SMBIOS_TYPE_POWERSUPPLY { + $class="00{0:X2}0000" -f $type + break; + } + $SMBIOS_TYPE_TPM { + $class="00{0:X2}0000" -f $type + break; + } + } + return $class +} +Function GetManufacturer($struct) { + $manufacturer="" + $type=(GetType $struct) + switch($type) { + $SMBIOS_TYPE_BASEBOARD { + $manufacturer=$struct.strings[$struct.data[0x4]] + break; + } + $SMBIOS_TYPE_BIOS { + $manufacturer=$struct.strings[$struct.data[0x4]] + break; + } + $SMBIOS_TYPE_CHASSIS { + $manufacturer=$struct.strings[$struct.data[0x4]] + break; + } + $SMBIOS_TYPE_PROCESSOR { + $manufacturer=$struct.strings[$struct.data[0x7]] + break; + } + $SMBIOS_TYPE_RAM { + $manufacturer=$struct.strings[$struct.data[0x17]] + break; + } + $SMBIOS_TYPE_SYSTEM { + $manufacturer=$struct.strings[$struct.data[0x4]] + break; + } + $SMBIOS_TYPE_POWERSUPPLY { + $manufacturer=$struct.strings[$struct.data[0x7]] + break; + } + $SMBIOS_TYPE_TPM { + $value=$struct.data[0x4..0x7] + $manufacturer=($value|ForEach-Object ToString X2) -join '' + break; + } + } + return $manufacturer +} +Function GetModel($struct) { + $model="" + $type=(GetType $struct) + switch($type) { + $SMBIOS_TYPE_BASEBOARD { + $model=$struct.strings[$struct.data[0x5]] + break; + } + $SMBIOS_TYPE_BIOS { + $model=$struct.strings[$struct.data[0x5]] + break; + } + $SMBIOS_TYPE_CHASSIS { + $value=$struct.data[0x5] + $model=($value|ForEach-Object ToString X2) -join '' + break; + } + $SMBIOS_TYPE_PROCESSOR { + $value=$struct.data[0x6] + $model=($value|ForEach-Object ToString X2) -join '' + break; + } + $SMBIOS_TYPE_RAM { + $model=$struct.strings[$struct.data[0x1A]] + break; + } + $SMBIOS_TYPE_SYSTEM { + $model=$struct.strings[$struct.data[0x5]] + break; + } + $SMBIOS_TYPE_POWERSUPPLY { + $model=$struct.strings[$struct.data[0xA]] + break; + } + $SMBIOS_TYPE_TPM { + $value=$struct.data[0x8..0x9] + $model=($value|ForEach-Object ToString X2) -join '' + break; + } + } + return $model +} +Function GetSerialNumber($struct) { + $serialNumber="" + $type=(GetType $struct) + switch($type) { + $SMBIOS_TYPE_BASEBOARD { + $serialNumber=$struct.strings[$struct.data[0x7]] + break; + } + ### $SMBIOS_TYPE_BIOS + ### N/A + ### + $SMBIOS_TYPE_CHASSIS { + $serialNumber=$struct.strings[$struct.data[0x7]] + break; + } + $SMBIOS_TYPE_PROCESSOR { + $serialNumber=$struct.strings[$struct.data[0x20]] + break; + } + $SMBIOS_TYPE_RAM { + $serialNumber=$struct.strings[$struct.data[0x18]] + break; + } + $SMBIOS_TYPE_SYSTEM { + $serialNumber=$struct.strings[$struct.data[0x7]] + break; + } + $SMBIOS_TYPE_POWERSUPPLY { + $serialNumber=$struct.strings[$struct.data[0x8]] + break; + } + ### $SMBIOS_TYPE_TPM { + ### N/A + ### + } + return $serialNumber +} +Function GetRevision($struct) { + $revision="" + $type=(GetType $struct) + switch($type) { + $SMBIOS_TYPE_BASEBOARD { + $revision=$struct.strings[$struct.data[0x6]] + break; + } + $SMBIOS_TYPE_BIOS { + $value=$struct.data[0x14..0x15] + $revision=($value|ForEach-Object ToString X2) -join '' + break; + } + $SMBIOS_TYPE_CHASSIS { + $revision=$struct.strings[$struct.data[0x6]] + break; + } + $SMBIOS_TYPE_PROCESSOR { + $revision=$struct.strings[$struct.data[0x10]] + break; + } + $SMBIOS_TYPE_RAM { + if ($SMBIOS_VERSION -ge 3.2) { + $revision=$struct.strings[$struct.data[0x2B]] + } + break; + } + $SMBIOS_TYPE_SYSTEM { + $revision=$struct.strings[$struct.data[0x6]] + break; + } + $SMBIOS_TYPE_POWERSUPPLY { + $revision=$struct.strings[$struct.data[0xB]] + break; + } + $SMBIOS_TYPE_TPM { + $value=$struct.data[0xA..0x11] + $revision=($value|ForEach-Object ToString X2) -join '' + break; + } + } + return $revision +} +Function GetFieldReplaceable($struct) { + $fieldReplaceable="" + $type=(GetType $struct) + switch($type) { + $SMBIOS_TYPE_BASEBOARD { + $bitField=$struct.data[0x9] + $mask=0x1C + $fieldReplaceable="false" + if (($bitField -band $mask) -ne 0) { + $fieldReplaceable="true" + } + break; + } + ### $SMBIOS_TYPE_BIOS + ### N/A + ### + ### $SMBIOS_TYPE_CHASSIS + ### N/A + ### + $SMBIOS_TYPE_PROCESSOR { + $bitField=$struct.data[0x19] + $mask=0x6 + $fieldReplaceable="true" + if ($bitField -eq $mask) { + $fieldReplaceable="false" + } + break; + } + ### $SMBIOS_TYPE_RAM + ### N/A + ### + ### $SMBIOS_TYPE_SYSTEM + ### N/A + ### + $SMBIOS_TYPE_POWERSUPPLY { + $bitField=$struct.data[0xE] + $mask=0x01 + $fieldReplaceable="false" + if (($bitField -band $mask) -ne 0) { + $fieldReplaceable="true" + } + break; + } + ### $SMBIOS_TYPE_TPM { + ### N/A + ### + } + return $fieldReplaceable +} # Example: # $smbios=(Get-SMBiosStructures) # echo $smbios["3"] @@ -69,3 +341,22 @@ Function Get-SMBiosString($struct, $type, $refbyte) { # echo $platformModel # echo $platformVersion # echo $platformSerial +# $testType=$SMBIOS_TYPE_CHASSIS +# echo (($smbios[$testType].data|ForEach-Object ToString X2) -join ' ') +# echo $smbios[$testType].strings +# $type=(GetType $smbios[$testType][0]) +# echo "a$type" +# $class=(GetComponentClassValue $smbios[$testType][0]) +# echo "b$class" +# $manufacturer=(GetManufacturer $smbios[$testType][0]) +# echo "c$manufacturer" +# $model=(GetModel $smbios[$testType][0]) +# echo "d$model" +# $serialNumber=(GetSerialNumber $smbios[$testType][0]) +# echo "e$serialNumber" +# $revision=(GetRevision $smbios[$testType][0]) +# echo "f$revision" +# $fieldReplaceable=(GetFieldReplaceable $smbios[$testType][0]) +# echo "g$fieldReplaceable" + + diff --git a/scripts/windows/allcomponents.ps1 b/scripts/windows/allcomponents.ps1 index ab0c3b7..1129b27 100644 --- a/scripts/windows/allcomponents.ps1 +++ b/scripts/windows/allcomponents.ps1 @@ -8,315 +8,122 @@ param( $APP_HOME=(Split-Path -parent $PSCommandPath) $PROPERTIES_URI="" # Specify the optional properties URI field $PROPERTIES_URI_LOCAL_COPY_FOR_HASH="" # If empty, the optional hashAlgorithm and hashValue fields will not be included for the URI -$ENTERPRISE_NUMBERS_FILE="$APP_HOME/../enterprise-numbers" -$PEN_ROOT="1.3.6.1.4.1." # OID root for the private enterprise numbers -$SMBIOS_SCRIPT="$APP_HOME/SMBios.ps1" -$HW_SCRIPT="$APP_HOME/hw.ps1" # For components not covered by SMBIOS +$JSON_SCRIPT="$APP_HOME/json.ps1" # Defines JSON structure and provides methods for producing relevant JSON +$SMBIOS_SCRIPT="$APP_HOME/SMBios.ps1" # Handles parsing of SMBIOS data +$HW_SCRIPT="$APP_HOME/hw.ps1" # Handles parsing of WMI and CIM + +### JSON +. $JSON_SCRIPT ### Load Raw SMBios Data -. $SMBIOS_SCRIPT +. $SMBIOS_SCRIPT # See the TCG SMBIOS Component Class Registry specification. $smbios=(Get-SMBiosStructures) -$SMBIOS_TYPE_PLATFORM="1" -$SMBIOS_TYPE_CHASSIS="3" -$SMBIOS_TYPE_BIOS="0" -$SMBIOS_TYPE_BASEBOARD="2" -$SMBIOS_TYPE_CPU="4" -$SMBIOS_TYPE_RAM="17" +$COMPCLASS_REGISTRY_SMBIOS="2.23.133.18.3.3" # See the TCG OID Registry. ### hw . $HW_SCRIPT ### ComponentClass values -$COMPCLASS_REGISTRY_TCG="2.23.133.18.3.1" # switch off values within SMBIOS to reveal accurate component classes -$COMPCLASS_BASEBOARD="00030003" # these values are meant to be an example. check the component class registry. +$COMPCLASS_REGISTRY_TCG="2.23.133.18.3.1" +$COMPCLASS_BASEBOARD="00030003" # these values are meant to be an example. check the TCG component class registry. $COMPCLASS_BIOS="00130003" $COMPCLASS_UEFI="00130002" -$COMPCLASS_CHASSIS="00020001" # TODO: chassis type is included in SMBIOS +$COMPCLASS_CHASSIS="00020001" $COMPCLASS_CPU="00010002" $COMPCLASS_HDD="00070002" $COMPCLASS_NIC="00090002" -$COMPCLASS_RAM="00060001" # TODO: memory type is included in SMBIOS +$COMPCLASS_RAM="00060001" $COMPCLASS_GFX="00050002" # Progress Group IDs: # 1: Overall progress # 2: Component type -# 3: Function progress per component Write-Progress -Id 1 -Activity "Setting up to gather component details" -PercentComplete 0 -### JSON Structure Keywords -$JSON_COMPONENTS="COMPONENTS" -$JSON_PROPERTIES="PROPERTIES" -$JSON_PROPERTIESURI="PROPERTIESURI" -$JSON_PLATFORM="PLATFORM" -#### JSON Component Keywords -$JSON_COMPONENTCLASS="COMPONENTCLASS" -$JSON_COMPONENTCLASSREGISTRY="COMPONENTCLASSREGISTRY" -$JSON_COMPONENTCLASSVALUE="COMPONENTCLASSVALUE" -$JSON_MANUFACTURER="MANUFACTURER" -$JSON_MODEL="MODEL" -$JSON_SERIAL="SERIAL" -$JSON_REVISION="REVISION" -$JSON_MANUFACTURERID="MANUFACTURERID" -$JSON_FIELDREPLACEABLE="FIELDREPLACEABLE" -$JSON_ADDRESSES="ADDRESSES" -$JSON_ETHERNETMAC="ETHERNETMAC" -$JSON_WLANMAC="WLANMAC" -$JSON_BLUETOOTHMAC="BLUETOOTHMAC" -$JSON_COMPONENTPLATFORMCERT="PLATFORMCERT" -$JSON_ATTRIBUTECERTIDENTIFIER="ATTRIBUTECERTIDENTIFIER" -$JSON_GENERICCERTIDENTIFIER="GENERICCERTIDENTIFIER" -$JSON_ISSUER="ISSUER" -$JSON_COMPONENTPLATFORMCERTURI="PLATFORMCERTURI" -$JSON_STATUS="STATUS" -#### JSON Platform Keywords (Subject Alternative Name) -$JSON_PLATFORMMODEL="PLATFORMMODEL" -$JSON_PLATFORMMANUFACTURERSTR="PLATFORMMANUFACTURERSTR" -$JSON_PLATFORMVERSION="PLATFORMVERSION" -$JSON_PLATFORMSERIAL="PLATFORMSERIAL" -$JSON_PLATFORMMANUFACTURERID="PLATFORMMANUFACTURERID" -#### JSON Platform URI Keywords -$JSON_URI="UNIFORMRESOURCEIDENTIFIER" -$JSON_HASHALG="HASHALGORITHM" -$JSON_HASHVALUE="HASHVALUE" -#### JSON Properties Keywords -$JSON_NAME="NAME" -$JSON_VALUE="VALUE" -$NOT_SPECIFIED="Not Specified" - - -### JSON Structure Format -$JSON_INTERMEDIATE_FILE_OBJECT="{{ - {0} -}}" -$JSON_PLATFORM_TEMPLATE=" - `"$JSON_PLATFORM`": {{ - {0} - }}" -$JSON_PROPERTIESURI_TEMPLATE=" - `"$JSON_PROPERTIESURI`": {{ - {0} - }}" -$JSON_COMPONENTSURI_TEMPLATE=" - `"$JSON_COMPONENTSURI`": {{ - {0} - }}" -$JSON_PROPERTY_ARRAY_TEMPLATE=" - `"$JSON_PROPERTIES`": [{0} - ]" -$JSON_COMPONENT_ARRAY_TEMPLATE=" - `"$JSON_COMPONENTS`": [{0} - ]" -$JSON_COMPONENT_TEMPLATE=" - {{ - {0} - }}" -$JSON_PROPERTY_TEMPLATE=" - {{ - `"$JSON_NAME`": `"{0}`", - `"$JSON_VALUE`": `"{1}`" - }} -" -$JSON_ADDRESSES_TEMPLATE=" `"$JSON_ADDRESSES`": [{0}]" -$JSON_ETHERNETMAC_TEMPLATE=" {{ - `"$JSON_ETHERNETMAC`": `"{0}`" }} " -$JSON_WLANMAC_TEMPLATE=" {{ - `"$JSON_WLANMAC`": `"{0}`" }} " -$JSON_BLUETOOTHMAC_TEMPLATE=" {{ - `"$JSON_BLUETOOTHMAC`": `"{0}`" }} " -$JSON_COMPONENTCLASS_TEMPLATE=" `"$JSON_COMPONENTCLASS`": {{ - `"$JSON_COMPONENTCLASSREGISTRY`": `"{0}`", - `"$JSON_COMPONENTCLASSVALUE`": `"{1}`" - }}" -$JSON_ATTRIBUTECERTIDENTIFIER_TEMPLATE=" `"$JSON_ATTRIBUTECERTIDENTIFIER`": {{ - `"$JSON_HASHALG`": `"{0}`", - `"$JSON_HASHVALUE`": `"{1}`" - }}," -$JSON_GENERICCERTIDENTIFIER_TEMPLATE=" `"$JSON_GENERICCERTIDENTIFIER`": {{ - `"$JSON_ISSUER`": `"{0}`", - `"$JSON_SERIAL`": `"{1}`" - }}," -$JSON_COMPONENTPLATFORMCERT_TEMPLATE=" - `"$JSON_COMPONENTPLATFORMCERT`": {{ - {0} - }}" -$JSON_COMPONENTPLATFORMCERTURI_TEMPLATE=' - `"$JSON_COMPONENTPLATFORMCERTURI`": {{ - {0} - }}' -$JSON_STATUS_TEMPLATE=" - `"$JSON_STATUS`": {{ - - }}" - -### JSON Constructor Aides -function HexToByteArray { # Powershell doesn't have a built in BinToHex function - Param ([String] $str ) - - if ($str.Length % 2 -ne 0) { - $str="0$str" +### Gather platform details for the subject alternative name +### Platform attributes in the SAN only need to be consistent between base and delta platform certificates +function gatherSmbiosSystemForSubjectAlternativeName() { + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering platform information" -CurrentOperation "Querying" -PercentComplete 0 + ### Gather platform details for the subject alternative name + $platformManufacturer=(Get-SMBiosString $smbios "$SMBIOS_TYPE_SYSTEM" 0x4) + $platformModel=(Get-SMBiosString $smbios "$SMBIOS_TYPE_SYSTEM" 0x5) + $platformVersion=(Get-SMBiosString $smbios "$SMBIOS_TYPE_SYSTEM" 0x6) + $platformSerial=(Get-SMBiosString $smbios "$SMBIOS_TYPE_SYSTEM" 0x7) + + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering platform information" -CurrentOperation "Cleaning output" -PercentComplete 40 + if ([string]::IsNullOrEmpty($platformManufacturer) -or ($platformManufacturer.Trim().Length -eq 0)) { + $platformManufacturer="$NOT_SPECIFIED" } + $platformManufacturer=$(jsonPlatformManufacturerStr "$platformManufacturer".Trim()) - if ($str.Length -ne 0) { - ,@($str -split '([a-f0-9]{2})' | foreach-object { - if ($_) { - [System.Convert]::ToByte($_,16) - } - }) - } -} -function jsonComponentClass () { - echo ("$JSON_COMPONENTCLASS_TEMPLATE" -f "$($args[0])","$($args[1])") -} -function jsonManufacturer () { - $manufacturer=("`"$JSON_MANUFACTURER`": `"{0}`"" -f "$($args[0])") - #$tmpManufacturerId=(queryForPen "$($args[0])") - #if (($tmpManufacturerId) -and ("$tmpManufacturerId" -ne "$PEN_ROOT")) { - # $tmpManufacturerId=(jsonManufacturerId "$tmpManufacturerId") - # $manufacturer="$manufacturer,$tmpManufacturerId" - #} - echo "$manufacturer" -} -function jsonModel () { - echo ("`"$JSON_MODEL`": `"{0}`"" -f "$($args[0])") -} -function jsonSerial () { - echo ("`"$JSON_SERIAL`": `"{0}`"" -f "$($args[0])") -} -function jsonRevision () { - echo ("`"$JSON_REVISION`": `"{0}`"" -f "$($args[0])") -} -function jsonManufacturerId () { - echo ("`"$JSON_MANUFACTURERID`": `"{0}`"" -f "$($args[0])") -} -function jsonFieldReplaceable () { - echo ("`"$JSON_FIELDREPLACEABLE`": `"{0}`"" -f "$($args[0])") -} -function jsonEthernetMac () { - echo ("$JSON_ETHERNETMAC_TEMPLATE" -f "$($args[0])") -} -function jsonWlanMac () { - echo ("$JSON_WLANMAC_TEMPLATE" -f "$($args[0])") -} -function jsonBluetoothMac () { - echo ("$JSON_BLUETOOTHMAC_TEMPLATE" -f "$($args[0])") -} -function jsonPlatformModel () { - echo ("`"$JSON_PLATFORMMODEL`": `"{0}`"" -f "$($args[0])") -} -function jsonPlatformManufacturerStr () { - $manufacturer=("`"$JSON_PLATFORMMANUFACTURERSTR`": `"{0}`"" -f "$($args[0])") - #$tmpManufacturerId=(queryForPen "$($args[0])") - #if (($tmpManufacturerId) -and ("$tmpManufacturerId" -ne "$PEN_ROOT")) { - # $tmpManufacturerId=(jsonPlatformManufacturerId "$tmpManufacturerId") - # $manufacturer="$manufacturer,$tmpManufacturerId" - #} - echo "$manufacturer" -} -function jsonPlatformVersion () { - echo ("`"$JSON_PLATFORMVERSION`": `"{0}`"" -f "$($args[0])") -} -function jsonPlatformSerial () { - echo ("`"$JSON_PLATFORMSERIAL`": `"{0}`"" -f "$($args[0])") -} -function jsonPlatformManufacturerId () { - echo ("`"$JSON_PLATFORMMANUFACTURERID`": `"{0}`"" -f "$($args[0])") -} -function queryForPen () { - Write-Progress -Id 3 -ParentId 2 -Activity "Searching for PEN..." - $result=$PEN_ROOT - if($args[0]) { - $penObject=(Get-Content "$ENTERPRISE_NUMBERS_FILE" | Select-String -Pattern "^[ \t]*$($args[0])`$" -Context 1) - if ($penObject) { - Write-Progress -Id 3 -ParentId 2 -Activity "Searching for PEN..." -CurrentOperation "Found" - $pen=$penObject.Context.PreContext[0] - $result+="$pen" - } - } - Write-Progress -Id 3 -ParentId 2 -Activity "Searching for PEN..." -PercentComplete 100 - echo $result -} -function jsonProperty () { - if ($args.Length -eq 2) { - echo ("$JSON_PROPERTY_TEMPLATE" -f "$($args[0])","$($args[1])") + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering platform information" -CurrentOperation "Cleaning output" -PercentComplete 55 + if ([string]::IsNullOrEmpty($platformModel) -or ($platformModel.Trim().Length -eq 0)) { + $platformModel="$NOT_SPECIFIED" } -} -function jsonUri () { - echo ("`"$JSON_URI`": `"{0}`"" -f "$($args[0])") -} -function jsonHashAlg () { - echo ("`"$JSON_HASHALG`": `"{0}`"" -f "$($args[0])") -} -function jsonHashValue () { - echo ("`"$JSON_HASHVALUE`": `"{0}`"" -f "$($args[0])") -} -function toCSV () { - if ($args.Length -ne 0) { - Write-Progress -Id 3 -ParentId 2 -Activity "CSV..." -PercentComplete 0 + $platformModel=$(jsonPlatformModel "$platformModel".Trim()) - $size = $args[0].Length - for ($i=0; $i -lt $size; $i++) { - Write-Progress -Id 3 -ParentId 2 -Activity "CSV..." -PercentComplete (($i / $size) * 100) + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering platform information" -CurrentOperation "Cleaning output" -PercentComplete 70 + if ([string]::IsNullOrEmpty($platformVersion) -or ($platformVersion.Trim().Length -eq 0)) { + $platformVersion="$NOT_SPECIFIED" + } + $platformVersion=(jsonPlatformVersion "$platformVersion".Trim()) - $item=($args[0].Get($i)) + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering platform information" -CurrentOperation "Cleaning output" -PercentComplete 85 + if (![string]::IsNullOrEmpty($platformSerial) -and ($platformSerial.Trim().Length -ne 0)) { + $platformSerial=(jsonPlatformSerial "$platformSerial".Trim()) + } + $platform=(jsonPlatformObject "$platformManufacturer" "$platformModel" "$platformVersion" "$platformSerial") + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering platform information" -CurrentOperation "Done" -PercentComplete 100 + return $platform.Trim(",") +} + +### Gather data from SMBIOS +function gatherSmbiosData() { + $components="" + $types=@($SMBIOS_TYPE_BASEBOARD,$SMBIOS_TYPE_BIOS,$SMBIOS_TYPE_CHASSIS,$SMBIOS_TYPE_PROCESSOR,$SMBIOS_TYPE_RAM,$SMBIOS_TYPE_SYSTEM,$SMBIOS_TYPE_POWERSUPPLY,$SMBIOS_TYPE_TPM) + + foreach ($type in $types) { + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering information about SMBIOS type $type" -CurrentOperation "Gathering" -PercentComplete 0 + $RS=$smbios[$type] + $numRows=$RS.Count + + for($i=0;$i -lt $numRows;$i++) { + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering information about SMBIOS type $type" -CurrentOperation "Working on element ($i+1) of $numRows" -PercentComplete ((($i+1)/$numRows)*100) + $component="" + $struct=$RS[$i] + + $componentClassValue=(GetComponentClassValue $struct) + $manufacturer=(GetManufacturer $struct) + $model=(GetModel $struct) + $serialNumber=(GetSerialNumber $struct) + $revision=(GetRevision $struct) + $fieldReplaceable=(GetFieldReplaceable $struct) + + # Do not include empty slots + if ([string]::IsNullOrEmpty($manufacturer) -and [string]::IsNullOrEmpty($model) -and [string]::IsNullOrEmpty($serialNumber) -and [string]::IsNullOrEmpty($revision)) { + continue + } - if ($item) { - $value="$value,$($args[0].Get($i))" + $componentClass=(jsonComponentClass "$COMPCLASS_REGISTRY_SMBIOS" "$componentClassValue") + $manufacturer=(jsonManufacturer "$manufacturer") + $model=(jsonModel "$model") + if (![string]::IsNullOrEmpty($serialNumber)) { + $serialNumber=(jsonSerial "$serialNumber") } - } - echo "$value".Trim(" ", ",") - Write-Progress -Id 3 -ParentId 2 -Activity "CSV..." -PercentComplete 100 - } -} -function jsonAddress () { - echo ("$JSON_ADDRESSES_TEMPLATE" -f "$(toCSV($args))") -} -function jsonComponent () { - echo ("$JSON_COMPONENT_TEMPLATE" -f "$(toCSV($args))") -} -function jsonComponentArray () { - echo ("$JSON_COMPONENT_ARRAY_TEMPLATE" -f "$(toCSV($args))") -} -function jsonPropertyArray () { - echo ("$JSON_PROPERTY_ARRAY_TEMPLATE" -f "$(toCSV($args))") -} -function jsonPlatformObject () { - echo ("$JSON_PLATFORM_TEMPLATE" -f "$(toCSV($args))") -} -function jsonComponentsUri () { - if ($COMPONENTS_URI) { - $componentsUri=(jsonUri "$COMPONENTS_URI") - $componentsUriDetails="" - if ($COMPONENTS_URI_LOCAL_COPY_FOR_HASH) { - $hashAlg="2.16.840.1.101.3.4.2.1" # SHA256, see https://tools.ietf.org/html/rfc5754 for other common hash algorithm IDs - $hashValue=([System.Convert]::ToBase64String($(HexToByteArray $(Get-FileHash "$COMPONENTS_URI_LOCAL_COPY_FOR_HASH" -Algorithm SHA256).Hash.Trim()))) - $hashAlgStr=(jsonHashAlg "$hashAlg") - $hashValueStr=(jsonHashValue "$hashValue") - $componentsUriDetails="$hashAlgStr"",""$hashValueStr" - } - echo ("$JSON_COMPONENTSURI_TEMPLATE" -f "$(toCSV("$componentsUri","$componentsUriDetails"))") - } -} -function jsonPropertiesUri () { - if ($PROPERTIES_URI) { - $propertiesUri=(jsonUri "$PROPERTIES_URI") - $propertiesUriDetails="" - if ($PROPERTIES_URI_LOCAL_COPY_FOR_HASH) { - $hashAlg="2.16.840.1.101.3.4.2.1" # SHA256, see https://tools.ietf.org/html/rfc5754 for other common hash algorithm IDs - $hashValue=([System.Convert]::ToBase64String($(HexToByteArray $(Get-FileHash "$PROPERTIES_URI_LOCAL_COPY_FOR_HASH" -Algorithm SHA256).Hash.Trim()))) - $hashAlgStr=(jsonHashAlg "$hashAlg") - $hashValueStr=(jsonHashValue "$hashValue") - $propertiesUriDetails="$hashAlgStr,$hashValueStr" - } - echo ("$JSON_PROPERTIESURI_TEMPLATE" -f "$(toCSV("$propertiesUri","$propertiesUriDetails"))") - } -} -function jsonIntermediateFile () { - echo ("$JSON_INTERMEDIATE_FILE_OBJECT" -f "$(toCSV($args))") + if (![string]::IsNullOrEmpty($revision)) { + $revision=(jsonRevision "$revision") + } + if (![string]::IsNullOrEmpty($fieldReplaceable)) { + $fieldReplaceable=(jsonFieldReplaceable "$fieldReplaceable") + } + $component=(jsonComponent "$componentClass" "$manufacturer" "$model" "$serialNumber" "$revision" "$fieldReplaceable") + $components+="$component," + } # for numRows (for each handle) + } # foreach type + Write-Progress -Id 2 -ParentId 1 -Activity "Complete" -CurrentOperation "Complete" -PercentComplete 100 + return "$components".Trim(",") } -Write-Progress -Id 1 -Activity "Gathering component details" -PercentComplete 10 - Write-Progress -Id 2 -ParentId 1 -Activity "Gathering platform information" -CurrentOperation "Querying" -PercentComplete 0 ### Gather platform details for the subject alternative name $platformManufacturer=(Get-SMBiosString $smbios "$SMBIOS_TYPE_PLATFORM" 0x4) @@ -350,8 +157,6 @@ $platform=(jsonPlatformObject "$platformManufacturer" "$platformModel" "$platfor Write-Progress -Id 2 -ParentId 1 -Activity "Gathering platform information" -CurrentOperation "Done" -PercentComplete 100 ### Gather component details -Write-Progress -Id 1 -Activity "Gathering component details" -PercentComplete 20 - Write-Progress -Id 2 -ParentId 1 -Activity "Gathering chassis information" -CurrentOperation "Querying" -PercentComplete 0 $chassisClass=(jsonComponentClass "$COMPCLASS_REGISTRY_TCG" "$COMPCLASS_CHASSIS") $chassisManufacturer=(Get-SMBiosString $smbios "$SMBIOS_TYPE_CHASSIS" 0x4) @@ -384,15 +189,16 @@ $componentChassis=(jsonComponent "$chassisClass" "$chassisManufacturer" "$chassi Write-Progress -Id 2 -ParentId 1 -Activity "Gathering chassis information" -CurrentOperation "Done" -PercentComplete 100 ### Gather baseboard details -Write-Progress -Id 1 -Activity "Gathering component details" -PercentComplete 30 - Write-Progress -Id 2 -ParentId 1 -Activity "Gathering baseboard information" -CurrentOperation "Querying" -PercentComplete 0 $baseboardClass=(jsonComponentClass "$COMPCLASS_REGISTRY_TCG" "$COMPCLASS_BASEBOARD") $baseboardManufacturer=(Get-SMBiosString $smbios "$SMBIOS_TYPE_BASEBOARD" 0x4) $baseboardModel=(Get-SMBiosString $smbios "$SMBIOS_TYPE_BASEBOARD" 0x5) $baseboardSerial=(Get-SMBiosString $smbios "$SMBIOS_TYPE_BASEBOARD" 0x7) $baseboardRevision=(Get-SMBiosString $smbios "$SMBIOS_TYPE_BASEBOARD" 0x6) -$baseboardFeatureFlags=$smbios["$SMBIOS_TYPE_BASEBOARD"].data[0x9] +$baseboardFeatureFlags=0 +if ($smbios["$SMBIOS_TYPE_BASEBOARD"]) { + $baseboardFeatureFlags=$smbios["$SMBIOS_TYPE_BASEBOARD"].data[0x9] +} $baseboardReplaceableIndicator=0x1C # from Table 14 Write-Progress -Id 2 -ParentId 1 -Activity "Gathering baseboard information" -CurrentOperation "Cleaning output" -PercentComplete 40 @@ -428,8 +234,6 @@ $componentBaseboard=(jsonComponent "$baseboardClass" "$baseboardManufacturer" "$ Write-Progress -Id 2 -ParentId 1 -Activity "Gathering baseboard information" -CurrentOperation "Done" -PercentComplete 100 ### Gather BIOS details -Write-Progress -Id 1 -Activity "Gathering component details" -PercentComplete 30 - Write-Progress -Id 2 -ParentId 1 -Activity "Gathering BIOS information" -CurrentOperation "Querying" -PercentComplete 0 $biosClass=(jsonComponentClass "$COMPCLASS_REGISTRY_TCG" "$COMPCLASS_BIOS") $biosManufacturer=(Get-SMBiosString $smbios "$SMBIOS_TYPE_BIOS" 0x4) @@ -463,8 +267,6 @@ $componentBios=(jsonComponent "$biosClass" "$biosManufacturer" "$biosModel" "$bi Write-Progress -Id 2 -ParentId 1 -Activity "Gathering baseboard information" -CurrentOperation "Done" -PercentComplete 100 ### Gather CPU details -Write-Progress -Id 1 -Activity "Gathering component details" -PercentComplete 40 - Write-Progress -Id 2 -ParentId 1 -Activity "Gathering CPU information" -CurrentOperation "Querying" -PercentComplete 0 function parseCpuData() { $RS=@($smbios["$SMBIOS_TYPE_CPU"]) @@ -475,52 +277,52 @@ function parseCpuData() { for($i=0;$i -lt $numRows;$i++) { Write-Progress -Id 2 -ParentId 1 -Activity "Gathering CPU information" -CurrentOperation ("Cleaning output for CPU " + ($i+1)) -PercentComplete ((($i+1) / $numRows) * 100) - $cpuClass=(jsonComponentClass "$COMPCLASS_REGISTRY_TCG" "$COMPCLASS_CPU") - $tmpManufacturer=(Get-SMBiosString $RS $i 0x7) - $tmpModel=[string]($RS[$i].data[0x6]) # Enum value for Family - $tmpSerial=(Get-SMBiosString $RS $i 0x20) - $tmpRevision=(Get-SMBiosString $RS $i 0x10) - $tmpUpgradeMethod=$RS[$i].data[0x19] # Enum for Processor Upgrade + if ($RS[$i]) { + $cpuClass=(jsonComponentClass "$COMPCLASS_REGISTRY_TCG" "$COMPCLASS_CPU") + $tmpManufacturer=(Get-SMBiosString $RS $i 0x7) + $tmpModel=[string]($RS[$i].data[0x6]) # Enum value for Family + $tmpSerial=(Get-SMBiosString $RS $i 0x20) + $tmpRevision=(Get-SMBiosString $RS $i 0x10) + $tmpUpgradeMethod=$RS[$i].data[0x19] # Enum for Processor Upgrade - if ([string]::IsNullOrEmpty($tmpManufacturer) -or ($tmpManufacturer.Trim().Length -eq 0)) { - $tmpManufacturer="$NOT_SPECIFIED" - } - $tmpManufacturer=$(jsonManufacturer "$tmpManufacturer".Trim()) + if ([string]::IsNullOrEmpty($tmpManufacturer) -or ($tmpManufacturer.Trim().Length -eq 0)) { + $tmpManufacturer="$NOT_SPECIFIED" + } + $tmpManufacturer=$(jsonManufacturer "$tmpManufacturer".Trim()) - if ([string]::IsNullOrEmpty($tmpModel) -or ($tmpModel.Trim().Length -eq 0)) { - $tmpModel="$NOT_SPECIFIED" - } - $tmpModel=$(jsonModel "$tmpModel".Trim()) + if ([string]::IsNullOrEmpty($tmpModel) -or ($tmpModel.Trim().Length -eq 0)) { + $tmpModel="$NOT_SPECIFIED" + } + $tmpModel=$(jsonModel "$tmpModel".Trim()) - if (![string]::IsNullOrEmpty($tmpSerial) -and ($tmpSerial.Trim().Length -ne 0)) { - $tmpSerial=(jsonSerial "$tmpSerial".Trim()) - } else { - $tmpSerial="" - } + if (![string]::IsNullOrEmpty($tmpSerial) -and ($tmpSerial.Trim().Length -ne 0)) { + $tmpSerial=(jsonSerial "$tmpSerial".Trim()) + } else { + $tmpSerial="" + } - if (![string]::IsNullOrEmpty($tmpRevision) -and ($tmpRevision.Trim().Length -ne 0)) { - $tmpRevision=(jsonRevision "$tmpRevision".Trim()) - } else { - $tmpRevision="" - } + if (![string]::IsNullOrEmpty($tmpRevision) -and ($tmpRevision.Trim().Length -ne 0)) { + $tmpRevision=(jsonRevision "$tmpRevision".Trim()) + } else { + $tmpRevision="" + } - if ("$tmpUpgradeMethod" -eq "$processorNotUpgradableIndicator") { - $tmpUpgradeMethod="false" - } else { - $tmpUpgradeMethod="true" - } - $replaceable=(jsonFieldReplaceable "$tmpUpgradeMethod") + if ("$tmpUpgradeMethod" -eq "$processorNotUpgradableIndicator") { + $tmpUpgradeMethod="false" + } else { + $tmpUpgradeMethod="true" + } + $replaceable=(jsonFieldReplaceable "$tmpUpgradeMethod") - $tmpComponent=(jsonComponent $cpuClass $tmpManufacturer $tmpModel $replaceable $tmpSerial $tmpRevision) - $component+="$tmpComponent," + $tmpComponent=(jsonComponent $cpuClass $tmpManufacturer $tmpModel $replaceable $tmpSerial $tmpRevision) + $component+="$tmpComponent," + } } Write-Progress -Id 2 -ParentId 1 -Activity "Gathering CPU information" -CurrentOperation "Done" -PercentComplete 100 return "$component".Trim(",") } ### Gather RAM details -Write-Progress -Id 1 -Activity "Gathering component details" -PercentComplete 50 - Write-Progress -Id 2 -ParentId 1 -Activity "Gathering RAM information" -CurrentOperation "Querying" -PercentComplete 0 function parseRamData() { $RS=@($smbios["$SMBIOS_TYPE_RAM"]) @@ -571,10 +373,8 @@ function parseRamData() { } ### Gather NIC details -Write-Progress -Id 1 -Activity "Gathering component details" -PercentComplete 60 - -Write-Progress -Id 2 -ParentId 1 -Activity "Gathering NIC information" -CurrentOperation "Querying CIM" -PercentComplete 0 function parseNicData() { + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering NIC information" -CurrentOperation "Querying CIM" -PercentComplete 0 $RS=@(Get-NetAdapter | select MacAddress,PhysicalMediaType,PNPDeviceID | where {($_.PhysicalMediaType -eq "Native 802.11" -or "802.3") -and ($_.PNPDeviceID -Match "^(PCI)\\.*$")}) $component="" $replaceable=(jsonFieldReplaceable "true") @@ -651,10 +451,8 @@ function parseNicData() { } ### Gather HDD details -Write-Progress -Id 1 -Activity "Gathering component details" -PercentComplete 70 - -Write-Progress -Id 2 -ParentId 1 -Activity "Gathering HDD information" -CurrentOperation "Querying" -PercentComplete 0 function parseHddData() { + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering HDD information" -CurrentOperation "Querying" -PercentComplete 0 $RS=(Get-CimInstance -ClassName CIM_DiskDrive | select serialnumber,mediatype,pnpdeviceid,manufacturer,model | where mediatype -eq "Fixed hard disk media") $component="" $replaceable=(jsonFieldReplaceable "true") @@ -677,7 +475,7 @@ function parseHddData() { } if(($pnpDevID -eq $null) -or (($pnpDevID -eq "(Standard disk drives)") -and ($pnpDevID.product -eq $null))) { - $regex="^.{,16}$" + $regex="^.{,16}$" $pnpDevID=[pscustomobject]@{ product=($RS[$i].model -replace '^(.{0,16}).*$','$1') # Strange behavior for this case, will return } @@ -719,10 +517,8 @@ function parseHddData() { } ### Gather GFX details -Write-Progress -Id 1 -Activity "Gathering component details" -PercentComplete 70 - -Write-Progress -Id 2 -ParentId 1 -Activity "Gathering GFX information" -CurrentOperation "Querying" -PercentComplete 0 function parseGfxData() { + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering GFX information" -CurrentOperation "Querying" -PercentComplete 0 $RS=(Get-CimInstance -ClassName CIM_VideoController | select pnpdeviceid ) $component="" $replaceable=(jsonFieldReplaceable "true") @@ -772,15 +568,22 @@ function parseGfxData() { } ### Collate the component details +Write-Progress -Id 1 -Activity "Gathering platform details" -PercentComplete 10 +$platform=(gatherSmbiosSystemForSubjectAlternativeName) +Write-Progress -Id 1 -Activity "Gathering data from SMBIOS" -PercentComplete 20 +$componentsSMBIOS=(gatherSmbiosData) +Write-Progress -Id 1 -Activity "Gathering component details" -PercentComplete 40 +$componentsNIC=(parseNicData) +Write-Progress -Id 1 -Activity "Gathering component details" -PercentComplete 60 +$componentsHDD=(parseHddData) +Write-Progress -Id 1 -Activity "Gathering component details" -PercentComplete 80 +$componentsGFX=(parseGfxData) $componentsCPU=$(parseCpuData) $componentsRAM=$(parseRamData) -$componentsNIC=$(parseNicData) -$componentsHDD=$(parseHddData) -$componentsGFX=$(parseGfxData) -$componentArray=(jsonComponentArray "$componentChassis" "$componentBaseboard" "$componentBios" "$componentsCPU" "$componentsRAM" "$componentsNIC" "$componentsHDD" "$componentsGFX") +$componentArray=(jsonComponentArray "$componentsSMBIOS" "$componentsNIC" "$componentsHDD" "$componentsGFX" "$componentChassis" "$componentBaseboard" "$componentBios" "$componentsCPU" "$componentsRAM") ### Gather property details -Write-Progress -Id 1 -Activity "Gathering properties" -PercentComplete 80 +Write-Progress -Id 1 -Activity "Gathering properties" -PercentComplete 90 $osCaption=((wmic os get caption /value | Select-String -Pattern "^.*=(.*)$").Matches.Groups[1].ToString().Trim()) $property1=(jsonProperty "caption" "$osCaption") ## Example1 $property2= ## Example2 @@ -798,7 +601,7 @@ if ($PROPERTIES_URI) { $propertiesUri=(jsonPropertiesUri) } -Write-Progress -Id 1 -Activity "Forming final output" -PercentComplete 90 +Write-Progress -Id 1 -Activity "Forming final output" -PercentComplete 95 ### Construct the final JSON object $FINAL_JSON_OBJECT=(jsonIntermediateFile "$platform" "$componentArray" "$componentsUri" "$propertyArray" "$propertiesUri") diff --git a/scripts/windows/componentlist.ps1 b/scripts/windows/componentlist.ps1 new file mode 100644 index 0000000..376e7f8 --- /dev/null +++ b/scripts/windows/componentlist.ps1 @@ -0,0 +1,360 @@ +param( + [parameter(Mandatory=$true)] + [ValidateNotNull()] + [string]$filename +) + +### User customizable values +$APP_HOME=(Split-Path -parent $PSCommandPath) +$PROPERTIES_URI="" # Specify the optional properties URI field +$PROPERTIES_URI_LOCAL_COPY_FOR_HASH="" # If empty, the optional hashAlgorithm and hashValue fields will not be included for the URI +$JSON_SCRIPT="$APP_HOME/json.ps1" # Defines JSON structure and provides methods for producing relevant JSON +$SMBIOS_SCRIPT="$APP_HOME/SMBios.ps1" # Handles parsing of SMBIOS data +$HW_SCRIPT="$APP_HOME/hw.ps1" # Handles parsing of WMI and CIM + +### JSON +. $JSON_SCRIPT + +### Load Raw SMBios Data +. $SMBIOS_SCRIPT # See the TCG SMBIOS Component Class Registry specification. +$smbios=(Get-SMBiosStructures) +$COMPCLASS_REGISTRY_SMBIOS="2.23.133.18.3.3" # See the TCG OID Registry. + +### hw +. $HW_SCRIPT + +### ComponentClass values +$COMPCLASS_REGISTRY_TCG="2.23.133.18.3.1" +$COMPCLASS_BASEBOARD="00030003" # these values are meant to be an example. check the TCG component class registry. +$COMPCLASS_BIOS="00130003" +$COMPCLASS_UEFI="00130002" +$COMPCLASS_CHASSIS="00020001" +$COMPCLASS_CPU="00010002" +$COMPCLASS_HDD="00070002" +$COMPCLASS_NIC="00090002" +$COMPCLASS_RAM="00060001" +$COMPCLASS_GFX="00050002" + +# Progress Group IDs: +# 1: Overall progress +# 2: Component type +Write-Progress -Id 1 -Activity "Setting up to gather component details" -PercentComplete 0 + +### Gather platform details for the subject alternative name +### Platform attributes in the SAN only need to be consistent between base and delta platform certificates +function gatherSmbiosSystemForSubjectAlternativeName() { + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering platform information" -CurrentOperation "Querying" -PercentComplete 0 + ### Gather platform details for the subject alternative name + $platformManufacturer=(Get-SMBiosString $smbios "$SMBIOS_TYPE_SYSTEM" 0x4) + $platformModel=(Get-SMBiosString $smbios "$SMBIOS_TYPE_SYSTEM" 0x5) + $platformVersion=(Get-SMBiosString $smbios "$SMBIOS_TYPE_SYSTEM" 0x6) + $platformSerial=(Get-SMBiosString $smbios "$SMBIOS_TYPE_SYSTEM" 0x7) + + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering platform information" -CurrentOperation "Cleaning output" -PercentComplete 40 + if ([string]::IsNullOrEmpty($platformManufacturer) -or ($platformManufacturer.Trim().Length -eq 0)) { + $platformManufacturer="$NOT_SPECIFIED" + } + $platformManufacturer=$(jsonPlatformManufacturerStr "$platformManufacturer".Trim()) + + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering platform information" -CurrentOperation "Cleaning output" -PercentComplete 55 + if ([string]::IsNullOrEmpty($platformModel) -or ($platformModel.Trim().Length -eq 0)) { + $platformModel="$NOT_SPECIFIED" + } + $platformModel=$(jsonPlatformModel "$platformModel".Trim()) + + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering platform information" -CurrentOperation "Cleaning output" -PercentComplete 70 + if ([string]::IsNullOrEmpty($platformVersion) -or ($platformVersion.Trim().Length -eq 0)) { + $platformVersion="$NOT_SPECIFIED" + } + $platformVersion=(jsonPlatformVersion "$platformVersion".Trim()) + + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering platform information" -CurrentOperation "Cleaning output" -PercentComplete 85 + if (![string]::IsNullOrEmpty($platformSerial) -and ($platformSerial.Trim().Length -ne 0)) { + $platformSerial=(jsonPlatformSerial "$platformSerial".Trim()) + } + $platform=(jsonPlatformObject "$platformManufacturer" "$platformModel" "$platformVersion" "$platformSerial") + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering platform information" -CurrentOperation "Done" -PercentComplete 100 + return $platform.Trim(",") +} + +### Gather data from SMBIOS +function gatherSmbiosData() { + $components="" + $types=@($SMBIOS_TYPE_BASEBOARD,$SMBIOS_TYPE_BIOS,$SMBIOS_TYPE_CHASSIS,$SMBIOS_TYPE_PROCESSOR,$SMBIOS_TYPE_RAM,$SMBIOS_TYPE_SYSTEM,$SMBIOS_TYPE_POWERSUPPLY,$SMBIOS_TYPE_TPM) + + foreach ($type in $types) { + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering information about SMBIOS type $type" -CurrentOperation "Gathering" -PercentComplete 0 + $RS=$smbios[$type] + $numRows=$RS.Count + + for($i=0;$i -lt $numRows;$i++) { + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering information about SMBIOS type $type" -CurrentOperation "Working on element ($i+1) of $numRows" -PercentComplete ((($i+1)/$numRows)*100) + $component="" + $struct=$RS[$i] + + $componentClassValue=(GetComponentClassValue $struct) + $manufacturer=(GetManufacturer $struct) + $model=(GetModel $struct) + $serialNumber=(GetSerialNumber $struct) + $revision=(GetRevision $struct) + $fieldReplaceable=(GetFieldReplaceable $struct) + + # Do not include empty slots + if ([string]::IsNullOrEmpty($manufacturer) -and [string]::IsNullOrEmpty($model) -and [string]::IsNullOrEmpty($serialNumber) -and [string]::IsNullOrEmpty($revision)) { + continue + } + + $componentClass=(jsonComponentClass "$COMPCLASS_REGISTRY_SMBIOS" "$componentClassValue") + $manufacturer=(jsonManufacturer "$manufacturer") + $model=(jsonModel "$model") + if (![string]::IsNullOrEmpty($serialNumber)) { + $serialNumber=(jsonSerial "$serialNumber") + } + if (![string]::IsNullOrEmpty($revision)) { + $revision=(jsonRevision "$revision") + } + if (![string]::IsNullOrEmpty($fieldReplaceable)) { + $fieldReplaceable=(jsonFieldReplaceable "$fieldReplaceable") + } + $component=(jsonComponent "$componentClass" "$manufacturer" "$model" "$serialNumber" "$revision" "$fieldReplaceable") + $components+="$component," + } # for numRows (for each handle) + } # foreach type + Write-Progress -Id 2 -ParentId 1 -Activity "Complete" -CurrentOperation "Complete" -PercentComplete 100 + return "$components".Trim(",") +} + +### Gather NIC details +function parseNicData() { + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering NIC information" -CurrentOperation "Querying CIM" -PercentComplete 0 + $RS=@(Get-NetAdapter | select MacAddress,PhysicalMediaType,PNPDeviceID | where {($_.PhysicalMediaType -eq "Native 802.11" -or "802.3") -and ($_.PNPDeviceID -Match "^(PCI)\\.*$")}) + $component="" + $replaceable=(jsonFieldReplaceable "true") + $numRows=$RS.Count + + for($i=0;$i -lt $numRows;$i++) { + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering NIC information" -CurrentOperation ("Cleaning output for NIC " + ($i+1)) -PercentComplete ((($i+1) / $numRows) * 100) + + $nicClass=(jsonComponentClass "$COMPCLASS_REGISTRY_TCG" "$COMPCLASS_NIC") + + $pnpDevID="" + if(isPCI($RS[$i].PNPDeviceID)) { + $pnpDevID=(pciParse $RS[$i].PNPDeviceID) + } else { + Continue + } + + $tmpManufacturer=$pnpDevID.vendor # PCI Vendor ID + $tmpModel=$pnpDevID.product # PCI Device Hardware ID + $tmpSerialConstant=($RS[$i].MacAddress) + $tmpSerialConstant=(standardizeMACAddr $tmpSerialConstant) + $tmpSerial="" + $tmpRevision=$pnpDevID.revision + $tmpMediaType=$RS[$i].PhysicalMediaType + $thisAddress="" + + if ([string]::IsNullOrEmpty($tmpManufacturer) -or ($tmpManufacturer.Trim().Length -eq 0)) { + $tmpManufacturer="$NOT_SPECIFIED" + } + $tmpManufacturer=$(jsonManufacturer "$tmpManufacturer".Trim()) + + + if ([string]::IsNullOrEmpty($tmpModel) -or ($tmpModel.Trim().Length -eq 0)) { + $tmpModel="$NOT_SPECIFIED" + } + $tmpModel=$(jsonModel "$tmpModel".Trim()) + + + + if (![string]::IsNullOrEmpty($tmpSerialConstant) -and ($tmpSerialConstant.Trim().Length -ne 0)) { + $tmpSerial=(jsonSerial "$tmpSerialConstant".Trim()) + } else { + $tmpSerial="" + } + + + if (![string]::IsNullOrEmpty($tmpRevision) -and ($tmpRevision.Trim().Length -ne 0)) { + $tmpRevision=(jsonRevision "$tmpRevision".Trim()) + } else { + $tmpRevision="" + } + + if ($tmpMediaType -and $tmpSerial) { + if ("$tmpMediaType" -match "^.*802[.]11.*$") { + $thisAddress=(jsonWlanMac $tmpSerialConstant) + } + elseif ("$tmpMediaType" -match "^.*[Bb]lue[Tt]ooth.*$") { + $thisAddress=(jsonBluetoothMac $tmpSerialConstant) + } + elseif ("$tmpMediaType" -match "^.*802[.]3.*$") { + $thisAddress=(jsonEthernetMac $tmpSerialConstant) + } + if ($thisAddress) { + $thisAddress=(jsonAddress "$thisAddress") + } + } + + $tmpComponent=(jsonComponent $nicClass $tmpManufacturer $tmpModel $replaceable $tmpSerial $tmpRevision $thisAddress) + $component+="$tmpComponent," + } + + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering NIC information" -CurrentOperation "Done" -PercentComplete 100 + return "$component".Trim(",") +} + +### Gather HDD details +function parseHddData() { + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering HDD information" -CurrentOperation "Querying" -PercentComplete 0 + $RS=(Get-CimInstance -ClassName CIM_DiskDrive | select serialnumber,mediatype,pnpdeviceid,manufacturer,model | where mediatype -eq "Fixed hard disk media") + $component="" + $replaceable=(jsonFieldReplaceable "true") + $numRows=1 + if ($RS.Count -gt 1) { + $numRows=($RS.Count) + } + for($i=0;$i -lt $numRows;$i++) { + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering Hard Disk information" -CurrentOperation ("Cleaning output for HDD " + ($i+1)) -PercentComplete ((($i+1) / $numRows) * 100) + + $hddClass=(jsonComponentClass "$COMPCLASS_REGISTRY_TCG" "$COMPCLASS_HDD") + + $pnpDevID="" + if(isIDE($RS[$i].PNPDeviceID)) { + $pnpDevID=(ideDiskParse $RS[$i].PNPDeviceID) + } elseif(isSCSI($RS[$i].PNPDeviceID)) { + $pnpDevID=(scsiDiskParse $RS[$i].PNPDeviceID) + } else { + Continue + } + + if(($pnpDevID -eq $null) -or (($pnpDevID -eq "(Standard disk drives)") -and ($pnpDevID.product -eq $null))) { + $regex="^.{,16}$" + $pnpDevID=[pscustomobject]@{ + product=($RS[$i].model -replace '^(.{0,16}).*$','$1') # Strange behavior for this case, will return + } + } + + $tmpManufacturer=$pnpDevID.vendor # PCI Vendor ID + $tmpModel=$pnpDevID.product # PCI Device Hardware ID + $tmpSerial=$RS[$i].serialnumber + $tmpRevision=$pnpDevID.revision + + if ([string]::IsNullOrEmpty($tmpManufacturer) -or ($tmpManufacturer.Trim().Length -eq 0)) { + $tmpManufacturer="$NOT_SPECIFIED" + } + $tmpManufacturer=$(jsonManufacturer "$tmpManufacturer".Trim()) + + if ([string]::IsNullOrEmpty($tmpModel) -or ($tmpModel.Trim().Length -eq 0)) { + $tmpModel="$NOT_SPECIFIED" + } + $tmpModel=$(jsonModel "$tmpModel".Trim()) + + if (![string]::IsNullOrEmpty($tmpSerial) -and ($tmpSerial.Trim().Length -ne 0)) { + $tmpSerial=(jsonSerial "$tmpSerial".Trim()) + } else { + $tmpSerial="" + } + + if (![string]::IsNullOrEmpty($tmpRevision) -and ($tmpRevision.Trim().Length -ne 0)) { + $tmpRevision=(jsonRevision "$tmpRevision".Trim()) + } else { + $tmpRevision="" + } + + $tmpComponent=(jsonComponent $hddClass $tmpManufacturer $tmpModel $replaceable $tmpSerial $tmpRevision) + $component+="$tmpComponent," + } + + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering Hard Disk information" -CurrentOperation "Done" -PercentComplete 100 + return "$component".Trim(",") +} + +### Gather GFX details +function parseGfxData() { + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering GFX information" -CurrentOperation "Querying" -PercentComplete 0 + $RS=(Get-CimInstance -ClassName CIM_VideoController | select pnpdeviceid ) + $component="" + $replaceable=(jsonFieldReplaceable "true") + $numRows=1 + if ($RS.Count -gt 1) { + $numRows=($RS.Count) + } + for($i=0;$i -lt $numRows;$i++) { + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering Graphics information" -CurrentOperation ("Cleaning output for HDD " + ($i+1)) -PercentComplete ((($i+1) / $numRows) * 100) + + $gfxClass=(jsonComponentClass "$COMPCLASS_REGISTRY_TCG" "$COMPCLASS_GFX") + + $pnpDevID="" + if(isPCI($RS[$i].PNPDeviceID)) { + $pnpDevID=(pciParse $RS[$i].PNPDeviceID) + } else { + Continue + } + + $tmpManufacturer=$pnpDevID.vendor # PCI Vendor ID + $tmpModel=$pnpDevID.product # PCI Device Hardware ID + $tmpRevision=$pnpDevID.revision + # CIM Class does not contain serialnumber + + if ([string]::IsNullOrEmpty($tmpManufacturer) -or ($tmpManufacturer.Trim().Length -eq 0)) { + $tmpManufacturer="$NOT_SPECIFIED" + } + $tmpManufacturer=$(jsonManufacturer "$tmpManufacturer".Trim()) + + if ([string]::IsNullOrEmpty($tmpModel) -or ($tmpModel.Trim().Length -eq 0)) { + $tmpModel="$NOT_SPECIFIED" + } + $tmpModel=$(jsonModel "$tmpModel".Trim()) + + if (![string]::IsNullOrEmpty($tmpRevision) -and ($tmpRevision.Trim().Length -ne 0)) { + $tmpRevision=(jsonRevision "$tmpRevision".Trim()) + } else { + $tmpRevision="" + } + + $tmpComponent=(jsonComponent $gfxClass $tmpManufacturer $tmpModel $replaceable $tmpRevision) + $component+="$tmpComponent," + } + + Write-Progress -Id 2 -ParentId 1 -Activity "Gathering Graphics information" -CurrentOperation "Done" -PercentComplete 100 + return "$component".Trim(",") +} + +### Collate the component details +Write-Progress -Id 1 -Activity "Gathering platform details" -PercentComplete 10 +$platform=(gatherSmbiosSystemForSubjectAlternativeName) +Write-Progress -Id 1 -Activity "Gathering data from SMBIOS" -PercentComplete 20 +$componentsSMBIOS=(gatherSmbiosData) +Write-Progress -Id 1 -Activity "Gathering component details" -PercentComplete 40 +$componentsNIC=(parseNicData) +Write-Progress -Id 1 -Activity "Gathering component details" -PercentComplete 60 +$componentsHDD=(parseHddData) +Write-Progress -Id 1 -Activity "Gathering component details" -PercentComplete 80 +$componentsGFX=(parseGfxData) +$componentArray=(jsonComponentArray "$componentsSMBIOS" "$componentsNIC" "$componentsHDD" "$componentsGFX") + +### Gather property details +Write-Progress -Id 1 -Activity "Gathering properties" -PercentComplete 90 +$osCaption=((wmic os get caption /value | Select-String -Pattern "^.*=(.*)$").Matches.Groups[1].ToString().Trim()) +$property1=(jsonProperty "caption" "$osCaption") ## Example1 +$property2= ## Example2 + +### Collate the property details +$propertyArray=(jsonPropertyArray "$property1") + +### Collate the URI details, if parameters above are blank, the fields will be excluded from the final JSON structure +$componentsUri="" +if ($COMPONENTS_URI) { + $componentsUri=(jsonComponentsUri) +} +$propertiesUri="" +if ($PROPERTIES_URI) { + $propertiesUri=(jsonPropertiesUri) +} + +Write-Progress -Id 1 -Activity "Forming final output" -PercentComplete 95 +### Construct the final JSON object +$FINAL_JSON_OBJECT=(jsonIntermediateFile "$platform" "$componentArray" "$componentsUri" "$propertyArray" "$propertiesUri") + +Write-Progress -Id 1 -Activity "Done" -PercentComplete 100 +[IO.File]::WriteAllText($filename, "$FINAL_JSON_OBJECT") + diff --git a/scripts/windows/json.ps1 b/scripts/windows/json.ps1 new file mode 100644 index 0000000..69168b6 --- /dev/null +++ b/scripts/windows/json.ps1 @@ -0,0 +1,267 @@ +### User customizable values +$APP_HOME=(Split-Path -parent $PSCommandPath) +$ENTERPRISE_NUMBERS_FILE="$APP_HOME/../enterprise-numbers" +$PEN_ROOT="1.3.6.1.4.1." # OID root for the private enterprise numbers + +### JSON Structure Keywords +$JSON_COMPONENTS="COMPONENTS" +$JSON_PROPERTIES="PROPERTIES" +$JSON_PROPERTIESURI="PROPERTIESURI" +$JSON_PLATFORM="PLATFORM" +#### JSON Component Keywords +$JSON_COMPONENTCLASS="COMPONENTCLASS" +$JSON_COMPONENTCLASSREGISTRY="COMPONENTCLASSREGISTRY" +$JSON_COMPONENTCLASSVALUE="COMPONENTCLASSVALUE" +$JSON_MANUFACTURER="MANUFACTURER" +$JSON_MODEL="MODEL" +$JSON_SERIAL="SERIAL" +$JSON_REVISION="REVISION" +$JSON_MANUFACTURERID="MANUFACTURERID" +$JSON_FIELDREPLACEABLE="FIELDREPLACEABLE" +$JSON_ADDRESSES="ADDRESSES" +$JSON_ETHERNETMAC="ETHERNETMAC" +$JSON_WLANMAC="WLANMAC" +$JSON_BLUETOOTHMAC="BLUETOOTHMAC" +$JSON_COMPONENTPLATFORMCERT="PLATFORMCERT" +$JSON_ATTRIBUTECERTIDENTIFIER="ATTRIBUTECERTIDENTIFIER" +$JSON_GENERICCERTIDENTIFIER="GENERICCERTIDENTIFIER" +$JSON_ISSUER="ISSUER" +$JSON_COMPONENTPLATFORMCERTURI="PLATFORMCERTURI" +$JSON_STATUS="STATUS" +#### JSON Platform Keywords (Subject Alternative Name) +$JSON_PLATFORMMODEL="PLATFORMMODEL" +$JSON_PLATFORMMANUFACTURERSTR="PLATFORMMANUFACTURERSTR" +$JSON_PLATFORMVERSION="PLATFORMVERSION" +$JSON_PLATFORMSERIAL="PLATFORMSERIAL" +$JSON_PLATFORMMANUFACTURERID="PLATFORMMANUFACTURERID" +#### JSON Platform URI Keywords +$JSON_URI="UNIFORMRESOURCEIDENTIFIER" +$JSON_HASHALG="HASHALGORITHM" +$JSON_HASHVALUE="HASHVALUE" +#### JSON Properties Keywords +$JSON_NAME="NAME" +$JSON_VALUE="VALUE" +$NOT_SPECIFIED="Not Specified" + + +### JSON Structure Format +$JSON_INTERMEDIATE_FILE_OBJECT="{{ + {0} +}}" +$JSON_PLATFORM_TEMPLATE=" + `"$JSON_PLATFORM`": {{ + {0} + }}" +$JSON_PROPERTIESURI_TEMPLATE=" + `"$JSON_PROPERTIESURI`": {{ + {0} + }}" +$JSON_COMPONENTSURI_TEMPLATE=" + `"$JSON_COMPONENTSURI`": {{ + {0} + }}" +$JSON_PROPERTY_ARRAY_TEMPLATE=" + `"$JSON_PROPERTIES`": [{0} + ]" +$JSON_COMPONENT_ARRAY_TEMPLATE=" + `"$JSON_COMPONENTS`": [{0} + ]" +$JSON_COMPONENT_TEMPLATE=" + {{ + {0} + }}" +$JSON_PROPERTY_TEMPLATE=" + {{ + `"$JSON_NAME`": `"{0}`", + `"$JSON_VALUE`": `"{1}`" + }} +" +$JSON_ADDRESSES_TEMPLATE=" `"$JSON_ADDRESSES`": [{0}]" +$JSON_ETHERNETMAC_TEMPLATE=" {{ + `"$JSON_ETHERNETMAC`": `"{0}`" }} " +$JSON_WLANMAC_TEMPLATE=" {{ + `"$JSON_WLANMAC`": `"{0}`" }} " +$JSON_BLUETOOTHMAC_TEMPLATE=" {{ + `"$JSON_BLUETOOTHMAC`": `"{0}`" }} " +$JSON_COMPONENTCLASS_TEMPLATE=" `"$JSON_COMPONENTCLASS`": {{ + `"$JSON_COMPONENTCLASSREGISTRY`": `"{0}`", + `"$JSON_COMPONENTCLASSVALUE`": `"{1}`" + }}" +$JSON_ATTRIBUTECERTIDENTIFIER_TEMPLATE=" `"$JSON_ATTRIBUTECERTIDENTIFIER`": {{ + `"$JSON_HASHALG`": `"{0}`", + `"$JSON_HASHVALUE`": `"{1}`" + }}," +$JSON_GENERICCERTIDENTIFIER_TEMPLATE=" `"$JSON_GENERICCERTIDENTIFIER`": {{ + `"$JSON_ISSUER`": `"{0}`", + `"$JSON_SERIAL`": `"{1}`" + }}," +$JSON_COMPONENTPLATFORMCERT_TEMPLATE=" + `"$JSON_COMPONENTPLATFORMCERT`": {{ + {0} + }}" +$JSON_COMPONENTPLATFORMCERTURI_TEMPLATE=' + `"$JSON_COMPONENTPLATFORMCERTURI`": {{ + {0} + }}' +$JSON_STATUS_TEMPLATE=" + `"$JSON_STATUS`": {{ + + }}" + +### JSON Constructor Aides +function HexToByteArray { # Powershell doesn't have a built in BinToHex function + Param ([String] $str ) + + if ($str.Length % 2 -ne 0) { + $str="0$str" + } + + if ($str.Length -ne 0) { + ,@($str -split '([a-f0-9]{2})' | foreach-object { + if ($_) { + [System.Convert]::ToByte($_,16) + } + }) + } +} +function jsonComponentClass () { + echo ("$JSON_COMPONENTCLASS_TEMPLATE" -f "$($args[0])","$($args[1])") +} +function jsonManufacturer () { + $manufacturer=("`"$JSON_MANUFACTURER`": `"{0}`"" -f "$($args[0])") + #$tmpManufacturerId=(queryForPen "$($args[0])") + #if (($tmpManufacturerId) -and ("$tmpManufacturerId" -ne "$PEN_ROOT")) { + # $tmpManufacturerId=(jsonManufacturerId "$tmpManufacturerId") + # $manufacturer="$manufacturer,$tmpManufacturerId" + #} + echo "$manufacturer" +} +function jsonModel () { + echo ("`"$JSON_MODEL`": `"{0}`"" -f "$($args[0])") +} +function jsonSerial () { + echo ("`"$JSON_SERIAL`": `"{0}`"" -f "$($args[0])") +} +function jsonRevision () { + echo ("`"$JSON_REVISION`": `"{0}`"" -f "$($args[0])") +} +function jsonManufacturerId () { + echo ("`"$JSON_MANUFACTURERID`": `"{0}`"" -f "$($args[0])") +} +function jsonFieldReplaceable () { + echo ("`"$JSON_FIELDREPLACEABLE`": `"{0}`"" -f "$($args[0])") +} +function jsonEthernetMac () { + echo ("$JSON_ETHERNETMAC_TEMPLATE" -f "$($args[0])") +} +function jsonWlanMac () { + echo ("$JSON_WLANMAC_TEMPLATE" -f "$($args[0])") +} +function jsonBluetoothMac () { + echo ("$JSON_BLUETOOTHMAC_TEMPLATE" -f "$($args[0])") +} +function jsonPlatformModel () { + echo ("`"$JSON_PLATFORMMODEL`": `"{0}`"" -f "$($args[0])") +} +function jsonPlatformManufacturerStr () { + $manufacturer=("`"$JSON_PLATFORMMANUFACTURERSTR`": `"{0}`"" -f "$($args[0])") + #$tmpManufacturerId=(queryForPen "$($args[0])") + #if (($tmpManufacturerId) -and ("$tmpManufacturerId" -ne "$PEN_ROOT")) { + # $tmpManufacturerId=(jsonPlatformManufacturerId "$tmpManufacturerId") + # $manufacturer="$manufacturer,$tmpManufacturerId" + #} + echo "$manufacturer" +} +function jsonPlatformVersion () { + echo ("`"$JSON_PLATFORMVERSION`": `"{0}`"" -f "$($args[0])") +} +function jsonPlatformSerial () { + echo ("`"$JSON_PLATFORMSERIAL`": `"{0}`"" -f "$($args[0])") +} +function jsonPlatformManufacturerId () { + echo ("`"$JSON_PLATFORMMANUFACTURERID`": `"{0}`"" -f "$($args[0])") +} +function queryForPen () { + $result=$PEN_ROOT + if($args[0]) { + $penObject=(Get-Content "$ENTERPRISE_NUMBERS_FILE" | Select-String -Pattern "^[ \t]*$($args[0])`$" -Context 1) + if ($penObject) { + $pen=$penObject.Context.PreContext[0] + $result+="$pen" + } + } + echo $result +} +function jsonProperty () { + if ($args.Length -eq 2) { + echo ("$JSON_PROPERTY_TEMPLATE" -f "$($args[0])","$($args[1])") + } +} +function jsonUri () { + echo ("`"$JSON_URI`": `"{0}`"" -f "$($args[0])") +} +function jsonHashAlg () { + echo ("`"$JSON_HASHALG`": `"{0}`"" -f "$($args[0])") +} +function jsonHashValue () { + echo ("`"$JSON_HASHVALUE`": `"{0}`"" -f "$($args[0])") +} +function toCSV () { + if ($args.Length -ne 0) { + $size = $args[0].Length + for ($i=0; $i -lt $size; $i++) { + $item=($args[0].Get($i)) + + if ($item) { + $value="$value,$($args[0].Get($i))" + } + } + echo "$value".Trim(" ", ",") + } +} +function jsonAddress () { + echo ("$JSON_ADDRESSES_TEMPLATE" -f "$(toCSV($args))") +} +function jsonComponent () { + echo ("$JSON_COMPONENT_TEMPLATE" -f "$(toCSV($args))") +} +function jsonComponentArray () { + echo ("$JSON_COMPONENT_ARRAY_TEMPLATE" -f "$(toCSV($args))") +} +function jsonPropertyArray () { + echo ("$JSON_PROPERTY_ARRAY_TEMPLATE" -f "$(toCSV($args))") +} +function jsonPlatformObject () { + echo ("$JSON_PLATFORM_TEMPLATE" -f "$(toCSV($args))") +} +function jsonComponentsUri () { + if ($COMPONENTS_URI) { + $componentsUri=(jsonUri "$COMPONENTS_URI") + $componentsUriDetails="" + if ($COMPONENTS_URI_LOCAL_COPY_FOR_HASH) { + $hashAlg="2.16.840.1.101.3.4.2.1" # SHA256, see https://tools.ietf.org/html/rfc5754 for other common hash algorithm IDs + $hashValue=([System.Convert]::ToBase64String($(HexToByteArray $(Get-FileHash "$COMPONENTS_URI_LOCAL_COPY_FOR_HASH" -Algorithm SHA256).Hash.Trim()))) + $hashAlgStr=(jsonHashAlg "$hashAlg") + $hashValueStr=(jsonHashValue "$hashValue") + $componentsUriDetails="$hashAlgStr"",""$hashValueStr" + } + echo ("$JSON_COMPONENTSURI_TEMPLATE" -f "$(toCSV("$componentsUri","$componentsUriDetails"))") + } +} +function jsonPropertiesUri () { + if ($PROPERTIES_URI) { + $propertiesUri=(jsonUri "$PROPERTIES_URI") + $propertiesUriDetails="" + if ($PROPERTIES_URI_LOCAL_COPY_FOR_HASH) { + $hashAlg="2.16.840.1.101.3.4.2.1" # SHA256, see https://tools.ietf.org/html/rfc5754 for other common hash algorithm IDs + $hashValue=([System.Convert]::ToBase64String($(HexToByteArray $(Get-FileHash "$PROPERTIES_URI_LOCAL_COPY_FOR_HASH" -Algorithm SHA256).Hash.Trim()))) + $hashAlgStr=(jsonHashAlg "$hashAlg") + $hashValueStr=(jsonHashValue "$hashValue") + $propertiesUriDetails="$hashAlgStr,$hashValueStr" + } + echo ("$JSON_PROPERTIESURI_TEMPLATE" -f "$(toCSV("$propertiesUri","$propertiesUriDetails"))") + } +} +function jsonIntermediateFile () { + echo ("$JSON_INTERMEDIATE_FILE_OBJECT" -f "$(toCSV($args))") +} diff --git a/scripts/windows/pc_certgen.ps1 b/scripts/windows/pc_certgen.ps1 index d4ed895..d2e1d24 100644 --- a/scripts/windows/pc_certgen.ps1 +++ b/scripts/windows/pc_certgen.ps1 @@ -1,7 +1,7 @@ $toolpath=(Split-Path -parent $PSCommandPath) $timestamp=(Get-Date -UFormat "%Y%m%d%H%M%S") #### Scripts and executable -$componentlister_script="$toolpath" + "/allcomponents.ps1" +$componentlister_script="$toolpath" + "/componentlist.ps1" $policymaker_script="$toolpath" + "/referenceoptions.ps1" $get_ek_script="$toolpath" + "/get_ek.ps1" $extensions_script="$toolpath" + "/otherextensions.ps1"