Services/Sync/P2P Key Exchange And Rotation
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 v1.1 API/v5 Data and the pairing extension of Weave Sync v1.5 API/v5 Data.
Arguable the J-PAKE based key exchange protocol used in Weave Sync v1.1/v5 already achieves this, however as discussed below a significant weakness is that it requires three round trips to complete and thus requires both the new and an already registered client to be online concurrently and with good connectivity. Also Weave Sync v1.1/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 v1.1/v5 and the Weave Sync v1.5/v5 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.
Existing Weave Sync Key Exchange Implementations
Passphrase (v1.1 API/v3 Data)
The Passphrase implementation 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
Easy Setup (v1.1 API/v5 Data)
The Easy Setup implementation generates a secret key on account registration and for additional clients performs key exchange using 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
One Password (v1.5 API/v5 Data)
Like the Passphrase implementation, the One Password (onepw) implementation derives a secret key from a user selected passphrase, however a single password/passphrase is used for both authentication and key derivation to address useability issues with 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 master key for an existing Weave Sync account
- Implement key rotation protocol to change the master key and re-distribute to other authorised (registered) clients (devices)
eXfio Peer v1
Messaging Protocol
Version 1 of the eXfio Peer protocol leverages 3DHE key exchange. A bonus of using 3DHE 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
- Each client publishes an identity key (AI, BI) and a set of ephemeral keys (AE{1..n}, BE{1..n})
- 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.
- 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.
- 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))
EphemeralKey JSON
{ keyid: "id of ephemeral key", key: "ephemeral public key" }
Client JSON
{ version: "version of client record", clientid: "id of client", name: "name of client", key: "identity public key", ekeys: [EphemeralKey1, EphemeralKey2, ..., EphemeralKeyn], status: "indicates if client is authorised, i.e. 'authorised' or 'pending'", authlevel: "will this client accept messages from unauthorised clients, i.e. 'all' indicates all clients, 'authorised' indicates authorised clients only" hmac: "HMAC of all other client fields" }
Message JSON
{ version: "version of message record", 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
IMPORTANT: If the attacker has full access to the storage, i.e. a hostile systems administrator, and knows the password a man-in-the-middle (MITM) attack is possible. At this time there is an implicit (and quite possibly incorrect) assumption that the systems administrator does not know the password. See version 2 of protocol for improved handling of this risk.
When Alice registers a new device with the Weave Sync server the client first checks if there are other authorised clients, if not it initialises the storage, if so it requests authorisation by following the procedure below.
- Client A: Create client record with status of 'pending'
- Client A: Send ClientAuthRequestMessage to existing authorised clients, i.e. Client B, including authcode digest (ClientAuthVerifier)
- Client A: Display authcode to user
- Client B: User enters authcode when prompted to approve and verify request. Alternatively reject request.
- Client B: On authorisation approved send ClientAuthResponseMessage with sync key
- Client B: On authorisation declined send ClientAuthResponseMessage with auth fail code
- Client A: Poll for authorisation response
- Client A: On authorisation approved notify user, verify HMAC of Client B record and update client record status to 'approved'
- Client A: On authorisation declined no action taken
Alice (Client A) Eve (Public) Bob (Client B) t0 AIs AIp, BIp BIs, MK BE{1..n}p BE{1..n}s t1 AIs AIp, BIp BIs, MK AEs AEp, BEp BEs BEp = BE[X]p, X ∈ {1..n} VD SK = KDF(3DHE(AIs, AEs, BIp, BEp)) VC = RANDOM() VD = DIGEST(VC + DIGEST(password)) t2 AIs, MK AIp, BIp BIs, MK AEs AEp, BEp BEs SK SK = KDF(3DHE(BIs, BEs, AIp, AEp)) VD VC = <user input> Verified = (VD == DIGEST(VC + DIGEST(password)))
Notes:
- The authcode is a random alphanumeric string which needs to be entered on the authorising device to verify the authenticity of the request. If the authcode is entered correctly then a man-in-the-middle attack is highly unlikely.
ClientAuthVerifier JSON
{ innersalt: "Salt value for inner hash, i.e. hash(password) salt: "Salt value for outer hash digest: "hash(authcode + hash(password)) }
ClientAuthRequestMessage JSON
{ clientid: "id of client", name: "name of client", auth: ClientAuthVerifier }
ClientAuthResponseMessage JSON
{ clientid: "id of client", name: "name of client", status: "okay|fail", message: "authorisation approved|authorisation rejected", synckey: "Master key for Weave Sync account (required if status 'okay')" }
Key Rotation Protocol
TODO
eXfio Peer v2
Version 2 of the eXfio Peer protocol improves the protection against a man in the middle (MITM) attack, at the expense of a more complex protocol, requiring two round-trips. Importantly the starting assumption is that an adversary has full access to the storage and knows the password, i.e. a hostile systems administrator. Fortunately an elegant means to mitigate against this threat is to use a SCIMP style hash commitment, which results in the adversary having a single opportunity to guess the authcode with a probability of 1.05 x 10-6.
Messaging Protocol v2
By first requiring each party to make a hash commitment an adversary is required to select a public key without knowing the other party’s key. Thus making it very difficult to launch a MITM attack without detection. See #Registration Protocol v2
Protocol Sequence
- Each client publishes an identity key (AI, BI) and a set of ephemeral key digests (AE{1..n}, BE{1..n}d)
- Client A generates a new ephemeral key (AEp) and sends a message to Client B nominating one of client B's ephemeral key digests (BEd).
- Client B receives client A's ephemeral key (AEp) and digest for own ephemeral key (BEd). Using 3DHE and a KDF Client B generates the session key (SK) then sends message including own ephemeral key (BEp) matching digest (BEd). Client B can now encrypt/decrypt the message body with session key.
- Client A receives client B's ephemeral key (BEp). Using 3DHE and a KDF, client A generates the session key (SK). Client A can now encrypt/decrypt the message body with the session key.
Alice (Client A) Eve (Public) Bob (Client B) t0 AIs AIp, BIp BIs BE{1..n}d BE{1..n}s BE{1..n}p t1 AIs AIp, BIp BIs AEs AEp BEs BEd = BE[X]d, X ∈ {1..n} BEd BEp t2 AIs AIp, BIp BIs AEs AEp, BEp BEs SK = KDF(3DHE(AIs, AEs, BIp, BEp)) BEd SK = KDF(3DHE(BIs, BEs, AIp, AEp) t3 AIs AIp, BIp BIs SK SK PT = <message> CT CT = ENCRYPT(PT, SK) PT = DECRYPT(PT)
EphemeralKey JSON
{ keyid: "id of ephemeral key", keydigest: "digest of ephemeral public key" }
Client JSON
{ version: "version of client record", clientid: "id of client", name: "name of client", key: "identity public key", ekeys: [EphemeralKey1, EphemeralKey2, ..., EphemeralKeyn], status: "indicates if client is authorised, i.e. 'authorised' or 'pending'", authlevel: "will this client accept messages from unauthorised clients, i.e. 'all' indicates all clients, 'authorised' indicates authorised clients only" hmac: "HMAC of all other client fields" }
Message JSON
{ version: "version of message record", srcclientid: "id of sender", srckeyid: "id of sender's ephemeral key", dstclientid: "id of receiver", dstkeyid: "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" }
SessionRequestMessage JSON
{ clientid: "id of client", name: "name of client" srckey: "sender's ephemeral key", dstkeydigest: "digest of receiever's ephemeral key" }
SessionVerifier JSON
{ timestamp: "time used as input in to verification" salt: "salt used as input in to verification" }
SessionResponseMessage JSON
{ clientid: "id of client", name: "name of client", status: "okay|fail", message: "ephemeral key okay|ephemeral key mismatch", dstkey: "ephemeral key matching dstkeydigest (if status okay)", auth: SessionVerifier (if status okay) }
Registration Protocol v2
The objective of the registration protocol is for a new device to obtain the master key (sync key) thus allowing it to read and write encrypted data to and from the storage. To maintain the security of the master key the protocol must defend against a man in the middle (MITM) attack from an adversary. Importantly for version 2 of the eXfio Peer protocol the starting assumption is that an adversary has full access to the storage and knows the password, i.e. a hostile systems administrator.
When Alice registers a new device with the Weave Sync server the client first checks if there are other authorised clients, if not it generates a master key (MK) and initialises the storage, if so it requests authorisation by following the procedure below.
- Client A: Authenticate to sync server and create client record with status of 'pending'
- Client A: Send SessionRequestMessage to existing authorised clients, providing an ephemeral key and nominating an ephemeral key digest of other party, i.e. Client B
- Client B: Send SessionResponseMessage including ephemeral key nominated by Client A. Display authcode generated from session key and master key
- Client A: User enters authcode. If session key verified (VCS) then send ClientAuthV2RequestMessage including proof of possessing Client B, i.e. master key component of authcode (VCM)
- Client B: If Client A responds with proof of possessing master key then send ClientAuthV2ResponseMessage including the master key
Finally Alice is notified of registration status and if successful client record is updated with status of 'approved'
Alice (Client A) Eve (Public) Bob (Client B) t0 AIs AIp, BIp BIs, MK BEd BEs BEp t1 AIs AIp, BIp BIs, MK AEs AEp BEs BEd BEp t2 AIs AIp, BIp BIs, MK AEs AEp, BEp BEs BT BEd BT SK = KDF(3DHE(AIs, AEs, BIp, BEp)) SK = KDF(3DHE(BIs, BEs, AIp, AEp) VCS = DIGEST(SK, BT) VCM = DIGEST(MK, BT) t3 AIs AIp, BIp BIs, MK AEs AEp, BEp BEs BT BEd BT SK SK VCS = <user input> VCS VCM = <user input> VCM Verified = (VCS == DIGEST(SK, BT)) VCP + (BEd == DIGEST(BEp)) VCP = VCM t4 AIs, MK AIp, BIp BIs, MK Verified = (VCP == VCM)
Notes:
- The authcode (VCS + VCM) is a digest of the session key and the master key respectively. This code needs to be entered on the device requesting authorisation to verify the user is in possession of an existing authorised device. If the authcode displayed by Client B matches the VCS value generated on Client A and the VCM value returned to Client B then a man-in-the-middle attack is highly unlikely.
ClientAuthV2Verifier JSON
{ proof: "Proof of receiving authcode through out of band channel" }
ClientAuthV2RequestMessage JSON
{ clientid: "id of client", name: "name of client", auth: ClientAuthV2Verifier }
ClientAuthV2ResponseMessage JSON
No change from V1
Key Rotation Protocol v2
TODO