/** * Get all the backups available in the local zip backup directory for the wallet id specified. */ public List<BackupSummary> getLocalZipBackups(WalletId walletId) { createApplicationDataDirectoryIfNotSet(); // Find the wallet root directory for this wallet id File walletRootDirectory = WalletManager.getOrCreateWalletDirectory(applicationDataDirectory, WalletManager.createWalletRoot(walletId)); if (!walletRootDirectory.exists()) { // No directory - no backups return Lists.newArrayList(); } // Find the zip-backups directory containing the local backups File zipBackupsDirectory = new File(walletRootDirectory.getAbsoluteFile() + File.separator + LOCAL_ZIP_BACKUP_DIRECTORY_NAME); return getWalletBackups(walletId, zipBackupsDirectory); }
/** * Perform a cloud zip backup */ private void performCloudZipBackup() { if (rememberedWalletIdForCloudBackup.isPresent() && rememberedPasswordForCloudBackup.isPresent()) { log.debug("Performing a cloud zip backup"); try { BackupManager.INSTANCE.createCloudBackup(rememberedWalletIdForCloudBackup.get(), rememberedPasswordForCloudBackup.get()); // Don't use anything remembered in the past at this point again // (This will miss anything newly remembered whilst the backup is taking place rememberedWalletIdForCloudBackup = Optional.absent(); rememberedPasswordForCloudBackup = Optional.absent(); } catch (IOException ioe) { log.error("Failed to perform cloud backup", ioe); CoreEvents.fireEnvironmentEvent(EnvironmentSummary.newBackupFailed()); } } else { log.debug("Cannot perform cloud backup as no remembered wallet id or password is available"); } }
/** * Perform a local zip backup */ private void performLocalZipBackup() { if (rememberedWalletIdForLocalBackup.isPresent() && rememberedPasswordForLocalBackup.isPresent()) { log.debug("Performing a local zip backup"); try { BackupManager.INSTANCE.createLocalBackup(rememberedWalletIdForLocalBackup.get(), rememberedPasswordForLocalBackup.get()); // Don't use anything remembered in the past at this point again // (This will miss anything newly remembered whilst the backup is taking place rememberedWalletIdForLocalBackup = Optional.absent(); rememberedPasswordForLocalBackup = Optional.absent(); } catch (IOException ioe) { log.error("Failed to perform local backup", ioe); // TODO handle exception (which is thrown inside the main runnable) } } }
/** * Load a zip backup file, copying all the backup files to the appropriate wallet root directory * * @param backupFileToLoad The encrypted backup file to load * @param seedPhrase The seed phrase to use to decrypt the backup file */ public WalletId loadZipBackup(File backupFileToLoad, List<String> seedPhrase) throws IOException { try { SeedPhraseGenerator seedPhraseGenerator = new Bip39SeedPhraseGenerator(); byte[] seed = seedPhraseGenerator.convertToSeed(seedPhrase); KeyParameter seedDerivedAESKey = org.multibit.commons.crypto.AESUtils.createAESKey(seed, WalletManager.scryptSalt()); return loadZipBackup(backupFileToLoad, seedDerivedAESKey); } catch (Exception e) { throw new EncryptedFileReaderWriterException("Cannot read and decrypt the backup file '" + backupFileToLoad.getAbsolutePath() + "'", e); } }
/** * Handles the process of shutting down the current wallet support services */ public void shutdownCurrentWallet(ShutdownEvent.ShutdownType shutdownType) { log.debug("Shutdown current wallet..."); if (!shutdownType.equals(ShutdownEvent.ShutdownType.SWITCH)) { // Hide the UI if not switching shutdownMainView(); } // Provide a graceful shutdown of the relevant core services in the correct order CoreServices.shutdownNow(shutdownType); // Close the current wallet WalletManager.INSTANCE.shutdownNow(shutdownType); // Close the backup manager for the wallet BackupManager.INSTANCE.shutdownNow(); // Close the installation manager InstallationManager.shutdownNow(shutdownType); }
createApplicationDataDirectoryIfNotSet(); thinBackupDirectory(walletId, cloudBackupDirectory.get());
Preconditions.checkNotNull(walletSummary.getWallet(), "'wallet' must be present"); Preconditions.checkNotNull(walletSummary.getWalletId(), "'walletId' must be present"); createApplicationDataDirectoryIfNotSet(); log.debug("Created rolling-backup AES copy successfully as file:\n'{}'", encryptedAESCopy == null ? "" : encryptedAESCopy.getAbsolutePath()); List<File> rollingBackups = getRollingBackups(walletSummary.getWalletId());
/** * Get all the backups available in the cloud backup directory for the wallet id specified. */ public List<BackupSummary> getCloudBackups(WalletId walletId, File cloudBackupDirectory) { return getWalletBackups(walletId, cloudBackupDirectory); }
/** * Perform a rolling backup using the last remembered wallet summary and credentials */ private void performRollingBackup() { if (rememberedWalletSummaryForRollingBackup.isPresent() && rememberedPasswordForRollingBackup.isPresent()) { log.debug("Performing a rolling backup"); try { BackupManager.INSTANCE.createRollingBackup(rememberedWalletSummaryForRollingBackup.get(), rememberedPasswordForRollingBackup.get()); // Don't use anything remembered in the past at this point again // (This will miss anything newly remembered whilst the backup is taking place rememberedWalletSummaryForRollingBackup = Optional.absent(); rememberedPasswordForRollingBackup = Optional.absent(); } catch (IOException ioe) { log.error("Failed to perform rolling backup", ioe); // TODO handle exception (which is thrown inside the main runnable) } } }
/** * @return True if backups are present in the cloud backup location given by the user */ private boolean isCloudBackupPresent() { // Ensure we start from a fresh list backupSummaries.clear(); // Get the cloud backups matching the entered seed try { // If no walletid is set (done with Trezor wallets) then work it out from the entered seed if (!walletId.isPresent()) { EnterSeedPhraseModel restoreWalletEnterSeedPhraseModel = getRestoreWalletEnterSeedPhraseModel(); SeedPhraseGenerator seedGenerator = new Bip39SeedPhraseGenerator(); byte[] seed = seedGenerator.convertToSeed(restoreWalletEnterSeedPhraseModel.getSeedPhrase()); walletId = Optional.of(new WalletId(seed)); } backupSummaries = BackupManager.INSTANCE.getCloudBackups(walletId.get(), new File(getRestoreLocation())); log.debug("There are {} cloud zip backups available", backupSummaries.size()); return !backupSummaries.isEmpty(); } catch (SeedPhraseException spe) { log.error("The seed phrase is incorrect."); return false; } }
/** * @return True if backups are present in the local zip backup location */ private boolean isLocalZipBackupPresent() { // Ensure we start from a fresh list backupSummaries.clear(); // Get the local backups try { // If no walletid is set (done with Trezor wallets) then work it out from the entered seed if (!walletId.isPresent()) { EnterSeedPhraseModel restoreWalletEnterSeedPhraseModel = getRestoreWalletEnterSeedPhraseModel(); if (restoreWalletEnterSeedPhraseModel == null) { // Avoid possible NPE return false; } SeedPhraseGenerator seedGenerator = new Bip39SeedPhraseGenerator(); byte[] seed = seedGenerator.convertToSeed(restoreWalletEnterSeedPhraseModel.getSeedPhrase()); walletId = Optional.of(new WalletId(seed)); } backupSummaries = BackupManager.INSTANCE.getLocalZipBackups(walletId.get()); log.debug("There are {} local zip backups available", backupSummaries.size()); return !backupSummaries.isEmpty(); } catch (SeedPhraseException spe) { log.error("The seed phrase is incorrect."); return false; } }
List<File> rollingBackupFiles = getRollingBackups(walletId);
WalletId loadedWalletId = BackupManager.INSTANCE.loadZipBackup(selectedBackupSummaryModel.getValue().getFile(), backupAESKey);
BackupManager.INSTANCE.shutdownNow();
createApplicationDataDirectoryIfNotSet(); thinBackupDirectory(walletId, localBackupDirectory);
List<BackupSummary> backups = getWalletBackups(walletId, backupDirectory);
try { WalletId loadedWalletId = BackupManager.INSTANCE.loadZipBackup(selectedBackupSummaryModel.getValue().getFile(), seedPhrase);