Skip to content

Commit 5d87fe6

Browse files
committed
(choria-io#2029) ensure signatures are correctly verified in plugins manager
Signed-off-by: R.I.Pienaar <rip@devco.net>
1 parent e637de9 commit 5d87fe6

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

aagent/watchers/pluginswatcher/plugins.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func (w *Watcher) watch(ctx context.Context) (state State, err error) {
248248
}
249249
}
250250

251-
w.Warnf("Deploying plugin %s from %s info %s", m.Name, m.Source, targetDir)
251+
w.Warnf("Deploying plugin %s from %s into %s", m.Name, m.Source, targetDir)
252252

253253
err = os.MkdirAll(targetDir, 0700)
254254
if err != nil {

aagent/watchers/pluginswatcher/plugins_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"time"
1616

1717
"github.com/choria-io/go-choria/aagent/model"
18+
iu "github.com/choria-io/go-choria/internal/util"
1819
"github.com/ghodss/yaml"
1920
"github.com/golang/mock/gomock"
2021
. "github.com/onsi/ginkgo/v2"
@@ -56,6 +57,27 @@ var _ = Describe("AAgent/Watchers/PluginsWatcher", func() {
5657
os.RemoveAll(td)
5758
})
5859

60+
Describe("Specification/Encode", func() {
61+
It("Should correctly encode the specification", func() {
62+
pub, priv, err := iu.Ed25519KeyPair()
63+
Expect(err).ToNot(HaveOccurred())
64+
65+
data, err := os.ReadFile("testdata/plugins.json")
66+
Expect(err).ToNot(HaveOccurred())
67+
68+
spec := &Specification{Plugins: data}
69+
_, err = spec.Encode(hex.EncodeToString(priv))
70+
Expect(err).ToNot(HaveOccurred())
71+
72+
sig, err := hex.DecodeString(spec.Signature)
73+
Expect(err).ToNot(HaveOccurred())
74+
75+
ok, err := iu.Ed25519Verify(pub, data, sig)
76+
Expect(err).ToNot(HaveOccurred())
77+
Expect(ok).To(BeTrue())
78+
})
79+
})
80+
5981
Describe("setProperties", func() {
6082
It("Should support defaulting manager machine prefix", func() {
6183
err = w.setProperties(map[string]any{})

aagent/watchers/pluginswatcher/specification.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,17 @@ func (s *Specification) Encode(key string) ([]byte, error) {
2323
var pk ed25519.PrivateKey
2424
var err error
2525

26-
data, err := json.Marshal(s)
27-
if err != nil {
28-
return nil, err
29-
}
30-
3126
if key != "" {
32-
if iu.IsEncodedEd25519KeyString(key) {
33-
pk, err = hex.DecodeString(key)
34-
} else {
27+
if iu.FileExist(key) {
3528
_, pk, err = iu.Ed25519KeyPairFromSeedFile(key)
29+
} else {
30+
pk, err = hex.DecodeString(key)
3631
}
3732
if err != nil {
3833
return nil, err
3934
}
4035

41-
sig, err := iu.Ed25519Sign(pk, data)
36+
sig, err := iu.Ed25519Sign(pk, s.Plugins)
4237
if err != nil {
4338
return nil, err
4439
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"name": "requests",
4+
"source": "http://plugins.choria.local/requests-agent_0.0.1_linux_amd64.tar.gz",
5+
"verify": "SHA256SUMS",
6+
"verify_checksum": "d3ebf8e4ae71245c051b9cb50f3712befbbc2c38c2cdf6e8e374eb7e613b1d11",
7+
"checksum": "5e73881403990220ad5e63a971fb3b8fd8299087439843d38d856d3be053fdc0"
8+
}
9+
]

0 commit comments

Comments
 (0)