hashicorp/memberlist — pull request #11 by ryanuber (2014-04-03 09:56:34+00:00)
Title: Allow multiple keys to be used for decrypting messages

For reliable key rotation to work, we need to support adding in encryption keys and then switching to them without removing the origin key. This would allow some time for all members to perform their key cut-over, and then remove the old key later on.

Here I have added a `config.SecretKeys` list, which tracks all keys memberlist currently knows about. We still have the original `config.SecretKey`, which is the key that is used for encrypting messages.

When a new key is installed, it is not immediately activated. This is to allow time for the new key to be distributed to all members. Once it is safe to start encrypting messages with the new key, a call to `UseSecretKey` can be made, passing in the key which should become the "active" key.

When a message is received, we first try to decode it using the "active" key. Failing that, we iterate through each of our `config.SecretKeys` (excluding the active key), and attempt to decrypt with each one until we get a success. If no keys work, then an error message is returned.

The original interfaces are all still intact.