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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
package pgpverify
import (
"os"
"strings"
"golang.org/x/crypto/openpgp"
)
// PgpVerifier - exported struct used for file verification
type PgpVerifier struct {
//Signature string
//Target string
//PublicKey string
Logger Logger
}
// Logger - logging interface
type Logger interface {
Log(msg string)
}
// Verify checks if a file was signed with the correct pgp key
// using a PEM formatted signature and a corresponding public key
func (pgpv *PgpVerifier) Verify(signature string, publicKey string, targetPath string) bool {
keyRingReader := strings.NewReader(publicKey)
signatureReader := strings.NewReader(signature)
verificationTarget, err := os.Open(targetPath)
if err != nil {
pgpv.Logger.Log("Open verification target: " + err.Error())
return false
}
keyring, err := openpgp.ReadArmoredKeyRing(keyRingReader)
if err != nil {
pgpv.Logger.Log("Read Armored Key Ring: " + err.Error())
return false
}
_, err = openpgp.CheckArmoredDetachedSignature(keyring, verificationTarget, signatureReader)
if err != nil {
pgpv.Logger.Log("Verification failed: " + err.Error())
return false
}
pgpv.Logger.Log("Successfully verified: entity.Identities")
return true
}
/*func main() {
keyRingReader, err := os.Open("public_leap.asc")
if err != nil {
fmt.Println(err)
return
}
signature, err := os.Open("RiseupVPN_release_1.0.5.apk.sig")
if err != nil {
fmt.Println(err)
return
}
verificationTarget, err := os.Open("RiseupVPN_release_1.0.5.apk")
if err != nil {
fmt.Println(err)
return
}
keyring, err := openpgp.ReadArmoredKeyRing(keyRingReader)
if err != nil {
fmt.Println("Read Armored Key Ring: " + err.Error())
return
}
entity, err := openpgp.CheckArmoredDetachedSignature(keyring, verificationTarget, signature)
if err != nil {
fmt.Println("Check Detached Signature: " + err.Error())
return
} else {
fmt.Println("successfully verified")
}
fmt.Println(entity.Identities)
}*/
|