当前位置: 首页>>代码示例>>Java>>正文


Java SSLServerSocket类代码示例

本文整理汇总了Java中javax.net.ssl.SSLServerSocket的典型用法代码示例。如果您正苦于以下问题:Java SSLServerSocket类的具体用法?Java SSLServerSocket怎么用?Java SSLServerSocket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SSLServerSocket类属于javax.net.ssl包,在下文中一共展示了SSLServerSocket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    // reserve the security properties
    String reservedSSFacProvider =
        Security.getProperty("ssl.ServerSocketFactory.provider");

    try {
        Security.setProperty("ssl.ServerSocketFactory.provider", "oops");
        ServerSocketFactory ssocketFactory =
                    SSLServerSocketFactory.getDefault();
        SSLServerSocket sslServerSocket =
                    (SSLServerSocket)ssocketFactory.createServerSocket();
    } catch (Exception e) {
        if (!(e.getCause() instanceof ClassNotFoundException)) {
            throw e;
        }
        // get the expected exception
    } finally {
        // restore the security properties
        if (reservedSSFacProvider == null) {
            reservedSSFacProvider = "";
        }
        Security.setProperty("ssl.ServerSocketFactory.provider",
                                                reservedSSFacProvider);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:DefaultSSLServSocketFac.java

示例2: createServerTransport

import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
private static TServerSocket createServerTransport(boolean secure)
        throws TTransportException
{
    if (!secure) {
        return new TServerSocket(0);
    }

    try {
        SSLContext serverSslContext = ClientTestUtils.getServerSslContext();
        SSLServerSocket serverSocket = (SSLServerSocket) serverSslContext.getServerSocketFactory().createServerSocket(0);
        return new TServerSocket(serverSocket);
    }
    catch (Exception e) {
        throw new TTransportException("Error initializing secure socket", e);
    }
}
 
开发者ID:airlift,项目名称:drift,代码行数:17,代码来源:TestClientsWithApacheServer.java

示例3: getSSLServerTransport

import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
private TServerTransport getSSLServerTransport() {
  try {
    TServerTransport transport;
    TSSLTransportFactory.TSSLTransportParameters params =
            new TSSLTransportFactory.TSSLTransportParameters();

    params.setKeyStore(keystore, keystorePassword, getkeyManagerAlgorithm(), keystoreType);
    transport = TSSLTransportFactory.getServerSocket(
            port, 120000, InetAddress.getByName(bindAddress), params);

    ServerSocket serverSock = ((TServerSocket) transport).getServerSocket();
    if (serverSock instanceof SSLServerSocket) {
      SSLServerSocket sslServerSock = (SSLServerSocket) serverSock;
      List<String> enabledProtocols = new ArrayList<String>();
      for (String protocol : sslServerSock.getEnabledProtocols()) {
        if (!excludeProtocols.contains(protocol)) {
          enabledProtocols.add(protocol);
        }
      }
      sslServerSock.setEnabledProtocols(enabledProtocols.toArray(new String[0]));
    }
    return transport;
  } catch (Throwable throwable) {
    throw new FlumeException("Cannot start Thrift source.", throwable);
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:27,代码来源:ThriftSource.java

示例4: initServerSocket

import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
/**
 * Configures the given SSL server socket with the requested cipher suites,
 * protocol versions, and need for client authentication
 */
private void initServerSocket(ServerSocket ssocket) {

    SSLServerSocket socket = (SSLServerSocket) ssocket;

    if (enabledCiphers != null) {
        socket.setEnabledCipherSuites(enabledCiphers);
    }

    String requestedProtocols = (String) attributes.get("protocols");
    setEnabledProtocols(socket, getEnabledProtocols(socket, 
                                                     requestedProtocols));

    // we don't know if client auth is needed -
    // after parsing the request we may re-handshake
    configureClientAuth(socket);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:JSSESocketFactory.java

示例5: finishServerSocket

import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
/**
 * Configure the SSLServerSocket based on this SocketCreator's settings.
 */
private void finishServerSocket(SSLServerSocket serverSocket) throws IOException {
  serverSocket.setUseClientMode(false);
  if (this.sslConfig.isRequireAuth()) {
    // serverSocket.setWantClientAuth( true );
    serverSocket.setNeedClientAuth(true);
  }
  serverSocket.setEnableSessionCreation(true);

  // restrict protocols
  String[] protocols = this.sslConfig.getProtocolsAsStringArray();
  if (!"any".equalsIgnoreCase(protocols[0])) {
    serverSocket.setEnabledProtocols(protocols);
  }
  // restrict ciphers
  String[] ciphers = this.sslConfig.getCiphersAsStringArray();
  if (!"any".equalsIgnoreCase(ciphers[0])) {
    serverSocket.setEnabledCipherSuites(ciphers);
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:23,代码来源:SocketCreator.java

示例6: createServerSocket

import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
/**
 * Create a server socket listening on the given port.
 *
 * @param port    The target listening port.
 * @param backlog The desired backlog value.
 *
 * @return An appropriate server socket for this connection.
 * @exception IOException
 * @exception ConnectException
 */
public ServerSocket createServerSocket(int port, int backlog)  throws IOException {
    try {
        // if no protection is required, just create a plain socket.
        if ((NoProtection.value & requires) == NoProtection.value) {
            if (log.isDebugEnabled()) log.debug("Created plain server socket for port " + port);
            return new ServerSocket(port, backlog);
        }
        else {
            // SSL is required.  Create one from the SSLServerFactory retrieved from the config.  This will
            // require additional QOS configuration after creation.
            SSLServerSocket serverSocket = (SSLServerSocket)getServerSocketFactory().createServerSocket(port, backlog);
            configureServerSocket(serverSocket);
            return serverSocket;
        }
    } catch (IOException ex) {
        log.error("Exception creating a server socket for port "  + port, ex);
        throw ex;
    }
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:30,代码来源:SocketFactory.java

示例7: configureServerSocket

import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
/**
 * Set the server socket configuration to our required
 * QOS values.
 *
 * A small experiment shows that setting either (want, need) parameter to either true or false sets the
 * other parameter to false.
 *
 * @param serverSocket
 *               The newly created SSLServerSocket.
 *
 * @throws IOException if server socket can't be configured
 */
private void configureServerSocket(SSLServerSocket serverSocket) throws IOException {
    // set the authentication value and cipher suite info.
    serverSocket.setEnabledCipherSuites(cipherSuites);
    if (clientAuthRequired) {
        serverSocket.setNeedClientAuth(true);
    } else if (clientAuthSupported) {
        serverSocket.setWantClientAuth(true);
    } else {
        serverSocket.setNeedClientAuth(false); //could set want with the same effect
    }
    serverSocket.setSoTimeout(SOCKET_TIMEOUT_MS);

    if (log.isDebugEnabled()) {
        log.debug("Created SSL server socket on port " + serverSocket.getLocalPort());
        log.debug("    client authentication " + (clientAuthSupported ? "SUPPORTED" : "UNSUPPORTED"));
        log.debug("    client authentication " + (clientAuthRequired ? "REQUIRED" : "OPTIONAL"));
        log.debug("    cipher suites:");

        for (int i = 0; i < cipherSuites.length; i++) {
            log.debug("    " + cipherSuites[i]);
        }
    }
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:36,代码来源:SocketFactory.java

示例8: printInfo

import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
public static void printInfo(SSLServerSocket socket) {
    System.out.println();
    System.out.println("--- SSL ServerSocket Info ---");
    System.out.print("SupportedProtocols    : ");
    printStringArray(socket.getSupportedProtocols());
    System.out.print("SupportedCipherSuites : ");
    printStringArray(socket.getSupportedCipherSuites());
    System.out.print("EnabledProtocols      : ");
    printStringArray(socket.getEnabledProtocols());
    System.out.print("EnabledCipherSuites   : ");
    String[] supportedCipherSuites = socket.getEnabledCipherSuites();
    Arrays.sort(supportedCipherSuites);
    printStringArray(supportedCipherSuites);
    System.out.println("NeedClientAuth        : "
            + socket.getNeedClientAuth());
    System.out.println("WantClientAuth        : "
            + socket.getWantClientAuth());
    System.out.println("-----------------------");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:CipherTestUtils.java

示例9: JSSEServer

import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
JSSEServer(CipherTestUtils cipherTest, int serverPort,
        String protocol, String cipherSuite) throws Exception {
    super(cipherTest);
    this.serverPort = serverPort;
    SSLContext serverContext = SSLContext.getInstance("TLS");
    serverContext.init(new KeyManager[]{cipherTest.getServerKeyManager()},
            new TrustManager[]{cipherTest.getServerTrustManager()},
            CipherTestUtils.secureRandom);
    SSLServerSocketFactory factory =
            (SSLServerSocketFactory)serverContext.getServerSocketFactory();
    serverSocket =
            (SSLServerSocket) factory.createServerSocket(serverPort);
    serverSocket.setEnabledProtocols(protocol.split(","));
    serverSocket.setEnabledCipherSuites(cipherSuite.split(","));

    CipherTestUtils.printInfo(serverSocket);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:JSSEServer.java

示例10: start

import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
public void start() throws IOException {
    if (this.status.compareAndSet(Status.READY, Status.ACTIVE)) {
        this.serverSocket = this.serverSocketFactory.createServerSocket(
                this.port, this.socketConfig.getBacklogSize(), this.ifAddress);
        this.serverSocket.setReuseAddress(this.socketConfig.isSoReuseAddress());
        if (this.socketConfig.getRcvBufSize() > 0) {
            this.serverSocket.setReceiveBufferSize(this.socketConfig.getRcvBufSize());
        }
        if (this.sslSetupHandler != null && this.serverSocket instanceof SSLServerSocket) {
            this.sslSetupHandler.initialize((SSLServerSocket) this.serverSocket);
        }
        this.requestListener = new RequestListener(
                this.socketConfig,
                this.serverSocket,
                this.httpService,
                this.connectionFactory,
                this.exceptionLogger,
                this.workerExecutorService);
        this.listenerExecutorService.execute(this.requestListener);
    }
}
 
开发者ID:gusavila92,项目名称:java-android-websocket-client,代码行数:22,代码来源:HttpServer.java

示例11: initSecure

import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
final ServerSocket initSecure(int port) throws Exception {
    ServerSocketFactory fac;
    if (sslContext != null) {
        fac = sslContext.getServerSocketFactory();
    } else {
        fac = SSLServerSocketFactory.getDefault();
    }
    SSLServerSocket se = (SSLServerSocket) fac.createServerSocket(port);
    SSLParameters sslp = se.getSSLParameters();
    sslp.setApplicationProtocols(new String[]{"h2"});
    se.setSSLParameters(sslp);
    se.setEnabledCipherSuites(se.getSupportedCipherSuites());
    se.setEnabledProtocols(se.getSupportedProtocols());
    // other initialisation here
    return se;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Http2TestServer.java

示例12: doServerSide

import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
void doServerSide() throws Exception {
        SSLServerSocketFactory sslssf =
            (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
        SSLServerSocket sslServerSocket =
            (SSLServerSocket) sslssf.createServerSocket(serverPort);
        serverPort = sslServerSocket.getLocalPort();

        /*
         * Signal Client, we're ready for his connect.
         */
        serverReady = true;

        while (serverReady) {
            SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
//            System.out.printf("  accept: %s%n", sslSocket);
            InputStream sslIS = sslSocket.getInputStream();
            OutputStream sslOS = sslSocket.getOutputStream();

            sslIS.read();
            sslOS.write(85);
            sslOS.flush();

            sslSocket.close();
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:SSLSessionFinalizeTest.java

示例13: doServerSide

import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
void doServerSide() throws Exception {
    SSLServerSocketFactory sslssf = getSSLServerSF();
    SSLServerSocket sslServerSocket =
        (SSLServerSocket) sslssf.createServerSocket(serverPort);

    // require client authentication.
    sslServerSocket.setNeedClientAuth(true);

    serverPort = sslServerSocket.getLocalPort();

    /*
     * Signal Client, we're ready for his connect.
     */
    serverReady = true;

    SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
    InputStream sslIS = sslSocket.getInputStream();
    OutputStream sslOS = sslSocket.getOutputStream();

    sslIS.read();
    sslOS.write('A');
    sslOS.flush();

    sslSocket.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:EmptyCertificateAuthorities.java

示例14: doServerSide

import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
void doServerSide() throws Exception {
    SSLServerSocketFactory sslssf =
        (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    SSLServerSocket sslServerSocket =
        (SSLServerSocket) sslssf.createServerSocket(serverPort);

    serverPort = sslServerSocket.getLocalPort();

    /*
     * Signal Client, we're ready for his connect.
     */
    serverReady = true;

    SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
    InputStream sslIS = sslSocket.getInputStream();
    OutputStream sslOS = sslSocket.getOutputStream();

    sslIS.read();
    sslOS.write('A');
    sslOS.flush();

    sslSocket.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:GenericBlockCipher.java

示例15: JSSEServer

import javax.net.ssl.SSLServerSocket; //导入依赖的package包/类
JSSEServer(CipherTestUtils cipherTest, int serverPort,
        String protocol, String cipherSuite) throws Exception {
    super(cipherTest);
    SSLContext serverContext = SSLContext.getInstance("TLS");
    serverContext.init(new KeyManager[]{cipherTest.getServerKeyManager()},
            new TrustManager[]{cipherTest.getServerTrustManager()},
            CipherTestUtils.secureRandom);
    SSLServerSocketFactory factory =
            (SSLServerSocketFactory)serverContext.getServerSocketFactory();
    serverSocket =
            (SSLServerSocket) factory.createServerSocket(serverPort);
    serverSocket.setEnabledProtocols(protocol.split(","));
    serverSocket.setEnabledCipherSuites(cipherSuite.split(","));

    CipherTestUtils.printInfo(serverSocket);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:JSSEServer.java


注:本文中的javax.net.ssl.SSLServerSocket类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。