chainhash.go 827 B

12345678910111213141516171819202122232425262728293031323334
  1. package tls
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/v2fly/v2ray-core/v5/main/commands/base"
  6. v2tls "github.com/v2fly/v2ray-core/v5/transport/internet/tls"
  7. )
  8. var cmdChainHash = &base.Command{
  9. UsageLine: "{{.Exec}} tls certChainHash [--cert <cert.pem>]",
  10. Short: "Generate certificate chain hash for given certificate bundle",
  11. }
  12. func init() {
  13. cmdChainHash.Run = executeChainHash // break init loop
  14. }
  15. var certFile = cmdChainHash.Flag.String("cert", "cert.pem", "")
  16. func executeChainHash(cmd *base.Command, args []string) {
  17. if len(*certFile) == 0 {
  18. base.Fatalf("cert file not specified")
  19. }
  20. certContent, err := os.ReadFile(*certFile)
  21. if err != nil {
  22. base.Fatalf("Failed to read cert file: %s", err)
  23. return
  24. }
  25. certChainHashB64 := v2tls.CalculatePEMCertChainSHA256Hash(certContent)
  26. fmt.Println(certChainHashB64)
  27. }