Skip to content

Commit b069ab9

Browse files
Robert EmeryRobert Emery
authored andcommitted
So it looks like GPG/PGP is basically hated within golang etc:
golang/go#29082 (comment) however it looks like https://jedisct1.github.io/minisign/ and http s://github.com/jedisct1/go-minisign work
1 parent dfeb623 commit b069ab9

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

configuration.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ LogFilePath=output.log
99
LogLevel=INFO
1010
LoadPprof=false
1111
SignedScriptsOnly=true
12-
PublicKeyRingFile=keyfile.gpg
12+
PublicKeyFile=keyfile.pub

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.16
44

55
require (
66
github.com/gorilla/mux v1.8.0
7+
github.com/jedisct1/go-minisign v0.0.0-20210106175330-e54e81d562c7 // indirect
78
github.com/kardianos/service v1.2.0
89
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
910
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec

go.sum

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
22
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
3+
github.com/jedisct1/go-minisign v0.0.0-20210106175330-e54e81d562c7 h1:qrPDNqqT76vs8oWL6Z1/D6hKvbXULvlD7FdNVTIUI8A=
4+
github.com/jedisct1/go-minisign v0.0.0-20210106175330-e54e81d562c7/go.mod h1:oPTyITpvr7hPx/9w76gWrgbZwbb+7gZ9/On8hFc+LNE=
35
github.com/kardianos/service v1.2.0 h1:bGuZ/epo3vrt8IPC7mnKQolqFeYJb7Cs8Rk4PSOBB/g=
46
github.com/kardianos/service v1.2.0/go.mod h1:CIMRFEJVL+0DS1a3Nx06NaMn4Dz63Ng6O7dl0qH0zVM=
57
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 h1:lDH9UUVJtmYCjyT0CI4q8xvlXPxeZ0gYCVvWbmPlp88=
68
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
79
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec h1:DGmKwyZwEB8dI7tbLt/I/gQuP559o/0FrAkHKlQM/Ks=
810
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec/go.mod h1:owBmyHYMLkxyrugmfwE/DLJyW8Ro9mkphwuVErQ0iUw=
11+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
12+
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
913
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
1014
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
15+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
1116
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
17+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
18+
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1219
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 h1:9UQO31fZ+0aKQOFldThf7BKPMJTiBfWycGh/u3UoO88=
1320
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1421
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
1522
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
23+
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
1624
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
25+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
1726
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
1827
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

internal/configuration/configuration.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package configuration
22

33
import (
4-
"os"
54
"path/filepath"
65
"strconv"
76
"time"
87

9-
"golang.org/x/crypto/openpgp"
10-
8+
"github.com/jedisct1/go-minisign"
119
ini "github.com/vaughan0/go-ini"
1210
)
1311

@@ -24,7 +22,7 @@ type SettingsValues struct {
2422
RequestTimeout time.Duration
2523
LoadPprof bool
2624
SignedScriptsOnly bool
27-
PublicKeyRing openpgp.EntityList
25+
PublicKey minisign.PublicKey
2826
}
2927

3028
// Settings is the loaded/updated settings from the configuration file
@@ -65,10 +63,14 @@ func Initialise(configurationDirectory string) {
6563
Settings.LoadPprof = getIniBoolOrPanic(iniFile, "Server", "LoadPprof")
6664
Settings.SignedScriptsOnly = getIniBoolOrPanic(iniFile, "Server", "SignedScriptsOnly")
6765

68-
keyringFileBuffer, _ := os.Open(getIniValueOrPanic(iniFile, "Server", "PublicKeyRingFile"))
69-
defer keyringFileBuffer.Close()
70-
entityList, _ := openpgp.ReadArmoredKeyRing(keyringFileBuffer)
71-
Settings.PublicKeyRing = entityList
66+
keyringFileBuffer := getIniValueOrPanic(iniFile, "Server", "PublicKeyFile")
67+
68+
publicKey, publicKeyError := minisign.NewPublicKeyFromFile(keyringFileBuffer)
69+
70+
if publicKeyError != nil {
71+
panic(publicKeyError)
72+
}
73+
Settings.PublicKey = publicKey
7274
}
7375

7476
func getIniValueOrPanic(input ini.File, group string, key string) string {

internal/web/helpers.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"sync"
1212
"time"
1313

14-
"golang.org/x/crypto/openpgp"
14+
"github.com/jedisct1/go-minisign"
1515
)
1616

1717
// Script represents an object submitted to the runscript endpoint
@@ -125,13 +125,18 @@ func runScript(responseWriter http.ResponseWriter, scriptToRun Script) []byte {
125125

126126
func verifySignature(stdin string, signature string) bool {
127127

128-
stdInReader := strings.NewReader(stdin)
129-
signatureReader := strings.NewReader(signature)
128+
stdinAsArray := []byte(stdin)
129+
signatureStruct, signatureError := minisign.DecodeSignature(signature)
130130

131-
signer, error := openpgp.CheckDetachedSignature(configuration.Settings.PublicKeyRing, stdInReader, signatureReader)
132-
if signer != nil && error != nil {
133-
return true
131+
if signatureError != nil {
132+
logwrapper.Log.Debugf("Signature Decoding error: %v", signatureError)
134133
}
135-
logwrapper.Log.Debugf("Signature Verification Error: %v", error)
136-
return false
134+
135+
isValid, error := configuration.Settings.PublicKey.Verify(stdinAsArray, signatureStruct)
136+
137+
if error != nil {
138+
logwrapper.Log.Debugf("Signature Verification: %b parsedSignature: %v Error: %v", isValid, signatureStruct, error)
139+
}
140+
141+
return isValid
137142
}

0 commit comments

Comments
 (0)