don't load masterkey from arbitrary paths

This commit is contained in:
Sebastian Stenzel
2026-03-12 09:58:52 +01:00
parent b8413a21a3
commit 8e4bff8c19

View File

@@ -33,6 +33,7 @@ import java.util.concurrent.ExecutionException;
public class MasterkeyFileLoadingStrategy implements KeyLoadingStrategy {
public static final String SCHEME = "masterkeyfile";
public static final String DEFAULT_MASTERKEY_PATH = "masterkey.cryptomator"; // relative to vault.cryptomator
private final Vault vault;
private final MasterkeyFileAccess masterkeyFileAccess;
@@ -63,16 +64,21 @@ public class MasterkeyFileLoadingStrategy implements KeyLoadingStrategy {
public Masterkey loadKey(URI keyId) throws MasterkeyLoadingFailedException {
window.setTitle(resourceBundle.getString("unlock.title").formatted(vault.getDisplayName()));
Preconditions.checkArgument(SCHEME.equalsIgnoreCase(keyId.getScheme()), "Only supports keys with scheme " + SCHEME);
if (!DEFAULT_MASTERKEY_PATH.equals(keyId.getSchemeSpecificPart())) {
LOG.warn("unsupported masterkey path found in vault.cryptomator: {}", keyId.getSchemeSpecificPart());
}
try {
Path filePath = vault.getPath().resolve(keyId.getSchemeSpecificPart());
// determine masterkey file path:
Path filePath = vault.getPath().resolve(DEFAULT_MASTERKEY_PATH);
if (!Files.exists(filePath)) {
filePath = askUserForMasterkeyFilePath();
}
// unlock:
if (passphrase == null) {
askForPassphrase();
}
var masterkey = masterkeyFileAccess.load(filePath, passphrase);
//backup
// backup on successful unlock:
if (filePath.startsWith(vault.getPath())) {
try {
BackupHelper.attemptBackup(filePath);