Exemple #1
0
  /**
   * SSL/TLS negotiation. Acquires an SSL socket of a control connection and carries out handshake
   * processing.
   *
   * @throws IOException If server negotiation fails
   */
  protected void sslNegotiation() throws IOException {
    plainSocket = _socket_;
    initSslContext();

    SSLSocketFactory ssf = context.getSocketFactory();
    String ip = _socket_.getInetAddress().getHostAddress();
    int port = _socket_.getPort();
    SSLSocket socket = (SSLSocket) ssf.createSocket(_socket_, ip, port, false);
    socket.setEnableSessionCreation(isCreation);
    socket.setUseClientMode(isClientMode);
    // server mode
    if (!isClientMode) {
      socket.setNeedClientAuth(isNeedClientAuth);
      socket.setWantClientAuth(isWantClientAuth);
    }

    if (protocols != null) {
      socket.setEnabledProtocols(protocols);
    }
    if (suites != null) {
      socket.setEnabledCipherSuites(suites);
    }
    socket.startHandshake();

    _socket_ = socket;
    _controlInput_ =
        new BufferedReader(new InputStreamReader(socket.getInputStream(), getControlEncoding()));
    _controlOutput_ =
        new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), getControlEncoding()));
  }
Exemple #2
0
  /**
   * Returns a socket of the data connection. Wrapped as an {@link SSLSocket}, which carries out
   * handshake processing.
   *
   * @param command The textual representation of the FTP command to send.
   * @param arg The arguments to the FTP command. If this parameter is set to null, then the command
   *     is sent with no arguments.
   * @return corresponding to the established data connection. Null is returned if an FTP protocol
   *     error is reported at any point during the establishment and initialization of the
   *     connection.
   * @throws IOException If there is any problem with the connection.
   * @see FTPClient#_openDataConnection_(int, String)
   * @since 3.2
   */
  @Override
  protected Socket _openDataConnection_(String command, String arg) throws IOException {
    Socket socket = super._openDataConnection_(command, arg);
    _prepareDataSocket_(socket);
    if (socket instanceof SSLSocket) {
      SSLSocket sslSocket = (SSLSocket) socket;

      sslSocket.setUseClientMode(isClientMode);
      sslSocket.setEnableSessionCreation(isCreation);

      // server mode
      if (!isClientMode) {
        sslSocket.setNeedClientAuth(isNeedClientAuth);
        sslSocket.setWantClientAuth(isWantClientAuth);
      }
      if (suites != null) {
        sslSocket.setEnabledCipherSuites(suites);
      }
      if (protocols != null) {
        sslSocket.setEnabledProtocols(protocols);
      }
      sslSocket.startHandshake();
    }

    return socket;
  }
 public void setWantClientAuth(final boolean want) {
   delegate.setWantClientAuth(want);
 }