2020-11-23 10:38:43 -05:00
|
|
|
package all
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/v2fly/VSign/signerVerify"
|
2021-06-04 19:42:53 -04:00
|
|
|
|
2022-01-02 10:16:23 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v5/main/commands/base"
|
2020-11-23 10:38:43 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
var cmdVerify = &base.Command{
|
|
|
|
UsageLine: "{{.Exec}} verify [--sig=sig-file] file",
|
2021-02-21 10:02:42 -05:00
|
|
|
Short: "verify if a binary is officially signed",
|
2020-11-23 10:38:43 -05:00
|
|
|
Long: `
|
|
|
|
Verify if a binary is officially signed.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
2021-02-21 10:02:42 -05:00
|
|
|
-sig <signature_file>
|
2020-11-23 10:38:43 -05:00
|
|
|
The path to the signature file
|
|
|
|
`,
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmdVerify.Run = executeVerify // break init loop
|
|
|
|
}
|
|
|
|
|
2021-11-27 01:32:07 -05:00
|
|
|
var verifySigFile = cmdVerify.Flag.String("sig", "", "Path to the signature file")
|
2020-11-23 10:38:43 -05:00
|
|
|
|
|
|
|
func executeVerify(cmd *base.Command, args []string) {
|
|
|
|
target := cmdVerify.Flag.Arg(0)
|
|
|
|
if target == "" {
|
|
|
|
base.Fatalf("empty file path.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if *verifySigFile == "" {
|
|
|
|
base.Fatalf("empty signature path.")
|
|
|
|
}
|
|
|
|
|
|
|
|
sigReader, err := os.Open(os.ExpandEnv(*verifySigFile))
|
|
|
|
if err != nil {
|
|
|
|
base.Fatalf("failed to open file %s: %s ", *verifySigFile, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
files := cmdVerify.Flag.Args()
|
|
|
|
|
|
|
|
err = signerVerify.OutputAndJudge(signerVerify.CheckSignaturesV2Fly(sigReader, files))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
base.Fatalf("file is not officially signed by V2Ray: %s", err)
|
|
|
|
}
|
|
|
|
}
|