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