| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
package org.apache.commons.httpclient.contrib.ssl; |
| 28 |
|
|
| 29 |
|
import java.io.IOException; |
| 30 |
|
import java.net.InetAddress; |
| 31 |
|
import java.net.InetSocketAddress; |
| 32 |
|
import java.net.Socket; |
| 33 |
|
import java.net.SocketAddress; |
| 34 |
|
import java.net.UnknownHostException; |
| 35 |
|
|
| 36 |
|
import javax.net.SocketFactory; |
| 37 |
|
import javax.net.ssl.SSLContext; |
| 38 |
|
import javax.net.ssl.TrustManager; |
| 39 |
|
|
| 40 |
|
import org.apache.commons.httpclient.ConnectTimeoutException; |
| 41 |
|
import org.apache.commons.httpclient.HttpClientError; |
| 42 |
|
import org.apache.commons.httpclient.params.HttpConnectionParams; |
| 43 |
|
import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory; |
| 44 |
|
import org.apache.commons.logging.Log; |
| 45 |
|
import org.apache.commons.logging.LogFactory; |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
@link |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
@author |
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
|
|
|
| 0% |
Uncovered Elements: 42 (42) |
Complexity: 13 |
Complexity Density: 0.48 |
|
| 94 |
|
public class EasySSLProtocolSocketFactory implements SecureProtocolSocketFactory { |
| 95 |
|
|
| 96 |
|
|
| 97 |
|
private static final Log LOG = LogFactory.getLog(EasySSLProtocolSocketFactory.class); |
| 98 |
|
|
| 99 |
|
private SSLContext sslcontext = null; |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 104 |
0
|
public EasySSLProtocolSocketFactory() {... |
| 105 |
0
|
super(); |
| 106 |
|
} |
| 107 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 108 |
0
|
private static SSLContext createEasySSLContext() {... |
| 109 |
0
|
try { |
| 110 |
0
|
SSLContext context = SSLContext.getInstance("SSL"); |
| 111 |
0
|
context.init( |
| 112 |
|
null, |
| 113 |
|
new TrustManager[] {new EasyX509TrustManager(null)}, |
| 114 |
|
null); |
| 115 |
0
|
return context; |
| 116 |
|
} catch (Exception e) { |
| 117 |
0
|
LOG.error(e.getMessage(), e); |
| 118 |
0
|
throw new HttpClientError(e.toString()); |
| 119 |
|
} |
| 120 |
|
} |
| 121 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 122 |
0
|
private SSLContext getSSLContext() {... |
| 123 |
0
|
if (this.sslcontext == null) { |
| 124 |
0
|
this.sslcontext = createEasySSLContext(); |
| 125 |
|
} |
| 126 |
0
|
return this.sslcontext; |
| 127 |
|
} |
| 128 |
|
|
| 129 |
|
|
| 130 |
|
@see |
| 131 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 132 |
0
|
public Socket createSocket(... |
| 133 |
|
String host, |
| 134 |
|
int port, |
| 135 |
|
InetAddress clientHost, |
| 136 |
|
int clientPort) |
| 137 |
|
throws IOException, UnknownHostException { |
| 138 |
|
|
| 139 |
0
|
return getSSLContext().getSocketFactory().createSocket( |
| 140 |
|
host, |
| 141 |
|
port, |
| 142 |
|
clientHost, |
| 143 |
|
clientPort |
| 144 |
|
); |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
|
|
| 153 |
|
@link |
| 154 |
|
|
| 155 |
|
|
| 156 |
|
@param |
| 157 |
|
@param |
| 158 |
|
@param |
| 159 |
|
@param |
| 160 |
|
@param@link |
| 161 |
|
|
| 162 |
|
@return |
| 163 |
|
|
| 164 |
|
@throws |
| 165 |
|
@throws |
| 166 |
|
|
| 167 |
|
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
| 168 |
0
|
public Socket createSocket(... |
| 169 |
|
final String host, |
| 170 |
|
final int port, |
| 171 |
|
final InetAddress localAddress, |
| 172 |
|
final int localPort, |
| 173 |
|
final HttpConnectionParams params |
| 174 |
|
) throws IOException, UnknownHostException, ConnectTimeoutException { |
| 175 |
0
|
if (params == null) { |
| 176 |
0
|
throw new IllegalArgumentException("Parameters may not be null"); |
| 177 |
|
} |
| 178 |
0
|
int timeout = params.getConnectionTimeout(); |
| 179 |
0
|
SocketFactory socketfactory = getSSLContext().getSocketFactory(); |
| 180 |
0
|
if (timeout == 0) { |
| 181 |
0
|
return socketfactory.createSocket(host, port, localAddress, localPort); |
| 182 |
|
} else { |
| 183 |
0
|
Socket socket = socketfactory.createSocket(); |
| 184 |
0
|
SocketAddress localaddr = new InetSocketAddress(localAddress, localPort); |
| 185 |
0
|
SocketAddress remoteaddr = new InetSocketAddress(host, port); |
| 186 |
0
|
socket.bind(localaddr); |
| 187 |
0
|
socket.connect(remoteaddr, timeout); |
| 188 |
0
|
return socket; |
| 189 |
|
} |
| 190 |
|
} |
| 191 |
|
|
| 192 |
|
|
| 193 |
|
@see |
| 194 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 195 |
0
|
public Socket createSocket(String host, int port)... |
| 196 |
|
throws IOException, UnknownHostException { |
| 197 |
0
|
return getSSLContext().getSocketFactory().createSocket( |
| 198 |
|
host, |
| 199 |
|
port |
| 200 |
|
); |
| 201 |
|
} |
| 202 |
|
|
| 203 |
|
|
| 204 |
|
@see |
| 205 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 206 |
0
|
public Socket createSocket(... |
| 207 |
|
Socket socket, |
| 208 |
|
String host, |
| 209 |
|
int port, |
| 210 |
|
boolean autoClose) |
| 211 |
|
throws IOException, UnknownHostException { |
| 212 |
0
|
return getSSLContext().getSocketFactory().createSocket( |
| 213 |
|
socket, |
| 214 |
|
host, |
| 215 |
|
port, |
| 216 |
|
autoClose |
| 217 |
|
); |
| 218 |
|
} |
| 219 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 220 |
0
|
public boolean equals(Object obj) {... |
| 221 |
0
|
return ((obj != null) && obj.getClass().equals(EasySSLProtocolSocketFactory.class)); |
| 222 |
|
} |
| 223 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 224 |
0
|
public int hashCode() {... |
| 225 |
0
|
return EasySSLProtocolSocketFactory.class.hashCode(); |
| 226 |
|
} |
| 227 |
|
|
| 228 |
|
} |