Class SSLSocketChannel

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.ByteChannel, java.nio.channels.Channel, java.nio.channels.ReadableByteChannel, java.nio.channels.WritableByteChannel, WrappedByteChannel

    public class SSLSocketChannel
    extends java.lang.Object
    implements WrappedByteChannel, java.nio.channels.ByteChannel
    A class that represents an SSL/TLS peer, and can be extended to create a client or a server. It makes use of the JSSE framework, and specifically the SSLEngine logic, which is described by Oracle as "an advanced API, not appropriate for casual use", since it requires the user to implement much of the communication establishment procedure himself. More information about it can be found here: http://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSSERefGuide.html#SSLEngine SSLSocketChannel implements the handshake protocol, required to establish a connection between two peers, which is common for both client and server and provides the abstract read(ByteBuffer) and write(ByteBuffer) (String)} methods, that need to be implemented by the specific SSL/TLS peer that is going to extend this class.
    Author:
    Alex Karnezis

    Modified by marci4 to allow the usage as a ByteChannel

    Permission for usage recieved at May 25, 2017 by Alex Karnezis

    • Constructor Summary

      Constructors 
      Constructor Description
      SSLSocketChannel​(java.nio.channels.SocketChannel inputSocketChannel, javax.net.ssl.SSLEngine inputEngine, java.util.concurrent.ExecutorService inputExecutor, java.nio.channels.SelectionKey key)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      boolean isBlocking()
      This function returns the blocking state of the channel
      boolean isNeedRead()
      returns whether readMore should be called to fetch data which has been decoded but not yet been returned.
      boolean isNeedWrite()
      returns whether writeMore should be called write additional data.
      boolean isOpen()  
      int read​(java.nio.ByteBuffer dst)  
      int readMore​(java.nio.ByteBuffer dst)
      This function does not read data from the underlying channel at all.
      int write​(java.nio.ByteBuffer output)  
      void writeMore()
      Gets called when WrappedByteChannel.isNeedWrite() ()} requires a additional rite
      • Methods inherited from class java.lang.Object

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

      • SSLSocketChannel

        public SSLSocketChannel​(java.nio.channels.SocketChannel inputSocketChannel,
                                javax.net.ssl.SSLEngine inputEngine,
                                java.util.concurrent.ExecutorService inputExecutor,
                                java.nio.channels.SelectionKey key)
                         throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • read

        public int read​(java.nio.ByteBuffer dst)
                 throws java.io.IOException
        Specified by:
        read in interface java.nio.channels.ReadableByteChannel
        Throws:
        java.io.IOException
      • write

        public int write​(java.nio.ByteBuffer output)
                  throws java.io.IOException
        Specified by:
        write in interface java.nio.channels.WritableByteChannel
        Throws:
        java.io.IOException
      • isNeedWrite

        public boolean isNeedWrite()
        Description copied from interface: WrappedByteChannel
        returns whether writeMore should be called write additional data.
        Specified by:
        isNeedWrite in interface WrappedByteChannel
        Returns:
        is a additional write needed
      • readMore

        public int readMore​(java.nio.ByteBuffer dst)
                     throws java.io.IOException
        Description copied from interface: WrappedByteChannel
        This function does not read data from the underlying channel at all. It is just a way to fetch data which has already be received or decoded but was but was not yet returned to the user. This could be the case when the decoded data did not fit into the buffer the user passed to ReadableByteChannel.read(ByteBuffer).
        Specified by:
        readMore in interface WrappedByteChannel
        Parameters:
        dst - the destiny of the read
        Returns:
        the amount of remaining data
        Throws:
        java.io.IOException - when a error occurred during unwrapping
      • isBlocking

        public boolean isBlocking()
        Description copied from interface: WrappedByteChannel
        This function returns the blocking state of the channel
        Specified by:
        isBlocking in interface WrappedByteChannel
        Returns:
        is the channel blocking
      • isOpen

        public boolean isOpen()
        Specified by:
        isOpen in interface java.nio.channels.Channel
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException