【问题标题】:Getting client ip when doing ocsp in Netty在 Netty 中进行 ocsp 时获取客户端 IP
【发布时间】:2019-04-09 00:58:33
【问题描述】:

我正在与 Netty 建立安全的 tls 连接。我在我的连接上使用相互身份验证。来自客户端的证书使用 ocsp 进行验证。

使用 Ocsp 的验证过程与我将 netty 定义为信任库的方式相同。

如果客户端的证书被撤销或未知,则从 tcp 断开连接。到目前为止,一切顺利。

当证书被撤销或未知时,我想将客户端的 ip 打印到日志中。我尝试了很多东西,但我做不到。

你能帮帮我吗?

构建器按以下方式构建。 我的 ocsp 代码在 WebSocketTrustManagerFactory 类中:

builder = SslContextBuilder
         .forServer(kmf)
         .clientAuth(ClientAuth.REQUIRE)
         .trustManager(new WebSocketTrustManagerFactory(finalTm));

【问题讨论】:

    标签: ip client netty mutual-authentication ocsp


    【解决方案1】:

    我想你可以检查一下 SslHandshakeCompletionEvent 并记录它是否失败。

    有点像:

    public void class MyHandler extends ChannelInboundHandlerAdapter {
    
        @Override
        public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
            if (evt instance of SslHandshakeCompletionEvent) {
                SslHandshakeCompletionEvent sslEvent = (SslHandshakeCompletionEvent) evt;
                if (!sslEvent.isSuccessful()) {
                    Throwable cause = sslEvent.cause();
                    logger.debug("Handshake failed for {}", ctx.channel().remoteAddress(), cause);
                }
            }
            ctx.fireUserEvent(evt);
        }
    }
    

    【讨论】:

    • 我认为“ctx.channel().remoteAddress()”会给我负载均衡器的 ip。我想我需要从 http 包中获取 x-forwarded-for 。你对此有什么想法吗?
    • 如果握手失败则还没有http头。
    猜你喜欢
    • 2016-10-07
    • 2015-06-06
    • 2020-11-10
    • 2018-02-13
    • 2016-12-03
    • 2020-12-08
    • 1970-01-01
    • 2017-08-11
    • 1970-01-01
    相关资源
    最近更新 更多