use of javax.net.ssl.SSLSession in project ORCID-Source by ORCID.
the class OrcidJerseyT2ClientOAuthConfig method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
SSLContext ctx = createSslContext();
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
}, ctx));
}
use of javax.net.ssl.SSLSession in project jdk8u_jdk by JetBrains.
the class JSSEClient method runTest.
@Override
void runTest(CipherTestUtils.TestParameters params) throws Exception {
SSLSocket socket = null;
try {
System.out.println("Connecting to server...");
keyManager.setAuthType(params.clientAuth);
sslContext.init(new KeyManager[] { keyManager }, new TrustManager[] { cipherTest.getClientTrustManager() }, CipherTestUtils.secureRandom);
SSLSocketFactory factory = (SSLSocketFactory) sslContext.getSocketFactory();
socket = (SSLSocket) factory.createSocket(serverHost, serverPort);
socket.setSoTimeout(CipherTestUtils.TIMEOUT);
socket.setEnabledCipherSuites(params.cipherSuite.split(","));
if (params.protocol != null && !params.protocol.trim().equals("") && !params.protocol.trim().equals(DEFAULT)) {
socket.setEnabledProtocols(params.protocol.split(","));
}
CipherTestUtils.printInfo(socket);
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
sendRequest(in, out);
SSLSession session = socket.getSession();
session.invalidate();
String cipherSuite = session.getCipherSuite();
if (params.cipherSuite.equals(cipherSuite) == false) {
throw new RuntimeException("Negotiated ciphersuite mismatch: " + cipherSuite + " != " + params.cipherSuite);
}
String protocol = session.getProtocol();
if (!DEFAULT.equals(params.protocol) && !params.protocol.contains(protocol)) {
throw new RuntimeException("Negotiated protocol mismatch: " + protocol + " != " + params.protocol);
}
if (!cipherSuite.contains("DH_anon")) {
session.getPeerCertificates();
}
Certificate[] certificates = session.getLocalCertificates();
if (params.clientAuth == null) {
if (certificates != null) {
throw new RuntimeException("Local certificates " + "should be null");
}
} else {
if ((certificates == null) || (certificates.length == 0)) {
throw new RuntimeException("Certificates missing");
}
String keyAlg = certificates[0].getPublicKey().getAlgorithm();
if ("EC".equals(keyAlg)) {
keyAlg = "ECDSA";
}
if (params.clientAuth == null ? keyAlg != null : !params.clientAuth.equals(keyAlg)) {
throw new RuntimeException("Certificate type mismatch: " + keyAlg + " != " + params.clientAuth);
}
}
} finally {
if (socket != null) {
socket.close();
}
}
}
use of javax.net.ssl.SSLSession in project jdk8u_jdk by JetBrains.
the class AcceptLargeFragments method main.
public static void main(String[] args) throws Exception {
SSLContext context = SSLContext.getDefault();
// set the property before initialization SSLEngine.
System.setProperty("jsse.SSLEngine.acceptLargeFragments", "true");
SSLEngine cliEngine = context.createSSLEngine();
cliEngine.setUseClientMode(true);
SSLEngine srvEngine = context.createSSLEngine();
srvEngine.setUseClientMode(false);
SSLSession cliSession = cliEngine.getSession();
SSLSession srvSession = srvEngine.getSession();
// check packet buffer sizes.
if (cliSession.getPacketBufferSize() < 33049 || srvSession.getPacketBufferSize() < 33049) {
throw new Exception("Don't accept large SSL/TLS fragments");
}
// check application data buffer sizes.
if (cliSession.getApplicationBufferSize() < 32768 || srvSession.getApplicationBufferSize() < 32768) {
throw new Exception("Don't accept large SSL/TLS application data ");
}
}
use of javax.net.ssl.SSLSession in project undertow by undertow-io.
the class JettyAlpnProvider method getSelectedProtocol.
@Override
public String getSelectedProtocol(SSLEngine engine) {
SSLSession handshake = engine.getHandshakeSession();
if (handshake != null) {
return (String) handshake.getValue(PROTOCOL_KEY);
}
handshake = engine.getSession();
if (handshake != null) {
return (String) handshake.getValue(PROTOCOL_KEY);
}
return null;
}
use of javax.net.ssl.SSLSession in project pictureapp by EyeSeeTea.
the class UnsafeOkHttpsClientFactory method getUnsafeOkHttpClient.
public static OkHttpClient getUnsafeOkHttpClient() {
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) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
} };
// 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 SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setSslSocketFactory(sslSocketFactory);
okHttpClient.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations