Path: blob/master/src/java.base/share/classes/java/net/SecureCacheResponse.java
41152 views
/*1* Copyright (c) 2003, 2020, 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*/2425package java.net;2627import java.security.cert.Certificate;28import javax.net.ssl.SSLSession;29import javax.net.ssl.SSLPeerUnverifiedException;30import java.security.Principal;31import java.util.List;32import java.util.Optional;3334/**35* Represents a cache response originally retrieved through secure36* means, such as TLS.37*38* @since 1.539*/40public abstract class SecureCacheResponse extends CacheResponse {41/**42* Constructor for subclasses to call.43*/44public SecureCacheResponse() {}4546/**47* Returns the cipher suite in use on the original connection that48* retrieved the network resource.49*50* @return a string representing the cipher suite51*/52public abstract String getCipherSuite();5354/**55* Returns the certificate chain that were sent to the server during56* handshaking of the original connection that retrieved the57* network resource. Note: This method is useful only58* when using certificate-based cipher suites.59*60* @return an immutable List of Certificate representing the61* certificate chain that was sent to the server. If no62* certificate chain was sent, null will be returned.63* @see #getLocalPrincipal()64*/65public abstract List<Certificate> getLocalCertificateChain();6667/**68* Returns the server's certificate chain, which was established as69* part of defining the session in the original connection that70* retrieved the network resource, from cache. Note: This method71* can be used only when using certificate-based cipher suites;72* using it with non-certificate-based cipher suites, such as73* Kerberos, will throw an SSLPeerUnverifiedException.74*75* @return an immutable List of Certificate representing the server's76* certificate chain.77* @throws SSLPeerUnverifiedException if the peer is not verified.78* @see #getPeerPrincipal()79*/80public abstract List<Certificate> getServerCertificateChain()81throws SSLPeerUnverifiedException;8283/**84* Returns the server's principal which was established as part of85* defining the session during the original connection that86* retrieved the network resource.87*88* @return the server's principal. Returns an X500Principal of the89* end-entity certificate for X509-based cipher suites, and90* KerberosPrincipal for Kerberos cipher suites.91*92* @throws SSLPeerUnverifiedException if the peer was not verified.93*94* @see #getServerCertificateChain()95* @see #getLocalPrincipal()96*/97public abstract Principal getPeerPrincipal()98throws SSLPeerUnverifiedException;99100/**101* Returns the principal that was sent to the server during102* handshaking in the original connection that retrieved the103* network resource.104*105* @return the principal sent to the server. Returns an X500Principal106* of the end-entity certificate for X509-based cipher suites, and107* KerberosPrincipal for Kerberos cipher suites. If no principal was108* sent, then null is returned.109*110* @see #getLocalCertificateChain()111* @see #getPeerPrincipal()112*/113public abstract Principal getLocalPrincipal();114115/**116* Returns an {@link Optional} containing the {@code SSLSession} in117* use on the original connection that retrieved the network resource.118* Returns an empty {@code Optional} if the underlying implementation119* does not support this method.120*121* @implSpec For compatibility, the default implementation of this122* method returns an empty {@code Optional}. Subclasses123* should override this method with an appropriate124* implementation since an application may need to access125* additional parameters associated with the SSL session.126*127* @return an {@link Optional} containing the {@code SSLSession} in128* use on the original connection129*130* @see SSLSession131*132* @since 12133*/134public Optional<SSLSession> getSSLSession() {135return Optional.empty();136}137}138139140