Encrypting Passwords in Properties Files

Last updated 7 months ago

Learn how to encrypt passwords stored in property files.

LightbulbWhat you'll learn

  • Create a KeyStore file
  • Encrypt your passwords stored in property files

Person reading a bookPrerequisites

  • A CoreMedia system
  • Knowledge about the CoreMedia system's file structure, configuration, and operation

WristwatchTime matters

Reading time: 3 to 5 minutes

Person in front of a laptopShould I read this?

This guide is for Developers, Administrators.

To encrypt passwords stored in properties files you can use the KeyStore based encryption service. This service uses a pair of public and private keys to encode and decode passwords. The keys are retrieved from a KeyStore located in the file system.

Preliminary Setup

Before you can use the KeyStore based encryption service, you must create a KeyStore file using the Java keytool command. The KeyStore file will contain the private key and the certificate that will be used to encrypt and decrypt the passwords. On the command prompt type:

keytool -genkey -alias <KEY_ALIAS> -keyalg RSA -validity 3650 -keystore <KEYSTORE_FILENAME>

The tool will ask you for the KeyStore password and the key password.

It will also ask you for your username, organizational unit, organization, city, state/province, country code. This information (which goes into your self-signed certificate) is not relevant for the correct functioning of your KeyStore. The resulting key/certificate will be valid for 3650 days (about 10 years). It is assumed that this should be enough for your CM installation.

Having the KeyStore created, the KeyStore credentials now must be stored in a password file, so that the servers and clients can access the KeyStore without prompting for passwords. The password file is in Java properties file format and has to contain the following entries:

CM_KEYSTORE_PASSWORD=<KEYSTORE_PASSWORD>
CM_KEY_ALIAS=<KEY_ALIAS>
CM_KEY_PASSWORD=<KEY_PASSWORD>

As the password file will contain the clear text passwords for your KeyStore, the file has to be protected from unauthorized access. This could be done for example by setting reasonable access rights for the file, or by putting it on a removable device.

In order to use the KeyStore with the Encryption Service, you have two options:

  • By default, the service expects

    • the KeyStore file under the path ${user.home}/.cmservices/.keystore

    • and the password file under ${user.home}/.cmservices/.keystore.properties

  • If you want store the files under different paths you have to provide the following two system properties:

    • CM_KEYSTORE_LOCATION: location of the KeyStore file

    • CM_KEYSTORE_PASSWORD_FILE_LOCATION: location of the password file

Password Encryption

For each password you want to encrypt take the following steps:

  1. Login as a user who can access the KeyStore and password file. Switch to the installation directory of the command line tools and enter the following command where <plaintextpassword> must be replaced with the password you want to encrypt:

bin/cm encryptpasswordproperty <plaintextpassword>
  1. The command output is the encrypted password (which includes the curly brackets!) and some informational text. Use the -r option (bin/cm encryptpasswordproperty -r <plaintextpassword>) to have the tool just dump out the encrypted password without other information.

    The tool will generate a unique value for the same plain text value each time you invoke it.

  2. Copy the password (including the curly brackets) into your respective properties file. You can append a comment after the closing curly bracket to add information. For example:

    sql.store.password={G/7UZ7hPQnGZ/xX4J/7b8FNp/ybEH/JU
    Qp5c8NRoDEQSlK5ypbkwotfu6j8U1SHr
    QifmKeAQUvou/+ES34/pRHs=} --- generated by User xxx on 28/03/2013

Verify a password

If you want to verify that a given encrypted password represents a given plaintext password, use

cm encryptpasswordproperty -c <plaintext password> <encrypted entry>

where <plaintext password> should be replaced with the password and <encrypted entry> with the result of the encryption tool. The command will provide you with textual information whether these passwords match. The command returns with return value "0" whether the tokens match or not.

Troubleshooting

You must set the CM_KEYSTORE_LOCATION and CM_KEYSTORE_PASSWORD_FILE_LOCATION system properties not only for the encryptpasswordproperty tool, but also for the tool that uses the encrypted password, for instance schemaaccess.

View the respective component’s log file. If an encrypted password cannot be decoded, you will see an error message in your log file telling you so. Since passwords decryption is verified early on (fail fast), you will find the error messages shortly after the component, service, or server starts.

Copyright © 2024 CoreMedia GmbH, CoreMedia Corporation. All Rights Reserved.
Loading...