Created
November 29, 2019 10:19
-
-
Save songlairui/1821f8580091c2148f45189d16b48444 to your computer and use it in GitHub Desktop.
generate self signed cerifcate. chrome, android mobile, traefik 生成自签名证书, 可用于 chrome 浏览器,安卓手机,traefik本地证书
This file contains 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
var fs = require("fs"); | |
var selfsigned = require("selfsigned"); | |
const SITE_PATTERN = "*.local.dev"; | |
var attrs = [ | |
{ name: "commonName", value: SITE_PATTERN }, | |
{ name: "countryName", value: "cn" }, | |
{ name: "localityName", value: "sz" }, | |
{ name: "stateOrProvinceName", value: "gd" }, | |
{ name: "organizationName", value: "x.y.f.g.z" }, | |
{ name: "organizationalUnitName", value: "ooooo" } | |
// 添加 emailAddress, 会导致 traefik 使用无效 | |
// { name: "emailAddress", value: "[email protected]" } | |
]; | |
var opts = { | |
days: 3650, | |
keySize: 2048, | |
algorithm: "sha256", | |
// 前两个为默认的 extension 配置 | |
extensions: [ | |
{ | |
name: "basicConstraints", | |
cA: true // 非 cA, 则 android 无法导入 | |
}, | |
{ | |
name: "keyUsage", | |
keyCertSign: true, | |
digitalSignature: true, | |
nonRepudiation: true, | |
keyEncipherment: true, | |
dataEncipherment: true | |
}, | |
{ | |
name: "subjectAltName", | |
altNames: [ | |
{ | |
type: 2, | |
value: SITE_PATTERN | |
} | |
] | |
} | |
] | |
}; | |
var pems = selfsigned.generate(attrs, opts); | |
const { public, private, cert, fingerprint } = pems; | |
fs.writeFileSync("dev.pub", public); | |
fs.writeFileSync("dev.key", private); | |
fs.writeFileSync("dev.crt", cert); | |
fs.writeFileSync("dev.fingerprint", fingerprint); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment