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


Java SSLSocket.close方法代码示例

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


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

示例1: check_nickname

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
public boolean check_nickname(String nickname) throws ClassNotFoundException
{
    //connect to Registrar to check if nickname is unique
    boolean check = false;
    try 
    {
        
        SSLSocket sslSocket=Client.get_SSLSock();
        //Socket s1 = new Socket("localhost", 5999);
        ObjectOutputStream out = new ObjectOutputStream(sslSocket.getOutputStream());
        ObjectInputStream in = new ObjectInputStream(sslSocket.getInputStream());

        out.writeObject(new Message(nickname, "null"));//here goes nickname
        out.flush();
        
        check = (boolean)in.readObject();

        sslSocket.close();
    } catch (IOException ex) {
        Logger.getLogger(NewConnection.class.getName()).log(Level.SEVERE, null, ex);
    }
    
    return check;
}
 
开发者ID:georgemakrakis,项目名称:TrackMeIfYouCanChat,代码行数:25,代码来源:Nickname.java

示例2: handleClient

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
private static void handleClient(SSLSocket sslSocket) throws IOException {
    String clientType;
    try {
        clientType = new Transmission(sslSocket).readText();
    } catch (IOException e) {
        Logger.log("Failed retreiving text from " + sslSocket.getInetAddress().getHostAddress() + ", problably not a secure connection, aborting.");
        sslSocket.close();
        return;
    }
    if (clientType.toUpperCase().equals("SENDER")) {
        Logger.log(sslSocket.getInetAddress().getHostAddress() + " is a sender.");
        handleSender(sslSocket);
    } else if (clientType.toUpperCase().equals("RECEPTOR")) {
        Logger.log(sslSocket.getInetAddress().getHostAddress() + " is a receptor.");
        handleReceptor(sslSocket);
    } else {
        Logger.log(sslSocket.getInetAddress().getHostAddress() + " isn't a secure connection, aborting connection.");
        sslSocket.close();
    }
}
 
开发者ID:luisbraganca,项目名称:file-transfer,代码行数:21,代码来源:Main.java

示例3: doServerSide

