Class SSL


  • public class SSL
    extends java.lang.Object
    A representation of an SSL connection.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected SSL​(java.lang.Object ssl, Socket socket)
      Store the reference to an SSL context.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void dispose()
      Free any used resources on this connection.
      java.lang.String getCertificateDN​(int component)
      Retrieve an X.509 distinguished name component.
      byte getCipherId()
      Return the SSL cipher id.
      java.lang.Exception getLastException()  
      byte[] getSessionId()
      Get the session id for a handshake.
      int handshakeStatus()
      Return the result of a handshake.
      int read​(SSLReadHolder rh)
      Read the SSL data stream.
      int renegotiate()
      Force the client to perform its handshake again.
      int verifyCertificate()
      Authenticate a received certificate.
      int write​(byte[] out_data)
      Write to the SSL data stream.
      int write​(byte[] out_data, int out_len)
      Write to the SSL data stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SSL

        protected SSL​(java.lang.Object ssl,
                      Socket socket)
        Store the reference to an SSL context.
        Parameters:
        ssl - A reference to an SSL object.
    • Method Detail

      • dispose

        public final void dispose()
                           throws IOException
        Free any used resources on this connection. A "Close Notify" message is sent on this connection (if possible). It is up to the application to close the socket.
        Throws:
        IOException
      • handshakeStatus

        public final int handshakeStatus()
        Return the result of a handshake.
        Returns:
        SSL_OK if the handshake is complete and ok.
      • getCipherId

        public final byte getCipherId()
        Return the SSL cipher id.
        Returns:
        The cipher id which is one of: - TLS_RSA_WITH_AES_128_CBC_SHA (0x2f) - TLS_RSA_WITH_AES_256_CBC_SHA (0x35) - TLS_RSA_WITH_RC4_128_SHA (0x05) - TLS_RSA_WITH_RC4_128_MD5 (0x04)
      • getSessionId

        public final byte[] getSessionId()
        Get the session id for a handshake. This will be a 32 byte sequence and is available after the first handshaking messages are sent. A SSLv23 handshake may have only 16 valid bytes.
        Returns:
        The session id as a 32 byte sequence.
      • getCertificateDN

        public final java.lang.String getCertificateDN​(int component)
                                                throws CryptoException
        Retrieve an X.509 distinguished name component. When a handshake is complete and a certificate has been exchanged, then the details of the remote certificate can be retrieved. This will usually be used by a client to check that the server's common name matches the URL. A full handshake needs to occur for this call to work.
        Parameters:
        component - [in] one of: - SSL_X509_CERT_COMMON_NAME - SSL_X509_CERT_ORGANIZATION - SSL_X509_CERT_ORGANIZATIONAL_NAME - SSL_X509_CA_CERT_COMMON_NAME - SSL_X509_CA_CERT_ORGANIZATION - SSL_X509_CA_CERT_ORGANIZATIONAL_NAME
        Returns:
        The appropriate string (or null if not defined)
        Throws:
        CryptoException
      • read

        public final int read​(SSLReadHolder rh)
                       throws SocketTimeoutException,
                              IOException
        Read the SSL data stream. Use rh before doing any successive ssl calls.
        Parameters:
        rh - [out] After a successful read, the decrypted data can be retrieved with rh.getData(). It will be null otherwise.
        Returns:
        The number of decrypted bytes: - if > 0, then the handshaking is complete and we are returning the number of decrypted bytes. - SSL_OK if the handshaking stage is successful (but not yet complete). - < 0 if an error.
        Throws:
        SocketTimeoutException
        IOException
      • write

        public final int write​(byte[] out_data)
                        throws IOException
        Write to the SSL data stream.
        Parameters:
        out_data - [in] The data to be written
        Returns:
        The number of bytes sent, or if < 0 if an error.
        Throws:
        IOException
      • write

        public final int write​(byte[] out_data,
                               int out_len)
                        throws IOException
        Write to the SSL data stream.
        Parameters:
        out_data - [in] The data to be written
        out_len - [in] The number of bytes to be written
        Returns:
        The number of bytes sent, or if < 0 if an error.
        Throws:
        IOException
      • verifyCertificate

        public final int verifyCertificate()
                                    throws CryptoException
        Authenticate a received certificate. This call is usually made by a client after a handshake is complete and the context is in SSL_SERVER_VERIFY_LATER mode.
        Returns:
        SSL_OK if the certificate is verified.
        Throws:
        CryptoException
      • renegotiate

        public final int renegotiate()
                              throws IOException
        Force the client to perform its handshake again. For a client this involves sending another "client hello" message. For the server is means sending a "hello request" message. This is a blocking call on the client (until the handshake completes).
        Returns:
        SSL_OK if renegotiation instantiation was ok
        Throws:
        IOException
      • getLastException

        public final java.lang.Exception getLastException()
        Returns:
        the last exception occurred in this SSL connection.
        Since:
        TotalCross 1.20