github.com/xmplusdev/xray-core@v1.8.10/main/commands/all/tls/certchainhash.go (about)

     1  package tls
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"os"
     7  
     8  	"github.com/xmplusdev/xray-core/main/commands/base"
     9  	"github.com/xmplusdev/xray-core/transport/internet/tls"
    10  )
    11  
    12  var cmdCertChainHash = &base.Command{
    13  	UsageLine: "{{.Exec}} certChainHash",
    14  	Short:     "Calculate TLS certificates hash.",
    15  	Long: `
    16  	xray tls certChainHash --cert <cert.pem>
    17  	Calculate TLS certificate chain hash.
    18  	`,
    19  }
    20  
    21  func init() {
    22  	cmdCertChainHash.Run = executeCertChainHash // break init loop
    23  }
    24  
    25  var input = cmdCertChainHash.Flag.String("cert", "fullchain.pem", "The file path of the certificates chain")
    26  
    27  func executeCertChainHash(cmd *base.Command, args []string) {
    28  	fs := flag.NewFlagSet("certChainHash", flag.ContinueOnError)
    29  	if err := fs.Parse(args); err != nil {
    30  		fmt.Println(err)
    31  		return
    32  	}
    33  	certContent, err := os.ReadFile(*input)
    34  	if err != nil {
    35  		fmt.Println(err)
    36  		return
    37  	}
    38  	certChainHashB64 := tls.CalculatePEMCertChainSHA256Hash(certContent)
    39  	fmt.Println(certChainHashB64)
    40  }