1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00
v2fly/infra/control/verify.go
Xiaokang Wang fb0aadeea9
Transfer VSign and related project to V2Fly and share under the same license as v2ray-core (#392)
* Move VSign to V2Fly

* Use transfered V2BuildAssist  project
2020-11-08 03:11:45 +08:00

64 lines
1.2 KiB
Go

package control
import (
"flag"
"os"
"github.com/v2fly/VSign/signerVerify"
"v2ray.com/core/common"
)
type VerifyCommand struct{}
func (c *VerifyCommand) Name() string {
return "verify"
}
func (c *VerifyCommand) Description() Description {
return Description{
Short: "Verify if a binary is officially signed.",
Usage: []string{
"v2ctl verify --sig=<sig-file> file...",
"Verify the file officially signed by V2Ray.",
},
}
}
func (c *VerifyCommand) Execute(args []string) error {
fs := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
sigFile := fs.String("sig", "", "Path to the signature file")
if err := fs.Parse(args); err != nil {
return err
}
target := fs.Arg(0)
if target == "" {
return newError("empty file path.")
}
if *sigFile == "" {
return newError("empty signature path.")
}
sigReader, err := os.Open(os.ExpandEnv(*sigFile))
if err != nil {
return newError("failed to open file ", *sigFile).Base(err)
}
files := fs.Args()
err = signerVerify.OutputAndJudge(signerVerify.CheckSignaturesV2Fly(sigReader, files))
if err == nil {
return nil
}
return newError("file is not officially signed by V2Ray").Base(err)
}
func init() {
common.Must(RegisterCommand(&VerifyCommand{}))
}