1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.ftp.core.data.handler.ftps;
21
22 import io.netty.channel.ChannelPipeline;
23 import io.netty.channel.socket.SocketChannel;
24 import io.netty.handler.ssl.SslHandler;
25 import io.netty.handler.traffic.ChannelTrafficShapingHandler;
26 import org.waarp.common.crypto.ssl.WaarpSslUtility;
27 import org.waarp.ftp.core.command.FtpArgumentCode.TransferMode;
28 import org.waarp.ftp.core.command.FtpArgumentCode.TransferStructure;
29 import org.waarp.ftp.core.config.FtpConfiguration;
30 import org.waarp.ftp.core.control.ftps.FtpsInitializer;
31 import org.waarp.ftp.core.data.handler.DataBusinessHandler;
32 import org.waarp.ftp.core.data.handler.DataNetworkHandler;
33 import org.waarp.ftp.core.data.handler.FtpDataInitializer;
34 import org.waarp.ftp.core.data.handler.FtpDataModeCodec;
35
36
37
38
39 public class FtpsDataInitializer extends FtpDataInitializer {
40
41
42
43
44
45
46
47
48 public FtpsDataInitializer(
49 final Class<? extends DataBusinessHandler> dataBusinessHandler,
50 final FtpConfiguration configuration, final boolean active) {
51 super(dataBusinessHandler, configuration, active);
52 }
53
54
55
56
57 @Override
58 public void initChannel(final SocketChannel ch) throws Exception {
59 final ChannelPipeline pipeline = ch.pipeline();
60
61 final SslHandler sslHandler =
62 FtpsInitializer.waarpSslContextFactory.createHandlerServer(
63 FtpsInitializer.waarpSslContextFactory.needClientAuthentication(),
64 ch);
65 WaarpSslUtility.addSslOpenedChannel(ch);
66 pipeline.addLast("ssl", sslHandler);
67
68 pipeline.addLast(FtpDataInitializer.CODEC_MODE,
69 new FtpDataModeCodec(TransferMode.STREAM,
70 TransferStructure.FILE));
71 pipeline.addLast(FtpDataInitializer.CODEC_LIMIT,
72 configuration.getFtpInternalConfiguration()
73 .getGlobalTrafficShapingHandler());
74 final ChannelTrafficShapingHandler limitChannel =
75 configuration.getFtpInternalConfiguration()
76 .newChannelTrafficShapingHandler();
77 if (limitChannel != null) {
78 pipeline.addLast(FtpDataInitializer.CODEC_LIMIT + "CHANNEL",
79 limitChannel);
80 }
81 pipeline.addLast(FtpDataInitializer.CODEC_TYPE, ftpDataTypeCodec);
82 pipeline.addLast(FtpDataInitializer.CODEC_STRUCTURE, ftpDataStructureCodec);
83
84 final DataBusinessHandler newbusiness =
85 dataBusinessHandler.getDeclaredConstructor().newInstance();
86 final DataNetworkHandler newNetworkHandler =
87 new DataNetworkHandler(configuration, newbusiness, isActive);
88 pipeline.addLast(
89 configuration.getFtpInternalConfiguration().getDataExecutor(),
90 FtpDataInitializer.HANDLER, newNetworkHandler);
91 }
92 }