|The stupid question is the question not asked|
Good IPC Message Protocols?by pileofrogs (Priest)
|on Jan 29, 2009 at 23:20 UTC||Need Help??|
pileofrogs has asked for the
wisdom of the Perl Monks concerning the following question:
I'm writing some client-server code, and while I've got no problem setting up the pipes, sockets or what-have-you, I've realised I don't know much about formatting the conversation that goes on over those pipes or sockets or what-have-you.
To be more specific, I have a server process with privileged access and clients that pass instructions to the server. The idea being to separate the privileged and mundane happenings. To be even more specific, this is in reference to Security, root and CGI?.
So, once I've got my sockets set up, what's the most secure, by that I mean limited, constrained, way to format the messages between my two processes?
I'd like to assume that my non-privileged client has been completely hacked, so I want to make it as hard as possible for the baddies to crack open the privileged process. I want to pretend bad guys can send anything at all down the socket at my privileged process.
For example, I could do something vague, like var = value separated by newline, ala:
I'd rather do something more secure. I thought I still use var and value pairs, but I'd encode the vars and values and delimit them by a character outside that encodings resulting character set. So, maybe I'd base64 encode the vars and values and separate them with a ':', using a newline to separate records, ala (totally fake):
(note: I'm not encrypting. I'm trying to make it really hard for the privileged process to miss-interpret the message it receives.)
Then, when I parse it out I only have 67 (65 from base64 plus ':' and '\n') acceptable characters, and I can drop any messages containing bad characters on the floor. Since ':' and '\n' aren't members of the base64 output list, splitting my vars and values will be a snap.
Obviously, this only helps me through one step. I have to decode and then use those vars and values, but now at least, I know which are vars and which are values.
So! My questions are: Does this make sense? Is there a better way to do this?