Class SSLCTX

  • Direct Known Subclasses:
    SSLClient, SSLServer

    public class SSLCTX
    extends java.lang.Object
    A base object for SSLServer/SSLClient.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String toSign  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected SSLCTX​(int options, int num_sessions)
      Establish a new client/server context.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void dispose()
      Remove a client/server context.
      protected void finalize()  
      SSL find​(Socket s)
      Find an ssl object based on a Socket reference.
      SSL newClient​(Socket socket, byte[] session_id)  
      SSL newServer​(Socket socket)  
      int objLoad​(int obj_type, byte[] data, int len, java.lang.String password)
      Load security material (CA, Cert or private key) in binary DER or ASCII PEM format.
      int objLoad​(int obj_type, Stream material, java.lang.String password)
      Load security material (CA, Cert or private key) in binary DER or ASCII PEM format.
      • Methods inherited from class java.lang.Object

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

      • SSLCTX

        protected SSLCTX​(int options,
                         int num_sessions)
                  throws NoSuchAlgorithmException
        Establish a new client/server context. This function is called before any client/server SSL connections are made. If multiple threads are used, then each thread will have its own SSLCTX context. Any number of connections may be made with a single context. Each new connection will use the this context's private key and certificate chain. If a different certificate chain is required, then a different context needs to be be used.
        Parameters:
        options - [in] Any particular options. At present the options supported are: - SSL_SERVER_VERIFY_LATER (client only): Don't stop a handshake if the server authentication fails. The certificate can be authenticated later with a call to verifyCert(). - SSL_CLIENT_AUTHENTICATION (server only): Enforce client authentication i.e. each handshake will include a "certificate request" message from the server. - SSL_NO_DEFAULT_KEY: Don't use the default key/certificate. The user will load the key/certificate explicitly. - SSL_DISPLAY_BYTES (full mode build only): Display the byte sequences during the handshake. - SSL_DISPLAY_STATES (full mode build only): Display the state changes during the handshake. - SSL_DISPLAY_CERTS (full mode build only): Display the certificates that are passed during a handshake. - SSL_DISPLAY_RSA (full mode build only): Display the RSA key details that are passed during a handshake.
        num_sessions - [in] The number of sessions to be used for session caching. If this value is 0, then there is no session caching. If this option is null, then the default internal private key/ certificate pair is used (if CONFIG_SSL_USE_DEFAULT_KEY is set). The resources used by this object are automatically freed.
        Throws:
        NoSuchAlgorithmException
    • Method Detail

      • dispose

        public final void dispose()
        Remove a client/server context. Frees any used resources used by this context. Each connection will be sent a "Close Notify" alert (if possible).
      • find

        public final SSL find​(Socket s)
        Find an ssl object based on a Socket reference. Goes through the list of SSL objects maintained in a client/server context to look for a socket match.
        Parameters:
        s - [in] A reference to a totalcross.net.Socket object.
        Returns:
        A reference to the SSL object. Returns null if the object could not be found.
      • objLoad

        public final int objLoad​(int obj_type,
                                 Stream material,
                                 java.lang.String password)
                          throws IOException,
                                 NoSuchAlgorithmException,
                                 CryptoException
        Load security material (CA, Cert or private key) in binary DER or ASCII PEM format. These information are used during the SSL protocol to authentication of SSL parts and cyphering/uncyphering of the data exchanged between the two parts.
        Parameters:
        obj_type - [in] The format of the file. Can be one of: - SSL_OBJ_X509_CERT (no password required). - SSL_OBJ_X509_CACERT (no password required). - SSL_OBJ_RSA_KEY (AES128/AES256 PEM encryption supported). (not supported on Desktop) - SSL_OBJ_P8 (RC4-128 encrypted data supported). (password protection not supported on Desktop) - SSL_OBJ_P12 (RC4-128 encrypted data supported). PEM encoded files are automatically detected and may contain several material, whereas DER encoding only support one single material.
        material - [in] security material input stream.
        password - [in] The password used. Can be null if not required.
        Returns:
        SSL_OK if the call succeeded
        Throws:
        CryptoException
        NoSuchAlgorithmException
        IOException
      • objLoad

        public final int objLoad​(int obj_type,
                                 byte[] data,
                                 int len,
                                 java.lang.String password)
                          throws NoSuchAlgorithmException,
                                 CryptoException
        Load security material (CA, Cert or private key) in binary DER or ASCII PEM format. These information are used during the SSL protocol to authenticate an SSL part and cyphering/uncyphering of the data exchanged between the two parts.
        Parameters:
        obj_type - [in] The format of the memory data. - SSL_OBJ_X509_CERT (no password required). - SSL_OBJ_X509_CACERT (no password required). - SSL_OBJ_RSA_KEY (AES128/AES256 PEM encryption supported). (not supported on Desktop) - SSL_OBJ_P8 (RC4-128 encrypted data supported). (password protection not supported on Desktop) - SSL_OBJ_P12 (RC4-128 encrypted data supported). PEM encoded data is automatically detected and may contain several material, whereas DER encoding only support one single material.
        data - [in] The binary data to be loaded.
        len - [in] The amount of data to be loaded.
        password - [in] The password used. Can be null if not required.
        Returns:
        SSL_OK if the call succeeded
        Throws:
        CryptoException
        NoSuchAlgorithmException
      • finalize

        protected final void finalize()
        Overrides:
        finalize in class java.lang.Object