Now I have carefully looked at your code, and I have some comments:
- This code looks so that it can easily protect against accidental modification of pickled objects while they are in flight.
sha224 is a great hash algorithm and it will be easy to spot packets that have been accidentally changed that may still transmit the TCP checksum . - This code does not protect against malicious modification of pickled objects while they are in flight. There is no certainty that the packets come from a trusted member of the computer network, and there is no assurance that the packets have not been changed. (Or completely fallen.)
Using only a hashing algorithm cannot prove the source of the packets or prove that they were not maliciously changed: an attacker can simply recalculate the hash after changing the data and resend the packet.
There are several “normal approaches” to this problem: you can use a shared secret, a key common to all clients participating in the network. This key will be used as part of the hash key, such as HMAC , and the data recipients will recalculate the HMAC authentication code using the shared key. It's quick and easy (and legal in some jurisdictions that prohibit cryptographic software), but a common key is a giant responsibility if any one of them has its own key. (Compromised systems may not even be part of your threat model.)
You can also use shared secrets paid by the host. It works the same as a shared secret between all nodes, but if one client key has been cracked, only one client key needs to be replaced on all other systems.
You can also use public key cryptography to provide package signatures . Each client has a private key and a corresponding public key, which is known to all customers. A compromised private key still crashes the system, but it significantly reduces the number of keys you need to prepare. (Only one for each customer, not one for each customer pair: O (N) versus O (N 2 ).)
Public key systems are fun to write yourself as a learning experience, but it's awful to try to program correctly. Protection against repeated attacks, selective deletion of messages, slicing / building messages, etc. Requires a lot of smart protocol design.
Thus, most people deploy a predefined transport security scheme such as SSLv3 or TLS . In combination with client certificates, it can easily provide assurances that both endpoints are those who, according to them, (to the level of compromised keys, of course), and ensure that data sent in a TLS-protected stream is delivered in the correct order and without fake.
TLS can work hard to properly configure. You can have just as good success with a simpler tool like ssh . Libraries are available , so you can manage connections programmatically, rather than relying on the ssh(1) and sshd(8) clients provided by the system.