Java Code Examples for javax.net.ssl.SSLSocket#setEnableSessionCreation()

The following examples show how to use javax.net.ssl.SSLSocket#setEnableSessionCreation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FTPSClient.java    From Aria with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: FTPClient.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void sslNegotiation() throws IOException {
    if(protocol.isSecure()) {
        final SSLSocket socket = (SSLSocket) sslSocketFactory.createSocket(_socket_,
                _socket_.getInetAddress().getHostAddress(), _socket_.getPort(), false);
        socket.setEnableSessionCreation(true);
        socket.setUseClientMode(true);
        socket.startHandshake();
        _socket_ = socket;
        _controlInput_ = new BufferedReader(new InputStreamReader(
                socket.getInputStream(), getControlEncoding()));
        _controlOutput_ = new BufferedWriter(new OutputStreamWriter(
                socket.getOutputStream(), getControlEncoding()));
    }
}
 
Example 3
Source File: SSLSocketTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * javax.net.ssl.SSLSocket#setEnableSessionCreation(boolean flag)
 * javax.net.ssl.SSLSocket#getEnableSessionCreation()
 */
public void j2objcNotImplemented_test_EnableSessionCreation() throws IOException {
    SSLSocket ssl = getSSLSocket();
    assertTrue(ssl.getEnableSessionCreation());
    ssl.setEnableSessionCreation(false);
    assertFalse(ssl.getEnableSessionCreation());
    ssl.setEnableSessionCreation(true);
    assertTrue(ssl.getEnableSessionCreation());
    ssl.close();
}
 
Example 4
Source File: FTPSClient.java    From Aria with Apache License 2.0 4 votes vote down vote up
/**
 * 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 host = (_hostname_ != null) ? _hostname_ : getRemoteAddress().getHostAddress();
  int port = _socket_.getPort();
  SSLSocket socket = (SSLSocket) ssf.createSocket(_socket_, host, port, false);
  socket.setEnableSessionCreation(isCreation);
  socket.setUseClientMode(isClientMode);

  // client mode
  if (isClientMode) {
    if (tlsEndpointChecking) {
      SSLSocketUtils.enableEndpointNameVerification(socket);
    }
  } else { // server mode
    socket.setNeedClientAuth(isNeedClientAuth);
    socket.setWantClientAuth(isWantClientAuth);
  }

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

  // TODO the following setup appears to duplicate that in the super class methods
  _socket_ = socket;
  _controlInput_ =
      new BufferedReader(new InputStreamReader(socket.getInputStream(), getControlEncoding()));
  _controlOutput_ =
      new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), getControlEncoding()));

  if (isClientMode) {
    if (hostnameVerifier != null && !hostnameVerifier.verify(host, socket.getSession())) {
      throw new SSLHandshakeException("Hostname doesn't match certificate");
    }
  }
}