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