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/com/sun/net/ssl/HttpsURLConnection.java (1 of 18352 files). Show all

Unified · Split

java/pkg/com/sun/net/ssl/HttpsURLConnection.java+192−0
@@ -0,0 +1,192 @@
1/*
2 * Copyright (c) 2000, 2004, 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 file was copied from javax.net.ssl.HttpsURLConnection
28 */
29
30package com.sun.net.ssl;
31
32import java.net.URL;
33import java.net.HttpURLConnection;
34import java.io.IOException;
35import javax.net.SocketFactory;
36import javax.net.ssl.SSLSocketFactory;
37
38import javax.security.cert.X509Certificate;
39
40/**
41 * HTTP URL connection with support for HTTPS-specific features. See
42 * <A HREF="http://www.w3.org/pub/WWW/Protocols/"> the spec </A> for
43 * details.
44 *
45 * @deprecated As of JDK 1.4, this implementation-specific class was
46 * replaced by {@link javax.net.ssl.HttpsURLConnection}.
47 */
48@Deprecated
49abstract public
50class HttpsURLConnection extends HttpURLConnection
51{
52 /*
53 * Initialize an HTTPS URLConnection ... could check that the URL
54 * is an "https" URL, and that the handler is also an HTTPS one,
55 * but that's established by other code in this package.
56 * @param url the URL
57 */
58 public HttpsURLConnection(URL url) throws IOException {
59 super(url);
60 }
61
62 /**
63 * Returns the cipher suite in use on this connection.
64 * @return the cipher suite
65 */
66 public abstract String getCipherSuite();
67
68 /**
69 * Returns the server's X.509 certificate chain, or null if
70 * the server did not authenticate.
71 * @return the server certificate chain
72 */
73 public abstract X509Certificate [] getServerCertificateChain();
74
75 /**
76 * HostnameVerifier provides a callback mechanism so that
77 * implementers of this interface can supply a policy for
78 * handling the case where the host to connect to and
79 * the server name from the certificate mismatch.
80 *
81 * The default implementation will deny such connections.
82 */
83 private static HostnameVerifier defaultHostnameVerifier =
84 new HostnameVerifier() {
85 public boolean verify(String urlHostname, String certHostname) {
86 return false;
87 }
88 };
89
90 protected HostnameVerifier hostnameVerifier = defaultHostnameVerifier;
91
92 /**
93 * Sets the default HostnameVerifier inherited when an instance
94 * of this class is created.
95 * @param v the default host name verifier
96 */
97 public static void setDefaultHostnameVerifier(HostnameVerifier v) {
98 if (v == null) {
99 throw new IllegalArgumentException(
100 "no default HostnameVerifier specified");
101 }
102
103 SecurityManager sm = System.getSecurityManager();
104 if (sm != null) {
105 sm.checkPermission(new SSLPermission("setHostnameVerifier"));
106 }
107 defaultHostnameVerifier = v;
108 }
109
110 /**
111 * Gets the default HostnameVerifier.
112 * @return the default host name verifier
113 */
114 public static HostnameVerifier getDefaultHostnameVerifier() {
115 return defaultHostnameVerifier;
116 }
117
118 /**
119 * Sets the HostnameVerifier.
120 * @param v the host name verifier
121 */
122 public void setHostnameVerifier(HostnameVerifier v) {
123 if (v == null) {
124 throw new IllegalArgumentException(
125 "no HostnameVerifier specified");
126 }
127
128 hostnameVerifier = v;
129 }
130
131 /**
132 * Gets the HostnameVerifier.
133 * @return the host name verifier
134 */
135 public HostnameVerifier getHostnameVerifier() {
136 return hostnameVerifier;
137 }
138
139 private static SSLSocketFactory defaultSSLSocketFactory = null;
140
141 private SSLSocketFactory sslSocketFactory = getDefaultSSLSocketFactory();
142
143 /**
144 * Sets the default SSL socket factory inherited when an instance
145 * of this class is created.
146 * @param sf the default SSL socket factory
147 */
148 public static void setDefaultSSLSocketFactory(SSLSocketFactory sf) {
149 if (sf == null) {
150 throw new IllegalArgumentException(
151 "no default SSLSocketFactory specified");
152 }
153
154 SecurityManager sm = System.getSecurityManager();
155 if (sm != null) {
156 sm.checkSetFactory();
157 }
158 defaultSSLSocketFactory = sf;
159 }
160
161 /**
162 * Gets the default SSL socket factory.
163 * @return the default SSL socket factory
164 */
165 public static SSLSocketFactory getDefaultSSLSocketFactory() {
166 if (defaultSSLSocketFactory == null) {
167 defaultSSLSocketFactory =
168 (SSLSocketFactory)SSLSocketFactory.getDefault();
169 }
170 return defaultSSLSocketFactory;
171 }
172
173 /**
174 * Sets the SSL socket factory.
175 * @param sf the SSL socket factory
176 */
177 public void setSSLSocketFactory(SSLSocketFactory sf) {
178 if (sf == null) {
179 throw new IllegalArgumentException(
180 "no SSLSocketFactory specified");
181 }
182 sslSocketFactory = sf;
183 }
184
185 /**
186 * Gets the SSL socket factory.
187 * @return the SSL socket factory
188 */
189 public SSLSocketFactory getSSLSocketFactory() {
190 return sslSocketFactory;
191 }
192}