Skip to content

Commit bee2da6

Browse files
committed
Added IsTrusted flag in PlatformReleases
This is required for post_install script processing.
1 parent 9613fea commit bee2da6

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

arduino/cores/cores.go

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type PlatformRelease struct {
4848
Menus *properties.Map `json:"-"`
4949
InstallDir *paths.Path `json:"-"`
5050
IsIDEBundled bool `json:"-"`
51+
IsTrusted bool `json:"-"`
5152
}
5253

5354
// BoardManifest contains information about a board. These metadata are usually

arduino/cores/packageindex/index.go

+23-5
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ import (
2121

2222
"github.com/arduino/arduino-cli/arduino/cores"
2323
"github.com/arduino/arduino-cli/arduino/resources"
24+
"github.com/arduino/arduino-cli/arduino/security"
2425
"github.com/arduino/go-paths-helper"
26+
"github.com/sirupsen/logrus"
2527
semver "go.bug.st/relaxed-semver"
2628
)
2729

2830
// Index represents Cores and Tools struct as seen from package_index.json file.
2931
type Index struct {
30-
Packages []*indexPackage `json:"packages"`
32+
Packages []*indexPackage `json:"packages"`
33+
IsTrusted bool
3134
}
3235

3336
// indexPackage represents a single entry from package_index.json file.
@@ -98,11 +101,11 @@ type indexHelp struct {
98101
// with the existing contents of the cores.Packages passed as parameter.
99102
func (index Index) MergeIntoPackages(outPackages cores.Packages) {
100103
for _, inPackage := range index.Packages {
101-
inPackage.extractPackageIn(outPackages)
104+
inPackage.extractPackageIn(outPackages, index.IsTrusted)
102105
}
103106
}
104107

105-
func (inPackage indexPackage) extractPackageIn(outPackages cores.Packages) {
108+
func (inPackage indexPackage) extractPackageIn(outPackages cores.Packages, trusted bool) {
106109
outPackage := outPackages.GetOrCreatePackage(inPackage.Name)
107110
outPackage.Maintainer = inPackage.Maintainer
108111
outPackage.WebsiteURL = inPackage.WebsiteURL
@@ -115,11 +118,11 @@ func (inPackage indexPackage) extractPackageIn(outPackages cores.Packages) {
115118
}
116119

117120
for _, inPlatform := range inPackage.Platforms {
118-
inPlatform.extractPlatformIn(outPackage)
121+
inPlatform.extractPlatformIn(outPackage, trusted)
119122
}
120123
}
121124

122-
func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *cores.Package) error {
125+
func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *cores.Package, trusted bool) error {
123126
outPlatform := outPackage.GetOrCreatePlatform(inPlatformRelease.Architecture)
124127
// FIXME: shall we use the Name and Category of the latest release? or maybe move Name and Category in PlatformRelease?
125128
outPlatform.Name = inPlatformRelease.Name
@@ -133,6 +136,7 @@ func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *core
133136
if err != nil {
134137
return fmt.Errorf("creating release: %s", err)
135138
}
139+
outPlatformRelease.IsTrusted = trusted
136140
outPlatformRelease.Resource = &resources.DownloadResource{
137141
ArchiveFileName: inPlatformRelease.ArchiveFileName,
138142
Checksum: inPlatformRelease.Checksum,
@@ -213,5 +217,19 @@ func LoadIndex(jsonIndexFile *paths.Path) (*Index, error) {
213217
return nil, err
214218
}
215219

220+
jsonSignatureFile := jsonIndexFile.Parent().Join(jsonIndexFile.Base() + ".sig")
221+
trusted, _, err := security.VerifyArduinoDetachedSignature(jsonIndexFile, jsonSignatureFile)
222+
if err != nil {
223+
logrus.
224+
WithField("index", jsonIndexFile).
225+
WithField("signatureFile", jsonSignatureFile).
226+
WithError(err).Infof("Checking signature")
227+
} else {
228+
logrus.
229+
WithField("index", jsonIndexFile).
230+
WithField("signatureFile", jsonSignatureFile).
231+
WithField("trusted", trusted).Infof("Checking signature")
232+
index.IsTrusted = trusted
233+
}
216234
return &index, nil
217235
}

arduino/security/signatures.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ import (
2323
"golang.org/x/crypto/openpgp"
2424
)
2525

26-
// VerifyArduinoDetachedSignature that give signaturePath GPG signature match the given targetPath file
27-
// ant the is an authentic signature from Arduino.
26+
// VerifyArduinoDetachedSignature checks that the detached GPG signature (in the
27+
// signaturePath file) matches the given targetPath file and is an authentic
28+
// signature from the bundled trusted keychain. If any of the above conditions
29+
// fails this function returns false. The PGP entity in the trusted keychain that
30+
// produced the signature is returned too.
2831
func VerifyArduinoDetachedSignature(targetPath *paths.Path, signaturePath *paths.Path) (bool, *openpgp.Entity, error) {
2932
keysBox, err := rice.FindBox("keys")
3033
if err != nil {

0 commit comments

Comments
 (0)