當前位置: 首頁>>代碼示例>>Java>>正文


Java SSLSocket.addHandshakeCompletedListener方法代碼示例

本文整理匯總了Java中javax.net.ssl.SSLSocket.addHandshakeCompletedListener方法的典型用法代碼示例。如果您正苦於以下問題:Java SSLSocket.addHandshakeCompletedListener方法的具體用法?Java SSLSocket.addHandshakeCompletedListener怎麽用?Java SSLSocket.addHandshakeCompletedListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.net.ssl.SSLSocket的用法示例。


在下文中一共展示了SSLSocket.addHandshakeCompletedListener方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initSocket

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
@Override
protected void initSocket() throws IOException {
    SSLSocket sslSocket = (SSLSocket) socketFactory.createSocket(destination.getAddress(), destination.getPort());

    sslSocket.addHandshakeCompletedListener(handshakeCompletedEvent -> {
                try {
                    LOGGER.debug("Connected [" + handshakeCompletedEvent.getSource() + ", " + sslSocket.getSession().getPeerCertificateChain()[0].getSubjectDN() + "]");
                } catch (SSLPeerUnverifiedException e) {
                    LOGGER.warn(e.getMessage(), e);
                }
            }
    );
    sslSocket.startHandshake();

    this.socket = sslSocket;
}
 
開發者ID:ARMmbed,項目名稱:java-coap,代碼行數:17,代碼來源:SSLSocketClientTransport.java

示例2: createSSLSocket

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
/**
 * Create an SSL client socket using the IOR-encoded
 * security characteristics.
 * Setting want/need client auth on a client socket has no effect so all we can do is use the right host, port, ciphers
 *
 * @param host     The target host name.
 * @param port     The target connection port.
 *
 * @return An appropriately configured client SSLSocket.
 * @exception IOException if ssl socket can't be obtained and configured.
 */
private Socket createSSLSocket(String host, int port, int requires, int supports) throws IOException {
    SSLSocketFactory factory = getSocketFactory();
    SSLSocket socket = (SSLSocket) factory.createSocket(host, port);

    socket.setSoTimeout(SOCKET_TIMEOUT_MS);

    // get a set of cipher suites appropriate for this connections requirements.
    // We request this for each connection, since the outgoing IOR's requirements may be different from
    // our server listener requirements.
    String[] iorSuites = SSLCipherSuiteDatabase.getCipherSuites(requires, supports, factory.getSupportedCipherSuites());
    socket.setEnabledCipherSuites(iorSuites);
    if (log.isDebugEnabled()) {
        log.debug("Created SSL socket to " + host + ":" + port);
        log.debug("    cipher suites:");

        for (int i = 0; i < iorSuites.length; i++) {
            log.debug("    " + iorSuites[i]);
        }
        socket.addHandshakeCompletedListener(new HandshakeCompletedListener() {

            public void handshakeCompleted(HandshakeCompletedEvent handshakeCompletedEvent) {
                Certificate[] certs = handshakeCompletedEvent.getLocalCertificates();
                if (certs != null) {
                    log.debug("handshake returned local certs count: " + certs.length);
                    for (int i = 0; i < certs.length; i++) {
                        Certificate cert = certs[i];
                        log.debug("cert: " + cert.toString());
                    }
                } else {
                    log.debug("handshake returned no local certs");
                }
            }
        });
    }
    return socket;
}
 
開發者ID:RuiChen08,項目名稱:dacapobench,代碼行數:48,代碼來源:SocketFactory.java

