Skip to content

Instantly share code, notes, and snippets.

@daeken
Last active December 20, 2015 20:18
Show Gist options
  • Select an option

  • Save daeken/6189151 to your computer and use it in GitHub Desktop.

Select an option

Save daeken/6189151 to your computer and use it in GitHub Desktop.

Setup

On first run, the master generates an AES256 key at random, known as the seed key.

Joining connection

On first connection from master to slave, slave displays a phrase consisting of 5 dictionary words. This phrase is passed through PBKDF2 (25k rounds, SHA-256) to generate a joining key. User inputs the phrase on the master, which then generates the joining key on that side.

The slave sends a random 32-byte challenge to the master, which is HMACed (using the joining key) by the master and returned to the slave for validation. If the HMAC does not match the expected value on the slave, an error is returned and the process begins again (generating a new phrase after X [3-5] failures). If the HMAC matches, then the slave requests the master's seed key (encrypted (AES256, ECB) with the joining key) and joins the machine pool.

Post-join connection

The master connects to the slave and initiates session key exchange. The master generates an AES256 key at random, known as the session key. The session key is encrypted (AES256, ECB) with the seed key and passed to the slave.

The master and slave both generate a 64-bit half-IV and exchange these, encrypted with the session key (AES256, ECB, right null-padded). At this point, a stream is initiated, utilizing AES256 in CFB mode (IV = master_half + slave_half) with the session key.

All communication for this session takes place over the secure stream, with no ability to reuse keys across connections; the process must repeat every connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment