{"version":3,"file":"trust-cert.cjs","sources":["../src/trust-cert.ts"],"sourcesContent":["import { copyFileSync, accessSync, existsSync, readdirSync, lstat, readFileSync } from 'fs'\nimport { join, basename, extname } from 'path'\nimport { promisify } from 'util'\nimport which from 'async-which'\nimport { Certificate } from '@fidm/x509'\nimport { exec as sudoExec } from 'exec-root'\nimport { exec } from 'child_process'\nimport * as os from 'os'\n\nconst nonSudoExec = promisify(exec)\nconst lstatAsync = promisify(lstat)\n\nexport const isDirectory = async (source: any) => {\n  try {\n    const stats = await lstatAsync(source)\n    return stats.isDirectory()\n  } catch (e) {\n    return false\n  }\n}\nconst isFile = async (source: any) => {\n  try {\n    const stats = await lstatAsync(source)\n    return stats.isFile()\n  } catch (e) {\n    return false\n  }\n}\nconst getCertCommonName = async (certPath: string) => {\n  // Check cert exists\n  accessSync(certPath)\n\n  // Read file\n  const cert = Certificate.fromPEM(readFileSync(certPath))\n  return cert.issuer.commonName\n}\n\nexport function generateTrust(platform: string = os.platform(), appName: string = 'Certificate Trust') {\n  if (platform === 'darwin') {\n    return new MacOsTrust(appName)\n  } else if (platform === 'win32') {\n    return new WindowsTrust(appName)\n  } else if (platform === 'linux') {\n    return new LinuxTrust(appName)\n  } else if (platform === 'nss') {\n    return new NssTrust(appName)\n  } else {\n    throw new Error('Only MacOs, Linux and Windows supported')\n  }\n}\n\nexport class Trust {\n  name: string = ''\n  appName: string = ''\n\n  constructor (appName: string) {\n    this.appName = appName\n  }\n\n  handleInstallResult(stderr: string, adding: boolean) {\n    if (stderr) {\n      throw {\n        message: `Could not ${adding ? 'add cert to' : 'remove cert from'} ${this.name} store`,\n        err: stderr\n      }\n    } else {\n      console.log(`Certificate successfully ${adding ? 'added to' : 'removed from'} ${this.name}!`)\n      return true\n    }\n  }\n}\n\nexport class MacOsTrust extends Trust {\n  name: string = 'MacOs'\n\n  async installFromFile(certPath: string) {\n    // Check cert exists\n    accessSync(certPath)\n\n    const { stderr } = await sudoExec(\n      `security add-trusted-cert -d -k /Library/Keychains/System.keychain \"${certPath}\"`,\n      { name: this.appName }\n    )\n\n    this.handleInstallResult(stderr, true)\n  }\n\n  async uninstall(certPath: string) {\n    const { stderr } = await sudoExec(\n      `security delete-certificate -c \"${await getCertCommonName(certPath)}\"`,\n      { name: this.appName }\n    )\n    this.handleInstallResult(stderr, false)\n  }\n\n  async exists(certPath: string): Promise<boolean> {\n    try {\n      await nonSudoExec(\n        `security find-certificate -c ${await getCertCommonName(\n          certPath\n        )} \"/Library/Keychains/System.keychain\"`\n      )\n      return true\n    } catch (e) {\n      return false\n    }\n  }\n}\n\nexport class WindowsTrust extends Trust {\n  name: string = 'Windows'\n\n  async installFromFile(certPath: string) {\n    // Check cert exists\n    accessSync(certPath)\n\n    // Copy over to .cer\n    const newCertPath = this.convertPathToCer(certPath)\n\n    // Copy cert to trust path\n    copyFileSync(certPath, newCertPath)\n\n    const { stderr } = await sudoExec(\n      `certutil -addstore \"Root\" \"${newCertPath}\"`,\n      { name: this.appName }\n    )\n\n    this.handleInstallResult(stderr, true)\n  }\n\n  async uninstall(certPath: string) {\n    const { stdout, stderr } = await nonSudoExec(`certutil.exe -dump \"${certPath}\" | find \"Serial\"`)\n\n    if (stdout) {\n      const [, , serialNumber] = stdout.split(' ')\n      const { stderr } = await sudoExec(\n        `certutil -delstore \"Root\" \"${serialNumber.trim()}\"`,\n        { name: this.appName }\n      )\n      this.handleInstallResult(stderr, false)\n    } else {\n      this.handleInstallResult(stderr, false)\n    }\n  }\n\n  async exists(certPath: string): Promise<boolean> {\n    try {\n      const { stdout, stderr } = await nonSudoExec(`certutil.exe -verify \"${certPath}\"`)\n\n      // ?\n      if (stdout) {\n        return !/UNTRUSTED root/.test(stdout)\n        // Does not exist\n      } else if (stderr) {\n        return false\n        // Exists\n      } else {\n        return true\n      }\n    } catch (e) {\n      return false\n    }\n  }\n\n  convertPathToCer(oldCertPath: string) {\n    return oldCertPath.substr(0, oldCertPath.lastIndexOf('.')) + '.cer'\n  }\n}\n\nexport class LinuxTrust extends Trust {\n  name: string = 'Linux'\n\n  // SystemTrustFilename is the format used to name the root certificates.\n  systemTrustFilename: string = ''\n\n  // systemTrustCommands is the command used to update the system truststore.\n  systemTrustCommands: string[] = []\n\n  constructor(appName: string) {\n    super(appName)\n\n    if (existsSync('/etc/pki/ca-trust/source/anchors/')) {\n      this.systemTrustFilename = '/etc/pki/ca-trust/source/anchors/%s.pem'\n      this.systemTrustCommands = ['update-ca-trust', 'extract']\n    } else if (existsSync('/usr/local/share/ca-certificates/')) {\n      this.systemTrustFilename = '/usr/local/share/ca-certificates/%s.crt'\n      this.systemTrustCommands = ['update-ca-certificates']\n    } else if (existsSync('/etc/ca-certificates/trust-source/anchors/')) {\n      this.systemTrustFilename = '/etc/ca-certificates/trust-source/anchors/%s.crt'\n      this.systemTrustCommands = ['trust', 'extract-compat']\n    }\n\n    if (this.systemTrustCommands) {\n      const resolved = which(this.systemTrustCommands[0])\n\n      if (!resolved) {\n        this.systemTrustCommands = []\n      }\n    }\n  }\n\n  async installFromFile(certPath: string) {\n    // Check cert exists and copy cert to trust path\n    existsSync(certPath)\n    copyFileSync(certPath, this.getNewCertPath(certPath))\n\n    // Update trust store\n    const { stderr } = await sudoExec(\n      this.systemTrustCommands.join(' '),\n      { name: this.appName }\n    )\n    this.handleInstallResult(stderr, true)\n  }\n\n  async uninstall(certPath: string) {\n    const { stderr } = await sudoExec(\n      `rm -f ${this.getNewCertPath(certPath)}`,\n      { name: this.appName }\n    )\n    this.handleInstallResult(stderr, false)\n  }\n\n  async exists(certPath: string): Promise<boolean> {\n    return isFile(this.getNewCertPath(certPath))\n  }\n\n  getNewCertPath(certPath: string): string {\n    const certFileName = basename(certPath, extname(certPath))\n    return this.systemTrustFilename.replace('%s', certFileName)\n  }\n}\n\nexport class NssTrust extends Trust {\n  name: string = 'Nss'\n  nssProfileDir: string = this.getNssProfileDir()\n  certutilPath: string = this.getCertutilPath()\n\n  async installFromFile(certPath: string) {\n    for (const db of await this.getFirefoxDatabases()) {\n      const { stderr } = await sudoExec(\n        `${this.certutilPath} -A -d \"${db}\" -t C,, -n \"${await getCertCommonName(certPath)}\" -i \"${certPath}\"`,\n        { name: this.appName }\n      )\n\n      this.handleInstallResult(stderr, true)\n    }\n  }\n\n  async uninstall(certPath: string) {\n    for (const db of await this.getFirefoxDatabases()) {\n      const { stderr } = await sudoExec(\n        `${this.certutilPath} -D -d \"${db}\" -n \"${await getCertCommonName(certPath)}\"`,\n        { name: this.appName }\n      )\n\n      this.handleInstallResult(stderr, false)\n    }\n  }\n\n  async exists(certPath: string): Promise<boolean> {\n    const firefoxDbs = await this.getFirefoxDatabases()\n    let allExist = firefoxDbs.length > 0\n\n    for (const db of firefoxDbs) {\n      try {\n        await nonSudoExec(\n          `${this.certutilPath} -V -d \"${db}\" -n \"${await getCertCommonName(certPath)}\" -u L`\n        )\n      } catch (e) {\n        allExist = false\n      }\n    }\n\n    return allExist\n  }\n\n  async getFirefoxDatabases() {\n    // Get all user profiles\n    const profiles = readdirSync(this.nssProfileDir).map(profile =>\n      join(this.nssProfileDir, profile)\n    )\n\n    let profileDirs = []\n    for (const profile of profiles) {\n      if (await isDirectory(profile)) {\n        profileDirs.push(profile)\n      }\n    }\n\n    // If any directories\n    if (profileDirs.length) {\n      let dbLinks = []\n      for (const profile of profileDirs) {\n        if (await isFile(join(profile, 'cert9.db'))) {\n          dbLinks.push(`sql:${profile}`)\n        } else if (await isFile(join(profile, 'cert8.db'))) {\n          dbLinks.push(`dbm:${profile}`)\n        }\n      }\n\n      return dbLinks\n    } else {\n      console.log('No profiles with cert8 or cert9 dbs found in firefox directory.')\n      return []\n    }\n  }\n\n  getNssProfileDir(): string {\n    const platform = os.platform()\n    if (platform === 'win32') {\n      return process.env['USERPROFILE'] + '\\\\AppData\\\\Roaming\\\\Mozilla\\\\Firefox\\\\Profiles'\n    } else if (platform === 'darwin') {\n      return process.env['HOME'] + '/Library/Application Support/Firefox/Profiles/'\n    } else if (platform === 'linux') {\n      return process.env['HOME'] + '/.mozilla/firefox/'\n    } else {\n      return ''\n    }\n  }\n\n  getCertutilPath(): string {\n    if (process.platform === 'win32') {\n      if (process.arch === 'x64') {\n        return join(__dirname, '..', 'nss', 'win64', 'certutil.exe')\n        // ia32\n      } else {\n        return join(__dirname, '..', 'nss', 'win32', 'certutil.exe')\n      }\n    } else if (process.platform === 'darwin') {\n      return join(__dirname, '..', 'nss', 'mac', 'certutil')\n    } else if (process.platform === 'linux') {\n      if (process.arch === 'x64') {\n        return join(__dirname, '..', 'nss', 'linux64', 'certutil')\n      } else {\n        return join(__dirname, '..', 'nss', 'linux32', 'certutil')\n      }\n    } else {\n      throw new Error('NSS only supported on MacOs, Linux and Windows')\n    }\n  }\n}\n"],"names":["promisify","exec","lstat","accessSync","Certificate","readFileSync","os.platform","tslib_1.__extends","sudoExec","copyFileSync","existsSync","basename","extname","readdirSync","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sBAqVA;AA5UA,IAAM,WAAW,GAAGA,cAAS,CAACC,kBAAI,CAAC,CAAA;AACnC,IAAM,UAAU,GAAGD,cAAS,CAACE,QAAK,CAAC,CAAA;AAEnC,IAAa,WAAW,GAAG,UAAO,MAAW;;;;;;gBAE3B,qBAAM,UAAU,CAAC,MAAM,CAAC,EAAA;;gBAAhC,KAAK,GAAG,SAAwB;gBACtC,sBAAO,KAAK,CAAC,WAAW,EAAE,EAAA;;;gBAE1B,sBAAO,KAAK,EAAA;;;;KAEf,CAAA;AACD,IAAM,MAAM,GAAG,UAAO,MAAW;;;;;;gBAEf,qBAAM,UAAU,CAAC,MAAM,CAAC,EAAA;;gBAAhC,KAAK,GAAG,SAAwB;gBACtC,sBAAO,KAAK,CAAC,MAAM,EAAE,EAAA;;;gBAErB,sBAAO,KAAK,EAAA;;;;KAEf,CAAA;AACD,IAAM,iBAAiB,GAAG,UAAO,QAAgB;;;;QAE/CC,a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