Skip to content

Instantly share code, notes, and snippets.

@technige
Last active June 25, 2020 11:36
Show Gist options
  • Save technige/9f909489cc0964606915b645ca7449ec to your computer and use it in GitHub Desktop.
Save technige/9f909489cc0964606915b645ca7449ec to your computer and use it in GitHub Desktop.
Tests for OCSP stapling
package tech.nige.demo;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
public class SocketDemo {
public static void main(String... args) throws NoSuchAlgorithmException, IOException {
SSLContext ssl = SSLContext.getDefault();
SSLSocket ss = (SSLSocket) ssl.getSocketFactory().createSocket();
InetSocketAddress address = new InetSocketAddress("py2neo.org", 443);
ss.connect(address);
Certificate[] certs = ss.getSession().getPeerCertificates();
for (Certificate cert : certs) {
System.out.println(cert);
}
ss.close();
}
}
import {connect} from "tls";
const host = "py2neo.org";
const port = 443;
const ss = connect(port, host, {"servername": host}, () => {
console.log(ss.getPeerCertificate(true));
ss.end();
});
from pprint import pprint
from socket import create_connection
from ssl import SSLContext, CERT_REQUIRED
host = "py2neo.org"
port = 443
ctx = SSLContext()
ctx.verify_mode = CERT_REQUIRED
ctx.load_default_certs()
ss = ctx.wrap_socket(create_connection((host, port)), server_hostname=host)
pprint(ss.getpeercert())
ss.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment