Skip to content

Commit 1222fb1

Browse files
cleanup
1 parent 29dbd0d commit 1222fb1

File tree

7 files changed

+200
-286
lines changed

7 files changed

+200
-286
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 36 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
6-
76
<groupId>org.cryptomator</groupId>
87
<artifactId>integrations-linux</artifactId>
98
<version>0.1.0-SNAPSHOT</version>
109

1110
<name>integrations-linux</name>
1211
<description>Provides optional Linux services used by Cryptomator</description>
1312
<url>http://www.cryptomator.org</url>
14-
1513
<scm>
1614
<connection>scm:git:[email protected]:cryptomator/integrations-linux.git</connection>
1715
<developerConnection>scm:git:[email protected]:cryptomator/integrations-linux.git</developerConnection>
@@ -39,20 +37,12 @@
3937
<properties>
4038
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4139

42-
<maven.compiler.release>11</maven.compiler.release>
43-
44-
<api.version>0.1.1</api.version>
45-
<commons-lang3.version>3.11</commons-lang3.version>
40+
<!-- runtime dependencies -->
41+
<api.version>0.1.3</api.version>
4642
<secret-service.version>1.1.0</secret-service.version>
4743
<kdewallet.version>1.1.1</kdewallet.version>
48-
<jwt.version>3.10.3</jwt.version>
49-
<easybind.version>2.1.0</easybind.version>
5044
<guava.version>30.0-jre</guava.version>
51-
<dagger.version>2.22</dagger.version>
52-
<gson.version>2.8.6</gson.version>
5345
<slf4j.version>1.7.30</slf4j.version>
54-
<logback.version>1.2.3</logback.version>
55-
<junit.jupiter.version>5.6.2</junit.jupiter.version>
5646
</properties>
5747

5848
<repositories>
@@ -66,7 +56,7 @@
6656
<distributionManagement>
6757
<repository>
6858
<id>bintray-jcenter</id>
69-
<url>https://api.bintray.com/maven/cryptomator/maven/integrations-win/;publish=1</url>
59+
<url>https://api.bintray.com/maven/cryptomator/maven/integrations-linux/;publish=1</url>
7060
</repository>
7161
</distributionManagement>
7262

@@ -76,59 +66,48 @@
7666
<artifactId>integrations-api</artifactId>
7767
<version>${api.version}</version>
7868
</dependency>
79-
<!-- Apache -->
8069
<dependency>
81-
<groupId>org.apache.commons</groupId>
82-
<artifactId>commons-lang3</artifactId>
83-
<version>${commons-lang3.version}</version>
70+
<groupId>org.slf4j</groupId>
71+
<artifactId>slf4j-api</artifactId>
72+
<version>${slf4j.version}</version>
8473
</dependency>
85-
<!-- Google -->
8674
<dependency>
8775
<groupId>com.google.guava</groupId>
8876
<artifactId>guava</artifactId>
8977
<version>${guava.version}</version>
9078
</dependency>
91-
<!-- secret-service lib -->
9279
<dependency>
9380
<groupId>de.swiesend</groupId>
9481
<artifactId>secret-service</artifactId>
9582
<version>${secret-service.version}</version>
9683
</dependency>
97-
<!-- kdewallet lib -->
9884
<dependency>
9985
<groupId>org.purejava</groupId>
10086
<artifactId>kdewallet</artifactId>
10187
<version>${kdewallet.version}</version>
10288
</dependency>
103-
<!-- Logging -->
104-
<dependency>
105-
<groupId>org.slf4j</groupId>
106-
<artifactId>slf4j-simple</artifactId>
107-
<version>${slf4j.version}</version>
108-
<scope>test</scope>
109-
</dependency>
110-
<!-- Testing -->
111-
<dependency>
112-
<groupId>org.junit.jupiter</groupId>
113-
<artifactId>junit-jupiter</artifactId>
114-
<version>${junit.jupiter.version}</version>
115-
<scope>test</scope>
116-
</dependency>
11789
</dependencies>
11890

11991
<build>
12092

