当前位置: 首页>>代码示例>>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;未经允许,请勿转载。