1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00
v2fly/infra/control/certchainhash.go

47 lines
1.1 KiB
Go
Raw Normal View History

package control
import (
"flag"
"fmt"
2021-04-15 14:02:57 -04:00
"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
}
2021-04-15 15:02:48 -04:00
certChainHashB64 := v2tls.CalculatePEMCertChainSHA256Hash(certContent)
fmt.Println(certChainHashB64)
return nil
}
func init() {
2021-04-17 05:50:53 -04:00
// Do not release tool before v5's refactor
// common.Must(RegisterCommand(&CertificateChainHashCommand{}))
}