1/*
2 * Copyright (c) 2000, 2017, 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 java.security.cert.Certificate;
36import javax.net.SocketFactory;
37import javax.net.ssl.SSLSocketFactory;
38import javax.net.ssl.SSLPeerUnverifiedException;
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(since="1.4")
49public abstract
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     * <P>
72     * Note: The returned value may not be a valid certificate chain
73     * and should not be relied on for trust decisions.
74     *
75     * @return the server certificate chain
76     */
77    public abstract Certificate[] getServerCertificates()
78        throws SSLPeerUnverifiedException;
79
80    /**
81     * HostnameVerifier provides a callback mechanism so that
82     * implementers of this interface can supply a policy for
83     * handling the case where the host to connect to and
84     * the server name from the certificate mismatch.
85     *
86     * The default implementation will deny such connections.
87     */
88    private static HostnameVerifier defaultHostnameVerifier =
89        new HostnameVerifier() {
90            public boolean verify(String urlHostname, String certHostname) {
91                return false;
92            }
93        };
94
95    protected HostnameVerifier hostnameVerifier = defaultHostnameVerifier;
96
97    /**
98     * Sets the default HostnameVerifier inherited when an instance
99     * of this class is created.
100     * @param v the default host name verifier
101     */
102    public static void setDefaultHostnameVerifier(HostnameVerifier v) {
103        if (v == null) {
104            throw new IllegalArgumentException(
105                "no default HostnameVerifier specified");
106        }
107
108        SecurityManager sm = System.getSecurityManager();
109        if (sm != null) {
110            sm.checkPermission(new SSLPermission("setHostnameVerifier"));
111        }
112        defaultHostnameVerifier = v;
113    }
114
115    /**
116     * Gets the default HostnameVerifier.
117     * @return the default host name verifier
118     */
119    public static HostnameVerifier getDefaultHostnameVerifier() {
120        return defaultHostnameVerifier;
121    }
122
123    /**
124     * Sets the HostnameVerifier.
125     * @param v the host name verifier
126     */
127    public void setHostnameVerifier(HostnameVerifier v) {
128        if (v == null) {
129            throw new IllegalArgumentException(
130                "no HostnameVerifier specified");
131        }
132
133        hostnameVerifier = v;
134    }
135
136    /**
137     * Gets the HostnameVerifier.
138     * @return the host name verifier
139     */
140    public HostnameVerifier getHostnameVerifier() {
141        return hostnameVerifier;
142    }
143
144    private static SSLSocketFactory defaultSSLSocketFactory = null;
145
146    private SSLSocketFactory sslSocketFactory = getDefaultSSLSocketFactory();
147
148    /**
149     * Sets the default SSL socket factory inherited when an instance
150     * of this class is created.
151     * @param sf the default SSL socket factory
152     */
153    public static void setDefaultSSLSocketFactory(SSLSocketFactory sf) {
154        if (sf == null) {
155            throw new IllegalArgumentException(
156                "no default SSLSocketFactory specified");
157        }
158
159        SecurityManager sm = System.getSecurityManager();
160        if (sm != null) {
161            sm.checkSetFactory();
162        }
163        defaultSSLSocketFactory = sf;
164    }
165
166    /**
167     * Gets the default SSL socket factory.
168     * @return the default SSL socket factory
169     */
170    public static SSLSocketFactory getDefaultSSLSocketFactory() {
171        if (defaultSSLSocketFactory == null) {
172            defaultSSLSocketFactory =
173                (SSLSocketFactory)SSLSocketFactory.getDefault();
174        }
175        return defaultSSLSocketFactory;
176    }
177
178    /**
179     * Sets the SSL socket factory.
180     * @param sf the SSL socket factory
181     */
182    public void setSSLSocketFactory(SSLSocketFactory sf) {
183        if (sf == null) {
184            throw new IllegalArgumentException(
185                "no SSLSocketFactory specified");
186        }
187
188        SecurityManager sm = System.getSecurityManager();
189        if (sm != null) {
190            sm.checkSetFactory();
191        }
192
193        sslSocketFactory = sf;
194    }
195
196    /**
197     * Gets the SSL socket factory.
198     * @return the SSL socket factory
199     */
200    public SSLSocketFactory getSSLSocketFactory() {
201        return sslSocketFactory;
202    }
203}
204