Updated the CA certificate to truncate the prefix of the subject key identifier

This commit is contained in:
Cyrus 2022-02-23 07:53:07 -05:00
parent 2263a3567f
commit 00d8dfb3b5

View File

@ -25,6 +25,8 @@ public class CertificateAuthorityCredential extends Certificate {
*/ */
public static final String SUBJECT_KEY_IDENTIFIER_FIELD = "subjectKeyIdentifier"; public static final String SUBJECT_KEY_IDENTIFIER_FIELD = "subjectKeyIdentifier";
private static final int CA_BYTE_SIZE = 20;
@Column @Column
private final byte[] subjectKeyIdentifier; private final byte[] subjectKeyIdentifier;
@ -85,8 +87,16 @@ public class CertificateAuthorityCredential extends Certificate {
public CertificateAuthorityCredential(final byte[] certificateBytes) public CertificateAuthorityCredential(final byte[] certificateBytes)
throws IOException { throws IOException {
super(certificateBytes); super(certificateBytes);
this.subjectKeyIdentifier = byte[] tempBytes = getX509Certificate()
getX509Certificate().getExtensionValue(SUBJECT_KEY_IDENTIFIER_EXTENSION); .getExtensionValue(SUBJECT_KEY_IDENTIFIER_EXTENSION);
if (tempBytes.length > CA_BYTE_SIZE) {
this.subjectKeyIdentifier = truncatePrefixBytes(tempBytes);
} else {
this.subjectKeyIdentifier =
getX509Certificate().getExtensionValue(SUBJECT_KEY_IDENTIFIER_EXTENSION);
}
if (this.subjectKeyIdentifier != null) { if (this.subjectKeyIdentifier != null) {
this.subjectKeyIdString = Hex.encodeHexString(this.subjectKeyIdentifier); this.subjectKeyIdString = Hex.encodeHexString(this.subjectKeyIdentifier);
} }
@ -103,8 +113,18 @@ public class CertificateAuthorityCredential extends Certificate {
public CertificateAuthorityCredential(final Path certificatePath) public CertificateAuthorityCredential(final Path certificatePath)
throws IOException { throws IOException {
super(certificatePath); super(certificatePath);
this.subjectKeyIdentifier = byte[] tempBytes = getX509Certificate()
getX509Certificate().getExtensionValue(SUBJECT_KEY_IDENTIFIER_EXTENSION); .getExtensionValue(SUBJECT_KEY_IDENTIFIER_EXTENSION);
if (tempBytes.length > CA_BYTE_SIZE) {
this.subjectKeyIdentifier = truncatePrefixBytes(tempBytes);
} else {
this.subjectKeyIdentifier =
getX509Certificate().getExtensionValue(SUBJECT_KEY_IDENTIFIER_EXTENSION);
}
if (this.subjectKeyIdentifier != null) {
this.subjectKeyIdString = Hex.encodeHexString(this.subjectKeyIdentifier);
}
} }
/** /**
@ -141,6 +161,13 @@ public class CertificateAuthorityCredential extends Certificate {
return this.subjectKeyIdString; return this.subjectKeyIdString;
} }
private byte[] truncatePrefixBytes(final byte[] certificateBytes) {
byte[] temp = new byte[CA_BYTE_SIZE];
System.arraycopy(certificateBytes, 4, temp, 0, CA_BYTE_SIZE);
return temp;
}
@Override @Override
@SuppressWarnings("checkstyle:avoidinlineconditionals") @SuppressWarnings("checkstyle:avoidinlineconditionals")
public boolean equals(final Object o) { public boolean equals(final Object o) {