1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-17 18:06:15 -05:00
v2fly/infra/control/certchainhash.go
2021-04-17 10:50:53 +01:00

47 lines
1.1 KiB
Go

package control
import (
"flag"
"fmt"
"io/ioutil"
v2tls "github.com/v2fly/v2ray-core/v4/transport/internet/tls"
)
type CertificateChainHashCommand struct {
}
func (c CertificateChainHashCommand) Name() string {
return "certChainHash"
}
func (c CertificateChainHashCommand) Description() Description {
return Description{
Short: "Calculate TLS certificates hash.",
Usage: []string{
"v2ctl certChainHash --cert <cert.pem>",
"Calculate TLS certificate chain hash.",
},
}
}
func (c CertificateChainHashCommand) Execute(args []string) error {
fs := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
cert := fs.String("cert", "fullchain.pem", "The file path of the certificates chain")
if err := fs.Parse(args); err != nil {
return err
}
certContent, err := ioutil.ReadFile(*cert)
if err != nil {
return err
}
certChainHashB64 := v2tls.CalculatePEMCertChainSHA256Hash(certContent)
fmt.Println(certChainHashB64)
return nil
}
func init() {
// Do not release tool before v5's refactor
// common.Must(RegisterCommand(&CertificateChainHashCommand{}))
}