mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-04-21 10:06:55 -04:00
@@ -62,6 +62,7 @@
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/libs</outputDirectory>
|
||||
<excludeClassifiers>linux,mac,win</excludeClassifiers>
|
||||
<excludeArtifactIds>dbus-java,secret-service,hkdf,java-utils</excludeArtifactIds>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
@@ -76,6 +77,17 @@
|
||||
<classifier>linux</classifier>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>copy-linux-secret-service</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/linux-libs</outputDirectory>
|
||||
<includeArtifactIds>dbus-java,secret-service,hkdf,java-utils</includeArtifactIds>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>copy-mac-libs</id>
|
||||
<phase>prepare-package</phase>
|
||||
|
||||
@@ -39,7 +39,14 @@
|
||||
<groupId>com.google.dagger</groupId>
|
||||
<artifactId>dagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- secret-service lib -->
|
||||
<dependency>
|
||||
<groupId>de.swiesend</groupId>
|
||||
<artifactId>secret-service</artifactId>
|
||||
<version>1.0.0-RC.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Logging -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.cryptomator.keychain;
|
||||
|
||||
public interface GnomeKeyringAccess {
|
||||
public void storePassword(String key, CharSequence passphrase);
|
||||
|
||||
public char[] loadPassword(String key);
|
||||
|
||||
public void deletePassword(String key);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.cryptomator.keychain;
|
||||
|
||||
import org.freedesktop.secret.simple.SimpleCollection;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class GnomeKeyringAccessImpl implements GnomeKeyringAccess {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GnomeKeyringAccessImpl.class);
|
||||
private SimpleCollection keyring;
|
||||
|
||||
public GnomeKeyringAccessImpl() {
|
||||
try {
|
||||
keyring = new SimpleCollection();
|
||||
} catch (IOException e) {
|
||||
LOG.error("D-Bus reports a problem.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void storePassword(String key, CharSequence passphrase) {
|
||||
List<String> list = keyring.getItems(createAttributes(key));
|
||||
if (list == null) {
|
||||
keyring.createItem("Cryptomator", passphrase, createAttributes(key));
|
||||
}
|
||||
}
|
||||
|
||||
public char[] loadPassword(String key) {
|
||||
List<String> list = keyring.getItems(createAttributes(key));
|
||||
if (list != null) {
|
||||
return keyring.getSecret(list.get(0));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void deletePassword(String key) {
|
||||
List<String> list = keyring.getItems(createAttributes(key));
|
||||
if (list != null) {
|
||||
keyring.deleteItem(list.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> createAttributes(String key) {
|
||||
Map<String, String> attributes = new HashMap();
|
||||
attributes.put("Vault", key);
|
||||
return attributes;
|
||||
}
|
||||
}
|
||||
@@ -31,8 +31,8 @@ public class KeychainModule {
|
||||
|
||||
@Provides
|
||||
@ElementsIntoSet
|
||||
Set<KeychainAccessStrategy> provideKeychainAccessStrategies(MacSystemKeychainAccess macKeychain, WindowsProtectedKeychainAccess winKeychain) {
|
||||
return Sets.newHashSet(macKeychain, winKeychain);
|
||||
Set<KeychainAccessStrategy> provideKeychainAccessStrategies(MacSystemKeychainAccess macKeychain, WindowsProtectedKeychainAccess winKeychain, LinuxSecretServiceAccess linKeychain) {
|
||||
return Sets.newHashSet(macKeychain, winKeychain, linKeychain);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.cryptomator.keychain;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class LinuxKeychainTester {
|
||||
public static boolean secretServiceIsAvailable() {
|
||||
try {
|
||||
Class.forName("org.freedesktop.secret.simple.SimpleCollection");
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<GnomeKeyringAccess> getSecretService() {
|
||||
if (!secretServiceIsAvailable()) return Optional.empty();
|
||||
try {
|
||||
Class clazz = Class.forName("org.cryptomator.keychain.GnomeKeyringAccessImpl");
|
||||
GnomeKeyringAccess keyring = (GnomeKeyringAccess) clazz.getDeclaredConstructor().newInstance();
|
||||
return Optional.of(keyring);
|
||||
} catch (Exception e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.cryptomator.keychain;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Optional;
|
||||
|
||||
public class LinuxSecretServiceAccess implements KeychainAccessStrategy {
|
||||
private final Optional<GnomeKeyringAccess> gnomeLoginKeyring;
|
||||
|
||||
@Inject
|
||||
public LinuxSecretServiceAccess() {
|
||||
gnomeLoginKeyring = LinuxKeychainTester.getSecretService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
return SystemUtils.IS_OS_LINUX && LinuxKeychainTester.getSecretService().isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storePassphrase(String key, CharSequence passphrase) {
|
||||
Preconditions.checkState(gnomeLoginKeyring.isPresent());
|
||||
gnomeLoginKeyring.get().storePassword(key, passphrase);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] loadPassphrase(String key) {
|
||||
Preconditions.checkState(gnomeLoginKeyring.isPresent());
|
||||
return gnomeLoginKeyring.get().loadPassword(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePassphrase(String key) {
|
||||
Preconditions.checkState(gnomeLoginKeyring.isPresent());
|
||||
gnomeLoginKeyring.get().deletePassword(key);
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,11 @@ package org.cryptomator.keychain;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
public class TestKeychainModule extends KeychainModule {
|
||||
|
||||
@Override
|
||||
Set<KeychainAccessStrategy> provideKeychainAccessStrategies(MacSystemKeychainAccess macKeychain, WindowsProtectedKeychainAccess winKeychain) {
|
||||
return Sets.newHashSet(new MapKeychainAccess());
|
||||
Set<KeychainAccessStrategy> provideKeychainAccessStrategies(MacSystemKeychainAccess macKeychain, WindowsProtectedKeychainAccess winKeychain, LinuxSecretServiceAccess linKeychain) {
|
||||
return Set.of(new MapKeychainAccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user