Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OS X Keychain access in Java for Generic Passwords

What is the standard way to retrieve generic passwords in the Keychain of OS X using only Java? Apple Developer Pages provide some good background but the implementation and examples are in C or native code unfortunately.

The Java KeyStore OS X implementation appears to be good only for public/private key pairs and certs but not generic username/password combos.

I see a project started Here: but it is relatively old and not actively maintained.

Is there a more state of the art solution to the problem of securing credentials in Mac OS X in Java?

EDIT: OAuth is not an option for the class of problem and environment that I am operating in ...

like image 919
echen Avatar asked Jul 06 '16 14:07

echen


2 Answers

There is also JNA + Maven project here which doesn't require compiling any native code in the build. Apparently supports OSX and Windows.

https://bitbucket.org/east301/java-keyring/

It has less features than osx-keychain-java, but supports Add and Get Generic Password.

<dependency>
  <groupId>net.east301</groupId>
  <artifactId>java-keyring</artifactId>
  <version>1.0.0</version>
</dependency>

Example code

import net.east301.keyring.Keyring;
import net.east301.keyring.PasswordRetrievalException;

Keyring keyring = Keyring.create();
String pw = keyring.getPassword(service, account);
like image 151
Yuri Schimke Avatar answered Oct 20 '22 16:10

Yuri Schimke


This seems to be a fairly common problem; the only solution I've found that looks like it might meet your requirements is this Github project, but it seems to be extremely old/unmaintained, and I can't speak to the quality or security of the code.

Unfortunately, there does not seem to be native support for accessing passwords stored in the keychain, and this does not seem to be a common enough problem for there to be an actively-developed library to solve it.

like image 1
F. Stephen Q Avatar answered Oct 20 '22 14:10

F. Stephen Q