View Javadoc

1   /**
2      This file is part of Waarp Project.
3   
4      Copyright 2009, Frederic Bregier, and individual contributors by the @author
5      tags. See the COPYRIGHT.txt in the distribution for a full listing of
6      individual contributors.
7   
8      All Waarp Project is free software: you can redistribute it and/or 
9      modify it under the terms of the GNU General Public License as published 
10     by the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12  
13     Waarp is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17  
18     You should have received a copy of the GNU General Public License
19     along with Waarp .  If not, see <http://www.gnu.org/licenses/>.
20   */
21  package org.waarp.ftp.core.control.ftps;
22  
23  import io.netty.channel.ChannelPipeline;
24  import io.netty.channel.socket.SocketChannel;
25  import io.netty.handler.codec.DelimiterBasedFrameDecoder;
26  import io.netty.handler.ssl.SslHandler;
27  import io.netty.util.concurrent.EventExecutorGroup;
28  
29  import org.waarp.common.crypto.ssl.WaarpSecureKeyStore;
30  import org.waarp.common.crypto.ssl.WaarpSslContextFactory;
31  import org.waarp.ftp.core.config.FtpConfiguration;
32  import org.waarp.ftp.core.control.BusinessHandler;
33  import org.waarp.ftp.core.control.FtpInitializer;
34  import org.waarp.ftp.core.session.FtpSession;
35  
36  /**
37   * @author "Frederic Bregier"
38   *
39   */
40  public class FtpsInitializer extends FtpInitializer {
41  
42      public static WaarpSslContextFactory waarpSslContextFactory;
43      public static WaarpSecureKeyStore waarpSecureKeyStore;
44  
45      /**
46       * Constructor which Initializes some data for Server only
47       * 
48       * @param businessHandler
49       * @param configuration
50       */
51      public FtpsInitializer(Class<? extends BusinessHandler> businessHandler,
52              FtpConfiguration configuration) {
53          super(businessHandler, configuration);
54      }
55  
56      /**
57       * Create the pipeline with Handler, ObjectDecoder, ObjectEncoder.
58       * 
59       */
60      @Override
61      public void initChannel(SocketChannel ch) throws Exception {
62          ChannelPipeline pipeline = ch.pipeline();
63          // Server: no renegotiation still, but possible clientAuthent
64          SslHandler handler = waarpSslContextFactory.initInitializer(true,
65                  waarpSslContextFactory.needClientAuthentication());
66          pipeline.addLast("SSL", handler);
67          // Add the text line codec combination first,
68          pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, delimiter));
69          pipeline.addLast("decoder", ftpControlStringDecoder);
70          pipeline.addLast("encoder", ftpControlStringEncoder);
71          // Threaded execution for business logic
72  
73          EventExecutorGroup executorGroup = configuration.getFtpInternalConfiguration().getExecutor();
74          // and then business logic. New one on every connection
75          BusinessHandler newbusiness = businessHandler.newInstance();
76          SslNetworkHandler newNetworkHandler = new SslNetworkHandler(new FtpSession(
77                  configuration, newbusiness));
78          pipeline.addLast(executorGroup, "handler", newNetworkHandler);
79      }
80  }