/** * @return The active {@link SSLSession} for the Socket or null if there is none */ private SSLSession getSslSession(final Socket socket) { return ((SSLSocket) socket).getSession(); }
@Override public SSLSession getSession() { return sock.getSession(); }
public SSLSession getSession() { return delegate.getSession(); }
public SSLSession getSession() { return socket.getSession(); }
/** * @return peer certificate chain associated with the ssl socket */ @Override public X509Certificate[] getPeerCertificates() { SSLSocket sslSocket = (SSLSocket)this.socket; SSLSession sslSession = sslSocket.getSession(); X509Certificate[] clientCertChain; try { clientCertChain = (X509Certificate[])sslSession.getPeerCertificates(); } catch (SSLPeerUnverifiedException e) { clientCertChain = null; } return clientCertChain; }
SSLSocketFactory ssf = (SSLSocketFactory) sslContext.getSocketFactory(); SSLSocket sslSocket = (SSLSocket) ssf.createSocket("untrusted.host.example", 443); SSLSession sslSession = sslSocket.getSession(); sslSession.getPeerCertificates();
SSLSocketFactory ssf = (SSLSocketFactory) sslContext.getSocketFactory(); SSLSocket sslSocket = (SSLSocket) ssf.createSocket("untrusted.host.example", 443); SSLSession sslSession = sslSocket.getSession(); // sslSession.getPeerCertificates(); sslSocket.getInputStream().read();
if (socket instanceof SSLSocket) { try { this.handshake = Handshake.get(((SSLSocket) socket).getSession()); } catch (IOException e) { throw new IllegalArgumentException(e);
public final void verify(String host, SSLSocket ssl) throws IOException { if(host == null) { throw new NullPointerException("host to verify is null"); } SSLSession session = ssl.getSession(); Certificate[] certs = session.getPeerCertificates(); X509Certificate x509 = (X509Certificate) certs[0]; verify(host, x509); }
@Override public SSLSession getSSLSession() { final Socket socket = super.getSocket(); if (socket instanceof SSLSocket) { return ((SSLSocket) socket).getSession(); } else { return null; } }
private Set<String> getCertificateIdentities(final Socket socket) throws IOException { if (socket instanceof SSLSocket) { try { final SSLSession sslSession = ((SSLSocket) socket).getSession(); return getCertificateIdentities(sslSession); } catch (CertificateException e) { throw new IOException("Could not extract Subject Alternative Names from client's certificate", e); } } else { return Collections.emptySet(); } }
private static String stringifyPrincipal(SSLSocket socket) { try { return String.format(" (%s)", socket.getSession().getPeerPrincipal().toString()); } catch (Exception e) { // Principal information is not available. return ""; } }
private void verifyHostname(SSLSocket socket, String hostname) throws HostnameUnverifiedException { if (mVerifyHostname == false) { // Skip hostname verification. return; } // Hostname verifier. OkHostnameVerifier verifier = OkHostnameVerifier.INSTANCE; // The SSL session. SSLSession session = socket.getSession(); // Verify the hostname. if (verifier.verify(hostname, session)) { // Verified. No problem. return; } // The certificate of the peer does not match the expected hostname. throw new HostnameUnverifiedException(socket, hostname); }
public SSLSession getSSLSession() { OperatedClientConnection conn = getWrappedConnection(); assertValid(conn); if (!isOpen()) return null; SSLSession result = null; Socket sock = conn.getSocket(); if (sock instanceof SSLSocket) { result = ((SSLSocket)sock).getSession(); } return result; }
client_sock.setEnabledCipherSuites(client_sock.getSupportedCipherSuites()); client_sock.startHandshake(); SSLSession sslSession=client_sock.getSession();
public void upgradeToSSL(SSLSocketFactory sslSocketFactory, HostnameVerifier hostnameVerifier) throws IOException { SSLSocket sslSocket = sslSocketFactory.createSocket(this.socket); sslSocket.startHandshake(); socket = sslSocket; inputStream = new ByteArrayInputStream(sslSocket.getInputStream()); outputStream = new ByteArrayOutputStream(sslSocket.getOutputStream()); if (hostnameVerifier != null && !hostnameVerifier.verify(sslSocket.getInetAddress().getHostName(), sslSocket.getSession())) { throw new IdentityVerificationException("\"" + sslSocket.getInetAddress().getHostName() + "\" identity was not confirmed"); } }
protected SSLSocket createSocketTo(Address target) throws Exception { SSLContext ctx=getContext(); SSLSocketFactory sslSocketFactory=ctx.getSocketFactory(); IpAddress dest=(IpAddress)down_prot.down(new Event(Event.GET_PHYSICAL_ADDRESS, target)); SSLSocket sock=null; for(int i=0; i < port_range; i++) { try { sock=(SSLSocket)sslSocketFactory.createSocket(dest.getIpAddress(), port+i); sock.setSoTimeout(socket_timeout); sock.setEnabledCipherSuites(sock.getSupportedCipherSuites()); sock.startHandshake(); SSLSession sslSession=sock.getSession(); log.debug("%s: created SSL connection to %s (%s); protocol: %s, cipher suite: %s", local_addr, target, sock.getRemoteSocketAddress(), sslSession.getProtocol(), sslSession.getCipherSuite()); if(session_verifier != null) session_verifier.verify(sslSession); return sock; } catch(SecurityException sec_ex) { throw sec_ex; } catch(Throwable t) { } } throw new IllegalStateException(String.format("failed connecting to %s (port range [%d - %d])", dest.getIpAddress(), port, port+port_range)); }
SSLSession sslSocketSession = sslSocket.getSession(); Handshake unverifiedHandshake = Handshake.get(sslSocketSession);
Handshake unverifiedHandshake = Handshake.get(sslSocket.getSession()); if (!address.hostnameVerifier().verify(address.url().host(), sslSocket.getSession())) { X509Certificate cert = (X509Certificate) unverifiedHandshake.peerCertificates().get(0); throw new SSLPeerUnverifiedException("Hostname " + address.url().host() + " not verified:"
private static void verifyPeerName(PGStream stream, Properties info, SSLSocket newConnection) throws PSQLException { HostnameVerifier hvn; String sslhostnameverifier = PGProperty.SSL_HOSTNAME_VERIFIER.get(info); if (sslhostnameverifier == null) { hvn = PGjdbcHostnameVerifier.INSTANCE; sslhostnameverifier = "PgjdbcHostnameVerifier"; } else { try { hvn = (HostnameVerifier) instantiate(sslhostnameverifier, info, false, null); } catch (Exception e) { throw new PSQLException( GT.tr("The HostnameVerifier class provided {0} could not be instantiated.", sslhostnameverifier), PSQLState.CONNECTION_FAILURE, e); } } if (hvn.verify(stream.getHostSpec().getHost(), newConnection.getSession())) { return; } throw new PSQLException( GT.tr("The hostname {0} could not be verified by hostnameverifier {1}.", stream.getHostSpec().getHost(), sslhostnameverifier), PSQLState.CONNECTION_FAILURE); }