1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package nl.altindag.ssl.trustmanager;
18
19 import java.security.KeyStore;
20 import java.security.KeyStoreException;
21 import java.security.cert.Certificate;
22 import java.security.cert.X509Certificate;
23 import java.util.ArrayList;
24 import java.util.Enumeration;
25 import java.util.List;
26
27
28
29
30 public class KeyStoreTestUtils {
31
32 static X509Certificate[] getTrustedX509Certificates(KeyStore trustStore) throws KeyStoreException {
33 List<X509Certificate> certificates = new ArrayList<>();
34 Enumeration<String> aliases = trustStore.aliases();
35 while (aliases.hasMoreElements()) {
36 Certificate certificate = trustStore.getCertificate(aliases.nextElement());
37 if (certificate instanceof X509Certificate) {
38 certificates.add((X509Certificate) certificate);
39 }
40 }
41
42 return certificates.toArray(new X509Certificate[0]);
43 }
44
45 }