UNPKG

@lark-project/cli

Version:

飞书项目插件开发工具

84 lines (83 loc) 2.69 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isTrustedCert = exports.removeFromKeyChain = exports.addToKeyChain = void 0; const child_process_1 = require("child_process"); const execa_1 = __importDefault(require("execa")); /** * 添加到系统钥匙串并信任证书 */ function addToKeyChain(certPath) { // osx if (process.platform === 'darwin') { const result = (0, child_process_1.execSync)(`sudo security add-trusted-cert \ -d -r trustRoot \ -k /Library/Keychains/System.keychain \ '${certPath}'`); console.log(result); return; } // windows if (process.platform === 'win32') { const result = (0, child_process_1.execSync)(`certutil -addstore -user root ${certPath}`); console.log(result); return; } // linux (0, child_process_1.execSync)(`sudo cp ${certPath} /usr/local/share/ca-certificates/devcert.crt`); (0, child_process_1.execSync)('sudo update-ca-certificates'); } exports.addToKeyChain = addToKeyChain; /** * 从钥匙串移除证书 * @param certName * @returns */ function removeFromKeyChain(certName) { if (process.platform === 'darwin') { try { const result = (0, child_process_1.execSync)(`sudo security delete-certificate -c "${certName}"`); console.log(result); return true; } catch (e) { console.warn(e); return false; } } if (process.platform === 'win32') { try { const result = (0, child_process_1.execSync)(`certutil -delstore -user root "${certName}"`); console.log(result); return true; } catch (e) { console.warn(e); return false; } } return false; } exports.removeFromKeyChain = removeFromKeyChain; async function isTrustedCert({ certPath, sha1 }) { try { if (process.platform === 'darwin') { await (0, execa_1.default)('security', ['verify-cert', '-L', '-c', certPath]); return true; } // certutil 通过 sha1 指纹判断证书是否被信任最准 if (process.platform === 'win32') { await (0, execa_1.default)('certutil', ['-store', '-user', 'root', sha1]); return true; } // 其它系统暂不支持判断证书信任 return false; } catch (e) { console.warn(e); return false; } } exports.isTrustedCert = isTrustedCert;