Page MenuHomePhabricator

D11716.diff
No OneTemporary

D11716.diff

diff --git a/native/backup/backup-handler.js b/native/backup/backup-handler.js
--- a/native/backup/backup-handler.js
+++ b/native/backup/backup-handler.js
@@ -3,7 +3,6 @@
import * as React from 'react';
import { isLoggedIn } from 'lib/selectors/user-selectors.js';
-import { accountHasPassword } from 'lib/shared/account-utils.js';
import { commCoreModule } from '../native-modules.js';
import { useSelector } from '../redux/redux-utils.js';
@@ -15,15 +14,12 @@
);
const loggedIn = useSelector(isLoggedIn);
const staffCanSee = useStaffCanSee();
- const isAccountWithPassword = useSelector(state =>
- accountHasPassword(state.currentUserInfo),
- );
const isBackground = useSelector(
state => state.lifecycleState === 'background',
);
React.useEffect(() => {
- if (!staffCanSee || !isAccountWithPassword) {
+ if (!staffCanSee) {
return;
}
@@ -40,13 +36,7 @@
console.log('Error stopping backup handler:', err);
}
}
- }, [
- isBackupEnabled,
- staffCanSee,
- loggedIn,
- isAccountWithPassword,
- isBackground,
- ]);
+ }, [isBackupEnabled, staffCanSee, loggedIn, isBackground]);
return null;
}
diff --git a/native/backup/use-client-backup.js b/native/backup/use-client-backup.js
--- a/native/backup/use-client-backup.js
+++ b/native/backup/use-client-backup.js
@@ -3,6 +3,8 @@
import * as React from 'react';
import { isLoggedIn } from 'lib/selectors/user-selectors.js';
+import { accountHasPassword } from 'lib/shared/account-utils.js';
+import type { SIWEBackupSecrets } from 'lib/types/siwe-types.js';
import { getContentSigningKey } from 'lib/utils/crypto-utils.js';
import { fetchNativeKeychainCredentials } from '../account/native-credentials.js';
@@ -22,11 +24,20 @@
return nativeCredentials.password;
}
+async function getSIWEBackupSecrets(): Promise<SIWEBackupSecrets> {
+ const siweBackupSecrets = await commCoreModule.getSIWEBackupSecrets();
+ if (!siweBackupSecrets) {
+ throw new Error('SIWE backup message and its signature are missing');
+ }
+ return siweBackupSecrets;
+}
+
function useClientBackup(): ClientBackup {
const accessToken = useSelector(state => state.commServicesAccessToken);
const currentUserID = useSelector(
state => state.currentUserInfo && state.currentUserInfo.id,
);
+ const currentUserInfo = useSelector(state => state.currentUserInfo);
const loggedIn = useSelector(isLoggedIn);
const setMockCommServicesAuthMetadata = React.useCallback(async () => {
@@ -50,11 +61,22 @@
console.info('Start uploading backup...');
await setMockCommServicesAuthMetadata();
- const backupSecret = await getBackupSecret();
- await commCoreModule.createNewBackup(backupSecret);
+
+ if (accountHasPassword(currentUserInfo)) {
+ const backupSecret = await getBackupSecret();
+ await commCoreModule.createNewBackup(backupSecret);
+ } else {
+ const { message, signature } = await getSIWEBackupSecrets();
+ await commCoreModule.createNewSIWEBackup(signature, message);
+ }
console.info('Backup uploaded.');
- }, [currentUserID, loggedIn, setMockCommServicesAuthMetadata]);
+ }, [
+ currentUserID,
+ loggedIn,
+ setMockCommServicesAuthMetadata,
+ currentUserInfo,
+ ]);
const restoreBackupProtocol = React.useCallback(async () => {
if (!loggedIn || !currentUserID) {
diff --git a/native/profile/profile-screen.react.js b/native/profile/profile-screen.react.js
--- a/native/profile/profile-screen.react.js
+++ b/native/profile/profile-screen.react.js
@@ -174,7 +174,7 @@
defaultNotifications,
keyserverSelection,
tunnelbrokerMenu;
- const { staffCanSee, isAccountWithPassword } = this.props;
+ const { staffCanSee } = this.props;
if (staffCanSee) {
developerTools = (
<ProfileRow content="Developer tools" onPress={this.onPressDevTools} />
@@ -203,7 +203,7 @@
}
let backupMenu;
- if (staffCanSee && isAccountWithPassword) {
+ if (staffCanSee) {
backupMenu = (
<ProfileRow content="Backup menu" onPress={this.onPressBackupMenu} />
);

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 5, 12:20 AM (13 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2615256
Default Alt Text
D11716.diff (4 KB)

Event Timeline