bitpay/copay — pull request #768 by ryanxcharles (2014-06-26 21:34:04+00:00)
Title: Authentication

In order to prevent MITM attacks, messages need to be signed. In this PR I add a new core class called Message which does the signing and encryption of network messages. This class is used by the network class to do encryption, decryption, signing and verification.

Another important element is that the public key needs to be checked against the peerId (the hash of the public key) to confirm that the claimed public key does in fact correspond to the peerId. That is also included in this PR.

There is still one missing piece that I have yet to add. The public keys (or peerId) needs to be visible in the interface, and each copayer needs to confirm through an existing secure communications channel that the public keys (or peerId) are accurate. I will add that in a subsequent PR.

The code in this PR is not intended to prevent all conceivable network attacks. Replay attacks and timing attacks are possible with this code. Ultimately, we will want to use an existing secure communications protocol like TLS instead of this network protocol. I have included a version number in the network code that may aid in allowing us to upgrade the network protocol at a later date.