From 3353bbf40e93d4cb90642426df6b791b7e2fe52e Mon Sep 17 00:00:00 2001 From: chubtub <43381989+chubtub@users.noreply.github.com> Date: Wed, 9 Mar 2022 17:23:00 -0500 Subject: [PATCH] Check Directory and File for supportRIMFormat. An empty value defaults to TCG_EventLog_Assertion. Update unit tests. --- tools/tcg_rim_tool/rim_fields.json | 2 +- .../main/java/hirs/swid/SwidTagConstants.java | 1 + .../main/java/hirs/swid/SwidTagGateway.java | 43 +++++++++++++------ .../test/resources/generated_no_cert.swidtag | 14 +++--- .../resources/generated_with_cert.swidtag | 14 +++--- 5 files changed, 46 insertions(+), 28 deletions(-) diff --git a/tools/tcg_rim_tool/rim_fields.json b/tools/tcg_rim_tool/rim_fields.json index db4b9264..192bc897 100644 --- a/tools/tcg_rim_tool/rim_fields.json +++ b/tools/tcg_rim_tool/rim_fields.json @@ -29,8 +29,8 @@ "rimLinkHash": "88f21d8e44d4271149297404df91caf207130bfa116582408abd04ede6db7f51" }, "Payload": { - "supportRIMFormat": "TCG_EventLog_Assertion", "Directory": { + "supportRIMFormat": "TCG_EventLog_Assertion", "name": "iotBase", "File": { "name": "TpmLog.bin" diff --git a/tools/tcg_rim_tool/src/main/java/hirs/swid/SwidTagConstants.java b/tools/tcg_rim_tool/src/main/java/hirs/swid/SwidTagConstants.java index e0998080..c5dd2af1 100644 --- a/tools/tcg_rim_tool/src/main/java/hirs/swid/SwidTagConstants.java +++ b/tools/tcg_rim_tool/src/main/java/hirs/swid/SwidTagConstants.java @@ -69,6 +69,7 @@ public class SwidTagConstants { public static final String SUPPORT_RIM_FORMAT = "supportRIMFormat"; public static final String TCG_EVENTLOG_ASSERTION = "TCG_EventLog_Assertion"; public static final String TPM_PCR_ASSERTION = "TPM_PCR_Assertion"; + public static final String SUPPORT_RIM_FORMAT_MISSING = "supportRIMFormat missing"; public static final String SUPPORT_RIM_URI_GLOBAL = "supportRIMURIGlobal"; public static final QName _SHA256_HASH = new QName( diff --git a/tools/tcg_rim_tool/src/main/java/hirs/swid/SwidTagGateway.java b/tools/tcg_rim_tool/src/main/java/hirs/swid/SwidTagGateway.java index 39cc8fa4..55ca8416 100644 --- a/tools/tcg_rim_tool/src/main/java/hirs/swid/SwidTagGateway.java +++ b/tools/tcg_rim_tool/src/main/java/hirs/swid/SwidTagGateway.java @@ -388,18 +388,6 @@ public class SwidTagGateway { jsonObject.getString(SwidTagConstants._N8060_ENVVARSUFFIX.getLocalPart(), "")); addNonNullAttribute(attributes, SwidTagConstants._N8060_PATHSEPARATOR, jsonObject.getString(SwidTagConstants._N8060_PATHSEPARATOR.getLocalPart(), "")); - String supportRimFormat = jsonObject.getString(SwidTagConstants.SUPPORT_RIM_FORMAT, - SwidTagConstants.TCG_EVENTLOG_ASSERTION); - if (supportRimFormat != null && !supportRimFormat.isEmpty()) { - attributes.put(SwidTagConstants._SUPPORT_RIM_FORMAT, supportRimFormat); - } else { - attributes.put(SwidTagConstants._SUPPORT_RIM_FORMAT, - SwidTagConstants.TCG_EVENTLOG_ASSERTION); - } - addNonNullAttribute(attributes, SwidTagConstants._SUPPORT_RIM_TYPE, - jsonObject.getString(SwidTagConstants.SUPPORT_RIM_TYPE, "")); - addNonNullAttribute(attributes, SwidTagConstants._SUPPORT_RIM_URI_GLOBAL, - jsonObject.getString(SwidTagConstants.SUPPORT_RIM_URI_GLOBAL, "")); return payload; } @@ -413,6 +401,21 @@ public class SwidTagGateway { private Directory createDirectory(JsonObject jsonObject) { Directory directory = objectFactory.createDirectory(); directory.setName(jsonObject.getString(SwidTagConstants.NAME, "")); + Map attributes = directory.getOtherAttributes(); + String supportRimFormat = jsonObject.getString(SwidTagConstants.SUPPORT_RIM_FORMAT, + SwidTagConstants.SUPPORT_RIM_FORMAT_MISSING); + if (!supportRimFormat.equals(SwidTagConstants.SUPPORT_RIM_FORMAT_MISSING)) { + if (supportRimFormat.isEmpty()) { + attributes.put(SwidTagConstants._SUPPORT_RIM_FORMAT, + SwidTagConstants.TCG_EVENTLOG_ASSERTION); + } else { + attributes.put(SwidTagConstants._SUPPORT_RIM_FORMAT, supportRimFormat); + } + } + addNonNullAttribute(attributes, SwidTagConstants._SUPPORT_RIM_TYPE, + jsonObject.getString(SwidTagConstants.SUPPORT_RIM_TYPE, "")); + addNonNullAttribute(attributes, SwidTagConstants._SUPPORT_RIM_URI_GLOBAL, + jsonObject.getString(SwidTagConstants.SUPPORT_RIM_URI_GLOBAL, "")); return directory; } @@ -428,9 +431,23 @@ public class SwidTagGateway { private hirs.swid.xjc.File createFile(JsonObject jsonObject) { hirs.swid.xjc.File file = objectFactory.createFile(); file.setName(jsonObject.getString(SwidTagConstants.NAME, "")); + Map attributes = file.getOtherAttributes(); + String supportRimFormat = jsonObject.getString(SwidTagConstants.SUPPORT_RIM_FORMAT, + SwidTagConstants.SUPPORT_RIM_FORMAT_MISSING); + if (!supportRimFormat.equals(SwidTagConstants.SUPPORT_RIM_FORMAT_MISSING)) { + if (supportRimFormat.isEmpty()) { + attributes.put(SwidTagConstants._SUPPORT_RIM_FORMAT, + SwidTagConstants.TCG_EVENTLOG_ASSERTION); + } else { + attributes.put(SwidTagConstants._SUPPORT_RIM_FORMAT, supportRimFormat); + } + } + addNonNullAttribute(attributes, SwidTagConstants._SUPPORT_RIM_TYPE, + jsonObject.getString(SwidTagConstants.SUPPORT_RIM_TYPE, "")); + addNonNullAttribute(attributes, SwidTagConstants._SUPPORT_RIM_URI_GLOBAL, + jsonObject.getString(SwidTagConstants.SUPPORT_RIM_URI_GLOBAL, "")); File rimEventLogFile = new File(rimEventLog); file.setSize(new BigInteger(Long.toString(rimEventLogFile.length()))); - Map attributes = file.getOtherAttributes(); addNonNullAttribute(attributes, SwidTagConstants._SHA256_HASH, HashSwid.get256Hash(rimEventLog)); return file; diff --git a/tools/tcg_rim_tool/src/test/resources/generated_no_cert.swidtag b/tools/tcg_rim_tool/src/test/resources/generated_no_cert.swidtag index ea454392..29193469 100644 --- a/tools/tcg_rim_tool/src/test/resources/generated_no_cert.swidtag +++ b/tools/tcg_rim_tool/src/test/resources/generated_no_cert.swidtag @@ -3,7 +3,7 @@ - + @@ -17,14 +17,14 @@ - 97uWB7zSsO5WaGbrcQrlKd1Bju0aDTjK1/ktUYBje8A= + K3XoBeYvgJBAKl8z273sL7z38qLLVBKLfUPt/gPUzBI= - N1YtTeo2Ryuj+CtlXIpICEay+ni7vt8+4J7tAsYpa3efnLwtea69PIqEylPWm9LdA8Eo8XDdpgxV -7h3hi2LTOU+Wxq3bLiLamo99T1EtIwl+ZPcOv8bsfEkmShHdMC0dlfcj6r7x4tc0XkNAhhJgfRNz -FsmPWKJb6FYcsHFbHO/Uw1hSokbAGcWWTshEOqvKHMa8UVkrFMUPnrnMtdyJqZlhDBrZHNi4rWth -8TjlUnQVSCF9s9I04FxJ1cUAdeVMHtXKM8Pvjv68PaJMJK73dW5Yd3SbcgoKLesf/HPWeeZL0rr4 -TNjlqJ/wq61Ons45MFG9bIscVbnd+XxFHx8Skw== + cIl1gPsUyEj2gDv3HTWNFDVxtcBjz4Revxxf2LJejtOXQW8mGepZH8CnvgO7zCAbZYlYUZXjYZ9M +jONVv8dcsAjVHRnP6YHywFfmSm8LUCwxsfuZQqn5jClqzu5VaqLzBhuJYvCpiEdIDJwDINQuORUB +nzul1CWc3Sm1Ms2wjlIq5ctWWJcddhdyIOjl8/oD4EC5E2rOSfNcRMZxldXtie9iinFGVbr0YNE+ ++lQ7hAU+SyV8RMx9tGnnsO8otwV4ddF+OfemcbzWGYBenLs3A8ZqWZyTvWphCgGqDUbOLssYciCC +mnYm5QOeh4QcE9H2kqTgZvcyCgPL/hDC7xhyjQ== 2fdeb8e7d030a2209daa01861a964fedecf2bcc1 diff --git a/tools/tcg_rim_tool/src/test/resources/generated_with_cert.swidtag b/tools/tcg_rim_tool/src/test/resources/generated_with_cert.swidtag index dc711f3e..f47230cf 100644 --- a/tools/tcg_rim_tool/src/test/resources/generated_with_cert.swidtag +++ b/tools/tcg_rim_tool/src/test/resources/generated_with_cert.swidtag @@ -3,7 +3,7 @@ - + @@ -17,14 +17,14 @@ - 97uWB7zSsO5WaGbrcQrlKd1Bju0aDTjK1/ktUYBje8A= + K3XoBeYvgJBAKl8z273sL7z38qLLVBKLfUPt/gPUzBI= - N1YtTeo2Ryuj+CtlXIpICEay+ni7vt8+4J7tAsYpa3efnLwtea69PIqEylPWm9LdA8Eo8XDdpgxV -7h3hi2LTOU+Wxq3bLiLamo99T1EtIwl+ZPcOv8bsfEkmShHdMC0dlfcj6r7x4tc0XkNAhhJgfRNz -FsmPWKJb6FYcsHFbHO/Uw1hSokbAGcWWTshEOqvKHMa8UVkrFMUPnrnMtdyJqZlhDBrZHNi4rWth -8TjlUnQVSCF9s9I04FxJ1cUAdeVMHtXKM8Pvjv68PaJMJK73dW5Yd3SbcgoKLesf/HPWeeZL0rr4 -TNjlqJ/wq61Ons45MFG9bIscVbnd+XxFHx8Skw== + cIl1gPsUyEj2gDv3HTWNFDVxtcBjz4Revxxf2LJejtOXQW8mGepZH8CnvgO7zCAbZYlYUZXjYZ9M +jONVv8dcsAjVHRnP6YHywFfmSm8LUCwxsfuZQqn5jClqzu5VaqLzBhuJYvCpiEdIDJwDINQuORUB +nzul1CWc3Sm1Ms2wjlIq5ctWWJcddhdyIOjl8/oD4EC5E2rOSfNcRMZxldXtie9iinFGVbr0YNE+ ++lQ7hAU+SyV8RMx9tGnnsO8otwV4ddF+OfemcbzWGYBenLs3A8ZqWZyTvWphCgGqDUbOLssYciCC +mnYm5QOeh4QcE9H2kqTgZvcyCgPL/hDC7xhyjQ== CN=example.RIM.signer,OU=PCClient,O=Example,ST=VA,C=US