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

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

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

SSLContext.getServerSocketFactory介绍

[英]Returns a server socket factory for this instance.
[中]返回此实例的服务器套接字工厂。

代码示例

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

protected SSLServerSocketFactory engineGetServerSocketFactory() {
  return delegate.getServerSocketFactory();
}

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

public ServerSocket createSSLServerSocket(int port, int backlog, InetAddress inetAddress) throws IOException {
  SSLServerSocketFactory serverSocketFactory = this.serverSSLContext.getServerSocketFactory();
  return serverSocketFactory.createServerSocket(port, backlog, inetAddress);
}

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

public SSLServerSocket createSSLServerSocket(int port) throws IOException {
  SSLServerSocket sslServerSocket =
      (SSLServerSocket) sslContext.getServerSocketFactory().createServerSocket(port);
  return configureSSLServerSocket(sslServerSocket);
}

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

public SSLServerSocket createSSLServerSocket() throws IOException {
  SSLServerSocket sslServerSocket =
      (SSLServerSocket) sslContext.getServerSocketFactory().createServerSocket();
  return configureSSLServerSocket(sslServerSocket);
}

代码示例来源:origin: NanoHttpd/nanohttpd

/**
 * Creates an SSLSocketFactory for HTTPS. Pass a loaded KeyStore and an
 * array of loaded KeyManagers. These objects must properly
 * loaded/initialized by the caller.
 */
public static SSLServerSocketFactory makeSSLSocketFactory(KeyStore loadedKeyStore, KeyManager[] keyManagers) throws IOException {
  SSLServerSocketFactory res = null;
  try {
    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(loadedKeyStore);
    SSLContext ctx = SSLContext.getInstance("TLS");
    ctx.init(keyManagers, trustManagerFactory.getTrustManagers(), null);
    res = ctx.getServerSocketFactory();
  } catch (Exception e) {
    throw new IOException(e.getMessage());
  }
  return res;
}

代码示例来源:origin: cSploit/android

private SSLServerSocket getSSLSocket() throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyManagementException{
 KeyStore keyStore = KeyStore.getInstance("PKCS12");
 keyStore.load(mContext.getAssets().open(KEYSTORE_FILE), KEYSTORE_PASS.toCharArray());
 KeyManagerFactory keyMan = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
 keyMan.init(keyStore, KEYSTORE_PASS.toCharArray());
 SSLContext sslContext = SSLContext.getInstance("TLS");
 sslContext.init(keyMan.getKeyManagers(), null, null);
 SSLServerSocketFactory sslFactory = sslContext.getServerSocketFactory();
 return (SSLServerSocket) sslFactory.createServerSocket(mPort, BACKLOG, mAddress);
}

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

/** {@inheritDoc} */
@Override protected SSLServerSocketFactory engineGetServerSocketFactory() {
  return new SSLServerSocketFactoryWrapper(delegate.getServerSocketFactory(), parameters);
}

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

@Override
protected SSLServerSocketFactory engineGetServerSocketFactory() {
  return matcher.getDefaultContext().getServerSocketFactory();
}

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

@Override
protected SSLServerSocketFactory engineGetServerSocketFactory() {
  return matcher.getDefaultContext().getServerSocketFactory();
}

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

public SslServerSocketFactory(final NiFiProperties nifiProperties) {
  final SSLContext sslCtx = SslContextFactory.createSslContext(nifiProperties);
  if (sslCtx == null) {
    try {
      sslServerSocketFactory = SSLContext.getDefault().getServerSocketFactory();
    } catch (final NoSuchAlgorithmException nsae) {
      throw new SslServerSocketFactoryCreationException(nsae);
    }
  } else {
    sslServerSocketFactory = sslCtx.getServerSocketFactory();
  }
}

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

private ServerSocket createServerSocket() throws IOException {
  final InetAddress inetAddress = hostname == null ? null : InetAddress.getByName(hostname);
  if (sslContext == null) {
    return new ServerSocket(port, 50, InetAddress.getByName(hostname));
  } else {
    final ServerSocket serverSocket = sslContext.getServerSocketFactory().createServerSocket(port, 50, inetAddress);
    ((SSLServerSocket) serverSocket).setNeedClientAuth(true);
    return serverSocket;
  }
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * Returns a configured SSLServerSocketFactory.
 *
 * @return the configured SSLSocketFactory.
 * @throws GeneralSecurityException thrown if the SSLSocketFactory could not
 * be initialized.
 * @throws IOException thrown if and IO error occurred while loading
 * the server keystore.
 */
public SSLServerSocketFactory createSSLServerSocketFactory()
 throws GeneralSecurityException, IOException {
 if (mode != Mode.SERVER) {
  throw new IllegalStateException(
    "Factory is not in SERVER mode. Actual mode is " + mode.toString());
 }
 return context.getServerSocketFactory();
}

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

/**
 * Returns the list of default "enabled" ciphers for server TLS connections, as reported by the default Java security provider.
 * This is most likely a subset of "available" ciphers.
 *
 * @return list of default server ciphers, or an empty list if the default cipher list cannot be loaded
 */
public static List<String> getEnabledJdkCipherSuites() {
  try {
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, null, null);
    String[] defaultCiphers = sslContext.getServerSocketFactory().getDefaultCipherSuites();
    return Arrays.asList(defaultCiphers);
  } catch (Throwable t) {
    log.info("Unable to load default JDK server cipher list from SSLContext");
    // log the actual exception for debugging
    log.debug("An error occurred while initializing an SSLContext or ServerSocketFactory", t);
    return Collections.emptyList();
  }
}

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

