Created
December 24, 2020 20:21
-
-
Save saltukalakus/9bafaef1342d2c15ece3dd03da2c2b02 to your computer and use it in GitHub Desktop.
Calculate domain fingerprints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const openssl = require('openssl-nodejs'); | |
const crypto = require('crypto'); | |
function handler(domain) | |
{ | |
return openssl(['s_client', '-connect', domain, '-showcerts'], function (err, buffer) { | |
const res = getCertificateFingerprintSha256(buffer.toString()); | |
console.log("sha - 256", res); | |
const res2 = getCertificateFingerprintSha1(buffer.toString()); | |
console.log("sha - 1", res2); | |
}); | |
}; | |
function getCertificateFingerprintSha256(certString) { | |
const baseString = certString.match(/-----BEGIN CERTIFICATE-----\s*([\s\S]+?)\s*-----END CERTIFICATE-----/i); | |
const rawCert = Buffer.from(baseString[1], "base64"); | |
const sha256sum = crypto.createHash("sha256").update(rawCert).digest("hex"); | |
return sha256sum.toUpperCase().replace(/(.{2})(?!$)/g, "$1:"); | |
} | |
function getCertificateFingerprintSha1(certString) { | |
const baseString = certString.match(/-----BEGIN CERTIFICATE-----\s*([\s\S]+?)\s*-----END CERTIFICATE-----/i); | |
const rawCert = Buffer.from(baseString[1], "base64"); | |
const sha1sum = crypto.createHash("sha1").update(rawCert).digest("hex"); | |
return sha1sum.toUpperCase().replace(/(.{2})(?!$)/g, "$1:"); | |
} | |
handler("saltukalakus.auth0.com:443"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment