laserlight;10901975 wrote:You can send the IV in the clear over the socket, but you must never use the same IV more than once with the same key and encryption algorithm.
Thanks for the clarification. According to what I've now read you can apparently send the IV right along with the ciphertext without any loss in security. The IV is merely intended to insure that the same message, sent twice, will be encrypted differently each time. If that is the case, I'm deducing that it would be good practice to try and make your IV look as similar to your ciphertext as possible. I.e., if your ciphertext consists entirely of uppercase hexadecimal chars (0-9 and A-F) then so should your IV.
There is some debate on the [man]mcrypt_create_iv[/man] function in the PHP documentation comments with many folks reporting that it is slow. Since performance is very important for this application, I'm tempted to use the alternative IV generator offered in the comments there:
function alt_mcrypt_create_iv ($size) {
$iv = '';
for($i = 0; $i < $size; $i++) {
$iv .= chr(rand(0,255));
}
return $iv;
}
I'm not really sure how long a given IV should be. Wikipedia says "The size of the IV depends on the encryption algorithm and on the cryptographic protocol in use and is normally as large as the block size of the cipher or as large as the encryption key." The word cipher (which can refer to either the algorithm or the ciphertext) as used here refers to the length of the ciphertext if I'm not mistaken. On the other hand, if you need the IV to encrypt the message, how does one know how long the encrypted message is? It's a bit confusing.
questions:
What do we think of that alt_mcrypt_create_iv function? Does it appear less secure than the mcrypt_create_iv function?
How long should the IV be? I'm guessing that it is more secure if the IV is longer but that exceeding the length of the plaintext message doesn't offer any benefit. The onlamp example I previously posted simply sets IV length to the length of the constant string MCRYPT_RIJNDAEL_128 and strlen('rijndael-128') == 12.
* Am I right in understanding what the technical/philosophical reason for the IV is, namely that it prevents a given plaintext string from being encrypted the same way twice?
laserlight;10901975 wrote:I believe that with SSL, it is the two parties that generate the key and IV. The central manager probably should perform the role of the certificate authority instead. It is probably wiser to implement SSL/TLS instead of inventing your own protocol - you already have many ways to go wrong in the implementation.
It is my understanding (but I could be wrong) that the public and private keys belonging to each party are basically very large prime numbers and that the establishment of a communication channel involves some pretty heavy lifting mathematically. Given that it's not practical to do this heavy lifting for each message to be sent, a 'session key' is established for a given SSL communication session. Seems to me I might use HTTPS to create some kind of session key for my socket communications without any appreciable loss in security, right?
I'm not sure what you mean by the Manager acting as a CA. My plan is basically this.
1) as each client process is launched, it will make an HTTPS connection to the Manger to request a session key. I rely on cURL and Apache to make sure the connection is secure and simply generate a random string of some decent length to use as an encryption key. I might also negotiate other things such as an agreed-upon IV length for the communication session. Or I could just default IV length to strlen($key).
2) The Manager will respond to each HTTPS request with the necessary information and will keep a record of it as being connected to the particular connecting client.
3) The HTTPS connection will be closed
4) a socket connection to the Manager (which is listening for connections) will be initiated by the client. All information transmitted across the socket will be encrypted using mcrypt functions, the agreed-upon key and an IV of the agreed-upon length.
Any feedback would be most appreciated. This approach seems pretty secure to me. It's important that it be both secure and fast.