使用 Axis2 附加客户端证书?

发布于 2024-12-23 02:33:06 字数 193 浏览 1 评论 0 原文

是否可以轻松地将客户端证书附加到使用 wsdl2java 生成的 Axis2 存根?我需要根据每个请求动态更改客户端证书,因此简单地将其存储在密钥库中不适用于我们的情况。

我找到了针对非 SOAP 调用执行此操作的示例,但找不到与使用 Axis 客户端存根相关的任何内容。我想,尝试破解 SOAP 调用的 XML 是一种选择,尽管这是一种痛苦的选择!呻吟!

Is it possible to easily attach a client certificate to a Axis2 stub generated using wsdl2java? I need to change the client certificate dynamically on a per-request basis, so simply storing it in the keystore won't work for our case.

I've found examples where this is being done for non-SOAP calls, but could not find anything related to using the Axis client stubs. Trying to hack the XML for the SOAP call is an option I guess, albiet a painful one! Groan!

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

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

发布评论

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

评论(1

此生挚爱伱 2024-12-30 02:33:06

如果您想根据建立的连接更改使用哪个证书,则需要配置 SSLContext 来执行此操作,如以下答案中所述:https://stackoverflow.com/a/3713147/372643

据我所知,Axis 2 使用 Apache HttpClient 3.x,因此,您需要遵循其配置 SSLContext 的方式(如果需要,还需要配置 X509KeyManager)。
最简单的方法可能是使用 SSLContext 配置 Apache HttpClient 的全局 https 协议处理程序,并使用配置为选择客户端证书的 X509KeyManager 进行设置您需要(通过chooseClientAlias)。

如果颁发者和连接的套接字(可能是远程地址)不足以决定选择哪个证书,您可能需要实现更复杂的逻辑,这几乎不可避免地需要与其余部分仔细同步。您的申请。

编辑

构建 SSLContextX509KeyManager 后,您需要将它们传递给 Apache HttpClient 3.x。为此,您可以构建自己的 SecureProtocolSocketFactory,它将从此 SSLContext 构建套接字(通过 SSLSocketFactory,请参阅SSLContext 方法)。 Apache HttpClient 3.x SSL 指南中提供了示例。避免使用 EasySSLProtocolSocketFactory,因为它不会检查任何服务器证书(从而允许 MITM 攻击)。您还可以尝试 此实现

请注意,您只需要自定义您的 X509KeyManager,您可以使用 null 初始化您的 SSLContext(通过 init)其他参数保留默认值(特别是默认信任设置)。

然后,使用如下所示为 Apache HttpClient 3.x 全局“安装”此 SecureProtocolSocketFactory

Protocol.registerProtocol("https", new Protocol("https",
   (ProtocolSocketFactory)secureProtocolSocketFactory, 443));

If you want to change which certificate is used depending on which connection is made, you'll need to configure an SSLContext to do so, as described in this answer: https://stackoverflow.com/a/3713147/372643

As far as I know, Axis 2 uses Apache HttpClient 3.x, so you'll need to follow its way of configuring the SSLContext (and X509KeyManager if needed).
The easiest way might be to configure Apache HttpClient's global https protocol handler with your SSLContext, set up with an X509KeyManager configured to choose the client certificate as you require (via chooseClientAlias).

If the issuers and the connected Socket (probably the remote address) are not enough for deciding which certificate to choose, you may need to implement a more complex logic which will almost inevitably require careful synchronization with the rest of your application.

EDIT:

Once you've built your SSLContext and X509KeyManager, you need to pass them to Apache HttpClient 3.x. For this, you can build your own SecureProtocolSocketFactory, which will build the socket from this SSLContext (via an SSLSocketFactory, see SSLContext methods). There are examples in the Apache HttpClient 3.x SSL guide. Avoid EasySSLProtocolSocketFactory, since it won't check any server cert (thereby allowing for MITM attacks). You could also try this implementation.

Note that you only really need to customize your X509KeyManager, you can initialize your SSLContext (via init) with null for the other parameters to keep the default values (in particular the default trust settings).

Then, "install" this SecureProtocolSocketFactory globally for Apache HttpClient 3.x using something like this:

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