Skip to content

Commit

Permalink
Corrected an issue with the root CA looking itself causing an issue
Browse files Browse the repository at this point in the history
because the one root CA had an illegal character.
  • Loading branch information
cyrus-dev committed Oct 10, 2023
1 parent 556322a commit ec39bf5
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public interface CACredentialRepository extends JpaRepository<CertificateAuthori
List<CertificateAuthorityCredential> findBySubject(String subject);
List<CertificateAuthorityCredential> findBySubjectSorted(String subject);
CertificateAuthorityCredential findBySubjectKeyIdentifier(byte[] subjectKeyIdentifier);
CertificateAuthorityCredential findBySubjectKeyIdString(String subjectKeyIdString);
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public DataTableResponse<HashMap<String, Object>> getTableData(
if (pagedResult.hasContent()) {
deviceList.addAll(pagedResult.getContent());
}
deviceList.setRecordsTotal(deviceRepository.count());
deviceList.setRecordsFiltered(deviceList.size());
deviceList.setRecordsTotal(input.getLength());
deviceList.setRecordsFiltered(deviceRepository.count());

FilteredRecordsList<HashMap<String, Object>> records
= retrieveDevicesAndAssociatedCertificates(deviceList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ public DataTableResponse<ReferenceManifest> getTableData(
log.info("Querying with the following dataTableInput: " + input.toString());

FilteredRecordsList<ReferenceManifest> records = new FilteredRecordsList<>();
int itemCount = 0;
int currentPage = input.getStart() / input.getLength();
Pageable paging = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
org.springframework.data.domain.Page<ReferenceManifest> pagedResult = referenceManifestRepository.findAll(paging);
Expand All @@ -128,12 +127,11 @@ public DataTableResponse<ReferenceManifest> getTableData(
for (ReferenceManifest manifest : pagedResult.getContent()) {
if (!manifest.getRimType().equals(ReferenceManifest.MEASUREMENT_RIM)) {
records.add(manifest);
itemCount++;
}
}
}
records.setRecordsTotal(referenceManifestRepository.count());
records.setRecordsFiltered(itemCount);
records.setRecordsTotal(input.getLength());
records.setRecordsFiltered(referenceManifestRepository.count());

log.debug("Returning list of size: " + records.size());
return new DataTableResponse<>(records, input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public void modify(final CriteriaQuery criteriaQuery) {
if (pagedResult.hasContent()) {
referenceDigestValues.addAll(pagedResult.getContent());
}
referenceDigestValues.setRecordsTotal(referenceDigestValueRepository.count());
referenceDigestValues.setRecordsFiltered(referenceDigestValues.size());
referenceDigestValues.setRecordsTotal(input.getLength());
referenceDigestValues.setRecordsFiltered(referenceDigestValueRepository.count());

// FilteredRecordsList<ReferenceDigestValue> referenceDigestValues =
// OrderedListQueryDataTableAdapter.getOrderedList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -149,15 +150,14 @@ public static Certificate containsAllChain(
final Certificate certificate,
final CertificateRepository certificateRepository,
final CACredentialRepository caCredentialRepository) {
List<CertificateAuthorityCredential> issuerCertificates = new LinkedList<>();
List<CertificateAuthorityCredential> issuerCertificates = new ArrayList<>();
CertificateAuthorityCredential skiCA = null;
String issuerResult;

//Check if there is a subject organization
if (certificate.getAuthorityKeyIdentifier() != null
&& !certificate.getAuthorityKeyIdentifier().isEmpty()) {
byte[] bytes = Hex.decode(certificate.getAuthorityKeyIdentifier());
skiCA = caCredentialRepository.findBySubjectKeyIdentifier(bytes);
skiCA = caCredentialRepository.findBySubjectKeyIdString(certificate.getAuthorityKeyIdentifier());
} else {
log.error(String.format("Certificate (%s) for %s has no authority key identifier.",
certificate.getClass().toString(), certificate.getSubject()));
Expand Down Expand Up @@ -185,7 +185,7 @@ public static Certificate containsAllChain(
if (issuerResult.isEmpty()) {
//Check if it's root certificate
if (BouncyCastleUtils.x500NameCompare(issuerCert.getIssuerSorted(),
issuerCert.getSubject())) {
issuerCert.getSubjectSorted())) {
return null;
}
return containsAllChain(issuerCert, certificateRepository, caCredentialRepository);
Expand Down
4 changes: 2 additions & 2 deletions HIRS_Utils/src/main/java/hirs/utils/BouncyCastleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static boolean x500NameCompare(final String nameValue1, final String name
X500Name x500Name2;

try {
x500Name1 = new X500Name(nameValue1.replace(SEPARATOR_PLUS, SEPARATOR_COMMA));
x500Name2 = new X500Name(nameValue2.replace(SEPARATOR_PLUS, SEPARATOR_COMMA));
x500Name1 = new X500Name(nameValue1);
x500Name2 = new X500Name(nameValue2);
result = x500Name1.equals(x500Name2);
} catch (IllegalArgumentException iaEx) {
log.error(iaEx.toString());
Expand Down

0 comments on commit ec39bf5

Please sign in to comment.