1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.waarp.gateway.ftp.adminssl;
19
20 import io.netty.channel.ChannelPipeline;
21 import io.netty.channel.ChannelInitializer;
22 import io.netty.channel.socket.SocketChannel;
23 import io.netty.handler.codec.http.HttpContentCompressor;
24 import io.netty.handler.codec.http.HttpObjectAggregator;
25 import io.netty.handler.codec.http.HttpServerCodec;
26 import io.netty.handler.ssl.SslHandler;
27 import io.netty.handler.stream.ChunkedWriteHandler;
28
29 import org.waarp.common.crypto.ssl.WaarpSecureKeyStore;
30 import org.waarp.common.crypto.ssl.WaarpSslContextFactory;
31 import org.waarp.gateway.ftp.config.FileBasedConfiguration;
32
33
34
35
36
37 public class HttpSslInitializer extends ChannelInitializer<SocketChannel> {
38 public static WaarpSslContextFactory waarpSslContextFactory;
39 public static WaarpSecureKeyStore waarpSecureKeyStore;
40 private boolean useHttpCompression = false;
41
42 public HttpSslInitializer(boolean useHttpCompression) {
43 this.useHttpCompression = useHttpCompression;
44 }
45
46 @Override
47 protected void initChannel(SocketChannel ch) {
48 final ChannelPipeline pipeline = ch.pipeline();
49
50 SslHandler sslhandler = waarpSslContextFactory.initInitializer(true, false);
51 pipeline.addLast("ssl", sslhandler);
52
53 pipeline.addLast("codec", new HttpServerCodec());
54 pipeline.addLast("aggregator", new HttpObjectAggregator(1048576));
55 pipeline.addLast("streamer", new ChunkedWriteHandler());
56 if (useHttpCompression) {
57 pipeline.addLast("deflater", new HttpContentCompressor());
58 }
59 pipeline.addLast(FileBasedConfiguration.fileBasedConfiguration.getHttpPipelineExecutor(), "handler",
60 new HttpSslHandler());
61 }
62 }