Web 服务安全和 Windows 证书

发布于 2024-10-04 02:30:07 字数 175 浏览 6 评论 0原文

我想使用 Apache CXF 和 WSS4J 签署 Web 服务请求。据我所知,我需要一个包含我想要用于签名的证书的 JKS 存储。 要求能够使用 Windows 证书存储中的 X.509 证书。签署 Web 服务请求时应从存储中读取证书。 我知道如何访问商店并获取证书。但是我如何使用它来代替我自己的 JKS 商店中的证书进行签名?

I want to sign webservice requests using Apache CXF and WSS4J. As far as I know, I would need a JKS store containing the certificate I want to use for signing.
There's the requirement to be able to use a X.509 certificate from the Windows certificate store. The certificate shall be read from the store at the time of signing the webservice request.
I know how to access the store and get the certificate. But how can I use it for signing instead of the certificate from my own JKS store?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

缱绻入梦 2024-10-11 02:30:07

KeyStore 不必是 JKS 密钥库。您可以编写自己的 JCA 提供程序并实现 KeyStoreSpi,并让它访问 Windows 证书存储。

The KeyStore need not be a JKS one. You might write your own JCA Provider and implement KeyStoreSpi, and have it access the Windows certificate store.

往昔成烟 2024-10-11 02:30:07

刚刚发现可以使用 MerlinDevice 类来实现。
它是这样完成的:

1) 配置 WSS4JOutInterceptor 的属性:

Map<String,Object> outProps = new HashMap<String,Object>();
outProps.put(WSHandlerConstants.ACTION, "Signature");
outProps.put(WSHandlerConstants.USER, "Friendly_name_of_your_certificate");
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, StupidCallback.class.getName());
outProps.put(WSHandlerConstants.SIG_PROP_FILE, "client_sign.properties");
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);

2) client_sign.properties 文件如下所示:

org.apache.ws.security.crypto.provider=org.apache.wss4j.common.crypto.MerlinDevice
keystore.provider=SunMSCAPI
cert.provider=SunMSCAPI
keystore.type=Windows-MY
truststore.type=Windows-ROOT

3) 并且 StupidCallback 只是返回常量字符串作为密码(它的值并不重要):

public class StupidCallback implements CallbackHandler
{
    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
    {
        WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
        pc.setPassword("password");
    }
}

仅此而已。

Just found it's possible to achieve using MerlinDevice class.
That's how its done:

1) Configuring properties for WSS4JOutInterceptor:

Map<String,Object> outProps = new HashMap<String,Object>();
outProps.put(WSHandlerConstants.ACTION, "Signature");
outProps.put(WSHandlerConstants.USER, "Friendly_name_of_your_certificate");
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, StupidCallback.class.getName());
outProps.put(WSHandlerConstants.SIG_PROP_FILE, "client_sign.properties");
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);

2) The client_sign.properties file looks like this:

org.apache.ws.security.crypto.provider=org.apache.wss4j.common.crypto.MerlinDevice
keystore.provider=SunMSCAPI
cert.provider=SunMSCAPI
keystore.type=Windows-MY
truststore.type=Windows-ROOT

3) And StupidCallback just returns constant string as a password (its value doesn't really matter):

public class StupidCallback implements CallbackHandler
{
    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
    {
        WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
        pc.setPassword("password");
    }
}

That's all.

过期以后 2024-10-11 02:30:07

查看 此内容,其中解释了如何使用 Windows 密钥库。然后您必须配置 CXF 以使用该密钥库。

Look at this that explains how to use the windows keystore. Then you have to configure CXF to use that keystore.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文