### Question:
SupplyChainCredentialValidator implements CredentialValidator { public static boolean signatureMatchesPublicKey(final X509Certificate cert, final X509Certificate signingCert) throws SupplyChainValidatorException { if (cert == null || signingCert == null) { throw new SupplyChainValidatorException("Certificate or signing certificate is null"); } try { cert.verify(signingCert.getPublicKey(), BouncyCastleProvider.PROVIDER_NAME); return true; } catch (InvalidKeyException | CertificateException | NoSuchAlgorithmException | NoSuchProviderException | SignatureException e) { LOGGER.error("Exception thrown while verifying certificate", e); return false; } } SupplyChainCredentialValidator(); static List<ComponentInfo> getComponentInfoFromPaccorOutput(final String paccorOutput); @Override AppraisalStatus validatePlatformCredential(final PlatformCredential pc,
                                                     final KeyStore trustStore,
                                                     final boolean acceptExpired); @Override AppraisalStatus validatePlatformCredentialAttributes(
            final PlatformCredential platformCredential,
            final DeviceInfoReport deviceInfoReport,
            final EndorsementCredential endorsementCredential); @Override AppraisalStatus validateDeltaPlatformCredentialAttributes(
            final PlatformCredential deltaPlatformCredential,
            final DeviceInfoReport deviceInfoReport,
            final PlatformCredential basePlatformCredential,
            final Map<PlatformCredential, SupplyChainValidation> deltaMapping); @Override AppraisalStatus validateEndorsementCredential(final EndorsementCredential ec,
                                                       final KeyStore trustStore,
                                                       final boolean acceptExpired); static boolean verifyCertificate(final X509AttributeCertificateHolder cert,
            final KeyStore trustStore); static boolean verifyCertificate(final X509Certificate cert,
            final KeyStore trustStore); static boolean validateCertChain(final X509AttributeCertificateHolder cert,
            final Set<X509Certificate> additionalCerts); static boolean validateCertChain(final X509Certificate cert,
            final Set<X509Certificate> additionalCerts); static boolean issuerMatchesSubjectDN(final X509AttributeCertificateHolder cert,
            final X509Certificate signingCert); static boolean issuerMatchesSubjectDN(final X509Certificate cert,
            final X509Certificate signingCert); static boolean signatureMatchesPublicKey(final X509Certificate cert,
            final X509Certificate signingCert); static boolean signatureMatchesPublicKey(final X509AttributeCertificateHolder cert,
            final X509Certificate signingCert); static boolean signatureMatchesPublicKey(final X509AttributeCertificateHolder cert,
        final PublicKey signingKey); Map<PlatformCredential, StringBuilder> getDeltaFailures(); static final String ENDORSEMENT_VALID; static final String PLATFORM_VALID; static final String PLATFORM_ATTRIBUTES_VALID; static final String FIRMWARE_VALID; }### Answer:
@Test public final void validateTestCertificateAgainstPublicKey() throws IOException, InvalidKeySpecException, NoSuchAlgorithmException, URISyntaxException, SupplyChainValidatorException { PlatformCredential credential = new PlatformCredential(Paths.get( this.getClass().getResource(TEST_PLATFORM_CRED).toURI() )); InputStream stream = this.getClass().getResourceAsStream(TEST_SIGNING_KEY); PEMParser pemParser = new PEMParser(new BufferedReader(new InputStreamReader(stream, "UTF-8"))); SubjectPublicKeyInfo info = (SubjectPublicKeyInfo) pemParser.readObject(); pemParser.close(); PublicKey signingKey = KeyFactory.getInstance("RSA") .generatePublic(new X509EncodedKeySpec(info.getEncoded())); Assert.assertTrue(supplyChainCredentialValidator.signatureMatchesPublicKey( credential.getX509AttributeCertificateHolder(), signingKey) ); }
@Test public final void checkTestCertificateAgainstInvalidPublicKey() throws IOException, URISyntaxException, SupplyChainValidatorException { PlatformCredential credential = new PlatformCredential( Paths.get(this.getClass().getResource(TEST_PLATFORM_CRED).toURI()) ); PublicKey invalidPublicKey = createKeyPair().getPublic(); Assert.assertFalse(supplyChainCredentialValidator.signatureMatchesPublicKey( credential.getX509AttributeCertificateHolder(), invalidPublicKey) ); }