Debian Codegraph @

ssl-proxies/src/main/java/org/globus/gsi/util/ProxyCertificateUtil.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.io.IOException;
18
19 import org.bouncycastle.asn1.x509.TBSCertificateStructure;
20 import org.bouncycastle.asn1.x509.X509Extension;
21 import org.bouncycastle.asn1.x509.X509Extensions;
22 import org.globus.gsi.GSIConstants;
23 import org.globus.gsi.proxy.ext.ProxyCertInfo;
24
25 /**
26 * FILL ME
27 *
28 * @author [email protected]
29 */
30 public final class ProxyCertificateUtil {
31
32 private ProxyCertificateUtil() {
33 //This should not be instantiated
34 }
35
36 /**
37 * Determines if a specified certificate type indicates a GSI-2, GSI-3 or
38 * GSI-4proxy certificate.
39 *
40 * @param certType the certificate type to check.
41 * @return true if certType is a GSI-2 or GSI-3 or GSI-4 proxy, false
42 * otherwise.
43 */
44 public static boolean isProxy(GSIConstants.CertificateType certType) {
45 return isGsi2Proxy(certType) || isGsi3Proxy(certType) || isGsi4Proxy(certType);
46 }
47
48 /**
49 * Determines if a specified certificate type indicates a GSI-4 proxy
50 * certificate.
51 *
52 * @param certType the certificate type to check.
53 * @return true if certType is a GSI-4 proxy, false otherwise.
54 */
55 public static boolean isGsi4Proxy(GSIConstants.CertificateType certType) {
56 return certType == GSIConstants.CertificateType.GSI_4_IMPERSONATION_PROXY
57 || certType == GSIConstants.CertificateType.GSI_4_INDEPENDENT_PROXY
58 || certType == GSIConstants.CertificateType.GSI_4_RESTRICTED_PROXY
59 || certType == GSIConstants.CertificateType.GSI_4_LIMITED_PROXY;
60 }
61
62 /**
63 * Determines if a specified certificate type indicates a GSI-3 proxy
64 * certificate.
65 *
66 * @param certType the certificate type to check.
67 * @return true if certType is a GSI-3 proxy, false otherwise.
68 */
69 public static boolean isGsi3Proxy(GSIConstants.CertificateType certType) {
70 return certType == GSIConstants.CertificateType.GSI_3_IMPERSONATION_PROXY
71 || certType == GSIConstants.CertificateType.GSI_3_INDEPENDENT_PROXY
72 || certType == GSIConstants.CertificateType.GSI_3_RESTRICTED_PROXY
73 || certType == GSIConstants.CertificateType.GSI_3_LIMITED_PROXY;
74 }
75
76 /**
77 * Determines if a specified certificate type indicates a GSI-2 proxy
78 * certificate.
79 *
80 * @param certType the certificate type to check.
81 * @return true if certType is a GSI-2 proxy, false otherwise.
82 */
83 public static boolean isGsi2Proxy(GSIConstants.CertificateType certType) {
84 return certType == GSIConstants.CertificateType.GSI_2_PROXY
85 || certType == GSIConstants.CertificateType.GSI_2_LIMITED_PROXY;
86 }
87
88 /**
89 * Determines if a specified certificate type indicates a GSI-2 or GSI-3 or
90 * GSI=4 limited proxy certificate.
91 *
92 * @param certType the certificate type to check.
93 * @return true if certType is a GSI-2 or GSI-3 or GSI-4 limited proxy,
94 * false otherwise.
95 */
96 public static boolean isLimitedProxy(GSIConstants.CertificateType certType) {
97 return certType == GSIConstants.CertificateType.GSI_3_LIMITED_PROXY
98 || certType == GSIConstants.CertificateType.GSI_2_LIMITED_PROXY
99 || certType == GSIConstants.CertificateType.GSI_4_LIMITED_PROXY;
100 }
101
102 /**
103 * Determines if a specified certificate type indicates a GSI-3 or GS-4
104 * limited proxy certificate.
105 *
106 * @param certType the certificate type to check.
107 * @return true if certType is a GSI-3 or GSI-4 independent proxy, false
108 * otherwise.
109 */
110 public static boolean isIndependentProxy(
111 GSIConstants.CertificateType certType) {
112 return certType == GSIConstants.CertificateType.GSI_3_INDEPENDENT_PROXY
113 || certType == GSIConstants.CertificateType.GSI_4_INDEPENDENT_PROXY;
114 }
115
116 /**
117 * Determines if a specified certificate type indicates a GSI-2 or GSI-3 or
118 * GSI-4 impersonation proxy certificate.
119 *
120 * @param certType the certificate type to check.
121 * @return true if certType is a GSI-2 or GSI-3 or GSI-4 impersonation
122 * proxy, false otherwise.
123 */
124 public static boolean isImpersonationProxy(GSIConstants.CertificateType certType) {
125 return certType == GSIConstants.CertificateType.GSI_3_IMPERSONATION_PROXY
126 || certType == GSIConstants.CertificateType.GSI_3_LIMITED_PROXY
127 || certType == GSIConstants.CertificateType.GSI_4_IMPERSONATION_PROXY
128 || certType == GSIConstants.CertificateType.GSI_4_LIMITED_PROXY
129 || certType == GSIConstants.CertificateType.GSI_2_LIMITED_PROXY
130 || certType == GSIConstants.CertificateType.GSI_2_PROXY;
131
132 }
133
134 public static int getProxyPathConstraint(TBSCertificateStructure crt)
135 throws IOException {
136
137 ProxyCertInfo proxyCertExt = getProxyCertInfo(crt);
138 return (proxyCertExt != null) ? proxyCertExt.getPathLenConstraint() : -1;
139 }
140
141 public static ProxyCertInfo getProxyCertInfo(TBSCertificateStructure crt)
142 throws IOException {
143
144 X509Extensions extensions = crt.getExtensions();
145 if (extensions == null) {
146 return null;
147 }
148 X509Extension ext =
149 extensions.getExtension(ProxyCertInfo.OID);
150 if (ext == null) {
151 ext = extensions.getExtension(ProxyCertInfo.OLD_OID);
152 }
153 return (ext != null) ? getProxyCertInfo(ext) : null;
154 }
155
156 public static ProxyCertInfo getProxyCertInfo(X509Extension ext) {
157
158 byte[] value = ext.getValue().getOctets();
159 return ProxyCertInfo.getInstance(value);
160 }
161
162 /**
163 * Returns a string description of a specified proxy
164 * type.
165 *
166 * @param proxyType the proxy type to get the string
167 * description of.
168 * @return the string description of the proxy type.
169 */
170 public static String getProxyTypeAsString(GSIConstants.CertificateType proxyType) {
171 switch(proxyType) {
172 case GSI_4_IMPERSONATION_PROXY:
173 return "RFC 3820 compliant impersonation proxy";
174 case GSI_4_INDEPENDENT_PROXY:
175 return "RFC 3820 compliant independent proxy";
176 case GSI_4_LIMITED_PROXY:
177 return "RFC 3820 compliant limited proxy";
178 case GSI_4_RESTRICTED_PROXY:
179 return "RFC 3820 compliant restricted proxy";
180 case GSI_3_IMPERSONATION_PROXY:
181 return "Proxy draft compliant impersonation proxy";
182 case GSI_3_INDEPENDENT_PROXY:
183 return "Proxy draft compliant independent proxy";
184 case GSI_3_LIMITED_PROXY:
185 return "Proxy draft compliant limited proxy";
186 case GSI_3_RESTRICTED_PROXY:
187 return "Proxy draft compliant restricted proxy";
188 case GSI_2_PROXY:
189 return "full legacy globus proxy";
190 case GSI_2_LIMITED_PROXY:
191 return "limited legacy globus proxy";
192 default:
193 return "not a proxy";
194 }
195 }
196
197 }