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 componentIdentifier; + private URIReference componentIdentifierUri; private List platformProperties; private URIReference platformPropertiesUri; @@ -33,6 +21,7 @@ public class PlatformConfiguration { */ public PlatformConfiguration() { this.componentIdentifier = new ArrayList<>(); + this.componentIdentifierUri = null; this.platformProperties = new ArrayList<>(); this.platformPropertiesUri = null; } @@ -55,65 +44,45 @@ public class PlatformConfiguration { } /** - * 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 + * Constructor given the Platform Configuration values for V2 configuration. + * + * @param componentIdentifier list containing all the components inside the + * Platform Configuration. + * @param componentIdentifierUri object containing the URI Reference + * @param platformProperties list containing all the properties inside the + * Platform Configuration. + * @param platformPropertiesUri object containing the URI Reference */ - public PlatformConfiguration(final ASN1Sequence sequence) throws IllegalArgumentException { - - //Default values - this.componentIdentifier = new ArrayList<>(); - this.platformProperties = new ArrayList<>(); - this.platformPropertiesUri = 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)); - this.componentIdentifier.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)); - this.platformProperties.add(new PlatformProperty(property)); - } - break; - case PLATFORM_PROPERTIES_URI: - //Get platformPropertiesURI - ASN1Sequence propertiesUri = ASN1Sequence.getInstance(taggedSequence, false); - //Save properties URI - this.platformPropertiesUri = new URIReference(propertiesUri); - break; - default: - break; - } - } + public PlatformConfiguration(final List componentIdentifier, + final URIReference componentIdentifierUri, + final List platformProperties, + final URIReference platformPropertiesUri) { + this.componentIdentifier = componentIdentifier; + this.componentIdentifierUri = componentIdentifierUri; + this.platformProperties = platformProperties; + this.platformPropertiesUri = platformPropertiesUri; } - /** + /** * @return the componentIdentifier */ public List getComponentIdentifier() { return Collections.unmodifiableList(componentIdentifier); } + /** + * Add function for the component identifier array. + * @param componentIdentifier object to add + * @return status of the add, if successful or not + */ + protected boolean add(final ComponentIdentifier componentIdentifier) { + if (this.componentIdentifier != null) { + return this.componentIdentifier.add(componentIdentifier); + } + + return false; + } + /** * @param componentIdentifier the componentIdentifier to set */ @@ -121,6 +90,20 @@ public class PlatformConfiguration { this.componentIdentifier = componentIdentifier; } + /** + * @return the componentIdentifierUri + */ + public URIReference getComponentIdentifierUri() { + return componentIdentifierUri; + } + + /** + * @param componentIdentifierUri the componentIdentifierUri to set + */ + public void setComponentIdentifierUri(final URIReference componentIdentifierUri) { + this.componentIdentifierUri = componentIdentifierUri; + } + /** * @return the platformProperties */ @@ -128,6 +111,19 @@ public class PlatformConfiguration { return Collections.unmodifiableList(platformProperties); } + /** + * Add function for the platform property array. + * @param platformProperty property object to add + * @return status of the add, if successful or not + */ + protected boolean add(final PlatformProperty platformProperty) { + if (this.platformProperties != null) { + return this.platformProperties.add(platformProperty); + } + + return false; + } + /** * @param platformProperties the platformProperties to set */ diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/certificate/attributes/PlatformConfigurationV1.java b/HIRS_Utils/src/main/java/hirs/data/persist/certificate/attributes/PlatformConfigurationV1.java new file mode 100644 index 00000000..1f57345d --- /dev/null +++ b/HIRS_Utils/src/main/java/hirs/data/persist/certificate/attributes/PlatformConfigurationV1.java @@ -0,0 +1,76 @@ +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,
+ *      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 allComponents = platformConfig.getComponentIdentifier(); + Assert.assertFalse(allComponents.isEmpty()); + + List platformProperties = platformConfig.getPlatformProperties(); + if (platformProperties.isEmpty()) { + Assert.fail("Platform Properties is empty."); + } + Assert.assertEquals(platformProperties.size(), 3); + + PlatformProperty property; + + //Check property #1 + property = (PlatformProperty) platformProperties.get(0); + Assert.assertTrue(property.getPropertyName().getString().equals("AMT")); + Assert.assertTrue(property.getPropertyValue().getString().equals("true")); + + //Check property #2 + property = (PlatformProperty) platformProperties.get(1); + Assert.assertTrue(property.getPropertyName().getString().equals("vPro Enabled")); + Assert.assertTrue(property.getPropertyValue().getString().equals("true")); + + //Check property #3 + property = (PlatformProperty) platformProperties.get(2); + Assert.assertTrue(property.getPropertyName().getString().equals("DropShip Enabled")); + Assert.assertTrue(property.getPropertyValue().getString().equals("false")); + } + /** * Tests Platform Configuration Values. View platform Properties * diff --git a/HIRS_Utils/src/test/resources/validation/platform_credentials_2/large_attribute_spec2.txt b/HIRS_Utils/src/test/resources/validation/platform_credentials_2/large_attribute_spec2.txt new file mode 100644 index 0000000000000000000000000000000000000000..f7396e7212351fc954babaee40b8cc2cc3034863 GIT binary patch literal 2144 zcmbVNeQXnD7~fsL_HmPS8)ajlH$VhNug_gSt{q@#yRIvvrO+-4EW^@Ww}bXtuD8Mb z+!dMN_!vYo0!$}P4aA@bD3J+9z6AWh7&M5O7zf0FF~KMcPVuh$fH?m!CilntKJWAO z{@&;JJ4j{LLP~uSMGz3TcZ=IV+|VPofw-2;fh@J6MyW19D_mqLJS1mcsw5nlmu_kB&(1co=680xf>g^(|o&|o=% z5GRCiXEelzhMUU9v>r}iqPR28C*piaVB;KV0n=c^`XC?Tl8F${Z~`7^N+hB!xU(_D za=0g%Y#QpvQ|+!?7IX!Iqz(!PFO$1^^=g8Z^Ah2B406?3Guo=!Zs#IMjw%B!L>_rw zQSwdS!qa=_<#w*W{@bFgyvs1DXbc6U4Jgt?(v-;vOJswQ0<)1MfieQM1X7BpVS-xK zAgWL;SpZtdLJ<^2GNeaRDl;-N5b3Jv(_%6UH0fm~3c5ktI5HQcr;~isUzXHt+P6T4 zOG=VL6bO<5DfEI`BUMl#8k9_-CnUr1?i4y3=D-7LwRDiL7%KKJ&|#ViCb?3GCt5K_ zu);@6?E@_IiU;0wg>L2^5+DE0_q9G+Cf( zRGQHbh-LX|oHT2$@Hzg`NA^53ZJ{iB6OgcKRHnjoL(>*bzkeDqjWikz&YD|w!8q<< z@JcosW$JN93%-DG5ne)^c7GU?o^IBxr;PwLxYJ*Q&&4Ui0`96O!91#@CJ>4xo45un z&ugMdyO}f@T@KJY{f^d5o7D_12UP){QDM2hxHOOnCd@`yrXI_y_W0a^-~t~Wu$uq^ z#@0MD0A+E|G;IYlMT1>bTEK3DrctT>1-=rO(8%x{BS<)K921sFfqN*@rl0R^)mp>l z5Gl7r%4w=RY$*?$MU*0YCcyagIB5}Vw8x%DAqP{~y+KSV@J$R9Vpy}EkK-;bv|Pe+ z$Xbl$Rq*jdppi|CoTwt9Xp(ttj&4??AS9CI27^qkL^LEs;(RO?X^;tK7}_VKXoeRg z*)f=GMyt(aw3>)UAqJJ{!Brs&ayFFftp6cZEF72QtifQSt+dHX8?D5eSQJvoArSXU z9G{3Q#aBUm8N^-cY?<5rUPOf|LEH#S)R|>!M5WT8h|V`$NxF4XVCs_$-^_-YS7T!;9+PAfOp;S)!q;z}{^*(RnJfC6y}nvql_jtH zow=}L_%4!m)j{n&+yHI+zqlj_2{Em$1k7iv2U;CRaYJCU9!9P$kgNKkG%2LiH$A$dpq#4{zZ!2 zna<{tPwwoGH&e8MYG3W%>UATnb^5GfA1GpKHm4DIJe6AgZikOvhHd3rY@-# zULCkrdTd44bp!qLPdzuMbiVn`%}bllw9g_-KLqTs_6*(rXV>}8*nso&+``t+o<-k2 zd-vpT1#g@xD>*dZdnJ3vjJu_GtW#a@BAYJ!(AQtbY&^~0zpwafV#dks1&g;_v0I*7cd(;T+*+i2_>UWl^*1|7B6Z@qL#0#B-uk?DwXS%_ zZGTr==}VdiTKd|vRx(>3eCAq5*UR5)Z=73abMfa6yjH!XZhhdrtFGQPi@CM8V~!gy z+-)19YvJ762OhMQRerW}(#3Js4~#mje#7_9p2unC;qR7zf&cP5)jNwl(z$C~_;{fB c)>l)Xo$#ZkYu6bf<{;J}?0rm5P761SM literal 0 HcmV?d00001