async function veryfyCertFile()

in lib/CertificateTools.js [382:416]


async function veryfyCertFile(keyPath, certPath, pfxPath, passphrase) {
    let verifyCertDate;
    try {
        let endDateStr;

        // For Windows OS:
        if (os.platform() === "win32") {
            if (!fs.existsSync(pfxPath) || !passphrase) {
                return false;
            }
            let certStr = await exec(`powershell.exe (New-Object System.Security.Cryptography.X509Certificates.X509Certificate2('${pfxPath}','${passphrase}')).NotAfter.ToString('yyyy-MM-dd HH:mm:ss')`);
            endDateStr = certStr.trim();
        }
        // For Linux and Mac/darwin OS:
        else if (os.platform() === "linux" || os.platform() === "darwin") {
            if (!fs.existsSync(certPath)) {
                return false;
            }
            endDateStr = await exec(`openssl x509 -enddate -noout -in ${certPath} | cut -d = -f 2`);
        }

        let endDate = Date.parse(endDateStr);
        verifyCertDate = (endDate - Date.now()) > certSafePeriod;
        if (verifyCertDate) {
            ConsoleWriter.info(`Certificate is valid.`);
        } else {
            ConsoleWriter.warn(`Certificate is invalid!`);
            removeCertFiles(certPath, keyPath, pfxPath);
        }
    } catch (err) {
        ConsoleWriter.warn(`Certificate verification error: ${err}`);
        removeCertFiles(certPath, keyPath, pfxPath);
    }
    return verifyCertDate;
}