1 /* |
1 /* |
2 * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
57 import java.io.BufferedReader; |
57 import java.io.BufferedReader; |
58 import java.io.DataOutputStream; |
58 import java.io.DataOutputStream; |
59 import java.io.IOException; |
59 import java.io.IOException; |
60 import java.io.InputStreamReader; |
60 import java.io.InputStreamReader; |
61 import java.net.Authenticator; |
61 import java.net.Authenticator; |
|
62 import java.net.InetAddress; |
62 import java.net.InetSocketAddress; |
63 import java.net.InetSocketAddress; |
63 import java.net.PasswordAuthentication; |
64 import java.net.PasswordAuthentication; |
64 import java.net.Proxy; |
65 import java.net.Proxy; |
65 import java.net.URL; |
66 import java.net.URL; |
66 import javax.net.ssl.HostnameVerifier; |
67 import javax.net.ssl.HostnameVerifier; |
77 * authentication proxy |
78 * authentication proxy |
78 */ |
79 */ |
79 |
80 |
80 public class ProxyAuthTest extends SSLSocketTemplate { |
81 public class ProxyAuthTest extends SSLSocketTemplate { |
81 private static boolean expectSuccess; |
82 private static boolean expectSuccess; |
|
83 |
|
84 ProxyAuthTest() { |
|
85 serverAddress = InetAddress.getLoopbackAddress(); |
|
86 } |
82 |
87 |
83 /* |
88 /* |
84 * Run the test case. |
89 * Run the test case. |
85 */ |
90 */ |
86 public static void main(String[] args) throws Exception { |
91 public static void main(String[] args) throws Exception { |
141 * we want to avoid URLspoofCheck failures in cases where the cert |
146 * we want to avoid URLspoofCheck failures in cases where the cert |
142 * DN name does not match the hostname in the URL. |
147 * DN name does not match the hostname in the URL. |
143 */ |
148 */ |
144 HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier()); |
149 HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier()); |
145 |
150 |
146 InetSocketAddress paddr = |
151 InetSocketAddress paddr = InetSocketAddress |
147 new InetSocketAddress("localhost", ps.getPort()); |
152 .createUnresolved(ps.getInetAddress().getHostAddress(), |
|
153 ps.getPort()); |
148 Proxy proxy = new Proxy(Proxy.Type.HTTP, paddr); |
154 Proxy proxy = new Proxy(Proxy.Type.HTTP, paddr); |
149 |
155 |
|
156 InetAddress serverAddress = this.serverAddress; |
|
157 String host = serverAddress == null |
|
158 ? "localhost" |
|
159 : serverAddress.getHostAddress(); |
|
160 if (host.indexOf(':') > -1) host = "[" + host + "]"; |
150 URL url = new URL( |
161 URL url = new URL( |
151 "https://" + "localhost:" + serverPort + "/index.html"); |
162 "https://" + host + ":" + serverPort + "/index.html"); |
|
163 System.out.println("URL: " + url); |
152 BufferedReader in = null; |
164 BufferedReader in = null; |
153 HttpsURLConnection uc = (HttpsURLConnection) url.openConnection(proxy); |
165 HttpsURLConnection uc = (HttpsURLConnection) url.openConnection(proxy); |
154 try { |
166 try { |
155 in = new BufferedReader(new InputStreamReader(uc.getInputStream())); |
167 in = new BufferedReader(new InputStreamReader(uc.getInputStream())); |
156 String inputLine; |
168 String inputLine; |
157 System.out.print("Client recieved from the server: "); |
169 System.out.print("Client received from the server: "); |
158 while ((inputLine = in.readLine()) != null) { |
170 while ((inputLine = in.readLine()) != null) { |
159 System.out.println(inputLine); |
171 System.out.println(inputLine); |
160 } |
172 } |
161 if (!expectSuccess) { |
173 if (!expectSuccess) { |
162 throw new RuntimeException( |
174 throw new RuntimeException( |