function fetchCert()

in TLSFingerprint/src/TLSFingerprint.js [24:62]


function fetchCert(host) {
  let fCert = {subject: {CN: ""}, fingerprint: ""};
  const options = {
    hostname: host,
    port: 443,
    path: "/",
    method: 'GET',
    checkServerIdentity: function(host, cert) {
      const err = tls.checkServerIdentity(host, cert);
      if (err) {
        return err;
      }
      fCert.subject.CN = cert.subject.CN;
      fCert.fingerprint = cert.fingerprint.toLowerCase();
    }
  };
  
  options.agent = new https.Agent(options);
  
  return new Promise((resolve, reject) => {
    let req = https.request(options, (res) => {
      res.on('data', d => {});
    
      res.on('end', () => {
        console.log('  Fetching from:', host);
        console.log('    Subject Common Name:', fCert.subject.CN);
        console.log('    Certificate SHA-1 fingerprint:', fCert.fingerprint);
        resolve(fCert);
      });

      res.on('error', (err) => {
        reject(err);
      });

    });
    
    req.end();
  });
}