Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access ssl certificate content using chrome puppeteer

I would like to access certificate details of a url using chrome puppeteer. Is it possible to do it with current puppeteer API?

like image 347
Abhishek Avatar asked Sep 08 '17 04:09

Abhishek


People also ask

How do I view an SSL certificate?

To check an SSL certificate on any website, all you need to do is follow two simple steps. First, check if the URL of the website begins with HTTPS, where S indicates it has an SSL certificate. Second, click on the padlock icon on the address bar to check all the detailed information related to the certificate.

How do I view SSL certificates on each browser?

First, go to any SSL-enabled website and tap on the padlock icon next to the URL. Now tap on the “Details” link. A popup will be on your screen that includes CA information along with security protocol and hashing algorithm used. Tap on Certificate Information to view more details about the certificate.


2 Answers

You can access the DER-encoded certificate using the Chrome DevTools Protocol Network.getCertificate method:

const certificate = await page._client.send('Network.getCertificate', {
  origin: 'https://example.com/',
});

for (let i = 0; i < certificate.tableNames.length; i++) {
  console.log(certificate.tableNames[i]);
}
like image 40
Grant Miller Avatar answered Oct 06 '22 00:10

Grant Miller


As Grant Miller said, you can access the full DER-encoded certificate using the Chrome DevTools Protocol Network.getCertificate method, instead of just the securityDetails a puppeteer response provices.

page.on('response', async (res) => {
  if (res.securityDetails() != null) {
    console.info(await page._client.send('Network.getCertificate', {origin: res.url()}));
    /*
      { tableNames: [ 'MIIDwTCCAqmgAwIBAgIJALzkRqUOhsraM...' ] }
      Network.getCertificate - Returns the DER-encoded certificate
    */
  }
}

You can then use any node package to parse each certificate from the encoded certificate chain.

like image 151
Marius Tibeica Avatar answered Oct 05 '22 23:10

Marius Tibeica