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

NullPointerException on systems without gnome-keyring installed or login as default collection #6

Closed
swiesend opened this issue Aug 14, 2019 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@swiesend
Copy link
Owner

On systems without gnome-keyring installed the secret-service can't find any default collection /org/freedesktop/secrets/collection/login.

This problem relates to Cryptomator #950.

cryptomator0.log

18:31:24.707 [JavaFX Application Thread] ERROR o.f.secret.handlers.MessageHandler - org.freedesktop.dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownMethod: Keine derartige Schnittstelle »org.freedesktop.DBus.Properties« des Objekts im Pfad /org/freedesktop/secrets/collection/login
....
Caused by: java.lang.NullPointerException: null
	at org.freedesktop.secret.handlers.MessageHandler.getProperty(MessageHandler.java:72)
	at org.freedesktop.secret.handlers.Messaging.getProperty(Messaging.java:41)
	at org.freedesktop.secret.Collection.isLocked(Collection.java:86)
	at org.freedesktop.secret.simple.SimpleCollection.unlock(SimpleCollection.java:174)
	at org.freedesktop.secret.simple.SimpleCollection.<init>(SimpleCollection.java:47)

Suggested solution

MessageHandler.send() should not return null, but preferably raise an Exception. The high low and level API should be adapted to handle this, where the high level API may return Optionals where returning a type or pass through any Exception as IOException when not returning anything.

public Object[] send(String service, String path, String iface, String method, String signature, Object... args) {
try {
org.freedesktop.dbus.messages.Message message = new MethodCall(
service,
path,
iface,
method, (byte) 0, signature, args);
connection.sendMessage(message);
org.freedesktop.dbus.messages.Message response = ((MethodCall) message).getReply(2000L);
log.trace(response.toString());
if (response instanceof org.freedesktop.dbus.errors.Error) {
switch (response.getName()) {
case "org.freedesktop.Secret.Error.NoSession":
throw new NoSession((String) response.getParameters()[0]);
case "org.freedesktop.Secret.Error.NoSuchObject":
throw new NoSuchObject((String) response.getParameters()[0]);
case "org.freedesktop.Secret.Error.IsLocked":
throw new IsLocked((String) response.getParameters()[0]);
default:
throw new DBusException(response.getName() + ": " + response.getParameters()[0]);
}
}
Object[] parameters = response.getParameters();
log.debug(Arrays.deepToString(parameters));
return parameters;
} catch (NoSession | NoSuchObject | IsLocked | DBusException e) {
log.error(e.toString(), e.getCause());
}
return null;
}

@swiesend
Copy link
Owner Author

The MessageHandler is updated and does not consume connection problems. Instead it throws any occurring exception as DBusException. This change led to an unfortunate big commit, but was inevitable in order to not commit non compiling code. I ran the test on my machine (Ubuntu 18.04 GNOME), but still have to test how the library behaves on other systems with and without gnome-keyring installed. I guess I should provide a small sample application or build Cryptomator with the current changes.

Now the high-level SimpleCollection API consumes and logs occuring DBusExceptions and explains connection problems by throwing IOExceptions with a short message.

Most returning methods of the SimpleCollection return now an Optional, except of getLabel() and getSecret(). If there is no security concern to wrap the char[] of getSecret() as Optional, then it may be more consistent to let all returning functions return an Optional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant