KeyStoreCertificateSource extends CommonCertificateSource { @Override public List<CertificateToken> getCertificates() { List<CertificateToken> list = new ArrayList<>(); try { Enumeration<String> aliases = keyStore.aliases(); while (aliases.hasMoreElements()) { Certificate certificate = keyStore.getCertificate(getKey(aliases.nextElement())); list.add(DSSUtils.loadCertificate(certificate.getEncoded())); } } catch (GeneralSecurityException e) { throw new DSSException("Unable to retrieve certificates from the keystore", e); } return Collections.unmodifiableList(list); } KeyStoreCertificateSource(final String ksType, final String ksPassword);  KeyStoreCertificateSource(final String ksFilePath, final String ksType, final String ksPassword);  KeyStoreCertificateSource(final File ksFile, final String ksType, final String ksPassword);  KeyStoreCertificateSource(final InputStream ksStream, final String ksType, final String ksPassword); CertificateToken getCertificate(String alias); @Override List<CertificateToken> getCertificates(); void addAllCertificatesToKeyStore(List<CertificateToken> certificates); void addCertificateToKeyStore(CertificateToken certificateToken); void deleteCertificateFromKeyStore(String alias); void clearAllCertificates(); void store(OutputStream os);  }
@Test public void loadKeystoreAndTruststore() throws IOException { KeyStoreCertificateSource kscs = new KeyStoreCertificateSource(new File("src/test/resources/good-user.p12"), "PKCS12", "ks-password"); assertTrue(kscs.getCertificates().size() > 0); kscs = new KeyStoreCertificateSource(new File("src/test/resources/trust-anchors.jks"), "JKS", "ks-password"); assertTrue(kscs.getCertificates().size() > 0); }