Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3523643
D14060.id46201.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D14060.id46201.diff
View Options
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
@@ -10,10 +10,13 @@
import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
import { useClientBackup } from './use-client-backup.js';
+import { useGetBackupSecretForLoggedInUser } from './use-get-backup-secret.js';
import { commCoreModule } from '../native-modules.js';
import { useSelector } from '../redux/redux-utils.js';
import { useStaffCanSee } from '../utils/staff-utils.js';
+const millisecondsPerDay = 24 * 60 * 60 * 1000;
+
function BackupHandler(): null {
const loggedIn = useSelector(isLoggedIn);
const staffCanSee = useStaffCanSee();
@@ -27,7 +30,9 @@
state => state.backupStore.latestBackupInfo,
);
const dispatchActionPromise = useDispatchActionPromise();
- const { createUserKeysBackup } = useClientBackup();
+ const { createUserKeysBackup, retrieveLatestBackupInfo, getBackupUserKeys } =
+ useClientBackup();
+ const getBackupSecret = useGetBackupSecretForLoggedInUser();
const backupUploadInProgress = React.useRef<boolean>(false);
const [handlerStarted, setHandlerStarted] = React.useState(false);
@@ -72,13 +77,62 @@
staffCanSee,
]);
+ const testUserKeysRestore = React.useCallback(async () => {
+ if (!latestBackupInfo?.backupID) {
+ return;
+ }
+ const {
+ latestBackupInfo: { backupID },
+ userIdentifier,
+ } = await retrieveLatestBackupInfo();
+
+ const backupSecret = await getBackupSecret();
+ const [
+ {
+ backupDataKey: backupDataKeyFromBackup,
+ backupLogDataKey: backupLogDataKeyFromBackup,
+ },
+ {
+ backupID: localBackupID,
+ backupDataKey: localBackupDataKey,
+ backupLogDataKey: localBackupLogDataKey,
+ },
+ ] = await Promise.all([
+ getBackupUserKeys(userIdentifier, backupSecret, backupID),
+ commCoreModule.getQRAuthBackupData(),
+ ]);
+
+ const backupIDCheck =
+ latestBackupInfo.backupID === backupID && backupID === localBackupID;
+ const keysCheck =
+ backupDataKeyFromBackup === localBackupDataKey &&
+ backupLogDataKeyFromBackup === localBackupLogDataKey;
+
+ if (!backupIDCheck || !keysCheck) {
+ throw new Error(
+ '\n' +
+ `backupID: ${backupID}\n` +
+ `latestBackupInfo.backupID: ${latestBackupInfo.backupID}\n` +
+ `localBackupID: ${localBackupID}\n` +
+ `backupDataKeyFromBackup: ${backupDataKeyFromBackup}\n` +
+ `backupLogDataKeyFromBackup: ${backupLogDataKeyFromBackup}\n` +
+ `localBackupDataKey: ${localBackupDataKey}\n` +
+ `localBackupLogDataKey: ${localBackupLogDataKey}\n`,
+ );
+ }
+ }, [
+ getBackupSecret,
+ getBackupUserKeys,
+ latestBackupInfo?.backupID,
+ retrieveLatestBackupInfo,
+ ]);
+
React.useEffect(() => {
if (
!staffCanSee ||
!canPerformBackupOperation ||
!handlerStarted ||
- backupUploadInProgress.current ||
- !!latestBackupInfo
+ backupUploadInProgress.current
) {
return;
}
@@ -91,6 +145,23 @@
return;
}
+ if (latestBackupInfo) {
+ const timestamp = latestBackupInfo.timestamp;
+ // If last upload one less than 24h ago ignore it
+ if (timestamp >= Date.now() - millisecondsPerDay) {
+ backupUploadInProgress.current = false;
+ return;
+ }
+
+ try {
+ await testUserKeysRestore();
+ } catch (err) {
+ const message = getMessageForException(err) ?? 'unknown error';
+ showAlertToStaff('Error restoring User Keys backup', message);
+ console.log('Error restoring User Keys backup:', message);
+ }
+ }
+
try {
const promise = (async () => {
const backupID = await createUserKeysBackup();
@@ -117,6 +188,7 @@
latestBackupInfo,
showAlertToStaff,
staffCanSee,
+ testUserKeysRestore,
]);
return null;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 9:55 AM (4 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2698574
Default Alt Text
D14060.id46201.diff (3 KB)
Attached To
Mode
D14060: [native] add handler for staff to attempt backup restore
Attached
Detach File
Event Timeline
Log In to Comment