To provide a method to securely copy a user's identity key from a master device to a newly-provisioned secondary device. Note that we do not cover copying an identity key from an existing secondary device to another secondary device.
The process, in general, works as follows:
- The user opens a registration screen on the secondary device which they wish to register, causing it to request a device code from the server.
- The new secondary device displays a QR code for the master device to scan which contains the device code from the server, and a curve25519 public key.
- The user selects "provision a new device" on their master device and scans the QR code. The master device requests a new registration code from the server.
- The master device encrypts its identity key using a shared key derived from the scanned key and one of its own chosing and sends the message to the secondary device (using the destination provided in the scanned QR code).
- The secondary device registers itself with the server using the provided registration code and identity key.
- Becasue an attacker who is standing behind the secondary device during registration could register the device on their own number, the secondary device must confirm the phone number provided by the master device.
- The secondary device opens a new channel for DeviceControl messages with the master device and all other existing devices.
- The devices continue to use this session to exchange control messages, including sharing sent messages and providing the secondary device(s) with messages received over the SMS channel (either encrypted or unencrypted).
-
GET /v1/devices/setup_code is added for this purpose. This returns a UUID which can be used as the user in a {basic_auth} header (with a password of "temp"). This auth token may be used to register on a websocket and receive messages, but it may not be used for any other purpose. The secondary device should open a listening websocket before proceeding to step 2.
-
The QR code should contain a link to textsecure-device-init:{setup_code UUID}/{ephemeral curve25519 public key}.
-
GET /v1/devices/provisioning_code already exists for this purpose (and may be extended to use codes longer than 6 digits).
-
The master device creates a new ephemeral curve25519 key and calculates a shared secret (using ECDH) between it and the scanned key. It then calculates an AES and MAC key by using the standard TextSecure HKDF function with the shared secret as the input, the master device's public key as the salt, and the info string set to 'WhisperDeviceInit'. It uses these keys to encrypt an IdentityKey message (using AES-CBC, below) and sends it, prepended with the constant version byte 1, the AES IV, and a full 32-byte HMAC256(version byte 1 + IV + encrypted data), as the identityKeyMessage field in a DeviceInit message (below).
message DeviceInit { required bytes masterEphemeralKey = 1; required bytes identityKeyMessage = 2; }
message IdentityKey { required bytes identityKey = 1; required string number = 2; required boolean masterSupportsSms = 3; // XXX: boolean is a protobuf type? required uint32 provisioningCode = 3; }
-
PUT /v1/devices/{provisioning_code}, and PUT /v1/keys already exist for this purpose.
-
The secondary device should hold the websocket created in step 1 until after this step completes.
-
- GET /v1/keys/{number}/* should return the keys required (the implementor may wish to make this call before the PUT /v1/keys in step 5 to avoid retreiving their own key).
- PUT /v1/messages/{destination} is changed to allow a message to be sent to a specific device (ie it will never return 409) if the sender is on the same account.
- New messages can be sent between devices with IncomingPushMessageSignal.Type (and the equivalent message type in /v1/messages/) set to PREKEY_BUNDLE_DEVICE_CONTROL = 5 indicating a standard PreKeyWhisperMessage containing a WhisperMessage with the ciphertext set to an encrypted copy of a DeviceControl message of type NEW_DEVICE_REGISTERED (below).
-
IncomingPushMessageSignal.Type (and the equivalent message type in /v1/messages/) may also be set to DEVICE_CONTROL = 6 indicating a WhisperMessage with a ciphertext set to an encrypted copy of a DeviceControl message (below). This allows the devices to send the following messages:
- OUTSIDE_TRANSPORT_RECEIVED_MESSAGE may be sent from the master device and must be sent to all other devices. It indicates to the secondary devices that a message was received over the SMS/MMS channel. If that message was encrypted, it must be decrypted before being relayed to secondary devices (using the original AttachmentPointer iff that attachment will be available to secondary devices using the same id which is present in the message, otherwise new AttachmentPointers must be created to share attachments with the secondary devices).
- SENT_MESSAGE may be sent from any device and must be sent to all other devices. It indicates the successful sending of a message over the specified channel.
- SEND_MESSAGE may be sent from any secondary device to the master device. It requests that the master device forward the given message over the SMS/MMS channel (possibly unencrypted over the wire). After receipt of the message, the master should respond with either a SENT_MESSAGE with the same contents (as it should forward the same SENT_MESSAGE to ALL secondary devices, including the originator) or a SEND_MESSAGE_FAILED.
- SEND_MESSAGE_FAILED may be sent from the master device to a single secondary device in response to a SEND_MESSAGE message. Its messageId field should be set to the same value as was set in the SEND_MESSAGE it received and indicates that the message failed to send. The reason field should be set to a short (less than 80 characters), human readable reason why the message could not be delivered, such as "Outgoing SMS not allowed".
message DeviceControl {
enum Type {
UNKNOWN = 0;
NEW_DEVICE_REGISTERED = 1; // Requries only newDeviceId
SENT_MESSAGE = 2; // Requires only message
SEND_MESSAGE = 3; // Requires both message and messageId
SEND_MESSAGE_FAILED = 4; // Requires only messageId
OUTSIDE_TRANSPORT_RECEIVED_MESSAGE = 5; // Requires only message
}
message MessageSentReceived {
enum RelayType {
PUSH = 1; // Indicates the message was already sent
SMS_MMS = 2; // Indicates the message was sent/received by the master,
// or that the master device needs to send the message
}
required string otherNumber = 1; // The source/destination account (ie phone #), not device
required RelayType relay = 2; // The relay used to send (always SMS_MMS for OUTSIDE_TRANSPORT_RECEIVED_MESSAGE/SEND_MESSAGE)
required uint64 timestamp = 3;
optional uint32 messageId = 4; // Only required for SEND_MESSAGE
required PushMessageContent message = 5;
}
message SendMessageFailed {
required uint32 messageId = 1;
required string reason = 2;
}
required Type type = 1;
optional uint32 newDeviceId = 2;
optional MessageSentReceived message = 3;
optional SendMessageFailed sendFailed = 4;
}
Reason why I still included SEND_MESSAGE/SMS stuff in here: Though it is tricky to enable across the board, I think its inclusion represents a feature that merits some complaints over its implementation. I know we have a very vocal community that will, no doubt, have a fun time commenting on the UI surrounding this feature, but I think we can minimize the user complaints and questions here. It seems wrong to me to limit our featureset because we're afraid of getting complaints from other developers (and, yes, I'll gladly help comment on those pulls/emails/etc if y'all forward them this way). I think the UI should (obviously) clearly state that SMS relay will ONLY work when the master device is on (my thought would be a checkbox in the secondary device options that says "Enable sending SMS/MMS messages to non-TextSecure users by relaying them through your phone. Note that this will only work when your phone is on, connected to the network, and TextSecure is set on your phone to allow outgoing SMS/MMS messages." Note that I'm not sure if we need a UI flag to allow relay in the Android side (I vote no) as it simplifies the whole thing. Implementation-wise, I dont think this feature is hard to add, and if it is a source of a lot of user complaints, hiding the checkbox so that users have to know where to go to enable the SMS relay may be a good option (how many users check out the options page for their browser extensions now, anyway?).
Why do we need an ACK here?
I would prefer to immediately tear this one-off session down.
I'd ideally like to maintain some consistency here. One possibility would be to have PUT /v1/messages/{destination} remain the same, with the one tweak that the source device can be omitted from the list of destination devices if source = destination.
I'd prefer not to put this in the IncomingPushMessage "type." That field is only for values that can not be opaque, for instance values that a receiving client needs in order to determine how to decrypt the message. These seem like values that could be within an encrypted message.
My sense is that we should just leave SMS out of this. If I receive an incoming SMS message on my desktop, I can't reply to it anyway. Also, it'd be way simpler if the only thing we ever had to deliver to provisioned devices was outgoing messages.