Merge pull request #1346 from purejava/fix-isSupported

Evade DBusException
This commit is contained in:
Armin Schrenk
2020-10-21 10:56:16 +02:00
committed by GitHub
3 changed files with 21 additions and 16 deletions

View File

@@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory;
public class LinuxKDEWalletKeychainAccessImpl implements KeychainAccessStrategy {
private final Logger log = LoggerFactory.getLogger(LinuxKDEWalletKeychainAccessImpl.class);
private static final Logger LOG = LoggerFactory.getLogger(LinuxKDEWalletKeychainAccessImpl.class);
private final String FOLDER_NAME = "Cryptomator";
private final String APP_NAME = "Cryptomator";
@@ -18,11 +18,12 @@ public class LinuxKDEWalletKeychainAccessImpl implements KeychainAccessStrategy
private KDEWallet wallet;
private int handle = -1;
public LinuxKDEWalletKeychainAccessImpl() {
public LinuxKDEWalletKeychainAccessImpl() throws KeychainAccessException {
try {
connection = DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION);
} catch (DBusException e) {
e.printStackTrace();
LOG.error("Connecting to D-Bus failed:", e);
throw new KeychainAccessException(e);
}
}
@@ -32,7 +33,7 @@ public class LinuxKDEWalletKeychainAccessImpl implements KeychainAccessStrategy
wallet = new KDEWallet(connection);
return wallet.isEnabled();
} catch (Exception e) {
e.printStackTrace();
LOG.error("A KDEWallet could not be created:", e);
return false;
}
}
@@ -44,12 +45,12 @@ public class LinuxKDEWalletKeychainAccessImpl implements KeychainAccessStrategy
!(wallet.hasEntry(handle, FOLDER_NAME, key, APP_NAME)
&& wallet.entryType(handle, FOLDER_NAME, key, APP_NAME) == 1)
&& wallet.writePassword(handle, FOLDER_NAME, key, passphrase.toString(), APP_NAME) == 0) {
log.debug("Passphrase successfully stored.");
LOG.debug("Passphrase successfully stored.");
} else {
log.debug("Passphrase was not stored.");
LOG.debug("Passphrase was not stored.");
}
} catch (Exception e) {
log.error(e.toString(), e.getCause());
LOG.error("Storing the passphrase failed:", e);
throw new KeychainAccessException(e);
}
}
@@ -60,12 +61,13 @@ public class LinuxKDEWalletKeychainAccessImpl implements KeychainAccessStrategy
try {
if (walletIsOpen()) {
password = wallet.readPassword(handle, FOLDER_NAME, key, APP_NAME);
log.debug("loadPassphrase: wallet is open.");
LOG.debug("loadPassphrase: wallet is open.");
} else {
log.debug("loadPassphrase: wallet is closed.");
LOG.debug("loadPassphrase: wallet is closed.");
}
return (password.equals("")) ? null : password.toCharArray();
} catch (Exception e) {
LOG.error("Loading the passphrase failed:", e);
throw new KeychainAccessException(e);
}
}
@@ -77,11 +79,12 @@ public class LinuxKDEWalletKeychainAccessImpl implements KeychainAccessStrategy
&& wallet.hasEntry(handle, FOLDER_NAME, key, APP_NAME)
&& wallet.entryType(handle, FOLDER_NAME, key, APP_NAME) == 1
&& wallet.removeEntry(handle, FOLDER_NAME, key, APP_NAME) == 0) {
log.debug("Passphrase successfully deleted.");
LOG.debug("Passphrase successfully deleted.");
} else {
log.debug("Passphrase was not deleted.");
LOG.debug("Passphrase was not deleted.");
}
} catch (Exception e) {
LOG.error("Deleting the passphrase failed:", e);
throw new KeychainAccessException(e);
}
}
@@ -93,11 +96,12 @@ public class LinuxKDEWalletKeychainAccessImpl implements KeychainAccessStrategy
&& wallet.hasEntry(handle, FOLDER_NAME, key, APP_NAME)
&& wallet.entryType(handle, FOLDER_NAME, key, APP_NAME) == 1
&& wallet.writePassword(handle, FOLDER_NAME, key, passphrase.toString(), APP_NAME) == 0) {
log.debug("Passphrase successfully changed.");
LOG.debug("Passphrase successfully changed.");
} else {
log.debug("Passphrase could not be changed.");
LOG.debug("Passphrase could not be changed.");
}
} catch (Exception e) {
LOG.error("Changing the passphrase failed:", e);
throw new KeychainAccessException(e);
}
}
@@ -112,9 +116,10 @@ public class LinuxKDEWalletKeychainAccessImpl implements KeychainAccessStrategy
wallet.openAsync(Static.DEFAULT_WALLET, 0, APP_NAME, false);
wallet.getSignalHandler().await(KWallet.walletAsyncOpened.class, Static.ObjectPaths.KWALLETD5, () -> null);
handle = wallet.getSignalHandler().getLastHandledSignal(KWallet.walletAsyncOpened.class, Static.ObjectPaths.KWALLETD5).handle;
log.debug("Wallet successfully initialized.");
LOG.debug("Wallet successfully initialized.");
return handle != -1;
} catch (Exception e) {
LOG.error("Asynchronous opening the wallet failed:", e);
throw new KeychainAccessException(e);
}
}

View File

@@ -34,7 +34,7 @@
<javafx.version>14</javafx.version>
<commons-lang3.version>3.11</commons-lang3.version>
<secret-service.version>1.1.0</secret-service.version>
<kdewallet.version>1.0.1</kdewallet.version>
<kdewallet.version>1.1.1</kdewallet.version>
<jwt.version>3.10.3</jwt.version>
<easybind.version>2.1.0</easybind.version>
<guava.version>29.0-jre</guava.version>

View File

@@ -82,7 +82,7 @@ Cryptomator uses 53 third-party dependencies under the following licenses:
- zxcvbn4j (com.nulab-inc:zxcvbn:1.3.0 - https://github.com/nulab/zxcvbn4j)
- secret-service (de.swiesend:secret-service:1.1.0 - https://github.com/swiesend/secret-service)
- Checker Qual (org.checkerframework:checker-qual:2.11.1 - https://checkerframework.org)
- kdewallet (org.purejava:kdewallet:1.0.1 - https://github.com/purejava/kdewallet)
- kdewallet (org.purejava:kdewallet:1.1.1 - https://github.com/purejava/kdewallet)
- SLF4J API Module (org.slf4j:slf4j-api:1.7.30 - http://www.slf4j.org)
The BSD 2-Clause License:
- EasyBind (com.tobiasdiez:easybind:2.1.0 - https://github.com/tobiasdiez/EasyBind)