Created
March 7, 2016 20:14
-
-
Save alexlehm/a7527a1eac119cca606e to your computer and use it in GitHub Desktop.
GetCertTLSTest.java
This file contains hidden or 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
| import javax.security.cert.X509Certificate; | |
| import org.junit.Test; | |
| import org.junit.runner.RunWith; | |
| import io.vertx.core.Vertx; | |
| import io.vertx.core.logging.Logger; | |
| import io.vertx.core.logging.LoggerFactory; | |
| import io.vertx.core.net.NetClient; | |
| import io.vertx.core.net.NetClientOptions; | |
| import io.vertx.core.net.NetSocket; | |
| import io.vertx.ext.unit.Async; | |
| import io.vertx.ext.unit.TestContext; | |
| import io.vertx.ext.unit.junit.VertxUnitRunner; | |
| /** | |
| * compare SSL connect and TLS connect (upgrade) | |
| * | |
| * @author <a href="http://oss.lehmann.cx/">Alexander Lehmann</a> | |
| */ | |
| @RunWith(VertxUnitRunner.class) | |
| public class GetCertTLSTest { | |
| Logger log = LoggerFactory.getLogger(this.getClass()); | |
| @Test | |
| public void testSSL(TestContext testContext) { | |
| Async async = testContext.async(); | |
| NetClientOptions options = new NetClientOptions(); | |
| options.setSsl(true); | |
| NetClient client = Vertx.vertx().createNetClient(options); | |
| client.connect(465, "smtp.gmail.com", r -> { | |
| if(r.succeeded()) { | |
| NetSocket ns = r.result(); | |
| X509Certificate[] certs; | |
| try { | |
| certs = ns.peerCertificateChain(); | |
| for(X509Certificate cert: certs) { | |
| log.info(cert.toString()); | |
| } | |
| async.complete(); | |
| } catch (Exception ex) { | |
| // TODO Auto-generated catch block | |
| ex.printStackTrace(); | |
| } | |
| } | |
| }); | |
| } | |
| @Test | |
| public void testTLS(TestContext testContext) { | |
| Async async = testContext.async(); | |
| NetClientOptions options = new NetClientOptions(); | |
| NetClient client = Vertx.vertx().createNetClient(options); | |
| client.connect(465, "smtp.gmail.com", r -> { | |
| if(r.succeeded()) { | |
| NetSocket ns = r.result(); | |
| ns.upgradeToSsl(v -> { | |
| X509Certificate[] certs; | |
| try { | |
| certs = ns.peerCertificateChain(); | |
| for(X509Certificate cert: certs) { | |
| log.info(cert.toString()); | |
| } | |
| async.complete(); | |
| } catch (Exception ex) { | |
| // TODO Auto-generated catch block | |
| ex.printStackTrace(); | |
| } | |
| }); | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment