Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/net/ssl/HttpsURLConnection.java
38922 views
/*1* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* NOTE: this file was copied from javax.net.ssl.HttpsURLConnection27*/2829package com.sun.net.ssl;3031import java.net.URL;32import java.net.HttpURLConnection;33import java.io.IOException;34import javax.net.SocketFactory;35import javax.net.ssl.SSLSocketFactory;3637import javax.security.cert.X509Certificate;3839/**40* HTTP URL connection with support for HTTPS-specific features. See41* <A HREF="http://www.w3.org/pub/WWW/Protocols/"> the spec </A> for42* details.43*44* @deprecated As of JDK 1.4, this implementation-specific class was45* replaced by {@link javax.net.ssl.HttpsURLConnection}.46*/47@Deprecated48abstract public49class HttpsURLConnection extends HttpURLConnection50{51/*52* Initialize an HTTPS URLConnection ... could check that the URL53* is an "https" URL, and that the handler is also an HTTPS one,54* but that's established by other code in this package.55* @param url the URL56*/57public HttpsURLConnection(URL url) throws IOException {58super(url);59}6061/**62* Returns the cipher suite in use on this connection.63* @return the cipher suite64*/65public abstract String getCipherSuite();6667/**68* Returns the server's X.509 certificate chain, or null if69* the server did not authenticate.70* @return the server certificate chain71*/72public abstract X509Certificate [] getServerCertificateChain();7374/**75* HostnameVerifier provides a callback mechanism so that76* implementers of this interface can supply a policy for77* handling the case where the host to connect to and78* the server name from the certificate mismatch.79*80* The default implementation will deny such connections.81*/82private static HostnameVerifier defaultHostnameVerifier =83new HostnameVerifier() {84public boolean verify(String urlHostname, String certHostname) {85return false;86}87};8889protected HostnameVerifier hostnameVerifier = defaultHostnameVerifier;9091/**92* Sets the default HostnameVerifier inherited when an instance93* of this class is created.94* @param v the default host name verifier95*/96public static void setDefaultHostnameVerifier(HostnameVerifier v) {97if (v == null) {98throw new IllegalArgumentException(99"no default HostnameVerifier specified");100}101102SecurityManager sm = System.getSecurityManager();103if (sm != null) {104sm.checkPermission(new SSLPermission("setHostnameVerifier"));105}106defaultHostnameVerifier = v;107}108109/**110* Gets the default HostnameVerifier.111* @return the default host name verifier112*/113public static HostnameVerifier getDefaultHostnameVerifier() {114return defaultHostnameVerifier;115}116117/**118* Sets the HostnameVerifier.119* @param v the host name verifier120*/121public void setHostnameVerifier(HostnameVerifier v) {122if (v == null) {123throw new IllegalArgumentException(124"no HostnameVerifier specified");125}126127hostnameVerifier = v;128}129130/**131* Gets the HostnameVerifier.132* @return the host name verifier133*/134public HostnameVerifier getHostnameVerifier() {135return hostnameVerifier;136}137138private static SSLSocketFactory defaultSSLSocketFactory = null;139140private SSLSocketFactory sslSocketFactory = getDefaultSSLSocketFactory();141142/**143* Sets the default SSL socket factory inherited when an instance144* of this class is created.145* @param sf the default SSL socket factory146*/147public static void setDefaultSSLSocketFactory(SSLSocketFactory sf) {148if (sf == null) {149throw new IllegalArgumentException(150"no default SSLSocketFactory specified");151}152153SecurityManager sm = System.getSecurityManager();154if (sm != null) {155sm.checkSetFactory();156}157defaultSSLSocketFactory = sf;158}159160/**161* Gets the default SSL socket factory.162* @return the default SSL socket factory163*/164public static SSLSocketFactory getDefaultSSLSocketFactory() {165if (defaultSSLSocketFactory == null) {166defaultSSLSocketFactory =167(SSLSocketFactory)SSLSocketFactory.getDefault();168}169return defaultSSLSocketFactory;170}171172/**173* Sets the SSL socket factory.174* @param sf the SSL socket factory175*/176public void setSSLSocketFactory(SSLSocketFactory sf) {177if (sf == null) {178throw new IllegalArgumentException(179"no SSLSocketFactory specified");180}181182SecurityManager sm = System.getSecurityManager();183if (sm != null) {184sm.checkSetFactory();185}186187sslSocketFactory = sf;188}189190/**191* Gets the SSL socket factory.192* @return the SSL socket factory193*/194public SSLSocketFactory getSSLSocketFactory() {195return sslSocketFactory;196}197}198199200