import * as tls from 'tls';
test('test', function (done) {
let host = 'httpbin.org';
let socket = tls.connect({
port:443,
host,
servername: host, // this is required in case the server enabled SNI
}, () => {
let x509Certificate = socket.getPeerX509Certificate();
expect(x509Certificate.subject).toBe('CN=httpbin.org');
done();
});
});
1条答案
按热度按时间jq6vz3qz1#
https://www.npmjs.com/package/certnames包启发了我,然后我发现我可以直接用捆绑的
tls
模块来做,因为证书是通过tls层传输的,所以我们不需要发出http请求来获得它。