2019-02-10 13:04:11 -05:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"os"
|
2020-10-11 07:22:46 -04:00
|
|
|
|
2020-11-07 14:11:45 -05:00
|
|
|
"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)
|
2019-06-14 09:47:28 -04:00
|
|
|
if target == "" {
|
2019-02-10 13:04:11 -05:00
|
|
|
return newError("empty file path.")
|
|
|
|
}
|
|
|
|
|
2019-06-14 09:47:28 -04:00
|
|
|
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{}))
|
|
|
|
}
|