protected SSLServerSocket createServerSocket() throws Exception {
  SSLContext ctx=getContext();
  SSLServerSocketFactory sslServerSocketFactory=ctx.getServerSocketFactory();
  SSLServerSocket sslServerSocket=null;
  for(int i=0; i < port_range; i++) {
    try {
      sslServerSocket=(SSLServerSocket)sslServerSocketFactory.createServerSocket(port + i, 50, bind_addr);
      sslServerSocket.setNeedClientAuth(require_client_authentication);
      return sslServerSocket;
    }
    catch(Throwable t) {
    }
  }
  throw new IllegalStateException(String.format("found no valid port to bind to in range [%d-%d]", port, port+port_range));
}

代码示例来源:origin: ch.qos.logback/logback-classic

/**
 * Creates a new server using a custom SSL context.
 * @param lc logger context for received events
 * @param port port on which the server is to listen
 * @param sslContext custom SSL context
 */
public SimpleSSLSocketServer(LoggerContext lc, int port, SSLContext sslContext) {
  super(lc, port);
  if (sslContext == null) {
    throw new NullPointerException("SSL context required");
  }
  SSLParametersConfiguration parameters = new SSLParametersConfiguration();
  parameters.setContext(lc);
  this.socketFactory = new ConfigurableSSLServerSocketFactory(parameters, sslContext.getServerSocketFactory());
}

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

public EchoServer(SecurityProtocol securityProtocol, Map<String, ?> configs) throws Exception {
  switch (securityProtocol) {
    case SSL:
      this.sslFactory = new SslFactory(Mode.SERVER);
      this.sslFactory.configure(configs);
      SSLContext sslContext = this.sslFactory.sslContext();
      this.serverSocket = sslContext.getServerSocketFactory().createServerSocket(0);
      break;
    case PLAINTEXT:
      this.serverSocket = new ServerSocket(0);
      this.sslFactory = null;
      break;
    default:
      throw new IllegalArgumentException("Unsupported securityProtocol " + securityProtocol);
  }
  this.port = this.serverSocket.getLocalPort();
  this.threads = Collections.synchronizedList(new ArrayList<Thread>());
  this.sockets = Collections.synchronizedList(new ArrayList<Socket>());
}

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

public synchronized void startServer(boolean ssl) throws Exception {
  if (!isServerRunning()) {
    if(ssl){
      final SSLContext sslCtx = SslContextFactory.createSslContext("src/test/resources/keystore.jks","passwordpassword".toCharArray(), "JKS", "src/test/resources/truststore.jks",
          "passwordpassword".toCharArray(), "JKS", SslContextFactory.ClientAuth.REQUIRED, "TLS");
      ServerSocketFactory sslSocketFactory = sslCtx.getServerSocketFactory();
      serverSocket = sslSocketFactory.createServerSocket(0, 0, ipAddress);
    } else {
      serverSocket = new ServerSocket(0, 0, ipAddress);
    }
    Thread t = new Thread(this);
    t.setName(this.getClass().getSimpleName());
    t.start();
    port = serverSocket.getLocalPort();
  }
}

代码示例来源:origin: ch.qos.logback/logback-classic

/**
 * {@inheritDoc}
 */
@Override
protected ServerSocketFactory getServerSocketFactory() throws Exception {
  if (socketFactory == null) {
    SSLContext sslContext = getSsl().createContext(this);
    SSLParametersConfiguration parameters = getSsl().getParameters();
    parameters.setContext(getContext());
    socketFactory = new ConfigurableSSLServerSocketFactory(parameters, sslContext.getServerSocketFactory());
  }
  return socketFactory;
}

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

/**
 * Creates a new SSL ServerSocketFactory. The given factory will use
 * user-provided key and trust managers (if the user provided them).
 *
 * @return Newly created (Ssl)ServerSocketFactory.
 * @throws IOException
 */
@Override
protected ServerSocketFactory createServerSocketFactory() throws IOException {
  if( SslContext.getCurrentSslContext()!=null ) {
    SslContext ctx = SslContext.getCurrentSslContext();
    try {
      return ctx.getSSLContext().getServerSocketFactory();
    } catch (Exception e) {
      throw IOExceptionSupport.create(e);
    }
  } else {
    return SSLServerSocketFactory.getDefault();
  }
}

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

public ServerSocket createSSLServerSocket(int port, int backlog, InetAddress inetAddress) throws IOException {
  this.initSSLContext();
  SSLServerSocketFactory serverSocketFactory = this.sslContext.getServerSocketFactory();
  SSLServerSocket serverSocket = (SSLServerSocket) serverSocketFactory.createServerSocket(port, backlog, inetAddress);
  if (this.jsseSecurityDomain.getProtocols() != null){
    serverSocket.setEnabledProtocols(this.jsseSecurityDomain.getProtocols());
  }
  if (this.jsseSecurityDomain.getCipherSuites() != null){
    serverSocket.setEnabledCipherSuites(this.jsseSecurityDomain.getCipherSuites());
  }
  if (this.jsseSecurityDomain.isClientAuth() || this.require_mutual_auth){
    serverSocket.setNeedClientAuth(true);
  } else {
    serverSocket.setWantClientAuth(this.request_mutual_auth);
  }
  return serverSocket;
}

相关文章