Last active
August 29, 2015 14:27
-
-
Save nomis/e6ae6a6b44edb7886492 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Socket s = null; | |
try { | |
/* from commons-net, simulation of STARTTLS by using a normal Socket to port 465 */ | |
s = new Socket("not-really-gmail.java.test.lp0.eu", 465); /* CNAME to smtp.gmail.com */ | |
SSLContext ctx = SSLContext.getInstance("TLS"); | |
ctx.init(null, null, null); | |
SSLSocketFactory ssf = ctx.getSocketFactory(); | |
// ssf = (SSLSocketFactory)SSLCertificateSocketFactory.getDefault(); | |
SSLSocket socket = (SSLSocket)ssf.createSocket(s, "not-really-gmail.java.test.lp0.eu", 465, true); | |
socket.setEnableSessionCreation(true); | |
socket.setUseClientMode(true); | |
// Can't use SSLParameters.setEndpointIdentificationAlgorithm("HTTPS") because Android doesn't support it | |
try { | |
socket.startHandshake(); | |
Log.i("test2", "Test failed"); | |
} catch (Exception e) { | |
Log.i("test2", "Handshake exception", e); | |
} | |
} catch (Exception e) { | |
Log.e("test2", "Error", e); | |
} finally { | |
try { | |
if (s != null) | |
s.close(); | |
} catch (IOException e) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment