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.InetAddress; 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. michael@0: * The factory encapsulates the logic for establishing a socket connection. michael@0: * michael@0: * @since 4.0 michael@0: * michael@0: * @deprecated use {@link SchemeSocketFactory} michael@0: */ michael@0: @Deprecated michael@0: public interface SocketFactory { michael@0: michael@0: /** michael@0: * Creates a new, unconnected socket. michael@0: * The socket should subsequently be passed to michael@0: * {@link #connectSocket connectSocket}. 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() michael@0: throws IOException; michael@0: michael@0: /** michael@0: * Connects a socket to the given host. michael@0: * michael@0: * @param sock the socket to connect, as obtained from michael@0: * {@link #createSocket createSocket}. michael@0: * null indicates that a new socket michael@0: * should be created and connected. michael@0: * @param host the host to connect to michael@0: * @param port the port to connect to on the host michael@0: * @param localAddress the local address to bind the socket to, or michael@0: * null for any michael@0: * @param localPort the port on the local machine, michael@0: * 0 or a negative number 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: String host, michael@0: int port, michael@0: InetAddress localAddress, michael@0: int localPort, michael@0: HttpParams params michael@0: ) throws IOException, UnknownHostException, ConnectTimeoutException; michael@0: michael@0: /** michael@0: * Checks whether a socket provides a secure connection. michael@0: * The socket must be {@link #connectSocket connected} michael@0: * by this factory. michael@0: * The factory will not perform I/O operations michael@0: * in this method. michael@0: *
michael@0: * As a rule of thumb, plain sockets are not secure and michael@0: * TLS/SSL sockets are secure. However, there may be michael@0: * application specific deviations. For example, a plain michael@0: * socket to a host in the same intranet ("trusted zone") michael@0: * could be considered secure. On the other hand, a michael@0: * TLS/SSL socket could be considered insecure based on michael@0: * 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) michael@0: throws IllegalArgumentException; michael@0: michael@0: }