import javax.net.ssl.SSLSocket; //导入方法依赖的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: doClientSide

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
void doClientSide() throws Exception {

        /*
         * Wait for server to get started.
         */
        while (!serverReady) {
            Thread.sleep(50);
        }

        SSLSocketFactory sslsf =
            (SSLSocketFactory) SSLSocketFactory.getDefault();
        SSLSocket sslSocket = (SSLSocket)
            sslsf.createSocket("localhost", serverPort);

        // enable TLSv1.1 only
        sslSocket.setEnabledProtocols(new String[] {"TLSv1.1"});

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

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

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

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

示例5: retryableSSLHandshakeException

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
@Test
public void retryableSSLHandshakeException() throws Exception {
  ConnectionSpecSelector connectionSpecSelector =
      createConnectionSpecSelector(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS);
  SSLSocket socket = createSocketWithEnabledProtocols(TlsVersion.TLS_1_1, TlsVersion.TLS_1_0);
  connectionSpecSelector.configureSecureSocket(socket);

  boolean retry = connectionSpecSelector.connectionFailed(RETRYABLE_EXCEPTION);
  assertTrue(retry);
  socket.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:ConnectionSpecSelectorTest.java

示例6: processHandshakeFailure

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
private void processHandshakeFailure(Socket raw) throws Exception {
  SSLContext context = SSLContext.getInstance("TLS");
  context.init(null, new TrustManager[] {UNTRUSTED_TRUST_MANAGER}, new SecureRandom());
  SSLSocketFactory sslSocketFactory = context.getSocketFactory();
  SSLSocket socket = (SSLSocket) sslSocketFactory.createSocket(
      raw, raw.getInetAddress().getHostAddress(), raw.getPort(), true);
  try {
    socket.startHandshake(); // we're testing a handshake failure
    throw new AssertionError();
  } catch (IOException expected) {
  }
  socket.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:MockWebServer.java

示例7: nonRetryableIOException

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
@Test
public void nonRetryableIOException() throws Exception {
  ConnectionSpecSelector connectionSpecSelector =
      createConnectionSpecSelector(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS);
  SSLSocket socket = createSocketWithEnabledProtocols(TlsVersion.TLS_1_1, TlsVersion.TLS_1_0);
  connectionSpecSelector.configureSecureSocket(socket);

  boolean retry = connectionSpecSelector.connectionFailed(
      new IOException("Non-handshake exception"));
  assertFalse(retry);
  socket.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:ConnectionSpecSelectorTest.java

示例8: nonRetryableSSLHandshakeException

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
@Test
public void nonRetryableSSLHandshakeException() throws Exception {
  ConnectionSpecSelector connectionSpecSelector =
      createConnectionSpecSelector(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS);
  SSLSocket socket = createSocketWithEnabledProtocols(TlsVersion.TLS_1_1, TlsVersion.TLS_1_0);
  connectionSpecSelector.configureSecureSocket(socket);

  SSLHandshakeException trustIssueException =
      new SSLHandshakeException("Certificate handshake exception");
  trustIssueException.initCause(new CertificateException());
  boolean retry = connectionSpecSelector.connectionFailed(trustIssueException);
  assertFalse(retry);
  socket.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:ConnectionSpecSelectorTest.java

示例9: someFallbacksSupported

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
@Test
public void someFallbacksSupported() throws Exception {
  ConnectionSpec sslV3 =
      new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
          .tlsVersions(TlsVersion.SSL_3_0)
          .build();

  ConnectionSpecSelector connectionSpecSelector = createConnectionSpecSelector(
      ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS, sslV3);

  TlsVersion[] enabledSocketTlsVersions = {TlsVersion.TLS_1_1, TlsVersion.TLS_1_0};
  SSLSocket socket = createSocketWithEnabledProtocols(enabledSocketTlsVersions);

  // MODERN_TLS is used here.
  connectionSpecSelector.configureSecureSocket(socket);
  assertEnabledProtocols(socket, TlsVersion.TLS_1_1, TlsVersion.TLS_1_0);

  boolean retry = connectionSpecSelector.connectionFailed(RETRYABLE_EXCEPTION);
  assertTrue(retry);
  socket.close();

  // COMPATIBLE_TLS is used here.
  socket = createSocketWithEnabledProtocols(enabledSocketTlsVersions);
  connectionSpecSelector.configureSecureSocket(socket);
  assertEnabledProtocols(socket, TlsVersion.TLS_1_0);

  retry = connectionSpecSelector.connectionFailed(RETRYABLE_EXCEPTION);
  assertFalse(retry);
  socket.close();

  // sslV3 is not used because SSLv3 is not enabled on the socket.
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:ConnectionSpecSelectorTest.java

示例10: doClientSide

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
void doClientSide() throws Exception {

        /*
         * Wait for server to get started.
         */
        while (!serverReady) {
            Thread.sleep(50);
        }

        SSLContext context = generateSSLContext(true);
        SSLSocketFactory sslsf = context.getSocketFactory();

        SSLSocket sslSocket =
            (SSLSocket)sslsf.createSocket("localhost", serverPort);

        try {
            sslSocket.setSoTimeout(5000);
            sslSocket.setSoLinger(true, 5);

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

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

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

示例11: doServerSide

import javax.net.ssl.SSLSocket; //导入方法依赖的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

示例12: cleanUpFailedSocket

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
/**
 * Do any cleanup necessary due to socket creation failure (e.g. due to hostname validation failure).
 * 
 * @param sslSocket the {@link SSLSocket} to cleanup
 */
protected void cleanUpFailedSocket(SSLSocket sslSocket) {
    try {
        sslSocket.close();
    } catch (IOException e) {
        // Do nothing. We haven't returned it yet, so can just ignore.
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:TLSProtocolSocketFactory.java

示例13: verifyHostname

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
private void verifyHostname(final SSLSocket sslsock, final String hostname) throws IOException {
    try {
        this.hostnameVerifier.verify(hostname, sslsock);
        // verifyHostName() didn't blowup - good!
    } catch (final IOException iox) {
        // close the socket before re-throwing the exception
        try { sslsock.close(); } catch (final Exception x) { /*ignore*/ }
        throw iox;
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:11,代码来源:SSLConnectionSocketFactory.java

示例14: Heartbeat

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
public Heartbeat(String nickname,String i2p_dest)
{
    try 
    {
        SSLSocket sslSocket=Client.get_SSLSock();
        
        //Socket s1 = new Socket("localhost", 5999);
        ObjectOutputStream out = new ObjectOutputStream(sslSocket.getOutputStream());
        ObjectInputStream in = new ObjectInputStream(sslSocket.getInputStream());
        
        
        Message msg = new Message();
        msg.set_name(Client.nickname);
        msg.set_HB();
        out.writeObject(msg);//here goes i2p_dest for heartbeat
        out.flush();
        
        String check = (String)in.readObject();//Read string to know what to do next
        if (check.equals("ArrayList"))
        {
            ar1 = (ArrayList<Message>) in.readObject();
            for (int i=0;i<ar1.size();i++)//remove curent user from list
            {
                if(ar1.get(i).get_i2p_dest().equals(i2p_dest))
                {
                    ar1.remove(i);
                }
            }
            System.out.println("Received HeartBeat");
            System.out.print("Users:");
            for (int i = 0; i < ar1.size(); i++) {
                System.out.print(" " + ar1.get(i).get_nickname());
            }
            System.out.println();
            Client.model1.removeAllElements();//remove all users from model1
            for (int i = 0; i < ar1.size(); i++) {
                Client.model1.addElement(ar1.get(i).get_nickname());//add all active users
            }
            Client.users=ar1;
        }
        else
        {
            Client.registered=false;//Set that client is not registered in Registrar
            new NewConnection(nickname, i2p_dest);
        }
        
        sslSocket.close();
    } catch (IOException | ClassNotFoundException ex) 
    {
        ex.printStackTrace();
    }
}
 
开发者ID:georgemakrakis,项目名称:TrackMeIfYouCanChat,代码行数:53,代码来源:Heartbeat.java

示例15: connectSocket

import javax.net.ssl.SSLSocket; //导入方法依赖的package包/类
/**
 * @since 4.1
 */
public Socket connectSocket(final Socket sock, final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final HttpParams params) throws IOException
{
	if (remoteAddress == null)
	{
		throw new IllegalArgumentException("Remote address may not be null");
	}

	if (params == null)
	{
		throw new IllegalArgumentException("HTTP parameters may not be null");
	}

	SSLSocket sslSocket = (SSLSocket) (sock != null ? sock : createSocket());

	if (localAddress != null)
	{
		//            sslSocket.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
		sslSocket.bind(localAddress);
	}

	int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
	int soTimeout = HttpConnectionParams.getSoTimeout(params);

	try
	{
		sslSocket.connect(remoteAddress, connTimeout);
	}
	catch (SocketTimeoutException ex)
	{
		throw new ConnectTimeoutException(String.format("Connect to %s/%s timed out", remoteAddress.getHostName(), remoteAddress.getAddress()));
	}

	sslSocket.setSoTimeout(soTimeout);

	if (this.hostnameVerifier != null)
	{
		try
		{
			this.hostnameVerifier.verify(remoteAddress.getHostName(), sslSocket);
			// verifyHostName() didn't blowup - good!
		}
		catch (IOException iox)
		{
			// close the socket before re-throwing the exception
			try
			{
				sslSocket.close();
			}
			catch (Exception x)
			{ /*ignore*/ }
			throw iox;
		}
	}

	return sslSocket;
}
 
开发者ID:ultrasonic,项目名称:ultrasonic,代码行数:60,代码来源:SSLSocketFactory.java


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