0

我有以下情况:

一个没有密码的 JKS 密钥库文件,其中包含一个也不受保护的私钥。我尝试配置 Rampart 以使用此密钥库,但我不断收到以下错误:

Caused by: org.apache.rampart.RampartException: No password supplied by the callback handler for the user : "username"

我的密码回调处理程序如下:

公共类 PWCBHandlerCertificate 实现 CallbackHandler {

public void handle( Callback[] callbacks ) throws IOException, UnsupportedCallbackException {

    for ( int i = 0; i < callbacks.length; i++ ) {
        WSPasswordCallback pwcb = (WSPasswordCallback) callbacks[i];

        String id = pwcb.getIdentifer();
        int usage = pwcb.getUsage();            
        if ( usage == WSPasswordCallback.DECRYPT || usage == WSPasswordCallback.SIGNATURE ) {                              
            Element temp = pwcb.getCustomToken();
            // used to retrieve password for private key
            if ( "username".equals( id ) ) {
                pwcb.setPassword( "" );
            }

        }
    }
}

}

我错过了什么?

提前致谢

4

1 回答 1

0

事实证明,壁垒 1.5.2(我不知道较新的版本,我必须保留这个......)强制证书具有有效的密码(非空且非空)。我下载了 Rampart 1.5.2 的源代码,并在 BindingBuilder.java 类(包 org.apache.rampart.builder)中找到了以下代码:

WSPasswordCallback[] cb = { new WSPasswordCallback(user,
                WSPasswordCallback.SIGNATURE) };

        try {
            handler.handle(cb);
            if(cb[0].getPassword() != null && !"".equals(cb[0].getPassword())) {                
                password = cb[0].getPassword();
                log.debug("Password : " + password);
            } else {
                //If there's no password then throw an exception
                throw new RampartException("noPasswordForUser", 
                        new String[]{user});
            }
        }

问题出在这里:

if(cb[0].getPassword() != null && !"".equals(cb[0].getPassword()))

如果从回调中接收到 null 或空密码,则会引发异常。为了避免这个问题,我不得不像这样注释掉部分代码:

if(cb[0].getPassword() != null /*&& !"".equals(cb[0].getPassword())*/)

我重新编译了该类并替换了rampart-core-1.5.2.jar中生成的.class

异常消失了,我现在可以成功使用无密码证书了。

我希望它有所帮助。

于 2019-10-03T15:42:38.517 回答