verify.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package control
  2. import (
  3. "flag"
  4. "github.com/xiaokangwang/VSign/signerVerify"
  5. "os"
  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. }