com.sun.grizzly.filter
Class SSLReadFilter

java.lang.Object
  extended by com.sun.grizzly.filter.SSLReadFilter
All Implemented Interfaces:
ProtocolFilter

public class SSLReadFilter
extends Object
implements ProtocolFilter

Simple ProtocolFilter implementation which execute an SSL handshake and decrypt the bytes, the pass the control to the next filter.

Author:
Jeanfrancois Arcand

Field Summary
protected  int inputBBSize
          Encrypted ByteBuffer default size.
protected  SSLContext sslContext
          The SSLContext associated with the SSL implementation we are running on.
 
Fields inherited from interface com.sun.grizzly.ProtocolFilter
SUCCESSFUL_READ
 
Constructor Summary
SSLReadFilter()
           
 
Method Summary
protected  void allocateBuffers()
          Allocate themandatory ByteBuffers.
 void configure(SSLConfig sslConfig)
          Configures SSL settings.
static Object[] doPeerCertificateChain(SelectionKey key, boolean needClientAuth)
          Get the peer certificate list by initiating a new handshake.
 boolean execute(Context ctx)
          Execute a unit of processing work to be performed.
 String[] getEnabledCipherSuites()
          Returns the list of cipher suites to be enabled when SSLEngine is initialized.
 String[] getEnabledProtocols()
          Returns the list of protocols to be enabled when SSLEngine is initialized.
 SSLContext getSSLContext()
          Return the SSLContext required to support SSL over NIO.
 boolean isClientMode()
          Returns true if the SSlEngine is set to use client mode when handshaking.
 boolean isNeedClientAuth()
          Returns true if the SSLEngine will require client authentication.
 boolean isWantClientAuth()
          Returns true if the engine will request client authentication.
protected static void log(String msg, Throwable t)
          Log a message/exception.
protected  SSLEngine newSSLEngine()
          Return a new configured SSLEngine
protected  SSLEngine newSSLEngine(SelectionKey key)
          Configure and return an instance of SSLEngine
 boolean postExecute(Context ctx)
          If no bytes were available, close the connection by cancelling the SelectionKey.
 void setClientMode(boolean clientMode)
          Configures the engine to use client (or server) mode when handshaking.
 void setEnabledCipherSuites(String[] enabledCipherSuites)
          Sets the list of cipher suites to be enabled when SSLEngine is initialized.
 void setEnabledProtocols(String[] enabledProtocols)
          Sets the list of protocols to be enabled when SSLEngine is initialized.
 void setNeedClientAuth(boolean needClientAuth)
          Configures the engine to require client authentication.
 void setSSLContext(SSLContext sslContext)
          Set the SSLContext required to support SSL over NIO.
 void setWantClientAuth(boolean wantClientAuth)
          Configures the engine to request client authentication.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sslContext

protected SSLContext sslContext
The SSLContext associated with the SSL implementation we are running on.


inputBBSize

protected int inputBBSize
Encrypted ByteBuffer default size.

Constructor Detail

SSLReadFilter

public SSLReadFilter()
Method Detail

execute

public boolean execute(Context ctx)
                throws IOException
Description copied from interface: ProtocolFilter
Execute a unit of processing work to be performed. This ProtocolFilter may either complete the required processing and return false, or delegate remaining processing to the next ProtocolFilter in a ProtocolChain containing this ProtocolFilter by returning true.

Specified by:
execute in interface ProtocolFilter
Parameters:
ctx - Context
Returns:
Throws:
IOException

postExecute

public boolean postExecute(Context ctx)
                    throws IOException
If no bytes were available, close the connection by cancelling the SelectionKey. If bytes were available, register the SelectionKey for new bytes.

Specified by:
postExecute in interface ProtocolFilter
Parameters:
ctx - Context
Returns:
true if the previous ProtocolFilter postExecute method needs to be invoked.
Throws:
IOException

allocateBuffers

protected void allocateBuffers()
Allocate themandatory ByteBuffers. Since the ByteBuffer are maintaned on the WorkerThread lazily, this method makes sure the ByteBuffers are properly allocated and configured.


doPeerCertificateChain

public static Object[] doPeerCertificateChain(SelectionKey key,
                                              boolean needClientAuth)
                                       throws IOException
Get the peer certificate list by initiating a new handshake.

Parameters:
key - SelectionKey
needClientAuth -
Returns:
Object[] An array of X509Certificate.
Throws:
IOException

newSSLEngine

protected SSLEngine newSSLEngine()
Return a new configured SSLEngine

Returns:
a new configured SSLEngine

newSSLEngine

protected SSLEngine newSSLEngine(SelectionKey key)
Configure and return an instance of SSLEngine

Parameters:
key - a SelectionKey
Returns:
a configured instance of SSLEngine

configure

public void configure(SSLConfig sslConfig)
Configures SSL settings. SSLConfig contains all the parameters required to build SSLEngine. There will be no need to call four methods: setSSLContext, setClientMode, setWantClientAuth, setNeedClientAuth.

Parameters:
sslConfig - SSLConfig configuration

setSSLContext

public void setSSLContext(SSLContext sslContext)
Set the SSLContext required to support SSL over NIO.

Parameters:
sslContext - SSLContext

getSSLContext

public SSLContext getSSLContext()
Return the SSLContext required to support SSL over NIO.

Returns:
SSLContext

getEnabledCipherSuites

public String[] getEnabledCipherSuites()
Returns the list of cipher suites to be enabled when SSLEngine is initialized.

Returns:
null means 'use SSLEngine's default.'

setEnabledCipherSuites

public void setEnabledCipherSuites(String[] enabledCipherSuites)
Sets the list of cipher suites to be enabled when SSLEngine is initialized.

Parameters:
enabledCipherSuites -

getEnabledProtocols

public String[] getEnabledProtocols()
Returns the list of protocols to be enabled when SSLEngine is initialized.

Returns:
null means 'use SSLEngine's default.'

setEnabledProtocols

public void setEnabledProtocols(String[] enabledProtocols)
Sets the list of protocols to be enabled when SSLEngine is initialized.

Parameters:
enabledProtocols - null means 'use SSLEngine's default.'

isClientMode

public boolean isClientMode()
Returns true if the SSlEngine is set to use client mode when handshaking.

Returns:
true / false

setClientMode

public void setClientMode(boolean clientMode)
Configures the engine to use client (or server) mode when handshaking.

Parameters:
clientMode -

isNeedClientAuth

public boolean isNeedClientAuth()
Returns true if the SSLEngine will require client authentication.

Returns:

setNeedClientAuth

public void setNeedClientAuth(boolean needClientAuth)
Configures the engine to require client authentication.

Parameters:
needClientAuth -

isWantClientAuth

public boolean isWantClientAuth()
Returns true if the engine will request client authentication.

Returns:

setWantClientAuth

public void setWantClientAuth(boolean wantClientAuth)
Configures the engine to request client authentication.

Parameters:
wantClientAuth -

log

protected static void log(String msg,
                          Throwable t)
Log a message/exception.

Parameters:
msg - String
t - Throwable


Copyright © 2008 SUN Microsystems. All Rights Reserved.