Skip to content

Commit

Permalink
子客户端翻译修复
Browse files Browse the repository at this point in the history
  • Loading branch information
LY1806620741 committed Jan 2, 2024
1 parent e6f628e commit b320c65
Show file tree
Hide file tree
Showing 12 changed files with 1,059 additions and 129 deletions.
26 changes: 15 additions & 11 deletions client/active.en.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
errUnknownGroupCommand = "err. Unknown command \"{{.Name}}\""
failedDeCodePublicKey = "failed to decode public key"
failedEnCodePublicKey = "failed to encode public key"
failedGenCaKey = "failed to generate the CA key"
help = "Usage of {{.Name}}:\n\t\t\n $ {{.Name}} auto\n use guide\n\n $ {{.Name}} mkcert\n use mkcert, the same as mkcert's usage.\n\n"
moreOptions = "For more options, run \"mkcert -help\"."
scan10 = "failed to encode certificate key"
scan100 = "Unable to obtain file information:"
scan101 = "Unable to move to the specified location:"
scan102 = "Unable to read file content:"
scan103 = "mkcert-rootCA"
scan104 = "invalid PEM data"
scan105 = "no certs found"
scan106 = "failed to open windows root store: %v"
scan107 = "failed to close windows root store: %v"
scan108 = "failed adding cert: %v"
scan109 = "failed enumerating certs: %v"
scan11 = "failed to save certificate and key"
scan110 = "failed duplicating context: %v"
scan111 = "failed deleting certificate: %v"
scan12 = "failed to save certificate"
scan13 = "failed to save certificate key"
scan14 = "failed to generate PKCS#12"
Expand Down Expand Up @@ -92,8 +98,6 @@ scan92 = "decode pem"
scan93 = "open root store"
scan94 = "add cert"
scan95 = "delete cert"
shortUsage = "Usage of mkcert:\n\n\t$ mkcert -install\n\tInstall the local CA in the system trust store.\n\n\t$ mkcert example.org\n\tGenerate \"example.org.pem\" and \"example.org-key.pem\".\n\n\t$ mkcert example.com myapp.dev localhost 127.0.0.1 ::1\n\tGenerate \"example.com+4.pem\" and \"example.com+4-key.pem\".\n\n\t$ mkcert \"*.example.it\"\n\tGenerate \"_wildcard.example.it.pem\" and \"_wildcard.example.it-key.pem\".\n\n\t$ mkcert -uninstall\n\tUninstall the local CA (but do not delete it).\n\n"

[advancedUsage]
description = "this is advancedUsage"
other = "Advanced options:\n\n\t-cert-file FILE, -key-file FILE, -p12-file FILE\n\t\tCustomize the output paths.\n\n\t-client\n\t\tGenerate a certificate for client authentication.\n\n\t-ecdsa\n\t\tGenerate a certificate with an ECDSA key.\n\n\t-pkcs12\n\t\tGenerate a \".p12\" PKCS #12 file, also know as a \".pfx\" file,\n\t\tcontaining certificate and key for legacy applications.\n\n\t-csr CSR\n\t\tGenerate a certificate based on the supplied CSR. Conflicts with\n\t\tall other flags and arguments except -install and -cert-file.\n\n\t-CAROOT\n\t\tPrint the CA certificate and key storage location.\n\n\t$CAROOT (environment variable)\n\t\tSet the CA certificate and key storage location. (This allows\n\t\tmaintaining multiple local CAs in parallel.)\n\n\t$TRUST_STORES (environment variable)\n\t\tA comma-separated list of trust stores to install the local\n\t\troot CA into. Options are: \"system\", \"java\" and \"nss\" (includes\n\t\tFirefox). Autodetected by default.\n\n"
scan97 = "Prompt failed %v\n"
scan98 = "Selection error"
scan99 = "Unable to open file:"
20 changes: 15 additions & 5 deletions client/active.zh.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ failedGenCaKey = "无法生成CA密钥"
help = "{{.Name}}的用法:\n\t\t\n $ {{.Name}} auto\n 使用向导\n\n $ {{.Name}} mkcert\n 使用 mkcert, 跟原版 mkcert 用法一致.\n\n"
moreOptions = "有关更多选项,请运行“mkcert-help”。"
scan10 = "无法对证书密钥进行编码"
scan100 = "无法获取文件信息:"
scan101 = "无法移动到指定位置:"
scan102 = "无法读取文件内容:"
scan103 = "mkcert-rootCA"
scan104 = "无效的PEM数据"
scan105 = "找不到证书"
scan106 = "无法打开windows根存储:%v"
scan107 = "无法关闭windows根存储:%v"
scan108 = "添加证书失败:%v"
scan109 = "枚举证书失败:%v"
scan11 = "无法保存证书和密钥"
scan110 = "复制上下文失败:%v"
scan111 = "删除证书失败: %v"
scan12 = "无法保存证书"
scan13 = "未能保存证书密钥"
scan14 = "未能生成PKCS#12"
Expand Down Expand Up @@ -92,8 +104,6 @@ scan92 = "解码pem"
scan93 = "打开根存储"
scan94 = "增加证书"
scan95 = "删除证书"
shortUsage = "mkcert 的用法:\n\n\t$ mkcert -install\n\t在系统信任存储中安装本地 CA。\n\n\t$ mkcert example.org\n\t生成 \"example.org.pem\"\"example.org-key.pem\"\n\n\t$ mkcert example.com myapp.dev localhost 127.0.0.1 ::1\n\t生成 \"example.com+4.pem\"\"example.com+4-key.pem\"\n\n\t$ mkcert \"*.example.it\"\n\t生成 \"_wildcard.example.it.pem\"\" _wildcard.example.it-key.pem\"\n\n\t$ mkcert -uninstall\n\t卸载本地 CA(但不删除它)。\n\n"

