jdk/src/java.base/share/classes/com/sun/net/ssl/HttpsURLConnection.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 29615 b0057b63b4e7
child 39562 672b948cb355
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
29615
b0057b63b4e7 8074531: Remove javax.security.cert.X509Certificate usage in internal networking packages
juh
parents: 25859
diff changeset
     2
 * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * NOTE:  this file was copied from javax.net.ssl.HttpsURLConnection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
package com.sun.net.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.HttpURLConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.IOException;
29615
b0057b63b4e7 8074531: Remove javax.security.cert.X509Certificate usage in internal networking packages
juh
parents: 25859
diff changeset
    35
import java.security.cert.Certificate;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.net.SocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.net.ssl.SSLSocketFactory;
29615
b0057b63b4e7 8074531: Remove javax.security.cert.X509Certificate usage in internal networking packages
juh
parents: 25859
diff changeset
    38
import javax.net.ssl.SSLPeerUnverifiedException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * HTTP URL connection with support for HTTPS-specific features. See
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <A HREF="http://www.w3.org/pub/WWW/Protocols/"> the spec </A> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @deprecated As of JDK 1.4, this implementation-specific class was
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *      replaced by {@link javax.net.ssl.HttpsURLConnection}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
@Deprecated
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 29615
diff changeset
    49
public abstract
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
class HttpsURLConnection extends HttpURLConnection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * Initialize an HTTPS URLConnection ... could check that the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * is an "https" URL, and that the handler is also an HTTPS one,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * but that's established by other code in this package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @param url the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public HttpsURLConnection(URL url) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        super(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Returns the cipher suite in use on this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @return the cipher suite
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public abstract String getCipherSuite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Returns the server's X.509 certificate chain, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * the server did not authenticate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @return the server certificate chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
29615
b0057b63b4e7 8074531: Remove javax.security.cert.X509Certificate usage in internal networking packages
juh
parents: 25859
diff changeset
    73
    public abstract Certificate[] getServerCertificates()
b0057b63b4e7 8074531: Remove javax.security.cert.X509Certificate usage in internal networking packages
juh
parents: 25859
diff changeset
    74
        throws SSLPeerUnverifiedException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * HostnameVerifier provides a callback mechanism so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * implementers of this interface can supply a policy for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * handling the case where the host to connect to and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * the server name from the certificate mismatch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * The default implementation will deny such connections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private static HostnameVerifier defaultHostnameVerifier =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        new HostnameVerifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            public boolean verify(String urlHostname, String certHostname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    protected HostnameVerifier hostnameVerifier = defaultHostnameVerifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Sets the default HostnameVerifier inherited when an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * of this class is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @param v the default host name verifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static void setDefaultHostnameVerifier(HostnameVerifier v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (v == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                "no default HostnameVerifier specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            sm.checkPermission(new SSLPermission("setHostnameVerifier"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        defaultHostnameVerifier = v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Gets the default HostnameVerifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @return the default host name verifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public static HostnameVerifier getDefaultHostnameVerifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return defaultHostnameVerifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Sets the HostnameVerifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param v the host name verifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public void setHostnameVerifier(HostnameVerifier v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (v == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                "no HostnameVerifier specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        hostnameVerifier = v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Gets the HostnameVerifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @return the host name verifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public HostnameVerifier getHostnameVerifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return hostnameVerifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private static SSLSocketFactory defaultSSLSocketFactory = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private SSLSocketFactory sslSocketFactory = getDefaultSSLSocketFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Sets the default SSL socket factory inherited when an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * of this class is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @param sf the default SSL socket factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public static void setDefaultSSLSocketFactory(SSLSocketFactory sf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if (sf == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                "no default SSLSocketFactory specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            sm.checkSetFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        defaultSSLSocketFactory = sf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Gets the default SSL socket factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @return the default SSL socket factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public static SSLSocketFactory getDefaultSSLSocketFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (defaultSSLSocketFactory == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            defaultSSLSocketFactory =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                (SSLSocketFactory)SSLSocketFactory.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        return defaultSSLSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Sets the SSL socket factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param sf the SSL socket factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public void setSSLSocketFactory(SSLSocketFactory sf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (sf == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                "no SSLSocketFactory specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
10916
5a763073fa37 7096936: issue in jsse/runtime
xuelei
parents: 5506
diff changeset
   183
5a763073fa37 7096936: issue in jsse/runtime
xuelei
parents: 5506
diff changeset
   184
        SecurityManager sm = System.getSecurityManager();
5a763073fa37 7096936: issue in jsse/runtime
xuelei
parents: 5506
diff changeset
   185
        if (sm != null) {
5a763073fa37 7096936: issue in jsse/runtime
xuelei
parents: 5506
diff changeset
   186
            sm.checkSetFactory();
5a763073fa37 7096936: issue in jsse/runtime
xuelei
parents: 5506
diff changeset
   187
        }
5a763073fa37 7096936: issue in jsse/runtime
xuelei
parents: 5506
diff changeset
   188
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        sslSocketFactory = sf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Gets the SSL socket factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @return the SSL socket factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public SSLSocketFactory getSSLSocketFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return sslSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
}