From b96b90fdd0fc823f50185c090946e562a6fdf228 Mon Sep 17 00:00:00 2001 From: iadgovuser58 <124906646+iadgovuser58@users.noreply.github.com> Date: Fri, 31 May 2024 14:57:35 -0400 Subject: [PATCH] accessing vendor-table.json from code --- .../src/main/java/hirs/utils/JsonUtils.java | 24 +++++++++++++++++++ .../utils/tpm/eventlog/uefi/UefiGuid.java | 6 ++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/HIRS_Utils/src/main/java/hirs/utils/JsonUtils.java b/HIRS_Utils/src/main/java/hirs/utils/JsonUtils.java index 78dfb0d4..63140cf3 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/JsonUtils.java +++ b/HIRS_Utils/src/main/java/hirs/utils/JsonUtils.java @@ -101,6 +101,30 @@ public final class JsonUtils { return jsonObject; } + + + + public static JsonObject getSpecificJsonObject(final String jsonFilename, final String elementName) { + // find the file and load it + return getSpecificJsonObject(jsonFilename, elementName, StandardCharsets.UTF_8); + } + + public static JsonObject getSpecificJsonObject(final String jsonFilename, + final String elementName, + final Charset charset) { + // find the file and load it + JsonObject jsonObject = getJsonObject(jsonFilename, charset); + + if (jsonObject != null && jsonObject.get(elementName) != null) { + return jsonObject.get(elementName).asObject(); + } + + return new JsonObject(); + } + public static JsonObject getJsonObject(final String jsonFilename) { + return getJsonObject(jsonFilename, StandardCharsets.UTF_8); + } + public static JsonObject getJsonObject(final String jsonFilename, final Charset charset) { // find the file and load it JsonObject jsonObject = new JsonObject(); diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiGuid.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiGuid.java index c0357e49..00c22ce1 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiGuid.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiGuid.java @@ -72,9 +72,13 @@ public class UefiGuid { System.out.println("XXXX EMPTYYYYYYY, before trying to grab file from code"); - uefiVendorRef = JsonUtils.getJsonObject("vendor-table2.json", +// uefiVendorRef = JsonUtils.getJsonObject("vendor-table2.json", +// StandardCharsets.UTF_8); + + uefiVendorRef = JsonUtils.getSpecificJsonObject("vendor-table2.json", "VendorTable", StandardCharsets.UTF_8); + // System.out.println("XXXX getClass: " + getClass()); // System.out.println("XXXX getClassResource: " + getClass().getResource("/vendor-table2.json")); //