1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.waarp.ftp.core.control.ftps;
22
23 import io.netty.channel.Channel;
24 import io.netty.channel.ChannelHandlerContext;
25
26 import org.waarp.common.crypto.ssl.WaarpSslUtility;
27 import org.waarp.common.logging.WaarpLogger;
28 import org.waarp.common.logging.WaarpLoggerFactory;
29 import org.waarp.ftp.core.control.NetworkHandler;
30 import org.waarp.ftp.core.session.FtpSession;
31
32
33
34
35
36 public class SslNetworkHandler extends NetworkHandler {
37
38
39
40 private static final WaarpLogger logger = WaarpLoggerFactory.getLogger(SslNetworkHandler.class);
41
42
43
44
45 public SslNetworkHandler(FtpSession session) {
46 super(session);
47 }
48
49 @Override
50 public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
51 Channel channel = ctx.channel();
52 logger.debug("Add channel to ssl " + channel.toString());
53 WaarpSslUtility.addSslOpenedChannel(channel);
54 getFtpSession().prepareSsl();
55 super.channelRegistered(ctx);
56 }
57
58
59
60
61
62
63
64 protected void callForSnmp(String error1, String error2) {
65
66 }
67
68 @Override
69 public void channelActive(final ChannelHandlerContext ctx) throws Exception {
70 if (!WaarpSslUtility.waitForHandshake(ctx.channel())) {
71 callForSnmp("SSL Connection Error", "During Ssl Handshake");
72 getFtpSession().setSsl(false);
73 return;
74 } else {
75 getFtpSession().setSsl(true);
76 }
77 super.channelActive(ctx);
78 }
79
80 }