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.
static String SSL_PREREAD_DATA
          Attribute is used to instruct SSLReadFilter to continue processing, if there is some data availabe in decoded ByteBuffer, even, if SSLReaderFilter wasn't able to read any additional data
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
 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.
 int getSslActivityTimeout()
           
 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 configuredSSLEngine
protected  SSLEngine obtainSSLEngine(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 setSslActivityTimeout(int sslActivityTimeout)
           
 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

SSL_PREREAD_DATA

public static final String SSL_PREREAD_DATA
Attribute is used to instruct SSLReadFilter to continue processing, if there is some data availabe in decoded ByteBuffer, even, if SSLReaderFilter wasn't able to read any additional data

See Also:
Constant Field Values

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

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 configuredSSLEngine

Returns:
a new configuredSSLEngine

obtainSSLEngine

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

Parameters:
key - a SelectionKey
Returns:
a configured instance ofSSLEngine

configure

public void configure(SSLConfig sslConfig)
Configures SSL settings. SSLConfig contains all the parameters required to buildSSLEngine. 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 -

getSslActivityTimeout

public int getSslActivityTimeout()

setSslActivityTimeout

public void setSslActivityTimeout(int sslActivityTimeout)

log

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

Parameters:
msg - String
t - Throwable


Copyright © 2012 Oracle Corporation. All Rights Reserved.