GetCertTLSTest.java
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