16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 *
26 * This class includes a proxy server that processes HTTP CONNECT requests,
27 * and tunnels the data from the client to the server, once the CONNECT
28 * is accepted.
29 * It is used by the regression test for the bug fixes: 4323990, 4413069
30 */
31 import java.io.*;
32 import java.net.*;
33 import javax.net.ssl.*;
34 import javax.net.ServerSocketFactory;
35 import sun.net.www.*;
36
37 public class ProxyTunnelServer extends Thread {
38
39 private static ServerSocket ss = null;
40 /*
41 * holds the registered user's username and password
42 * only one such entry is maintained
43 */
44 private String userPlusPass;
45
46 // client requesting for a tunnel
47 private Socket clientSocket = null;
48
49 /*
50 * Origin server's address and port that the client
51 * wants to establish the tunnel for communication.
52 */
53 private InetAddress serverInetAddr;
54 private int serverPort;
55
275 + connectStr);
276 }
277 serverInetAddr = InetAddress.getByName(serverName);
278 }
279
280 public int getPort() {
281 return ss.getLocalPort();
282 }
283
284 /*
285 * do "basic" authentication, authInfo is of the form:
286 * Basic <encoded username":"password>
287 * reference RFC 2617
288 */
289 private boolean authenticate(String authInfo) throws IOException {
290 boolean matched = false;
291 try {
292 authInfo.trim();
293 int ind = authInfo.indexOf(' ');
294 String recvdUserPlusPass = authInfo.substring(ind + 1).trim();
295 // extract encoded (username:passwd
296 if (userPlusPass.equals(
297 new String(
298 (new sun.misc.BASE64Decoder()).
299 decodeBuffer(recvdUserPlusPass)
300 ))) {
301 matched = true;
302 }
303 } catch (Exception e) {
304 throw new IOException(
305 "Proxy received invalid Proxy-Authorization value: "
306 + authInfo);
307 }
308 return matched;
309 }
310 }
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 *
26 * This class includes a proxy server that processes HTTP CONNECT requests,
27 * and tunnels the data from the client to the server, once the CONNECT
28 * is accepted.
29 * It is used by the regression test for the bug fixes: 4323990, 4413069
30 */
31 import java.io.*;
32 import java.net.*;
33 import javax.net.ssl.*;
34 import javax.net.ServerSocketFactory;
35 import sun.net.www.*;
36 import java.util.Base64;
37
38 public class ProxyTunnelServer extends Thread {
39
40 private static ServerSocket ss = null;
41 /*
42 * holds the registered user's username and password
43 * only one such entry is maintained
44 */
45 private String userPlusPass;
46
47 // client requesting for a tunnel
48 private Socket clientSocket = null;
49
50 /*
51 * Origin server's address and port that the client
52 * wants to establish the tunnel for communication.
53 */
54 private InetAddress serverInetAddr;
55 private int serverPort;
56
276 + connectStr);
277 }
278 serverInetAddr = InetAddress.getByName(serverName);
279 }
280
281 public int getPort() {
282 return ss.getLocalPort();
283 }
284
285 /*
286 * do "basic" authentication, authInfo is of the form:
287 * Basic <encoded username":"password>
288 * reference RFC 2617
289 */
290 private boolean authenticate(String authInfo) throws IOException {
291 boolean matched = false;
292 try {
293 authInfo.trim();
294 int ind = authInfo.indexOf(' ');
295 String recvdUserPlusPass = authInfo.substring(ind + 1).trim();
296
297 // extract encoded (username:passwd
298 if (userPlusPass.equals(
299 new String( Base64.getMimeDecoder()
300 .decode(recvdUserPlusPass))))
301 {
302 matched = true;
303 }
304 } catch (Exception e) {
305 throw new IOException(
306 "Proxy received invalid Proxy-Authorization value: "
307 + authInfo);
308 }
309 return matched;
310 }
311 }
|