/** * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://aws.amazon.com/apache2.0 * * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES * OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and * limitations under the License. */ package com.amazonaws.mobileconnectors.iot; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.Socket; import javax.net.ssl.SSLSocketFactory; public class AWSIotProxiedSocketFactory extends SSLSocketFactory { private final SSLSocketFactory socketFactory; private final Proxy proxy; public AWSIotProxiedSocketFactory(SSLSocketFactory delegate, String proxyHost, int proxyPort){ this.socketFactory = delegate; this.proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(proxyHost, proxyPort)); } @Override public String[] getDefaultCipherSuites() { return socketFactory.getDefaultCipherSuites(); } @Override public String[] getSupportedCipherSuites() { return socketFactory.getSupportedCipherSuites(); } @Override public Socket createSocket(){ return new AWSIotProxiedSSLSocket(socketFactory, new Socket(proxy)); } @Override public Socket createSocket(Socket socket, String s, int i, boolean b) throws IOException { return socketFactory.createSocket(socket, s, i, b); } @Override public Socket createSocket(String s, int i) throws IOException { return socketFactory.createSocket(s, i); } @Override public Socket createSocket(String s, int i, InetAddress inetAddress, int i1) throws IOException { return socketFactory.createSocket(s, i, inetAddress, i1); } @Override public Socket createSocket(InetAddress inetAddress, int i) throws IOException { return socketFactory.createSocket(inetAddress, i); } @Override public Socket createSocket(InetAddress inetAddress, int i, InetAddress inetAddress1, int i1) throws IOException { return socketFactory.createSocket(inetAddress, i, inetAddress1, i1); } }