r/javahelp • • 4d ago

Keystore: CLI-Based key manager for Java

Some weeks ago I started working on a Java CLI-based keystore app. I know some mature ones already exist on the market, but I wanted it to be as simple to use as possible and include commands that suit my work.

GitHub Repository: https://github.com/mateasmario/keystore

Until this moment, some functionality includes:

* adding, removing, getting and listing custom keys

* copying a key without displaying it on the screen

* listing all keys without displaying their value on the screen

* generating keys based on certain criteria (length, include digits, uppercase, lowercase, symbols, etc.)

* generating OTP values based on the current time (elapsed seconds after epoch time - 1970) and already stored keys

Managing keys requires a password that is set by the user (keyboard input) when the first key is added/generated to the keystore. That password is used to AES-Encrypt the keystore file in the user data directory (e.g. %localappdata% for Windows).

There is also the possibility of switching to the FILE mode, which is going to ask the user for a file path instead of typing a password. That file contains the key that can be used to decrypt (maybe you keep your secrets on a USB drive). You don't need to create the key manually. Even in FILE mode, the user's still going to be asked for a password the first time, which will be used to derive a key and store it in the specified file path.

Was curious on how I can improve it: how to improve both user experience and also add features that might be helpful to you, the developer community.

3 Upvotes

5 comments sorted by

•

u/AutoModerator 4d ago

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions

  • You include any and all error messages in full

  • You ask clear questions

  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/LutimoDancer3459 4d ago

Why not a wrapper with you wanted functionality for an existing solution?

1

u/mmateas 4d ago

It was a good opportunity of practicing and learning new stuff :) why reuse, when I call build my own?

2

u/LutimoDancer3459 4d ago

Nothing against a nice learning program. But learning to use the stuff that exists and build upon it can also be beneficial if you are a professional developer.

Java has a commonly used keystore. A tool that wraps it and adds functionality can be used everywhere by everyone. A new custom implementation cant and wont be as easily done.

1

u/Far-Bullfrog161 3d ago

Nice project. A few things I'd look at on the security side, since that's what people will judge a key manager on first. How are you turning the password into the AES key? If it's a plain hash, switch to PBKDF2WithHmacSHA256 (it's in the JDK) with a random salt and a high iteration count, or Argon2 via a library, and store the salt next to the ciphertext. For the cipher use AES/GCM with a fresh random IV every time you write the file, that gets you integrity checking too and a wrong password fails cleanly instead of decrypting to garbage. Read the password with Console.readPassword() into a char[] and wipe it after use rather than keeping it in a String. When you copy a key, clear the clipboard after 20-30 seconds, most password managers do that and people will expect it. For OTP, test your output against the RFC 6238 test vectors and support base32 secrets so it works with the same codes as Google Authenticator, that's probably the most useful feature for other devs. Also put a version number in the file header now, it'll save you pain when you change the format later.