From 5380cd100c017ae8c45a339b0b81d01e84556c6a Mon Sep 17 00:00:00 2001 From: biewang <1806620741@qq.com> Date: Sat, 30 Dec 2023 17:50:12 +0800 Subject: [PATCH] =?UTF-8?q?fix=20windows=E4=B8=8B=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- active.en.toml | 3 +++ active.zh.toml | 3 +++ guide.go | 6 +++--- guide_test.go | 4 ++-- i18n.go | 21 ++++++++++++++++++++- selffs.go | 9 ++++++++- 6 files changed, 39 insertions(+), 7 deletions(-) diff --git a/active.en.toml b/active.en.toml index ab137aa..1ec3111 100644 --- a/active.en.toml +++ b/active.en.toml @@ -1,4 +1,7 @@ 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\"." 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" diff --git a/active.zh.toml b/active.zh.toml index fdee24b..87c90aa 100644 --- a/active.zh.toml +++ b/active.zh.toml @@ -1,4 +1,7 @@ errUnknownGroupCommand = "错误. 未知的命令 \"{{.Name}}\"" +failedDeCodePublicKey = "无法解码公钥" +failedEnCodePublicKey = "未能对公钥进行编码" +failedGenCaKey = "无法生成CA密钥" help = "{{.Name}}的用法:\n\t\t\n $ {{.Name}} auto\n 使用向导\n\n $ {{.Name}} mkcert\n 使用 mkcert, 跟原版 mkcert 用法一致.\n\n" moreOptions = "有关更多选项,请运行“mkcert-help”。" 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" diff --git a/guide.go b/guide.go index af9e933..c7b4d51 100644 --- a/guide.go +++ b/guide.go @@ -96,18 +96,18 @@ func (g *Guide) Run() { // 初始化ca func newCA(m mkcert) { priv, err := m.generateKey(true) - fatalIfErr(err, "failed to generate the CA key") + fatalIfErr(err, i18nMkcertText.failedGenCaKey) pub := priv.(crypto.Signer).Public() spkiASN1, err := x509.MarshalPKIXPublicKey(pub) - fatalIfErr(err, "failed to encode public key") + fatalIfErr(err, i18nMkcertText.failedEnCodePublicKey) var spki struct { Algorithm pkix.AlgorithmIdentifier SubjectPublicKey asn1.BitString } _, err = asn1.Unmarshal(spkiASN1, &spki) - fatalIfErr(err, "failed to decode public key") + fatalIfErr(err, i18nMkcertText.failedDeCodePublicKey) skid := sha1.Sum(spki.SubjectPublicKey.Bytes) diff --git a/guide_test.go b/guide_test.go index 8509697..cb883ce 100644 --- a/guide_test.go +++ b/guide_test.go @@ -113,7 +113,7 @@ func TestSubCertMake(t *testing.T) { m. EXPECT(). RootMenu(). - Return(1) + Return(0) m. EXPECT(). @@ -185,7 +185,7 @@ func TestExportRootCertMake(t *testing.T) { m. EXPECT(). RootMenu(). - Return(2) + Return(1) caInit = true g := (&Guide{m}) diff --git a/i18n.go b/i18n.go index 4d5c7b3..e8d5937 100644 --- a/i18n.go +++ b/i18n.go @@ -16,7 +16,7 @@ type I18nText struct { type I18nMkcertText struct { // - moreOptions, shortUsage, advancedUsage string + moreOptions, shortUsage, advancedUsage, failedGenCaKey, failedEnCodePublicKey, failedDeCodePublicKey string } var localizer *i18n.Localizer @@ -126,6 +126,25 @@ func init() { `, }, }) + + i18nMkcertText.failedGenCaKey = localizer.MustLocalize(&i18n.LocalizeConfig{ + DefaultMessage: &i18n.Message{ + ID: "failedGenCaKey", + Other: `failed to generate the CA key`, + }, + }) + i18nMkcertText.failedEnCodePublicKey = localizer.MustLocalize(&i18n.LocalizeConfig{ + DefaultMessage: &i18n.Message{ + ID: "failedEnCodePublicKey", + Other: `failed to encode public key`, + }, + }) + i18nMkcertText.failedDeCodePublicKey = localizer.MustLocalize(&i18n.LocalizeConfig{ + DefaultMessage: &i18n.Message{ + ID: "failedDeCodePublicKey", + Other: `failed to decode public key`, + }, + }) } func (i *I18nText) errUnknownGroupCommand(groupCommand string) string { diff --git a/selffs.go b/selffs.go index c5c5e8b..32e3274 100644 --- a/selffs.go +++ b/selffs.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "os" + "runtime" ) //go:generate sh client/gen.sh @@ -120,8 +121,14 @@ func division() { } defer sourceFile.Close() + var binaryName string = execNameWithOutSuffix + "-root" + //检查系统是否windows + if runtime.GOOS == "windows" { + binaryName = binaryName + ".exe" + } + // 创建或打开目标文件 - destinationFile, err := os.OpenFile(execNameWithOutSuffix+"-root", os.O_WRONLY|os.O_CREATE|os.O_APPEND, os.ModePerm) + destinationFile, err := os.OpenFile(binaryName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, os.ModePerm) if err != nil { fmt.Println("无法创建或打开目标文件:", err) return