首页 > 解决方案 > 运行 ciphertool.sh 时传入 carbon server 的密钥库密码 -Dconfigure NOT 提示时

问题描述

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

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

>./ciphertool.sh -Dconfigure

BUILD SUCCESSFUL
Total time: 20 seconds
Using CARBON_HOME:   C:\Program Files\WSO2\Identity Server\5.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 服务器的密钥库密码,而不是在显示提示时。

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

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

我尝试过的事情:

  1. “是”命令:yes PASSWORD| $WSO2IS_HOME/bin/ciphertool.sh -Dconfigure
  2. 使用“回声”: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)

标签: wso2is

解决方案


事实证明 WSO2 IS 支持这一点。我无法在任何地方找到它的记录。

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

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是“密码”。

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

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


推荐阅读