verify.go 1.2 KB

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