From 3ae32b6777af38f2a42c1889c59c7e8320e4dfdf Mon Sep 17 00:00:00 2001 From: Cyrus <24922493+cyrus-dev@users.noreply.github.com> Date: Mon, 25 Mar 2019 11:13:09 -0400 Subject: [PATCH] [#106] Platform Configuration v2 (#112) * These changes are the beginning stage for spec 2 changes to the platform configuration section of the attributes platform certificate. * Updated typos and corrected check style errors. * Updating Platform Credential Unit test from #24 * Added unit test resource --- .../certificate/PlatformCredential.java | 15 +- .../attributes/PlatformConfiguration.java | 128 +++++++++--------- .../attributes/PlatformConfigurationV1.java | 76 +++++++++++ .../attributes/PlatformConfigurationV2.java | 85 ++++++++++++ .../certificate/PlatformCredentialTest.java | 49 +++++++ .../large_attribute_spec2.txt | Bin 0 -> 2144 bytes 6 files changed, 282 insertions(+), 71 deletions(-) create mode 100644 HIRS_Utils/src/main/java/hirs/data/persist/certificate/attributes/PlatformConfigurationV1.java create mode 100644 HIRS_Utils/src/main/java/hirs/data/persist/certificate/attributes/PlatformConfigurationV2.java create mode 100644 HIRS_Utils/src/test/resources/validation/platform_credentials_2/large_attribute_spec2.txt diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/certificate/PlatformCredential.java b/HIRS_Utils/src/main/java/hirs/data/persist/certificate/PlatformCredential.java index 2b5abb5e..e6d04b88 100644 --- a/HIRS_Utils/src/main/java/hirs/data/persist/certificate/PlatformCredential.java +++ b/HIRS_Utils/src/main/java/hirs/data/persist/certificate/PlatformCredential.java @@ -2,6 +2,8 @@ package hirs.data.persist.certificate; import hirs.data.persist.certificate.attributes.ComponentIdentifier; import hirs.data.persist.certificate.attributes.PlatformConfiguration; +import hirs.data.persist.certificate.attributes.PlatformConfigurationV1; +import hirs.data.persist.certificate.attributes.PlatformConfigurationV2; import hirs.data.persist.certificate.attributes.TBBSecurityAssertion; import hirs.data.persist.certificate.attributes.URIReference; import hirs.persist.CertificateManager; @@ -68,8 +70,8 @@ public class PlatformCredential extends DeviceAssociatedCertificate { //OID for Certificate Attributes private static final String TCG_PLATFORM_SPECIFICATION = "2.23.133.2.17"; - private static final String TPM_SECURITU_ASSERTION = "2.23.133.2.18"; - private static final String TBB_SECURITU_ASSERTION = "2.23.133.2.19"; + private static final String TPM_SECURITY_ASSERTION = "2.23.133.2.18"; + private static final String TBB_SECURITY_ASSERTION = "2.23.133.2.19"; private static final String TCG_CREDENTIAL_SPECIFICATION = "2.23.133.2.23"; private static final String PLATFORM_CONFIGURATION_URI = "2.23.133.5.1.3"; private static final String PLATFORM_CONFIGURATION = "2.23.133.5.1.7.1"; @@ -626,7 +628,7 @@ public class PlatformCredential extends DeviceAssociatedCertificate { = ASN1Sequence.getInstance(attr.getAttrValues().getObjectAt(0)); //Parse sequence based on the attribute OID switch (attr.getAttrType().getId()) { - case TBB_SECURITU_ASSERTION: + case TBB_SECURITY_ASSERTION: attributes.put("tbbSecurityAssertion", new TBBSecurityAssertion(attributeSequence)); break; @@ -635,15 +637,18 @@ public class PlatformCredential extends DeviceAssociatedCertificate { new URIReference(attributeSequence)); break; case PLATFORM_CONFIGURATION: + attributes.put("platformConfiguration", + new PlatformConfigurationV1(attributeSequence)); + break; case PLATFORM_CONFIGURATION_V2: attributes.put("platformConfiguration", - new PlatformConfiguration(attributeSequence)); + new PlatformConfigurationV2(attributeSequence)); break; case TCG_PLATFORM_SPECIFICATION: case TCG_CREDENTIAL_SPECIFICATION: break; default: - //No class deffined for this attribute + //No class defined for this attribute LOGGER.warn("No class defined for attribute with OID: " + attr.getAttrType().getId()); break; diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/certificate/attributes/PlatformConfiguration.java b/HIRS_Utils/src/main/java/hirs/data/persist/certificate/attributes/PlatformConfiguration.java index 86c3ef48..907a40f6 100644 --- a/HIRS_Utils/src/main/java/hirs/data/persist/certificate/attributes/PlatformConfiguration.java +++ b/HIRS_Utils/src/main/java/hirs/data/persist/certificate/attributes/PlatformConfiguration.java @@ -4,27 +4,15 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import org.bouncycastle.asn1.ASN1Sequence; -import org.bouncycastle.asn1.ASN1TaggedObject; /** - * Basic class that handle Platform Configuration for the Platform Certificate - * Attribute. - *
- * PlatformConfiguration ::= SEQUENCE { - * componentIdentifier [0] IMPLICIT SEQUENCE(SIZE(1..CONFIGMAX)) OF - * ComponentIdentifier OPTIONAL, - * platformProperties [1] IMPLICIT SEQUENCE(SIZE(1..CONFIGMAX)) OF Properties OPTIONAL, - * platformPropertiesUri [2] IMPLICIT URIReference OPTIONAL } - *+ * Abstract class that provides base info for Platform Configuration of + * the Platform Certificate Attribute. */ -public class PlatformConfiguration { - - private static final int COMPONENT_IDENTIFIER = 0; - private static final int PLATFORM_PROPERTIES = 1; - private static final int PLATFORM_PROPERTIES_URI = 2; +public abstract class PlatformConfiguration { private List
+ * PlatformConfiguration ::= SEQUENCE { + * componentIdentifier [0] IMPLICIT SEQUENCE(SIZE(1..CONFIGMAX)) OF + * ComponentIdentifier OPTIONAL, + * platformProperties [1] IMPLICIT SEQUENCE(SIZE(1..CONFIGMAX)) OF Properties OPTIONAL, + * platformPropertiesUri [2] IMPLICIT URIReference OPTIONAL } + *+ */ +public class PlatformConfigurationV1 extends PlatformConfiguration { + + private static final int COMPONENT_IDENTIFIER = 0; + private static final int PLATFORM_PROPERTIES = 1; + private static final int PLATFORM_PROPERTIES_URI = 2; + + /** + * Constructor given the SEQUENCE that contains Platform Configuration. + * @param sequence containing the the Platform Configuration. + * @throws IllegalArgumentException if there was an error on the parsing + */ + public PlatformConfigurationV1(final ASN1Sequence sequence) throws IllegalArgumentException { + + //Default values + setComponentIdentifier(new ArrayList<>()); + setPlatformProperties(new ArrayList<>()); + setPlatformPropertiesUri(null); + + for (int i = 0; i < sequence.size(); i++) { + ASN1TaggedObject taggedSequence + = ASN1TaggedObject.getInstance(sequence.getObjectAt(i)); + //Set information based on the set tagged + switch (taggedSequence.getTagNo()) { + case COMPONENT_IDENTIFIER: + //Get componentIdentifier + ASN1Sequence componentConfiguration + = ASN1Sequence.getInstance(taggedSequence, false); + + //Get and set all the component values + for (int j = 0; j < componentConfiguration.size(); j++) { + //DERSequence with the components + ASN1Sequence component + = ASN1Sequence.getInstance(componentConfiguration.getObjectAt(j)); + add(new ComponentIdentifier(component)); + } + break; + case PLATFORM_PROPERTIES: + //Get platformProperties + ASN1Sequence properties = ASN1Sequence.getInstance(taggedSequence, false); + + //Get and set all the properties values + for (int j = 0; j < properties.size(); j++) { + //DERSequence with the components + ASN1Sequence property = ASN1Sequence.getInstance(properties.getObjectAt(j)); + add(new PlatformProperty(property)); + } + break; + case PLATFORM_PROPERTIES_URI: + //Get platformPropertiesURI + ASN1Sequence propertiesUri = ASN1Sequence.getInstance(taggedSequence, false); + //Save properties URI + setPlatformPropertiesUri(new URIReference(propertiesUri)); + break; + default: + break; + } + } + } +} diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/certificate/attributes/PlatformConfigurationV2.java b/HIRS_Utils/src/main/java/hirs/data/persist/certificate/attributes/PlatformConfigurationV2.java new file mode 100644 index 00000000..c84acc34 --- /dev/null +++ b/HIRS_Utils/src/main/java/hirs/data/persist/certificate/attributes/PlatformConfigurationV2.java @@ -0,0 +1,85 @@ +package hirs.data.persist.certificate.attributes; + +import java.util.ArrayList; +import org.bouncycastle.asn1.ASN1Sequence; +import org.bouncycastle.asn1.ASN1TaggedObject; + +/** + * Basic class that handle Platform Configuration for the Platform Certificate + * Attribute. + *
+ * PlatformConfiguration ::= SEQUENCE { + * componentIdentifier [0] IMPLICIT SEQUENCE(SIZE(1..CONFIGMAX)) OF + * ComponentIdentifier OPTIONAL, + * componentIdentifiersUri [1] IMPLICIT URIReference OPTIONAL + * platformProperties [2] IMPLICIT SEQUENCE(SIZE(1..CONFIGMAX)) OF Properties OPTIONAL, + * platformPropertiesUri [3] IMPLICIT URIReference OPTIONAL } + *+ */ +public class PlatformConfigurationV2 extends PlatformConfiguration { + + private static final int COMPONENT_IDENTIFIER = 0; + private static final int COMPONENT_IDENTIFIER_URI = 1; + private static final int PLATFORM_PROPERTIES = 2; + private static final int PLATFORM_PROPERTIES_URI = 3; + + /** + * Constructor given the SEQUENCE that contains Platform Configuration. + * @param sequence containing the the Platform Configuration. + * @throws IllegalArgumentException if there was an error on the parsing + */ + public PlatformConfigurationV2(final ASN1Sequence sequence) throws IllegalArgumentException { + + //Default values + setComponentIdentifier(new ArrayList<>()); + setComponentIdentifierUri(null); + setPlatformProperties(new ArrayList<>()); + setPlatformPropertiesUri(null); + + for (int i = 0; i < sequence.size(); i++) { + ASN1TaggedObject taggedSequence + = ASN1TaggedObject.getInstance(sequence.getObjectAt(i)); + //Set information based on the set tagged + switch (taggedSequence.getTagNo()) { + case COMPONENT_IDENTIFIER: + //Get componentIdentifier + ASN1Sequence componentConfiguration + = ASN1Sequence.getInstance(taggedSequence, false); + + //Get and set all the component values + for (int j = 0; j < componentConfiguration.size(); j++) { + //DERSequence with the components + ASN1Sequence component + = ASN1Sequence.getInstance(componentConfiguration.getObjectAt(j)); + add(new ComponentIdentifier(component)); + } + break; + case COMPONENT_IDENTIFIER_URI: + //Get platformPropertiesURI + ASN1Sequence componentUri = ASN1Sequence.getInstance(taggedSequence, false); + //Save properties URI + setComponentIdentifierUri(new URIReference(componentUri)); + break; + case PLATFORM_PROPERTIES: + //Get platformProperties + ASN1Sequence properties = ASN1Sequence.getInstance(taggedSequence, false); + + //Get and set all the properties values + for (int j = 0; j < properties.size(); j++) { + //DERSequence with the components + ASN1Sequence property = ASN1Sequence.getInstance(properties.getObjectAt(j)); + add(new PlatformProperty(property)); + } + break; + case PLATFORM_PROPERTIES_URI: + //Get platformPropertiesURI + ASN1Sequence propertiesUri = ASN1Sequence.getInstance(taggedSequence, false); + //Save properties URI + setPlatformPropertiesUri(new URIReference(propertiesUri)); + break; + default: + break; + } + } + } +} diff --git a/HIRS_Utils/src/test/java/hirs/data/persist/certificate/PlatformCredentialTest.java b/HIRS_Utils/src/test/java/hirs/data/persist/certificate/PlatformCredentialTest.java index 7343880b..888758e6 100644 --- a/HIRS_Utils/src/test/java/hirs/data/persist/certificate/PlatformCredentialTest.java +++ b/HIRS_Utils/src/test/java/hirs/data/persist/certificate/PlatformCredentialTest.java @@ -68,6 +68,12 @@ public class PlatformCredentialTest { static final String TEST_PLATFORM_CERT2_1 = "/validation/platform_credentials_2/basic_plat_cert.pem"; + /** + * Platform Certificate spec 2. + */ + static final String TEST_PLATFORM_CERT2_SPEC2 = + "/validation/platform_credentials_2/large_attribute_spec2.txt"; + /** * Platform Certificate 2.0 with all the expected data. */ @@ -659,6 +665,49 @@ public class PlatformCredentialTest { } + /** + * Tests Platform Configuration Values. View platform Properties + * + * @throws IOException if an IO error occurs during processing + * @throws URISyntaxException if there is a problem constructing the cert's URI + */ + @Test + public final void testPlatformConfiguarion5() throws IOException, URISyntaxException { + + URL resource = this.getClass().getResource(TEST_PLATFORM_CERT2_SPEC2); + Path certPath = Paths.get(resource.toURI()); + + PlatformCredential platformCert = new PlatformCredential(certPath); + PlatformConfiguration platformConfig = platformCert.getPlatformConfiguration(); + + //Check component identifier + List