mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-04-21 18:16:54 -04:00
implemented keychain access on OS X
This commit is contained in:
@@ -18,6 +18,10 @@
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>1.54</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.cryptomator</groupId>
|
||||
<artifactId>jni</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- DI -->
|
||||
<dependency>
|
||||
|
||||
@@ -1,45 +1,41 @@
|
||||
package org.cryptomator.keychain;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyStore;
|
||||
import java.nio.CharBuffer;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.jni.JniModule;
|
||||
import org.cryptomator.jni.MacKeychainAccess;
|
||||
|
||||
@Singleton
|
||||
class MacSystemKeychainAccess implements KeychainAccessStrategy {
|
||||
|
||||
private final KeyStore keyStore;
|
||||
private final MacKeychainAccess keychain;
|
||||
|
||||
@Inject
|
||||
public MacSystemKeychainAccess() {
|
||||
KeyStore ks;
|
||||
try {
|
||||
ks = KeyStore.getInstance("KeychainStore", "Apple");
|
||||
ks.load(null);
|
||||
} catch (GeneralSecurityException | IOException e) {
|
||||
ks = null;
|
||||
if (JniModule.macFunctions().isPresent()) {
|
||||
this.keychain = JniModule.macFunctions().get().getKeychainAccess();
|
||||
} else {
|
||||
this.keychain = null;
|
||||
}
|
||||
this.keyStore = ks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storePassphrase(String key, CharSequence passphrase) {
|
||||
// TODO Auto-generated method stub
|
||||
keychain.storePassword(key, passphrase);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence loadPassphrase(String key) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return CharBuffer.wrap(keychain.loadPassword(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
return SystemUtils.IS_OS_MAC_OSX && keyStore != null;
|
||||
return SystemUtils.IS_OS_MAC_OSX && keychain != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<!-- dependency versions -->
|
||||
<cryptomator.jni.version>1.0.0-SNAPSHOT</cryptomator.jni.version>
|
||||
<log4j.version>2.1</log4j.version>
|
||||
<slf4j.version>1.7.7</slf4j.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
@@ -122,6 +123,13 @@
|
||||
<artifactId>ui</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Cryptomator libraries -->
|
||||
<dependency>
|
||||
<groupId>org.cryptomator</groupId>
|
||||
<artifactId>jni</artifactId>
|
||||
<version>${cryptomator.jni.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Logging -->
|
||||
<dependency>
|
||||
|
||||
@@ -57,7 +57,6 @@
|
||||
<dependency>
|
||||
<groupId>org.cryptomator</groupId>
|
||||
<artifactId>jni</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- EasyBind -->
|
||||
|
||||
Reference in New Issue
Block a user