Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added checks for system-only DBus #4

Merged
merged 2 commits into from
Jan 27, 2021
Merged

Conversation

Liboicl
Copy link
Contributor

@Liboicl Liboicl commented Dec 29, 2020

I run a Linux distribution that doesn't implement a session DBus, but does have a system-wide DBus. This change simply checks if the DBus connection fails and tries to connect to the system DBus. The ExceptionInInitializerError exception is also thrown by the SecretServiceKeychain because of this. I added that check to notify that it isn't supported.
It fixes this issue for me cryptomator/cryptomator#1479

@CLAassistant
Copy link

CLAassistant commented Dec 29, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@purejava purejava left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the PR on Kubuntu 20.4 and DBus initialization does still work there.
I do not have a Linux without a DBusType.SESSION to test the PR there myself.

DBusConnection conn = null;
try {
conn = DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION);
} catch (RuntimeException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DBusConnection.getConnection throws a DBusException doesn't it? I'd suggest to catch that instead.

Copy link
Contributor Author

@Liboicl Liboicl Dec 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can throw a DBusException on certain errors but in the case of a non-existent session DBus it is only throwing a RuntimeException as per this line
Caused by: java.lang.RuntimeException: Cannot Resolve Session Bus Address
Using a DBusException in place of it results in the same error as before and the catch is never executed. Maybe I should catch both, though?
There may be a better way to check before the exception is thrown... Let me look into it a bit more.

EDIT: I added in a more specific check in the new push and prettied the code up a bit, trying to conform to the other code. I also took out the stack trace output for the missing session DBus, as it isn't necessary when handled correctly. Let me know what your thoughts are on it.

EDIT 2: Sorry to keep editing, but looking at the source for dbus-java it should be throwing a DBusException. I'm not sure why it isn't in this case. I'm going to try to compile it myself and see how it handles.

@@ -18,7 +18,7 @@ public boolean isSupported() {
try (@SuppressWarnings("unused") SimpleCollection keyring = new SimpleCollection()) {
// seems like we're able to access the keyring.
return true;
} catch (IOException | RuntimeException e) {
} catch (IOException | ExceptionInInitializerError | RuntimeException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add the ExceptionInInitializerError here? I think secret-service throws an IOException if something goes wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's based upon the actual code running on my setup. With the Session DBus non-existent it threw an ExceptionInInitializerError upon running, so I just added it to the list so it marks it as not supported. Without that, it crashes similarly to the original issue, but with SecretService in the backtrace.

@Liboicl
Copy link
Contributor Author

Liboicl commented Dec 30, 2020

A follow up on the DBusException. It seems the version used in cryptomator is https://github.com/hypfvieh/dbus-java and for whatever reason, this version throws a RuntimeException instead of a DBusExcepiton when throwing "Cannot Resolve Session Bus Address"

From line 256-258 in org.freedesktop.dbus.connections.impl.DBusConnection
if (!addressfile.exists()) { throw new RuntimeException("Cannot Resolve Session Bus Address"); }

That also means the issue might just be a missing address file or misconfigured dbus for the other user, instead of not having a session dbus, but this pull request should still fix the issue either way.

swiesend added a commit to swiesend/secret-service that referenced this pull request Jan 5, 2021
@swiesend swiesend mentioned this pull request Jan 5, 2021
@swiesend
Copy link
Contributor

swiesend commented Jan 5, 2021

I released the secret-service 1.3.0, which should address this issue.

@Liboicl
Copy link
Contributor Author

Liboicl commented Jan 8, 2021

@swiesend I tested your pull request and it definitely didn't fix the issue on my system. I tried it straight from your repo and with only my changes to KDEWallet, but without checking for the "ExceptionInInitializerError" I still get

14:52:40.708 [JavaFX Application Thread] WARN  o.c.l.k.KDEWalletKeychainAccess - SESSION DBus not found.
Exception in thread "JavaFX Application Thread" java.lang.ExceptionInInitializerError
	at org.cryptomator.linux.keychain.SecretServiceKeychainAccess.isSupported(SecretServiceKeychainAccess.java:19)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:176)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
	at org.cryptomator.common.keychain.KeychainModule.provideSupportedKeychainAccessProviders(KeychainModule.java:30)
	at org.cryptomator.common.keychain.KeychainModule_ProvideSupportedKeychainAccessProvidersFactory.provideSupportedKeychainAccessProviders(KeychainModule_ProvideSupportedKeychainAccessProvidersFactory.java:39)
	at org.cryptomator.common.keychain.KeychainModule_ProvideSupportedKeychainAccessProvidersFactory.get(KeychainModule_ProvideSupportedKeychainAccessProvidersFactory.java:29)
	at org.cryptomator.common.keychain.KeychainModule_ProvideSupportedKeychainAccessProvidersFactory.get(KeychainModule_ProvideSupportedKeychainAccessProvidersFactory.java:11)
	at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
	at org.cryptomator.common.keychain.KeychainModule_ProvideKeychainAccessProviderFactory.get(KeychainModule_ProvideKeychainAccessProviderFactory.java:33)
	at org.cryptomator.common.keychain.KeychainModule_ProvideKeychainAccessProviderFactory.get(KeychainModule_ProvideKeychainAccessProviderFactory.java:12)
	at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
	at org.cryptomator.common.keychain.KeychainManager_Factory.get(KeychainManager_Factory.java:27)
	at org.cryptomator.common.keychain.KeychainManager_Factory.get(KeychainManager_Factory.java:9)
	at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
	at org.cryptomator.ui.mainwindow.VaultDetailLockedController_Factory.get(VaultDetailLockedController_Factory.java:45)
	at org.cryptomator.ui.mainwindow.VaultDetailLockedController_Factory.get(VaultDetailLockedController_Factory.java:13)
	at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
	at org.cryptomator.ui.common.FXMLLoaderFactory.constructController(FXMLLoaderFactory.java:75)
	at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:940)
	at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:982)
	at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:229)
	at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:754)
	at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2808)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2634)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
	at javafx.fxml.FXMLLoader$IncludeElement.constructValue(FXMLLoader.java:1156)
	at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:756)
	at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2808)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2634)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
	at javafx.fxml.FXMLLoader$IncludeElement.constructValue(FXMLLoader.java:1156)
	at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:756)
	at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2808)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2634)
	at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2532)
	at org.cryptomator.ui.common.FXMLLoaderFactory.load(FXMLLoaderFactory.java:46)
	at org.cryptomator.ui.common.FXMLLoaderFactory.createScene(FXMLLoaderFactory.java:60)
	at org.cryptomator.ui.mainwindow.MainWindowModule.provideMainScene(MainWindowModule.java:64)
	at org.cryptomator.ui.mainwindow.MainWindowModule_ProvideMainSceneFactory.provideMainScene(MainWindowModule_ProvideMainSceneFactory.java:36)
	at org.cryptomator.ui.mainwindow.MainWindowModule_ProvideMainSceneFactory.get(MainWindowModule_ProvideMainSceneFactory.java:27)
	at org.cryptomator.ui.mainwindow.MainWindowModule_ProvideMainSceneFactory.get(MainWindowModule_ProvideMainSceneFactory.java:10)
	at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
	at org.cryptomator.ui.mainwindow.MainWindowComponent.showMainWindow(MainWindowComponent.java:28)
	at org.cryptomator.ui.fxapp.FxApplication.lambda$showMainWindow$1(FxApplication.java:107)
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
	at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
	at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
	at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.RuntimeException: Cannot Resolve Session Bus Address
	at org.freedesktop.dbus.connections.impl.DBusConnection.lambda$getConnection$1(DBusConnection.java:257)
	at org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:165)
	at org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:228)
	at org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:184)
	at org.freedesktop.secret.simple.SimpleCollection.<clinit>(SimpleCollection.java:39)
	... 58 more

swiesend added a commit to swiesend/secret-service that referenced this pull request Jan 19, 2021
@infeo
Copy link
Member

infeo commented Jan 27, 2021

I opened an issue in the upstream dbus-java library regarding the RuntimeException:
hypfvieh/dbus-java#128

The next release contains a change such that the static methods do not throw it anymore :D @swiesend @purejava It might be worthwile checking, if that version can be used in your libraries but the maintainer mentions possible breaking changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants