|
|
**This document is out of date. See https://code.briarproject.org/akwizgran/briar-spec/blob/master/protocols/BQP.md for the current version.**
|
|
|
|
|
|
BQP is a key agreement protocol that establishes an ephemeral symmetric key between a pair of mobile devices equipped with screens and cameras.
|
|
|
|
|
|
Each device displays a QR code containing a commitment to an ephemeral public key and information about how to connect to the device over various short-range transports. The devices scan each other's codes and use the transport information to establish an insecure duplex connection. The devices then exchange public keys matching their commitments over the insecure connection. Each device derives the shared secret from its own private key and the received public key, and a master key is derived from the shared secret. The master key may be used to derive keys for communicating securely over the transport connection.
|
|
|
|
|
|
The initial exchange of QR codes is assumed to be secure against man-in-the-middle attacks because the users can see which devices they are scanning. Man-in-the-middle attacks against the subsequent exchange of public keys over the insecure connection can be detected by comparing the keys to the commitments contained in the QR codes. We assume the adversary can read, modify, delete and insert traffic on all transports at will.
|
|
|
|
|
|
### Notation
|
|
|
|
|
|
We use || to denote concatenation, double quotes to denote an ASCII string, and len(x) to denote the length of x in bytes, represented as a 32-bit integer. All integers in BQP are big-endian.
|
|
|
|
|
|
### Crypto primitives
|
|
|
|
|
|
BQP uses the following cryptographic primitives:
|
|
|
|
|
|
* A cryptographic hash function, H(m)
|
|
|
* A key agreement function, DH(pri, pub), where pri is one party's private key and pub is the other party's public key
|
|
|
* A message authentication code, MAC(k, m)
|
|
|
|
|
|
We use H(m) to define a multi-argument hash function:
|
|
|
|
|
|
* `HASH(x_1, ..., x_n) == H(len(x_1) || x_1 || ... || len(x_n) || x_n)`
|
|
|
|
|
|
We use MAC(k, m) to define a key derivation function:
|
|
|
|
|
|
* `KDF(k, x_1, ..., x_n) == MAC(k, len(x_1) || x_1 || ... || len(x_n) || x_n)`
|
|
|
|
|
|
All hashes are HASH_LEN bytes, all symmetric keys are KEY_LEN bytes, and the output of MAC(k, m) is MAC_LEN bytes. For simplicity we require that HASH_LEN == KEY_LEN == MAC_LEN.
|
|
|
|
|
|
> Implementation note: We propose to use BLAKE2s as the hash function, Curve25519 as the key agreement function, and keyed BLAKE2s as the message authentication code. This gives HASH_LEN = KEY_LEN = MAC_LEN = 32.
|
|
|
|
|
|
### Key generation
|
|
|
|
|
|
Each device starts by generating a fresh ephemeral key pair (pri, pub). The commitment to the public key is the first COMMIT_LEN bytes of HASH("COMMIT", pub). We require that COMMIT_LEN <= HASH_LEN.
|
|
|
|
|
|
> Implementation note: COMMIT_LEN = 16 is sufficient for 128-bit security because the adversary cannot make use of the birthday paradox: a successful man-in-the-middle attack requires a public key with a commitment that matches the victim's commitment, rather than two public keys with commitments that match each other.
|
|
|
|
|
|
### QR codes
|
|
|
|
|
|
Each device creates a QR code with a binary payload, which is encoded using Base32, as defined in [RFC 4648](https://tools.ietf.org/html/rfc4648). The QR code uses alphanumeric mode. The binary payload is a [BDF](BDF) list with three or more elements. The first element is the protocol version (int). The second element is the public key commitment (raw). The remaining elements are transport descriptors.
|
|
|
|
|
|
The protocol version is 1 for the current version of BQP.
|
|
|
|
|
|
### Transport descriptors
|
|
|
|
|
|
A transport descriptor describes how to connect to a device over a short-range transport. Each descriptor is a BDF list with two or more elements. The first element is the transport identifier (int). The remaining elements are the fields of the descriptor.
|
|
|
|
|
|
The following transports have been defined:
|
|
|
|
|
|
**0: Bluetooth** - The device registers a Bluetooth service to accept RFCOMM connections. The service UUID is generated by converting the first 16 bytes of the device's public key commitment into a UUID as specified in section 4.4 of [RFC 4122](https://tools.ietf.org/html/rfc4122). The descriptor contains one field:
|
|
|
|
|
|
* The device's Bluetooth MAC address (raw)
|
|
|
|
|
|
**1: LAN** - The device connects to a local area network and opens a port to accept TCP connections. The descriptor contains two fields:
|
|
|
|
|
|
* The device's link-local or site-local IPv4 or IPv6 address (raw)
|
|
|
* The port number (int)
|
|
|
|
|
|
**2: Wi-Fi** - The device connects to a Wi-Fi network and opens a port to accept TCP connections. The descriptor contains three fields:
|
|
|
|
|
|
* The device's link-local or site-local IPv4 or IPv6 address (raw)
|
|
|
* The port number (int)
|
|
|
* The SSID of the network (string)
|
|
|
|
|
|
**3: Wi-Fi Direct** - The device creates a Wi-Fi Direct legacy mode access point and opens a port to accept TCP connections. The descriptor contains four fields:
|
|
|
|
|
|
* The device's link-local or site-local IPv4 or IPv6 address (raw)
|
|
|
* The port number (int)
|
|
|
* The SSID of the access point (string)
|
|
|
* The password of the access point (string)
|
|
|
|
|
|
New transports may be defined in future without incrementing the protocol version. Devices must ignore any transports they do not recognise.
|
|
|
|
|
|
### Connection establishment
|
|
|
|
|
|
When a device has scanned a QR code it may immediately connect to the other device over any transports supported by both devices, simultaneously or in any order. This may result in one or more transport connections being established by either or both of the devices.
|
|
|
|
|
|
If no connections can be established within CONNECTION_TIMEOUT seconds of scanning the QR code, the device aborts the protocol.
|
|
|
|
|
|
The devices are assigned roles according to the lexicographic order of their public key commitments: the device with the earlier commitment takes the role of Alice, while the device with the later commitment takes the role of Bob. If multiple transport connections are established, Alice decides which connection to use and closes any other connections.
|
|
|
|
|
|
> Implementation note: We propose to use CONNECTION_TIMEOUT = 20 seconds as a reasonable tradeoff between reliability and responsiveness.
|
|
|
|
|
|
### Records
|
|
|
|
|
|
Alice and Bob exchange a series of records over the connection chosen by Alice. Each record starts with a four-byte header with the following format:
|
|
|
|
|
|
* Bits 0-7: Protocol version
|
|
|
* Bits 8-15: Record type
|
|
|
* Bits 16-31: Length of the payload in bytes as a 16-bit integer
|
|
|
|
|
|
The current version of the protocol is 1, which has three record types:
|
|
|
|
|
|
**0: KEY** - The payload consists of the sender's ephemeral public key.
|
|
|
|
|
|
**1: CONFIRM** - The payload consists of a message authentication code.
|
|
|
|
|
|
**2: ABORT** - The payload is empty. When a device receives an ABORT record it responds with an ABORT record (unless it has already sent one) and aborts the protocol.
|
|
|
|
|
|
### Key exchange
|
|
|
|
|
|
Alice begins by sending a KEY record containing her ephemeral public key, pub_a. Bob compares the first COMMIT_LEN bytes of HASH("COMMIT", pub_a) to the commitment in Alice's QR code. If the key does not match the commitment, Bob sends an ABORT record and aborts the protocol.
|
|
|
|
|
|
Bob sends a KEY record containing his ephemeral public key, pub_b. Alice compares the first COMMIT_LEN bytes of HASH("COMMIT", pub_b) to the commitment in Bob's QR code. If the key does not match the commitment, Alice sends an ABORT record and aborts the protocol.
|
|
|
|
|
|
Alice and Bob calculate the shared secret as follows:
|
|
|
|
|
|
* Alice calculates `s = HASH("SHARED_SECRET", DH(pri_a, pub_b), pub_a, pub_b)`
|
|
|
* Bob calculates `s = HASH("SHARED_SECRET", DH(pri_b, pub_a), pub_a, pub_b)`
|
|
|
|
|
|
If the adversary has not modified the KEY records, both devices should calculate the same shared secret.
|
|
|
|
|
|
### Confirmation
|
|
|
|
|
|
Each device knows it has received the correct public key because it has compared the received public key to the commitment in the QR code. However, each device also needs to know that the other device has received the correct public key. To confirm this, both devices derive a confirmation key from the shared secret and use it to calculate two message authentication codes over the binary payloads of the QR codes, q_a and q_b, and the public keys, pub_a and pub_b:
|
|
|
|
|
|
* `ck = KDF(s, "CONFIRMATION_KEY")`
|
|
|
* `sent_a = len(q_a) || q_a || len(pub_a) || pub_a`
|
|
|
* `sent_b = len(q_b) || q_b || len(pub_b) || pub_b`
|
|
|
* `mac_a = MAC(ck, sent_a || sent_b)`
|
|
|
* `mac_b = MAC(ck, sent_b || sent_a)`
|
|
|
|
|
|
Alice sends a CONFIRM record containing mac_a. Bob compares the received mac_a to the mac_a he calculated. If the values do not match, Bob sends an ABORT record and aborts the protocol.
|
|
|
|
|
|
Bob sends a CONFIRM record containing mac_b. Alice compares the received mac_b to the mac_b she calculated. If the values do not match, Alice sends an ABORT record and aborts the protocol.
|
|
|
|
|
|
### Master key derivation
|
|
|
|
|
|
Finally, both devices derive the master key:
|
|
|
|
|
|
* `mk = KDF(s, "MASTER_KEY")`
|
|
|
|
|
|
The master key is retured to the calling application, together with the transport connection and a flag indicating whether the device played the role of Alice or Bob. The application may use the master key and flag to derive encryption and authentication keys for communicating securely over the transport connection. |
|
|
See https://code.briarproject.org/akwizgran/briar-spec/blob/master/protocols/BQP.md for the current version. |
|
|
\ No newline at end of file |