Services/Sync/P2P Key Exchange And Rotation: Difference between revisions

From MozillaWiki
< Services‎ | Sync
Jump to navigation Jump to search
(Fixed links)
(Added more detail of messaging protocol)
Line 86: Line 86:
===Messaging Protocol===
===Messaging Protocol===
A bonus of using the 3DHE key exchange is that it naturally abstracts in to a generalised messaging protocol that can be used to send an arbitrary messages encrypted with the session key derived during the 3DHE key exchange. In addition perfect forward secrecy can be achieved using [https://github.com/trevp/axolotl/wiki axolotl key ratcheting] as used in the Text Secure application. Although this is not implemented at this stage it presents an opportunity to extend functionality to include peer to peer key management that can be shared between multiple devices.
A bonus of using the 3DHE key exchange is that it naturally abstracts in to a generalised messaging protocol that can be used to send an arbitrary messages encrypted with the session key derived during the 3DHE key exchange. In addition perfect forward secrecy can be achieved using [https://github.com/trevp/axolotl/wiki axolotl key ratcheting] as used in the Text Secure application. Although this is not implemented at this stage it presents an opportunity to extend functionality to include peer to peer key management that can be shared between multiple devices.
'''Protocol Sequence'''
<ol start="0">
<li>Each client publishes an identity key (AI, BI) and a set of ephemeral keys (AE{1..n}, BE{1..n})</li>
<li>Client A generates a new ephemeral key (AE) and randomly selects one of client B's ephemeral keys (BE). Using 3DHE and a KDF, client A generates the shared secret (S) then sends message including own ephemeral key (AE) and identifier for client B's ephemeral key (X). Body can be encrypted with shared secret.</li>
<li>Client B receives client A's ephemeral key (AE) and identifier for own ephemeral key (BE). Using 3DHE and a KDF, client B generates the shared secret (S) and can then decrypt the message body.</li>
<li>Both client A and client B can now continue to communicate using the shared secret (S) as a session key</li>
</ol>
<pre>
          Alice (Client A)                      Eve (Public)    Bob (Client B)
t0        AIs                                    AIp, BIp        BIs
                                                  BE{1..n}p        BE{1..n}s
t1        AIs                                    AIp, BIp                     
          AEs                                    AEp, BEp         
          BIp                                                       
          BEp = BE{X}p, X ∈ {1..n}                                           
          S = KDF(3DHE(AIs, AEs, BIp, BEp))   
t2                                                                BIs
                                                                  BEs ∈ BE{X}s, X ∈ {1..n}
                                                                  AIp
                                                                  AEp
                                                                  S = KDF(3DHE(BIs, BEs, AIp, AEp))
</pre>
'''Message JSON'''
<pre>
{
  version:      "version string",
  srcclientid:  "id of sender",
  srckeyid:    "id of sender's ephemeral key",
  srckey:      "sender's ephemeral key (optional after first message, i.e. sequence > 1)",
  dstclientid:  "id of receiver",
  srckeyid:    "id of receiver's ephemeral key",
  sequence:    "sequence of this message in session",
  type:        "message type",
  content:      "message content"
  hmac:        "HMAC of all other message fields"
}
</pre>


=== Registration Protocol ===
=== Registration Protocol ===

Revision as of 09:13, 9 November 2014

Support secure and intuitive key exchange and key rotation between Weave Sync clients.

Over a number of versions of Weave Sync different key exchange mechanisms have been implemented, however to date they have had significant weaknesses in either security or user experience (UX) or both. This wiki describes (yet another) proposal which attempts to find the balance between (good enough) security and an intuitive UX.

Overview

The objective of the P2P Key Exchange protocol is to securely transfer a secret key to a new weave client during registration. Importantly, as such it is only relevant for Weave Sync versions which utilise a randomly generated secret key, namely Weave Sync v5 and the pairing extension of Weave Sync v6.

Arguable the Weave Sync v5 J-PAKE based key exchange protocol already achieves this, however as discussed below a significant weakness is that it requires three round trips to completed and thus requires both the new and an already registered client to be online concurrently and with good connectivity. Also Weave Sync v5, as currently implemented, does not support rotation of the secret key.

The P2P Key Exchange Protocol aims to address these issues by implementing a 3DHE based key exchange protocol with pre-generated ephemeral keys, allowing the key exchange to be completed asynchronously and in a single round trip. The same technique can also be leveraged for key rotation, although in this case only a single message needs to be sent by the initiating client, a response is not required but can be used to indicate success. The key exchange is also implemented within Weave Sync storage meaning no changes are required to the Weave Sync registration API to implement.

The P2P Key Exchange protocol is inspired by TextSecure.

'Pros'

  • User only needs to know username and password to register device
  • Secret key is randomly generated
  • Secret key does not leave device
  • Key exchange is implemented using Weave Sync storage and thus is compatible with both Weave Sync v5 and the Weave Sync v6 pairing extension

'Cons'

  • Registering additional devices after the first requires access to an already registered device
  • Performing key exchange within Weave Sync storage may have security ramifications (TBD).

Existing Weave Sync Key Exchange Implementations

Weave Sync v3 (Passphrase)

Weave Sync v3 derives a secret key from a user selected passphrase independent of the account password.

'Pros'

  • Registering additional devices does not require access to an already registered device
  • Secret key does not leave device

'Cons'

  • User needs to know passphrase in addition to username and password to register device
  • Secret key is only as secure as passphrase

Weave Sync v5 (Easy Setup)

Weave Sync v5 generates a secret key on account registration and for additional clients performs key exchange using the Easy Setup protocol based on J-PAKE.

'Pros'

  • User only needs to know username and password to register device
  • Secret key is randomly generated
  • Secret key does not leave device

'Cons'

  • Registering additional devices after the first requires access to an already registered device
  • J-PAKE key exchange requires three round trips and hence both devices must be connected concurrently and with good connectivity

Weave Sync v6 (One Password)

Like v3, Weave Sync v6 derives a secret key from a user selected passphrase, however the onepw protocol uses a single password/passphrase for both authentication and key derivation to address useability issues with v3 caused by maintaining independent passwords/passphrases.

'Pros'

  • User only needs to know username and password to register device
  • Registering additional devices does not require access to an already registered device

'Cons'

  • Secret key is derived from password which is partially known by authentication server
  • Secret key is only as secure as password
  • Registration and authentication protocol significantly more complex

Design

User Stories

  • Information is secure: As a user I want my data to be secure, hence the secret key must be secure
  • Easy to register: As a user I want to be able to register a new device with only the username and password
  • Easy to change key: As a user I want to be able to change the secret key and de-register a device in the case that it has become compromised, i.e. device lost or stolen

Desired Behaviour

1) Register a device using only username and password

2) If verification is required this must be no more than one additional step and involve no more than one additional device

