diff --git a/main/keychain/pom.xml b/main/keychain/pom.xml
index 8ae41d506..29471ed1d 100644
--- a/main/keychain/pom.xml
+++ b/main/keychain/pom.xml
@@ -10,6 +10,11 @@
System Keychain Access
+
+ org.cryptomator
+ commons
+
+
org.apache.commons
commons-lang3
diff --git a/main/keychain/src/main/java/org/cryptomator/keychain/WindowsProtectedKeychainAccess.java b/main/keychain/src/main/java/org/cryptomator/keychain/WindowsProtectedKeychainAccess.java
index 57d9cdfa7..ce8c5744d 100644
--- a/main/keychain/src/main/java/org/cryptomator/keychain/WindowsProtectedKeychainAccess.java
+++ b/main/keychain/src/main/java/org/cryptomator/keychain/WindowsProtectedKeychainAccess.java
@@ -5,30 +5,6 @@
*******************************************************************************/
package org.cryptomator.keychain;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.UncheckedIOException;
-import java.io.Writer;
-import java.lang.reflect.Type;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.file.FileSystems;
-import java.nio.file.Files;
-import java.nio.file.NoSuchFileException;
-import java.nio.file.Path;
-import java.nio.file.StandardOpenOption;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-import java.util.UUID;
-
-import javax.inject.Inject;
-
import com.google.common.io.BaseEncoding;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -42,11 +18,36 @@ import com.google.gson.JsonSerializer;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.lang3.SystemUtils;
+import org.cryptomator.common.Environment;
import org.cryptomator.jni.WinDataProtection;
import org.cryptomator.jni.WinFunctions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.inject.Inject;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.UncheckedIOException;
+import java.io.Writer;
+import java.lang.reflect.Type;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
import static java.nio.charset.StandardCharsets.UTF_8;
class WindowsProtectedKeychainAccess implements KeychainAccessStrategy {
@@ -57,24 +58,13 @@ class WindowsProtectedKeychainAccess implements KeychainAccessStrategy {
.disableHtmlEscaping().create();
private final Optional winFunctions;
- private final Path keychainPath;
+ private final List keychainPaths;
private Map keychainEntries;
@Inject
- public WindowsProtectedKeychainAccess(Optional winFunctions) {
+ public WindowsProtectedKeychainAccess(Optional winFunctions, Environment environment) {
this.winFunctions = winFunctions;
- String keychainPathProperty = System.getProperty("cryptomator.keychainPath");
- if (keychainPathProperty == null) {
- LOG.warn("Windows DataProtection module loaded, but no cryptomator.keychainPath property found.");
- }
- if (keychainPathProperty != null) {
- if (keychainPathProperty.startsWith("~/")) {
- keychainPathProperty = SystemUtils.USER_HOME + keychainPathProperty.substring(1);
- }
- this.keychainPath = FileSystems.getDefault().getPath(keychainPathProperty);
- } else {
- this.keychainPath = null;
- }
+ this.keychainPaths = environment.getKeychainPath().collect(Collectors.toList());
}
private WinDataProtection dataProtection() {
@@ -124,7 +114,7 @@ class WindowsProtectedKeychainAccess implements KeychainAccessStrategy {
@Override
public boolean isSupported() {
- return SystemUtils.IS_OS_WINDOWS && winFunctions.isPresent() && keychainPath != null;
+ return SystemUtils.IS_OS_WINDOWS && winFunctions.isPresent() && !keychainPaths.isEmpty();
}
private byte[] generateSalt() {
@@ -138,30 +128,44 @@ class WindowsProtectedKeychainAccess implements KeychainAccessStrategy {
private void loadKeychainEntriesIfNeeded() {
if (keychainEntries == null) {
- loadKeychainEntries();
- }
- assert keychainEntries != null;
- }
-
- private void loadKeychainEntries() {
- Type type = new TypeToken