本文整理汇总了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;
}
示例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();
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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.
}
示例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();
}
}
示例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.");
}
}
示例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.
}
}
示例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;
}
}
示例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();
}
}
示例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;
}