Skip to content

Commit

Permalink
issue_865: finished making more corrections to the PR. should be good…
Browse files Browse the repository at this point in the history
… to go.
  • Loading branch information
ThatSilentCoder committed Oct 31, 2024
1 parent 7448d54 commit 09a57f0
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 489 deletions.
2 changes: 1 addition & 1 deletion HIRS_Utils/src/main/java/hirs/utils/digest/Digest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public final class Digest extends AbstractDigest {
columnDefinition = "varbinary(64)")
private final byte[] digest;

@Getter
@XmlElement
@Column(nullable = false)
@Enumerated(EnumType.ORDINAL)
@Getter
private final DigestAlgorithm algorithm;

/**
Expand Down
97 changes: 37 additions & 60 deletions HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/TcgTpmtHa.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,62 +21,76 @@ public class TcgTpmtHa {
* TCG ID for SHA1.
*/
public static final int TPM_ALG_SHA1 = 0x04;

/**
* TCG ID for SHA1.
*/
public static final int TPM_ALG_SHA256 = 0x0B;

/**
* TCG ID for SHA 384.
*/
public static final int TPM_ALG_SHA384 = 0x0C;

/**
* TCG ID for SHA512.
*/
public static final int TPM_ALG_SHA_512 = 0x0D;

/**
* TCG ID for Null algorithm.
*/
public static final int TPM_ALG_NULL = 0x10;

/**
* TCG ID for SHA1.
*/
public static final int TPM_ALG_SHA1_LENGTH = 20;

/**
* TCG ID for SHA1.
*/
public static final int TPM_ALG_SHA256_LENGTH = 32;

/**
* TCG ID for SHA 384.
*/
public static final int TPM_ALG_SHA384_LENGTH = 48;

/**
* TCG ID for SHA512.
*/
public static final int TPM_ALG_SHA512_LENGTH = 64;

/**
* TCG ID for Null algorithm.
*/
public static final int TPM_ALG_NULL_LENGTH = 0;

/**
* TCG Defined Algorithm Identifiers.
*/
@Getter
private int hashAlgId = 0;

/**
* Length of the hash.
*/
@Getter
private int hashLength = 0;

/**
* Human readable name of the hash algorithm.
* Human-readable name of the hash algorithm.
*/
@Getter
private String hashName = "";

/**
* Hash data.
*/
@Getter(value = AccessLevel.PROTECTED)
private byte[] digest = null;

