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


Java SSLServerSocket.accept方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: process

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
 * Accept and process an incoming request. Only the TLS handshake is used here.
 * Incoming data is just consumed, and the socket is closed after that.
 *
 * @param sslServerSocket
 *            {@link SSLServerSocket} to accept connections from
 */
private void process(SSLServerSocket sslServerSocket) {
    try (SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept()) {
        sslSocket.setEnabledCipherSuites(sslSocket.getSupportedCipherSuites());
        sslSocket.startHandshake();

        SSLSession sslSession = sslSocket.getSession();
        X509Certificate cert = (X509Certificate) sslSession.getLocalCertificates()[0];
        LOG.info("tls-sni: {}", domainsToString(cert));

        try (InputStream in = sslSocket.getInputStream()) {
            while (in.read() >= 0); //NOSONAR: intentional empty statement
        }
    } catch (Exception ex) {
        LOG.error("Failed to process request", ex);
    }
}
 
开发者ID:shred,项目名称:acme4j,代码行数:24,代码来源:TlsSniServer.java

示例5: main

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    int port = 7443;
    if (args.length >= 1) {
        port = Integer.parseInt(args[0]);
    }

    SSLServer ssl = new SSLServer();
    ssl.setTrustMaterial(TrustMaterial.TRUST_ALL);
    ssl.setCheckExpiry(false);
    ssl.setCheckCRL(false);
    ssl.setCheckHostname(false);
    ssl.setWantClientAuth(true);

    SSLServerSocket ss = (SSLServerSocket) ssl.createServerSocket(port, 3);
    System.out.println("SSL Echo server listening on port: " + port);
    while (true) {
        SSLSocket s = (SSLSocket) ss.accept();
        s.setSoTimeout(30000);
        EchoRunnable r = new EchoRunnable(s);
        new Thread(r).start();
    }

}
 
开发者ID:drankye,项目名称:haox,代码行数:24,代码来源:SSLEchoServer.java

