1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.net.ssl;
15
16 import java.io.IOException;
17 import java.net.InetAddress;
18 import java.net.Socket;
19 import java.net.UnknownHostException;
20
21 import javax.net.SocketFactory;
22 import javax.net.ssl.SSLParameters;
23 import javax.net.ssl.SSLSocket;
24 import javax.net.ssl.SSLSocketFactory;
25
26
27
28
29
30
31
32
33
34
35
36
37 public class ConfigurableSSLSocketFactory extends SocketFactory {
38
39 private final SSLParametersConfiguration parameters;
40 private final SSLSocketFactory delegate;
41
42
43
44
45
46
47
48
49
50 public ConfigurableSSLSocketFactory(SSLParametersConfiguration parameters, SSLSocketFactory delegate) {
51 this.parameters = parameters;
52 this.delegate = delegate;
53 }
54
55
56
57
58 @Override
59 public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)
60 throws IOException {
61 SSLSocket socket = (SSLSocket) delegate.createSocket(address, port, localAddress, localPort);
62 parameters.configure(new SSLConfigurableSocket(socket));
63 return socket;
64 }
65
66
67
68
69 @Override
70 public Socket createSocket(InetAddress host, int port) throws IOException {
71 SSLSocket socket = (SSLSocket) delegate.createSocket(host, port);
72 parameters.configure(new SSLConfigurableSocket(socket));
73 return socket;
74 }
75
76
77
78
79 @Override
80 public Socket createSocket(String host, int port, InetAddress localHost, int localPort)
81 throws IOException, UnknownHostException {
82 SSLSocket socket = (SSLSocket) delegate.createSocket(host, port, localHost, localPort);
83 parameters.configure(new SSLConfigurableSocket(socket));
84 return socket;
85 }
86
87
88
89
90 @Override
91 public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
92 SSLSocket socket = (SSLSocket) delegate.createSocket(host, port);
93 parameters.configure(new SSLConfigurableSocket(socket));
94 return socket;
95 }
96
97 }