Browse Source

Vault Format 7

Sebastian Stenzel 5 years ago
parent
commit
7de08f52df

+ 21 - 7
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<Vault> 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<Path> accessPoint;
 
-	private Volume volume;
+	private volatile Volume volume;
 
 	@Inject
 	Vault(VaultSettings vaultSettings, Provider<Volume> volumeProvider, @DefaultMountFlags StringBinding defaultMountFlags, AtomicReference<CryptoFileSystem> cryptoFileSystem, ObjectProperty<VaultState> state, VaultStats stats) {
@@ -94,7 +97,7 @@ public class Vault {
 	}
 
 	private CryptoFileSystem unlockCryptoFileSystem(CharSequence passphrase) throws NoSuchFileException, IOException, InvalidPassphraseException, CryptoException {
-		List<FileSystemFlags> flags = new ArrayList<>();
+		Set<FileSystemFlags> 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<Vault> hasState(VaultState state) {
-		return vault -> {
-			return vault.getState() == state;
-		};
+	
+	private static Predicate<Vault> 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);

+ 2 - 2
main/pom.xml

@@ -24,8 +24,8 @@
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 
 		<!-- dependency versions -->
-		<cryptomator.cryptolib.version>1.2.1</cryptomator.cryptolib.version>
-		<cryptomator.cryptofs.version>1.8.7</cryptomator.cryptofs.version>
+		<cryptomator.cryptolib.version>1.2.2</cryptomator.cryptolib.version>
+		<cryptomator.cryptofs.version>1.9.0-beta1</cryptomator.cryptofs.version>
 		<cryptomator.jni.version>2.2.0</cryptomator.jni.version>
 		<cryptomator.fuse.version>1.2.0</cryptomator.fuse.version>
 		<cryptomator.dokany.version>1.1.11</cryptomator.dokany.version>

+ 3 - 1
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) {