Code example for SSLEngine

Methods: beginHandshake, getHandshakeStatus, getSession

0
     
    public SecureNioChannel(SocketChannel channel, SSLEngine engine, 
                            ApplicationBufferHandler bufHandler, NioSelectorPool pool) throws IOException {
        super(channel,bufHandler);
        this.sslEngine = engine;
        int appBufSize = sslEngine.getSession().getApplicationBufferSize();
        int netBufSize = sslEngine.getSession().getPacketBufferSize();
        //allocate network buffers - TODO, add in optional direct non-direct buffers 
        if ( netInBuffer == null ) netInBuffer = ByteBuffer.allocateDirect(netBufSize);
        if ( netOutBuffer == null ) netOutBuffer = ByteBuffer.allocateDirect(netBufSize);
         
        //selector pool for blocking operations 
        this.pool = pool;
         
        //ensure that the application has a large enough read/write buffers 
        //by doing this, we should not encounter any buffer overflow errors 
        bufHandler.expand(bufHandler.getReadBuffer(), appBufSize);
        bufHandler.expand(bufHandler.getWriteBuffer(), appBufSize);
        reset(); 
    } 
     
    public void reset(SSLEngine engine) throws IOException {
        this.sslEngine = engine;
        reset(); 
    } 
    public void reset() throws IOException { 
        super.reset(); 
        netOutBuffer.position(0);
        netOutBuffer.limit(0);
        netInBuffer.position(0);
        netInBuffer.limit(0);
        initHandshakeComplete = false;
        closed = false;
        closing = false;
        //initiate handshake 
        sslEngine.beginHandshake();
        initHandshakeStatus = sslEngine.getHandshakeStatus();
    } 
     
    public int getBufferSize() { 
        int size = super.getBufferSize();
        size += netInBuffer!=null?netInBuffer.capacity():0;