src/java.base/share/classes/sun/net/www/protocol/https/AbstractDelegateHttpsURLConnection.java
author xuelei
Fri, 01 Mar 2019 08:35:14 -0800
changeset 53972 43c2ab1bdfd3
parent 52474 13266dac5fdb
permissions -rw-r--r--
8215430: Remove the internal package com.sun.net.ssl Reviewed-by: chegar, mullan, wetmore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
53972
43c2ab1bdfd3 8215430: Remove the internal package com.sun.net.ssl
xuelei
parents: 52474
diff changeset
     2
 * Copyright (c) 2001, 2019, 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
package sun.net.www.protocol.https;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.Proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.SecureCacheResponse;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.List;
52474
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
    34
import java.util.Optional;
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
    35
import javax.net.ssl.SSLSession;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.net.ssl.SSLPeerUnverifiedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.net.www.http.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.net.www.protocol.http.HttpURLConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * HTTPS URL connection support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * We need this delegate because HttpsURLConnection is a subclass of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * java.net.HttpURLConnection. We will avoid copying over the code from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * sun.net.www.protocol.http.HttpURLConnection by having this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public abstract class AbstractDelegateHttpsURLConnection extends
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        HttpURLConnection {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    protected AbstractDelegateHttpsURLConnection(URL url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            sun.net.www.protocol.http.Handler handler) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        this(url, null, handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    protected AbstractDelegateHttpsURLConnection(URL url, Proxy p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            sun.net.www.protocol.http.Handler handler) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        super(url, p, handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected abstract javax.net.ssl.SSLSocketFactory getSSLSocketFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    protected abstract javax.net.ssl.HostnameVerifier getHostnameVerifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * No user application is able to call these routines, as no one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * should ever get access to an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * DelegateHttpsURLConnection (sun.* or com.*)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Create a new HttpClient object, bypassing the cache of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * HTTP client objects/connections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @param url the URL being accessed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public void setNewClient (URL url)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        setNewClient (url, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Obtain a HttpClient object. Use the cached copy if specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param url       the URL being accessed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param useCache  whether the cached connection should be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *        if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public void setNewClient (URL url, boolean useCache)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        http = HttpsClient.New (getSSLSocketFactory(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                getHostnameVerifier(),
16499
88276d2da9c0 8009251: Add proxy handling and keep-alive fixes to jsse
robm
parents: 10596
diff changeset
    93
                                useCache, this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        ((HttpsClient)http).afterConnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Create a new HttpClient object, set up so that it uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * per-instance proxying to the given HTTP proxy.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * bypasses the cache of HTTP client objects/connections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param url       the URL being accessed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param proxyHost the proxy host to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param proxyPort the proxy port to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public void setProxiedClient (URL url, String proxyHost, int proxyPort)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        setProxiedClient(url, proxyHost, proxyPort, false);
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
     * Obtain a HttpClient object, set up so that it uses per-instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * proxying to the given HTTP proxy. Use the cached copy of HTTP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * client objects/connections if specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @param url       the URL being accessed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param proxyHost the proxy host to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param proxyPort the proxy port to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @param useCache  whether the cached connection should be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *        if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public void setProxiedClient (URL url, String proxyHost, int proxyPort,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            boolean useCache) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        proxiedConnect(url, proxyHost, proxyPort, useCache);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (!http.isCachedConnection()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            doTunneling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        ((HttpsClient)http).afterConnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    protected void proxiedConnect(URL url, String proxyHost, int proxyPort,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            boolean useCache) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (connected)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        http = HttpsClient.New (getSSLSocketFactory(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                getHostnameVerifier(),
16499
88276d2da9c0 8009251: Add proxy handling and keep-alive fixes to jsse
robm
parents: 10596
diff changeset
   138
                                proxyHost, proxyPort, useCache, this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        connected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Used by subclass to access "connected" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public boolean isConnected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return connected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Used by subclass to access "connected" variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public void setConnected(boolean conn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        connected = conn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Implements the HTTP protocol handler's "connect" method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * establishing an SSL connection to the server as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public void connect() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (connected)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        plainConnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (cachedResponse != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            // using cached response
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (!http.isCachedConnection() && http.needsTunneling()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            doTunneling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        ((HttpsClient)http).afterConnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    // will try to use cached HttpsClient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    protected HttpClient getNewHttpClient(URL url, Proxy p, int connectTimeout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        return HttpsClient.New(getSSLSocketFactory(), url,
16499
88276d2da9c0 8009251: Add proxy handling and keep-alive fixes to jsse
robm
parents: 10596
diff changeset
   178
                               getHostnameVerifier(), p, true, connectTimeout,
88276d2da9c0 8009251: Add proxy handling and keep-alive fixes to jsse
robm
parents: 10596
diff changeset
   179
                               this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    // will open new connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    protected HttpClient getNewHttpClient(URL url, Proxy p, int connectTimeout,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                          boolean useCache)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return HttpsClient.New(getSSLSocketFactory(), url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                               getHostnameVerifier(), p,
16499
88276d2da9c0 8009251: Add proxy handling and keep-alive fixes to jsse
robm
parents: 10596
diff changeset
   188
                               useCache, connectTimeout, this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Returns the cipher suite in use on this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public String getCipherSuite () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (cachedResponse != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            return ((SecureCacheResponse)cachedResponse).getCipherSuite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (http == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            throw new IllegalStateException("connection not yet open");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
           return ((HttpsClient)http).getCipherSuite ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Returns the certificate chain the client sent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * server, or null if the client did not authenticate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public java.security.cert.Certificate[] getLocalCertificates() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (cachedResponse != null) {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   211
            List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getLocalCertificateChain();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            } else {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   215
                return l.toArray(new java.security.cert.Certificate[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (http == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            throw new IllegalStateException("connection not yet open");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            return (((HttpsClient)http).getLocalCertificates ());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Returns the server's certificate chain, or throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * SSLPeerUnverified Exception if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * the server did not authenticate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public java.security.cert.Certificate[] getServerCertificates()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            throws SSLPeerUnverifiedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (cachedResponse != null) {
29377
d3f457ce9c48 8073430: Deprecate security APIs that have been superseded
juh
parents: 25859
diff changeset
   233
            List<java.security.cert.Certificate> l =
d3f457ce9c48 8073430: Deprecate security APIs that have been superseded
juh
parents: 25859
diff changeset
   234
                    ((SecureCacheResponse)cachedResponse)
d3f457ce9c48 8073430: Deprecate security APIs that have been superseded
juh
parents: 25859
diff changeset
   235
                            .getServerCertificateChain();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            } else {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   239
                return l.toArray(new java.security.cert.Certificate[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (http == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            throw new IllegalStateException("connection not yet open");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return (((HttpsClient)http).getServerCertificates ());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Returns the server's principal, or throws SSLPeerUnverifiedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * if the server did not authenticate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    Principal getPeerPrincipal()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            throws SSLPeerUnverifiedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (cachedResponse != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            return ((SecureCacheResponse)cachedResponse).getPeerPrincipal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (http == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            throw new IllegalStateException("connection not yet open");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            return (((HttpsClient)http).getPeerPrincipal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Returns the principal the client sent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * server, or null if the client did not authenticate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    Principal getLocalPrincipal()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (cachedResponse != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            return ((SecureCacheResponse)cachedResponse).getLocalPrincipal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (http == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            throw new IllegalStateException("connection not yet open");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            return (((HttpsClient)http).getLocalPrincipal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
52474
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
   285
    SSLSession getSSLSession() {
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
   286
        if (cachedResponse != null) {
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
   287
            Optional<SSLSession> option =
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
   288
                    ((SecureCacheResponse)cachedResponse).getSSLSession();
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
   289
            if (option.isPresent()) {
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
   290
                return option.orElseThrow();
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
   291
            }
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
   292
        }
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
   293
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
   294
        if (http == null) {
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
   295
            throw new IllegalStateException("connection not yet open");
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
   296
        }
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
   297
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
   298
        return ((HttpsClient)http).getSSLSession();
13266dac5fdb 8212261: Add SSLSession accessors to HttpsURLConnection and SecureCacheResponse
xuelei
parents: 47216
diff changeset
   299
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
}