View Javadoc
1   /**
2    * This file is part of Waarp Project.
3    * 
4    * Copyright 2009, Frederic Bregier, and individual contributors by the @author tags. See the
5    * COPYRIGHT.txt in the distribution for a full listing of individual contributors.
6    * 
7    * All Waarp Project is free software: you can redistribute it and/or modify it under the terms of
8    * the GNU General Public License as published by the Free Software Foundation, either version 3 of
9    * the License, or (at your option) any later version.
10   * 
11   * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12   * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13   * Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License along with Waarp . If not, see
16   * <http://www.gnu.org/licenses/>.
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   * @author Frederic Bregier
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          // Add SSL handler first to encrypt and decrypt everything.
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  }