Sebastian Stenzel 5 anni fa
parent
commit
c13449c6ad

+ 1 - 1
main/keychain/src/main/java/org/cryptomator/keychain/KeychainAccessStrategy.java

@@ -29,7 +29,7 @@ interface KeychainAccessStrategy {
 	void deletePassphrase(String key) throws KeychainAccessException;
 
 	/**
-	 * Updates a passphrase with a given key.
+	 * Updates a passphrase with a given key. Noop, if there is no item for the given key.
 	 *
 	 * @param key Unique key previously used while {@link #storePassphrase(String, CharSequence) storing a passphrase}.
 	 * @param passphrase The secret to be updated in this keychain.

+ 4 - 2
main/keychain/src/main/java/org/cryptomator/keychain/MacSystemKeychainAccess.java

@@ -49,8 +49,10 @@ class MacSystemKeychainAccess implements KeychainAccessStrategy {
 	}
 
 	@Override
-	public void changePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
-		storePassphrase(key, passphrase);
+	public void changePassphrase(String key, CharSequence passphrase) {
+		if (keychain().deletePassword(key)) {
+			keychain().storePassword(key, passphrase);
+		}
 	}
 
 }

+ 5 - 2
main/keychain/src/main/java/org/cryptomator/keychain/WindowsProtectedKeychainAccess.java

@@ -115,8 +115,11 @@ class WindowsProtectedKeychainAccess implements KeychainAccessStrategy {
 	}
 
 	@Override
-	public void changePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
-		storePassphrase(key, passphrase);
+	public void changePassphrase(String key, CharSequence passphrase) {
+		loadKeychainEntriesIfNeeded();
+		if (keychainEntries.remove(key) != null) {
+			storePassphrase(key, passphrase);
+		}
 	}
 
 	@Override