-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
309 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 10 additions & 2 deletions
12
src/main/headers/org_cryptomator_macos_keychain_MacKeychain_Native.h
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/org/cryptomator/macos/keychain/TouchIdKeychainAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.cryptomator.macos.keychain; | ||
|
||
import org.cryptomator.integrations.common.OperatingSystem; | ||
import org.cryptomator.integrations.common.Priority; | ||
import org.cryptomator.integrations.keychain.KeychainAccessException; | ||
import org.cryptomator.integrations.keychain.KeychainAccessProvider; | ||
import org.cryptomator.macos.common.Localization; | ||
|
||
/** | ||
* Stores passwords in the macOS system keychain. Requires an authenticated user to do so. | ||
* Authentication is done via TouchID or password as a fallback, when TouchID is not available. | ||
* <p> | ||
* Items are stored in the default keychain with the service name <code>Cryptomator</code>, unless configured otherwise | ||
* using the system property <code>cryptomator.integrationsMac.keychainServiceName</code>. | ||
*/ | ||
@Priority(1010) | ||
@OperatingSystem(OperatingSystem.Value.MAC) | ||
public class TouchIdKeychainAccess implements KeychainAccessProvider { | ||
|
||
private static final String SERVICE_NAME = System.getProperty("cryptomator.integrationsMac.keychainServiceName", "Cryptomator"); | ||
|
||
private final MacKeychain keychain; | ||
|
||
public TouchIdKeychainAccess() { | ||
this(new MacKeychain()); | ||
} | ||
|
||
// visible for testing | ||
TouchIdKeychainAccess(MacKeychain keychain) { | ||
this.keychain = keychain; | ||
} | ||
|
||
@Override | ||
public String displayName() { | ||
return Localization.get().getString("org.cryptomator.macos.keychain.touchIdDisplayName"); | ||
} | ||
|
||
@Override | ||
public void storePassphrase(String key, String displayName, CharSequence passphrase) throws KeychainAccessException { | ||
keychain.storePassword(SERVICE_NAME, key, passphrase, true); | ||
} | ||
|
||
@Override | ||
public void storePassphrase(String key, String displayName, CharSequence passphrase, boolean requireOsAuthentication) throws KeychainAccessException { | ||
keychain.storePassword(SERVICE_NAME, key, passphrase, requireOsAuthentication); | ||
} | ||
|
||
@Override | ||
public char[] loadPassphrase(String key) { | ||
return keychain.loadPassword(SERVICE_NAME, key); | ||
} | ||
|
||
@Override | ||
public boolean isSupported() { | ||
return keychain.isTouchIDavailable(); | ||
} | ||
|
||
@Override | ||
public boolean isLocked() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void deletePassphrase(String key) throws KeychainAccessException { | ||
keychain.deletePassword(SERVICE_NAME, key); | ||
} | ||
|
||
@Override | ||
public void changePassphrase(String key, String displayName, CharSequence passphrase) throws KeychainAccessException { | ||
if (keychain.deletePassword(SERVICE_NAME, key)) { | ||
keychain.storePassword(SERVICE_NAME, key, passphrase, true); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.