BaselineBCertificateSelector extends CertificateReorderer { public List<CertificateToken> getCertificates() { List<CertificateToken> orderedCertificates = getOrderedCertificates(); ListCertificateSource trustedCertSources = certificateVerifier.getTrustedCertSources(); if (parameters.bLevel().isTrustAnchorBPPolicy() && !trustedCertSources.isEmpty()) { List<CertificateToken> result = new LinkedList<>(); for (CertificateToken certificateToken : orderedCertificates) { if (trustedCertSources.isTrusted(certificateToken)) { break; } result.add(certificateToken); } return result; } else { return orderedCertificates; } } BaselineBCertificateSelector(CertificateVerifier certificateVerifier, AbstractSignatureParameters parameters); List<CertificateToken> getCertificates();  }
@Test public void testNormalNoTrust() { CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); CommonSignatureParamaters parameters = new CommonSignatureParamaters(); parameters.setSigningCertificate(c1); parameters.setCertificateChain(c2); BaselineBCertificateSelector selector = new BaselineBCertificateSelector(certificateVerifier, parameters); List<CertificateToken> certificates = selector.getCertificates(); assertEquals(2, certificates.size()); assertEquals(c1, certificates.get(0)); assertEquals(c2, certificates.get(1)); }
@Test public void testNormalTrust() { CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); CertificateSource trustCertSource = new CommonTrustedCertificateSource(); trustCertSource.addCertificate(c2); certificateVerifier.setTrustedCertSources(trustCertSource); CommonSignatureParamaters parameters = new CommonSignatureParamaters(); parameters.setSigningCertificate(c1); parameters.setCertificateChain(c2); BaselineBCertificateSelector selector = new BaselineBCertificateSelector(certificateVerifier, parameters); List<CertificateToken> certificates = selector.getCertificates(); assertEquals(1, certificates.size()); assertEquals(c1, certificates.get(0)); }
@Test public void testSkipTrustAndUpper() { CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); CertificateSource trustCertSource = new CommonTrustedCertificateSource(); trustCertSource.addCertificate(c2); certificateVerifier.setTrustedCertSources(trustCertSource); CommonSignatureParamaters parameters = new CommonSignatureParamaters(); parameters.setSigningCertificate(c1); parameters.setCertificateChain(c2, c3); BaselineBCertificateSelector selector = new BaselineBCertificateSelector(certificateVerifier, parameters); List<CertificateToken> certificates = selector.getCertificates(); assertEquals(1, certificates.size()); assertEquals(c1, certificates.get(0)); for (CertificateToken certificateToken : certificates) { assertEquals(SignatureValidity.VALID, certificateToken.getSignatureValidity()); } }
@Test public void testNormalTrust2() { CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); CertificateSource trustCertSource = new CommonTrustedCertificateSource(); trustCertSource.addCertificate(c3); certificateVerifier.setTrustedCertSources(trustCertSource); CommonSignatureParamaters parameters = new CommonSignatureParamaters(); parameters.setSigningCertificate(c1); parameters.setCertificateChain(c2, c3); BaselineBCertificateSelector selector = new BaselineBCertificateSelector(certificateVerifier, parameters); List<CertificateToken> certificates = selector.getCertificates(); assertEquals(2, certificates.size()); assertEquals(c1, certificates.get(0)); assertEquals(c2, certificates.get(1)); }
@Test public void testNormalTrustOtherRoot() { CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); CertificateSource trustCertSource = new CommonTrustedCertificateSource(); trustCertSource.addCertificate(c3Bis); certificateVerifier.setTrustedCertSources(trustCertSource); CommonSignatureParamaters parameters = new CommonSignatureParamaters(); parameters.setSigningCertificate(c1); parameters.setCertificateChain(c2, c3); BaselineBCertificateSelector selector = new BaselineBCertificateSelector(certificateVerifier, parameters); List<CertificateToken> certificates = selector.getCertificates(); assertEquals(2, certificates.size()); assertEquals(c1, certificates.get(0)); assertEquals(c2, certificates.get(1)); }
@Test public void testNormalTrustTooMuch() { CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); CertificateSource trustCertSource = new CommonTrustedCertificateSource(); trustCertSource.addCertificate(c3); certificateVerifier.setTrustedCertSources(trustCertSource); CommonSignatureParamaters parameters = new CommonSignatureParamaters(); parameters.setSigningCertificate(c1); parameters.setCertificateChain(c2, c3, c4); BaselineBCertificateSelector selector = new BaselineBCertificateSelector(certificateVerifier, parameters); List<CertificateToken> certificates = selector.getCertificates(); assertEquals(2, certificates.size()); assertEquals(c1, certificates.get(0)); assertEquals(c2, certificates.get(1)); }
@Test public void testNormalIncludeTrust() { CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); CertificateSource trustCertSource = new CommonTrustedCertificateSource(); trustCertSource.addCertificate(c2); certificateVerifier.setTrustedCertSources(trustCertSource); CommonSignatureParamaters parameters = new CommonSignatureParamaters(); parameters.setSigningCertificate(c1); parameters.setCertificateChain(c2); parameters.bLevel().setTrustAnchorBPPolicy(false); BaselineBCertificateSelector selector = new BaselineBCertificateSelector(certificateVerifier, parameters); List<CertificateToken> certificates = selector.getCertificates(); assertEquals(2, certificates.size()); assertEquals(c1, certificates.get(0)); assertEquals(c2, certificates.get(1)); }
@Test public void testNormalIncludeTrustFixChainOrder() { CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); CertificateSource trustCertSource = new CommonTrustedCertificateSource(); trustCertSource.addCertificate(c3); certificateVerifier.setTrustedCertSources(trustCertSource); CommonSignatureParamaters parameters = new CommonSignatureParamaters(); parameters.setSigningCertificate(c1); parameters.setCertificateChain(c3, c2); parameters.bLevel().setTrustAnchorBPPolicy(false); BaselineBCertificateSelector selector = new BaselineBCertificateSelector(certificateVerifier, parameters); List<CertificateToken> certificates = selector.getCertificates(); assertEquals(3, certificates.size()); assertEquals(c1, certificates.get(0)); assertEquals(c2, certificates.get(1)); assertEquals(c3, certificates.get(2)); }
@Test public void testDuplicateSigningCert() { CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); CommonSignatureParamaters parameters = new CommonSignatureParamaters(); parameters.setSigningCertificate(c1); parameters.setCertificateChain(c1, c2); BaselineBCertificateSelector selector = new BaselineBCertificateSelector(certificateVerifier, parameters); List<CertificateToken> certificates = selector.getCertificates(); assertEquals(2, certificates.size()); assertEquals(c1, certificates.get(0)); assertEquals(c2, certificates.get(1)); }