certchainhash.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package all
  2. import (
  3. "flag"
  4. "fmt"
  5. "io/ioutil"
  6. "github.com/v2fly/v2ray-core/v4/commands/base"
  7. v2tls "github.com/v2fly/v2ray-core/v4/transport/internet/tls"
  8. )
  9. type CertificateChainHashCommand struct{}
  10. func (c CertificateChainHashCommand) Name() string {
  11. return "certChainHash"
  12. }
  13. func (c CertificateChainHashCommand) Description() base.Command {
  14. return base.Command{
  15. Short: "Calculate TLS certificates hash.",
  16. UsageLine: "v2ctl certChainHash --cert <cert.pem Calculate TLS certificate chain hash.",
  17. }
  18. }
  19. func (c CertificateChainHashCommand) Execute(args []string) error {
  20. fs := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  21. cert := fs.String("cert", "fullchain.pem", "The file path of the certificates chain")
  22. if err := fs.Parse(args); err != nil {
  23. return err
  24. }
  25. certContent, err := ioutil.ReadFile(*cert)
  26. if err != nil {
  27. return err
  28. }
  29. certChainHashB64 := v2tls.CalculatePEMCertChainSHA256Hash(certContent)
  30. fmt.Println(certChainHashB64)
  31. return nil
  32. }
  33. func init() {
  34. // Do not release tool before v5's refactor
  35. // common.Must(RegisterCommand(&CertificateChainHashCommand{}))
  36. }