Package org.conscrypt

Class OpenSSLSessionImpl

java.lang.Object
org.conscrypt.OpenSSLSessionImpl
All Implemented Interfaces:
SSLSession

public class OpenSSLSessionImpl
extends Object
implements SSLSession
Implementation of the class OpenSSLSessionImpl based on OpenSSL.
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected long sslSessionNativePointer  
  • Constructor Summary

    Constructors
    Modifier Constructor Description
    protected OpenSSLSessionImpl​(long sslSessionNativePointer, X509Certificate[] localCertificates, X509Certificate[] peerCertificates, String peerHost, int peerPort, org.conscrypt.AbstractSessionContext sessionContext)
    Class constructor creates an SSL session context given the appropriate SSL parameters.
  • Method Summary

    Modifier and Type Method Description
    protected void finalize()
    Invoked when the garbage collector has detected that this instance is no longer reachable.
    int getApplicationBufferSize()
    Returns the largest buffer size for the application's data bound to this concrete SSL session.
    String getCipherSuite()
    Returns a string identifier of the crypto tools used in the actual SSL session.
    long getCreationTime()
    Gets the creation time of the SSL session.
    byte[] getId()
    Gets the identifier of the actual SSL session
    long getLastAccessedTime()
    Returns the last time this concrete SSL session was accessed.
    Certificate[] getLocalCertificates()
    Returns the certificate(s) of the principal (subject) of this concrete SSL session used in the handshaking phase of the connection.
    Principal getLocalPrincipal()
    Returns the principal (subject) of this concrete SSL session used in the handshaking phase of the connection.
    int getPacketBufferSize()
    Returns the largest SSL/TLS packet size one can expect for this concrete SSL session.
    X509Certificate[] getPeerCertificateChain()
    Returns the certificate(s) of the peer in this SSL session used in the handshaking phase of the connection.
    Certificate[] getPeerCertificates()
    Return the identity of the peer in this SSL session determined via certificate(s).
    String getPeerHost()
    The peer's host name used in this SSL session is returned.
    int getPeerPort()
    Returns the peer's port number for the actual SSL session.
    Principal getPeerPrincipal()
    The identity of the principal that was used by the peer during the SSL handshake phase is returned by this method.
    String getProtocol()
    Returns the standard version name of the SSL protocol used in all connections pertaining to this SSL session.
    SSLSessionContext getSessionContext()
    Returns the context to which the actual SSL session is bound.
    Object getValue​(String name)
    Returns the object which is bound to the the input parameter name.
    String[] getValueNames()
    Returns an array with the names (sort of links) of all the data objects of the application layer bound into the SSL session.
    void invalidate()
    It invalidates a SSL session forbidding any resumption.
    boolean isValid()
    Returns a boolean flag signaling whether a SSL session is valid and available for resuming or joining or not.
    void putValue​(String name, Object value)
    A link (name) with the specified value object of the SSL session's application layer data is created or replaced.
    void removeValue​(String name)
    Removes a link (name) with the specified value object of the SSL session's application layer data.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • sslSessionNativePointer

      protected long sslSessionNativePointer
  • Constructor Details

    • OpenSSLSessionImpl

      protected OpenSSLSessionImpl​(long sslSessionNativePointer, X509Certificate[] localCertificates, X509Certificate[] peerCertificates, String peerHost, int peerPort, org.conscrypt.AbstractSessionContext sessionContext)
      Class constructor creates an SSL session context given the appropriate SSL parameters.
  • Method Details

    • getId

      public byte[] getId()
      Gets the identifier of the actual SSL session
      Specified by:
      getId in interface SSLSession
      Returns:
      array of sessions' identifiers.
    • getCreationTime

      public long getCreationTime()
      Gets the creation time of the SSL session.
      Specified by:
      getCreationTime in interface SSLSession
      Returns:
      the session's creation time in milliseconds since the epoch
    • getLastAccessedTime

      public long getLastAccessedTime()
      Returns the last time this concrete SSL session was accessed. Accessing here is to mean that a new connection with the same SSL context data was established.
      Specified by:
      getLastAccessedTime in interface SSLSession
      Returns:
      the session's last access time in milliseconds since the epoch
    • getApplicationBufferSize

      public int getApplicationBufferSize()
      Returns the largest buffer size for the application's data bound to this concrete SSL session.
      Specified by:
      getApplicationBufferSize in interface SSLSession
      Returns:
      the largest buffer size
    • getPacketBufferSize

      public int getPacketBufferSize()
      Returns the largest SSL/TLS packet size one can expect for this concrete SSL session.
      Specified by:
      getPacketBufferSize in interface SSLSession
      Returns:
      the largest packet size
    • getLocalPrincipal

      public Principal getLocalPrincipal()
      Returns the principal (subject) of this concrete SSL session used in the handshaking phase of the connection.
      Specified by:
      getLocalPrincipal in interface SSLSession
      Returns:
      a X509 certificate or null if no principal was defined
    • getLocalCertificates

      public Certificate[] getLocalCertificates()
      Returns the certificate(s) of the principal (subject) of this concrete SSL session used in the handshaking phase of the connection. The OpenSSL native method supports only RSA certificates.
      Specified by:
      getLocalCertificates in interface SSLSession
      Returns:
      an array of certificates (the local one first and then eventually that of the certification authority) or null if no certificate were used during the handshaking phase.
    • getPeerCertificateChain

      public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException
      Returns the certificate(s) of the peer in this SSL session used in the handshaking phase of the connection. Please notice hat this method is superseded by getPeerCertificates().
      Specified by:
      getPeerCertificateChain in interface SSLSession
      Returns:
      an array of X509 certificates (the peer's one first and then eventually that of the certification authority) or null if no certificate were used during the SSL connection.
      Throws:
      SSLPeerUnverifiedException - if either a non-X.509 certificate was used (i.e. Kerberos certificates) or the peer could not be verified.
    • getPeerCertificates

      public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException
      Return the identity of the peer in this SSL session determined via certificate(s).
      Specified by:
      getPeerCertificates in interface SSLSession
      Returns:
      an array of X509 certificates (the peer's one first and then eventually that of the certification authority) or null if no certificate were used during the SSL connection.
      Throws:
      SSLPeerUnverifiedException - if either a non-X.509 certificate was used (i.e. Kerberos certificates) or the peer could not be verified.
    • getPeerPrincipal

      public Principal getPeerPrincipal() throws SSLPeerUnverifiedException
      The identity of the principal that was used by the peer during the SSL handshake phase is returned by this method.
      Specified by:
      getPeerPrincipal in interface SSLSession
      Returns:
      a X500Principal of the last certificate for X509-based cipher suites.
      Throws:
      SSLPeerUnverifiedException - if either a non-X.509 certificate was used (i.e. Kerberos certificates) or the peer does not exist.
    • getPeerHost

      public String getPeerHost()
      The peer's host name used in this SSL session is returned. It is the host name of the client for the server; and that of the server for the client. It is not a reliable way to get a fully qualified host name: it is mainly used internally to implement links for a temporary cache of SSL sessions.
      Specified by:
      getPeerHost in interface SSLSession
      Returns:
      the host name of the peer, or null if no information is available.
    • getPeerPort

      public int getPeerPort()
      Returns the peer's port number for the actual SSL session. It is the port number of the client for the server; and that of the server for the client. It is not a reliable way to get a peer's port number: it is mainly used internally to implement links for a temporary cache of SSL sessions.
      Specified by:
      getPeerPort in interface SSLSession
      Returns:
      the peer's port number, or -1 if no one is available.
    • getCipherSuite

      public String getCipherSuite()
      Returns a string identifier of the crypto tools used in the actual SSL session. For example AES_256_WITH_MD5.
      Specified by:
      getCipherSuite in interface SSLSession
      Returns:
      the name of the cipher suite used in this session.
    • getProtocol

      public String getProtocol()
      Returns the standard version name of the SSL protocol used in all connections pertaining to this SSL session.
      Specified by:
      getProtocol in interface SSLSession
      Returns:
      the protocol name that is used for all connections in this session.
    • getSessionContext

      public SSLSessionContext getSessionContext()
      Returns the context to which the actual SSL session is bound. A SSL context consists of (1) a possible delegate, (2) a provider and (3) a protocol.
      Specified by:
      getSessionContext in interface SSLSession
      Returns:
      the SSL context used for this session, or null if it is unavailable.
    • isValid

      public boolean isValid()
      Returns a boolean flag signaling whether a SSL session is valid and available for resuming or joining or not.
      Specified by:
      isValid in interface SSLSession
      Returns:
      true if this session may be resumed.
    • invalidate

      public void invalidate()
      It invalidates a SSL session forbidding any resumption.
      Specified by:
      invalidate in interface SSLSession
    • getValue

      public Object getValue​(String name)
      Returns the object which is bound to the the input parameter name. This name is a sort of link to the data of the SSL session's application layer, if any exists.
      Specified by:
      getValue in interface SSLSession
      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 - if the argument is null.
    • getValueNames

      public String[] getValueNames()
      Returns an array with the names (sort of links) of all the data objects of the application layer bound into the SSL session.
      Specified by:
      getValueNames in interface SSLSession
      Returns:
      a non-null (possibly empty) array of names of the data objects bound to this SSL session.
    • putValue

      public void putValue​(String name, Object value)
      A link (name) with the specified value object of the SSL session's application layer data is created or replaced. If the new (or existing) value object implements the SSLSessionBindingListener interface, that object will be notified in due course.
      Specified by:
      putValue in interface SSLSession
      Parameters:
      name - the name of the link (no null are accepted!)
      value - data object that shall be bound to name.
      Throws:
      IllegalArgumentException - if one or both argument(s) is null.
    • removeValue

      public void removeValue​(String name)
      Removes a link (name) with the specified value object of the SSL session's application layer data.

      If the value object implements the SSLSessionBindingListener interface, the object will receive a valueUnbound notification.

      Specified by:
      removeValue in interface SSLSession
      Parameters:
      name - the name of the link (no null are accepted!)
      Throws:
      IllegalArgumentException - if the argument is null.
    • finalize

      protected void finalize() throws Throwable
      Description copied from class: Object
      Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.

      Note that objects that override finalize are significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicit close method (and implement Closeable), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like a BigInteger where typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.

      If you must use finalizers, consider at least providing your own ReferenceQueue and having your own thread process that queue.

      Unlike constructors, finalizers are not automatically chained. You are responsible for calling super.finalize() yourself.

      Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.

      Overrides:
      finalize in class Object
      Throws:
      Throwable