Updated how the platform certificate is accessed

This commit is contained in:
Cyrus 2024-03-18 14:57:05 -04:00
parent e0de63aa03
commit 32b10260fd
3 changed files with 10 additions and 8 deletions

View File

@ -25,7 +25,6 @@ public interface CertificateRepository extends JpaRepository<Certificate, UUID>
List<Certificate> findByType(String dType); List<Certificate> findByType(String dType);
@Query(value = "SELECT * FROM Certificate where serialNumber = ?1 AND DTYPE = ?2", nativeQuery = true) @Query(value = "SELECT * FROM Certificate where serialNumber = ?1 AND DTYPE = ?2", nativeQuery = true)
Certificate findBySerialNumber(BigInteger serialNumber, String dType); Certificate findBySerialNumber(BigInteger serialNumber, String dType);
Certificate findByPlatformSerialAndSerialNumber(String platformSerial, BigInteger serialNumber);
@Query(value = "SELECT * FROM Certificate where platformSerial = ?1 AND DTYPE = 'PlatformCredential'", nativeQuery = true) @Query(value = "SELECT * FROM Certificate where platformSerial = ?1 AND DTYPE = 'PlatformCredential'", nativeQuery = true)
List<PlatformCredential> byBoardSerialNumber(String boardSerialNumber); List<PlatformCredential> byBoardSerialNumber(String boardSerialNumber);
@Query(value = "SELECT * FROM Certificate where holderSerialNumber = ?1 AND DTYPE = 'PlatformCredential'", nativeQuery = true) @Query(value = "SELECT * FROM Certificate where holderSerialNumber = ?1 AND DTYPE = 'PlatformCredential'", nativeQuery = true)

View File

@ -6,6 +6,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.math.BigInteger;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -15,4 +16,5 @@ public interface PlatformCertificateRepository extends JpaRepository<PlatformCre
List<PlatformCredential> findByArchiveFlag(boolean archiveFlag); List<PlatformCredential> findByArchiveFlag(boolean archiveFlag);
Page<PlatformCredential> findByArchiveFlag(boolean archiveFlag, Pageable pageable); Page<PlatformCredential> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
List<PlatformCredential> findByDeviceId(UUID deviceId); List<PlatformCredential> findByDeviceId(UUID deviceId);
PlatformCredential findByPlatformSerialAndSerialNumber(String platformSerial, BigInteger serialNumber);
} }

View File

@ -4,6 +4,7 @@ import hirs.attestationca.persist.entity.manager.CertificateRepository;
import hirs.attestationca.persist.entity.manager.ComponentAttributeRepository; import hirs.attestationca.persist.entity.manager.ComponentAttributeRepository;
import hirs.attestationca.persist.entity.manager.ComponentInfoRepository; import hirs.attestationca.persist.entity.manager.ComponentInfoRepository;
import hirs.attestationca.persist.entity.manager.ComponentResultRepository; import hirs.attestationca.persist.entity.manager.ComponentResultRepository;
import hirs.attestationca.persist.entity.manager.PlatformCertificateRepository;
import hirs.attestationca.persist.entity.userdefined.certificate.ComponentResult; import hirs.attestationca.persist.entity.userdefined.certificate.ComponentResult;
import hirs.attestationca.persist.entity.userdefined.certificate.PlatformCredential; import hirs.attestationca.persist.entity.userdefined.certificate.PlatformCredential;
import hirs.attestationca.persist.entity.userdefined.certificate.attributes.ComponentAttributeResult; import hirs.attestationca.persist.entity.userdefined.certificate.attributes.ComponentAttributeResult;
@ -28,20 +29,20 @@ import java.util.UUID;
@Log4j2 @Log4j2
@Controller @Controller
@RequestMapping("/HIRS_AttestationCAPortal/portal/component-validation") @RequestMapping("/HIRS_AttestationCAPortal/portal/component-comparison")
public class ComponentComparisonPageController extends PageController<CertificateDetailsPageParams> { public class ComponentComparisonPageController extends PageController<CertificateDetailsPageParams> {
private final CertificateRepository certificateRepository; private final PlatformCertificateRepository platformCertificateRepository;
private final ComponentResultRepository componentResultRepository; private final ComponentResultRepository componentResultRepository;
private final ComponentInfoRepository componentInfoRepository; private final ComponentInfoRepository componentInfoRepository;
private final ComponentAttributeRepository componentAttributeRepository; private final ComponentAttributeRepository componentAttributeRepository;
@Autowired @Autowired
public ComponentComparisonPageController(final CertificateRepository certificateRepository, public ComponentComparisonPageController(final PlatformCertificateRepository platformCertificateRepository,
final ComponentResultRepository componentResultRepository, final ComponentResultRepository componentResultRepository,
final ComponentInfoRepository componentInfoRepository, final ComponentInfoRepository componentInfoRepository,
final ComponentAttributeRepository componentAttributeRepository) { final ComponentAttributeRepository componentAttributeRepository) {
super(Page.COMPONENT_COMPARISON); super(Page.COMPONENT_COMPARISON);
this.certificateRepository = certificateRepository; this.platformCertificateRepository = platformCertificateRepository;
this.componentResultRepository = componentResultRepository; this.componentResultRepository = componentResultRepository;
this.componentInfoRepository = componentInfoRepository; this.componentInfoRepository = componentInfoRepository;
this.componentAttributeRepository = componentAttributeRepository; this.componentAttributeRepository = componentAttributeRepository;
@ -76,7 +77,7 @@ public class ComponentComparisonPageController extends PageController<Certificat
try { try {
UUID uuid = UUID.fromString(params.getId()); UUID uuid = UUID.fromString(params.getId());
data.putAll(getPlatformComponentInformation(uuid, params.getDeviceName(), data.putAll(getPlatformComponentInformation(uuid, params.getDeviceName(),
certificateRepository, componentResultRepository, platformCertificateRepository, componentResultRepository,
componentInfoRepository, componentInfoRepository,
componentAttributeRepository)); componentAttributeRepository));
} catch (IllegalArgumentException iaEx) { } catch (IllegalArgumentException iaEx) {
@ -113,7 +114,7 @@ public class ComponentComparisonPageController extends PageController<Certificat
*/ */
public static HashMap<String, Object> getPlatformComponentInformation( public static HashMap<String, Object> getPlatformComponentInformation(
final UUID sessionId, final String deviceName, final UUID sessionId, final String deviceName,
final CertificateRepository certificateRepository, final PlatformCertificateRepository platformCertificateRepository,
final ComponentResultRepository componentResultRepository, final ComponentResultRepository componentResultRepository,
final ComponentInfoRepository componentInfoRepository, final ComponentInfoRepository componentInfoRepository,
final ComponentAttributeRepository componentAttributeRepository) final ComponentAttributeRepository componentAttributeRepository)
@ -129,7 +130,7 @@ public class ComponentComparisonPageController extends PageController<Certificat
} }
}); });
componentResults.addAll(componentResultRepository.findAllById(tempIdList)); componentResults.addAll(componentResultRepository.findAllById(tempIdList));
PlatformCredential platformCredential = (PlatformCredential) certificateRepository PlatformCredential platformCredential = platformCertificateRepository
.findByPlatformSerialAndSerialNumber(componentResults.get(0).getBoardSerialNumber(), .findByPlatformSerialAndSerialNumber(componentResults.get(0).getBoardSerialNumber(),
BigInteger.valueOf(Long.parseLong(componentResults.get(0).getCertificateSerialNumber()))); BigInteger.valueOf(Long.parseLong(componentResults.get(0).getCertificateSerialNumber())));