From 7de08f52dfed297da94761b9fe314c1ec9ef31dc Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Fri, 6 Sep 2019 10:21:37 +0200 Subject: [PATCH] Vault Format 7 --- .../org/cryptomator/common/vaults/Vault.java | 28 ++++++++++++++----- main/pom.xml | 4 +-- .../controllers/ChangePasswordController.java | 4 ++- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java b/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java index 58581ce07..56e889c44 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java @@ -41,14 +41,17 @@ import java.nio.file.NotDirectoryException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; import java.util.Objects; +import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; @PerVault public class Vault { + @Deprecated(forRemoval = true, since = "1.5.0") public static final Predicate NOT_LOCKED = hasState(VaultState.LOCKED).negate(); private static final Logger LOG = LoggerFactory.getLogger(Vault.class); private static final String MASTERKEY_FILENAME = "masterkey.cryptomator"; @@ -67,7 +70,7 @@ public class Vault { private final BooleanBinding unlocked; private final ObjectBinding accessPoint; - private Volume volume; + private volatile Volume volume; @Inject Vault(VaultSettings vaultSettings, Provider volumeProvider, @DefaultMountFlags StringBinding defaultMountFlags, AtomicReference cryptoFileSystem, ObjectProperty state, VaultStats stats) { @@ -94,7 +97,7 @@ public class Vault { } private CryptoFileSystem unlockCryptoFileSystem(CharSequence passphrase) throws NoSuchFileException, IOException, InvalidPassphraseException, CryptoException { - List flags = new ArrayList<>(); + Set flags = EnumSet.noneOf(FileSystemFlags.class); if (vaultSettings.usesReadOnlyMode().get()) { flags.add(FileSystemFlags.READONLY); } @@ -106,6 +109,7 @@ public class Vault { return CryptoFileSystemProvider.newFileSystem(getPath(), fsProps); } + @Deprecated(forRemoval = true, since = "1.5.0") public void create(CharSequence passphrase) throws IOException { if (!isValidVaultDirectory()) { CryptoFileSystemProvider.initialize(getPath(), MASTERKEY_FILENAME, passphrase); @@ -114,6 +118,7 @@ public class Vault { } } + @Deprecated(forRemoval = true, since = "1.5.0") public void changePassphrase(CharSequence oldPassphrase, CharSequence newPassphrase) throws IOException, InvalidPassphraseException { CryptoFileSystemProvider.changePassphrase(getPath(), MASTERKEY_FILENAME, oldPassphrase, newPassphrase); } @@ -146,6 +151,7 @@ public class Vault { /** * Ejects any mounted drives and locks this vault. no-op if this vault is currently locked. */ + @Deprecated(forRemoval = true, since = "1.5.0") public void prepareForShutdown() { try { lock(false); @@ -165,11 +171,9 @@ public class Vault { public void reveal() throws Volume.VolumeException { volume.reveal(); } - - public static Predicate hasState(VaultState state) { - return vault -> { - return vault.getState() == state; - }; + + private static Predicate hasState(VaultState state) { + return vault -> vault.getState() == state; } // ****************************************************************************** @@ -295,14 +299,17 @@ public class Vault { return EasyBind.map(vaultSettings.path(), Path::getFileName).map(Path::toString); } + @Deprecated(forRemoval = true, since = "1.5.0") public boolean doesVaultDirectoryExist() { return Files.isDirectory(getPath()); } + @Deprecated(forRemoval = true, since = "1.5.0") public boolean isValidVaultDirectory() { return CryptoFileSystemProvider.containsVault(getPath(), MASTERKEY_FILENAME); } + @Deprecated(forRemoval = true, since = "1.5.0") public long pollBytesRead() { CryptoFileSystem fs = cryptoFileSystem.get(); if (fs != null) { @@ -312,6 +319,7 @@ public class Vault { } } + @Deprecated(forRemoval = true, since = "1.5.0") public long pollBytesWritten() { CryptoFileSystem fs = cryptoFileSystem.get(); if (fs != null) { @@ -321,18 +329,22 @@ public class Vault { } } + @Deprecated(forRemoval = true, since = "1.5.0") public String getCustomMountPath() { return vaultSettings.individualMountPath().getValueSafe(); } + @Deprecated(forRemoval = true, since = "1.5.0") public void setCustomMountPath(String mountPath) { vaultSettings.individualMountPath().set(mountPath); } + @Deprecated(forRemoval = true, since = "1.5.0") public String getMountName() { return vaultSettings.mountName().get(); } + @Deprecated(forRemoval = true, since = "1.5.0") public void setMountName(String mountName) throws IllegalArgumentException { if (StringUtils.isBlank(mountName)) { throw new IllegalArgumentException("mount name is empty"); @@ -366,6 +378,7 @@ public class Vault { vaultSettings.mountFlags().set(mountFlags); } + @Deprecated(forRemoval = true, since = "1.5.0") public Character getWinDriveLetter() { if (vaultSettings.winDriveLetter().get() == null) { return null; @@ -374,6 +387,7 @@ public class Vault { } } + @Deprecated(forRemoval = true, since = "1.5.0") public void setWinDriveLetter(Path root) { if (root == null) { vaultSettings.winDriveLetter().set(null); diff --git a/main/pom.xml b/main/pom.xml index 2a9f53aad..3b97c73f3 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -24,8 +24,8 @@ UTF-8 - 1.2.1 - 1.8.7 + 1.2.2 + 1.9.0-beta1 2.2.0 1.2.0 1.1.11 diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/ChangePasswordController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/ChangePasswordController.java index f766a5078..eb1ad1614 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/ChangePasswordController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/ChangePasswordController.java @@ -23,6 +23,7 @@ import javafx.scene.control.Label; import javafx.scene.layout.GridPane; import javafx.scene.layout.Region; import javafx.scene.text.Text; +import org.cryptomator.cryptofs.CryptoFileSystemProvider; import org.cryptomator.cryptolib.api.InvalidPassphraseException; import org.cryptomator.cryptolib.api.UnsupportedVaultFormatException; import org.cryptomator.ui.controls.SecurePasswordField; @@ -42,6 +43,7 @@ import java.util.Optional; public class ChangePasswordController implements ViewController { private static final Logger LOG = LoggerFactory.getLogger(ChangePasswordController.class); + private static final String MASTERKEY_FILENAME = "masterkey.cryptomator"; private final Application app; private final PasswordStrengthUtil strengthRater; @@ -153,7 +155,7 @@ public class ChangePasswordController implements ViewController { private void didClickChangePasswordButton(ActionEvent event) { downloadsPageLink.setVisible(false); try { - vault.changePassphrase(oldPasswordField.getCharacters(), newPasswordField.getCharacters()); + CryptoFileSystemProvider.changePassphrase(vault.getPath(), MASTERKEY_FILENAME, oldPasswordField.getCharacters(), newPasswordField.getCharacters()); messageText.setText(null); listener.ifPresent(this::invokeListenerLater); } catch (InvalidPassphraseException e) {