KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > internal > verifier > DefaultTrustAuthority


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.osgi.internal.verifier;
12
13 import java.security.cert.Certificate JavaDoc;
14 import java.security.cert.CertificateException JavaDoc;
15 import org.eclipse.osgi.internal.provisional.verifier.CertificateTrustAuthority;
16 import org.eclipse.osgi.util.NLS;
17
18 public class DefaultTrustAuthority implements CertificateTrustAuthority {
19     // the KeyStores that we determine trust from. This only gets intialized the
20
// supportFlags include the VERIFY_TRUST flag
21
private KeyStores keyStores;
22     // used to indicate if we should check the KeyStores object for trust.
23
private int supportFlags;
24     public DefaultTrustAuthority(int supportFlags) {
25         this.supportFlags = supportFlags;
26     }
27     public void checkTrust(Certificate JavaDoc[] certChain) throws CertificateException JavaDoc {
28         if (certChain == null || certChain.length == 0) {
29             throw new IllegalArgumentException JavaDoc(JarVerifierMessages.Cert_Verifier_Illegal_Args);
30         }
31         KeyStores stores = getKeyStores();
32         // stores == null when the supportFlags includes the VERIFY_TRUST flag
33
if (stores != null && !stores.isTrusted(certChain[certChain.length - 1])) {
34             throw new CertificateException JavaDoc(NLS.bind(JarVerifierMessages.Cert_Verifier_Not_Trusted, new String JavaDoc[] {certChain[0].toString()}));
35         }
36     }
37
38     private synchronized KeyStores getKeyStores() {
39         if (((supportFlags & SignedBundleHook.VERIFY_TRUST) == 0) || keyStores != null)
40             return keyStores;
41         keyStores = new KeyStores();
42         return keyStores;
43     }
44     public void addTrusted(Certificate JavaDoc[] certs) throws CertificateException JavaDoc {
45         // do nothing for now ...
46
}
47
48 }
49
Popular Tags