[advancedUsage]
description = "这是高级用法"
other = "高级选项:\n\n\t-cert-file FILE、-key-file FILE、-p12-file FILE\n\t\t自定义输出路径。\n\n\t-client\n\t\t生成 用于客户端身份验证的证书。\n\n\t-ecdsa\n\t\t使用 ECDSA 密钥生成证书。\n\n\t-pkcs12\n\t\t生成 \".p12\" PKCS # 12 文件,也称为“.pfx”文件,\n\t\t包含旧应用程序的证书和密钥。\n\n\t-csr CSR\n\t\t根据提供的 CSR 生成证书 。 与除 -install 和 -cert-file 之外的\n\t\t所有其他标志和参数冲突。\n\n\t-CAROOT\n\t\t打印 CA 证书和密钥存储位置。\n\n\t$ CAROOT(环境变量)\n\t\t设置 CA 证书和密钥存储位置。 (这允许\n\t\t并行维护多个本地 CA。)\n\n\t$TRUST_STORES(环境变量)\n\t\t用于安装本地 CA 的以逗号分隔的信任存储列表\n\t\troot CA 进入。 选项有:\"system\"\"java\"\"nss\"(包括\n\t\tFirefox)。 默认情况下自动检测。\n\n"
scan97 = "提示失败 %v\n"
scan98 = "选择错误"
scan99 = "无法打开文件:"
143 changes: 102 additions & 41 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import (
const rootName = "rootCA.pem"

type mkcert struct {
CAROOT string
caCert *x509.Certificate
CAROOT string
caCert *x509.Certificate

// The system cert pool is only loaded once. After installing the root, checks
// will keep failing until the next execution. TODO: maybe execve?
// https://github.com/golang/go/issues/24540 (thanks, myself)
ignoreCheckFailure bool
ignoreCheckFailure bool
}

func (m *mkcert) checkPlatform() bool {
Expand All @@ -37,75 +37,127 @@ func (m *mkcert) checkPlatform() bool {
func (m *mkcert) install() {
if storeEnabled("system") {
if m.checkPlatform() {
log.Print("The local CA is already installed in the system trust store! 👍")
log.Print(i18nText.
scan48,
)
} else {
if m.installPlatform() {
log.Print("The local CA is now installed in the system trust store! ⚡️")
log.Print(i18nText.
scan62,
)
}
m.ignoreCheckFailure = true // TODO: replace with a check for a successful install
m.ignoreCheckFailure = true // TODO: replace with a check for a successful install
}
}
if storeEnabled("nss") && hasNSS {
if m.checkNSS() {
log.Printf("The local CA is already installed in the %s trust store! 👍", NSSBrowsers)
log.Printf(i18nText.
scan63,

NSSBrowsers)
} else {
if hasCertutil && m.installNSS() {
log.Printf("The local CA is now installed in the %s trust store (requires browser restart)! 🦊", NSSBrowsers)
log.Printf(i18nText.
scan64,

NSSBrowsers)
} else if CertutilInstallHelp == "" {
log.Printf(`Note: %s support is not available on your platform. ℹ️`, NSSBrowsers)
log.Printf(i18nText.
scan65,

NSSBrowsers)
} else if !hasCertutil {
log.Printf(`Warning: "certutil" is not available, so the CA can't be automatically installed in %s! ⚠️`, NSSBrowsers)
log.Printf(`Install "certutil" with "%s" and re-run "mkcert -install" 👈`, CertutilInstallHelp)
log.Printf(i18nText.
scan66,

NSSBrowsers)
log.Printf(i18nText.
scan67,

CertutilInstallHelp)
}
}
}
if storeEnabled("java") && hasJava {
if m.checkJava() {
log.Println("The local CA is already installed in Java's trust store! 👍")
log.Println(i18nText.
scan68,
)
} else {
if hasKeytool {
m.installJava()
log.Println("The local CA is now installed in Java's trust store! ☕️")
log.Println(i18nText.
scan69,
)
} else {
log.Println(`Warning: "keytool" is not available, so the CA can't be automatically installed in Java's trust store! ⚠️`)
log.Println(i18nText.
scan70,
)
}
}
}
log.Print("")
log.Print(i18nText.
scan96,
)
}

func (m *mkcert) uninstall() {
if storeEnabled("nss") && hasNSS {
if hasCertutil {
m.uninstallNSS()
} else if CertutilInstallHelp != "" {
log.Print("")
log.Printf(`Warning: "certutil" is not available, so the CA can't be automatically uninstalled from %s (if it was ever installed)! ⚠️`, NSSBrowsers)
log.Printf(`You can install "certutil" with "%s" and re-run "mkcert -uninstall" 👈`, CertutilInstallHelp)
log.Print("")
log.Print(i18nText.
scan96,
)
log.Printf(i18nText.
scan72,

NSSBrowsers)
log.Printf(i18nText.
scan73,

CertutilInstallHelp)
log.Print(i18nText.
scan96,
)
}
}
if storeEnabled("java") && hasJava {
if hasKeytool {
m.uninstallJava()
} else {
log.Print("")
log.Println(`Warning: "keytool" is not available, so the CA can't be automatically uninstalled from Java's trust store (if it was ever installed)! ⚠️`)
log.Print("")
log.Print(i18nText.
scan96,
)
log.Println(i18nText.
scan74,
)
log.Print(i18nText.
scan96,
)
}
}
if storeEnabled("system") && m.uninstallPlatform() {
log.Print("The local CA is now uninstalled from the system trust store(s)! 👋")
log.Print("")
log.Print(i18nText.
scan75,
)
log.Print(i18nText.
scan96,
)
} else if storeEnabled("nss") && hasCertutil {
log.Printf("The local CA is now uninstalled from the %s trust store(s)! 👋", NSSBrowsers)
log.Print("")
log.Printf(i18nText.
scan76,

NSSBrowsers)
log.Print(i18nText.
scan96,
)
}
}

type item struct {
Name string
Description string
Name string
Description string
}

func (m *mkcert) caUniqueName() string {
Expand All @@ -127,10 +179,10 @@ func main() {
}

templates := &promptui.SelectTemplates{
Label: "{{ . }}?",
Active: "\U0001F336 {{ .Name | cyan }}",
Inactive: " {{ .Name | cyan }}",
Selected: "\U0001F336 {{ .Name | red | cyan }}",
Label: "{{ . }}?",
Active: "\U0001F336 {{ .Name | cyan }}",
Inactive: " {{ .Name | cyan }}",
Selected: "\U0001F336 {{ .Name | red | cyan }}",
Details: `
--------- 详情 ----------
{{ "名字:" | faint }} {{ .Name }}
Expand All @@ -146,27 +198,36 @@ func main() {
}

prompt := promptui.Select{
Label: "当前是授信客户端,你要做什么",
Items: items,
Templates: templates,
Size: 4,
Searcher: searcher,
Label: "当前是授信客户端,你要做什么",
Items: items,
Templates: templates,
Size: 4,
Searcher: searcher,
}

i, _, err := prompt.Run()

if err != nil {
fmt.Printf("Prompt failed %v\n", err)
log.Fatalln("选择错误")
fmt.Printf(i18nText.
scan97,

err)
log.Fatalln(i18nText.
scan98,
)
} else {
m := &mkcert{}
m.CAROOT = "./"
certDERBlock, _ := pem.Decode(cert)
if certDERBlock == nil || certDERBlock.Type != "CERTIFICATE" {
log.Fatalln("ERROR: failed to read the CA certificate: unexpected content")
log.Fatalln(i18nText.
scan33,
)
}
m.caCert, err = x509.ParseCertificate(certDERBlock.Bytes)
fatalIfErr(err, "failed to parse the CA certificate")
fatalIfErr(err, i18nText.
scan34,
)
if i == 0 {
m.install()
} else if i == 1 {
Expand Down
14 changes: 11 additions & 3 deletions client/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ func commandWithSudo(cmd ...string) *exec.Cmd {
}
if !binaryExists("sudo") {
sudoWarningOnce.Do(func() {
log.Println(`Warning: "sudo" is not available, and mkcert is not running as root. The (un)install operation might fail. ⚠️`)
log.Println(i18nText.
scan79,
)
})
return exec.Command(cmd[0], cmd[1:]...)
}
Expand All @@ -26,7 +28,10 @@ func commandWithSudo(cmd ...string) *exec.Cmd {

func fatalIfCmdErr(err error, cmd string, out []byte) {
if err != nil {
log.Fatalf("ERROR: failed to execute \"%s\": %s\n\n%s\n", cmd, err, out)
log.Fatalf(i18nText.
scan78,

cmd, err, out)
}
}

Expand Down Expand Up @@ -55,6 +60,9 @@ func storeEnabled(name string) bool {

func fatalIfErr(err error, msg string) {
if err != nil {
log.Fatalf("ERROR: %s: %s", msg, err)
log.Fatalf(i18nText.
scan77,

msg, err)
}
}
Loading

0 comments on commit b320c65

Please sign in to comment.