Package com.sshtools.synergy.nio.ssl
Class SSLContextConnection
java.lang.Object
com.sshtools.synergy.nio.SocketConnection
com.sshtools.synergy.nio.ssl.SSLContextConnection
- All Implemented Interfaces:
SelectionKeyAware,SelectorRegistrationListener,SocketHandler
This class implements an SSL socket connection for the custom server.
Using the Java 1.5 SSLEngine class this implementation wraps all protocol
traffic into SSL records.
-
Field Summary
Fields inherited from class com.sshtools.synergy.nio.SocketConnection
closed, daemon, daemonContext, key, protocolEngine, selectorThread, socketChannel, socketDataIn, socketDataOut -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.SSLContextConnection(boolean allowClientCertificate, boolean requireClientCertificate) -
Method Summary
Modifier and TypeMethodDescriptionstatic SSLContextGet the SSL context.static voidInitialize SSL.booleanIs the socket still connected? During the initial handshake check the raw socket status, otherwise check the protocol status.booleanThis method is called when new network data arrives on the socket.booleanWrite any application data to the socket by wrapping it up into the SSL protocol.voidregistrationCompleted(SelectableChannel channel, SelectionKey key, SelectorThread selectorThread) This method is called once the socket is registered with a SelectorThread.booleanTell the selector that the handler wants to write.Methods inherited from class com.sshtools.synergy.nio.SocketConnection
addTask, closeConnection, closeConnection, flagWrite, getConnection, getContext, getDaemonContext, getIdleStates, getInitialOps, getLocalAddress, getLocalPort, getName, getPort, getProtocolEngine, getRemoteAddress, getSelectorThread, getSocketChannel, getThread, initialize, isSelectorThread, setProtocolEngine, setSelectionKey, setThread, wantsRead
-
Constructor Details
-
SSLContextConnection
public SSLContextConnection()Default constructor. We need one of these so we can dynamically create a SocketConnection on demand. -
SSLContextConnection
public SSLContextConnection(boolean allowClientCertificate, boolean requireClientCertificate)
-
-
Method Details
-
registrationCompleted
public void registrationCompleted(SelectableChannel channel, SelectionKey key, SelectorThread selectorThread) This method is called once the socket is registered with a SelectorThread. At this point we're ready to start transfering data.- Specified by:
registrationCompletedin interfaceSelectorRegistrationListener- Overrides:
registrationCompletedin classSocketConnection- Parameters:
channel- SelectableChannelkey- SelectionKeyselectorThread- SelectorThread
-
getSSLContext
Get the SSL context. If SSL isn't initialized when this is called we initialize it.- Returns:
- SSLContext
- Throws:
ExceptionIOException
-
initializeSSL
Initialize SSL. If at all possible this should be called before any connection attempts are made.- Throws:
FileNotFoundExceptionIOException
-
isConnected
public boolean isConnected()Is the socket still connected? During the initial handshake check the raw socket status, otherwise check the protocol status.- Overrides:
isConnectedin classSocketConnection- Returns:
- boolean
-
processReadEvent
public boolean processReadEvent()This method is called when new network data arrives on the socket. We have to unwrap any SSL traffic into raw application data- Specified by:
processReadEventin interfaceSocketHandler- Overrides:
processReadEventin classSocketConnection- Parameters:
applicationData- ByteBuffer- Returns:
- boolean
-
processWriteEvent
public boolean processWriteEvent()Write any application data to the socket by wrapping it up into the SSL protocol.- Specified by:
processWriteEventin interfaceSocketHandler- Overrides:
processWriteEventin classSocketConnection- Parameters:
applicationData- ByteBuffer- Returns:
- boolean
-
wantsWrite
public boolean wantsWrite()Description copied from interface:SocketHandlerTell the selector that the handler wants to write.- Specified by:
wantsWritein interfaceSocketHandler- Overrides:
wantsWritein classSocketConnection- Returns:
-