示例3: JSSESupport

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
JSSESupport(SSLSocket sock){
    ssl=sock;
    session = sock.getSession();
    sock.addHandshakeCompletedListener(listener);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:6,代碼來源:JSSESupport.java

示例4: testRenegotiateFail

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
@Test
public void testRenegotiateFail() throws Exception {

    // If RFC5746 is supported, renegotiation will always work (and will
    // always be secure)
    if (TesterSupport.RFC_5746_SUPPORTED) {
        return;
    }

    Tomcat tomcat = getTomcatInstance();

    File appDir = new File(getBuildDirectory(), "webapps/examples");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());

    TesterSupport.initSsl(tomcat);

    // Default - MITM attack prevented

    tomcat.start();
    SSLContext sslCtx = SSLContext.getInstance("TLS");
    sslCtx.init(null, TesterSupport.getTrustManagers(), null);
    SSLSocketFactory socketFactory = sslCtx.getSocketFactory();
    SSLSocket socket = (SSLSocket) socketFactory.createSocket("localhost", getPort());

    socket.addHandshakeCompletedListener(new HandshakeCompletedListener() {
        @Override
        public void handshakeCompleted(HandshakeCompletedEvent event) {
            handshakeDone = true;
        }
    });

    OutputStream os = socket.getOutputStream();
    os.write("GET /examples/servlets/servlet/HelloWorldExample HTTP/1.0\n".getBytes());
    os.flush();


    InputStream is = socket.getInputStream();

    // Make sure the NIO connector has read the request before the handshake
    Thread.sleep(100);

    socket.startHandshake();

    os = socket.getOutputStream();

    try {
        os.write("Host: localhost\n\n".getBytes());
    } catch (IOException ex) {
        ex.printStackTrace();
        fail("Re-negotiation failed");
    }
    Reader r = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(r);
    String line = br.readLine();
    while (line != null) {
        // For testing System.out.println(line);
        line = br.readLine();
    }

    if (!handshakeDone) {
        // success - we timed-out without handshake
        return;
    }

    fail("Re-negotiation worked");
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:68,代碼來源:TestSsl.java

示例5: getLocalAddressForTlsDst

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
/**
 * Creates and binds, if necessary, a socket connected to the specified
 * destination address and port and then returns its local address.
 *
 * @param dst the destination address that the socket would need to connect
 * to.
 * @param dstPort the port number that the connection would be established
 * with.
 * @param localAddress the address that we would like to bind on (null for
 * the "any" address).
 *
 * @param channel the message channel that will be servicing the socket
 *
 * @return the SocketAddress that this handler would use when connecting to
 * the specified destination address and port.
 *
 * @throws IOException if we fail binding the socket
 */
public SocketAddress getLocalAddressForTlsDst(InetAddress dst, int dstPort,
         InetAddress localAddress, TLSMessageChannel channel)
         throws IOException {
    String key = makeKey(dst, dstPort);

    Socket clientSock = getSocket(key);

    if (clientSock == null) {

        clientSock = sipStack.getNetworkLayer()
            .createSSLSocket(dst, dstPort, localAddress);

        SSLSocket sslsock = (SSLSocket) clientSock;

        if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
            logger.logDebug(
                    "inaddr = " + dst);
            logger.logDebug(
                    "port = " + dstPort);
        }

        HandshakeCompletedListenerImpl listner
                = new HandshakeCompletedListenerImpl(channel, sslsock);

        channel.setHandshakeCompletedListener(listner);
        sslsock.addHandshakeCompletedListener(listner);
        sslsock.setEnabledProtocols(sipStack.getEnabledProtocols());
        sslsock.setEnabledCipherSuites(sipStack.getEnabledCipherSuites());

        listner.startHandshakeWatchdog();
        sslsock.startHandshake();
        channel.setHandshakeCompleted(true);
        if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
            this.logger.logDebug(
                    "Handshake passed");
        }

        // allow application to enforce policy by validating the
        // certificate
        try {
            sipStack.getTlsSecurityPolicy().enforceTlsPolicy(
                        channel.getEncapsulatedClientTransaction());
        }
        catch (SecurityException ex) {
            throw new IOException(ex.getMessage());
        }

        if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
            this.logger.logDebug(
                    "TLS Security policy passed");
        }

        putSocket(key, clientSock);
    }

    return clientSock.getLocalSocketAddress();
}
 
開發者ID:YunlongYang,項目名稱:LightSIP,代碼行數:76,代碼來源:IOHandler.java

示例6: JSSESupport

import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
JSSESupport(SSLSocket sock) {
	ssl = sock;
	session = sock.getSession();
	sock.addHandshakeCompletedListener(listener);
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:6,代碼來源:JSSESupport.java


注:本文中的javax.net.ssl.SSLSocket.addHandshakeCompletedListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。