1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.ssl.ocsp;
17
18 import io.netty.channel.ChannelHandlerContext;
19 import io.netty.channel.ChannelInboundHandlerAdapter;
20 import io.netty.handler.ssl.ReferenceCountedOpenSslContext;
21 import io.netty.handler.ssl.ReferenceCountedOpenSslEngine;
22 import io.netty.handler.ssl.SslHandshakeCompletionEvent;
23 import io.netty.util.internal.ObjectUtil;
24 import io.netty.util.internal.ThrowableUtil;
25 import io.netty.util.internal.UnstableApi;
26
27 import javax.net.ssl.SSLHandshakeException;
28
29
30
31
32
33
34
35 @UnstableApi
36 public abstract class OcspClientHandler extends ChannelInboundHandlerAdapter {
37
38 private static final SSLHandshakeException OCSP_VERIFICATION_EXCEPTION = ThrowableUtil.unknownStackTrace(
39 new SSLHandshakeException("Bad OCSP response"), OcspClientHandler.class, "verify(...)");
40
41 private final ReferenceCountedOpenSslEngine engine;
42
43 protected OcspClientHandler(ReferenceCountedOpenSslEngine engine) {
44 this.engine = ObjectUtil.checkNotNull(engine, "engine");
45 }
46
47
48
49
50 protected abstract boolean verify(ChannelHandlerContext ctx, ReferenceCountedOpenSslEngine engine) throws Exception;
51
52 @Override
53 public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
54 if (evt instanceof SslHandshakeCompletionEvent) {
55 ctx.pipeline().remove(this);
56
57 SslHandshakeCompletionEvent event = (SslHandshakeCompletionEvent) evt;
58 if (event.isSuccess() && !verify(ctx, engine)) {
59 throw OCSP_VERIFICATION_EXCEPTION;
60 }
61 }
62
63 ctx.fireUserEventTriggered(evt);
64 }
65 }