Page MenuHomePhabricator

D11901.diff
No OneTemporary

D11901.diff

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
@@ -33,6 +33,7 @@
import {
composeTunnelbrokerQRAuthMessage,
parseTunnelbrokerQRAuthMessage,
+ signDeviceListUpdate,
} from '../qr-code/qr-code-utils.js';
import { useStyles } from '../themes/colors.js';
import Alert from '../utils/alert.js';
@@ -121,9 +122,8 @@
devices: [...devices, newDeviceID],
timestamp: Date.now(),
};
- await updateDeviceList({
- rawDeviceList: JSON.stringify(newDeviceList),
- });
+ const signedDeviceList = await signDeviceListUpdate(newDeviceList);
+ await updateDeviceList(signedDeviceList);
},
[identityContext],
);
diff --git a/native/qr-code/qr-code-utils.js b/native/qr-code/qr-code-utils.js
--- a/native/qr-code/qr-code-utils.js
+++ b/native/qr-code/qr-code-utils.js
@@ -1,6 +1,10 @@
// @flow
import { hexToUintArray } from 'lib/media/data-utils.js';
+import type {
+ RawDeviceList,
+ SignedDeviceList,
+} from 'lib/types/identity-service-types.js';
import {
peerToPeerMessageTypes,
type QRCodeAuthMessage,
@@ -9,6 +13,8 @@
qrCodeAuthMessagePayloadValidator,
type QRCodeAuthMessagePayload,
} from 'lib/types/tunnelbroker/qr-code-auth-message-types.js';
+import { getConfig } from 'lib/utils/config.js';
+import { getContentSigningKey } from 'lib/utils/crypto-utils.js';
import {
convertBytesToObj,
@@ -52,4 +58,29 @@
return Promise.resolve(payload);
}
-export { composeTunnelbrokerQRAuthMessage, parseTunnelbrokerQRAuthMessage };
+async function signDeviceListUpdate(
+ deviceListPayload: RawDeviceList,
+): Promise<SignedDeviceList> {
+ const deviceID = await getContentSigningKey();
+ const rawDeviceList = JSON.stringify(deviceListPayload);
+
+ // don't sign device list if current device is not a primary one
+ if (deviceListPayload.devices[0] !== deviceID) {
+ return {
+ rawDeviceList,
+ };
+ }
+
+ const { olmAPI } = getConfig();
+ const curPrimarySignature = await olmAPI.signMessage(rawDeviceList);
+ return {
+ rawDeviceList,
+ curPrimarySignature,
+ };
+}
+
+export {
+ composeTunnelbrokerQRAuthMessage,
+ parseTunnelbrokerQRAuthMessage,
+ signDeviceListUpdate,
+};

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 18, 12:41 AM (21 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2532481
Default Alt Text
D11901.diff (2 KB)

Event Timeline