12193
<plugins>
12294
<plugin>
95+
<groupId>org.apache.maven.plugins</groupId>
12396
<artifactId>maven-compiler-plugin</artifactId>
97+
<version>3.8.0</version>
98+
<configuration>
99+
<release>11</release>
100+
</configuration>
124101
</plugin>
125102
<plugin>
126103
<groupId>org.apache.maven.plugins</groupId>
127104
<artifactId>maven-surefire-plugin</artifactId>
105+
<version>2.22.2</version>
128106
</plugin>
129107
<plugin>
130108
<groupId>org.apache.maven.plugins</groupId>
131109
<artifactId>maven-enforcer-plugin</artifactId>
110+
<version>3.0.0-M3</version>
132111
<executions>
133112
<execution>
134113
<id>check-preconditions</id>
@@ -190,62 +169,30 @@
190169
<placement>a</placement>
191170
<head>Implementation Note:</head>
192171
</tag>
193-
<tag><name>param</name></tag>
194-
<tag><name>return</name></tag>
195-
<tag><name>throws</name></tag>
196-
<tag><name>since</name></tag>
197-
<tag><name>version</name></tag>
198-
<tag><name>serialData</name></tag>
199-
<tag><name>see</name></tag>
172+
<tag>
173+
<name>param</name>
174+
</tag>
175+
<tag>
176+
<name>return</name>
177+
</tag>
178+
<tag>
179+
<name>throws</name>
180+
</tag>
181+
<tag>
182+
<name>since</name>
183+
</tag>
184+
<tag>
185+
<name>version</name>
186+
</tag>
187+
<tag>
188+
<name>serialData</name>
189+
</tag>
190+
<tag>
191+
<name>see</name>
192+
</tag>
200193
</tags>
201194
</configuration>
202195
</plugin>
203196
</plugins>
204-
205-
206-
207-
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
208-
<plugins>
209-
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
210-
<plugin>
211-
<artifactId>maven-clean-plugin</artifactId>
212-
<version>3.1.0</version>
213-
</plugin>
214-
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
215-
<plugin>
216-
<artifactId>maven-resources-plugin</artifactId>
217-
<version>3.0.2</version>
218-
</plugin>
219-
<plugin>
220-
<artifactId>maven-compiler-plugin</artifactId>
221-
<version>3.8.1</version>
222-
</plugin>
223-
<plugin>
224-
<artifactId>maven-surefire-plugin</artifactId>
225-
<version>3.0.0-M5</version>
226-
</plugin>
227-
<plugin>
228-
<groupId>org.apache.maven.plugins</groupId>
229-
<artifactId>maven-enforcer-plugin</artifactId>
230-
<version>3.0.0-M3</version>
231-
</plugin>
232-
<plugin>
233-
<artifactId>maven-jar-plugin</artifactId>
234-
<version>3.2.0</version>
235-
</plugin>
236-
<plugin>
237-
<artifactId>maven-install-plugin</artifactId>
238-
<version>3.0.0-M1</version>
239-
</plugin>
240-
<plugin>
241-
<artifactId>maven-deploy-plugin</artifactId>
242-
<version>3.0.0-M1</version>
243-
</plugin>
244-
<plugin>
245-
<artifactId>maven-project-info-reports-plugin</artifactId>
246-
<version>3.1.1</version>
247-
</plugin>
248-
</plugins>
249-
</pluginManagement>
250197
</build>
251198
</project>
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package org.cryptomator.linux.keychain;
2+
3+
import com.google.common.base.Preconditions;
4+
import org.cryptomator.integrations.keychain.KeychainAccessException;
5+
import org.cryptomator.integrations.keychain.KeychainAccessProvider;
6+
import org.freedesktop.dbus.connections.impl.DBusConnection;
7+
import org.freedesktop.dbus.exceptions.DBusException;
8+
import org.kde.KWallet;
9+
import org.kde.Static;
10+
import org.purejava.KDEWallet;
11+
import org.slf4j.Logger;
12+
import org.slf4j.LoggerFactory;
13+
14+
import java.util.Optional;
15+
16+
public class KDEWalletKeychainAccess implements KeychainAccessProvider {
17+
18+
private static final Logger LOG = LoggerFactory.getLogger(KDEWalletKeychainAccess.class);
19+
private static final String FOLDER_NAME = "Cryptomator";
20+
private static final String APP_NAME = "Cryptomator";
21+
22+
private final Optional<ConnectedWallet> wallet;
23+
24+
public KDEWalletKeychainAccess() {
25+
ConnectedWallet wallet = null;
26+
try {
27+
DBusConnection conn = DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION);
28+
wallet = new ConnectedWallet(conn);
29+
} catch (DBusException e) {
30+
LOG.warn("Connecting to D-Bus failed.", e);
31+
}
32+
this.wallet = Optional.ofNullable(wallet);
33+
}
34+
35+
@Override
36+
public boolean isSupported() {
37+
return wallet.map(ConnectedWallet::isSupported).orElse(false);
38+
}
39+
40+
@Override
41+
public void storePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
42+
Preconditions.checkState(wallet.isPresent(), "Keychain not supported.");
43+
wallet.get().storePassphrase(key, passphrase);
44+
}
45+
46+
@Override
47+
public char[] loadPassphrase(String key) throws KeychainAccessException {
48+
Preconditions.checkState(wallet.isPresent(), "Keychain not supported.");
49+
return wallet.get().loadPassphrase(key);
50+
}
51+
52+
@Override
53+
public void deletePassphrase(String key) throws KeychainAccessException {
54+
Preconditions.checkState(wallet.isPresent(), "Keychain not supported.");
55+
wallet.get().deletePassphrase(key);
56+
}
57+
58+
@Override
59+
public void changePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
60+
Preconditions.checkState(wallet.isPresent(), "Keychain not supported.");
61+
wallet.get().changePassphrase(key, passphrase);
62+
}
63+
64+
private static class ConnectedWallet {
65+
66+
private final KDEWallet wallet;
67+
private int handle = -1;
68+
69+
public ConnectedWallet(DBusConnection connection) {
70+
this.wallet = new KDEWallet(connection);
71+
}
72+
73+
public boolean isSupported() {
74+
return wallet.isEnabled();
75+
}
76+
77+
public void storePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
78+
try {
79+
if (walletIsOpen() &&
80+
!(wallet.hasEntry(handle, FOLDER_NAME, key, APP_NAME) && wallet.entryType(handle, FOLDER_NAME, key, APP_NAME) == 1)
81+
&& wallet.writePassword(handle, FOLDER_NAME, key, passphrase.toString(), APP_NAME) == 0) {
82+
LOG.debug("Passphrase successfully stored.");
83+
} else {
84+
LOG.debug("Passphrase was not stored.");
85+
}
86+
} catch (RuntimeException e) {
87+
throw new KeychainAccessException("Storing the passphrase failed.", e);
88+
}
89+
}
90+
91+
public char[] loadPassphrase(String key) throws KeychainAccessException {
92+
String password = "";
93+
try {
94+
if (walletIsOpen()) {
95+
password = wallet.readPassword(handle, FOLDER_NAME, key, APP_NAME);
96+
LOG.debug("loadPassphrase: wallet is open.");
97+
} else {
98+
LOG.debug("loadPassphrase: wallet is closed.");
99+
}
100+
return (password.equals("")) ? null : password.toCharArray();
101+
} catch (RuntimeException e) {
102+
throw new KeychainAccessException("Loading the passphrase failed.", e);
103+
}
104+
}
105+
106+
public void deletePassphrase(String key) throws KeychainAccessException {
107+
try {
108+
if (walletIsOpen()
109+
&& wallet.hasEntry(handle, FOLDER_NAME, key, APP_NAME)
110+
&& wallet.entryType(handle, FOLDER_NAME, key, APP_NAME) == 1
111+
&& wallet.removeEntry(handle, FOLDER_NAME, key, APP_NAME) == 0) {
112+
LOG.debug("Passphrase successfully deleted.");
113+
} else {
114+
LOG.debug("Passphrase was not deleted.");
115+
}
116+
} catch (RuntimeException e) {
117+
throw new KeychainAccessException("Deleting the passphrase failed.", e);
118+
}
119+
}
120+
121+
public void changePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
122+
try {
123+
if (walletIsOpen()
124+
&& wallet.hasEntry(handle, FOLDER_NAME, key, APP_NAME)
125+
&& wallet.entryType(handle, FOLDER_NAME, key, APP_NAME) == 1
126+
&& wallet.writePassword(handle, FOLDER_NAME, key, passphrase.toString(), APP_NAME) == 0) {
127+
LOG.debug("Passphrase successfully changed.");
128+
} else {
129+
LOG.debug("Passphrase could not be changed.");
130+
}
131+
} catch (RuntimeException e) {
132+
throw new KeychainAccessException("Changing the passphrase failed.", e);
133+
}
134+
}
135+
136+
private boolean walletIsOpen() throws KeychainAccessException {
137+
try {
138+
if (wallet.isOpen(Static.DEFAULT_WALLET)) {
139+
// This is needed due to KeechainManager loading the passphase directly
140+
if (handle == -1) handle = wallet.open(Static.DEFAULT_WALLET, 0, APP_NAME);
141+
return true;
142+
}
143+
wallet.openAsync(Static.DEFAULT_WALLET, 0, APP_NAME, false);
144+
wallet.getSignalHandler().await(KWallet.walletAsyncOpened.class, Static.ObjectPaths.KWALLETD5, () -> null);
145+
handle = wallet.getSignalHandler().getLastHandledSignal(KWallet.walletAsyncOpened.class, Static.ObjectPaths.KWALLETD5).handle;
146+
LOG.debug("Wallet successfully initialized.");
147+
return handle != -1;
148+
} catch (RuntimeException e) {
149+
throw new KeychainAccessException("Asynchronous opening the wallet failed.", e);
150+
}
151+
}
152+
153+
154+
}
155+
}

0 commit comments

Comments
 (0)