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