Page MenuHomePhabricator

D13965.id.diff
No OneTemporary

D13965.id.diff

diff --git a/lib/types/tunnelbroker/qr-code-auth-message-types.js b/lib/types/tunnelbroker/qr-code-auth-message-types.js
--- a/lib/types/tunnelbroker/qr-code-auth-message-types.js
+++ b/lib/types/tunnelbroker/qr-code-auth-message-types.js
@@ -6,21 +6,37 @@
import { tShape, tString, tUserID } from '../../utils/validation-utils.js';
export const qrCodeAuthMessageTypes = Object.freeze({
+ // sent by primary device
DEVICE_LIST_UPDATE_SUCCESS: 'DeviceListUpdateSuccess',
+ // sent by secondary device
SECONDARY_DEVICE_REGISTRATION_SUCCESS: 'SecondaryDeviceRegistrationSuccess',
- BACKUP_DATA_KEY_MESSAGE: 'BackupDataKeyMessage',
});
+type QRAuthBackupData = {
+ +backupID: string,
+ +backupDataKey: string,
+ +backupLogDataKey: string,
+};
+export const qrAuthBackupDataValidator: TInterface<QRAuthBackupData> =
+ tShape<QRAuthBackupData>({
+ backupID: t.String,
+ backupDataKey: t.String,
+ backupLogDataKey: t.String,
+ });
+
export type DeviceListUpdateSuccess = {
+type: 'DeviceListUpdateSuccess',
+userID: string,
+primaryDeviceID: string,
+ // We don't need `backupData` for the keyserver
+ +backupData: ?QRAuthBackupData,
};
export const deviceListUpdateSuccessValidator: TInterface<DeviceListUpdateSuccess> =
tShape<DeviceListUpdateSuccess>({
type: tString(qrCodeAuthMessageTypes.DEVICE_LIST_UPDATE_SUCCESS),
userID: tUserID,
primaryDeviceID: t.String,
+ backupData: t.maybe(qrAuthBackupDataValidator),
});
export type SecondaryDeviceRegistrationSuccess = {
@@ -33,28 +49,12 @@
requestBackupKeys: t.Boolean,
});
-export type BackupDataKeyMessage = {
- +type: 'BackupDataKeyMessage',
- +backupID: string,
- +backupDataKey: string,
- +backupLogDataKey: string,
-};
-export const backupDataKeyMessageValidator: TInterface<BackupDataKeyMessage> =
- tShape<BackupDataKeyMessage>({
- type: tString(qrCodeAuthMessageTypes.BACKUP_DATA_KEY_MESSAGE),
- backupID: t.String,
- backupDataKey: t.String,
- backupLogDataKey: t.String,
- });
-
export type QRCodeAuthMessagePayload =
| DeviceListUpdateSuccess
- | SecondaryDeviceRegistrationSuccess
- | BackupDataKeyMessage;
+ | SecondaryDeviceRegistrationSuccess;
export const qrCodeAuthMessagePayloadValidator: TUnion<QRCodeAuthMessagePayload> =
t.union([
deviceListUpdateSuccessValidator,
secondaryDeviceRegistrationSuccessValidator,
- backupDataKeyMessageValidator,
]);
diff --git a/native/profile/secondary-device-qr-code-scanner.react.js b/native/profile/secondary-device-qr-code-scanner.react.js
--- a/native/profile/secondary-device-qr-code-scanner.react.js
+++ b/native/profile/secondary-device-qr-code-scanner.react.js
@@ -126,36 +126,11 @@
return;
}
- const [backupSecret, latestBackupInfo] = await Promise.all([
- getBackupSecret(),
- retrieveLatestBackupInfo(),
- ]);
- const backupKeysResponse = await commCoreModule.retrieveBackupKeys(
- backupSecret,
- latestBackupInfo.backupID,
- );
- const backupKeys = assertWithValidator<BackupKeys>(
- JSON.parse(backupKeysResponse),
- backupKeysValidator,
- );
-
- const backupKeyMessage = await composeTunnelbrokerQRAuthMessage(
- encryptionKey,
- {
- type: qrCodeAuthMessageTypes.BACKUP_DATA_KEY_MESSAGE,
- ...backupKeys,
- },
- );
- await tunnelbrokerContext.sendMessageToDevice({
- deviceID: targetDeviceID,
- payload: JSON.stringify(backupKeyMessage),
- });
-
Alert.alert('Device added', 'Device registered successfully', [
{ text: 'OK', onPress: goBack },
]);
},
- [getBackupSecret, goBack, retrieveLatestBackupInfo, tunnelbrokerContext],
+ [goBack],
);
React.useEffect(() => {
@@ -199,10 +174,26 @@
const deviceType = secondaryDeviceType.current;
const sendDeviceListUpdateSuccessMessage = async () => {
+ let backupData = null;
+ if (deviceType !== identityDeviceTypes.KEYSERVER) {
+ const [backupSecret, latestBackupInfo] = await Promise.all([
+ getBackupSecret(),
+ retrieveLatestBackupInfo(),
+ ]);
+ const backupKeysResponse = await commCoreModule.retrieveBackupKeys(
+ backupSecret,
+ latestBackupInfo.backupID,
+ );
+ backupData = assertWithValidator<BackupKeys>(
+ JSON.parse(backupKeysResponse),
+ backupKeysValidator,
+ );
+ }
const message = await composeTunnelbrokerQRAuthMessage(encryptionKey, {
type: qrCodeAuthMessageTypes.DEVICE_LIST_UPDATE_SUCCESS,
userID,
primaryDeviceID,
+ backupData,
});
await tunnelbrokerContext.sendMessageToDevice({
deviceID: targetDeviceID,
@@ -269,9 +260,11 @@
goBack();
}
}, [
+ getBackupSecret,
goBack,
identityContext,
keyserverDeviceID,
+ retrieveLatestBackupInfo,
runDeviceListUpdate,
tunnelbrokerContext,
]);

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 20, 8:01 AM (9 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2543445
Default Alt Text
D13965.id.diff (4 KB)

Event Timeline