# SSLSession

public interface **SSLSession**

|---|---|---|
| Known Indirect Subclasses [ExtendedSSLSession](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/ExtendedSSLSession.html) |---|---| | [ExtendedSSLSession](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/ExtendedSSLSession.html) | Extends the `SSLSession` interface to support additional session attributes. | |||

In SSL, sessions are used to describe an ongoing relationship between
two entities. Each SSL connection involves one session at a time, but
that session may be used on many connections between those entities,
simultaneously or sequentially. The session used on a connection may
also be replaced by a different session. Sessions are created, or
rejoined, as part of the SSL handshaking protocol. Sessions may be
invalidated due to policies affecting security or resource usage,
or by an application explicitly calling `invalidate`.
Session management policies are typically used to tune performance.

In addition to the standard session attributes, SSL sessions expose
these read-only attributes:

- *Peer Identity.* Sessions are between a particular client and a particular server. The identity of the peer may have been established as part of session setup. Peers are generally identified by X.509 certificate chains.
- *Cipher Suite Name.* Cipher suites describe the kind of cryptographic protection that's used by connections in a particular session.
- *Peer Host.* All connections in a session are between the same two hosts. The address of the host on the other side of the connection is available.

Sessions may be explicitly invalidated. Invalidation may also
be done implicitly, when faced with certain kinds of errors.

### Public Method Summary

