14 * 15 * You should have received a copy of the GNU General Public License version 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 // SunJSSE does not support dynamic system properties, no way to re-use 26 // system properties in samevm/agentvm mode. 27 // 28 29 /* 30 * @test 31 * @bug 6216082 32 * @summary Redirect problem with HttpsURLConnection using a proxy 33 * @modules java.base/sun.net.www 34 * @library .. 35 * @build HttpCallback TestHttpsServer ClosedChannelList 36 * HttpTransaction TunnelProxy 37 * @key intermittent 38 * @run main/othervm B6216082 39 */ 40 41 import java.io.*; 42 import java.net.*; 43 import javax.net.ssl.*; 44 import java.util.*; 45 46 public class B6216082 { 47 static SimpleHttpTransaction httpTrans; 48 static TestHttpsServer server; 49 static TunnelProxy proxy; 50 51 // it seems there's no proxy ever if a url points to 'localhost', 52 // even if proxy related properties are set. so we need to bind 53 // our simple http proxy and http server to a non-loopback address 54 static InetAddress firstNonLoAddress = null; 55 56 public static void main(String[] args) throws Exception { 57 HostnameVerifier reservedHV = 58 HttpsURLConnection.getDefaultHostnameVerifier(); 59 try { 60 // XXX workaround for CNFE 61 Class.forName("java.nio.channels.ClosedByInterruptException"); 62 if (!setupEnv()) { 63 return; 64 } 65 101 } 102 System.out.println(firstNonLoAddress.getHostAddress()); 103 // will use proxy 104 System.setProperty( "https.proxyHost", firstNonLoAddress.getHostAddress()); 105 106 // setup properties to do ssl 107 String keyFilename = System.getProperty("test.src", "./") + "/" + 108 pathToStores + "/" + keyStoreFile; 109 String trustFilename = System.getProperty("test.src", "./") + "/" + 110 pathToStores + "/" + trustStoreFile; 111 112 System.setProperty("javax.net.ssl.keyStore", keyFilename); 113 System.setProperty("javax.net.ssl.keyStorePassword", passwd); 114 System.setProperty("javax.net.ssl.trustStore", trustFilename); 115 System.setProperty("javax.net.ssl.trustStorePassword", passwd); 116 HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier()); 117 return true; 118 } 119 120 public static InetAddress getNonLoAddress() throws Exception { 121 NetworkInterface loNIC = NetworkInterface.getByInetAddress(InetAddress.getByName("localhost")); 122 Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces(); 123 while (nics.hasMoreElements()) { 124 NetworkInterface nic = nics.nextElement(); 125 if (!nic.getName().equalsIgnoreCase(loNIC.getName())) { 126 Enumeration<InetAddress> addrs = nic.getInetAddresses(); 127 while (addrs.hasMoreElements()) { 128 InetAddress addr = addrs.nextElement(); 129 if (!addr.isLoopbackAddress()) 130 return addr; 131 } 132 } 133 } 134 135 return null; 136 } 137 138 public static void startHttpServer() throws IOException { 139 // Both the https server and the proxy let the 140 // system pick up an ephemeral port. 141 httpTrans = new SimpleHttpTransaction(); 142 server = new TestHttpsServer(httpTrans, 1, 10, 0); 143 proxy = new TunnelProxy(1, 10, 0); 144 } 145 146 public static void makeHttpCall() throws Exception { 147 System.out.println("https server listen on: " + server.getLocalPort()); 148 System.out.println("https proxy listen on: " + proxy.getLocalPort()); 149 URL url = new URL("https" , firstNonLoAddress.getHostAddress(), 150 server.getLocalPort(), "/"); 151 HttpURLConnection uc = (HttpURLConnection)url.openConnection(); 152 System.out.println(uc.getResponseCode()); 153 uc.disconnect(); 154 } 155 | 14 * 15 * You should have received a copy of the GNU General Public License version 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 // SunJSSE does not support dynamic system properties, no way to re-use 26 // system properties in samevm/agentvm mode. 27 // 28 29 /* 30 * @test 31 * @bug 6216082 32 * @summary Redirect problem with HttpsURLConnection using a proxy 33 * @modules java.base/sun.net.www 34 * @library .. /lib/testlibrary 35 * @build HttpCallback TestHttpsServer ClosedChannelList 36 * HttpTransaction TunnelProxy jdk.testlibrary.NetworkConfiguration 37 * @key intermittent 38 * @run main/othervm B6216082 39 */ 40 41 import java.io.*; 42 import java.net.*; 43 import javax.net.ssl.*; 44 import java.util.*; 45 46 import jdk.testlibrary.NetworkConfiguration; 47 48 public class B6216082 { 49 static SimpleHttpTransaction httpTrans; 50 static TestHttpsServer server; 51 static TunnelProxy proxy; 52 53 // it seems there's no proxy ever if a url points to 'localhost', 54 // even if proxy related properties are set. so we need to bind 55 // our simple http proxy and http server to a non-loopback address 56 static InetAddress firstNonLoAddress = null; 57 58 public static void main(String[] args) throws Exception { 59 HostnameVerifier reservedHV = 60 HttpsURLConnection.getDefaultHostnameVerifier(); 61 try { 62 // XXX workaround for CNFE 63 Class.forName("java.nio.channels.ClosedByInterruptException"); 64 if (!setupEnv()) { 65 return; 66 } 67 103 } 104 System.out.println(firstNonLoAddress.getHostAddress()); 105 // will use proxy 106 System.setProperty( "https.proxyHost", firstNonLoAddress.getHostAddress()); 107 108 // setup properties to do ssl 109 String keyFilename = System.getProperty("test.src", "./") + "/" + 110 pathToStores + "/" + keyStoreFile; 111 String trustFilename = System.getProperty("test.src", "./") + "/" + 112 pathToStores + "/" + trustStoreFile; 113 114 System.setProperty("javax.net.ssl.keyStore", keyFilename); 115 System.setProperty("javax.net.ssl.keyStorePassword", passwd); 116 System.setProperty("javax.net.ssl.trustStore", trustFilename); 117 System.setProperty("javax.net.ssl.trustStorePassword", passwd); 118 HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier()); 119 return true; 120 } 121 122 public static InetAddress getNonLoAddress() throws Exception { 123 InetAddress lh = InetAddress.getByName("localhost"); 124 NetworkInterface loNIC = NetworkInterface.getByInetAddress(lh); 125 126 NetworkConfiguration nc = NetworkConfiguration.probe(); 127 Optional<InetAddress> oaddr = nc.interfaces() 128 .filter(nif -> !nif.getName().equalsIgnoreCase(loNIC.getName())) 129 .flatMap(nif -> nc.addresses(nif)) 130 .filter(a -> !a.isLoopbackAddress()) 131 .findFirst(); 132 133 return oaddr.orElseGet(() -> null); 134 } 135 136 public static void startHttpServer() throws IOException { 137 // Both the https server and the proxy let the 138 // system pick up an ephemeral port. 139 httpTrans = new SimpleHttpTransaction(); 140 server = new TestHttpsServer(httpTrans, 1, 10, 0); 141 proxy = new TunnelProxy(1, 10, 0); 142 } 143 144 public static void makeHttpCall() throws Exception { 145 System.out.println("https server listen on: " + server.getLocalPort()); 146 System.out.println("https proxy listen on: " + proxy.getLocalPort()); 147 URL url = new URL("https" , firstNonLoAddress.getHostAddress(), 148 server.getLocalPort(), "/"); 149 HttpURLConnection uc = (HttpURLConnection)url.openConnection(); 150 System.out.println(uc.getResponseCode()); 151 uc.disconnect(); 152 } 153 |