github.com/v2fly/v2ray-core/v4@v4.45.2/infra/control/verify.go (about)

     1  package control
     2  
     3  import (
     4  	"flag"
     5  	"os"
     6  
     7  	"github.com/v2fly/VSign/signerVerify"
     8  
     9  	"github.com/v2fly/v2ray-core/v4/common"
    10  )
    11  
    12  type VerifyCommand struct{}
    13  
    14  func (c *VerifyCommand) Name() string {
    15  	return "verify"
    16  }
    17  
    18  func (c *VerifyCommand) Description() Description {
    19  	return Description{
    20  		Short: "Verify if a binary is officially signed.",
    21  		Usage: []string{
    22  			"v2ctl verify --sig=<sig-file> file...",
    23  			"Verify the file officially signed by V2Ray.",
    24  		},
    25  	}
    26  }
    27  
    28  func (c *VerifyCommand) Execute(args []string) error {
    29  	fs := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
    30  
    31  	sigFile := fs.String("sig", "", "Path to the signature file")
    32  
    33  	if err := fs.Parse(args); err != nil {
    34  		return err
    35  	}
    36  
    37  	target := fs.Arg(0)
    38  	if target == "" {
    39  		return newError("empty file path.")
    40  	}
    41  
    42  	if *sigFile == "" {
    43  		return newError("empty signature path.")
    44  	}
    45  
    46  	sigReader, err := os.Open(os.ExpandEnv(*sigFile))
    47  	if err != nil {
    48  		return newError("failed to open file ", *sigFile).Base(err)
    49  	}
    50  
    51  	files := fs.Args()
    52  
    53  	err = signerVerify.OutputAndJudge(signerVerify.CheckSignaturesV2Fly(sigReader, files))
    54  
    55  	if err == nil {
    56  		return nil
    57  	}
    58  
    59  	return newError("file is not officially signed by V2Ray").Base(err)
    60  }
    61  
    62  func init() {
    63  	common.Must(RegisterCommand(&VerifyCommand{}))
    64  }