提交 d1f2f618 编写于 作者: C chegar

6973030: NTLM proxy authentication fails with https

Reviewed-by: michaelm
上级 879f7042
...@@ -1768,6 +1768,10 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -1768,6 +1768,10 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
// Not really necessary for a tunnel, but can't hurt // Not really necessary for a tunnel, but can't hurt
requests.setIfNotSet("Accept", acceptString); requests.setIfNotSet("Accept", acceptString);
if (http.getHttpKeepAliveSet()) {
requests.setIfNotSet("Proxy-Connection", "keep-alive");
}
setPreemptiveProxyAuthentication(requests); setPreemptiveProxyAuthentication(requests);
/* Log the CONNECT request */ /* Log the CONNECT request */
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 6226610 * @bug 6226610 6973030
* @run main/othervm B6226610 * @run main/othervm B6226610
* @summary HTTP tunnel connections send user headers to proxy * @summary HTTP tunnel connections send user headers to proxy
*/ */
...@@ -36,45 +36,23 @@ ...@@ -36,45 +36,23 @@
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import javax.net.ssl.*; import sun.net.www.MessageHeader;
import javax.net.ServerSocketFactory;
import sun.net.www.*;
import java.util.Enumeration;
public class B6226610 { public class B6226610 {
static HeaderCheckerProxyTunnelServer proxy; static HeaderCheckerProxyTunnelServer proxy;
// it seems there's no proxy ever if a url points to 'localhost', public static void main(String[] args) throws Exception
// even if proxy related properties are set. so we need to bind
// our simple http proxy and http server to a non-loopback address
static InetAddress firstNonLoAddress = null;
public static void main(String[] args)
{ {
try { proxy = new HeaderCheckerProxyTunnelServer();
proxy = new HeaderCheckerProxyTunnelServer(); proxy.start();
proxy.start();
} catch (Exception e) {
System.out.println("Cannot create proxy: " + e);
}
try {
firstNonLoAddress = getNonLoAddress();
if (firstNonLoAddress == null) {
System.out.println("The test needs at least one non-loopback address to run. Quit now.");
System.exit(0);
}
} catch (Exception e) {
e.printStackTrace();
}
System.setProperty( "https.proxyHost", firstNonLoAddress.getHostAddress()); String hostname = InetAddress.getLocalHost().getHostName();
System.setProperty( "https.proxyPort", (new Integer(proxy.getLocalPort())).toString() );
try { try {
URL u = new URL("https://" + firstNonLoAddress.getHostAddress()); URL u = new URL("https://" + hostname + "/");
java.net.URLConnection c = u.openConnection(); System.out.println("Connecting to " + u);
InetSocketAddress proxyAddr = new InetSocketAddress(hostname, proxy.getLocalPort());
java.net.URLConnection c = u.openConnection(new Proxy(Proxy.Type.HTTP, proxyAddr));
/* I want this header to go to the destination server only, protected /* I want this header to go to the destination server only, protected
* by SSL * by SSL
...@@ -89,33 +67,15 @@ public class B6226610 { ...@@ -89,33 +67,15 @@ public class B6226610 {
} }
else else
System.out.println(e); System.out.println(e);
} finally {
if (proxy != null) proxy.shutdown();
} }
if (HeaderCheckerProxyTunnelServer.failed) if (HeaderCheckerProxyTunnelServer.failed)
throw new RuntimeException("Test failed: Proxy should not receive user defined headers for tunneled requests"); throw new RuntimeException("Test failed; see output");
}
public static InetAddress getNonLoAddress() throws Exception {
NetworkInterface loNIC = NetworkInterface.getByInetAddress(InetAddress.getByName("localhost"));
Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
while (nics.hasMoreElements()) {
NetworkInterface nic = nics.nextElement();
if (!nic.getName().equalsIgnoreCase(loNIC.getName())) {
Enumeration<InetAddress> addrs = nic.getInetAddresses();
while (addrs.hasMoreElements()) {
InetAddress addr = addrs.nextElement();
if (!addr.isLoopbackAddress())
return addr;
}
}
}
return null;
} }
} }
class HeaderCheckerProxyTunnelServer extends Thread class HeaderCheckerProxyTunnelServer extends Thread
{ {
public static boolean failed = false; public static boolean failed = false;
...@@ -139,6 +99,10 @@ class HeaderCheckerProxyTunnelServer extends Thread ...@@ -139,6 +99,10 @@ class HeaderCheckerProxyTunnelServer extends Thread
} }
} }
void shutdown() {
try { ss.close(); } catch (IOException e) {}
}
public void run() public void run()
{ {
try { try {
...@@ -178,6 +142,15 @@ class HeaderCheckerProxyTunnelServer extends Thread ...@@ -178,6 +142,15 @@ class HeaderCheckerProxyTunnelServer extends Thread
retrieveConnectInfo(statusLine); retrieveConnectInfo(statusLine);
if (mheader.findValue("X-TestHeader") != null) { if (mheader.findValue("X-TestHeader") != null) {
System.out.println("Proxy should not receive user defined headers for tunneled requests");
failed = true;
}
// 6973030
String value;
if ((value = mheader.findValue("Proxy-Connection")) == null ||
!value.equals("keep-alive")) {
System.out.println("Proxy-Connection:keep-alive not being sent");
failed = true; failed = true;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册