2021-04-15 14:01:55 -04:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2021-04-15 14:02:57 -04:00
|
|
|
"io/ioutil"
|
|
|
|
|
2021-04-15 14:01:55 -04:00
|
|
|
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)
|
2021-04-15 14:01:55 -04:00
|
|
|
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{}))
|
2021-04-15 14:01:55 -04:00
|
|
|
}
|