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.UnstableApi;
25
26 import javax.net.ssl.SSLHandshakeException;
27
28
29
30
31
32
33
34 @UnstableApi
35 public abstract class OcspClientHandler extends ChannelInboundHandlerAdapter {
36
37 private final ReferenceCountedOpenSslEngine engine;
38
39 protected OcspClientHandler(ReferenceCountedOpenSslEngine engine) {
40 this.engine = ObjectUtil.checkNotNull(engine, "engine");
41 }
42
43
44
45
46 protected abstract boolean verify(ChannelHandlerContext ctx, ReferenceCountedOpenSslEngine engine) throws Exception;
47
48 @Override
49 public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
50 if (evt instanceof SslHandshakeCompletionEvent) {
51 ctx.pipeline().remove(this);
52
53 SslHandshakeCompletionEvent event = (SslHandshakeCompletionEvent) evt;
54 if (event.isSuccess() && !verify(ctx, engine)) {
55 throw new SSLHandshakeException("Bad OCSP response");
56 }
57 }
58
59 ctx.fireUserEventTriggered(evt);
60 }
61 }