mobile/android/thirdparty/ch/boye/httpclientandroidlib/conn/scheme/SchemeSocketFactory.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 * ====================================================================
michael@0 3 * Licensed to the Apache Software Foundation (ASF) under one
michael@0 4 * or more contributor license agreements. See the NOTICE file
michael@0 5 * distributed with this work for additional information
michael@0 6 * regarding copyright ownership. The ASF licenses this file
michael@0 7 * to you under the Apache License, Version 2.0 (the
michael@0 8 * "License"); you may not use this file except in compliance
michael@0 9 * with the License. You may obtain a copy of the License at
michael@0 10 *
michael@0 11 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 12 *
michael@0 13 * Unless required by applicable law or agreed to in writing,
michael@0 14 * software distributed under the License is distributed on an
michael@0 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
michael@0 16 * KIND, either express or implied. See the License for the
michael@0 17 * specific language governing permissions and limitations
michael@0 18 * under the License.
michael@0 19 * ====================================================================
michael@0 20 *
michael@0 21 * This software consists of voluntary contributions made by many
michael@0 22 * individuals on behalf of the Apache Software Foundation. For more
michael@0 23 * information on the Apache Software Foundation, please see
michael@0 24 * <http://www.apache.org/>.
michael@0 25 *
michael@0 26 */
michael@0 27
michael@0 28 package ch.boye.httpclientandroidlib.conn.scheme;
michael@0 29
michael@0 30 import java.io.IOException;
michael@0 31 import java.net.InetSocketAddress;
michael@0 32 import java.net.Socket;
michael@0 33 import java.net.UnknownHostException;
michael@0 34
michael@0 35 import ch.boye.httpclientandroidlib.conn.ConnectTimeoutException;
michael@0 36 import ch.boye.httpclientandroidlib.params.HttpParams;
michael@0 37
michael@0 38 /**
michael@0 39 * A factory for creating, initializing and connecting sockets. The factory encapsulates the logic
michael@0 40 * for establishing a socket connection.
michael@0 41 *
michael@0 42 * @since 4.1
michael@0 43 */
michael@0 44 public interface SchemeSocketFactory {
michael@0 45
michael@0 46 /**
michael@0 47 * Creates a new, unconnected socket. The socket should subsequently be passed to
michael@0 48 * {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)}.
michael@0 49 *
michael@0 50 * @param params Optional {@link HttpParams parameters}. In most cases these parameters
michael@0 51 * will not be required and will have no effect, as usually socket
michael@0 52 * initialization should take place in the
michael@0 53 * {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)}
michael@0 54 * method. However, in rare cases one may want to pass additional parameters
michael@0 55 * to this method in order to create a customized {@link Socket} instance,
michael@0 56 * for instance bound to a SOCKS proxy server.
michael@0 57 *
michael@0 58 * @return a new socket
michael@0 59 *
michael@0 60 * @throws IOException if an I/O error occurs while creating the socket
michael@0 61 */
michael@0 62 Socket createSocket(HttpParams params) throws IOException;
michael@0 63
michael@0 64 /**
michael@0 65 * Connects a socket to the target host with the given remote address.
michael@0 66 *
michael@0 67 * @param sock the socket to connect, as obtained from
michael@0 68 * {@link #createSocket(HttpParams) createSocket}.
michael@0 69 * <code>null</code> indicates that a new socket
michael@0 70 * should be created and connected.
michael@0 71 * @param remoteAddress the remote address to connect to
michael@0 72 * @param localAddress the local address to bind the socket to, or
michael@0 73 * <code>null</code> for any
michael@0 74 * @param params additional {@link HttpParams parameters} for connecting
michael@0 75 *
michael@0 76 * @return the connected socket. The returned object may be different
michael@0 77 * from the <code>sock</code> argument if this factory supports
michael@0 78 * a layered protocol.
michael@0 79 *
michael@0 80 * @throws IOException if an I/O error occurs
michael@0 81 * @throws UnknownHostException if the IP address of the target host
michael@0 82 * can not be determined
michael@0 83 * @throws ConnectTimeoutException if the socket cannot be connected
michael@0 84 * within the time limit defined in the <code>params</code>
michael@0 85 */
michael@0 86 Socket connectSocket(
michael@0 87 Socket sock,
michael@0 88 InetSocketAddress remoteAddress,
michael@0 89 InetSocketAddress localAddress,
michael@0 90 HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException;
michael@0 91
michael@0 92 /**
michael@0 93 * Checks whether a socket provides a secure connection. The socket must be
michael@0 94 * {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams) connected}
michael@0 95 * by this factory. The factory will <i>not</i> perform I/O operations in this method.
michael@0 96 * <p>
michael@0 97 * As a rule of thumb, plain sockets are not secure and TLS/SSL sockets are secure. However,
michael@0 98 * there may be application specific deviations. For example, a plain socket to a host in the
michael@0 99 * same intranet ("trusted zone") could be considered secure. On the other hand, a TLS/SSL
michael@0 100 * socket could be considered insecure based on the cipher suite chosen for the connection.
michael@0 101 *
michael@0 102 * @param sock the connected socket to check
michael@0 103 *
michael@0 104 * @return <code>true</code> if the connection of the socket
michael@0 105 * should be considered secure, or
michael@0 106 * <code>false</code> if it should not
michael@0 107 *
michael@0 108 * @throws IllegalArgumentException
michael@0 109 * if the argument is invalid, for example because it is
michael@0 110 * not a connected socket or was created by a different
michael@0 111 * socket factory.
michael@0 112 * Note that socket factories are <i>not</i> required to
michael@0 113 * check these conditions, they may simply return a default
michael@0 114 * value when called with an invalid socket argument.
michael@0 115 */
michael@0 116 boolean isSecure(Socket sock) throws IllegalArgumentException;
michael@0 117
michael@0 118 }

mercurial