From 681fc92a3c38f2c3985e8741dbc6fd13d1a774f8 Mon Sep 17 00:00:00 2001 From: chubtub <43381989+chubtub@users.noreply.github.com> Date: Thu, 13 Apr 2023 00:14:15 -0400 Subject: [PATCH] Modify gateway class to generate a detached signature for a signed swidtag. Created new unit test and updated test resource files. --- .../src/main/java/hirs/swid/SwidTagGateway.java | 14 ++------------ .../test/java/hirs/swid/TestSwidTagGateway.java | 1 + 2 files changed, 3 insertions(+), 12 deletions(-) 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 b1f982b2..9c9f5ace 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 @@ -656,17 +656,8 @@ public class SwidTagGateway { } KeyInfo keyinfo = kiFactory.newKeyInfo(keyInfoElements); - Document detachedSignature = null; - try { - detachedSignature = DocumentBuilderFactory.newInstance() - .newDocumentBuilder().newDocument(); - } catch (ParserConfigurationException e) { - System.out.println("Error creating new document object: " + e.getMessage()); - } - detachedSignature.setXmlVersion("1.0"); - detachedSignature.appendChild(detachedSignature.createElement("root")); - DOMSignContext context = new DOMSignContext(privateKey, - detachedSignature.getDocumentElement()); + Document detachedSignature = db.newDocument(); + DOMSignContext context = new DOMSignContext(privateKey, detachedSignature); context.setIdAttributeNS(softwareIdentity, null, "id"); XMLSignature signature = sigFactory.newXMLSignature(signedInfo, keyinfo); try { @@ -675,7 +666,6 @@ public class SwidTagGateway { System.out.println("Error while signing SoftwareIdentity"); e.printStackTrace(); } - System.out.println("Detached signature: " + detachedSignature); return detachedSignature; } diff --git a/tools/tcg_rim_tool/src/test/java/hirs/swid/TestSwidTagGateway.java b/tools/tcg_rim_tool/src/test/java/hirs/swid/TestSwidTagGateway.java index 4b462004..ce32ef43 100644 --- a/tools/tcg_rim_tool/src/test/java/hirs/swid/TestSwidTagGateway.java +++ b/tools/tcg_rim_tool/src/test/java/hirs/swid/TestSwidTagGateway.java @@ -175,6 +175,7 @@ public class TestSwidTagGateway { gateway.setDefaultCredentials(true); Document doc = gateway.signXMLDocument(signFilePath); gateway.writeSwidTagFile(doc, DEFAULT_OUTPUT); + validator.validateSwidTag(DEFAULT_OUTPUT, "DEFAULT"); } catch (Exception e) { e.printStackTrace(); }