1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.util.security;
20
21 import java.io.InputStream;
22 import java.security.KeyStore;
23 import java.security.cert.CRL;
24 import java.security.cert.CertificateFactory;
25 import java.util.Collection;
26
27 import org.eclipse.jetty.util.resource.Resource;
28
29 public class CertificateUtils
30 {
31
32 public static KeyStore getKeyStore(Resource store, String storeType, String storeProvider, String storePassword) throws Exception
33 {
34 KeyStore keystore = null;
35
36 if (store != null)
37 {
38 if (storeProvider != null)
39 {
40 keystore = KeyStore.getInstance(storeType, storeProvider);
41 }
42 else
43 {
44 keystore = KeyStore.getInstance(storeType);
45 }
46
47 if (!store.exists())
48 throw new IllegalStateException("no valid keystore");
49
50 try (InputStream inStream = store.getInputStream())
51 {
52 keystore.load(inStream, storePassword == null ? null : storePassword.toCharArray());
53 }
54 }
55
56 return keystore;
57 }
58
59
60 public static Collection<? extends CRL> loadCRL(String crlPath) throws Exception
61 {
62 Collection<? extends CRL> crlList = null;
63
64 if (crlPath != null)
65 {
66 InputStream in = null;
67 try
68 {
69 in = Resource.newResource(crlPath).getInputStream();
70 crlList = CertificateFactory.getInstance("X.509").generateCRLs(in);
71 }
72 finally
73 {
74 if (in != null)
75 {
76 in.close();
77 }
78 }
79 }
80
81 return crlList;
82 }
83
84 }