BcX509CertificateChainBuilder implements CertificateChainBuilder { @Override public Collection<CertifiedPublicKey> build(CertifiedPublicKey certificate, CertificateProvider provider) { if (certificate == null) { return null; } Deque<CertifiedPublicKey> result = new ArrayDeque<>(); build(result, certificate, provider); return result; }  @Override Collection<CertifiedPublicKey> build(CertifiedPublicKey certificate, CertificateProvider provider);  }
@Test void validV3CertificatePath() throws Exception { Collection<X509CertificateHolder> certs = new ArrayList<>(); certs.add(BcUtils.getX509CertificateHolder(v3CaCert)); certs.add(BcUtils.getX509CertificateHolder(v3InterCaCert)); CollectionStore store = new CollectionStore(certs); CertificateProvider provider = componentManager.getInstance(CertificateProvider.class, "BCStoreX509"); ((BcStoreX509CertificateProvider) provider).setStore(store); Collection<CertifiedPublicKey> chain = builder.build(v3Cert, provider); assertThat(chain, contains(v3CaCert, v3InterCaCert, v3Cert)); }
@Test void incompleteV3CertificatePath() throws Exception { Collection<X509CertificateHolder> certs = new ArrayList<>(); certs.add(BcUtils.getX509CertificateHolder(v3InterCaCert)); CollectionStore store = new CollectionStore(certs); CertificateProvider provider = componentManager.getInstance(CertificateProvider.class, "BCStoreX509"); ((BcStoreX509CertificateProvider) provider).setStore(store); Collection<CertifiedPublicKey> chain = builder.build(v3Cert, provider); assertThat(chain, contains(v3InterCaCert, v3Cert)); }
@Test void brokenV3CertificatePath() throws Exception { Collection<X509CertificateHolder> certs = new ArrayList<>(); certs.add(BcUtils.getX509CertificateHolder(v3CaCert)); CollectionStore store = new CollectionStore(certs); CertificateProvider provider = componentManager.getInstance(CertificateProvider.class, "BCStoreX509"); ((BcStoreX509CertificateProvider) provider).setStore(store); Collection<CertifiedPublicKey> chain = builder.build(v3Cert, provider); assertThat(chain, contains(v3Cert)); }
@Test void validV1CertificatePath() throws Exception { Collection<X509CertificateHolder> certs = new ArrayList<>(); certs.add(BcUtils.getX509CertificateHolder(v1CaCert)); CollectionStore store = new CollectionStore(certs); CertificateProvider provider = componentManager.getInstance(CertificateProvider.class, "BCStoreX509"); ((BcStoreX509CertificateProvider) provider).setStore(store); Collection<CertifiedPublicKey> chain = builder.build(v1Cert, provider); assertThat(chain, contains(v1CaCert, v1Cert)); }
@Test void incompleteV1CertificatePath() throws Exception { CertificateProvider provider = componentManager.getInstance(CertificateProvider.class, "BCStoreX509"); Collection<CertifiedPublicKey> chain = builder.build(v1Cert, provider); assertThat(chain, contains(v1Cert)); }