certchainhash.go 1.1 KB

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