{"name":"node-easy-cert","version":"1.0.2","description":"A tool for managing self-signed certifications","main":"src/index.js","scripts":{"test":"sh test/test.sh"},"repository":{"type":"git","url":"git+https://github.com/ottomao/node-easy-cert.git"},"keywords":["certification","https"],"author":"","license":"MIT","dependencies":{"async-task-mgr":"^1.1.0","colorful":"^2.1.0","commander":"^2.9.0","node-forge":"^0.6.42"},"devDependencies":{"babel-polyfill":"^6.13.0","babel-preset-es2015":"^6.13.2","babel-preset-stage-0":"^6.5.0","babel-register":"^6.11.6","jasmine":"^2.4.1","bdd-stdin":"^0.2.0"},"gitHead":"d6d5c2208125cb9585832d74747ed5e1bdaad450","bugs":{"url":"https://github.com/ottomao/node-easy-cert/issues"},"homepage":"https://github.com/ottomao/node-easy-cert#readme","_id":"node-easy-cert@1.0.2","_shasum":"6e80ebadbad4c5990a92d3ecd16a936c45e8da8f","_from":".","_npmVersion":"3.10.9","_nodeVersion":"6.9.2","_npmUser":{"name":"ottomao","email":"ottomao@gmail.com"},"dist":{"shasum":"6e80ebadbad4c5990a92d3ecd16a936c45e8da8f","tarball":"http://registry-npm.ywwl.com/node-easy-cert/download/node-easy-cert-1.0.2.tgz","integrity":"sha512-uBCDHdR9Nx5oUAcVb2NCUW8+I7hzdgeKSf9NlY7Ni40nGudPaeJMywVklpBeDQwWfPZm31w8Vr0XFebhQGh35A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAMc06TnE8zjNyGf3FVs7fEqMAGqTJSK/+r4tYHGC2P6AiA/DnStvzTSHnNPoAsu08cs+3WTQtPD1jZvFhnQGEl4Sg=="}],"size":12296,"noattachment":false,"key":"/node-easy-cert/-/node-easy-cert-1.0.2.tgz"},"maintainers":[{"name":"codingfishman","email":"08fishman@gmail.com"},{"name":"ottomao","email":"ottomao@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/node-easy-cert-1.0.2.tgz_1485762054808_0.24353355495259166"},"directories":{},"readme":"node-easy-cert\n-------------------\n\n[![npm download][download-image]][download-url]\n\n[download-image]: https://img.shields.io/npm/dm/node-easy-cert.svg?style=flat-square\n[download-url]: https://npmjs.org/package/node-easy-cert\n\n\n## 用于管理自生成的HTTPS证书的插件\n本插件可以生成自签名的root证书，并基于该root证书，生成各个域名的HTTPS证书。\n\n## 使用方式\n```js\nconst CertManager = require('cert-manager');\n\nconst options = {\n  rootDirPath: '/the/full/path/of/the/dir', // default to /{USER_HOME}/{.node_easy_certs}/\n  // the default attrs of a generated cert, you can change it here\n  defaultCertAttrs: [\n    { name: 'countryName', value: 'CN' },\n    { name: 'organizationName', value: 'CertManager' },\n    { shortName: 'ST', value: 'SH' },\n    { shortName: 'OU', value: 'CertManager SSL' }\n  ]\n}\n\nconst crtMgr = new CertManager(options);\nconst rootOptions = {\n  commonName: 'theNameYouLike'\n};\n\ncrtMgr.generateRootCA(rootOptions);\n```\n## 配置项(可选)\n\n### rootDirPath\n证书目录的全路径，如果配置，优先级高于rootDirName\n\n## 证书生成目录\n默认情况下，证书都会生成在 `{USER_HOME}/.node_easy_certs/`。\n如果配置了`rootDirPath`, 那么所有的证书都会生成在该目录下。\n\n## 方法\n### generateRootCA(options, callback(error, keyPath, crtPath))\n在证书根目录下面生成根证书rootCA.crt 和 rootCA.key。生成后，请选择rootCA.crt,**安装并信任**，否则您的组件可能工作失败。\n\n#### 返回\n- 无\n\n#### 参数\n- options `object`\n  - options.commonName `string` `required`\n\n  rootCA的commonName，安装后，将会作为系统里面的证书名称显示在列表中\n  - options.overwrite `bool` `optional`\n\n  `default`: false\n  > 是否覆盖已经存在的rootCA，默认为false。在false的情形下，如果遇到已经存在的rootCA，会返回错误 `ROOT_CA_EXISTED` 并终止创建。\n\n- callback `function` `optional`\n\n  - error 如果发生错误，将放入error参数\n  - keyPath 生成好的rootCA.key的全路径\n  - crtPath 生成好的rootCA.crt的全路径\n\n#### 调用示例\n\n```js\nconst options = {\n  commonName: 'yourPreference'\n};\n\ncrtMgr.generateRootCA(options, (error, keyPath, crtPath) {\n  // 如果根证书已经存在，且没有设置overwrite为true，则需要捕获\n  if (error === 'ROOT_CA_EXISTED') {\n    // 处理当证书已经存在的情形\n  }\n\n  if(!error) {\n    // 证书需要被安装并信任，可以在此打开该目录并给出提示，也可以进行其他操作\n    const isWin = /^win/.test(process.platform);\n    const certDir = path.dirname(keyPath);\n    if(isWin){\n      exec(\"start .\",{ cwd : certDir });\n    }else{\n      exec(\"open .\",{ cwd : certDir });\n    }\n  }\n});\n```\n\n### getCertificate(hostname, callback([error, keyContent, crtContent]))\n获取指定域名下的证书的key和crt内容，如果证书还不存在，则会先创建该证书。\n\n> 证书的生成基于生成的rootCA根证书来签名，如果rootCA根证书还未创建，则会终止并抛出错误：`ROOT_CA_NOT_EXISTS`\n\n#### 返回\n- 无\n\n#### 参数\n- `hostname` `string`\n所要获取证书内容的hostname\n\n- `callback` `function`\n获取到内容后的回调函数，主要包含key的内容和crt的内容，如果获取过程中出现异常，则放入error变量中\n\n> 获取子域名的证书，要求已经存在根证书，否则会提示失败。组件会抛出对应的异常。您可以捕获并通过 `generateRootCA()`来生成根证书。**并安装并请信任该根证书**\n\n#### 调用实例\n```js\ncertManager.getCertificate('localhost', (error, keyContent, crtContent) => {\n\n  // 如果根证书还没有生成，需要先生成根证书\n  if (error === 'ROOT_CA_NOT_EXISTS') {\n    // handle the issue\n  }\n\n  // 正常操作\n  // ...\n});\n\n```\n\n### getRootDirPath()\n获取由当前cert-manager实例所管理的证书的根目录\n\n#### 返回\n- `string`\n  当前cert-manager实例所管理的证书所对应的根目录。默认为{USER_HOME}/.node_easy_certs/\n\n### getRootCAFilePath()\n获取根证书的全路径\n\n#### 返回\n- `string`\n根证书的全路径，如果根证书不存在，将返回空字符串\n\n### isRootCAFileExists()\n获取根证书是否存在的状态\n\n### ifRootCATrusted()\n检测RootCA是否已经被信任\n> 1.2.1 新增对Windows平台的支持\n\n#### 返回\n- `bool` 是否存在根证书\n\n### clearCerts()\n清除当前目录下所有的证书文件\n\n#### 返回\n- 无\n\n#### 参数\n- `callback`  `function`\n删除结束后的回调函数，如果删除过程中有错误，将会被放入error对象中\n\n# 错误码\n在运行过程中，会根据错误原因抛出指定错误码，包括如下\n\n| 错误码        | 释义           | 备注|\n| ------------- |:-------------:|:----------:|\n|ROOT_CA_NOT_EXISTS   |root根证书不存在。当我们执行的某个操作依赖于根证书，而根证书不存在时，就会抛出该异常。我们可以尝试生成根证书||\n|ROOT_CA_COMMON_NAME_UNSPECIFIED| commonName未设置。比如当我们调用`genearteRootCA()`时,commonName是必传的。||\n|ROOT_CA_EXISTED |rootCA 根证书已经存在。当我们重新生成证书，如果证书已经存在，会抛出该异常。|可以在调用`generateRootCA`时，传入 `option.overwirte=true`来覆盖|\n\n","publish_time":1485762055039,"_cnpm_publish_time":1485762055039,"dist-tags":{"latest":"1.3.3"}}