1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-18 02:16:10 -05:00
v2fly/infra/control/verify.go

65 lines
1.2 KiB
Go
Raw Normal View History

2019-02-10 13:04:11 -05:00
package control
import (
"flag"
"os"
"github.com/v2fly/VSign/signerVerify"
2021-02-16 15:31:50 -05:00
"github.com/v2fly/v2ray-core/v4/common"
2019-02-10 13:04:11 -05:00
)
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{}))
}