Skip to content

Commit

Permalink
Add back tls certChainHash command
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaokangwang committed Sep 8, 2024
1 parent 5ad675f commit 366a6ca
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions main/commands/all/tls/chainhash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package tls

import (
"fmt"
"os"

"github.com/v2fly/v2ray-core/v5/main/commands/base"
v2tls "github.com/v2fly/v2ray-core/v5/transport/internet/tls"
)

var cmdChainHash = &base.Command{
UsageLine: "{{.Exec}} tls certChainHash [--cert <cert.pem>]",
Short: "Generate certificate chain hash for given certificate bundle",
}

func init() {
cmdChainHash.Run = executeChainHash // break init loop
}

var certFile = cmdChainHash.Flag.String("cert", "cert.pem", "")

func executeChainHash(cmd *base.Command, args []string) {
if len(*certFile) == 0 {
base.Fatalf("cert file not specified")
}
certContent, err := os.ReadFile(*certFile)
if err != nil {
base.Fatalf("Failed to read cert file: %s", err)
return
}

certChainHashB64 := v2tls.CalculatePEMCertChainSHA256Hash(certContent)
fmt.Println(certChainHashB64)
}
1 change: 1 addition & 0 deletions main/commands/all/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ var CmdTLS = &base.Command{
Commands: []*base.Command{
cmdCert,
cmdPing,
cmdChainHash,
},
}

0 comments on commit 366a6ca

Please sign in to comment.