Sockets + ObjectInputStream, Retrieving Invalid Data for Security
If I have a Socket listening for data and im using an ObjectInputStream,
how do I retrieve the data of any failed readObject() attempts?
Should I subclass an InputStream and override the read methods
to copy the data (or at least make it accessible during an error)?
I could then reset the copy buffer after every successful readObject
attempt.
Is there already a class / utility for doing this?
Because this connection is very sensitive im trying to retain a transcript of
all the invalid data the socket has seen.
Thanks for any suggestions.
# 1
> If I have a Socket listening for data and im using an
> ObjectInputStream,
> how do I retrieve the data of any failed readObject()
> attempts?
>
> Should I subclass an InputStream and override the
> read methods
> to copy the data (or at least make it accessible
> during an error)?
> I could then reset the copy buffer after every
> successful readObject
> attempt.
>
> Is there already a class / utility for doing this?
>
> Because this connection is very sensitive im trying
> to retain a transcript of
> all the invalid data the socket has seen.
>
> Thanks for any suggestions.
I think you should look at your underlying problem rather than dealing with symptoms.
If a readObject failed then it probaby failed for good reason. What exactly is the error?
I guess another way to say it would be what you are talking about is nonsense. An Object stream is not any more "sensitive" over a Socket then a file, in terms of when the actual data is actually sent. So yes the operation could fail because the socket is dead but it isn't going to fail because TCP is injecting bytes or swapping byte order along the way.
So there is anoyther more fundamental problem and error message you haven't told us about yet.
# 2
> I guess another way to say it would be what you are
> talking about is nonsense.
Haha, your "no nonsense" responses are always charming.
You misunderstood my question. Ill try to be more clear.
Admittedly, I know very little about networking protocols.
I have a ServerSocket waiting for connections.
When a connection is made an ObjectInputStream is listening
for Objects. If a connection is made between 2 of my programs
then everything is great and thats not what im asking about.
My question regards this: what if someone|thing else (a different
program or whatever) establishs a connection with my program?
At the ServerSocket layer the precaution is taken to block all non-localhost connections and any explicit connections the user allows.
But suppose somehow a program that doesnt adhere to the Object
protocol is able to connect and they send some data over... the OIS
will throw an exception - but wont provide a copy of the data that
was sent over.
I think the InputStream subclassing will work. Its super simple and
just requires copying the data into a buffer:
public int read(byte[] b){
super.read(b)
// copy b into a temporary buffer
}
Its essential (based on my requirements) to monitor the data that
is exchanged. Object Streams provide a great service and wrap things
up so id like to use them - and still retain access to the data my socket
is receiving.
Thanks!
# 4
Strange requirement. Most servers just close the connection if they receive something that doesn't conform to the initial protocol. This goes for HTTP, RMI, SSL, ... You could implement it by interposing your own FilterInputStream subclass between the socket and the ObjectInputStream, but I would question the whole idea first. What interest can junk data possibly have?
Except maybe I suppose in the case of a security attack, but surely all you really need there is the source-address, which is right there in the accepted Socket.
ejpa at 2007-7-12 19:08:08 >
