Skip to content

Commit

Permalink
fix windows下程序名
Browse files Browse the repository at this point in the history
  • Loading branch information
LY1806620741 committed Dec 30, 2023
1 parent 66c822a commit 5380cd1
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 7 deletions.
3 changes: 3 additions & 0 deletions active.en.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 3 additions & 0 deletions active.zh.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 3 additions & 3 deletions guide.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions guide_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestSubCertMake(t *testing.T) {
m.
EXPECT().
RootMenu().
Return(1)
Return(0)

m.
EXPECT().
Expand Down Expand Up @@ -185,7 +185,7 @@ func TestExportRootCertMake(t *testing.T) {
m.
EXPECT().
RootMenu().
Return(2)
Return(1)

caInit = true
g := (&Guide{m})
Expand Down
21 changes: 20 additions & 1 deletion i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion selffs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"
"os"
"runtime"
)

//go:generate sh client/gen.sh
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5380cd1

Please sign in to comment.