Encrypting Passwords with Cipher Tool
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.
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.
Before you begin
If you are using Windows, you need to have Ant (http://ant.apache.org/) installed before using the Cipher Tool.
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:
The first step is to update the
cipher-tool.propertiesfile and thecipher-text.propertiesfile with information of the passwords that you want to encrypt.Follow the steps given below.
Open the
cipher-tool.propertiesfile stored in the<PRODUCT_HOME>/repository/conf/securityfolder. This file should contain information about the configuration files in which the passwords (that require encryption) are located. The following format is used:<alias>=<file_name>//<xpath>,<true/false>Example 1: Consider the admin user's password in the
user-mgt.xmlfile shown below.<UserManager> <Realm> <Configuration> <AddAdmin>true</AddAdmin> <AdminRole>admin</AdminRole> <AdminUser> <UserName>admin</UserName> <Password>admin</Password> </AdminUser> ........ </Configuation> ........ </Realm> </UserManager>To encrypt this password, the
cipher-tool.propertiesfile should contain the details shown below. Note that this password is a value given to an XML element (which is 'Password'). Therefore, the XPath ends with the element name, and the flag that follows the XPath is set to 'false'.UserManager.AdminUser.Password=repository/conf/user-mgt.xml//UserManager/Realm/Configuration/AdminUser/Password,falseExample 2: Consider the password that is used to connect to an LDAP user store (configured in the
user-mgt.xmlfile) shown below.<Property name="ConnectionPassword">admin</Property>To encrypt this password, the
cipher-tool.propertiesfile should be updated as shown below. Note that there are two possible alias values you can use for this attribute. In this example, the 'Property' element of the XML file uses the 'name' attribute with the "ConnectionPassword" tag. The password we are encrypting is the value of this "ConnectionPassword" tag. This is denoted in the XPath as 'Property[@name='ConnectionPassword']', and the flag that follows the XPath is set to 'false'.Using the
UserStoreManager.Property.ConnectionPasswordalias:UserStoreManager.Property.ConnectionPassword=repository/conf/user-mgt.xml//UserManager/Realm/UserStoreManager/Property[@name='ConnectionPassword'],falseUsing the
UserManager.Configuration.Property.ConnectionPasswordalias:UserManager.Configuration.Property.ConnectionPassword=repository/conf/user-mgt.xml//UserManager/Realm/UserStoreManager/Property[@name='ConnectionPassword'],false
Example 3: Consider the keystore password specified in the
catalina-server.xmlfile shown below.<Connector protocol="org.apache.coyote.http11.Http11NioProtocol" ... keystorePass="wso2carbon" ... >To encrypt this password, the
cipher-tool.propertiesfile should contain the details shown below. In this example, 'Connector' is the XML element, and 'keystorePass' is an attribute of that element. The password value that we are encrypting is the tag of the XML attribute. This is denoted in the XPath as 'Connector[@keystorePass]', and the flag that follows the XPath is set to ‘true’.Server.Service.Connector.keystorePass=repository/conf/tomcat/catalina-server.xml//Server/Service/Connector[@keystorePass],trueOpen the
cipher-text.propertiesfile stored in the<PRODUCT_HOME>/repository/conf/securityfolder. This file should contain the secret alias names and the corresponding plaintext passwords (enclosed within square brackets) as shown below.<alias>=[plain_text_password]Shown below are the records in the
cipher-text.propertiesfile for the three examples discussed above.//Example 1: Encrypting the admin user's password in the user-mgt.xml file. UserManager.AdminUser.Password=[admin] //Example 2: Encrypting the LDAP connection password in the user-mgt.xml file. Use one of the following: UserStoreManager.Property.ConnectionPassword=[admin] # UserManager.Configuration.Property.ConnectionPassword=[admin] //Example 3: Encrypting the keystore password in the catalina-server.xml file. Server.Service.Connector.keystorePass=[wso2carbon]
Open a command prompt and go to the
<PRODUCT_HOME>/bindirectory, where the cipher tool scripts (for Windows and Linux) are stored.Execute the cipher tool script from the command prompt using the command relevant to your OS:
On Windows:
./ciphertool.bat -DconfigureOn Linux:
./ciphertool.sh -Dconfigure
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".
Now, to verify the password encryption:
Open the
cipher-text.propertiesfile and see that the plain text passwords are replaced by a cipher value.Open the
secret-conf.propertiesfile 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 log4j.properties 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
log4j.appender.LOGEVENT=org.wso2.carbon.logging.service.appender.LogEventAppender
log4j.appender.LOGEVENT.url=tcp://localhost:7611
log4j.appender.LOGEVENT.layout=org.wso2.carbon.utils.logging.TenantAwarePatternLayout
log4j.appender.LOGEVENT.columnList=%T,%S,%A,%d,%c,%p,%m,%I,%Stacktrace
log4j.appender.LOGEVENT.userName=admin
log4j.appender.LOGEVENT.password=admin
log4j.appender.LOGEVENT.processingLimit=1000
log4j.appender.LOGEVENT.maxTolerableConsecutiveFailure=20Since we cannot use the automated process to encrypt the admin password shown above, follow the steps given below to encrypt it manually.
Download and install a WSO2 product.
Open a command prompt and go to the
<PRODUCT_HOME>/bindirectory, where the cipher tool scripts (for Windows and Linux) are stored.You must first enable the Cipher tool for the product by executing the
-Dconfigure command with the cipher tool script as shown below.On Linux:
./ciphertool.sh -DconfigureOn Windows:
./ciphertool.bat -Dconfigure
Now, you can start encrypting the admin password manually. Execute the Cipher tool using the relevant command for your OS:
On Linux:
./ciphertool.shOn Windows:
./ciphertool.bat
You will be asked to enter the primary key password, which is by default 'wso2carbon'. Enter the password and proceed.
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 :adminYou will receive the encrypted value. For example:
Encrypted value is: gaMpTzAccMScaHllsZLXspm1i4HLI0M/srL5pB8jyknRKQ2zT7NuCvt1+qEkElRLgwlrohz3lkuE0KFuapXrCSs5pxfGMOLn4/k7dNs2SlwbsG8C++/ ZfUuft1Sl6cqvDRM55fQwzCPfybl713HvKu3oDaJ9VKgSbvHlQj6zqzg=Open the
cipher-text.propertiesfile, stored in the<PRODUCT_HOME>/repository/conf/securityfolder.Add the encrypted password against the secret alias as shown below.
log4j.appender.LOGEVENT.password=cpw74SGeBNgAVpryqj5/xshSyW5BDW9d1UW0xMZ DxVeoa6RjyA1JRHutZ4SfzfSgSzy2GQJ/2jQIw70IeT5EQEAR8XLGaqlsE5IlNoe9dhyLiPXEPRGq4k/BgUQD YiBg0nU7wRsR8YXrvf+ak8ulX2yGv0Sf8=Now, open the
log4j.propertiesfile, stored in the<PRODUCT_HOME>/repository/conffolder 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 .... log4j.appender.LOGEVENT.password=secretAlias:log4j.appender.LOGEVENT.password ....