Debian Codegraph @

ssl-proxies-tomcat/src/main/java/org/globus/gsi/tomcat/GlobusSSLSocketFactory.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.tomcat;
17
18 import org.apache.tomcat.util.net.AbstractEndpoint;
19 import org.apache.tomcat.util.net.jsse.JSSESocketFactory;
20 import org.globus.gsi.X509ProxyCertPathParameters;
21 import org.globus.gsi.jsse.GlobusSSLHelper;
22 import org.globus.gsi.provider.GlobusProvider;
23 import org.globus.gsi.trustmanager.PKITrustManager;
24 import org.globus.gsi.trustmanager.X509ProxyCertPathValidator;
25 import org.globus.gsi.stores.ResourceSigningPolicyStore;
26 import org.globus.gsi.stores.Stores;
27
28 import javax.net.ssl.SSLServerSocket;
29 import javax.net.ssl.TrustManager;
30 import java.io.IOException;
31 import java.net.InetAddress;
32 import java.net.ServerSocket;
33 import java.security.KeyStore;
34 import java.security.Security;
35 import java.security.cert.CertStore;
36
37 /**
38 * This extends the standard JSSE to support the globus trust manager and all of the associated properties:
39 * CRLs, SigningPolicies, proxy certificates.
40 *
41 * @version 1.0
42 * @since 1.0
43 */
44 public class GlobusSSLSocketFactory extends JSSESocketFactory {
45
46 static {
47 Security.addProvider(new GlobusProvider());
48 }
49
50 protected Object crlLocation;
51 protected Object signingPolicyLocation;
52 protected Object rejectLimitedProxyEntry;
53
54 public GlobusSSLSocketFactory(AbstractEndpoint endpoint) {
55 super(endpoint);
56 crlLocation = endpoint.getAttribute("crlLocation");
57 signingPolicyLocation = endpoint.getAttribute("signingPolicyLocation");
58 rejectLimitedProxyEntry = endpoint.getAttribute("rejectLimitedProxy");
59 }
60
61 /**
62 * Create a Globus trust manager which supports proxy certificates. This requires that the CRL store, and
63 * signing policy store be configured.
64 *
65 * @param keystoreType The type of keystore to create.
66 * @param keystoreProvider The keystore provider to use.
67 * @param algorithm The keystore algorithm.
68 * @return A set of configured TrustManagers.
69 * @throws Exception If we cannot create the trust managers.
70 */
71 @Override
72 protected TrustManager[] getTrustManagers(String keystoreType, String keystoreProvider, String algorithm)
73 throws Exception {
74 KeyStore trustStore = getTrustStore(keystoreType, keystoreProvider);
75
76 CertStore crlStore = null;
77 if (crlLocation != null) {
78 crlStore = GlobusSSLHelper.findCRLStore((String) crlLocation);
79 }
80
81 ResourceSigningPolicyStore policyStore = null;
82 if (signingPolicyLocation != null) {
83 policyStore = Stores.getSigningPolicyStore((String) signingPolicyLocation);
84 }
85
86 boolean rejectLimitedProxy = rejectLimitedProxyEntry != null &&
87 Boolean.parseBoolean((String) rejectLimitedProxyEntry);
88
89 X509ProxyCertPathParameters parameters = new X509ProxyCertPathParameters(trustStore, crlStore, policyStore,
90 rejectLimitedProxy);
91 TrustManager trustManager = new PKITrustManager(new X509ProxyCertPathValidator(), parameters);
92 return new TrustManager[]{trustManager};
93 }
94
95
96 @Override
97 protected Object clone() throws CloneNotSupportedException {
98 // TODO Auto-generated method stub
99 return super.clone();
100 }
101
102
103 @Override
104 public ServerSocket createSocket(int port, int backlog, InetAddress ifAddress) throws IOException {
105 return new GlobusSSLSocketWrapper((SSLServerSocket) super.createSocket(port, backlog, ifAddress));
106 }
107
108
109 @Override
110 public ServerSocket createSocket(int port, int backlog) throws IOException {
111 return createSocket(port, backlog, null);
112 }
113
114
115 @Override
116 public ServerSocket createSocket(int port) throws IOException {
117 return createSocket(port, 50);
118 }
119 }