运行 ciphertool.sh 时传入carbon server的keystore密码 -Dconfigure NOT when prompted

Pass in keystore password of carbon server when running ciphertool.sh -Dconfigure NOT when prompted

我正在尝试 运行 ciphertool.sh -Dconfigure 命令来加密我的 WSO2 身份服务器中的密码。

我已经完成了 运行 命令的常规过程,然后在出现提示时输入密钥库密码。例如:

>./ciphertool.sh -Dconfigure

BUILD SUCCESSFUL
Total time: 20 seconds
Using CARBON_HOME:   C:\Program Files\WSO2\Identity Server.7.0
Using JAVA_HOME:    C:\Program Files\Java\jdk1.8.0_181
[Please Enter Primary KeyStore Password of Carbon Server : ]

我想让这个过程更加自动化,并在 运行 执行 ciphertool.sh -Dconfigure 命令时包括 Carbon 服务器的密钥库密码,而不是在显示提示时。

我知道您可以在解密密码时利用 password-tmp 文件,如下所述:https://docs.wso2.com/display/Carbon440/Resolving+Encrypted+Passwords

这样您就可以跳过提示输入密码的步骤。我们可以在加密密码时做类似的事情吗?

我尝试过的事情:

  1. "yes"命令:yes PASSWORD| $WSO2IS_HOME/bin/ciphertool.sh -Dconfigure
  2. 使用"echo":echo PASSWORD | $WSO2IS_HOME/bin/ciphertool.sh -Dconfigure
  3. 从文件重定向:$WSO2IS_HOME/bin/ciphertool.sh -Dconfigure < PASSWORD.txt

每次我 运行 这些命令时,ciphertool 脚本似乎无法识别我尝试输入的密码。错误如下所示:

Exception in thread "main" org.wso2.ciphertool.exception.CipherToolException: String cannot be null
        at org.wso2.ciphertool.utils.Utils.getValueFromConsole(Utils.java:54)
        at org.wso2.ciphertool.utils.KeyStoreUtil.initializeCipher(KeyStoreUtil.java:48)
        at org.wso2.ciphertool.CipherTool.main(CipherTool.java:53)

原来 WSO2 IS 支持这个。不过,我无法在任何地方找到它的记录。

CipherTool.java(https://github.com/wso2/cipher-tool/blob/master/components/ciphertool/src/main/java/org/wso2/ciphertool/CipherTool.java)中的initialize()方法有这段代码

private static void initialize(String[] args) {
    String property;
    for (String arg : args) {
        if (arg.equals("-help")) {
            printHelp();
            System.exit(0);
        } else if (arg.substring(0, 2).equals("-D")) {
            property = arg.substring(2);
            if (property.equals(Constants.CONFIGURE)) {
                System.setProperty(property, Constants.TRUE);
            } else if (property.equals(Constants.CHANGE)) {
                System.setProperty(property, Constants.TRUE);
            } else if (property.length() >= 8 && property.substring(0, 8).equals(Constants.CONSOLE_PASSWORD_PARAM)) {
                System.setProperty(Constants.KEYSTORE_PASSWORD, property.substring(9));
            } else {
                System.out.println("This option is not define!");
                System.exit(-1);
            }
        }
    }
    Utils.setSystemProperties();
}

Constants.CONSOLE_PASSWORD_PARAM 是 "password"。

因此传递密钥库密码的命令如下所示:

>./ciphertool.sh -Dconfigure -Dpassword=MY_PASSWORD