2 * Copyright (c) 2019-2020. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.chess.scanner.proxy.client;
19 import java.io.IOException;
20 import java.net.InetSocketAddress;
21 import java.net.Proxy;
22 import java.net.Socket;
24 import org.apache.http.HttpHost;
25 import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
26 import org.apache.http.protocol.HttpContext;
27 import org.apache.http.ssl.SSLContexts;
29 import org.hedgecode.chess.scanner.ScannerConstants;
32 * SSLSocksSocketFactory
34 * @author Dmitry Samoshin aka gotty
36 public class SSLSocksSocketFactory extends SSLConnectionSocketFactory {
38 SSLSocksSocketFactory() {
40 SSLContexts.createSystemDefault()
45 public Socket createSocket(final HttpContext context) throws IOException {
46 Proxy proxy = new Proxy(
48 (InetSocketAddress) context.getAttribute(ScannerConstants.PROXY_SOCKS_ADDRESS)
50 return new Socket(proxy);
54 public Socket connectSocket(
55 int connectTimeout, Socket socket, HttpHost host,
56 InetSocketAddress remoteAddress, InetSocketAddress localAddress,
58 ) throws IOException {
59 InetSocketAddress unresolvedAddress = InetSocketAddress.createUnresolved(
60 host.getHostName(), remoteAddress.getPort()
62 return super.connectSocket(
63 connectTimeout, socket, host, unresolvedAddress, localAddress, context