Hunter0x7c7
2022-08-11 b8230139fb40edea387617b6accd8371e37eda58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package all
 
import (
    "os"
 
    "github.com/v2fly/VSign/signerVerify"
 
    "github.com/v2fly/v2ray-core/v5/main/commands/base"
)
 
var cmdVerify = &base.Command{
    UsageLine: "{{.Exec}} verify [--sig=sig-file] file",
    Short:     "verify if a binary is officially signed",
    Long: `
Verify if a binary is officially signed.
 
Arguments:
 
    -sig <signature_file>
        The path to the signature file
`,
}
 
func init() {
    cmdVerify.Run = executeVerify // break init loop
}
 
var verifySigFile = cmdVerify.Flag.String("sig", "", "Path to the signature file")
 
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)
    }
}