|
@@ -1,47 +1,47 @@
|
|
|
package org.cryptomator.ui.health;
|
|
|
|
|
|
+import com.google.common.base.Preconditions;
|
|
|
+import org.cryptomator.common.vaults.Vault;
|
|
|
import org.cryptomator.cryptofs.VaultConfig;
|
|
|
import org.cryptomator.cryptofs.health.api.DiagnosticResult;
|
|
|
import org.cryptomator.cryptolib.api.Masterkey;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
|
+import javax.inject.Inject;
|
|
|
import javafx.scene.control.Alert;
|
|
|
import java.nio.file.Path;
|
|
|
import java.security.SecureRandom;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
-class DiagnosticResultAction implements Runnable {
|
|
|
+@HealthCheckScoped
|
|
|
+class ResultFixApplier {
|
|
|
+
|
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(ResultFixApplier.class);
|
|
|
|
|
|
- private final DiagnosticResult result;
|
|
|
private final Path vaultPath;
|
|
|
- private final VaultConfig vaultConfig;
|
|
|
- private final Masterkey masterkey;
|
|
|
private final SecureRandom csprng;
|
|
|
+ private final Masterkey masterkey;
|
|
|
+ private final VaultConfig vaultConfig;
|
|
|
|
|
|
- DiagnosticResultAction(DiagnosticResult result, Path vaultPath, VaultConfig vaultConfig, Masterkey masterkey, SecureRandom csprng) {
|
|
|
- this.result = result;
|
|
|
- this.vaultPath = vaultPath;
|
|
|
- this.vaultConfig = vaultConfig;
|
|
|
- this.masterkey = masterkey;
|
|
|
+ @Inject
|
|
|
+ public ResultFixApplier(@HealthCheckWindow Vault vault, AtomicReference<Masterkey> masterkeyRef, AtomicReference<VaultConfig> vaultConfigRef, SecureRandom csprng) {
|
|
|
+ this.vaultPath = vault.getPath();
|
|
|
+ this.masterkey = masterkeyRef.get();
|
|
|
+ this.vaultConfig = vaultConfigRef.get();
|
|
|
this.csprng = csprng;
|
|
|
}
|
|
|
|
|
|
- public void run() {
|
|
|
+ public void fix(DiagnosticResult result) {
|
|
|
+ Preconditions.checkArgument(result.getServerity() == DiagnosticResult.Severity.WARN, "Unfixable result");
|
|
|
try (var masterkeyClone = masterkey.clone();
|
|
|
var cryptor = vaultConfig.getCipherCombo().getCryptorProvider(csprng).withKey(masterkeyClone)) {
|
|
|
result.fix(vaultPath, vaultConfig, masterkeyClone, cryptor);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ LOG.error("Failed to apply fix", e);
|
|
|
Alert alert = new Alert(Alert.AlertType.ERROR, e.getMessage());
|
|
|
alert.showAndWait();
|
|
|
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- public DiagnosticResult.Severity getSeverity() {
|
|
|
- return result.getServerity();
|
|
|
- }
|
|
|
-
|
|
|
- public String getDescription() {
|
|
|
- return result.toString();
|
|
|
- }
|
|
|
-
|
|
|
}
|