Debian Codegraph @

ssl-proxies/src/main/java/org/globus/gsi/util/KeyStoreUtil.java

raw
1 /*
2 * Copyright 1999-2010 University of Chicago
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 * express or implied.
12 *
13 * See the License for the specific language governing permissions and limitations under the License.
14 */
15 package org.globus.gsi.util;
16
17 import java.security.KeyStore;
18 import java.security.KeyStoreException;
19 import java.security.cert.Certificate;
20 import java.security.cert.X509CertSelector;
21 import java.security.cert.X509Certificate;
22 import java.util.Collection;
23 import java.util.Enumeration;
24 import java.util.Vector;
25
26 /**
27 * FILL ME
28 *
29 * @author [email protected]
30 */
31 public final class KeyStoreUtil {
32
33 private KeyStoreUtil() {
34 //Should not be constructed
35 }
36
37 /**
38 * Returns the list of certificates in the KeyStore. Return object will not
39 * be null.
40 *
41 * @param keyStore
42 * @param selector
43 * @return the list of certificates in the KeyStore
44 * @throws KeyStoreException
45 */
46 public static Collection<? extends Certificate> getTrustedCertificates(KeyStore keyStore, X509CertSelector selector)
47 throws KeyStoreException {
48
49 Vector<X509Certificate> certificates = new Vector<X509Certificate>();
50 Enumeration<String> aliases = keyStore.aliases();
51 while (aliases.hasMoreElements()) {
52 String alias = aliases.nextElement();
53 if (keyStore.isCertificateEntry(alias)) {
54 // If a specific impl of keystore requires refresh, this would be a
55 // good place to add it.
56 Certificate certificate = keyStore.getCertificate(alias);
57 if (certificate instanceof X509Certificate) {
58 X509Certificate x509Cert = (X509Certificate) certificate;
59 if (selector.match(certificate)) {
60 certificates.add(x509Cert);
61 }
62 }
63 }
64 }
65 return certificates;
66 }
67
68 }