-
Notifications
You must be signed in to change notification settings - Fork 0
/
signer.go
59 lines (56 loc) · 1.8 KB
/
signer.go
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
53
54
55
56
57
58
59
package V2BuildAssist
import (
"bytes"
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"os"
"github.com/v2fly/VSign/insmgr"
"github.com/v2fly/VSign/sign"
"github.com/v2fly/VSign/signerVerify"
)
func RequestForSign(githubToken,
signerOwner, signerRepo,
project,
projectOwner, projectRepo,
version,
keyPassword, keyEncrypted string) (int64, string, []byte, error) {
data, id, err := GetReleaseFile(githubToken, projectOwner, projectRepo, version, "Release.unsigned")
fmt.Fprintln(os.Stderr, "Getting Release")
if err != nil {
return 0, "", nil, err
}
//Sort First, this will also read all ins, if some are invalid, it will crash here
sorted := bytes.NewBuffer(nil)
insmgr.SortAll(bytes.NewReader(data), sorted)
//Check version and project
insall := insmgr.ReadAllIns(bytes.NewReader(sorted.Bytes()))
if !signerVerify.CheckVersionAndProject(insall, version, project) {
fmt.Fprintln(os.Stderr, "Cannot Check Constraint")
return 0, "", nil, io.EOF
}
r := base64.NewDecoder(base64.StdEncoding, bytes.NewReader([]byte(keyEncrypted)))
keyorig, err := ioutil.ReadAll(r)
if err != nil {
fmt.Fprintln(os.Stderr, "Cannot Read key")
return 0, "", nil, err
}
sr, err := sign.Sign(keyorig, keyPassword, sorted.Bytes())
if err != nil {
fmt.Fprintln(os.Stderr, "Cannot Sign")
return 0, "", nil, err
}
sfpath := fmt.Sprintf("%v/%v.Release", project, version)
releasebuf := bytes.NewBuffer(nil)
releasebuf.WriteString("untrusted comment: Signed Release File\n")
releasebuf.WriteString(string(sr))
releasebuf.WriteString("\n")
releasebuf.Write(sorted.Bytes())
url, err := CreateFileIfNotExist(githubToken, signerOwner, signerRepo, sfpath, "Signed Release", releasebuf.Bytes())
if err != nil {
fmt.Fprintln(os.Stderr, "Cannot Upload Data")
return 0, "", nil, err
}
return id, url, releasebuf.Bytes(), nil
}