/**
* buffer to hold the structure.
*/
Expand Down Expand Up @@ -111,27 +125,14 @@ public TcgTpmtHa(final ByteArrayInputStream is) throws IOException {
* @return name of the algorithm
*/
public static String tcgAlgIdToString(final int algId) {
String alg;
switch (algId) {
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_SHA_512:
alg = "TPM_ALG_SHA512";
break;
case TPM_ALG_NULL:
alg = "TPM_ALG_NULL";
break;
default:
alg = "Unknown or invalid Hash";
}
return alg;
return switch (algId) {
case TPM_ALG_SHA1 -> "TPM_ALG_SHA1";
case TPM_ALG_SHA256 -> "TPM_ALG_SHA256";
case TPM_ALG_SHA384 -> "TPM_ALG_SHA384";
case TPM_ALG_SHA_512 -> "TPM_ALG_SHA512";
case TPM_ALG_NULL -> "TPM_ALG_NULL";
default -> "Unknown or invalid Hash";
};
}

/**
Expand All @@ -143,25 +144,13 @@ public static String tcgAlgIdToString(final int algId) {
* @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":
default:
alg = TPM_ALG_NULL;
}
return alg;
return switch (algorithm) {
case "TPM_ALG_SHA1" -> TPM_ALG_SHA1;
case "TPM_ALG_SHA256" -> TPM_ALG_SHA256;
case "TPM_ALG_SHA384" -> TPM_ALG_SHA384;
case "TPM_ALG_SHA512" -> TPM_ALG_SHA_512;
default -> TPM_ALG_NULL;
};
}

/**
Expand All @@ -173,25 +162,13 @@ public static int tcgAlgStringToId(final String algorithm) {
* @return length of hash data in bytes
*/
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_LENGTH;
break;
case TPM_ALG_SHA384:
length = TPM_ALG_SHA384_LENGTH;
break;
case TPM_ALG_SHA_512:
length = TPM_ALG_SHA512_LENGTH;
break;
case TPM_ALG_NULL:
default:
length = TPM_ALG_NULL_LENGTH;
}
return length;
return switch (algId) {
case TPM_ALG_SHA1 -> TPM_ALG_SHA1_LENGTH;
case TPM_ALG_SHA256 -> TPM_ALG_SHA256_LENGTH;
case TPM_ALG_SHA384 -> TPM_ALG_SHA384_LENGTH;
case TPM_ALG_SHA_512 -> TPM_ALG_SHA512_LENGTH;
default -> TPM_ALG_NULL_LENGTH;
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public class EvPostCode {
* Event Description.
*/
private String codeInfo = "";

/**
* String type flag.
*/
private boolean bisString = false;

/**
* Firmware object.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
* \ |-------------------------|
*/
public class UefiSignatureList {
/**
* Array List of Signature found in the list.
*/
private final ArrayList<UefiSignatureData> sigList = new ArrayList<>();
/**
* Size of the signature list.
*/
Expand Down Expand Up @@ -93,18 +97,16 @@ public class UefiSignatureList {
* Current status of Signature List data.
*/
private String dataInvalidStatus = "Signature List data validity is undetermined yet";
/**
* Array List of Signature found in the list.
*/
private final ArrayList<UefiSignatureData> sigList = new ArrayList<UefiSignatureData>();
/**
* Input Stream for processing.
*/
private ByteArrayInputStream efiSigDataIS = null;

/**
* Type of signature.
*/
private UefiGuid signatureType = null;

/**
* Track status of vendor-table.json.
*/
Expand Down Expand Up @@ -212,16 +214,11 @@ private void processSignatureList(final byte[] efiSigData)
* @return true if the GUID is a valid GUID for Signature List Type, false if not.
*/
public boolean isValidSigListGUID(final UefiGuid guid) {
switch (guid.getVendorTableReference()) {
case "EFI_CERT_SHA256_GUID":
case "EFI_CERT_X509_SHA256":
case "EFI_CERT_X509_SHA384":
case "EFI_CERT_X509_SHA512":
case "EFI_CERT_X509_GUID":
return true;
default:
return false;
}
return switch (guid.getVendorTableReference()) {
case "EFI_CERT_SHA256_GUID", "EFI_CERT_X509_SHA256", "EFI_CERT_X509_SHA384",
"EFI_CERT_X509_SHA512", "EFI_CERT_X509_GUID" -> true;
default -> false;
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public class CanonicalizationMethodType {
@XmlAnyElement(lax = true)
protected List<Object> content;

@Setter
@Getter
@Setter
@XmlAttribute(name = "Algorithm", required = true)
@XmlSchemaType(name = "anyURI")
protected String algorithm;
Expand Down
4 changes: 2 additions & 2 deletions HIRS_Utils/src/main/java/hirs/utils/xjc/DSAKeyValueType.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
* &lt;/complexType>
* </pre>
*/
@Setter
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DSAKeyValueType", propOrder = {
"p",
Expand All @@ -58,7 +58,7 @@
public class DSAKeyValueType {
@XmlElement(name = "P")
protected byte[] p;

@XmlElement(name = "Q")
protected byte[] q;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public class DigestMethodType {
@XmlAnyElement(lax = true)
protected List<Object> content;

@Setter
@Getter
@Setter
@XmlAttribute(name = "Algorithm", required = true)
@XmlSchemaType(name = "anyURI")
protected String algorithm;
Expand Down
2 changes: 1 addition & 1 deletion HIRS_Utils/src/main/java/hirs/utils/xjc/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public class Entity
@XmlElement(name = "Meta")
protected List<Meta> meta;

@Setter
@Getter
@Setter
@XmlAttribute(name = "name", required = true)
protected String name;

Expand Down
2 changes: 1 addition & 1 deletion HIRS_Utils/src/main/java/hirs/utils/xjc/Evidence.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
* &lt;/complexType>
* </pre>
*/
@Setter
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Evidence", namespace = "http://standards.iso.org/iso/19770/-2/2015/schema.xsd")
public class Evidence
Expand Down
2 changes: 1 addition & 1 deletion HIRS_Utils/src/main/java/hirs/utils/xjc/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
* &lt;/complexType>
* </pre>
*/
@Setter
@Getter
@Setter
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "File", namespace = "http://standards.iso.org/iso/19770/-2/2015/schema.xsd")
public class File
Expand Down
2 changes: 1 addition & 1 deletion HIRS_Utils/src/main/java/hirs/utils/xjc/KeyInfoType.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public class KeyInfoType {
@XmlAnyElement(lax = true)
protected List<Object> content;

@Setter
@Getter
@Setter
@XmlAttribute(name = "Id")
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlID
Expand Down
2 changes: 1 addition & 1 deletion HIRS_Utils/src/main/java/hirs/utils/xjc/KeyValueType.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class KeyValueType {
*/
public List<Object> getContent() {
if (content == null) {
content = new ArrayList<Object>();
content = new ArrayList<>();
}
return this.content;
}
Expand Down
Loading

0 comments on commit 09a57f0

Please sign in to comment.