mirror of
https://github.com/nsacyber/HIRS.git
synced 2024-12-19 04:58:00 +00:00
Added methods to retrieve event log hash algorithm and algorithm id
This commit is contained in:
parent
8b36d2636b
commit
f3da6b44ac
@ -10,7 +10,7 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Interface for handling different formats of TCG Event logs.
|
||||
* Class for handling different formats of TCG Event logs.
|
||||
*/
|
||||
public class TCGEventLog {
|
||||
|
||||
@ -90,9 +90,15 @@ public class TCGEventLog {
|
||||
this.hashType = hashType;
|
||||
this.initValue = initValue;
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(rawlog);
|
||||
// Process the 1st entry as a SHA1 format (per the spec)
|
||||
eventList.add(new TpmPcrEvent1(is));
|
||||
// put all events into an event list for further processing
|
||||
while (is.available() > 0) {
|
||||
eventList.add(new TpmPcrEvent1(is));
|
||||
if (hashType.compareToIgnoreCase(HASH_STRING) == 0) {
|
||||
eventList.add(new TpmPcrEvent1(is));
|
||||
} else {
|
||||
eventList.add(new TpmPcrEvent2(is));
|
||||
}
|
||||
}
|
||||
calculatePcrValues();
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public class TCGEventLogProcessor {
|
||||
/**
|
||||
* Name of the hash algorithm used to process the Event Log, default is SHA256.
|
||||
*/
|
||||
private String algorithm = "SHA256";
|
||||
private String algorithm = "TPM_ALG_SHA256";
|
||||
/**
|
||||
* Parsed event log array.
|
||||
*/
|
||||
@ -52,7 +52,7 @@ public class TCGEventLogProcessor {
|
||||
TCGEventLog.HASH256_STRING, TCGEventLog.INIT_SHA256_LIST);
|
||||
} else {
|
||||
tcgLog = new TCGEventLog(rawLog);
|
||||
algorithm = "SHA";
|
||||
algorithm = "TPM_ALG_SHA1";
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,6 +75,24 @@ public class TCGEventLogProcessor {
|
||||
return tcgLog.getExpectedPCRValue(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the TCG Algorithm Registry defined string for the Digest Algorithm
|
||||
* used in the event log.
|
||||
* @return TCG Defined Algorithm name
|
||||
*/
|
||||
public String getEventLogHashAlgorithm() {
|
||||
return algorithm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the TCG Algorithm Registry defined ID for the Digest Algorithm
|
||||
* used in the event log.
|
||||
* @return TCG Defined Algorithm name
|
||||
*/
|
||||
public int getEventLogHashAlgorithmID() {
|
||||
return TcgTpmtHa.tcgAlgStringtoId(algorithm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a TPM baseline using the expected PCR Values.
|
||||
* Expected PCR Values were Calculated from the EventLog (RIM Support file).
|
||||
@ -87,7 +105,7 @@ public class TCGEventLogProcessor {
|
||||
TPMMeasurementRecord record;
|
||||
String pcrValue;
|
||||
for (int i = 0; i < TpmPcrEvent.PCR_COUNT; i++) {
|
||||
if (algorithm.compareToIgnoreCase("SHA1") == 0) { // Log Was SHA1 Format
|
||||
if (algorithm.compareToIgnoreCase("TPM_ALG_SHA1") == 0) { // Log Was SHA1 Format
|
||||
pcrValue = tcgLog.getExpectedPCRValue(i);
|
||||
byte[] hexValue = HexUtils.hexStringToByteArray(pcrValue);
|
||||
final Digest hash = new Digest(DigestAlgorithm.SHA1, hexValue);
|
||||
|
@ -34,43 +34,43 @@ public class TcgTpmtHa {
|
||||
/**
|
||||
* TCG ID for SHA1.
|
||||
*/
|
||||
private static final int TPM_ALG_SHA1 = 0x04;
|
||||
public static final int TPM_ALG_SHA1 = 0x04;
|
||||
/**
|
||||
* TCG ID for SHA1.
|
||||
*/
|
||||
private static final int TPM_ALG_SHA256 = 0x0B;
|
||||
public static final int TPM_ALG_SHA256 = 0x0B;
|
||||
/**
|
||||
* TCG ID for SHA 384.
|
||||
*/
|
||||
private static final int TPM_ALG_SHA384 = 0x0C;
|
||||
public static final int TPM_ALG_SHA384 = 0x0C;
|
||||
/**
|
||||
* TCG ID for SHA512.
|
||||
*/
|
||||
private static final int TPM_ALG_SHA_512 = 0x0D;
|
||||
public static final int TPM_ALG_SHA_512 = 0x0D;
|
||||
/**
|
||||
* TCG ID for Null algorithm.
|
||||
*/
|
||||
private static final int TPM_ALG_NULL = 0x10;
|
||||
public static final int TPM_ALG_NULL = 0x10;
|
||||
/**
|
||||
* TCG ID for SHA1.
|
||||
*/
|
||||
private static final int TPM_ALG_SHA1_LENGTH = 20;
|
||||
public static final int TPM_ALG_SHA1_LENGTH = 20;
|
||||
/**
|
||||
* TCG ID for SHA1.
|
||||
*/
|
||||
private static final int TPM_ALG_SHA256_LENGH = 32;
|
||||
public static final int TPM_ALG_SHA256_LENGTH = 32;
|
||||
/**
|
||||
* TCG ID for SHA 384.
|
||||
*/
|
||||
private static final int TPM_ALG_SHA384_LENGTH = 48;
|
||||
public static final int TPM_ALG_SHA384_LENGTH = 48;
|
||||
/**
|
||||
* TCG ID for SHA512.
|
||||
*/
|
||||
private static final int TPM_ALG_SHA512_LENGTH = 64;
|
||||
public static final int TPM_ALG_SHA512_LENGTH = 64;
|
||||
/**
|
||||
* TCG ID for Null algorithm.
|
||||
*/
|
||||
private static final int TPM_ALG_NULL_LENGTH = 0;
|
||||
public static final int TPM_ALG_NULL_LENGTH = 0;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -139,8 +139,9 @@ public class TcgTpmtHa {
|
||||
* Only hash algorithms found in Table 7 are used.
|
||||
*
|
||||
* @param algid int to convert to string
|
||||
* @return name of the algorithm
|
||||
*/
|
||||
private String tcgAlgIdtoString(final int algid) {
|
||||
public static String tcgAlgIdtoString(final int algid) {
|
||||
String alg;
|
||||
switch (algid) {
|
||||
case TPM_ALG_SHA1:
|
||||
@ -164,6 +165,38 @@ public class TcgTpmtHa {
|
||||
return alg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the TCG defined ID via a lookup o the TCG Defined Algorithm String.
|
||||
* Lookup based upon section 6.3 for the TPM-Rev-2.0-Part-2-Structures.pdf document.
|
||||
* Only hash algorithms found in Table 7 are used.
|
||||
*
|
||||
* @param algorithm String to convert to an id
|
||||
* @return id of hash algorithm
|
||||
*/
|
||||
public static int tcgAlgStringtoId(final String algorithm) {
|
||||
int alg;
|
||||
switch (algorithm) {
|
||||
case "TPM_ALG_SHA1":
|
||||
alg = TPM_ALG_SHA1;
|
||||
break;
|
||||
case "TPM_ALG_SHA256":
|
||||
alg = TPM_ALG_SHA256;
|
||||
break;
|
||||
case "TPM_ALG_SHA384":
|
||||
alg = TPM_ALG_SHA384;
|
||||
break;
|
||||
case "TPM_ALG_SHA512":
|
||||
alg = TPM_ALG_SHA_512;
|
||||
break;
|
||||
case "TPM_ALG_NULL":
|
||||
alg = TPM_ALG_NULL;
|
||||
break;
|
||||
default:
|
||||
alg = TPM_ALG_NULL;
|
||||
}
|
||||
return alg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the length of a given TPM ALG Identifier.
|
||||
* (lookup based upon section 6.3 for the TPM-Rev-2.0-Part-2-Structures.pdf document)
|
||||
@ -172,14 +205,14 @@ public class TcgTpmtHa {
|
||||
* @param algId TCG defined Algorithm identifier
|
||||
* @return length of hash data in bytes
|
||||
*/
|
||||
private int tcgAlgLength(final int algId) {
|
||||
public static int tcgAlgLength(final int algId) {
|
||||
int length;
|
||||
switch (algId) {
|
||||
case TPM_ALG_SHA1:
|
||||
length = TPM_ALG_SHA1_LENGTH;
|
||||
break;
|
||||
case TPM_ALG_SHA256:
|
||||
length = TPM_ALG_SHA256_LENGH;
|
||||
length = TPM_ALG_SHA256_LENGTH;
|
||||
break;
|
||||
case TPM_ALG_SHA384:
|
||||
length = TPM_ALG_SHA384_LENGTH;
|
||||
|
@ -105,6 +105,11 @@ public class TCGEventLogProcessorTest extends SpringPersistenceTest {
|
||||
// Test 2 get an individual PCR
|
||||
String pcr3 = tlp.getExpectedPCRValue(3);
|
||||
Assert.assertEquals(pcr3, pcrFromLog[3]);
|
||||
// Test 3 check the Algorithm Identifiers used in the log
|
||||
String algStr = tlp.getEventLogHashAlgorithm();
|
||||
Assert.assertEquals(algStr, "TPM_ALG_SHA256");
|
||||
int id = tlp.getEventLogHashAlgorithmID();
|
||||
Assert.assertEquals(id, TcgTpmtHa.TPM_ALG_SHA256);
|
||||
LOGGER.debug("OK. Parsing of a Crypto Agile Format Success");
|
||||
}
|
||||
|
||||
@ -135,6 +140,11 @@ public class TCGEventLogProcessorTest extends SpringPersistenceTest {
|
||||
// Test 2 get an individual PCR
|
||||
String pcr0 = tlp.getExpectedPCRValue(0);
|
||||
Assert.assertEquals(pcr0, pcrFromLog[0]);
|
||||
// Test 3 check the Algorithm Identifiers used in the log
|
||||
String algStr = tlp.getEventLogHashAlgorithm();
|
||||
Assert.assertEquals(algStr, "TPM_ALG_SHA1");
|
||||
int id = tlp.getEventLogHashAlgorithmID();
|
||||
Assert.assertEquals(id, TcgTpmtHa.TPM_ALG_SHA1);
|
||||
LOGGER.debug("OK. Parsing of a SHA1 formatted TCG Event Log Success");
|
||||
}
|
||||
|
||||
|
42
tools/tcg_rim_tool/generated_swidTag.swidtag
Normal file
42
tools/tcg_rim_tool/generated_swidTag.swidtag
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<SoftwareIdentity xmlns="http://standards.iso.org/iso/19770/-2/2015/schema.xsd" xmlns:ns2="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true">
|
||||
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
|
||||
<SignedInfo>
|
||||
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
|
||||
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
|
||||
<Reference URI="">
|
||||
<Transforms>
|
||||
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
|
||||
</Transforms>
|
||||
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
|
||||
<DigestValue>jfwo1CF30jTNX7m/j85Avnt0EedV/QJIsRUZnaOY+Dg=</DigestValue>
|
||||
</Reference>
|
||||
</SignedInfo>
|
||||
<SignatureValue>VqUHbt1UqkxlLHVkTOlQs54KWjv5IPKzSCxrsPb8kGjaj5XjHkc1Z/h88znIIMTdCLcyrKgNEXS4
|
||||
9EHI9nn9LmwXEd/ozKWd8adu6wLdxKj6uIfd0HaCLFrVlnf/b16xO9AW6wp5pLmXwoFi7zBXXJrn
|
||||
F9MDKy55mXkxb/Z5RUC3IKqsoz+EuKjs6d+yhtb1EQtpJD2dZj23+VjMH4gXxEerDNR1PiPhma/i
|
||||
QMFa1hwSO7AuasYPy0WCRIgrJ5ZL5x2ZoaSIdE2TsCqnStVL+KLZeMWNCqw4k89hsuELW7Azrl57
|
||||
Vm2qzPok0svrB1K4QyZdyK2bnG1QY3Fip5Jdmg==</SignatureValue>
|
||||
<KeyInfo>
|
||||
<X509Data>
|
||||
<X509SubjectName>CN=example.RIM.signer,OU=PCClient,O=Example,ST=VA,C=US</X509SubjectName>
|
||||
<X509Certificate>MIIDYTCCAkmgAwIBAgIJAPB+r6VBhBn4MA0GCSqGSIb3DQEBCwUAMFMxCzAJBgNVBAYTAlVTMQsw
|
||||
CQYDVQQIDAJWQTEQMA4GA1UECgwHRXhhbXBsZTERMA8GA1UECwwIUENDbGllbnQxEjAQBgNVBAMM
|
||||
CUV4YW1wbGVDQTAeFw0yMDAyMTAxODE1MzRaFw0yOTEyMTkxODE1MzRaMFwxCzAJBgNVBAYTAlVT
|
||||
MQswCQYDVQQIDAJWQTEQMA4GA1UECgwHRXhhbXBsZTERMA8GA1UECwwIUENDbGllbnQxGzAZBgNV
|
||||
BAMMEmV4YW1wbGUuUklNLnNpZ25lcjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKd1
|
||||
lWGkSRuxAAY2wHag2GVxUk1dZx2PTpfQOflvLeccAVwa8mQhlsRERq+QK8ilj8Xfqs44/nBaccZD
|
||||
OjdfIxIUCMfwhGXjxCaqZbgTucNsExDnu4arTGraoAwzHg0cVLiKT/Cxj9NL4dcMgxRXsPdHfXb0
|
||||
923C7xYd2t2qfW05umgaj7qeQl6c68CFNsGX4JA8rWFQZvvGx5DGlK4KTcjPuQQINs5fxasNKqLY
|
||||
2hq+z82x/rqwr2hmyizD6FpFSyIABPEMPfB036GEhRwu1WEMkq8yIp2jgRUoFYke9pB3ph9pVow0
|
||||
Hh4mNFSKD4pP41VSKY1nus83mdkuukPy5o0CAwEAAaMvMC0wCQYDVR0TBAIwADALBgNVHQ8EBAMC
|
||||
BsAwEwYDVR0lBAwwCgYIKwYBBQUHAwMwDQYJKoZIhvcNAQELBQADggEBAGuJ+dasb3/Mb7TBJ1Oe
|
||||
al5ISq8d2LQD5ke5qnjgSQWKXfQ9fcUy3dWnt3Oked/i8B/Tyk3jCdTZJU3J3iRNgTqFfMLP8rU1
|
||||
w2tPYBjjuPKiiK4YRBHPxtFxPdOL1BPmL4ZzNs33Lv6H0m4aff9p6QpMclX5b/CRjl+80JWRLiLj
|
||||
U3B0CejZB9dJrPr9SBaC31cDoeTpja9Cl86ip7KkqrZZIYeMuNF6ucWyWtjrW2kr3UhmEy8x/6y4
|
||||
KigsK8sBwmNv4N2Pu3RppeIcpjYj5NVA1hwRA4eeMgJp2u+urm3l1oo1UNX1HsSSBHp1Owc9zZLm
|
||||
07Pl8T46kpIA4sroCAU=</X509Certificate>
|
||||
</X509Data>
|
||||
</KeyInfo>
|
||||
</Signature>
|
||||
</SoftwareIdentity>
|
Loading…
Reference in New Issue
Block a user