1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00
v2fly/infra/control/verify.go

63 lines
1.2 KiB
Go
Raw Normal View History

2019-02-10 13:04:11 -05:00
package control
import (
"flag"
2020-07-04 08:28:15 -04:00
"github.com/xiaokangwang/VSign/signerVerify"
2019-02-10 13:04:11 -05:00
"os"
"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{
2020-07-04 08:28:15 -04:00
"v2ctl verify --sig=<sig-file> file...",
2019-02-10 13:04:11 -05:00
"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 == "" {
2019-02-10 13:04:11 -05:00
return newError("empty file path.")
}
if *sigFile == "" {
2020-07-04 08:28:15 -04:00
return newError("empty signature path.")
2019-02-10 13:04:11 -05:00
}
sigReader, err := os.Open(os.ExpandEnv(*sigFile))
if err != nil {
return newError("failed to open file ", *sigFile).Base(err)
}
2020-07-04 08:28:15 -04:00
files := fs.Args()
2019-02-10 13:04:11 -05:00
2020-07-04 08:28:15 -04:00
err = signerVerify.OutputAndJudge(signerVerify.CheckSignaturesV2Fly(sigReader, files))
2019-02-28 14:37:54 -05:00
2020-07-04 08:28:15 -04:00
if err == nil {
2019-02-28 14:37:54 -05:00
return nil
2019-02-10 13:04:11 -05:00
}
2020-07-04 08:28:15 -04:00
return newError("file is not officially signed by V2Ray").Base(err)
2019-02-10 13:04:11 -05:00
}
func init() {
common.Must(RegisterCommand(&VerifyCommand{}))
}