示例6: doServerSide

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
void doServerSide() throws Exception {
    SSLContext context = generateSSLContext(false);
    SSLServerSocketFactory sslssf = context.getServerSocketFactory();
    SSLServerSocket sslServerSocket =
        (SSLServerSocket)sslssf.createServerSocket(serverPort);
    serverPort = sslServerSocket.getLocalPort();

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

    SSLSocket sslSocket = (SSLSocket)sslServerSocket.accept();
    try {
        sslSocket.setSoTimeout(5000);
        sslSocket.setSoLinger(true, 5);

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

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

        throw new Exception("EC curve secp224k1 should be disabled");
    } catch (SSLHandshakeException she) {
        // expected exception: no cipher suites in common
        System.out.println("Expected exception: " + she);
    } finally {
        sslSocket.close();
        sslServerSocket.close();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:ECCurvesconstraints.java

示例7: 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();

    boolean interrupted = false;
    try {
        sslIS.read();
        sslOS.write('A');
        sslOS.flush();
    } catch (IOException ioe) {
        // get the expected exception
        interrupted = true;
    } finally {
        sslSocket.close();
    }

    if (!interrupted) {
        throw new SSLHandshakeException(
            "A weak cipher suite is negotiated, " +
            "TLSv1.1 must not negotiate the exportable cipher suites.");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:ExportableStreamCipher.java

示例8: doServerSide

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

    // enable a stream cipher
    sslServerSocket.setEnabledCipherSuites(
        new String[] {"SSL_RSA_WITH_RC4_128_MD5"});

    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,代码行数:28,代码来源:GenericStreamCipher.java

示例9: 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 = null;
    try {
        sslSocket = (SSLSocket) sslServerSocket.accept();
        sslSocket.setSoTimeout(TIMEOUT);
        readOneRequest(sslSocket.getInputStream());
        sslSocket.getOutputStream().write(replyString.getBytes());

        readOneRequest(sslSocket.getInputStream());
        sslSocket.getOutputStream().write(replyString.getBytes());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (sslSocket != null) { sslSocket.close(); }
            sslServerSocket.close();
        } catch (IOException unused)  {  /* gulp!burp! */   }
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:30,代码来源:CookieHttpsClientTest.java

示例10: run

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
@Override
public void run() {

  // Specifying the Keystore details
  // System.setProperty("javax.net.ssl.keyStore", config.getSslKeyStoreName());
  // System.setProperty("javax.net.ssl.keyStorePassword", config.getSslCertPassword());

  try {
    // Initialize the Server Socket
    SSLContext sslContext = SSLContext.getInstance("SSL");
    sslContext.init(config.getKmf().getKeyManagers(), null, null);

    SSLServerSocketFactory factory = sslContext.getServerSocketFactory();
    log.info("factory created");

    SSLServerSocket serverSocket = (SSLServerSocket) factory.createServerSocket(config.getAsPortSsl());
    log.info("server socket created");

    // SSLContext sslContext = config.getSslContext();
    // SSLServerSocketFactory factory = (SSLServerSocketFactory)
    // sslContext.getServerSocketFactory();
    //
    // SSLServerSocket sslServerSocket =
    // (SSLServerSocket) factory.createServerSocket(config.getAsPortSsl());

    log.info("AS SSL thread started on port " + config.getAsPortSsl());
    while (true) {
      Socket clientSocket = serverSocket.accept();
      log.info("New client connected using SSL");
      threadPool.execute(new AppHandler(clientSocket, config));
    }
  } catch (IOException | NoSuchAlgorithmException | KeyManagementException e) {
    log.error("Could not create SSL context: " + e);
    e.printStackTrace();
  }
}
 
开发者ID:RapidProjectH2020,项目名称:rapid-linux,代码行数:37,代码来源:ClientListenerSSL.java

示例11: run

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
@Override
public void run() {

  Log.i(TAG, "ClientListenerSSL started");

  try {
    SSLContext sslContext = SSLContext.getInstance("SSL");
    sslContext.init(config.getKmf().getKeyManagers(), null, null);

    SSLServerSocketFactory factory =
        (SSLServerSocketFactory) sslContext.getServerSocketFactory();
    Log.i(TAG, "factory created");

    SSLServerSocket serverSocket =
        (SSLServerSocket) factory.createServerSocket(config.getSslClonePort());
    Log.i(TAG, "server socket created");

    // If we want also the client to authenticate himself
    // serverSocket.setNeedClientAuth(true); // default is false

    while (true) {
      // Log.i(TAG, "Saved session IDs: ");
      // Enumeration<byte[]> sessionIDs = sslContext.getServerSessionContext().getIds();
      // while(sessionIDs.hasMoreElements()) {
      // Log.i(TAG, "ID: " + RapidUtils.bytesToHex(sessionIDs.nextElement()));
      // }
      // Log.i(TAG, "");
      //
      Socket clientSocket = serverSocket.accept();
      Log.i(TAG, "New client connected using SSL");
      new AppHandler(clientSocket, context, config);
    }

  } catch (IOException | NoSuchAlgorithmException | KeyManagementException e1) {
    e1.printStackTrace();
  }
}
 
开发者ID:RapidProjectH2020,项目名称:offloading-framework-android,代码行数:38,代码来源:AccelerationServer.java

示例12: iniciarServicio

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
private static void iniciarServicio(final int puerto, final char[] password) {
    try {

        SSLContext context = SSLContext.getInstance("SSL");
        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");

        KeyStore ks = KeyStore.getInstance("JKS");

        ks.load(new FileInputStream("src/cert/keystore.jks"), password);
        kmf.init(ks, "PrometheuS".toCharArray());

        context.init(kmf.getKeyManagers(), null, null);
        SSLServerSocketFactory factory = context.getServerSocketFactory();
        SSLServerSocket socket = (SSLServerSocket) factory.createServerSocket(puerto);


        while (true) {

            Socket userSocket = socket.accept();

            Servicio serv = new Servicio(userSocket);
            serv.start();
        }

    } catch (NoSuchAlgorithmException | KeyStoreException |
            CertificateException | UnrecoverableKeyException |
            KeyManagementException | IOException ex) {
        System.out.println("ERROR: " + ex.getMessage());
    }
}
 
开发者ID:Prometheus-ETSIIT,项目名称:locaviewer,代码行数:31,代码来源:Servidor.java

示例13: iniciarServicio

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
private static void iniciarServicio(final int puerto, final char[] password) {
    try {
     
        SSLContext context = SSLContext.getInstance("SSL");
        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");

        KeyStore ks = KeyStore.getInstance("JKS");

        ks.load(new FileInputStream("src/cert/keystore.jks"), password);
        kmf.init(ks, "PrometheuS".toCharArray());

        context.init(kmf.getKeyManagers(), null, null);
        SSLServerSocketFactory factory = context.getServerSocketFactory();
        SSLServerSocket socket = (SSLServerSocket) factory.createServerSocket(puerto);


        while (true) {

            Socket userSocket = socket.accept();

            Servicio serv = new Servicio(userSocket);
            serv.start();
        }

    } catch (NoSuchAlgorithmException | KeyStoreException |
            CertificateException | UnrecoverableKeyException | 
            KeyManagementException | IOException ex) {
        System.out.println("ERROR: " + ex.getMessage());
    }
}
 
开发者ID:Prometheus-ETSIIT,项目名称:locaviewer,代码行数:31,代码来源:Servidor.java

示例14: testMutualSSL

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
@Test
public void testMutualSSL() throws Exception {

	Security.addProvider(new BeIDProvider());

	final KeyPair serverKeyPair = generateKeyPair();
	final PrivateKey serverPrivateKey = serverKeyPair.getPrivate();
	final DateTime notBefore = new DateTime();
	final DateTime notAfter = notBefore.plusDays(1);
	final X509Certificate serverCertificate = generateCACertificate(serverKeyPair, "CN=Test", notBefore, notAfter);

	final KeyManager keyManager = new ServerTestX509KeyManager(serverPrivateKey, serverCertificate);
	final TrustManager trustManager = new ServerTestX509TrustManager();
	final SSLContext sslContext = SSLContext.getInstance("TLS");
	sslContext.init(new KeyManager[] { keyManager }, new TrustManager[] { trustManager }, new SecureRandom());

	final SSLServerSocketFactory sslServerSocketFactory = sslContext.getServerSocketFactory();

	final int serverPort = 8443;
	final SSLServerSocket sslServerSocket = (SSLServerSocket) sslServerSocketFactory.createServerSocket(serverPort);

	sslServerSocket.setNeedClientAuth(true);

	final TestRunnable testRunnable = new TestRunnable(serverPort);
	final Thread thread = new Thread(testRunnable);
	thread.start();

	SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
	LOGGER.debug("server accepted");
	InputStream inputStream = sslSocket.getInputStream();
	int result = inputStream.read();
	LOGGER.debug("result: {}", result);
	assertEquals(12, result);
	SSLSession sslSession = sslSocket.getSession();
	sslSession.invalidate();
	sslSocket = (SSLSocket) sslServerSocket.accept();
	inputStream = sslSocket.getInputStream();
	result = inputStream.read();
	LOGGER.debug("result: {}", result);
	assertEquals(34, result);
}
 
开发者ID:e-Contract,项目名称:commons-eid,代码行数:42,代码来源:SSLTest.java

示例15: run

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
public void run() {
    try {
        store = provideKeys ? getKeyStore(keys) : null;
        KeyManager[] keyManagers = store != null ? getKeyManagers(store) : null;
        TrustManager[] trustManagers = new TrustManager[] { trustManager };

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

        SSLServerSocket serverSocket = (SSLServerSocket)sslContext
                .getServerSocketFactory().createServerSocket();

        if (clientAuth == CLIENT_AUTH_WANTED) {
            serverSocket.setWantClientAuth(true);
        } else if (clientAuth == CLIENT_AUTH_NEEDED) {
            serverSocket.setNeedClientAuth(true);
        } else {
            serverSocket.setWantClientAuth(false);
        }

        serverSocket.bind(new InetSocketAddress(port));

        SSLSocket clientSocket = (SSLSocket)serverSocket.accept();

        InputStream istream = clientSocket.getInputStream();
        byte[] buffer = new byte[1024];
        istream.read(buffer);

        OutputStream ostream = clientSocket.getOutputStream();
        ostream.write(testData.getBytes());
        ostream.flush();

        while (notFinished) {
            Thread.currentThread().sleep(500);
        }

        clientSocket.close();
        serverSocket.close();

    } catch (Exception ex) {
        exception = ex;
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:44,代码来源:SSLSessionTest.java


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