/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
*
* This class includes a proxy server that processes HTTP CONNECT requests,
* and tunnels the data from the client to the server, once the CONNECT
* request is accepted.
* It is used by the TunnelThroughProxy test.
*/
/*
* holds the registered user's username and password
* only one such entry is maintained
*/
// client requesting for a tunnel
/*
* Origin server's address and port that the client
* wants to establish the tunnel for communication.
*/
private int serverPort;
/*
* denote whether the proxy needs to authorize
* CONNECT requests.
*/
static boolean needAuth = false;
}
}
}
/*
* register users with the proxy, by providing username and
* password. The username and password are used for authorizing the
* user when a CONNECT request is made and needAuth is set to true.
*/
}
public void run() {
try {
} catch (Exception e) {
e.printStackTrace();
try {
}
catch (IOException excep) {
}
}
}
/*
* Processes the CONNECT requests, if needAuth is set to true, then
* the name and password are extracted from the Proxy-Authorization header
* of the request. They are checked against the one that is registered,
* if there is a match, connection is set in tunneling mode. If
* needAuth is set to false, Proxy-Authorization checks are not made
*/
// retrieve the host and port info from the status-line
// retrieveConnectInfo(statusLine);
if (needAuth) {
!= null) {
if (authenticate(authInfo)) {
needAuth = false;
"Proxy: client authentication successful");
}
}
}
// connection set to the tunneling mode
if (!needAuth) {
// doTunnel();
/*
* done with tunneling, we process only one successful
* tunneling request
*/
} else {
// we may get another request with Proxy-Authorization set
restart();
}
} else {
+ "CONNECT method requests, recieved: "
+ statusLine);
}
}
if (needAuth) {
} else {
}
}
}
/*sc
* note: Tunneling has to be provided in both directions, i.e
* from client->server and server->client, even if the application
* data may be unidirectional, SSL handshaking data flows in either
* direction.
*/
}
/*
* This inner class provides unidirectional data flow through the sockets
* by continuously copying bytes from the input socket onto the output
* socket, until both sockets are open and EOF has not been received.
*/
throws Exception {
}
public void run() {
int BUFFER_SIZE = 400;
byte[] buf = new byte[BUFFER_SIZE];
int bytesRead = 0;
try {
}
} catch (IOException e) {
/*
* The peer end has closed the connection
* we will close the tunnel
*/
close();
}
}
public void close() {
try {
} catch (IOException ignored) { }
}
}
/*
***************************************************************
* helper methods follow
***************************************************************
*/
/*
* This method retrieves the hostname and port of the destination
* that the connect request wants to establish a tunnel for
* communication.
* The input, connectStr is of the form:
* CONNECT server-name:server-port HTTP/1.x
*/
int starti;
int endi;
try {
// retrieve server name and port
} catch (Exception e) {
throw new IOException("Proxy recieved a request: "
+ connectStr);
}
}
public int getPort() {
return ss.getLocalPort();
}
/*
* do "basic" authentication, authInfo is of the form:
* Basic <encoded username":"password>
* reference RFC 2617
*/
boolean matched = false;
try {
// extract encoded (username:passwd
if (userPlusPass.equals(
new String(
))) {
matched = true;
}
} catch (Exception e) {
throw new IOException(
"Proxy received invalid Proxy-Authorization value: "
+ authInfo);
}
return matched;
}
}