net.cnri.dobj
Class ConnectionEncryption

java.lang.Object
  extended by net.cnri.dobj.ConnectionEncryption
Direct Known Subclasses:
DESEncryption, GenericEncryption

public abstract class ConnectionEncryption
extends java.lang.Object

Objects of class ConnectionEncryption are capable of encrypting and decrypting traffic on the connection.


Constructor Summary
ConnectionEncryption()
           
 
Method Summary
static ConnectionEncryption constructInstance(DOConnection conn, HeaderSet request, HeaderSet response)
          Constructs a ConnectionEncryption instance that conforms to the given parameters.
static java.security.SecureRandom getRandom()
          Return a singleton SecureRandom object.
abstract  void initParameters(HeaderSet request, HeaderSet parameters)
          Set up the encryption mechanism and put the parameters into the given HeaderSet so that they can be communicated to the other side.
abstract  void processIncomingChunk(java.nio.ByteBuffer buf)
          Decrypts the incoming chunk of bytes and puts the result back into the given ByteBuffer for reading.
abstract  java.nio.ByteBuffer processOutgoingChunk(java.nio.ByteBuffer buf)
          Processes the outgoing chunk of bytes and returns the processed version.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionEncryption

public ConnectionEncryption()
Method Detail

initParameters

public abstract void initParameters(HeaderSet request,
                                    HeaderSet parameters)
                             throws java.lang.Exception
Set up the encryption mechanism and put the parameters into the given HeaderSet so that they can be communicated to the other side. The "cryptsecretkey" parameter is encrypted using the public key that is included in the request argument.

Throws:
java.lang.Exception

processIncomingChunk

public abstract void processIncomingChunk(java.nio.ByteBuffer buf)
                                   throws java.security.GeneralSecurityException
Decrypts the incoming chunk of bytes and puts the result back into the given ByteBuffer for reading.

Throws:
java.security.GeneralSecurityException

processOutgoingChunk

public abstract java.nio.ByteBuffer processOutgoingChunk(java.nio.ByteBuffer buf)
                                                  throws java.security.GeneralSecurityException
Processes the outgoing chunk of bytes and returns the processed version. Note: This may process the bytes in-line, or re-use the returned buffer in order to avoid allocating a new buffer for every invocation.

Throws:
java.security.GeneralSecurityException

constructInstance

public static ConnectionEncryption constructInstance(DOConnection conn,
                                                     HeaderSet request,
                                                     HeaderSet response)
                                              throws java.lang.Exception
Constructs a ConnectionEncryption instance that conforms to the given parameters. This is called by DOConnection when the other side of a connection sends a request to establish encryption on a connection. After this method returns, the given response will be sent to the other side of the connection immediately before the connection becomes encrypted.

Parameters:
request - The parameter set containing input for the encryption setup
response - The parameter set where the encryption details will be stored
Returns:
a ConnectionEncryption object conforming to the parameters
Throws:
java.lang.Exception

getRandom

public static final java.security.SecureRandom getRandom()
Return a singleton SecureRandom object.