Skip to content

Commit 744aeab

Browse files
authored
Merge pull request #394 from nsacyber/unit-test-delta-fix
Delta Component Unit Tests Fixes
2 parents 54b45f1 + 14ecd98 commit 744aeab

File tree

3 files changed

+70
-39
lines changed

3 files changed

+70
-39
lines changed

HIRS_Utils/src/main/java/hirs/validation/SupplyChainCredentialValidator.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,21 +321,21 @@ public AppraisalStatus validateDeltaPlatformCredentialAttributes(
321321

322322
// this needs to be a loop for all deltas, link to issue #110
323323
// check that they don't have the same serial number
324-
for (PlatformCredential delta : deltaMapping.keySet()) {
324+
for (PlatformCredential pc : deltaMapping.keySet()) {
325325
if (!basePlatformCredential.getPlatformSerial()
326-
.equals(delta.getPlatformSerial())) {
326+
.equals(pc.getPlatformSerial())) {
327327
message = String.format("Base and Delta platform serial "
328328
+ "numbers do not match (%s != %s)",
329-
delta.getPlatformSerial(),
329+
pc.getPlatformSerial(),
330330
basePlatformCredential.getPlatformSerial());
331331
LOGGER.error(message);
332332
return new AppraisalStatus(FAIL, message);
333333
}
334334
// none of the deltas should have the serial number of the base
335-
if (basePlatformCredential.getSerialNumber()
336-
.equals(delta.getSerialNumber())) {
335+
if (!pc.isBase() && basePlatformCredential.getSerialNumber()
336+
.equals(pc.getSerialNumber())) {
337337
message = String.format("Delta Certificate with same serial number as base. (%s)",
338-
delta.getSerialNumber());
338+
pc.getSerialNumber());
339339
LOGGER.error(message);
340340
return new AppraisalStatus(FAIL, message);
341341
}

HIRS_Utils/src/test/java/hirs/validation/SupplyChainCredentialValidatorTest.java

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"javax.security.auth.*" })
100100
public class SupplyChainCredentialValidatorTest {
101101

102+
private static final String JSON_FILE = "/config/component-class.json";
102103
private static final String SAMPLE_PACCOR_OUTPUT_TXT = "sample_paccor_output.txt";
103104
private static final String SAMPLE_PACCOR_OUTPUT_NOT_SPECIFIED_TXT
104105
= "sample_paccor_output_not_specified_values.txt";
@@ -2028,29 +2029,41 @@ public final void testValidateDeltaPlatformCredentialAttributes()
20282029
PlatformCredential delta1 = mock(PlatformCredential.class);
20292030
PlatformCredential delta2 = mock(PlatformCredential.class);
20302031

2031-
ComponentIdentifier compId1 = new ComponentIdentifier(new DERUTF8String("Intel"),
2032+
ComponentIdentifierV2 compId1 = new ComponentIdentifierV2(
2033+
new ComponentClass(Paths.get(this.getClass()
2034+
.getResource(JSON_FILE).toURI()), "0x00010002"),
2035+
new DERUTF8String("Intel"),
20322036
new DERUTF8String("Core i7"), new DERUTF8String("Not Specified"),
20332037
new DERUTF8String("Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz"), null,
2034-
ASN1Boolean.TRUE, new ArrayList<>(0));
2035-
ComponentIdentifier compId2 = new ComponentIdentifier(
2038+
ASN1Boolean.TRUE, new ArrayList<>(0), null, null,
2039+
null);
2040+
ComponentIdentifierV2 compId2 = new ComponentIdentifierV2(
2041+
new ComponentClass(Paths.get(this.getClass()
2042+
.getResource(JSON_FILE).toURI()), "0x00050004"),
20362043
new DERUTF8String("Intel Corporation"),
20372044
new DERUTF8String("Ethernet Connection I217-V-faulty"),
20382045
new DERUTF8String("23:94:17:ba:86:5e"), new DERUTF8String("00"), null,
2039-
ASN1Boolean.FALSE, new ArrayList<>(0));
2040-
ComponentIdentifier compId3 = new ComponentIdentifier(
2046+
ASN1Boolean.FALSE, new ArrayList<>(0), null, null,
2047+
null);
2048+
ComponentIdentifierV2 compId3 = new ComponentIdentifierV2(
2049+
new ComponentClass(Paths.get(this.getClass()
2050+
.getResource(JSON_FILE).toURI()), "0x00090002"),
20412051
new DERUTF8String("Intel Corporation"),
20422052
new DERUTF8String("82580 Gigabit Network Connection-faulty"),
20432053
new DERUTF8String("90:e2:ba:31:83:10"), new DERUTF8String(""), null,
2044-
ASN1Boolean.FALSE, new ArrayList<>(0));
2054+
ASN1Boolean.FALSE, new ArrayList<>(0), null, null,
2055+
null);
20452056
ComponentIdentifierV2 deltaCompId2 = new ComponentIdentifierV2(
2046-
new ComponentClass(),
2057+
new ComponentClass(Paths.get(this.getClass()
2058+
.getResource(JSON_FILE).toURI()), "0x00050004"),
20472059
new DERUTF8String("Intel Corporation"),
20482060
new DERUTF8String("Ethernet Connection I217-V"),
20492061
new DERUTF8String("23:94:17:ba:86:5e"), new DERUTF8String("00"), null,
20502062
ASN1Boolean.FALSE, new ArrayList<>(0), null, null,
20512063
AttributeStatus.ADDED);
20522064
ComponentIdentifierV2 deltaCompId3 = new ComponentIdentifierV2(
2053-
new ComponentClass(),
2065+
new ComponentClass(Paths.get(this.getClass()
2066+
.getResource(JSON_FILE).toURI()), "0x00090002"),
20542067
new DERUTF8String("Intel Corporation"),
20552068
new DERUTF8String("82580 Gigabit Network Connection"),
20562069
new DERUTF8String("90:e2:ba:31:83:10"), new DERUTF8String(""), null,
@@ -2060,6 +2073,7 @@ public final void testValidateDeltaPlatformCredentialAttributes()
20602073
ComponentIdentifierV2 ciV21Faulty = new ComponentIdentifierV2();
20612074
ComponentIdentifierV2 ciV22Faulty = new ComponentIdentifierV2();
20622075
ciV21Faulty.setComponentManufacturer(compId2.getComponentManufacturer());
2076+
ciV21Faulty.setComponentClass(compId2.getComponentClass());
20632077
ciV21Faulty.setComponentModel(compId2.getComponentModel());
20642078
ciV21Faulty.setComponentSerial(compId2.getComponentSerial());
20652079
ciV21Faulty.setComponentRevision(compId2.getComponentRevision());
@@ -2068,6 +2082,7 @@ public final void testValidateDeltaPlatformCredentialAttributes()
20682082
ciV21Faulty.setComponentAddress(compId2.getComponentAddress());
20692083
ciV21Faulty.setAttributeStatus(AttributeStatus.REMOVED);
20702084
ciV22Faulty.setComponentManufacturer(compId3.getComponentManufacturer());
2085+
ciV22Faulty.setComponentClass(compId3.getComponentClass());
20712086
ciV22Faulty.setComponentModel(compId3.getComponentModel());
20722087
ciV22Faulty.setComponentSerial(compId3.getComponentSerial());
20732088
ciV22Faulty.setComponentRevision(compId3.getComponentRevision());
@@ -2094,17 +2109,17 @@ public final void testValidateDeltaPlatformCredentialAttributes()
20942109
when(base.getManufacturer()).thenReturn("innotek GmbH");
20952110
when(base.getModel()).thenReturn("VirtualBox");
20962111
when(base.getVersion()).thenReturn("1.2");
2097-
when(base.getPlatformSerial()).thenReturn("0");
2098-
when(delta1.getPlatformSerial()).thenReturn("0");
2099-
when(delta2.getPlatformSerial()).thenReturn("0");
2112+
when(base.getPlatformSerial()).thenReturn("62UIAE5");
2113+
when(delta1.getPlatformSerial()).thenReturn("62UIAE5");
2114+
when(delta2.getPlatformSerial()).thenReturn("62UIAE5");
21002115
when(base.getPlatformType()).thenReturn("base");
21012116
when(delta1.getPlatformType()).thenReturn("delta");
21022117
when(delta2.getPlatformType()).thenReturn("delta");
2103-
when(base.getSerialNumber()).thenReturn(BigInteger.ZERO);
2104-
when(delta1.getSerialNumber()).thenReturn(BigInteger.ONE);
2105-
when(delta2.getSerialNumber()).thenReturn(BigInteger.TEN);
2106-
when(delta1.getHolderSerialNumber()).thenReturn(BigInteger.ZERO);
2107-
when(delta2.getHolderSerialNumber()).thenReturn(BigInteger.ONE);
2118+
when(base.getSerialNumber()).thenReturn(BigInteger.valueOf(01));
2119+
when(delta1.getSerialNumber()).thenReturn(BigInteger.valueOf(39821));
2120+
when(delta2.getSerialNumber()).thenReturn(BigInteger.valueOf(39822));
2121+
when(delta1.getHolderSerialNumber()).thenReturn(BigInteger.valueOf(02));
2122+
when(delta2.getHolderSerialNumber()).thenReturn(BigInteger.valueOf(39821));
21082123
when(base.getComponentIdentifiers()).thenReturn(compList);
21092124
when(delta1.getComponentIdentifiers()).thenReturn(delta1List);
21102125
when(delta2.getComponentIdentifiers()).thenReturn(delta2List);
@@ -2129,9 +2144,9 @@ public final void testValidateDeltaPlatformCredentialAttributes()
21292144
AppraisalStatus result = supplyChainCredentialValidator
21302145
.validateDeltaPlatformCredentialAttributes(delta2,
21312146
deviceInfoReport, base, chainCredentials);
2132-
Assert.assertEquals(result.getAppStatus(), AppraisalStatus.Status.PASS);
21332147
Assert.assertEquals(result.getMessage(),
21342148
SupplyChainCredentialValidator.PLATFORM_ATTRIBUTES_VALID);
2149+
Assert.assertEquals(result.getAppStatus(), AppraisalStatus.Status.PASS);
21352150
}
21362151

21372152
/**
@@ -2149,22 +2164,33 @@ public final void testValidateChainFailure()
21492164
PlatformCredential base = mock(PlatformCredential.class);
21502165
PlatformCredential delta1 = mock(PlatformCredential.class);
21512166

2152-
ComponentIdentifier compId1 = new ComponentIdentifier(new DERUTF8String("Intel"),
2167+
ComponentIdentifierV2 compId1 = new ComponentIdentifierV2(
2168+
new ComponentClass(Paths.get(this.getClass()
2169+
.getResource(JSON_FILE).toURI()), "0x00010002"),
2170+
new DERUTF8String("Intel"),
21532171
new DERUTF8String("Core i7"), new DERUTF8String("Not Specified"),
21542172
new DERUTF8String("Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz"), null,
2155-
ASN1Boolean.TRUE, new ArrayList<>(0));
2156-
ComponentIdentifier compId2 = new ComponentIdentifier(
2173+
ASN1Boolean.TRUE, new ArrayList<>(0), null, null,
2174+
null);
2175+
ComponentIdentifierV2 compId2 = new ComponentIdentifierV2(
2176+
new ComponentClass(Paths.get(this.getClass()
2177+
.getResource(JSON_FILE).toURI()), "0x00050004"),
21572178
new DERUTF8String("Intel Corporation"),
21582179
new DERUTF8String("Ethernet Connection I217-V-faulty"),
21592180
new DERUTF8String("23:94:17:ba:86:5e"), new DERUTF8String("00"), null,
2160-
ASN1Boolean.FALSE, new ArrayList<>(0));
2161-
ComponentIdentifier compId3 = new ComponentIdentifier(
2181+
ASN1Boolean.FALSE, new ArrayList<>(0), null, null,
2182+
null);
2183+
ComponentIdentifierV2 compId3 = new ComponentIdentifierV2(
2184+
new ComponentClass(Paths.get(this.getClass()
2185+
.getResource(JSON_FILE).toURI()), "0x00090002"),
21622186
new DERUTF8String("Intel Corporation"),
21632187
new DERUTF8String("82580 Gigabit Network Connection-faulty"),
21642188
new DERUTF8String("90:e2:ba:31:83:10"), new DERUTF8String(""), null,
2165-
ASN1Boolean.FALSE, new ArrayList<>(0));
2189+
ASN1Boolean.FALSE, new ArrayList<>(0), null, null,
2190+
null);
21662191
ComponentIdentifierV2 deltaCompId2 = new ComponentIdentifierV2(
2167-
new ComponentClass(),
2192+
new ComponentClass(Paths.get(this.getClass()
2193+
.getResource(JSON_FILE).toURI()), "0x00050004"),
21682194
new DERUTF8String("Intel Corporation"),
21692195
new DERUTF8String("Ethernet Connection I217-V"),
21702196
new DERUTF8String("23:94:17:ba:86:5e"), new DERUTF8String("00"), null,
@@ -2231,12 +2257,8 @@ public final void testValidateChainFailure()
22312257
deviceInfoReport, base, chainCredentials);
22322258
Assert.assertEquals(result.getAppStatus(), AppraisalStatus.Status.FAIL);
22332259
Assert.assertEquals(result.getMessage(),
2234-
"Delta Certificate with same serial number as base. (0)");
2235-
// Assert.assertEquals(result.getMessage(),
2236-
// "There are unmatched components:\n"
2237-
// + "Manufacturer=Intel Corporation, Model=82580 "
2238-
// + "Gigabit Network Connection-faulty, "
2239-
// + "Serial=90:e2:ba:31:83:10, Revision=;\n");
2260+
"There are 1 unmatched components on the Platform Certificate:\n"
2261+
+ "COMPID=370101885;1");
22402262
}
22412263

22422264
/**

HIRS_Utils/src/test/resources/hirs/validation/sample_paccor_output.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@
55
},
66
"COMPONENTS": [
77
{
8-
"MANUFACTURER": "Intel","MODEL": "Core i7","SERIAL": "Not Specified","REVISION": "Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz"
8+
"COMPONENTCLASS": {
9+
"COMPONENTCLASSREGISTRY": "2.23.133.18.3.1",
10+
"COMPONENTCLASSVALUE": "00010002"
11+
},"MANUFACTURER": "Intel","MODEL": "Core i7","SERIAL": "Not Specified","REVISION": "Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz"
912
},
1013
{
11-
"MANUFACTURER": "Intel Corporation","MODEL": "Ethernet Connection I217-V", "FIELDREPLACEABLE": "false","SERIAL": "23:94:17:ba:86:5e", "REVISION": "00"
14+
"COMPONENTCLASS": {
15+
"COMPONENTCLASSREGISTRY": "2.23.133.18.3.1",
16+
"COMPONENTCLASSVALUE": "00050004"
17+
},"MANUFACTURER": "Intel Corporation","MODEL": "Ethernet Connection I217-V", "FIELDREPLACEABLE": "false","SERIAL": "23:94:17:ba:86:5e", "REVISION": "00"
1218
},
1319
{
14-
"MANUFACTURER": "Intel Corporation","MODEL": "82580 Gigabit Network Connection", "FIELDREPLACEABLE": "false", "SERIAL": "90:e2:ba:31:83:10", "REVISION": ""
20+
"COMPONENTCLASS": {
21+
"COMPONENTCLASSREGISTRY": "2.23.133.18.3.1",
22+
"COMPONENTCLASSVALUE": "00090002"
23+
},"MANUFACTURER": "Intel Corporation","MODEL": "82580 Gigabit Network Connection", "FIELDREPLACEABLE": "false", "SERIAL": "90:e2:ba:31:83:10", "REVISION": ""
1524
}
1625
],
1726
"PROPERTIES": [

0 commit comments

Comments
 (0)