@Override public void close() throws IOException { sock.close(); }
public void close() throws IOException { delegate.close(); }
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(); }
@Override public void close() throws IOException { if (log.isDebugEnabled()) log.debug("closing " + endpoint()); sock.close(); }
if (socket != null) { try { socket.close(); } catch (IOException ex) { LOGGER.trace("Error closing socket", ex);
private void closeSockets() { if(clientSocket != null) { try { clientSocket.close(); } catch(final Exception e) { e.printStackTrace(); } } if (serverSocket != null) { try { serverSocket.close(); } catch (final Exception e) { e.printStackTrace(); } } }
LOG.debug( "Starting SSL handshake..." ); socket.startHandshake(); socket.close(); LOG.debug( "No errors, certificate is already trusted" );
private static <T> T connectSSL(String address, int port, int timeout, F3<T, InputStream, BufferedReader, DataOutputStream> protocol) { T resp; try (SSLSocket socket = sslSocket(address, port, timeout)) { socket.setSoTimeout(timeout); resp = communicate(protocol, socket); socket.close(); } catch (Exception e) { throw U.rte(e); } return resp; }
try { sslsock.close(); } catch (Exception x) { /*ignore*/ } throw iox;
@Test public void emptyConfigurationHasDefaultTrustStore() throws IOException { final SslConfiguration sc = SslConfiguration.createSSLConfiguration(null, null, null); final SSLSocketFactory factory = sc.getSslSocketFactory(); try { try (final SSLSocket clientSocket = (SSLSocket) factory.createSocket(TLS_TEST_HOST, TLS_TEST_PORT)) { Assert.assertNotNull(clientSocket); clientSocket.close(); } } catch (final UnknownHostException offline) { // this exception is thrown on Windows when offline } }
} finally { if (sslSocket != null) { sslSocket.close();
} finally { if (sslSocket != null) { sslSocket.close();
@Override public void close() throws IOException { sock.close(); }
public void implCloseSelectableChannel() throws IOException { _socket.close(); }
@Override public void close() throws IOException { if (log.isDebugEnabled()) log.debug("closing " + endpoint()); sock.close(); }
/** * Check the server from the Socket connection against the server name(s) * as expressed in the server certificate (RFC 2595 check). * * @param server name of the server expected * @param sslSocket SSLSocket connected to the server * @exception IOException if we can't verify identity of server */ private static void checkServerIdentity(String server, SSLSocket sslSocket) throws IOException { // Check against the server name(s) as expressed in server certificate try { java.security.cert.Certificate[] certChain = sslSocket.getSession().getPeerCertificates(); if (certChain != null && certChain.length > 0 && certChain[0] instanceof X509Certificate && matchCert(server, (X509Certificate)certChain[0])) return; } catch (SSLPeerUnverifiedException e) { sslSocket.close(); IOException ioex = new IOException( "Can't verify identity of server: " + server); ioex.initCause(e); throw ioex; } // If we get here, there is nothing to consider the server as trusted. sslSocket.close(); throw new IOException("Can't verify identity of server: " + server); }
/** * Check the server from the Socket connection against the server name(s) * as expressed in the server certificate (RFC 2595 check). * * @param server name of the server expected * @param sslSocket SSLSocket connected to the server * @exception IOException if we can't verify identity of server */ private static void checkServerIdentity(String server, SSLSocket sslSocket) throws IOException { // Check against the server name(s) as expressed in server certificate try { java.security.cert.Certificate[] certChain = sslSocket.getSession().getPeerCertificates(); if (certChain != null && certChain.length > 0 && certChain[0] instanceof X509Certificate && matchCert(server, (X509Certificate)certChain[0])) return; } catch (SSLPeerUnverifiedException e) { sslSocket.close(); IOException ioex = new IOException( "Can't verify identity of server: " + server); ioex.initCause(e); throw ioex; } // If we get here, there is nothing to consider the server as trusted. sslSocket.close(); throw new IOException("Can't verify identity of server: " + server); }
@Override public void shutdown() { try { handleEvent(Event.STREAM_CLOSE, Direction.IN); } catch (Exception e) { s_logger.info("[ignored]" + "error sending input close event: " + e.getLocalizedMessage()); } try { handleEvent(Event.STREAM_CLOSE, Direction.OUT); } catch (Exception e) { s_logger.info("[ignored]" + "error sending output close event: " + e.getLocalizedMessage()); } try { if (sslSocket != null) sslSocket.close(); } catch (Exception e) { s_logger.info("[ignored]" + "error closing ssl socket: " + e.getLocalizedMessage()); } try { socket.close(); } catch (Exception e) { s_logger.info("[ignored]" + "error closing socket: " + e.getLocalizedMessage()); } }
/** * Lifted from Thrift-0.9.1 because it was private. Create an SSLSocket with the given factory, * host:port, and timeout. * * @param factory * Factory to create the socket from * @param host * Destination host * @param port * Destination port * @param timeout * Socket timeout */ private static TSocket createClient(SSLSocketFactory factory, String host, int port, int timeout) throws TTransportException { SSLSocket socket = null; try { socket = (SSLSocket) factory.createSocket(host, port); socket.setSoTimeout(timeout); return new TSocket(socket); } catch (Exception e) { try { if (socket != null) socket.close(); } catch (IOException ioe) {} throw new TTransportException("Could not connect to " + host + " on port " + port, e); } } }
if (!msf.isServerTrusted(host, sslsocket)) { try { sslsocket.close(); } finally { throw new IOException("Server is not trusted: " + host);