History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/net/www/protocol/https (7 of 18352 files). Show all

Unified · Split

7 files
  1. java/pkg/sun/net/www/protocol/https/AbstractDelegateHttpsURLConnection.java +312 −0
  2. java/pkg/sun/net/www/protocol/https/DefaultHostnameVerifier.java +45 −0
  3. java/pkg/sun/net/www/protocol/https/DelegateHttpsURLConnection.java +83 −0
  4. java/pkg/sun/net/www/protocol/https/Handler.java +64 −0
  5. java/pkg/sun/net/www/protocol/https/HttpsClient.java +749 −0
  6. java/pkg/sun/net/www/protocol/https/HttpsURLConnectionImpl.java +537 −0
  7. java/pkg/sun/net/www/protocol/https/mkfile +13 −0
java/pkg/sun/net/www/protocol/https/AbstractDelegateHttpsURLConnection.java+312−0
@@ -0,0 +1,312 @@
1+/*
2+ * Copyright (c) 2001, 2006, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
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
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package sun.net.www.protocol.https;
27+
28+import java.net.URL;
29+import java.net.Proxy;
30+import java.net.SecureCacheResponse;
31+import java.security.Principal;
32+import java.io.IOException;
33+import java.util.List;
34+import javax.net.ssl.SSLPeerUnverifiedException;
35+import sun.net.www.http.*;
36+import sun.net.www.protocol.http.HttpURLConnection;
37+
38+/**
39+ * HTTPS URL connection support.
40+ * We need this delegate because HttpsURLConnection is a subclass of
41+ * java.net.HttpURLConnection. We will avoid copying over the code from
42+ * sun.net.www.protocol.http.HttpURLConnection by having this class
43+ *
44+ */
45+public abstract class AbstractDelegateHttpsURLConnection extends
46+ HttpURLConnection {
47+
48+ protected AbstractDelegateHttpsURLConnection(URL url,
49+ sun.net.www.protocol.http.Handler handler) throws IOException {
50+ this(url, null, handler);
51+ }
52+
53+ protected AbstractDelegateHttpsURLConnection(URL url, Proxy p,
54+ sun.net.www.protocol.http.Handler handler) throws IOException {
55+ super(url, p, handler);
56+ }
57+
58+ protected abstract javax.net.ssl.SSLSocketFactory getSSLSocketFactory();
59+
60+ protected abstract javax.net.ssl.HostnameVerifier getHostnameVerifier();
61+
62+ /**
63+ * No user application is able to call these routines, as no one
64+ * should ever get access to an instance of
65+ * DelegateHttpsURLConnection (sun.* or com.*)
66+ */
67+
68+ /**
69+ * Create a new HttpClient object, bypassing the cache of
70+ * HTTP client objects/connections.
71+ *
72+ * Note: this method is changed from protected to public because
73+ * the com.sun.ssl.internal.www.protocol.https handler reuses this
74+ * class for its actual implemantation
75+ *
76+ * @param url the URL being accessed
77+ */
78+ public void setNewClient (URL url)
79+ throws IOException {
80+ setNewClient (url, false);
81+ }
82+
83+ /**
84+ * Obtain a HttpClient object. Use the cached copy if specified.
85+ *
86+ * Note: this method is changed from protected to public because
87+ * the com.sun.ssl.internal.www.protocol.https handler reuses this
88+ * class for its actual implemantation
89+ *
90+ * @param url the URL being accessed
91+ * @param useCache whether the cached connection should be used
92+ * if present
93+ */
94+ public void setNewClient (URL url, boolean useCache)
95+ throws IOException {
96+ http = HttpsClient.New (getSSLSocketFactory(),
97+ url,
98+ getHostnameVerifier(),
99+ useCache);
100+ ((HttpsClient)http).afterConnect();
101+ }
102+
103+ /**
104+ * Create a new HttpClient object, set up so that it uses
105+ * per-instance proxying to the given HTTP proxy. This
106+ * bypasses the cache of HTTP client objects/connections.
107+ *
108+ * Note: this method is changed from protected to public because
109+ * the com.sun.ssl.internal.www.protocol.https handler reuses this
110+ * class for its actual implemantation
111+ *
112+ * @param url the URL being accessed
113+ * @param proxyHost the proxy host to use
114+ * @param proxyPort the proxy port to use
115+ */
116+ public void setProxiedClient (URL url, String proxyHost, int proxyPort)
117+ throws IOException {
118+ setProxiedClient(url, proxyHost, proxyPort, false);
119+ }
120+
121+ /**
122+ * Obtain a HttpClient object, set up so that it uses per-instance
123+ * proxying to the given HTTP proxy. Use the cached copy of HTTP
124+ * client objects/connections if specified.
125+ *
126+ * Note: this method is changed from protected to public because
127+ * the com.sun.ssl.internal.www.protocol.https handler reuses this
128+ * class for its actual implemantation
129+ *
130+ * @param url the URL being accessed
131+ * @param proxyHost the proxy host to use
132+ * @param proxyPort the proxy port to use
133+ * @param useCache whether the cached connection should be used
134+ * if present
135+ */
136+ public void setProxiedClient (URL url, String proxyHost, int proxyPort,
137+ boolean useCache) throws IOException {
138+ proxiedConnect(url, proxyHost, proxyPort, useCache);
139+ if (!http.isCachedConnection()) {
140+ doTunneling();
141+ }
142+ ((HttpsClient)http).afterConnect();
143+ }
144+
145+ protected void proxiedConnect(URL url, String proxyHost, int proxyPort,
146+ boolean useCache) throws IOException {
147+ if (connected)
148+ return;
149+ http = HttpsClient.New (getSSLSocketFactory(),
150+ url,
151+ getHostnameVerifier(),
152+ proxyHost, proxyPort, useCache);
153+ connected = true;
154+ }
155+
156+ /**
157+ * Used by subclass to access "connected" variable.
158+ */
159+ public boolean isConnected() {
160+ return connected;
161+ }
162+
163+ /**
164+ * Used by subclass to access "connected" variable.
165+ */
166+ public void setConnected(boolean conn) {
167+ connected = conn;
168+ }
169+
170+ /**
171+ * Implements the HTTP protocol handler's "connect" method,
172+ * establishing an SSL connection to the server as necessary.
173+ */
174+ public void connect() throws IOException {
175+ if (connected)
176+ return;
177+ plainConnect();
178+ if (cachedResponse != null) {
179+ // using cached response
180+ return;
181+ }
182+ if (!http.isCachedConnection() && http.needsTunneling()) {
183+ doTunneling();
184+ }
185+ ((HttpsClient)http).afterConnect();
186+ }
187+
188+ // will try to use cached HttpsClient
189+ protected HttpClient getNewHttpClient(URL url, Proxy p, int connectTimeout)
190+ throws IOException {
191+ return HttpsClient.New(getSSLSocketFactory(), url,
192+ getHostnameVerifier(), p, true, connectTimeout);
193+ }
194+
195+ // will open new connection
196+ protected HttpClient getNewHttpClient(URL url, Proxy p, int connectTimeout,
197+ boolean useCache)
198+ throws IOException {
199+ return HttpsClient.New(getSSLSocketFactory(), url,
200+ getHostnameVerifier(), p,
201+ useCache, connectTimeout);
202+ }
203+
204+ /**
205+ * Returns the cipher suite in use on this connection.
206+ */
207+ public String getCipherSuite () {
208+ if (cachedResponse != null) {
209+ return ((SecureCacheResponse)cachedResponse).getCipherSuite();
210+ }
211+ if (http == null) {
212+ throw new IllegalStateException("connection not yet open");
213+ } else {
214+ return ((HttpsClient)http).getCipherSuite ();
215+ }
216+ }
217+
218+ /**
219+ * Returns the certificate chain the client sent to the
220+ * server, or null if the client did not authenticate.
221+ */
222+ public java.security.cert.Certificate[] getLocalCertificates() {
223+ if (cachedResponse != null) {
224+ List l = ((SecureCacheResponse)cachedResponse).getLocalCertificateChain();
225+ if (l == null) {
226+ return null;
227+ } else {
228+ return (java.security.cert.Certificate[])l.toArray();
229+ }
230+ }
231+ if (http == null) {
232+ throw new IllegalStateException("connection not yet open");
233+ } else {
234+ return (((HttpsClient)http).getLocalCertificates ());
235+ }
236+ }
237+
238+ /**
239+ * Returns the server's certificate chain, or throws
240+ * SSLPeerUnverified Exception if
241+ * the server did not authenticate.
242+ */
243+ public java.security.cert.Certificate[] getServerCertificates()
244+ throws SSLPeerUnverifiedException {
245+ if (cachedResponse != null) {
246+ List l = ((SecureCacheResponse)cachedResponse).getServerCertificateChain();
247+ if (l == null) {
248+ return null;
249+ } else {
250+ return (java.security.cert.Certificate[])l.toArray();
251+ }
252+ }
253+
254+ if (http == null) {
255+ throw new IllegalStateException("connection not yet open");
256+ } else {
257+ return (((HttpsClient)http).getServerCertificates ());
258+ }
259+ }
260+
261+ /**
262+ * Returns the server's X.509 certificate chain, or null if
263+ * the server did not authenticate.
264+ */
265+ public javax.security.cert.X509Certificate[] getServerCertificateChain()
266+ throws SSLPeerUnverifiedException {
267+ if (cachedResponse != null) {
268+ throw new UnsupportedOperationException("this method is not supported when using cache");
269+ }
270+ if (http == null) {
271+ throw new IllegalStateException("connection not yet open");
272+ } else {
273+ return ((HttpsClient)http).getServerCertificateChain ();
274+ }
275+ }
276+
277+ /**
278+ * Returns the server's principal, or throws SSLPeerUnverifiedException
279+ * if the server did not authenticate.
280+ */
281+ Principal getPeerPrincipal()
282+ throws SSLPeerUnverifiedException
283+ {
284+ if (cachedResponse != null) {
285+ return ((SecureCacheResponse)cachedResponse).getPeerPrincipal();
286+ }
287+
288+ if (http == null) {
289+ throw new IllegalStateException("connection not yet open");
290+ } else {
291+ return (((HttpsClient)http).getPeerPrincipal());
292+ }
293+ }
294+
295+ /**
296+ * Returns the principal the client sent to the
297+ * server, or null if the client did not authenticate.
298+ */
299+ Principal getLocalPrincipal()
300+ {
301+ if (cachedResponse != null) {
302+ return ((SecureCacheResponse)cachedResponse).getLocalPrincipal();
303+ }
304+
305+ if (http == null) {
306+ throw new IllegalStateException("connection not yet open");
307+ } else {
308+ return (((HttpsClient)http).getLocalPrincipal());
309+ }
310+ }
311+
312+}
java/pkg/sun/net/www/protocol/https/DefaultHostnameVerifier.java+45−0
@@ -0,0 +1,45 @@
1+/*
2+ * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
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
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package sun.net.www.protocol.https;
27+
28+import javax.net.ssl.HostnameVerifier;
29+import javax.net.ssl.SSLSession;
30+
31+/**
32+ * <code>HostnameVerifier</code> provides a callback mechanism so that
33+ * implementers of this interface can supply a policy for
34+ * handling the case where the host to connect to and
35+ * the server name from the certificate mismatch.
36+ *
37+ * The default implementation will deny such connections.
38+ *
39+ * @author Xuelei Fan
40+ */
41+final public class DefaultHostnameVerifier implements HostnameVerifier {
42+ public boolean verify(String hostname, SSLSession session) {
43+ return false;
44+ }
45+}
java/pkg/sun/net/www/protocol/https/DelegateHttpsURLConnection.java+83−0
@@ -0,0 +1,83 @@
1+/*
2+ * Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
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
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package sun.net.www.protocol.https;
27+
28+import java.net.URL;
29+import java.net.Proxy;
30+import java.io.IOException;
31+
32+/**
33+ * This class was introduced to provide an additional level of
34+ * abstraction between javax.net.ssl.HttpURLConnection and
35+ * com.sun.net.ssl.HttpURLConnection objects. <p>
36+ *
37+ * javax.net.ssl.HttpURLConnection is used in the new sun.net version
38+ * of protocol implementation (this one)
39+ * com.sun.net.ssl.HttpURLConnection is used in the com.sun version.
40+ *
41+ */
42+public class DelegateHttpsURLConnection extends AbstractDelegateHttpsURLConnection {
43+
44+ // we need a reference to the HttpsURLConnection to get
45+ // the properties set there
46+ // we also need it to be public so that it can be referenced
47+ // from sun.net.www.protocol.http.HttpURLConnection
48+ // this is for ResponseCache.put(URI, URLConnection)
49+ // second parameter needs to be cast to javax.net.ssl.HttpsURLConnection
50+ // instead of AbstractDelegateHttpsURLConnection
51+ public javax.net.ssl.HttpsURLConnection httpsURLConnection;
52+
53+ DelegateHttpsURLConnection(URL url,
54+ sun.net.www.protocol.http.Handler handler,
55+ javax.net.ssl.HttpsURLConnection httpsURLConnection)
56+ throws IOException {
57+ this(url, null, handler, httpsURLConnection);
58+ }
59+
60+ DelegateHttpsURLConnection(URL url, Proxy p,
61+ sun.net.www.protocol.http.Handler handler,
62+ javax.net.ssl.HttpsURLConnection httpsURLConnection)
63+ throws IOException {
64+ super(url, p, handler);
65+ this.httpsURLConnection = httpsURLConnection;
66+ }
67+
68+ protected javax.net.ssl.SSLSocketFactory getSSLSocketFactory() {
69+ return httpsURLConnection.getSSLSocketFactory();
70+ }
71+
72+ protected javax.net.ssl.HostnameVerifier getHostnameVerifier() {
73+ return httpsURLConnection.getHostnameVerifier();
74+ }
75+
76+ /*
77+ * Called by layered delegator's finalize() method to handle closing
78+ * the underlying object.
79+ */
80+ protected void dispose() throws Throwable {
81+ super.finalize();
82+ }
83+}
java/pkg/sun/net/www/protocol/https/Handler.java+64−0
@@ -0,0 +1,64 @@
1+/*
2+ * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
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
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+/*-
27+ * HTTP stream opener
28+ */
29+
30+package sun.net.www.protocol.https;
31+
32+import java.io.IOException;
33+import java.net.URL;
34+import java.net.Proxy;
35+
36+/** open an http input stream given a URL */
37+public class Handler extends sun.net.www.protocol.http.Handler {
38+ protected String proxy;
39+ protected int proxyPort;
40+
41+ protected int getDefaultPort() {
42+ return 443;
43+ }
44+
45+ public Handler () {
46+ proxy = null;
47+ proxyPort = -1;
48+ }
49+
50+ public Handler (String proxy, int port) {
51+ this.proxy = proxy;
52+ this.proxyPort = port;
53+ }
54+
55+ protected java.net.URLConnection openConnection(URL u)
56+ throws IOException {
57+ return openConnection(u, (Proxy)null);
58+ }
59+
60+ protected java.net.URLConnection openConnection(URL u, Proxy p)
61+ throws IOException {
62+ return new HttpsURLConnectionImpl(u, p, this);
63+ }
64+}
java/pkg/sun/net/www/protocol/https/HttpsClient.java+749−0
@@ -0,0 +1,749 @@
1+/*
2+ * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
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
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+
27+package sun.net.www.protocol.https;
28+
29+import java.io.IOException;
30+import java.io.UnsupportedEncodingException;
31+import java.io.PrintStream;
32+import java.io.BufferedOutputStream;
33+import java.net.Socket;
34+import java.net.SocketException;
35+import java.net.URL;
36+import java.net.UnknownHostException;
37+import java.net.InetSocketAddress;
38+import java.net.Proxy;
39+import java.net.CookieHandler;
40+import java.security.Principal;
41+import java.security.cert.*;
42+import java.util.StringTokenizer;
43+import java.util.Vector;
44+import java.security.AccessController;
45+
46+import javax.security.auth.x500.X500Principal;
47+
48+import javax.net.ssl.*;
49+import sun.net.www.http.HttpClient;
50+import sun.security.action.*;
51+
52+import sun.security.util.HostnameChecker;
53+import sun.security.ssl.SSLSocketImpl;
54+
55+
56+/**
57+ * This class provides HTTPS client URL support, building on the standard
58+ * "sun.net.www" HTTP protocol handler. HTTPS is the same protocol as HTTP,
59+ * but differs in the transport layer which it uses: <UL>
60+ *
61+ * <LI>There's a <em>Secure Sockets Layer</em> between TCP
62+ * and the HTTP protocol code.
63+ *
64+ * <LI>It uses a different default TCP port.
65+ *
66+ * <LI>It doesn't use application level proxies, which can see and
67+ * manipulate HTTP user level data, compromising privacy. It uses
68+ * low level tunneling instead, which hides HTTP protocol and data
69+ * from all third parties. (Traffic analysis is still possible).
70+ *
71+ * <LI>It does basic server authentication, to protect
72+ * against "URL spoofing" attacks. This involves deciding
73+ * whether the X.509 certificate chain identifying the server
74+ * is trusted, and verifying that the name of the server is
75+ * found in the certificate. (The application may enable an
76+ * anonymous SSL cipher suite, and such checks are not done
77+ * for anonymous ciphers.)
78+ *
79+ * <LI>It exposes key SSL session attributes, specifically the
80+ * cipher suite in use and the server's X509 certificates, to
81+ * application software which knows about this protocol handler.
82+ *
83+ * </UL>
84+ *
85+ * <P> System properties used include: <UL>
86+ *
87+ * <LI><em>https.proxyHost</em> ... the host supporting SSL
88+ * tunneling using the conventional CONNECT syntax
89+ *
90+ * <LI><em>https.proxyPort</em> ... port to use on proxyHost
91+ *
92+ * <LI><em>https.cipherSuites</em> ... comma separated list of
93+ * SSL cipher suite names to enable.
94+ *
95+ * <LI><em>http.nonProxyHosts</em> ...
96+ *
97+ * </UL>
98+ *
99+ * @author David Brownell
100+ * @author Bill Foote
101+ */
102+
103+// final for export control reasons (access to APIs); remove with care
104+final class HttpsClient extends HttpClient
105+ implements HandshakeCompletedListener
106+{
107+ // STATIC STATE and ACCESSORS THERETO
108+
109+ // HTTPS uses a different default port number than HTTP.
110+ private static final int httpsPortNumber = 443;
111+
112+ // default HostnameVerifier class canonical name
113+ private static final String defaultHVCanonicalName =
114+ "javax.net.ssl.HttpsURLConnection.DefaultHostnameVerifier";
115+
116+ /** Returns the default HTTPS port (443) */
117+ @Override
118+ protected int getDefaultPort() { return httpsPortNumber; }
119+
120+ private HostnameVerifier hv;
121+ private SSLSocketFactory sslSocketFactory;
122+
123+ // HttpClient.proxyDisabled will always be false, because we don't
124+ // use an application-level HTTP proxy. We might tunnel through
125+ // our http proxy, though.
126+
127+
128+ // INSTANCE DATA
129+
130+ // last negotiated SSL session
131+ private SSLSession session;
132+
133+ private String [] getCipherSuites() {
134+ //
135+ // If ciphers are assigned, sort them into an array.
136+ //
137+ String ciphers [];
138+ String cipherString = AccessController.doPrivileged(
139+ new GetPropertyAction("https.cipherSuites"));
140+
141+ if (cipherString == null || "".equals(cipherString)) {
142+ ciphers = null;
143+ } else {
144+ StringTokenizer tokenizer;
145+ Vector<String> v = new Vector<String>();
146+
147+ tokenizer = new StringTokenizer(cipherString, ",");
148+ while (tokenizer.hasMoreTokens())
149+ v.addElement(tokenizer.nextToken());
150+ ciphers = new String [v.size()];
151+ for (int i = 0; i < ciphers.length; i++)
152+ ciphers [i] = v.elementAt(i);
153+ }
154+ return ciphers;
155+ }
156+
157+ private String [] getProtocols() {
158+ //
159+ // If protocols are assigned, sort them into an array.
160+ //
161+ String protocols [];
162+ String protocolString = AccessController.doPrivileged(
163+ new GetPropertyAction("https.protocols"));
164+
165+ if (protocolString == null || "".equals(protocolString)) {
166+ protocols = null;
167+ } else {
168+ StringTokenizer tokenizer;
169+ Vector<String> v = new Vector<String>();
170+
171+ tokenizer = new StringTokenizer(protocolString, ",");
172+ while (tokenizer.hasMoreTokens())
173+ v.addElement(tokenizer.nextToken());
174+ protocols = new String [v.size()];
175+ for (int i = 0; i < protocols.length; i++) {
176+ protocols [i] = v.elementAt(i);
177+ }
178+ }
179+ return protocols;
180+ }
181+
182+ private String getUserAgent() {
183+ String userAgent = java.security.AccessController.doPrivileged(
184+ new sun.security.action.GetPropertyAction("https.agent"));
185+ if (userAgent == null || userAgent.length() == 0) {
186+ userAgent = "JSSE";
187+ }
188+ return userAgent;
189+ }
190+
191+ // should remove once HttpClient.newHttpProxy is putback
192+ private static Proxy newHttpProxy(String proxyHost, int proxyPort) {
193+ InetSocketAddress saddr = null;
194+ final String phost = proxyHost;
195+ final int pport = proxyPort < 0 ? httpsPortNumber : proxyPort;
196+ try {
197+ saddr = java.security.AccessController.doPrivileged(new
198+ java.security.PrivilegedExceptionAction<InetSocketAddress>() {
199+ public InetSocketAddress run() {
200+ return new InetSocketAddress(phost, pport);
201+ }});
202+ } catch (java.security.PrivilegedActionException pae) {
203+ }
204+ return new Proxy(Proxy.Type.HTTP, saddr);
205+ }
206+
207+ // CONSTRUCTOR, FACTORY
208+
209+
210+ /**
211+ * Create an HTTPS client URL. Traffic will be tunneled through any
212+ * intermediate nodes rather than proxied, so that confidentiality
213+ * of data exchanged can be preserved. However, note that all the
214+ * anonymous SSL flavors are subject to "person-in-the-middle"
215+ * attacks against confidentiality. If you enable use of those
216+ * flavors, you may be giving up the protection you get through
217+ * SSL tunneling.
218+ *
219+ * Use New to get new HttpsClient. This constructor is meant to be
220+ * used only by New method. New properly checks for URL spoofing.
221+ *
222+ * @param URL https URL with which a connection must be established
223+ */
224+ private HttpsClient(SSLSocketFactory sf, URL url)
225+ throws IOException
226+ {
227+ // HttpClient-level proxying is always disabled,
228+ // because we override doConnect to do tunneling instead.
229+ this(sf, url, (String)null, -1);
230+ }
231+
232+ /**
233+ * Create an HTTPS client URL. Traffic will be tunneled through
234+ * the specified proxy server.
235+ */
236+ HttpsClient(SSLSocketFactory sf, URL url, String proxyHost, int proxyPort)
237+ throws IOException {
238+ this(sf, url, proxyHost, proxyPort, -1);
239+ }
240+
241+ /**
242+ * Create an HTTPS client URL. Traffic will be tunneled through
243+ * the specified proxy server, with a connect timeout
244+ */
245+ HttpsClient(SSLSocketFactory sf, URL url, String proxyHost, int proxyPort,
246+ int connectTimeout)
247+ throws IOException {
248+ this(sf, url,
249+ (proxyHost == null? null:
250+ HttpsClient.newHttpProxy(proxyHost, proxyPort)),
251+ connectTimeout);
252+ }
253+
254+ /**
255+ * Same as previous constructor except using a Proxy
256+ */
257+ HttpsClient(SSLSocketFactory sf, URL url, Proxy proxy,
258+ int connectTimeout)
259+ throws IOException {
260+ this.proxy = proxy;
261+ setSSLSocketFactory(sf);
262+ this.proxyDisabled = true;
263+
264+ this.host = url.getHost();
265+ this.url = url;
266+ port = url.getPort();
267+ if (port == -1) {
268+ port = getDefaultPort();
269+ }
270+ setConnectTimeout(connectTimeout);
271+ // get the cookieHandler if there is any
272+ cookieHandler = java.security.AccessController.doPrivileged(
273+ new java.security.PrivilegedAction<CookieHandler>() {
274+ public CookieHandler run() {
275+ return CookieHandler.getDefault();
276+ }
277+ });
278+ openServer();
279+ }
280+
281+
282+ // This code largely ripped off from HttpClient.New, and
283+ // it uses the same keepalive cache.
284+
285+ static HttpClient New(SSLSocketFactory sf, URL url, HostnameVerifier hv)
286+ throws IOException {
287+ return HttpsClient.New(sf, url, hv, true);
288+ }
289+
290+ /** See HttpClient for the model for this method. */
291+ static HttpClient New(SSLSocketFactory sf, URL url,
292+ HostnameVerifier hv, boolean useCache) throws IOException {
293+ return HttpsClient.New(sf, url, hv, (String)null, -1, useCache);
294+ }
295+
296+ /**
297+ * Get a HTTPS client to the URL. Traffic will be tunneled through
298+ * the specified proxy server.
299+ */
300+ static HttpClient New(SSLSocketFactory sf, URL url, HostnameVerifier hv,
301+ String proxyHost, int proxyPort) throws IOException {
302+ return HttpsClient.New(sf, url, hv, proxyHost, proxyPort, true);
303+ }
304+
305+ static HttpClient New(SSLSocketFactory sf, URL url, HostnameVerifier hv,
306+ String proxyHost, int proxyPort, boolean useCache)
307+ throws IOException {
308+ return HttpsClient.New(sf, url, hv, proxyHost, proxyPort, useCache, -1);
309+ }
310+
311+ static HttpClient New(SSLSocketFactory sf, URL url, HostnameVerifier hv,
312+ String proxyHost, int proxyPort, boolean useCache,
313+ int connectTimeout)
314+ throws IOException {
315+
316+ return HttpsClient.New(sf, url, hv,
317+ (proxyHost == null? null :
318+ HttpsClient.newHttpProxy(proxyHost, proxyPort)),
319+ useCache, connectTimeout);
320+ }
321+
322+ static HttpClient New(SSLSocketFactory sf, URL url, HostnameVerifier hv,
323+ Proxy p, boolean useCache,
324+ int connectTimeout)
325+ throws IOException {
326+ HttpsClient ret = null;
327+ if (useCache) {
328+ /* see if one's already around */
329+ ret = (HttpsClient) kac.get(url, sf);
330+ if (ret != null) {
331+ ret.cachedHttpClient = true;
332+ }
333+ }
334+ if (ret == null) {
335+ ret = new HttpsClient(sf, url, p, connectTimeout);
336+ } else {
337+ SecurityManager security = System.getSecurityManager();
338+ if (security != null) {
339+ security.checkConnect(url.getHost(), url.getPort());
340+ }
341+ ret.url = url;
342+ }
343+ ret.setHostnameVerifier(hv);
344+
345+ return ret;
346+ }
347+
348+ // METHODS
349+ void setHostnameVerifier(HostnameVerifier hv) {
350+ this.hv = hv;
351+ }
352+
353+ void setSSLSocketFactory(SSLSocketFactory sf) {
354+ sslSocketFactory = sf;
355+ }
356+
357+ SSLSocketFactory getSSLSocketFactory() {
358+ return sslSocketFactory;
359+ }
360+
361+ /**
362+ * The following method, createSocket, is defined in NetworkClient
363+ * and overridden here so that the socket facroty is used to create
364+ * new sockets.
365+ */
366+ @Override
367+ protected Socket createSocket() throws IOException {
368+ try {
369+ return sslSocketFactory.createSocket();
370+ } catch (SocketException se) {
371+ //
372+ // bug 6771432
373+ // javax.net.SocketFactory throws a SocketException with an
374+ // UnsupportedOperationException as its cause to indicate that
375+ // unconnected sockets have not been implemented.
376+ //
377+ Throwable t = se.getCause();
378+ if (t != null && t instanceof UnsupportedOperationException) {
379+ return super.createSocket();
380+ } else {
381+ throw se;
382+ }
383+ }
384+ }
385+
386+
387+ @Override
388+ public boolean needsTunneling() {
389+ return (proxy != null && proxy.type() != Proxy.Type.DIRECT
390+ && proxy.type() != Proxy.Type.SOCKS);
391+ }
392+
393+ @Override
394+ public void afterConnect() throws IOException, UnknownHostException {
395+ if (!isCachedConnection()) {
396+ SSLSocket s = null;
397+ SSLSocketFactory factory = sslSocketFactory;
398+ try {
399+ if (!(serverSocket instanceof SSLSocket)) {
400+ s = (SSLSocket)factory.createSocket(serverSocket,
401+ host, port, true);
402+ } else {
403+ s = (SSLSocket)serverSocket;
404+ if (s instanceof SSLSocketImpl) {
405+ ((SSLSocketImpl)s).setHost(host);
406+ }
407+ }
408+ } catch (IOException ex) {
409+ // If we fail to connect through the tunnel, try it
410+ // locally, as a last resort. If this doesn't work,
411+ // throw the original exception.
412+ try {
413+ s = (SSLSocket)factory.createSocket(host, port);
414+ } catch (IOException ignored) {
415+ throw ex;
416+ }
417+ }
418+
419+ //
420+ // Force handshaking, so that we get any authentication.
421+ // Register a handshake callback so our session state tracks any
422+ // later session renegotiations.
423+ //
424+ String [] protocols = getProtocols();
425+ String [] ciphers = getCipherSuites();
426+ if (protocols != null) {
427+ s.setEnabledProtocols(protocols);
428+ }
429+ if (ciphers != null) {
430+ s.setEnabledCipherSuites(ciphers);
431+ }
432+ s.addHandshakeCompletedListener(this);
433+
434+ // We have two hostname verification approaches. One is in
435+ // SSL/TLS socket layer, where the algorithm is configured with
436+ // SSLParameters.setEndpointIdentificationAlgorithm(), and the
437+ // hostname verification is done by X509ExtendedTrustManager when
438+ // the algorithm is "HTTPS". The other one is in HTTPS layer,
439+ // where the algorithm is customized by
440+ // HttpsURLConnection.setHostnameVerifier(), and the hostname
441+ // verification is done by HostnameVerifier when the default
442+ // rules for hostname verification fail.
443+ //
444+ // The relationship between two hostname verification approaches
445+ // likes the following:
446+ //
447+ // | EIA algorithm
448+ // +----------------------------------------------
449+ // | null | HTTPS | LDAP/other |
450+ // -------------------------------------------------------------
451+ // | |1 |2 |3 |
452+ // HNV | default | Set HTTPS EIA | use EIA | HTTPS |
453+ // |--------------------------------------------------------
454+ // | non - |4 |5 |6 |
455+ // | default | HTTPS/HNV | use EIA | HTTPS/HNV |
456+ // -------------------------------------------------------------
457+ //
458+ // Abbreviation:
459+ // EIA: the endpoint identification algorithm in SSL/TLS
460+ // socket layer
461+ // HNV: the hostname verification object in HTTPS layer
462+ // Notes:
463+ // case 1. default HNV and EIA is null
464+ // Set EIA as HTTPS, hostname check done in SSL/TLS
465+ // layer.
466+ // case 2. default HNV and EIA is HTTPS
467+ // Use existing EIA, hostname check done in SSL/TLS
468+ // layer.
469+ // case 3. default HNV and EIA is other than HTTPS
470+ // Use existing EIA, EIA check done in SSL/TLS
471+ // layer, then do HTTPS check in HTTPS layer.
472+ // case 4. non-default HNV and EIA is null
473+ // No EIA, no EIA check done in SSL/TLS layer, then do
474+ // HTTPS check in HTTPS layer using HNV as override.
475+ // case 5. non-default HNV and EIA is HTTPS
476+ // Use existing EIA, hostname check done in SSL/TLS
477+ // layer. No HNV override possible. We will review this
478+ // decision and may update the architecture for JDK 7.
479+ // case 6. non-default HNV and EIA is other than HTTPS
480+ // Use existing EIA, EIA check done in SSL/TLS layer,
481+ // then do HTTPS check in HTTPS layer as override.
482+ boolean needToCheckSpoofing = true;
483+ String identification =
484+ s.getSSLParameters().getEndpointIdentificationAlgorithm();
485+ if (identification != null && identification.length() != 0) {
486+ if (identification.equalsIgnoreCase("HTTPS")) {
487+ // Do not check server identity again out of SSLSocket,
488+ // the endpoint will be identified during TLS handshaking
489+ // in SSLSocket.
490+ needToCheckSpoofing = false;
491+ } // else, we don't understand the identification algorithm,
492+ // need to check URL spoofing here.
493+ } else {
494+ boolean isDefaultHostnameVerifier = false;
495+
496+ // We prefer to let the SSLSocket do the spoof checks, but if
497+ // the application has specified a HostnameVerifier (HNV),
498+ // we will always use that.
499+ if (hv != null) {
500+ String canonicalName = hv.getClass().getCanonicalName();
501+ if (canonicalName != null &&
502+ canonicalName.equalsIgnoreCase(defaultHVCanonicalName)) {
503+ isDefaultHostnameVerifier = true;
504+ }
505+ } else {
506+ // Unlikely to happen! As the behavior is the same as the
507+ // default hostname verifier, so we prefer to let the
508+ // SSLSocket do the spoof checks.
509+ isDefaultHostnameVerifier = true;
510+ }
511+
512+ if (isDefaultHostnameVerifier) {
513+ // If the HNV is the default from HttpsURLConnection, we
514+ // will do the spoof checks in SSLSocket.
515+ SSLParameters paramaters = s.getSSLParameters();
516+ paramaters.setEndpointIdentificationAlgorithm("HTTPS");
517+ s.setSSLParameters(paramaters);
518+
519+ needToCheckSpoofing = false;
520+ }
521+ }
522+
523+ s.startHandshake();
524+ session = s.getSession();
525+ // change the serverSocket and serverOutput
526+ serverSocket = s;
527+ try {
528+ serverOutput = new PrintStream(
529+ new BufferedOutputStream(serverSocket.getOutputStream()),
530+ false, encoding);
531+ } catch (UnsupportedEncodingException e) {
532+ throw new InternalError(encoding+" encoding not found");
533+ }
534+
535+ // check URL spoofing if it has not been checked under handshaking
536+ if (needToCheckSpoofing) {
537+ checkURLSpoofing(hv);
538+ }
539+ } else {
540+ // if we are reusing a cached https session,
541+ // we don't need to do handshaking etc. But we do need to
542+ // set the ssl session
543+ session = ((SSLSocket)serverSocket).getSession();
544+ }
545+ }
546+
547+ // Server identity checking is done according to RFC 2818: HTTP over TLS
548+ // Section 3.1 Server Identity
549+ private void checkURLSpoofing(HostnameVerifier hostnameVerifier)
550+ throws IOException {
551+ //
552+ // Get authenticated server name, if any
553+ //
554+ String host = url.getHost();
555+
556+ // if IPv6 strip off the "[]"
557+ if (host != null && host.startsWith("[") && host.endsWith("]")) {
558+ host = host.substring(1, host.length()-1);
559+ }
560+
561+ Certificate[] peerCerts = null;
562+ String cipher = session.getCipherSuite();
563+ try {
564+ HostnameChecker checker = HostnameChecker.getInstance(
565+ HostnameChecker.TYPE_TLS);
566+
567+ // Use ciphersuite to determine whether Kerberos is present.
568+ if (cipher.startsWith("TLS_KRB5")) {
569+ if (!HostnameChecker.match(host, getPeerPrincipal())) {
570+ throw new SSLPeerUnverifiedException("Hostname checker" +
571+ " failed for Kerberos");
572+ }
573+ } else { // X.509
574+
575+ // get the subject's certificate
576+ peerCerts = session.getPeerCertificates();
577+
578+ X509Certificate peerCert;
579+ if (peerCerts[0] instanceof
580+ java.security.cert.X509Certificate) {
581+ peerCert = (java.security.cert.X509Certificate)peerCerts[0];
582+ } else {
583+ throw new SSLPeerUnverifiedException("");
584+ }
585+ checker.match(host, peerCert);
586+ }
587+
588+ // if it doesn't throw an exception, we passed. Return.
589+ return;
590+
591+ } catch (SSLPeerUnverifiedException e) {
592+
593+ //
594+ // client explicitly changed default policy and enabled
595+ // anonymous ciphers; we can't check the standard policy
596+ //
597+ // ignore
598+ } catch (java.security.cert.CertificateException cpe) {
599+ // ignore
600+ }
601+
602+ if ((cipher != null) && (cipher.indexOf("_anon_") != -1)) {
603+ return;
604+ } else if ((hostnameVerifier != null) &&
605+ (hostnameVerifier.verify(host, session))) {
606+ return;
607+ }
608+
609+ serverSocket.close();
610+ session.invalidate();
611+
612+ throw new IOException("HTTPS hostname wrong: should be <"
613+ + url.getHost() + ">");
614+ }
615+
616+ @Override
617+ protected void putInKeepAliveCache() {
618+ kac.put(url, sslSocketFactory, this);
619+ }
620+
621+ /*
622+ * Close an idle connection to this URL (if it exists in the cache).
623+ */
624+ @Override
625+ public void closeIdleConnection() {
626+ HttpClient http = (HttpClient) kac.get(url, sslSocketFactory);
627+ if (http != null) {
628+ http.closeServer();
629+ }
630+ }
631+
632+ /**
633+ * Returns the cipher suite in use on this connection.
634+ */
635+ String getCipherSuite() {
636+ return session.getCipherSuite();
637+ }
638+
639+ /**
640+ * Returns the certificate chain the client sent to the
641+ * server, or null if the client did not authenticate.
642+ */
643+ public java.security.cert.Certificate [] getLocalCertificates() {
644+ return session.getLocalCertificates();
645+ }
646+
647+ /**
648+ * Returns the certificate chain with which the server
649+ * authenticated itself, or throw a SSLPeerUnverifiedException
650+ * if the server did not authenticate.
651+ */
652+ java.security.cert.Certificate [] getServerCertificates()
653+ throws SSLPeerUnverifiedException
654+ {
655+ return session.getPeerCertificates();
656+ }
657+
658+ /**
659+ * Returns the X.509 certificate chain with which the server
660+ * authenticated itself, or null if the server did not authenticate.
661+ */
662+ javax.security.cert.X509Certificate [] getServerCertificateChain()
663+ throws SSLPeerUnverifiedException
664+ {
665+ return session.getPeerCertificateChain();
666+ }
667+
668+ /**
669+ * Returns the principal with which the server authenticated
670+ * itself, or throw a SSLPeerUnverifiedException if the
671+ * server did not authenticate.
672+ */
673+ Principal getPeerPrincipal()
674+ throws SSLPeerUnverifiedException
675+ {
676+ Principal principal;
677+ try {
678+ principal = session.getPeerPrincipal();
679+ } catch (AbstractMethodError e) {
680+ // if the provider does not support it, fallback to peer certs.
681+ // return the X500Principal of the end-entity cert.
682+ java.security.cert.Certificate[] certs =
683+ session.getPeerCertificates();
684+ principal = (X500Principal)
685+ ((X509Certificate)certs[0]).getSubjectX500Principal();
686+ }
687+ return principal;
688+ }
689+
690+ /**
691+ * Returns the principal the client sent to the
692+ * server, or null if the client did not authenticate.
693+ */
694+ Principal getLocalPrincipal()
695+ {
696+ Principal principal;
697+ try {
698+ principal = session.getLocalPrincipal();
699+ } catch (AbstractMethodError e) {
700+ principal = null;
701+ // if the provider does not support it, fallback to local certs.
702+ // return the X500Principal of the end-entity cert.
703+ java.security.cert.Certificate[] certs =
704+ session.getLocalCertificates();
705+ if (certs != null) {
706+ principal = (X500Principal)
707+ ((X509Certificate)certs[0]).getSubjectX500Principal();
708+ }
709+ }
710+ return principal;
711+ }
712+
713+ /**
714+ * This method implements the SSL HandshakeCompleted callback,
715+ * remembering the resulting session so that it may be queried
716+ * for the current cipher suite and peer certificates. Servers
717+ * sometimes re-initiate handshaking, so the session in use on
718+ * a given connection may change. When sessions change, so may
719+ * peer identities and cipher suites.
720+ */
721+ public void handshakeCompleted(HandshakeCompletedEvent event)
722+ {
723+ session = event.getSession();
724+ }
725+
726+ /**
727+ * @return the proxy host being used for this client, or null
728+ * if we're not going through a proxy
729+ */
730+ @Override
731+ public String getProxyHostUsed() {
732+ if (!needsTunneling()) {
733+ return null;
734+ } else {
735+ return super.getProxyHostUsed();
736+ }
737+ }
738+
739+ /**
740+ * @return the proxy port being used for this client. Meaningless
741+ * if getProxyHostUsed() gives null.
742+ */
743+ @Override
744+ public int getProxyPortUsed() {
745+ return (proxy == null || proxy.type() == Proxy.Type.DIRECT ||
746+ proxy.type() == Proxy.Type.SOCKS)? -1:
747+ ((InetSocketAddress)proxy.address()).getPort();
748+ }
749+}
java/pkg/sun/net/www/protocol/https/HttpsURLConnectionImpl.java+537−0
@@ -0,0 +1,537 @@
1+/*
2+ * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
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
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+/*
27+ * NOTE: This class lives in the package sun.net.www.protocol.https.
28+ * There is a copy in com.sun.net.ssl.internal.www.protocol.https for JSSE
29+ * 1.0.2 compatibility. It is 100% identical except the package and extends
30+ * lines. Any changes should be made to be class in sun.net.* and then copied
31+ * to com.sun.net.*.
32+ */
33+
34+// For both copies of the file, uncomment one line and comment the other
35+package sun.net.www.protocol.https;
36+// package com.sun.net.ssl.internal.www.protocol.https;
37+
38+import java.net.URL;
39+import java.net.Proxy;
40+import java.net.ProtocolException;
41+import java.io.*;
42+import javax.net.ssl.*;
43+import java.security.Permission;
44+import java.security.Principal;
45+import java.util.Map;
46+import java.util.List;
47+import sun.net.www.http.HttpClient;
48+
49+/**
50+ * A class to represent an HTTP connection to a remote object.
51+ *
52+ * Ideally, this class should subclass and inherit the http handler
53+ * implementation, but it can't do so because that class have the
54+ * wrong Java Type. Thus it uses the delegate (aka, the
55+ * Adapter/Wrapper design pattern) to reuse code from the http
56+ * handler.
57+ *
58+ * Since it would use a delegate to access
59+ * sun.net.www.protocol.http.HttpURLConnection functionalities, it
60+ * needs to implement all public methods in it's super class and all
61+ * the way to Object.
62+ *
63+ */
64+
65+// For both copies of the file, uncomment one line and comment the
66+// other. The differences between the two copies are introduced for
67+// plugin, and it is marked as such.
68+public class HttpsURLConnectionImpl
69+ extends javax.net.ssl.HttpsURLConnection {
70+// public class HttpsURLConnectionOldImpl
71+// extends com.sun.net.ssl.HttpsURLConnection {
72+
73+ // NOTE: made protected for plugin so that subclass can set it.
74+ protected DelegateHttpsURLConnection delegate;
75+
76+// For both copies of the file, uncomment one line and comment the other
77+ HttpsURLConnectionImpl(URL u, Handler handler) throws IOException {
78+// HttpsURLConnectionOldImpl(URL u, Handler handler) throws IOException {
79+ this(u, null, handler);
80+ }
81+
82+// For both copies of the file, uncomment one line and comment the other
83+ HttpsURLConnectionImpl(URL u, Proxy p, Handler handler) throws IOException {
84+// HttpsURLConnectionOldImpl(URL u, Proxy p, Handler handler) throws IOException {
85+ super(u);
86+ delegate = new DelegateHttpsURLConnection(url, p, handler, this);
87+ }
88+
89+ // NOTE: introduced for plugin
90+ // subclass needs to overwrite this to set delegate to
91+ // the appropriate delegatee
92+ protected HttpsURLConnectionImpl(URL u) throws IOException {
93+ super(u);
94+ }
95+
96+ /**
97+ * Create a new HttpClient object, bypassing the cache of
98+ * HTTP client objects/connections.
99+ *
100+ * @param url the URL being accessed
101+ */
102+ protected void setNewClient(URL url) throws IOException {
103+ delegate.setNewClient(url, false);
104+ }
105+
106+ /**
107+ * Obtain a HttpClient object. Use the cached copy if specified.
108+ *
109+ * @param url the URL being accessed
110+ * @param useCache whether the cached connection should be used
111+ * if present
112+ */
113+ protected void setNewClient(URL url, boolean useCache)
114+ throws IOException {
115+ delegate.setNewClient(url, useCache);
116+ }
117+
118+ /**
119+ * Create a new HttpClient object, set up so that it uses
120+ * per-instance proxying to the given HTTP proxy. This
121+ * bypasses the cache of HTTP client objects/connections.
122+ *
123+ * @param url the URL being accessed
124+ * @param proxyHost the proxy host to use
125+ * @param proxyPort the proxy port to use
126+ */
127+ protected void setProxiedClient(URL url, String proxyHost, int proxyPort)
128+ throws IOException {
129+ delegate.setProxiedClient(url, proxyHost, proxyPort);
130+ }
131+
132+ /**
133+ * Obtain a HttpClient object, set up so that it uses per-instance
134+ * proxying to the given HTTP proxy. Use the cached copy of HTTP
135+ * client objects/connections if specified.
136+ *
137+ * @param url the URL being accessed
138+ * @param proxyHost the proxy host to use
139+ * @param proxyPort the proxy port to use
140+ * @param useCache whether the cached connection should be used
141+ * if present
142+ */
143+ protected void setProxiedClient(URL url, String proxyHost, int proxyPort,
144+ boolean useCache) throws IOException {
145+ delegate.setProxiedClient(url, proxyHost, proxyPort, useCache);
146+ }
147+
148+ /**
149+ * Implements the HTTP protocol handler's "connect" method,
150+ * establishing an SSL connection to the server as necessary.
151+ */
152+ public void connect() throws IOException {
153+ delegate.connect();
154+ }
155+
156+ /**
157+ * Used by subclass to access "connected" variable. Since we are
158+ * delegating the actual implementation to "delegate", we need to
159+ * delegate the access of "connected" as well.
160+ */
161+ protected boolean isConnected() {
162+ return delegate.isConnected();
163+ }
164+
165+ /**
166+ * Used by subclass to access "connected" variable. Since we are
167+ * delegating the actual implementation to "delegate", we need to
168+ * delegate the access of "connected" as well.
169+ */
170+ protected void setConnected(boolean conn) {
171+ delegate.setConnected(conn);
172+ }
173+
174+ /**
175+ * Returns the cipher suite in use on this connection.
176+ */
177+ public String getCipherSuite() {
178+ return delegate.getCipherSuite();
179+ }
180+
181+ /**
182+ * Returns the certificate chain the client sent to the
183+ * server, or null if the client did not authenticate.
184+ */
185+ public java.security.cert.Certificate []
186+ getLocalCertificates() {
187+ return delegate.getLocalCertificates();
188+ }
189+
190+ /**
191+ * Returns the server's certificate chain, or throws
192+ * SSLPeerUnverified Exception if
193+ * the server did not authenticate.
194+ */
195+ public java.security.cert.Certificate []
196+ getServerCertificates() throws SSLPeerUnverifiedException {
197+ return delegate.getServerCertificates();
198+ }
199+
200+ /**
201+ * Returns the server's X.509 certificate chain, or null if
202+ * the server did not authenticate.
203+ *
204+ * NOTE: This method is not necessary for the version of this class
205+ * implementing javax.net.ssl.HttpsURLConnection, but provided for
206+ * compatibility with the com.sun.net.ssl.HttpsURLConnection version.
207+ */
208+ public javax.security.cert.X509Certificate[] getServerCertificateChain() {
209+ try {
210+ return delegate.getServerCertificateChain();
211+ } catch (SSLPeerUnverifiedException e) {
212+ // this method does not throw an exception as declared in
213+ // com.sun.net.ssl.HttpsURLConnection.
214+ // Return null for compatibility.
215+ return null;
216+ }
217+ }
218+
219+ /**
220+ * Returns the principal with which the server authenticated itself,
221+ * or throw a SSLPeerUnverifiedException if the server did not authenticate.
222+ */
223+ public Principal getPeerPrincipal()
224+ throws SSLPeerUnverifiedException
225+ {
226+ return delegate.getPeerPrincipal();
227+ }
228+
229+ /**
230+ * Returns the principal the client sent to the
231+ * server, or null if the client did not authenticate.
232+ */
233+ public Principal getLocalPrincipal()
234+ {
235+ return delegate.getLocalPrincipal();
236+ }
237+
238+ /*
239+ * Allowable input/output sequences:
240+ * [interpreted as POST/PUT]
241+ * - get output, [write output,] get input, [read input]
242+ * - get output, [write output]
243+ * [interpreted as GET]
244+ * - get input, [read input]
245+ * Disallowed:
246+ * - get input, [read input,] get output, [write output]
247+ */
248+
249+ public synchronized OutputStream getOutputStream() throws IOException {
250+ return delegate.getOutputStream();
251+ }
252+
253+ public synchronized InputStream getInputStream() throws IOException {
254+ return delegate.getInputStream();
255+ }
256+
257+ public InputStream getErrorStream() {
258+ return delegate.getErrorStream();
259+ }
260+
261+ /**
262+ * Disconnect from the server.
263+ */
264+ public void disconnect() {
265+ delegate.disconnect();
266+ }
267+
268+ public boolean usingProxy() {
269+ return delegate.usingProxy();
270+ }
271+
272+ /**
273+ * Returns an unmodifiable Map of the header fields.
274+ * The Map keys are Strings that represent the
275+ * response-header field names. Each Map value is an
276+ * unmodifiable List of Strings that represents
277+ * the corresponding field values.
278+ *
279+ * @return a Map of header fields
280+ * @since 1.4
281+ */
282+ public Map<String,List<String>> getHeaderFields() {
283+ return delegate.getHeaderFields();
284+ }
285+
286+ /**
287+ * Gets a header field by name. Returns null if not known.
288+ * @param name the name of the header field
289+ */
290+ public String getHeaderField(String name) {
291+ return delegate.getHeaderField(name);
292+ }
293+
294+ /**
295+ * Gets a header field by index. Returns null if not known.
296+ * @param n the index of the header field
297+ */
298+ public String getHeaderField(int n) {
299+ return delegate.getHeaderField(n);
300+ }
301+
302+ /**
303+ * Gets a header field by index. Returns null if not known.
304+ * @param n the index of the header field
305+ */
306+ public String getHeaderFieldKey(int n) {
307+ return delegate.getHeaderFieldKey(n);
308+ }
309+
310+ /**
311+ * Sets request property. If a property with the key already
312+ * exists, overwrite its value with the new value.
313+ * @param value the value to be set
314+ */
315+ public void setRequestProperty(String key, String value) {
316+ delegate.setRequestProperty(key, value);
317+ }
318+
319+ /**
320+ * Adds a general request property specified by a
321+ * key-value pair. This method will not overwrite
322+ * existing values associated with the same key.
323+ *
324+ * @param key the keyword by which the request is known
325+ * (e.g., "<code>accept</code>").
326+ * @param value the value associated with it.
327+ * @see #getRequestProperties(java.lang.String)
328+ * @since 1.4
329+ */
330+ public void addRequestProperty(String key, String value) {
331+ delegate.addRequestProperty(key, value);
332+ }
333+
334+ /**
335+ * Overwrite super class method
336+ */
337+ public int getResponseCode() throws IOException {
338+ return delegate.getResponseCode();
339+ }
340+
341+ public String getRequestProperty(String key) {
342+ return delegate.getRequestProperty(key);
343+ }
344+
345+ /**
346+ * Returns an unmodifiable Map of general request
347+ * properties for this connection. The Map keys
348+ * are Strings that represent the request-header
349+ * field names. Each Map value is a unmodifiable List
350+ * of Strings that represents the corresponding
351+ * field values.
352+ *
353+ * @return a Map of the general request properties for this connection.
354+ * @throws IllegalStateException if already connected
355+ * @since 1.4
356+ */
357+ public Map<String,List<String>> getRequestProperties() {
358+ return delegate.getRequestProperties();
359+ }
360+
361+ /*
362+ * We support JDK 1.2.x so we can't count on these from JDK 1.3.
363+ * We override and supply our own version.
364+ */
365+ public void setInstanceFollowRedirects(boolean shouldFollow) {
366+ delegate.setInstanceFollowRedirects(shouldFollow);
367+ }
368+
369+ public boolean getInstanceFollowRedirects() {
370+ return delegate.getInstanceFollowRedirects();
371+ }
372+
373+ public void setRequestMethod(String method) throws ProtocolException {
374+ delegate.setRequestMethod(method);
375+ }
376+
377+ public String getRequestMethod() {
378+ return delegate.getRequestMethod();
379+ }
380+
381+ public String getResponseMessage() throws IOException {
382+ return delegate.getResponseMessage();
383+ }
384+
385+ public long getHeaderFieldDate(String name, long Default) {
386+ return delegate.getHeaderFieldDate(name, Default);
387+ }
388+
389+ public Permission getPermission() throws IOException {
390+ return delegate.getPermission();
391+ }
392+
393+ public URL getURL() {
394+ return delegate.getURL();
395+ }
396+
397+ public int getContentLength() {
398+ return delegate.getContentLength();
399+ }
400+
401+ public long getContentLengthLong() {
402+ return delegate.getContentLengthLong();
403+ }
404+
405+ public String getContentType() {
406+ return delegate.getContentType();
407+ }
408+
409+ public String getContentEncoding() {
410+ return delegate.getContentEncoding();
411+ }
412+
413+ public long getExpiration() {
414+ return delegate.getExpiration();
415+ }
416+
417+ public long getDate() {
418+ return delegate.getDate();
419+ }
420+
421+ public long getLastModified() {
422+ return delegate.getLastModified();
423+ }
424+
425+ public int getHeaderFieldInt(String name, int Default) {
426+ return delegate.getHeaderFieldInt(name, Default);
427+ }
428+
429+ public long getHeaderFieldLong(String name, long Default) {
430+ return delegate.getHeaderFieldLong(name, Default);
431+ }
432+
433+ public Object getContent() throws IOException {
434+ return delegate.getContent();
435+ }
436+
437+ public Object getContent(Class[] classes) throws IOException {
438+ return delegate.getContent(classes);
439+ }
440+
441+ public String toString() {
442+ return delegate.toString();
443+ }
444+
445+ public void setDoInput(boolean doinput) {
446+ delegate.setDoInput(doinput);
447+ }
448+
449+ public boolean getDoInput() {
450+ return delegate.getDoInput();
451+ }
452+
453+ public void setDoOutput(boolean dooutput) {
454+ delegate.setDoOutput(dooutput);
455+ }
456+
457+ public boolean getDoOutput() {
458+ return delegate.getDoOutput();
459+ }
460+
461+ public void setAllowUserInteraction(boolean allowuserinteraction) {
462+ delegate.setAllowUserInteraction(allowuserinteraction);
463+ }
464+
465+ public boolean getAllowUserInteraction() {
466+ return delegate.getAllowUserInteraction();
467+ }
468+
469+ public void setUseCaches(boolean usecaches) {
470+ delegate.setUseCaches(usecaches);
471+ }
472+
473+ public boolean getUseCaches() {
474+ return delegate.getUseCaches();
475+ }
476+
477+ public void setIfModifiedSince(long ifmodifiedsince) {
478+ delegate.setIfModifiedSince(ifmodifiedsince);
479+ }
480+
481+ public long getIfModifiedSince() {
482+ return delegate.getIfModifiedSince();
483+ }
484+
485+ public boolean getDefaultUseCaches() {
486+ return delegate.getDefaultUseCaches();
487+ }
488+
489+ public void setDefaultUseCaches(boolean defaultusecaches) {
490+ delegate.setDefaultUseCaches(defaultusecaches);
491+ }
492+
493+ /*
494+ * finalize (dispose) the delegated object. Otherwise
495+ * sun.net.www.protocol.http.HttpURLConnection's finalize()
496+ * would have to be made public.
497+ */
498+ protected void finalize() throws Throwable {
499+ delegate.dispose();
500+ }
501+
502+ public boolean equals(Object obj) {
503+ return delegate.equals(obj);
504+ }
505+
506+ public int hashCode() {
507+ return delegate.hashCode();
508+ }
509+
510+ public void setConnectTimeout(int timeout) {
511+ delegate.setConnectTimeout(timeout);
512+ }
513+
514+ public int getConnectTimeout() {
515+ return delegate.getConnectTimeout();
516+ }
517+
518+ public void setReadTimeout(int timeout) {
519+ delegate.setReadTimeout(timeout);
520+ }
521+
522+ public int getReadTimeout() {
523+ return delegate.getReadTimeout();
524+ }
525+
526+ public void setFixedLengthStreamingMode (int contentLength) {
527+ delegate.setFixedLengthStreamingMode(contentLength);
528+ }
529+
530+ public void setFixedLengthStreamingMode(long contentLength) {
531+ delegate.setFixedLengthStreamingMode(contentLength);
532+ }
533+
534+ public void setChunkedStreamingMode (int chunklen) {
535+ delegate.setChunkedStreamingMode(chunklen);
536+ }
537+}
java/pkg/sun/net/www/protocol/https/mkfile+13−0
@@ -0,0 +1,13 @@
1+<../../../../../../../mkconfig
2+
3+TARG=\
4+ AbstractDelegateHttpsURLConnection.dis\
5+ DefaultHostnameVerifier.dis\
6+ DelegateHttpsURLConnection.dis\
7+ Handler.dis\
8+ HttpsClient.dis\
9+ HttpsURLConnectionImpl.dis\
10+
11+DISBIN=$ROOT/java/dis/java/java/sun/net/www/protocol/https
12+
13+<$ROOT/mkfiles/mkjava