Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/net/ssl/SSLSession.java
38918 views
/*1* Copyright (c) 1997, 2012, 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 javax.net.ssl;2627import java.security.Principal;2829/**30* In SSL, sessions are used to describe an ongoing relationship between31* two entities. Each SSL connection involves one session at a time, but32* that session may be used on many connections between those entities,33* simultaneously or sequentially. The session used on a connection may34* also be replaced by a different session. Sessions are created, or35* rejoined, as part of the SSL handshaking protocol. Sessions may be36* invalidated due to policies affecting security or resource usage,37* or by an application explicitly calling <code>invalidate</code>.38* Session management policies are typically used to tune performance.39*40* <P> In addition to the standard session attributes, SSL sessions expose41* these read-only attributes: <UL>42*43* <LI> <em>Peer Identity.</em> Sessions are between a particular44* client and a particular server. The identity of the peer may45* have been established as part of session setup. Peers are46* generally identified by X.509 certificate chains.47*48* <LI> <em>Cipher Suite Name.</em> Cipher suites describe the49* kind of cryptographic protection that's used by connections50* in a particular session.51*52* <LI> <em>Peer Host.</em> All connections in a session are53* between the same two hosts. The address of the host on the other54* side of the connection is available.55*56* </UL>57*58* <P> Sessions may be explicitly invalidated. Invalidation may also59* be done implicitly, when faced with certain kinds of errors.60*61* @since 1.462* @author David Brownell63*/64public interface SSLSession {6566/**67* Returns the identifier assigned to this Session.68*69* @return the Session identifier70*/71public byte[] getId();727374/**75* Returns the context in which this session is bound.76* <P>77* This context may be unavailable in some environments,78* in which case this method returns null.79* <P>80* If the context is available and there is a81* security manager installed, the caller may require82* permission to access it or a security exception may be thrown.83* In a Java environment, the security manager's84* <code>checkPermission</code> method is called with a85* <code>SSLPermission("getSSLSessionContext")</code> permission.86*87* @throws SecurityException if the calling thread does not have88* permission to get SSL session context.89* @return the session context used for this session, or null90* if the context is unavailable.91*/92public SSLSessionContext getSessionContext();939495/**96* Returns the time at which this Session representation was created,97* in milliseconds since midnight, January 1, 1970 UTC.98*99* @return the time this Session was created100*/101public long getCreationTime();102103104/**105* Returns the last time this Session representation was accessed by the106* session level infrastructure, in milliseconds since107* midnight, January 1, 1970 UTC.108* <P>109* Access indicates a new connection being established using session data.110* Application level operations, such as getting or setting a value111* associated with the session, are not reflected in this access time.112*113* <P> This information is particularly useful in session management114* policies. For example, a session manager thread could leave all115* sessions in a given context which haven't been used in a long time;116* or, the sessions might be sorted according to age to optimize some task.117*118* @return the last time this Session was accessed119*/120public long getLastAccessedTime();121122123/**124* Invalidates the session.125* <P>126* Future connections will not be able to127* resume or join this session. However, any existing connection128* using this session can continue to use the session until the129* connection is closed.130*131* @see #isValid()132*/133public void invalidate();134135136/**137* Returns whether this session is valid and available for resuming or138* joining.139*140* @return true if this session may be rejoined.141* @see #invalidate()142*143* @since 1.5144*/145public boolean isValid();146147148/**149*150* Binds the specified <code>value</code> object into the151* session's application layer data152* with the given <code>name</code>.153* <P>154* Any existing binding using the same <code>name</code> is155* replaced. If the new (or existing) <code>value</code> implements the156* <code>SSLSessionBindingListener</code> interface, the object157* represented by <code>value</code> is notified appropriately.158* <p>159* For security reasons, the same named values may not be160* visible across different access control contexts.161*162* @param name the name to which the data object will be bound.163* This may not be null.164* @param value the data object to be bound. This may not be null.165* @throws IllegalArgumentException if either argument is null.166*/167public void putValue(String name, Object value);168169170/**171* Returns the object bound to the given name in the session's172* application layer data. Returns null if there is no such binding.173* <p>174* For security reasons, the same named values may not be175* visible across different access control contexts.176*177* @param name the name of the binding to find.178* @return the value bound to that name, or null if the binding does179* not exist.180* @throws IllegalArgumentException if the argument is null.181*/182public Object getValue(String name);183184185/**186* Removes the object bound to the given name in the session's187* application layer data. Does nothing if there is no object188* bound to the given name. If the bound existing object189* implements the <code>SessionBindingListener</code> interface,190* it is notified appropriately.191* <p>192* For security reasons, the same named values may not be193* visible across different access control contexts.194*195* @param name the name of the object to remove visible196* across different access control contexts197* @throws IllegalArgumentException if the argument is null.198*/199public void removeValue(String name);200201202/**203* Returns an array of the names of all the application layer204* data objects bound into the Session.205* <p>206* For security reasons, the same named values may not be207* visible across different access control contexts.208*209* @return a non-null (possibly empty) array of names of the objects210* bound to this Session.211*/212public String [] getValueNames();213214/**215* Returns the identity of the peer which was established as part216* of defining the session.217* <P>218* Note: This method can be used only when using certificate-based219* cipher suites; using it with non-certificate-based cipher suites,220* such as Kerberos, will throw an SSLPeerUnverifiedException.221*222* @return an ordered array of peer certificates,223* with the peer's own certificate first followed by any224* certificate authorities.225* @exception SSLPeerUnverifiedException if the peer's identity has not226* been verified227* @see #getPeerPrincipal()228*/229public java.security.cert.Certificate [] getPeerCertificates()230throws SSLPeerUnverifiedException;231232/**233* Returns the certificate(s) that were sent to the peer during234* handshaking.235* <P>236* Note: This method is useful only when using certificate-based237* cipher suites.238* <P>239* When multiple certificates are available for use in a240* handshake, the implementation chooses what it considers the241* "best" certificate chain available, and transmits that to242* the other side. This method allows the caller to know243* which certificate chain was actually used.244*245* @return an ordered array of certificates,246* with the local certificate first followed by any247* certificate authorities. If no certificates were sent,248* then null is returned.249*250* @see #getLocalPrincipal()251*/252public java.security.cert.Certificate [] getLocalCertificates();253254/**255* Returns the identity of the peer which was identified as part256* of defining the session.257* <P>258* Note: This method can be used only when using certificate-based259* cipher suites; using it with non-certificate-based cipher suites,260* such as Kerberos, will throw an SSLPeerUnverifiedException.261*262* <p><em>Note: this method exists for compatibility with previous263* releases. New applications should use264* {@link #getPeerCertificates} instead.</em></p>265*266* @return an ordered array of peer X.509 certificates,267* with the peer's own certificate first followed by any268* certificate authorities. (The certificates are in269* the original JSSE certificate270* {@link javax.security.cert.X509Certificate} format.)271* @exception SSLPeerUnverifiedException if the peer's identity272* has not been verified273* @see #getPeerPrincipal()274*/275public javax.security.cert.X509Certificate [] getPeerCertificateChain()276throws SSLPeerUnverifiedException;277278/**279* Returns the identity of the peer which was established as part of280* defining the session.281*282* @return the peer's principal. Returns an X500Principal of the283* end-entity certiticate for X509-based cipher suites, and284* KerberosPrincipal for Kerberos cipher suites.285*286* @throws SSLPeerUnverifiedException if the peer's identity has not287* been verified288*289* @see #getPeerCertificates()290* @see #getLocalPrincipal()291*292* @since 1.5293*/294public Principal getPeerPrincipal()295throws SSLPeerUnverifiedException;296297/**298* Returns the principal that was sent to the peer during handshaking.299*300* @return the principal sent to the peer. Returns an X500Principal301* of the end-entity certificate for X509-based cipher suites, and302* KerberosPrincipal for Kerberos cipher suites. If no principal was303* sent, then null is returned.304*305* @see #getLocalCertificates()306* @see #getPeerPrincipal()307*308* @since 1.5309*/310public Principal getLocalPrincipal();311312/**313* Returns the name of the SSL cipher suite which is used for all314* connections in the session.315*316* <P> This defines the level of protection317* provided to the data sent on the connection, including the kind318* of encryption used and most aspects of how authentication is done.319*320* @return the name of the session's cipher suite321*/322public String getCipherSuite();323324/**325* Returns the standard name of the protocol used for all326* connections in the session.327*328* <P> This defines the protocol used in the connection.329*330* @return the standard name of the protocol used for all331* connections in the session.332*/333public String getProtocol();334335/**336* Returns the host name of the peer in this session.337* <P>338* For the server, this is the client's host; and for339* the client, it is the server's host. The name may not be340* a fully qualified host name or even a host name at all as341* it may represent a string encoding of the peer's network address.342* If such a name is desired, it might343* be resolved through a name service based on the value returned344* by this method.345* <P>346* This value is not authenticated and should not be relied upon.347* It is mainly used as a hint for <code>SSLSession</code> caching348* strategies.349*350* @return the host name of the peer host, or null if no information351* is available.352*/353public String getPeerHost();354355/**356* Returns the port number of the peer in this session.357* <P>358* For the server, this is the client's port number; and for359* the client, it is the server's port number.360* <P>361* This value is not authenticated and should not be relied upon.362* It is mainly used as a hint for <code>SSLSession</code> caching363* strategies.364*365* @return the port number of the peer host, or -1 if no information366* is available.367*368* @since 1.5369*/370public int getPeerPort();371372/**373* Gets the current size of the largest SSL/TLS packet that is expected374* when using this session.375* <P>376* A <code>SSLEngine</code> using this session may generate SSL/TLS377* packets of any size up to and including the value returned by this378* method. All <code>SSLEngine</code> network buffers should be sized379* at least this large to avoid insufficient space problems when380* performing <code>wrap</code> and <code>unwrap</code> calls.381*382* @return the current maximum expected network packet size383*384* @see SSLEngine#wrap(ByteBuffer, ByteBuffer)385* @see SSLEngine#unwrap(ByteBuffer, ByteBuffer)386*387* @since 1.5388*/389public int getPacketBufferSize();390391392/**393* Gets the current size of the largest application data that is394* expected when using this session.395* <P>396* <code>SSLEngine</code> application data buffers must be large397* enough to hold the application data from any inbound network398* application data packet received. Typically, outbound399* application data buffers can be of any size.400*401* @return the current maximum expected application packet size402*403* @see SSLEngine#wrap(ByteBuffer, ByteBuffer)404* @see SSLEngine#unwrap(ByteBuffer, ByteBuffer)405*406* @since 1.5407*/408public int getApplicationBufferSize();409}410411412