javax.net.ssl.SSLSocketFactory.createSocket()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(208)

本文整理了Java中javax.net.ssl.SSLSocketFactory.createSocket()方法的一些代码示例,展示了SSLSocketFactory.createSocket()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SSLSocketFactory.createSocket()方法的具体详情如下:
包路径:javax.net.ssl.SSLSocketFactory
类名称:SSLSocketFactory
方法名:createSocket

SSLSocketFactory.createSocket介绍

[英]Creates an SSLSocket over the specified socket that is connected to the specified host at the specified port.
[中]在指定端口连接到指定主机的指定套接字上创建SSLSocket。

代码示例

代码示例来源:origin: square/okhttp

private void processHandshakeFailure(Socket raw) throws Exception {
 SSLContext context = SSLContext.getInstance("TLS");
 context.init(null, new TrustManager[] {UNTRUSTED_TRUST_MANAGER}, new SecureRandom());
 SSLSocketFactory sslSocketFactory = context.getSocketFactory();
 SSLSocket socket = (SSLSocket) sslSocketFactory.createSocket(
   raw, raw.getInetAddress().getHostAddress(), raw.getPort(), true);
 try {
  socket.startHandshake(); // we're testing a handshake failure
  throw new AssertionError();
 } catch (IOException expected) {
 }
 socket.close();
}

代码示例来源:origin: apache/zookeeper

public SSLSocket createSSLSocket(Socket socket, byte[] pushbackBytes) throws IOException {
  SSLSocket sslSocket;
  if (pushbackBytes != null && pushbackBytes.length > 0) {
    sslSocket = (SSLSocket) sslContext.getSocketFactory().createSocket(
        socket, new ByteArrayInputStream(pushbackBytes), true);
  } else {
    sslSocket = (SSLSocket) sslContext.getSocketFactory().createSocket(
        socket, null, socket.getPort(), true);
  }
  return configureSSLSocket(sslSocket, false);
}

代码示例来源:origin: shyiko/mysql-binlog-connector-java

@Override
public SSLSocket createSocket(Socket socket) throws SocketException {
  SSLContext sc;
  try {
    sc = SSLContext.getInstance(this.protocol);
    initSSLContext(sc);
  } catch (GeneralSecurityException e) {
    throw new SocketException(e.getMessage());
  }
  try {
    return (SSLSocket) sc.getSocketFactory()
      .createSocket(socket, socket.getInetAddress().getHostName(), socket.getPort(), true);
  } catch (IOException e) {
    throw new SocketException(e.getMessage());
  }
}

代码示例来源:origin: oblac/jodd

socket = socketFactory.createSocket(host, port);
  sslSocket = (SSLSocket) ((SSLSocketFactory)socketFactory).createSocket(socket, host, port, true);
  sslSocket = (SSLSocket) (getDefaultSSLSocketFactory(trustAll)).createSocket(socket, host, port, true);

代码示例来源:origin: apache/cloudstack

@Override
public void upgradeToSsl() {
  if (sslSocket != null)
    // Already upgraded
    return;
  if (verbose)
    System.out.println("[" + this + "] INFO: Upgrading socket to SSL.");
  try {
    // Use most secure implementation of SSL available now.
    // JVM will try to negotiate TLS1.2, then will fallback to TLS1.0, if
    // TLS1.2 is not supported.
    SSLContext sslContext = SSLUtils.getSSLContext();
    // Trust all certificates (FIXME: insecure)
    sslContext.init(null, new TrustManager[] {new TrustAllX509TrustManager(sslState)}, null);
    SSLSocketFactory sslSocketFactory = new SecureSSLSocketFactory(sslContext);
    sslSocket = (SSLSocket)sslSocketFactory.createSocket(socket, address.getHostName(), address.getPort(), true);
    sslSocket.setEnabledProtocols(SSLUtils.getSupportedProtocols(sslSocket.getEnabledProtocols()));
    sslSocket.startHandshake();
    InputStream sis = sslSocket.getInputStream();
    source.setInputStream(sis);
    OutputStream sos = sslSocket.getOutputStream();
    sink.setOutputStream(sos);
  } catch (Exception e) {
    throw new RuntimeException("Cannot upgrade socket to SSL: " + e.getMessage(), e);
  }
}

代码示例来源:origin: i2p/i2p.i2p

_proxy = _sslContext.getSocketFactory().createSocket(_proxy, host, port, true);
else
  _proxy = ((SSLSocketFactory) SSLSocketFactory.getDefault()).createSocket(_proxy, host, port, true);
if (_log.shouldLog(Log.DEBUG))
  _log.debug(_proxyType + " proxy headers read completely");
  _proxy = _sslContext.getSocketFactory().createSocket(host, port);
else
  _proxy = SSLSocketFactory.getDefault().createSocket(host, port);
