2021-10-22 04:04:06 +00:00
|
|
|
package tls
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2024-03-03 15:52:22 +00:00
|
|
|
"os"
|
2021-10-22 04:04:06 +00:00
|
|
|
|
|
|
|
"github.com/xtls/xray-core/main/commands/base"
|
|
|
|
"github.com/xtls/xray-core/transport/internet/tls"
|
|
|
|
)
|
|
|
|
|
|
|
|
var cmdCertChainHash = &base.Command{
|
|
|
|
UsageLine: "{{.Exec}} certChainHash",
|
|
|
|
Short: "Calculate TLS certificates hash.",
|
|
|
|
Long: `
|
|
|
|
xray tls certChainHash --cert <cert.pem>
|
|
|
|
Calculate TLS certificate chain hash.
|
|
|
|
`,
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmdCertChainHash.Run = executeCertChainHash // break init loop
|
|
|
|
}
|
|
|
|
|
|
|
|
var input = cmdCertChainHash.Flag.String("cert", "fullchain.pem", "The file path of the certificates chain")
|
|
|
|
|
|
|
|
func executeCertChainHash(cmd *base.Command, args []string) {
|
|
|
|
fs := flag.NewFlagSet("certChainHash", flag.ContinueOnError)
|
|
|
|
if err := fs.Parse(args); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
2024-03-03 15:52:22 +00:00
|
|
|
certContent, err := os.ReadFile(*input)
|
2021-10-22 04:04:06 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
certChainHashB64 := tls.CalculatePEMCertChainSHA256Hash(certContent)
|
|
|
|
fmt.Println(certChainHashB64)
|
|
|
|
}
|