use of javax.net.ssl.SSLSession in project jdk8u_jdk by JetBrains.
the class X509TrustManagerImpl method getRequestedServerNames.
// Also used by X509KeyManagerImpl
static List<SNIServerName> getRequestedServerNames(Socket socket) {
if (socket != null && socket.isConnected() && socket instanceof SSLSocket) {
SSLSocket sslSocket = (SSLSocket) socket;
SSLSession session = sslSocket.getHandshakeSession();
if (session != null && (session instanceof ExtendedSSLSession)) {
ExtendedSSLSession extSession = (ExtendedSSLSession) session;
return extSession.getRequestedServerNames();
}
}
return Collections.<SNIServerName>emptyList();
}
use of javax.net.ssl.SSLSession in project BBS-Android by bdpqchen.
the class CollectionClient method getUnSaveBuilder.
private static OkHttpClient.Builder getUnSaveBuilder() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
} };
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final javax.net.ssl.SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
return builder;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.net.ssl.SSLSession in project webpieces by deanhiller.
the class TestSSLEngine method testRawSSLEngine.
//private static final Logger log = LoggerFactory.getLogger(TestSSLEngine.class);
/**
* Sunny day scenaior of normal two normal SSLEngines...no split packets,
* no failures, etc.
* @throws Exception
*/
public void testRawSSLEngine() throws Exception {
SSLEngine server = getServerEngine();
SSLEngine client = getClientEngine();
SSLSession s = client.getSession();
ByteBuffer unencrPacket = ByteBuffer.allocate(s.getApplicationBufferSize());
ByteBuffer encPacket = ByteBuffer.allocate(s.getPacketBufferSize());
encPacket.clear();
unencrPacket.clear();
doHandshakeAndVerify(client, server, unencrPacket, encPacket);
doRehandshake();
//connection is now established....
encPacket.clear();
client.closeOutbound();
SSLEngineResult result = client.wrap(unencrPacket, encPacket);
assertEquals(HandshakeStatus.NEED_UNWRAP, result.getHandshakeStatus());
assertEquals(Status.CLOSED, result.getStatus());
encPacket.flip();
result = server.unwrap(encPacket, unencrPacket);
assertEquals(HandshakeStatus.NEED_WRAP, result.getHandshakeStatus());
assertEquals(Status.CLOSED, result.getStatus());
encPacket.clear();
result = server.wrap(unencrPacket, encPacket);
assertEquals(HandshakeStatus.NOT_HANDSHAKING, result.getHandshakeStatus());
assertEquals(Status.CLOSED, result.getStatus());
encPacket.flip();
result = client.unwrap(encPacket, unencrPacket);
assertEquals(HandshakeStatus.NOT_HANDSHAKING, result.getHandshakeStatus());
assertEquals(Status.CLOSED, result.getStatus());
}
use of javax.net.ssl.SSLSession in project bnd by bndtools.
the class HttpsUtil method disableServerVerification.
static void disableServerVerification(URLConnection connection) throws GeneralSecurityException {
if (!(connection instanceof HttpsURLConnection))
return;
HttpsURLConnection httpsConnection = (HttpsURLConnection) connection;
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException {
}
public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException {
}
} };
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new SecureRandom());
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
httpsConnection.setSSLSocketFactory(sslSocketFactory);
HostnameVerifier trustAnyHost = new HostnameVerifier() {
public boolean verify(String string, SSLSession session) {
return true;
}
};
httpsConnection.setHostnameVerifier(trustAnyHost);
}
use of javax.net.ssl.SSLSession in project opennms by OpenNMS.
the class VmwareViJavaAccess method relax.
/**
* This method is used to "relax" the policies concerning self-signed certificates.
*/
protected void relax() {
TrustManager[] trustAllCerts = new TrustManager[] { new AnyServerX509TrustManager() };
try {
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
} catch (Exception exception) {
logger.warn("Error setting relaxed SSL policy", exception);
}
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
});
}
Aggregations