Determine path length limitations during unlock

This commit is contained in:
Sebastian Stenzel
2020-04-28 09:48:25 +02:00
parent b1dc983d6b
commit c99e0ea656
3 changed files with 24 additions and 1 deletions
@@ -9,8 +9,10 @@ import com.google.common.base.Strings;
import com.google.common.io.BaseEncoding;
import javafx.beans.Observable;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
@@ -38,6 +40,7 @@ public class VaultSettings {
public static final boolean DEFAULT_USES_INDIVIDUAL_MOUNTPATH = false;
public static final boolean DEFAULT_USES_READONLY_MODE = false;
public static final String DEFAULT_MOUNT_FLAGS = "";
public static final int DEFAULT_PATH_LENGTH_LIMITATION = -1;
private static final Random RNG = new Random();
@@ -51,6 +54,7 @@ public class VaultSettings {
private final StringProperty individualMountPath = new SimpleStringProperty();
private final BooleanProperty usesReadOnlyMode = new SimpleBooleanProperty(DEFAULT_USES_READONLY_MODE);
private final StringProperty mountFlags = new SimpleStringProperty(DEFAULT_MOUNT_FLAGS);
private final IntegerProperty pathLengthLimitation = new SimpleIntegerProperty(DEFAULT_PATH_LENGTH_LIMITATION);
public VaultSettings(String id) {
this.id = Objects.requireNonNull(id);
@@ -59,7 +63,7 @@ public class VaultSettings {
}
Observable[] observables() {
return new Observable[]{path, mountName, winDriveLetter, unlockAfterStartup, revealAfterMount, usesIndividualMountPath, individualMountPath, usesReadOnlyMode, mountFlags};
return new Observable[]{path, mountName, winDriveLetter, unlockAfterStartup, revealAfterMount, usesIndividualMountPath, individualMountPath, usesReadOnlyMode, mountFlags, pathLengthLimitation};
}
private void deriveMountNameFromPath(Path path) {
@@ -146,6 +150,10 @@ public class VaultSettings {
public StringProperty mountFlags() {
return mountFlags;
}
public IntegerProperty pathLengthLimitation() {
return pathLengthLimitation;
}
/* Hashcode/Equals */
@@ -29,6 +29,7 @@ class VaultSettingsJsonAdapter {
out.name("individualMountPath").value(value.individualMountPath().get());
out.name("usesReadOnlyMode").value(value.usesReadOnlyMode().get());
out.name("mountFlags").value(value.mountFlags().get());
out.name("pathLengthLimitation").value(value.pathLengthLimitation().get());
out.endObject();
}
@@ -43,6 +44,7 @@ class VaultSettingsJsonAdapter {
boolean usesIndividualMountPath = VaultSettings.DEFAULT_USES_INDIVIDUAL_MOUNTPATH;
boolean usesReadOnlyMode = VaultSettings.DEFAULT_USES_READONLY_MODE;
String mountFlags = VaultSettings.DEFAULT_MOUNT_FLAGS;
int pathLengthLimitation = VaultSettings.DEFAULT_PATH_LENGTH_LIMITATION;
in.beginObject();
while (in.hasNext()) {
@@ -78,6 +80,9 @@ class VaultSettingsJsonAdapter {
case "mountFlags":
mountFlags = in.nextString();
break;
case "pathLengthLimitation":
pathLengthLimitation = in.nextInt();
break;
default:
LOG.warn("Unsupported vault setting found in JSON: " + name);
in.skipValue();
@@ -96,6 +101,7 @@ class VaultSettingsJsonAdapter {
vaultSettings.individualMountPath().set(individualMountPath);
vaultSettings.usesReadOnlyMode().set(usesReadOnlyMode);
vaultSettings.mountFlags().set(mountFlags);
vaultSettings.pathLengthLimitation().set(pathLengthLimitation);
return vaultSettings;
}
@@ -21,6 +21,7 @@ import org.cryptomator.cryptofs.CryptoFileSystem;
import org.cryptomator.cryptofs.CryptoFileSystemProperties;
import org.cryptomator.cryptofs.CryptoFileSystemProperties.FileSystemFlags;
import org.cryptomator.cryptofs.CryptoFileSystemProvider;
import org.cryptomator.cryptofs.common.FileSystemCapabilityChecker;
import org.cryptomator.cryptolib.api.CryptoException;
import org.cryptomator.cryptolib.api.InvalidPassphraseException;
import org.slf4j.Logger;
@@ -101,10 +102,18 @@ public class Vault {
if (vaultSettings.usesReadOnlyMode().get()) {
flags.add(FileSystemFlags.READONLY);
}
if (vaultSettings.pathLengthLimitation().get() == -1) {
LOG.debug("Determining path length limitations...");
int limit = new FileSystemCapabilityChecker().determineSupportedPathLength(getPath());
vaultSettings.pathLengthLimitation().set(limit);
LOG.info("Storing path length limit of {}", limit);
}
assert vaultSettings.pathLengthLimitation().get() > 0;
CryptoFileSystemProperties fsProps = CryptoFileSystemProperties.cryptoFileSystemProperties() //
.withPassphrase(passphrase) //
.withFlags(flags) //
.withMasterkeyFilename(MASTERKEY_FILENAME) //
.withMaxPathLength(vaultSettings.pathLengthLimitation().get()) //
.build();
return CryptoFileSystemProvider.newFileSystem(getPath(), fsProps);
}