github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/infra/control/verify.go (about)

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