2 // ========================================================================
3 // Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.util.security;
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;
27 import org.eclipse.jetty.util.resource.Resource;
29 public class CertificateUtils
31 /* ------------------------------------------------------------ */
32 public static KeyStore getKeyStore(InputStream storeStream, String storePath, String storeType, String storeProvider, String storePassword) throws Exception
34 KeyStore keystore = null;
36 if (storeStream != null || storePath != null)
38 InputStream inStream = storeStream;
43 inStream = Resource.newResource(storePath).getInputStream();
46 if (storeProvider != null)
48 keystore = KeyStore.getInstance(storeType, storeProvider);
52 keystore = KeyStore.getInstance(storeType);
55 keystore.load(inStream, storePassword == null ? null : storePassword.toCharArray());
69 /* ------------------------------------------------------------ */
70 public static Collection<? extends CRL> loadCRL(String crlPath) throws Exception
72 Collection<? extends CRL> crlList = null;
76 InputStream in = null;
79 in = Resource.newResource(crlPath).getInputStream();
80 crlList = CertificateFactory.getInstance("X.509").generateCRLs(in);