Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

...

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

  1. The first step is to update the update the cipher-tool.properties file and the  file and the cipher-text.properties file with  file with information of the passwords that you want to encrypt. 

    Info
    Open

    By default, the cipher-tool.properties

     file stored in the 

    and cipher-text.properties files that are shipped with your product will contain information on the most common passwords that require encryption. If a required password is missing in the default files, you can add them manually

    Follow the steps given below.

    Using the UserStoreManager.Property.ConnectionPassword alias
    1. Open the cipher-tool.properties file stored in the <PRODUCT_HOME>/repository/conf/security folder. The This file should contain information about the configuration files in which the passwords (that require encryption) are located as shown below. The following format is used:

      Code Block
      <alias>=<file_name>//<xpath>,<true/false>

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

      Code Block
      UserManager.AdminUser.Password=repository/conf/user-mgt.xml//UserManager/Realm/Configuration/AdminUser/Password,false
      Info

      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 note 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 cipher-text.properties 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.

      Code Block
      <alias>=[plain_text_password]

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

      Code Block
      UserManager.AdminUser.Password=[admin]
    Info

    By default, the cipher-tool.properties and cipher-text.properties files that are shipped with your product pack will contain information on the most common passwords that require encryption. If a required password is missing in the default files, you can add them manually. For example, if you want to encrypt the password that is used to connect to an LDAP user store (configured in the user-mgt.xml file), add the following: 

    Add a new entry to the cipher-tool.properties file as shown below. Note that the <alias> value should be the same value that is hard coded in the relevant Carbon component. In this example (LDAP user store connection password), there are two possible alias values you can use as shown below.


    1. Info

      Important!

      • The <alias> should be the same value that is hardcoded in the relevant Carbon component.
      • The <file_path> specifies the path to the XML file that contains the password. This can be the relative file path, or the absolute file path (starting from <PRODUCT_HOME>).

      • The <xpath> specifies the XPath to the XML element/attribute/tag that should be encrypted. See the examples given below.
      • The flag that follows the XPath should be set to 'false' if you are encrypting the value of an XML element, or the value of an XML attribute's tag. The flag should be 'true' if you are encrypting the tag of an XML attribute. See the examples given below.

      Example 1: Consider the admin user's password in the user-mgt.xml file shown below. 

      Code Block
      <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.properties file 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'.

      Code Block
      UserManager.AdminUser.Password=repository/conf/user-mgt.xml//UserManager/Realm/Configuration/AdminUser/Password,false

      Example 2: Consider the password that is used to connect to an LDAP user store (configured in the user-mgt.xml file) shown below.

      Code Block
      <Property name="ConnectionPassword">admin</Property>

      To encrypt this password, the cipher-tool.properties file 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.ConnectionPassword alias:

        Code Block
        UserStoreManager.Property.ConnectionPassword=repository/conf/user-mgt.xml//UserManager/Realm/UserStoreManager/Property[@name='ConnectionPassword'],
    true
      • false
      • Using

    the
      • the UserManager.Configuration.Property.ConnectionPassword

    alias
      •  alias:

        Code Block
        UserManager.Configuration.Property.ConnectionPassword=repository/conf/user-mgt.xml//UserManager/Realm/UserStoreManager/Property[@name='ConnectionPassword'],false
      Note

      If you are trying the above example, be sure that only the relevant user store manager is enabled in the user-mgt.xml file.

      Example 3: Consider the keystore password specified in the catalina-server.xml file shown below. 

      Code Block
      <Connector protocol="org.apache.coyote.http11.Http11NioProtocol"  
       ... 
       keystorePass="wso2carbon" 
      ... >

      To encrypt this password, the cipher-tool.properties file 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]',

    trueAdd a new entry to the
    1. and the flag that follows the XPath is set to ‘true’.

      Code Block
      Server.Service.Connector.keystorePass=repository/conf/tomcat/catalina-server.xml//Server/Service/Connector[@keystorePass],true
    2. Open the cipher-text.properties file stored in the <PRODUCT_HOME>/repository/conf/security folder. This file

    corresponding to the new entry in the cipher-tool.properties file:
    1. should contain the secret alias names and the corresponding plaintext passwords (enclosed within square brackets) as shown below.

      Code Block
      <alias>=[plain_text_password]

      Shown below are the records in the cipher-text.properties file for the three examples discussed above.

      Code Block
      //
    Use the alias corresponding to the value
    1. 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 
    cipher
    1. user-
    tool
    1. mgt.
    properties
    1. xml file. 
    #UserStoreManager
    1. Use one of the following:
      UserStoreManager.Property.ConnectionPassword=[
    password
    1. admin]
      # 
    #UserManager
    1. UserManager.
    Configuraton
    1. Configuration.Property.ConnectionPassword=[admin]
      //Example 3: Encrypting the keystore password
    ]Save the information.
    1.  in the catalina-server.xml file.
      Server.Service.Connector.keystorePass=[wso2carbon]
    Note

    If your password contains a backslash character (\) you need to use an alias with the escape characters. For example, if your password is admin\} the value should be given as shown in the example below.

    Code Block
    UserStoreManager.Property.ConnectionPassword=[admin\\}]
  2. Open a command prompt and go to the to the <PRODUCT_HOME>/bin directory, where the cipher tool scripts (for Windows and Linux) are stored. 

  3. Execute the cipher tool script from the command prompt using the command relevant to your OS: 

    • On LinuxWindows./ciphertool.sh bat -Dconfigure

    • On WindowsLinux./ciphertool.bat sh -Dconfigure

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

    Note

    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 plaintext passwords you specified in the cipher-text.properties file.

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

    Code Block
    UserManager.AdminUser.Password=[admin]

    If a password is not specified in the cipher-text.properties 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 Open the cipher-text.properties file and  file and see that the plain text passwords are replaced by a cipher value.

    • Open the Open the secret-conf.properties file from the  file from the <PRODUCT_HOME>/repository/conf/security/ folder and  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.

...


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 the cipher tool scripts (for Windows and Linux) are stored. 

  3. Execute the following command for your OS:

    • On Linux: ./ciphertool.sh -Dchange

    • On Windows: ./ciphertool.bat -Dchange

    Note

    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 cipher-text.properties file for automatic encryption.

  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.

...