|---|---|
| abstract int | [getApplicationBufferSize](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getApplicationBufferSize())() Gets the current size of the largest application data that is expected when using this session. |
| abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getCipherSuite](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getCipherSuite())() Returns the name of the SSL cipher suite which is used for all connections in the session. |
| abstract long | [getCreationTime](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getCreationTime())() Returns the time at which this Session representation was created, in milliseconds since midnight, January 1, 1970 UTC. |
| abstract byte\[\] | [getId](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getId())() Returns the identifier assigned to this Session. |
| abstract long | [getLastAccessedTime](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getLastAccessedTime())() Returns the last time this Session representation was accessed by the session level infrastructure, in milliseconds since midnight, January 1, 1970 UTC. |
| abstract [Certificate\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Certificate.html) | [getLocalCertificates](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getLocalCertificates())() Returns the certificate(s) that were sent to the peer during handshaking. |
| abstract [Principal](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Principal.html) | [getLocalPrincipal](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getLocalPrincipal())() Returns the principal that was sent to the peer during handshaking. |
| abstract int | [getPacketBufferSize](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getPacketBufferSize())() Gets the current size of the largest SSL/TLS packet that is expected when using this session. |
| abstract [X509Certificate\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/cert/X509Certificate.html) | [getPeerCertificateChain](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getPeerCertificateChain())() Returns the identity of the peer which was identified as part of defining the session. |
| abstract [Certificate\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Certificate.html) | [getPeerCertificates](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getPeerCertificates())() Returns the identity of the peer which was established as part of defining the session. |
| abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getPeerHost](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getPeerHost())() Returns the host name of the peer in this session. |
| abstract int | [getPeerPort](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getPeerPort())() Returns the port number of the peer in this session. |
| abstract [Principal](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Principal.html) | [getPeerPrincipal](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getPeerPrincipal())() Returns the identity of the peer which was established as part of defining the session. |
| abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getProtocol](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getProtocol())() Returns the standard name of the protocol used for all connections in the session. |
| abstract [SSLSessionContext](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSessionContext.html) | [getSessionContext](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getSessionContext())() Returns the context in which this session is bound. |
| abstract [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [getValue](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getValue(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) name) Returns the object bound to the given name in the session's application layer data. |
| abstract [String\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getValueNames](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getValueNames())() Returns an array of the names of all the application layer data objects bound into the Session. |
| abstract void | [invalidate](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#invalidate())() Invalidates the session. |
| abstract boolean | [isValid](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#isValid())() Returns whether this session is valid and available for resuming or joining. |
| abstract void | [putValue](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#putValue(java.lang.String,%20java.lang.Object))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) name, [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) value) Binds the specified `value` object into the session's application layer data with the given `name`. |
| abstract void | [removeValue](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#removeValue(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) name) Removes the object bound to the given name in the session's application layer data. |

## Public Methods

#### public abstract int
**getApplicationBufferSize**
()

Gets the current size of the largest application data that is
expected when using this session.


`SSLEngine` application data buffers must be large
enough to hold the application data from any inbound network
application data packet received. Typically, outbound
application data buffers can be of any size.

##### Returns

- the current maximum expected application packet size

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLEngine.html#wrap(java.nio.ByteBuffer,%20java.nio.ByteBuffer)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLEngine.html#unwrap(java.nio.ByteBuffer,%20java.nio.ByteBuffer)`

#### public abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**getCipherSuite**
()

Returns the name of the SSL cipher suite which is used for all
connections in the session.

This defines the level of protection
provided to the data sent on the connection, including the kind
of encryption used and most aspects of how authentication is done.

##### Returns

- the name of the session's cipher suite

#### public abstract long
**getCreationTime**
()

Returns the time at which this Session representation was created,
in milliseconds since midnight, January 1, 1970 UTC.

##### Returns

- the time this Session was created

#### public abstract byte\[\]
**getId**
()

Returns the identifier assigned to this Session.

##### Returns

- the Session identifier

#### public abstract long
**getLastAccessedTime**
()

Returns the last time this Session representation was accessed by the
session level infrastructure, in milliseconds since
midnight, January 1, 1970 UTC.


Access indicates a new connection being established using session data.
Application level operations, such as getting or setting a value
associated with the session, are not reflected in this access time.

This information is particularly useful in session management
policies. For example, a session manager thread could leave all
sessions in a given context which haven't been used in a long time;
or, the sessions might be sorted according to age to optimize some task.

##### Returns

- the last time this Session was accessed

#### public abstract [Certificate\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Certificate.html)
**getLocalCertificates**
()

Returns the certificate(s) that were sent to the peer during
handshaking.


Note: This method is useful only when using certificate-based
cipher suites.


When multiple certificates are available for use in a
handshake, the implementation chooses what it considers the
"best" certificate chain available, and transmits that to
the other side. This method allows the caller to know
which certificate chain was actually used.

##### Returns

- an ordered array of certificates, with the local certificate first followed by any certificate authorities. If no certificates were sent, then null is returned.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getLocalPrincipal()`

#### public abstract [Principal](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Principal.html)
**getLocalPrincipal**
()

Returns the principal that was sent to the peer during handshaking.

##### Returns

- the principal sent to the peer. Returns an X500Principal of the end-entity certificate for X509-based cipher suites, and KerberosPrincipal for Kerberos cipher suites. If no principal was sent, then null is returned.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getLocalCertificates()`
- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getPeerPrincipal()`

#### public abstract int
**getPacketBufferSize**
()

Gets the current size of the largest SSL/TLS packet that is expected
when using this session.


A `SSLEngine` using this session may generate SSL/TLS
packets of any size up to and including the value returned by this
method. All `SSLEngine` network buffers should be sized
at least this large to avoid insufficient space problems when
performing `wrap` and `unwrap` calls.

##### Returns

- the current maximum expected network packet size

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLEngine.html#wrap(java.nio.ByteBuffer,%20java.nio.ByteBuffer)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLEngine.html#unwrap(java.nio.ByteBuffer,%20java.nio.ByteBuffer)`

#### public abstract [X509Certificate\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/cert/X509Certificate.html)
**getPeerCertificateChain**
()

Returns the identity of the peer which was identified as part
of defining the session.


Note: This method can be used only when using certificate-based
cipher suites; using it with non-certificate-based cipher suites,
such as Kerberos, will throw an SSLPeerUnverifiedException.

*Note: this method exists for compatibility with previous
releases. New applications should use
`https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getPeerCertificates()` instead.*

<br />

##### Returns

- an ordered array of peer X.509 certificates, with the peer's own certificate first followed by any certificate authorities. (The certificates are in the original JSSE certificate `https://developers.google.com/j2objc/javadoc/jre/reference/javax/security/cert/X509Certificate.html` format.)

##### Throws

| [SSLPeerUnverifiedException](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLPeerUnverifiedException.html) | if the peer's identity has not been verified |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getPeerPrincipal()`

#### public abstract [Certificate\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Certificate.html)
**getPeerCertificates**
()

Returns the identity of the peer which was established as part
of defining the session.


Note: This method can be used only when using certificate-based
cipher suites; using it with non-certificate-based cipher suites,
such as Kerberos, will throw an SSLPeerUnverifiedException.

##### Returns

- an ordered array of peer certificates, with the peer's own certificate first followed by any certificate authorities.

##### Throws

| [SSLPeerUnverifiedException](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLPeerUnverifiedException.html) | if the peer's identity has not been verified |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getPeerPrincipal()`

#### public abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**getPeerHost**
()

Returns the host name of the peer in this session.


For the server, this is the client's host; and for
the client, it is the server's host. The name may not be
a fully qualified host name or even a host name at all as
it may represent a string encoding of the peer's network address.
If such a name is desired, it might
be resolved through a name service based on the value returned
by this method.


This value is not authenticated and should not be relied upon.
It is mainly used as a hint for `SSLSession` caching
strategies.

##### Returns

- the host name of the peer host, or null if no information is available.

#### public abstract int
**getPeerPort**
()

Returns the port number of the peer in this session.


For the server, this is the client's port number; and for
the client, it is the server's port number.


This value is not authenticated and should not be relied upon.
It is mainly used as a hint for `SSLSession` caching
strategies.

##### Returns

- the port number of the peer host, or -1 if no information is available.

#### public abstract [Principal](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/Principal.html)
**getPeerPrincipal**
()

Returns the identity of the peer which was established as part of
defining the session.

##### Returns

- the peer's principal. Returns an X500Principal of the end-entity certiticate for X509-based cipher suites, and KerberosPrincipal for Kerberos cipher suites.

##### Throws

| [SSLPeerUnverifiedException](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLPeerUnverifiedException.html) | if the peer's identity has not been verified |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getPeerCertificates()`
- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#getLocalPrincipal()`

#### public abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**getProtocol**
()

Returns the standard name of the protocol used for all
connections in the session.

This defines the protocol used in the connection.

##### Returns

- the standard name of the protocol used for all connections in the session.

#### public abstract [SSLSessionContext](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSessionContext.html)
**getSessionContext**
()

Returns the context in which this session is bound.


This context may be unavailable in some environments,
in which case this method returns null.


If the context is available and there is a
security manager installed, the caller may require
permission to access it or a security exception may be thrown.
In a Java environment, the security manager's
`checkPermission` method is called with a
`SSLPermission("getSSLSessionContext")` permission.

##### Returns

- the session context used for this session, or null if the context is unavailable.

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if the calling thread does not have permission to get SSL session context. |
|---|---|

#### public abstract [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)
**getValue**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) name)

Returns the object bound to the given name in the session's
application layer data. Returns null if there is no such binding.


For security reasons, the same named values may not be
visible across different access control contexts.

##### Parameters

| name | the name of the binding to find. |
|---|---|

##### Returns

- the value bound to that name, or null if the binding does not exist.

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the argument is null. |
|---|---|

#### public abstract [String\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**getValueNames**
()

Returns an array of the names of all the application layer
data objects bound into the Session.


For security reasons, the same named values may not be
visible across different access control contexts.

##### Returns

- a non-null (possibly empty) array of names of the objects bound to this Session.

#### public abstract void
**invalidate**
()

Invalidates the session.


Future connections will not be able to
resume or join this session. However, any existing connection
using this session can continue to use the session until the
connection is closed.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#isValid()`

#### public abstract boolean
**isValid**
()

Returns whether this session is valid and available for resuming or
joining.

##### Returns

- true if this session may be rejoined.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSession.html#invalidate()`

#### public abstract void
**putValue**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) name, [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) value)

Binds the specified `value` object into the
session's application layer data
with the given `name`.


Any existing binding using the same `name` is
replaced. If the new (or existing) `value` implements the
`SSLSessionBindingListener` interface, the object
represented by `value` is notified appropriately.


For security reasons, the same named values may not be
visible across different access control contexts.

##### Parameters

| name | the name to which the data object will be bound. This may not be null. |
| value | the data object to be bound. This may not be null. |
|---|---|

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if either argument is null. |
|---|---|

#### public abstract void
**removeValue**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) name)

Removes the object bound to the given name in the session's
application layer data. Does nothing if there is no object
bound to the given name. If the bound existing object
implements the `SessionBindingListener` interface,
it is notified appropriately.


For security reasons, the same named values may not be
visible across different access control contexts.

##### Parameters

| name | the name of the object to remove visible across different access control contexts |
|---|---|

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the argument is null. |
|---|---|