mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-14 00:31:27 +00:00
don't load masterkey from arbitrary paths
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user