if (_fetchHeaderTimeout > 0) {
  _proxy.setSoTimeout(_fetchHeaderTimeout);

代码示例来源:origin: frohoff/ysoserial

public Socket createSocket(String host, int port) throws IOException {
    try {
      SSLContext ctx = SSLContext.getInstance("TLS");
      ctx.init(null, new TrustManager[] {new TrustAllSSL()}, null);
      SSLSocketFactory factory = ctx.getSocketFactory();
      return factory.createSocket(host, port);
    } catch(Exception e) {
      throw new IOException(e);
    }
  }
}

代码示例来源:origin: wildfly/wildfly

public Socket createSSLSocket(String host, int port) throws IOException {
  InetAddress address = InetAddress.getByName(host);
  javax.net.ssl.SSLSocketFactory socketFactory = this.clientSSLContext.getSocketFactory();
  return socketFactory.createSocket(address, port);
}

代码示例来源:origin: stackoverflow.com

return makeSocketSafe(delegate.createSocket(s, host, port, autoClose));
return makeSocketSafe(delegate.createSocket(host, port));
return makeSocketSafe(delegate.createSocket(host, port, localHost, localPort));
return makeSocketSafe(delegate.createSocket(host, port));

代码示例来源:origin: stackoverflow.com

SSLContext sslContext = SSLContext.getInstance("TLS");
  sslContext.init(null, new TrustManager[] { tm }, null);
  return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
  return sslContext.getSocketFactory().createSocket();

代码示例来源:origin: jeremylong/DependencyCheck

/**
 * Creates a new SSL Socket.
 *
 * @param host the host to connect to
 * @param port the port to connect to
 * @return the SSL Socket
 * @throws IOException thrown if the creation fails
 */
@Override
public Socket createSocket(InetAddress host, int port) throws IOException {
  final SSLSocketFactory factory = sslCtxt.getSocketFactory();
  final SSLSocket ss = (SSLSocket) factory.createSocket(host, port);
  ss.setEnabledProtocols(protocols);
  return ss;
}

代码示例来源:origin: stackoverflow.com

return makeSocketSafe(delegate.createSocket(s, host, port, autoClose));
return makeSocketSafe(delegate.createSocket(host, port));
return makeSocketSafe(delegate.createSocket(host, port, localHost, localPort));
return makeSocketSafe(delegate.createSocket(host, port));

代码示例来源:origin: k9mail/k-9

@Override
  public Socket createSocket(Socket socket, String host, int port, String clientCertificateAlias)
      throws NoSuchAlgorithmException, KeyManagementException, MessagingException, IOException {

    TrustManager[] trustManagers = new TrustManager[] { new VeryTrustingTrustManager(serverCertificate) };

    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, trustManagers, null);

    SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
    return sslSocketFactory.createSocket(
        socket,
        socket.getInetAddress().getHostAddress(),
        socket.getPort(),
        true);
  }
}

代码示例来源:origin: jeremylong/DependencyCheck

/**
 * Creates a new SSL Socket.
 *
 * @param host the host to connect to
 * @param port the port to connect to
 * @return the SSL Socket
 * @throws IOException thrown if the creation fails
 */
@Override
public Socket createSocket(String host, int port) throws IOException {
  final SSLSocketFactory factory = sslCtxt.getSocketFactory();
  final SSLSocket ss = (SSLSocket) factory.createSocket(host, port);
  ss.setEnabledProtocols(protocols);
  return ss;
}

代码示例来源:origin: stackoverflow.com

return makeSocketSafe(delegate.createSocket(s, host, port, autoClose));
return makeSocketSafe(delegate.createSocket(host, port));
return makeSocketSafe(delegate.createSocket(host, port, localHost, localPort));
return makeSocketSafe(delegate.createSocket(host, port));

代码示例来源:origin: stackoverflow.com

protected SSLContext sslContext = SSLContext.getInstance("TLS");
  sslContext.init(null, new TrustManager[]{new AdditionalKeyStoresTrustManager(keyStore)}, null);
  return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
  return sslContext.getSocketFactory().createSocket();

代码示例来源:origin: apache/zookeeper

public SSLSocket createSSLSocket() throws IOException {
  return configureSSLSocket((SSLSocket) sslContext.getSocketFactory().createSocket(), true);
}

代码示例来源:origin: eclipse/paho.mqtt.java

socket = ((SSLSocketFactory)factory).createSocket(tempsocket, host, port, true);
} else {
  socket = factory.createSocket();
  socket.connect(sockaddr, conTimeout*1000);

代码示例来源:origin: stackoverflow.com

SSLContext sslContext = SSLContext.getInstance("TLS");
  sslContext.init(null, new TrustManager[] { tm }, null);
  return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
  return sslContext.getSocketFactory().createSocket();

代码示例来源:origin: jeremylong/DependencyCheck

/**
 * Creates an SSL Socket.
 *
 * @param s the base socket
 * @param host the host
 * @param port the port
 * @param autoClose if the socket should auto-close
 * @return the SSL Socket
 * @throws IOException thrown if the creation fails
 */
@Override
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
  final SSLSocketFactory factory = sslCtxt.getSocketFactory();
  final SSLSocket ss = (SSLSocket) factory.createSocket(s, host, port, autoClose);
  ss.setEnabledProtocols(protocols);
  return ss;
}

相关文章