3) A registered device can change the sync key and re-distribute it to other selected devices with minimal actions, i.e. see (2) above.

Implementation

Note for the purposes of describing the technical implementation the term client will be used in place of device and similarly authorised/unauthorised will be used in place of registered/unregistered.

What Needs To Be Done

  • Implement messaging protocol to support sending of messages between both authorised (registered) and unauthorised (unregistered) clients (devices)
  • Implement registration protocol to authorise a new client (device) and exchange the secret key for an existing Weave Sync account
  • Implement key rotation protocol to change the secret key and re-distribute to other authorised (registered) clients (devices)

Messaging Protocol

A bonus of using the 3DHE key exchange is that it naturally abstracts in to a generalised messaging protocol that can be used to send an arbitrary messages encrypted with the session key derived during the 3DHE key exchange. In addition perfect forward secrecy can be achieved using axolotl key ratcheting as used in the Text Secure application. Although this is not implemented at this stage it presents an opportunity to extend functionality to include peer to peer key management that can be shared between multiple devices.

Protocol Sequence

  1. Each client publishes an identity key (AI, BI) and a set of ephemeral keys (AE{1..n}, BE{1..n})
  2. Client A generates a new ephemeral key (AE) and randomly selects one of client B's ephemeral keys (BE). Using 3DHE and a KDF, client A generates the shared secret (S) then sends message including own ephemeral key (AE) and identifier for client B's ephemeral key (X). Body can be encrypted with shared secret.
  3. Client B receives client A's ephemeral key (AE) and identifier for own ephemeral key (BE). Using 3DHE and a KDF, client B generates the shared secret (S) and can then decrypt the message body.
  4. Both client A and client B can now continue to communicate using the shared secret (S) as a session key
           Alice (Client A)                       Eve (Public)     Bob (Client B)

t0         AIs                                    AIp, BIp         BIs
                                                  BE{1..n}p        BE{1..n}s

t1         AIs                                    AIp, BIp                      
           AEs                                    AEp, BEp          
           BIp                                                         
           BEp = BE{X}p, X ∈ {1..n}                                            
           S = KDF(3DHE(AIs, AEs, BIp, BEp))    

t2                                                                 BIs
                                                                   BEs ∈ BE{X}s, X ∈ {1..n}
                                                                   AIp
                                                                   AEp
                                                                   S = KDF(3DHE(BIs, BEs, AIp, AEp))

Message JSON

{
  version:      "version string",
  srcclientid:  "id of sender",
  srckeyid:     "id of sender's ephemeral key",
  srckey:       "sender's ephemeral key (optional after first message, i.e. sequence > 1)",
  dstclientid:  "id of receiver",
  srckeyid:     "id of receiver's ephemeral key",
  sequence:     "sequence of this message in session",
  type:         "message type",
  content:      "message content"
  hmac:         "HMAC of all other message fields"
}

Registration Protocol

TODO

Key Rotation Protocol

TODO