Skip to content

Commit dd0171e

Browse files
committed
add code and pom to project
1 parent dd386e3 commit dd0171e

File tree

5 files changed

+524
-0
lines changed

5 files changed

+524
-0
lines changed

pom.xml

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
<?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"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.cryptomator</groupId>
8+
<artifactId>integrations-linux</artifactId>
9+
<version>0.1.0-SNAPSHOT</version>
10+
11+
<name>integrations-linux</name>
12+
<description>Provides optional Linux services used by Cryptomator</description>
13+
<url>http://www.cryptomator.org</url>
14+
15+
<scm>
16+
<connection>scm:git:[email protected]:cryptomator/integrations-linux.git</connection>
17+
<developerConnection>scm:git:[email protected]:cryptomator/integrations-linux.git</developerConnection>
18+
<url>[email protected]:cryptomator/integrations-linux.git</url>
19+
</scm>
20+
21+
<developers>
22+
<developer>
23+
<name>Armin Schrenk</name>
24+
<email>[email protected]</email>
25+
<timezone>+1</timezone>
26+
<organization>Skymatic GmbH</organization>
27+
<organizationUrl>http://skymatic.de</organizationUrl>
28+
</developer>
29+
</developers>
30+
31+
<licenses>
32+
<license>
33+
<name>GNU Affero General Public License (AGPL) version 3.0</name>
34+
<url>https://www.gnu.org/licenses/agpl.txt</url>
35+
<distribution>repo</distribution>
36+
</license>
37+
</licenses>
38+
39+
<properties>
40+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
41+
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>
46+
<secret-service.version>1.1.0</secret-service.version>
47+
<kdewallet.version>1.1.1</kdewallet.version>
48+
<jwt.version>3.10.3</jwt.version>
49+
<easybind.version>2.1.0</easybind.version>
50+
<guava.version>30.0-jre</guava.version>
51+
<dagger.version>2.22</dagger.version>
52+
<gson.version>2.8.6</gson.version>
53+
<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>
56+
</properties>
57+
58+
<repositories>
59+
<repository>
60+
<id>bintray</id>
61+
<name>bintray</name>
62+
<url>https://jcenter.bintray.com</url>
63+
</repository>
64+
</repositories>
65+
66+
<distributionManagement>
67+
<repository>
68+
<id>bintray-jcenter</id>
69+
<url>https://api.bintray.com/maven/cryptomator/maven/integrations-win/;publish=1</url>
70+
</repository>
71+
</distributionManagement>
72+
73+
<dependencies>
74+
<dependency>
75+
<groupId>org.cryptomator</groupId>
76+
<artifactId>integrations-api</artifactId>
77+
<version>${api.version}</version>
78+
</dependency>
79+
<!-- Apache -->
80+
<dependency>
81+
<groupId>org.apache.commons</groupId>
82+
<artifactId>commons-lang3</artifactId>
83+
<version>${commons-lang3.version}</version>
84+
</dependency>
85+
<!-- Google -->
86+
<dependency>
87+
<groupId>com.google.guava</groupId>
88+
<artifactId>guava</artifactId>
89+
<version>${guava.version}</version>
90+
</dependency>
91+
<!-- secret-service lib -->
92+
<dependency>
93+
<groupId>de.swiesend</groupId>
94+
<artifactId>secret-service</artifactId>
95+
<version>${secret-service.version}</version>
96+
</dependency>
97+
<!-- kdewallet lib -->
98+
<dependency>
99+
<groupId>org.purejava</groupId>
100+
<artifactId>kdewallet</artifactId>
101+
<version>${kdewallet.version}</version>
102+
</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>
117+
</dependencies>
118+
119+
<build>
120+
121+
<plugins>
122+
<plugin>
123+
<artifactId>maven-compiler-plugin</artifactId>
124+
</plugin>
125+
<plugin>
126+
<groupId>org.apache.maven.plugins</groupId>
127+
<artifactId>maven-surefire-plugin</artifactId>
128+
</plugin>
129+
<plugin>
130+
<groupId>org.apache.maven.plugins</groupId>
131+
<artifactId>maven-enforcer-plugin</artifactId>
132+
<executions>
133+
<execution>
134+
<id>check-preconditions</id>
135+
<goals>
136+
<goal>enforce</goal>
137+
</goals>
138+
<configuration>
139+
<rules>
140+
<requireOS>
141+
<family>unix</family>
142+
<name>Linux</name>
143+
<message>This build configuration requires Linux.</message>
144+
</requireOS>
145+
</rules>
146+
</configuration>
147+
</execution>
148+
</executions>
149+
</plugin>
150+
<plugin>
151+
<artifactId>maven-source-plugin</artifactId>
152+
<version>3.2.0</version>
153+
<executions>
154+
<execution>
155+
<id>attach-sources</id>
156+
<goals>
157+
<goal>jar-no-fork</goal>
158+
</goals>
159+
</execution>
160+
</executions>
161+
</plugin>
162+
<plugin>
163+
<artifactId>maven-javadoc-plugin</artifactId>
164+
<version>3.2.0</version>
165+
<executions>
166+
<execution>
167+
<id>attach-javadocs</id>
168+
<goals>
169+
<goal>jar</goal>
170+
</goals>
171+
</execution>
172+
</executions>
173+
<configuration>
174+
<quiet>true</quiet>
175+
<release>11</release>
176+
<tags>
177+
<!-- workaround for "unknown tag: implNote", see https://blog.codefx.org/java/new-javadoc-tags/#Maven -->
178+
<tag>
179+
<name>apiNote</name>
180+
<placement>a</placement>
181+
<head>API Note:</head>
182+
</tag>
183+
<tag>
184+
<name>implSpec</name>
185+
<placement>a</placement>
186+
<head>Implementation Requirements:</head>
187+
</tag>
188+
<tag>
189+
<name>implNote</name>
190+
<placement>a</placement>
191+
<head>Implementation Note:</head>
192+
</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>
200+
</tags>
201+
</configuration>
202+
</plugin>
203+
</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>
250+
</build>
251+
</project>
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package org.cryptomator.linux.keychain;
2+
3+
import org.cryptomator.integrations.keychain.KeychainAccessException;
4+
import org.cryptomator.integrations.keychain.KeychainAccessProvider;
5+
import org.freedesktop.dbus.connections.impl.DBusConnection;
6+
import org.freedesktop.dbus.exceptions.DBusException;
7+
import org.kde.KWallet;
8+
import org.kde.Static;
9+
import org.purejava.KDEWallet;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
12+
13+
public class LinuxKDEWalletKeychainAccessImpl implements KeychainAccessProvider {
14+
15+
private static final Logger LOG = LoggerFactory.getLogger(LinuxKDEWalletKeychainAccessImpl.class);
16+
17+
private final String FOLDER_NAME = "Cryptomator";
18+
private final String APP_NAME = "Cryptomator";
19+
private DBusConnection connection;
20+
private KDEWallet wallet;
21+
private int handle = -1;
22+
23+
public LinuxKDEWalletKeychainAccessImpl() throws KeychainAccessException {
24+
try {
25+
connection = DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION);
26+
} catch (DBusException e) {
27+
LOG.error("Connecting to D-Bus failed:", e);
28+
throw new KeychainAccessException("TODO", e); //FIXME
29+
}
30+
}
31+
32+
@Override
33+
public boolean isSupported() {
34+
try {
35+
wallet = new KDEWallet(connection);
36+
return wallet.isEnabled();
37+
} catch (Exception e) {
38+
LOG.error("A KDEWallet could not be created:", e);
39+
return false;
40+
}
41+
}
42+
43+
@Override
44+
public void storePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
45+
try {
46+
if (walletIsOpen() &&
47+
!(wallet.hasEntry(handle, FOLDER_NAME, key, APP_NAME)
48+
&& wallet.entryType(handle, FOLDER_NAME, key, APP_NAME) == 1)
49+
&& wallet.writePassword(handle, FOLDER_NAME, key, passphrase.toString(), APP_NAME) == 0) {
50+
LOG.debug("Passphrase successfully stored.");
51+
} else {
52+
LOG.debug("Passphrase was not stored.");
53+
}
54+
} catch (Exception e) {
55+
LOG.error("Storing the passphrase failed:", e);
56+
throw new KeychainAccessException("TODO", e); //FIXME
57+
}
58+
}
59+
60+
@Override
61+
public char[] loadPassphrase(String key) throws KeychainAccessException {
62+
String password = "";
63+
try {
64+
if (walletIsOpen()) {
65+
password = wallet.readPassword(handle, FOLDER_NAME, key, APP_NAME);
66+
LOG.debug("loadPassphrase: wallet is open.");
67+
} else {
68+
LOG.debug("loadPassphrase: wallet is closed.");
69+
}
70+
return (password.equals("")) ? null : password.toCharArray();
71+
} catch (Exception e) {
72+
LOG.error("Loading the passphrase failed:", e);
73+
throw new KeychainAccessException("TODO", e); //FIXME
74+
}
75+
}
76+
77+
@Override
78+
public void deletePassphrase(String key) throws KeychainAccessException {
79+
try {
80+
if (walletIsOpen()
81+
&& wallet.hasEntry(handle, FOLDER_NAME, key, APP_NAME)
82+
&& wallet.entryType(handle, FOLDER_NAME, key, APP_NAME) == 1
83+
&& wallet.removeEntry(handle, FOLDER_NAME, key, APP_NAME) == 0) {
84+
LOG.debug("Passphrase successfully deleted.");
85+
} else {
86+
LOG.debug("Passphrase was not deleted.");
87+
}
88+
} catch (Exception e) {
89+
LOG.error("Deleting the passphrase failed:", e);
90+
throw new KeychainAccessException("TODO", e); //FIXME
91+
}
92+
}
93+
94+
@Override
95+
public void changePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
96+
try {
97+
if (walletIsOpen()
98+
&& wallet.hasEntry(handle, FOLDER_NAME, key, APP_NAME)
99+
&& wallet.entryType(handle, FOLDER_NAME, key, APP_NAME) == 1
100+
&& wallet.writePassword(handle, FOLDER_NAME, key, passphrase.toString(), APP_NAME) == 0) {
101+
LOG.debug("Passphrase successfully changed.");
102+
} else {
103+
LOG.debug("Passphrase could not be changed.");
104+
}
105+
} catch (Exception e) {
106+
LOG.error("Changing the passphrase failed:", e);
107+
throw new KeychainAccessException("TODO", e); //FIXME
108+
}
109+
}
110+
111+
private boolean walletIsOpen() throws KeychainAccessException {
112+
try {
113+
if (wallet.isOpen(Static.DEFAULT_WALLET)) {
114+
// This is needed due to KeechainManager loading the passphase directly
115+
if (handle == -1) handle = wallet.open(Static.DEFAULT_WALLET, 0, APP_NAME);
116+
return true;
117+
}
118+
wallet.openAsync(Static.DEFAULT_WALLET, 0, APP_NAME, false);
119+
wallet.getSignalHandler().await(KWallet.walletAsyncOpened.class, Static.ObjectPaths.KWALLETD5, () -> null);
120+
handle = wallet.getSignalHandler().getLastHandledSignal(KWallet.walletAsyncOpened.class, Static.ObjectPaths.KWALLETD5).handle;
121+
LOG.debug("Wallet successfully initialized.");
122+
return handle != -1;
123+
} catch (Exception e) {
124+
LOG.error("Asynchronous opening the wallet failed:", e);
125+
throw new KeychainAccessException("TODO", e); //FIXME
126+
}
127+
}
128+
}

0 commit comments

Comments
 (0)