ソースを参照

implemented keychain access on OS X

Sebastian Stenzel 8 年 前
コミット
72e52df4e0

+ 4 - 0
main/keychain/pom.xml

@@ -18,6 +18,10 @@
 			<artifactId>bcprov-jdk15on</artifactId>
 			<version>1.54</version>
 		</dependency>
+		<dependency>
+			<groupId>org.cryptomator</groupId>
+			<artifactId>jni</artifactId>
+		</dependency>
 
 		<!-- DI -->
 		<dependency>

+ 11 - 15
main/keychain/src/main/java/org/cryptomator/keychain/MacSystemKeychainAccess.java

@@ -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;
 	}
 
 }

+ 8 - 0
main/pom.xml

@@ -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>

+ 0 - 1
main/ui/pom.xml

@@ -57,7 +57,6 @@
 		<dependency>
 			<groupId>org.cryptomator</groupId>
 			<artifactId>jni</artifactId>
-			<version>1.0.0-SNAPSHOT</version>
 		</dependency>
 		
 		<!-- EasyBind -->