This documentation is for WSO2 Carbon 4.4.0. View documentation for the latest release.
Encrypting Passwords with Cipher Tool - Carbon 4.4.0 - WSO2 Documentation
Due to a known issue do not use JDK1.8.0_151 with WSO2 products. Use JDK 1.8.0_144 until JDK 1.8.0_162-ea is released.
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 47 Next »

The instructions on this page explain how plain text passwords in configuration files can be encrypted using the secure vault implementation that is built into WSO2 products. Note that you can customize the default secure vault configurations in the product by implementing a new secret repository, call back handler etc. Read more about the Secure Vault implementation in WSO2 products.

In any WSO2 product that is based on Carbon 4.4.0 or a later version, the Cipher Tool feature will be installed by default. You can use this tool to easily encrypt passwords or other elements in configuration files.

Note the following before you begin:

  • If you are a developer who is building a Carbon product, see the topic on enabling Cipher Tool for password encryption for instructions on how to include the Cipher Tool as a feature in your product build.
  • The default keystore that is shipped with your WSO2 product (i.e. wso2carbon.jks) is used for password encryption by default. See this link for details on how to set up and configure new keystores for encrypting plain text passwords.

Follow the topics given below for instructions.

Encrypting passwords using the automated process

This automated process can only be used for passwords that can be given as an xpath. If you cannot give an xpath for the password that you want to encrypt, you must use the manual encryption process explained in the next section.

Follow the steps given below to have passwords encrypted using the automated process:

  1. The first step is to update the file and the file with information of the passwords that you want to encrypt. 

    1. Open the file stored in the <PRODUCT_HOME>/repository/conf/security folder. The file should contain information about the files in which the passwords (that require encryption) are located as shown below:


      For example, if you want to encrypt the admin user password in the user-mgt.xml file, the following should be added to the file:


      Either the relative path or the absolute path of each file starting from <PRODUCT_HOME> should be given. The last value that follows the file path is set to 'true' or 'false' indicating whether or not the value to be encrypted is an attribute. 

      By default, the file that is shipped with your product pack will contain information on the most common passwords that require encryption. 

    2. Open the file stored in the <PRODUCT_HOME>/repository/conf/security folder. This file should contain the secret alias names and the corresponding plain text passwords (enclosed within square brackets) as shown below.


      For example, if you want to encrypt the admin user password in the user-mgt.xml file, the following should be added to the file:

  2. Open a command prompt and go to the <PRODUCT_HOME>/bin directory, where the script is stored. 

  3. Run the script using the command prompt as shown below. 

    ./ -Dconfigure
  4. The following message will be prompted:  "[Please Enter Primary KeyStore Password of Carbon Server : ]". Enter the keystore password (which is "wso2carbon" for the default keystore) and proceed. If the script execution is successful, you will see the following message: "Secret Configurations are written to the property file successfully".

    If you are using the cipher tool for the first time, the ./ -Dconfigure command will first initialize the tool for your product. The tool will then start encrypting the plain text passwords you specified in the file.

    Shown below is an example of an alias and the corresponding plain text password (in square brackets) in the file:


    If a password is not specified in the file for an alias, the user needs to provide it through the command line. Check whether the alias is a known password alias in Carbon configurations. If the tool modifies the configuration element and file, you must replace the configuration element with the alias name. Define a Secret Callback in the configuration file and add proper namespaces for defining the Secure Vault.

  5. Now, to verify the password encryption: 
    • Open the file and see that the plain text passwords are replaced by a cipher value.

    • Open the file from the <PRODUCT_HOME>/repository/conf/security/ folder and see that the default configurations are changed.

Encrypting passwords manually

This manual process can be used for encrypting any password in a configuration file. However, if you want to encrypt any elements that cannot use an xpath to specify the location in a configuration file, you must use manual encryption. It is not possible to use the automated encryption process if an xpath is not specified for the element.

For example, consider the file given below, which does not use xpath notations. As shown below, the password of the LOGEVENT appender is set to admin:

# LOGEVENT is set to be a LogEventAppender using a PatternLayout to send logs to LOGEVENT 

Since we cannot use the automated process to encrypt the admin password shown above, follow the steps given below to encrypt it manually.

  1. Download and install a WSO2 product.
  2. Open a command prompt and navigate to the <PRODUCT_HOME>/bin folder.
  3. You must first enable the Cipher tool for the product by executing the following command:

    sh -Dconfigure 

    If you are using the cipher tool for the first time, this command will first initialize the tool for your product. The tool will then encrypt any plain text passwords that are specified in the file. See the automated encryption process for more information.

  4. Now, you can start encrypting the admin password manually. Execute the Cipher tool using the following command:

  5. You will be asked to enter the primary key password, which is by default 'wso2carbon'. Enter the password and proceed.
  6. You will now be asked to enter the plain text password that you want to encrypt. Enter the following element as the password and proceed:

    Enter Plain Text Value :admin

    Note that in certain configuration files, the password that requires encryption may not be specified as a single value as it is in the file. For example, the file used in WSO2 ESB contains the password in the connection URL. In such cases, you need to encrypt the entire connection URL as explained here.

  7. You will receive the encrypted value. For example:

    Encrypted value is: 
  8. Open the file, stored in the <PRODUCT_HOME>/repository/conf/security folder.

  9. Add the encrypted password against the secret alias as shown below.

  10. Now, open the file, stored in the <PRODUCT_HOME>/repository/conf folder and replace the plain text element with the alias of the encrypted value as shown below.

    # LOGEVENT is set to be a LogEventAppender using a PatternLayout to send logs to LOGEVENT 

Another example of a configuration file that uses passwords without an xpath notation is the file. This file is used in WSO2 Enterprise Service Bus (WSO2 ESB) for the purpose of connecting to a message broker. You can read more about this functionality from here. As shown below, this file contains a password value (admin) in the connection URL (amqp://admin:[email protected]/carbon?brokerlist='tcp://localhost:5673'). To encrypt this password, you can follow the same manual process explained above. However, you must encrypt the entire connection URL (amqp://admin:[email protected]/carbon?brokerlist='tcp://localhost:5673') and not just the password value given in the URL.

# register some connection factories
# connectionfactory.[jndiname] = [ConnectionURL]
connectionfactory.QueueConnectionFactory = amqp://admin:[email protected]/carbon?brokerlist='tcp://localhost:5673'

# register some queues in JNDI using the form
# queue.[jndiName] = [physicalName]
queue.MyQueue = example.MyQueue

# register some topics in JNDI using the form
# topic.[jndiName] = [physicalName]
topic.MyTopic = example.MyTopic

Changing encrypted passwords

To change any password which we have encrypted already, follow the below steps:

  1. Be sure to shut down the server.

  2. Open a command prompt and go to the <PRODUCT_HOME>/bin directory, where we have stored the script.

  3. Execute the following command:

    ./ -Dchange
  4. It will prompt for the primary keystore password. Enter the keystore password (which is "wso2carbon" for the default keystore).

  5. The alias values of all the passwords that you encrypted will now be shown in a numbered list. 

  6. The system will then prompt you to select the alias of the password which you want to change. Enter the list number of the password alias.

  7. The system will then prompt you (twice) to enter the new password. Enter your new password.

  8. The password should now be changed and encrypted.

If you have encrypted passwords as explained above, note that these passwords have to be decrypted again for the server to be usable. That is, the passwords have to be resolved by a system administrator during server startup. The Resolving Passwords topic explains how encrypted passwords are resolved.

  • No labels