Encryption in Remoting
anil.saldhana Aug 15, 2006 11:24 AMRelated to http://jira.jboss.com/jira/browse/JBREM-419
I plug in a CipherOutputStream to the JBossObjectOutputStream. The issue with COS is that it needs an explicit close() to flush all the data across. But this causes a socket write error as shown:
[SocketServerInvokerThread-127.0.0.1-0] ERROR org.jboss.remoting.transport.socket.ServerThread - failed to process invocation. java.net.SocketException: Software caused connection abort: socket write error at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(Unknown Source) at java.net.SocketOutputStream.write(Unknown Source) at java.io.BufferedOutputStream.flushBuffer(Unknown Source) at java.io.BufferedOutputStream.flush(Unknown Source) at java.io.DataOutputStream.flush(Unknown Source) at org.jboss.serial.io.JBossObjectOutputStream.flush(JBossObjectOutputStream.java:248) at javax.crypto.CipherOutputStream.flush(DashoA12275) at java.io.DataOutputStream.flush(Unknown Source) at org.jboss.serial.io.JBossObjectOutputStream.flush(JBossObjectOutputStream.java:248) at org.jboss.remoting.serialization.impl.jboss.JBossSerializationManager.sendObject(JBossSerializationManager.java:95) at org.jboss.remoting.marshal.serializable.SerializableMarshaller.write(SerializableMarshaller.java:84) at org.jboss.remoting.marshal.encryption.EncryptingMarshaller.write(EncryptingMarshaller.java:123) at org.jboss.remoting.transport.socket.ServerThread.versionedWrite(ServerThread.java:484) at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:463)
Clebert mentioned that there may be an issue with JBossOOS close with the following:
public void close() throws IOException {
flush();
dataOutput.close();
dataOutput.close();
}
A copy/paste error.
* I do not know yet whether the socket write error is something related to JBossOOS close or the other side closed the socket.
EncryptingMarshaller code:
public void write(Object dataObject, OutputStream output) throws IOException
{
if(cipher == null)
throw new IllegalStateException("Cipher is null for algo="+ this.cipherAlgorithm);
output.flush();
CipherOutputStream cos = new CipherOutputStream(output, cipher);
SerializationManager sm = SerializationStreamFactory.getManagerInstance(getSerializationType());
ObjectOutputStream oos = sm.createOutput(cos);
if(wrappedMarshaller != null)
{
wrappedMarshaller.write(dataObject, oos);
}
else
{
super.write(dataObject, oos);
}
oos.flush();
cos.close();
oos.close(); //There is a need to close cos
}
Clebert fixed the following:
http://jira.jboss.com/jira/browse/JBSER-87