From 313d274524e05bbfd2c7efb5bff127b3f4638b33 Mon Sep 17 00:00:00 2001 From: chubtub <43381989+chubtub@users.noreply.github.com> Date: Tue, 4 May 2021 13:46:09 -0400 Subject: [PATCH 1/4] Implement getopts in download_validation_reports.sh for argument parsing. --- scripts/download_validation_reports.sh | 78 +++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/scripts/download_validation_reports.sh b/scripts/download_validation_reports.sh index c67fdac3..11659967 100644 --- a/scripts/download_validation_reports.sh +++ b/scripts/download_validation_reports.sh @@ -5,12 +5,77 @@ #$2 filter end date 'yyyy-mm-dd' #$3 ACA address, default is localhost if not given -if [ -z "$3" ] - then - endpoint="https://localhost:8443/HIRS_AttestationCAPortal/portal/validation-reports" - else - endpoint="https://$3:8443/HIRS_AttestationCAPortal/portal/validation-reports" +#check for getopt(1) on local system +getopt --test > /dev/null +if [[ ${PIPESTATUS[0]} -ne 4 ]] +then + echo "getopt is required to use this script, please ensure installation!" +else + echo "getopt detected" fi + +#set parameter names and call getopts on inputsi, then parse/assign arguments +SHORTOPTS=m:s: +LONGOPTS=start-date:,end-date:,ip:,system-only,component-only,manufacturer:,serial: +PARSED=$(getopt --options=$SHORTOPTS --longoptions=$LONGOPTS --name "$0" -- "$@") +if [[ ${PIPESTATUS[0]} -ne 0 ]] +then + exit 2 +fi +eval set -- "$PARSED" +startDate= +endDate= +ip=localhost +system= +component= +manufacturer= +serial= +while true +do + case "$1" in + --start-date) + startDate="$2" + shift 2 + ;; + --end-date) + endDate="$2" + shift 2 + ;; + --ip) + ip="$2" + shift 2 + ;; + --system-only) + system=true + shift + ;; + --component-only) + component=true + shift + ;; + -m|--manufacturer) + manufacturer="$2" + shift 2 + ;; + -s|--serial) + serial="$2" + shift 2 + ;; + --) + shift + break + ;; + *) + echo "Programming error" + exit 3 + ;; + esac +done + +echo "start date: $startDate, end date: $endDate, ip: $ip, system: $system, component: $component, manufacturer: $manufacturer, serial: $serial" + +#call ACA for validation report +endpoint="https://$ip:8443/HIRS_AttestationCAPortal/portal/validation-reports" echo "$endpoint" content=$(curl --insecure $endpoint/list) rawTimes=$(jq -r '.data | map(.createTime | tostring) | join(",")' <<< "$content") @@ -22,5 +87,4 @@ done deviceNames=$(jq -r '.data | map(.device.name) | join(",")' <<< "$content") echo "Create times: $createTimes" echo "Device names: $deviceNames" -curl --data "dateStart=$1&dateEnd=$2&createTimes=$createTimes&deviceNames=$deviceNames" --insecure $endpoint/download - +curl --data "dateStart=$startDate&dateEnd=$endDate&createTimes=$createTimes&deviceNames=$deviceNames&system=$system&component=$component&manufacturer=$manufacturer&serial=$serial" --insecure $endpoint/download From 12d03ea2ea9c18f371ce1001be656a9c66e5897c Mon Sep 17 00:00:00 2001 From: chubtub <43381989+chubtub@users.noreply.github.com> Date: Wed, 5 May 2021 12:54:07 -0400 Subject: [PATCH 2/4] Support --system-only and --component-only options from commandline in controller class. --- .../ValidationReportsPageController.java | 71 ++++++++++++++----- 1 file changed, 53 insertions(+), 18 deletions(-) diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java index 7b84263b..a53c97cc 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java @@ -58,12 +58,13 @@ public class ValidationReportsPageController extends PageController createTimes = new ArrayList(); String[] deviceNames = new String[]{}; + String columnHeaders = ""; + boolean systemOnly = false; + boolean componentOnly = false; Enumeration parameters = request.getParameterNames(); while (parameters.hasMoreElements()) { @@ -208,6 +212,29 @@ public class ValidationReportsPageController extends PageController> parsedComponents = parseComponents(pc); - for (ArrayList component : parsedComponents) { - for (String data : component) { - reportData.append(data + ","); - } - reportData.deleteCharAt(reportData.length() - 1); - reportData.append("\n,,,,,"); + if (!componentOnly) { + reportData.append(pc.getManufacturer() + "," + + pc.getModel() + "," + + pc.getPlatformSerial() + "," + + LocalDateTime.now().toString() + "," + + pc.getDevice().getSupplyChainStatus() + ","); } - if (reportData.lastIndexOf(",") > 4) { - reportData.delete(reportData.lastIndexOf(",") - 4, reportData.length()); + if (!systemOnly) { + ArrayList> parsedComponents = parseComponents(pc); + for (ArrayList component : parsedComponents) { + for (String data : component) { + reportData.append(data + ","); + } + reportData.deleteCharAt(reportData.length() - 1); + reportData.append("\n,,,,,"); + } } } } + if (columnHeaders.isEmpty()) { + columnHeaders = systemColumnHeaders + componentColumnHeaders; + } bufferedWriter.append(columnHeaders + "\n"); bufferedWriter.append(reportData.toString() + "\n"); LOGGER.info(columnHeaders); From 3435265c5a1197064cc84779b3b8cef4a564c250 Mon Sep 17 00:00:00 2001 From: chubtub <43381989+chubtub@users.noreply.github.com> Date: Mon, 10 May 2021 13:53:18 -0400 Subject: [PATCH 3/4] Add -h|--help option. --- scripts/download_validation_reports.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/scripts/download_validation_reports.sh b/scripts/download_validation_reports.sh index 11659967..d01c89af 100644 --- a/scripts/download_validation_reports.sh +++ b/scripts/download_validation_reports.sh @@ -15,8 +15,8 @@ else fi #set parameter names and call getopts on inputsi, then parse/assign arguments -SHORTOPTS=m:s: -LONGOPTS=start-date:,end-date:,ip:,system-only,component-only,manufacturer:,serial: +SHORTOPTS=m:s:h +LONGOPTS=start-date:,end-date:,ip:,system-only,component-only,manufacturer:,serial:,help PARSED=$(getopt --options=$SHORTOPTS --longoptions=$LONGOPTS --name "$0" -- "$@") if [[ ${PIPESTATUS[0]} -ne 0 ]] then @@ -30,6 +30,15 @@ system= component= manufacturer= serial= + +helpText="\n\n\nHELP MENU\n\nThe following options are available:\n--start-date\t\t\tDefault: 1970-01-01\tThe earliest date to return validation reports from.\n" +helpText+="--end-date\t\t\tDefault: current time\tThe latest date to return validation reports from.\n" +helpText+="--ip\t\t\t\tDefault: localhost\tThe IP address where the ACA is located.\n" +helpText+="--system-only\t\t\t\t\t\t\tReturn only system information from validation reports.\n" +helpText+="--component-only\t\t\t\t\t\tReturn only component information from validation reports.\n" +helpText+="-m|--manufacturer\t\t\t\tReturn only the validation report of the device from this manufacturer.\n" +helpText+="-s|--serial\t\t\t\t\t\tReturn only the validation report of the device with this serial number.\n" + while true do case "$1" in @@ -61,6 +70,10 @@ do serial="$2" shift 2 ;; + -h|--help) + printf "$helpText" + exit 0 + ;; --) shift break @@ -78,6 +91,8 @@ echo "start date: $startDate, end date: $endDate, ip: $ip, system: $system, comp endpoint="https://$ip:8443/HIRS_AttestationCAPortal/portal/validation-reports" echo "$endpoint" content=$(curl --insecure $endpoint/list) + +#Parse JSON response for create times and device names rawTimes=$(jq -r '.data | map(.createTime | tostring) | join(",")' <<< "$content") createTimes="" for i in ${rawTimes//,/ } @@ -85,6 +100,7 @@ do createTimes+="$(date -u +"%Y-%m-%d %H:%M:%S" -d @"$(($i/1000))")," done deviceNames=$(jq -r '.data | map(.device.name) | join(",")' <<< "$content") + echo "Create times: $createTimes" echo "Device names: $deviceNames" curl --data "dateStart=$startDate&dateEnd=$endDate&createTimes=$createTimes&deviceNames=$deviceNames&system=$system&component=$component&manufacturer=$manufacturer&serial=$serial" --insecure $endpoint/download From da7e1de7f3b6f6b8dfb062b532a08d4b4ae9d892 Mon Sep 17 00:00:00 2001 From: chubtub <43381989+chubtub@users.noreply.github.com> Date: Tue, 11 May 2021 13:06:21 -0400 Subject: [PATCH 4/4] Support -m|--manufacturer and -s|--serial filter options from commandline in controller class. --- .../ValidationReportsPageController.java | 51 ++++++++++--------- scripts/download_validation_reports.sh | 2 +- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java index a53c97cc..8883d6a7 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java @@ -159,6 +159,8 @@ public class ValidationReportsPageController extends PageController> parsedComponents = parseComponents(pc); - for (ArrayList component : parsedComponents) { - for (String data : component) { - reportData.append(data + ","); + if ((filterManufacturer.isEmpty() || filterManufacturer.equals( + pc.getManufacturer())) + && (filterSerial.isEmpty() || filterSerial.equals( + pc.getPlatformSerial()))) { + if (!componentOnly) { + reportData.append(pc.getManufacturer() + "," + + pc.getModel() + "," + + pc.getPlatformSerial() + "," + + LocalDateTime.now().toString() + "," + + pc.getDevice().getSupplyChainStatus() + ","); + } + if (!systemOnly) { + ArrayList> parsedComponents = parseComponents(pc); + for (ArrayList component : parsedComponents) { + for (String data : component) { + reportData.append(data + ","); + } + reportData.deleteCharAt(reportData.length() - 1); + reportData.append("\n,,,,,"); } - reportData.deleteCharAt(reportData.length() - 1); - reportData.append("\n,,,,,"); } } } @@ -284,8 +289,6 @@ public class ValidationReportsPageController extends PageController