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


Java SSLServerSocket.getLocalPort方法代码示例

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


在下文中一共展示了SSLServerSocket.getLocalPort方法的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: JSSEServer

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
JSSEServer(CipherTest cipherTest) throws Exception {
    super(cipherTest);
    SSLContext serverContext = SSLContext.getInstance("TLS");
    serverContext.init(
            new KeyManager[] { CipherTest.keyManager },
            new TrustManager[] { CipherTest.trustManager },
            CipherTest.secureRandom);

    SSLServerSocketFactory factory = (SSLServerSocketFactory)serverContext.getServerSocketFactory();
    serverSocket = (SSLServerSocket)factory.createServerSocket(0);
    serverSocket.setSoTimeout(CipherTest.TIMEOUT);
    CipherTest.serverPort = serverSocket.getLocalPort();
    serverSocket.setEnabledCipherSuites(factory.getSupportedCipherSuites());
    serverSocket.setWantClientAuth(true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:JSSEServer.java

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

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

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

示例8: JSSEServer

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
JSSEServer(CipherTest cipherTest) throws Exception {
    super(cipherTest);
    SSLContext serverContext = SSLContext.getInstance("TLS");
    serverContext.init(new KeyManager[] {cipherTest.keyManager}, new TrustManager[] {cipherTest.trustManager}, cipherTest.secureRandom);

    SSLServerSocketFactory factory = (SSLServerSocketFactory)serverContext.getServerSocketFactory();
    serverSocket = (SSLServerSocket)factory.createServerSocket(0);
    cipherTest.serverPort = serverSocket.getLocalPort();
    serverSocket.setEnabledCipherSuites(factory.getSupportedCipherSuites());
    serverSocket.setWantClientAuth(true);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:12,代码来源:JSSEServer.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: setUp

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    // setup an "http" server
    server = new ServerSocket(0);
    serverPort = server.getLocalPort();

    // setup an "https" server
    final SSLServerSocket sslServer = (SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket(0);
    sslServerPort = sslServer.getLocalPort();

    final SocketConfig sconfig = SocketConfig.custom().setSoTimeout(100).build();
    connFactory = new BasicConnFactory(sconfig, ConnectionConfig.DEFAULT);
    pool = new BasicConnPool(connFactory);
}
 
开发者ID:reportportal,项目名称:client-java-httpclient-repacked,代码行数:15,代码来源:TestBasicConnPool.java

示例11: testSetSSLSocketFactory

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
 * Tests possibility to set up the SSLSocketFactory
 * to be used by HttpsURLConnection.
 */
public void testSetSSLSocketFactory() throws Throwable {
    // create the SSLServerSocket which will be used by server side
    SSLContext ctx = getContext();
    SSLServerSocket ss = (SSLServerSocket) ctx.getServerSocketFactory().createServerSocket(0);

    // create the HostnameVerifier to check hostname verification
    TestHostnameVerifier hnv = new TestHostnameVerifier();
    HttpsURLConnection.setDefaultHostnameVerifier(hnv);

    // create HttpsURLConnection to be tested
    URL url = new URL("https://localhost:" + ss.getLocalPort());
    HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();

    SSLSocketFactory socketFactory = (SSLSocketFactory) ctx.getSocketFactory();
    connection.setSSLSocketFactory(socketFactory);

    TestHostnameVerifier hnv_late = new TestHostnameVerifier();
    // late initialization: should not be used for created connection
    HttpsURLConnection.setDefaultHostnameVerifier(hnv_late);

    // perform the interaction between the peers
    SSLSocket peerSocket = (SSLSocket) doInteraction(connection, ss);
    // check the connection state
    checkConnectionStateParameters(connection, peerSocket);
    // check the verification process
    assertTrue("Hostname verification was not done", hnv.verified);
    assertFalse("Hostname verification should not be done by this verifier",
                hnv_late.verified);
    // check the used SSLSocketFactory
    assertNotSame("Default SSLSocketFactory should not be used",
                  HttpsURLConnection.getDefaultSSLSocketFactory(),
                  connection.getSSLSocketFactory());
    assertSame("Result differs from expected",
               socketFactory, connection.getSSLSocketFactory());

    // should silently exit
    connection.connect();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:43,代码来源:HttpsURLConnectionTest.java

示例12: testSetHostnameVerifier

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
 * Tests if setHostnameVerifier() method replaces default verifier.
 */
public void testSetHostnameVerifier() throws Throwable {
    // setting up the properties pointing to the key/trust stores
    setUpStoreProperties();

    // create the SSLServerSocket which will be used by server side
    SSLServerSocket ss = (SSLServerSocket)
            getContext().getServerSocketFactory().createServerSocket(0);

    // create the HostnameVerifier to check that Hostname verification
    // is done
    TestHostnameVerifier hnv = new TestHostnameVerifier();
    HttpsURLConnection.setDefaultHostnameVerifier(hnv);

    // create HttpsURLConnection to be tested
    URL url = new URL("https://localhost:" + ss.getLocalPort());
    HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
    connection.setSSLSocketFactory(getContext().getSocketFactory());

    TestHostnameVerifier hnv_late = new TestHostnameVerifier();
    // replace default verifier
    connection.setHostnameVerifier(hnv_late);

    // perform the interaction between the peers and check the results
    SSLSocket peerSocket = (SSLSocket) doInteraction(connection, ss);
    assertTrue("Hostname verification was not done", hnv_late.verified);
    assertFalse("Hostname verification should not be done by this verifier",
                hnv.verified);
    checkConnectionStateParameters(connection, peerSocket);

    // should silently exit
    connection.connect();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:36,代码来源:HttpsURLConnectionTest.java

示例13: test_doOutput

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
 * Tests the behaviour in case of sending the data to the server.
 */
public void test_doOutput() throws Throwable {
    // setting up the properties pointing to the key/trust stores
    setUpStoreProperties();

    // create the SSLServerSocket which will be used by server side
    SSLServerSocket ss = (SSLServerSocket)
            getContext().getServerSocketFactory().createServerSocket(0);

    // create the HostnameVerifier to check that Hostname verification
    // is done
    TestHostnameVerifier hnv = new TestHostnameVerifier();
    HttpsURLConnection.setDefaultHostnameVerifier(hnv);

    // create HttpsURLConnection to be tested
    URL url = new URL("https://localhost:" + ss.getLocalPort());
    HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
    connection.setSSLSocketFactory(getContext().getSocketFactory());
    connection.setDoOutput(true);

    // perform the interaction between the peers and check the results
    SSLSocket peerSocket = (SSLSocket) doInteraction(connection, ss);
    checkConnectionStateParameters(connection, peerSocket);

    // should silently exit
    connection.connect();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:30,代码来源:HttpsURLConnectionTest.java

示例14: testSetHostnameVerifier

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
 * Tests if setHostnameVerifier() method replaces default verifier.
 */
public void testSetHostnameVerifier() throws Throwable {
    // setting up the properties pointing to the key/trust stores
    setUpStoreProperties();

    try {
        // create the SSLServerSocket which will be used by server side
        SSLServerSocket ss = (SSLServerSocket) getContext()
                .getServerSocketFactory().createServerSocket(0);

        // create the HostnameVerifier to check that Hostname verification
        // is done
        TestHostnameVerifier hnv = new TestHostnameVerifier();
        HttpsURLConnection.setDefaultHostnameVerifier(hnv);

        // create HttpsURLConnection to be tested
        URL url = new URL("https://localhost:" + ss.getLocalPort());
        HttpsURLConnection connection = (HttpsURLConnection) url
                .openConnection();

        TestHostnameVerifier hnv_late = new TestHostnameVerifier();
        // replace default verifier
        connection.setHostnameVerifier(hnv_late);

        // perform the interaction between the peers and check the results
        SSLSocket peerSocket = (SSLSocket) doInteraction(connection, ss);
        assertTrue("Hostname verification was not done", hnv_late.verified);
        assertFalse(
                "Hostname verification should not be done by this verifier",
                hnv.verified);
        checkConnectionStateParameters(connection, peerSocket);

        // should silently exit
        connection.connect();
    } finally {
        // roll the properties back to system values
        tearDownStoreProperties();
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:42,代码来源:HttpsURLConnectionTest.java

示例15: test_doOutput

import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
 * Tests the behaviour in case of sending the data to the server.
 */
public void test_doOutput() throws Throwable {
    // setting up the properties pointing to the key/trust stores
    setUpStoreProperties();

    try {
        // create the SSLServerSocket which will be used by server side
        SSLServerSocket ss = (SSLServerSocket) getContext()
                .getServerSocketFactory().createServerSocket(0);

        // create the HostnameVerifier to check that Hostname verification
        // is done
        TestHostnameVerifier hnv = new TestHostnameVerifier();
        HttpsURLConnection.setDefaultHostnameVerifier(hnv);

        // create HttpsURLConnection to be tested
        URL url = new URL("https://localhost:" + ss.getLocalPort());
        HttpsURLConnection connection = (HttpsURLConnection) url
                .openConnection();
        connection.setDoOutput(true);

        // perform the interaction between the peers and check the results
        SSLSocket peerSocket = (SSLSocket) doInteraction(connection, ss);
        checkConnectionStateParameters(connection, peerSocket);

        // should silently exit
        connection.connect();
    } finally {
        // roll the properties back to system values
        tearDownStoreProperties();
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:35,代码来源:HttpsURLConnectionTest.java


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