We are using Maven 2 and have a maven repository manager secured with SSL client authentication. In order for Maven to access the repository the following system properties must be passed to Java:
javax.net.ssl.trustStore=trust.jks
javax.net.ssl.trustStorePassword=<trustPass>
javax.net.ssl.keyStore=keystore.p12
javax.net.ssl.keyStoreType=pkcs12
javax.net.ssl.keyStorePassword=<keyStorePass>
See this mini-guide for more details.
In order to set these system properties in Maven, I have to use the MAVEN_OPTS environment variable (or pass them directly on the command-line). Either way, when Maven actually executes, all of these properties become visible to other users on the system (via ps), including my key store password.
Is there a way to set these properties so that the password doesn't get exposed on the command-line?
Yes, you can either use
System.setProperty()
in your code, before getting the initial SSLContext, or you can go through the agony and pain of creating your own KeyManager etc etc etc as described with examples in the JSEE Reference Guide.On OSX, you can use your the keychain as a keystore (as far as I know, there is still a bug, so it only works if there is only one "identity", that is one combination of cert+private key).
Do use it, use
-Djavax.net.ssl.keyStore=NONE
,-Djavax.net.ssl.keyStoreType=KeychainStore
and-Djavax.net.ssl.keyStorePassword=-
.The keychain will then prompt you to approve the use of the private key when it's required.
OSX
The solution I came up with on OSX is the following
.mavenrc
. It uses a python script to access the password in the keychain in order to open the client certificate and then generates a random passphrase and a temporary certificate with that random password.Put this in
~/.mavenrc
and add your client certificate to the OSX keychain. Make sure and setMAVEN_CLIENT_CERT
to the location of your client certificate.~/.mavenrc
Linux
On Linux, the following .mavenrc will work with gnome keyring (make sure and add the cert password to your login keyring and set the id variable
KEYRING_ID
):~/.mavenrc
You can define these properties in your Maven Settings file. They will be accessible in the same way as when you provide them on the command line. Here is an example for your Maven Settings file:
Although I have not done the same thing you are attempting I have used this same technique when dealing with secrets.