Debian Codegraph @

ssl-proxies/src/main/java/org/globus/gsi/trustmanager/SigningPolicyChecker.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
16 package org.globus.gsi.trustmanager;
17
18 import org.globus.gsi.util.ProxyCertificateUtil;
19
20 import org.globus.gsi.provider.SigningPolicyStore;
21
22 import java.security.cert.CertPathValidatorException;
23 import java.security.cert.CertStoreException;
24 import java.security.cert.X509Certificate;
25
26 import javax.security.auth.x500.X500Principal;
27
28 import org.globus.gsi.GSIConstants;
29 import org.globus.gsi.SigningPolicy;
30
31 /**
32 * This checks to make sure the Distinguished Name in the certificate is valid according to the signing policy.
33 */
34 public class SigningPolicyChecker implements CertificateChecker {
35 private SigningPolicyStore policyStore;
36
37 public SigningPolicyChecker(SigningPolicyStore policyStore) {
38 this.policyStore = policyStore;
39 }
40
41 /**
42 * Validate DN against the signing policy
43 *
44 * @param cert The certificate to check.
45 * @param certType The type of certificate to check.
46 * @throws CertPathValidatorException if the certificate is invalid according to the signing policy.
47 */
48 public void invoke(X509Certificate cert, GSIConstants.CertificateType certType) throws CertPathValidatorException {
49 if (!requireSigningPolicyCheck(certType)) {
50 return;
51 }
52 X500Principal caPrincipal = cert.getIssuerX500Principal();
53 SigningPolicy policy;
54 try {
55 policy = this.policyStore.getSigningPolicy(caPrincipal);
56 } catch (CertStoreException e) {
57 throw new CertPathValidatorException(e);
58 }
59
60 if (policy == null) {
61 throw new CertPathValidatorException("No signing policy for " + cert.getIssuerDN());
62 }
63
64 boolean valid = policy.isValidSubject(cert.getSubjectX500Principal());
65
66 if (!valid) {
67 throw new CertPathValidatorException("Certificate " + cert.getSubjectDN()
68 + " violates signing policy for CA " + caPrincipal.getName());
69 }
70 }
71
72 /**
73 * if a certificate is not a CA or if it is not a proxy, return true.
74 *
75 * @param certType The type of Certificate being queried.
76 * @return True if the CertificateType requires a Signing Policy check.
77 */
78 private boolean requireSigningPolicyCheck(GSIConstants.CertificateType certType) {
79
80 return !ProxyCertificateUtil.isProxy(certType) && certType != GSIConstants.CertificateType.CA;
81 }
82 }