michael@0: /* michael@0: * ==================================================================== michael@0: * Licensed to the Apache Software Foundation (ASF) under one michael@0: * or more contributor license agreements. See the NOTICE file michael@0: * distributed with this work for additional information michael@0: * regarding copyright ownership. The ASF licenses this file michael@0: * to you under the Apache License, Version 2.0 (the michael@0: * "License"); you may not use this file except in compliance michael@0: * with the License. You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, michael@0: * software distributed under the License is distributed on an michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY michael@0: * KIND, either express or implied. See the License for the michael@0: * specific language governing permissions and limitations michael@0: * under the License. michael@0: * ==================================================================== michael@0: * michael@0: * This software consists of voluntary contributions made by many michael@0: * individuals on behalf of the Apache Software Foundation. For more michael@0: * information on the Apache Software Foundation, please see michael@0: * . michael@0: * michael@0: */ michael@0: michael@0: package ch.boye.httpclientandroidlib.conn.scheme; michael@0: michael@0: import java.io.IOException; michael@0: import java.net.InetSocketAddress; michael@0: import java.net.Socket; michael@0: import java.net.UnknownHostException; michael@0: michael@0: import ch.boye.httpclientandroidlib.conn.ConnectTimeoutException; michael@0: import ch.boye.httpclientandroidlib.params.HttpParams; michael@0: michael@0: /** michael@0: * A factory for creating, initializing and connecting sockets. The factory encapsulates the logic michael@0: * for establishing a socket connection. michael@0: * michael@0: * @since 4.1 michael@0: */ michael@0: public interface SchemeSocketFactory { michael@0: michael@0: /** michael@0: * Creates a new, unconnected socket. The socket should subsequently be passed to michael@0: * {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)}. michael@0: * michael@0: * @param params Optional {@link HttpParams parameters}. In most cases these parameters michael@0: * will not be required and will have no effect, as usually socket michael@0: * initialization should take place in the michael@0: * {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)} michael@0: * method. However, in rare cases one may want to pass additional parameters michael@0: * to this method in order to create a customized {@link Socket} instance, michael@0: * for instance bound to a SOCKS proxy server. michael@0: * michael@0: * @return a new socket michael@0: * michael@0: * @throws IOException if an I/O error occurs while creating the socket michael@0: */ michael@0: Socket createSocket(HttpParams params) throws IOException; michael@0: michael@0: /** michael@0: * Connects a socket to the target host with the given remote address. michael@0: * michael@0: * @param sock the socket to connect, as obtained from michael@0: * {@link #createSocket(HttpParams) createSocket}. michael@0: * null indicates that a new socket michael@0: * should be created and connected. michael@0: * @param remoteAddress the remote address to connect to michael@0: * @param localAddress the local address to bind the socket to, or michael@0: * null for any michael@0: * @param params additional {@link HttpParams parameters} for connecting michael@0: * michael@0: * @return the connected socket. The returned object may be different michael@0: * from the sock argument if this factory supports michael@0: * a layered protocol. michael@0: * michael@0: * @throws IOException if an I/O error occurs michael@0: * @throws UnknownHostException if the IP address of the target host michael@0: * can not be determined michael@0: * @throws ConnectTimeoutException if the socket cannot be connected michael@0: * within the time limit defined in the params michael@0: */ michael@0: Socket connectSocket( michael@0: Socket sock, michael@0: InetSocketAddress remoteAddress, michael@0: InetSocketAddress localAddress, michael@0: HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException; michael@0: michael@0: /** michael@0: * Checks whether a socket provides a secure connection. The socket must be michael@0: * {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams) connected} michael@0: * by this factory. The factory will not perform I/O operations in this method. michael@0: *

michael@0: * As a rule of thumb, plain sockets are not secure and TLS/SSL sockets are secure. However, michael@0: * there may be application specific deviations. For example, a plain socket to a host in the michael@0: * same intranet ("trusted zone") could be considered secure. On the other hand, a TLS/SSL michael@0: * socket could be considered insecure based on the cipher suite chosen for the connection. michael@0: * michael@0: * @param sock the connected socket to check michael@0: * michael@0: * @return true if the connection of the socket michael@0: * should be considered secure, or michael@0: * false if it should not michael@0: * michael@0: * @throws IllegalArgumentException michael@0: * if the argument is invalid, for example because it is michael@0: * not a connected socket or was created by a different michael@0: * socket factory. michael@0: * Note that socket factories are not required to michael@0: * check these conditions, they may simply return a default michael@0: * value when called with an invalid socket argument. michael@0: */ michael@0: boolean isSecure(Socket sock) throws IllegalArgumentException; michael@0: michael@0: }