@@ -21,13 +21,16 @@ import (
21
21
22
22
"github.com/arduino/arduino-cli/arduino/cores"
23
23
"github.com/arduino/arduino-cli/arduino/resources"
24
+ "github.com/arduino/arduino-cli/arduino/security"
24
25
"github.com/arduino/go-paths-helper"
26
+ "github.com/sirupsen/logrus"
25
27
semver "go.bug.st/relaxed-semver"
26
28
)
27
29
28
30
// Index represents Cores and Tools struct as seen from package_index.json file.
29
31
type Index struct {
30
- Packages []* indexPackage `json:"packages"`
32
+ Packages []* indexPackage `json:"packages"`
33
+ IsTrusted bool
31
34
}
32
35
33
36
// indexPackage represents a single entry from package_index.json file.
@@ -98,11 +101,11 @@ type indexHelp struct {
98
101
// with the existing contents of the cores.Packages passed as parameter.
99
102
func (index Index ) MergeIntoPackages (outPackages cores.Packages ) {
100
103
for _ , inPackage := range index .Packages {
101
- inPackage .extractPackageIn (outPackages )
104
+ inPackage .extractPackageIn (outPackages , index . IsTrusted )
102
105
}
103
106
}
104
107
105
- func (inPackage indexPackage ) extractPackageIn (outPackages cores.Packages ) {
108
+ func (inPackage indexPackage ) extractPackageIn (outPackages cores.Packages , trusted bool ) {
106
109
outPackage := outPackages .GetOrCreatePackage (inPackage .Name )
107
110
outPackage .Maintainer = inPackage .Maintainer
108
111
outPackage .WebsiteURL = inPackage .WebsiteURL
@@ -115,11 +118,11 @@ func (inPackage indexPackage) extractPackageIn(outPackages cores.Packages) {
115
118
}
116
119
117
120
for _ , inPlatform := range inPackage .Platforms {
118
- inPlatform .extractPlatformIn (outPackage )
121
+ inPlatform .extractPlatformIn (outPackage , trusted )
119
122
}
120
123
}
121
124
122
- func (inPlatformRelease indexPlatformRelease ) extractPlatformIn (outPackage * cores.Package ) error {
125
+ func (inPlatformRelease indexPlatformRelease ) extractPlatformIn (outPackage * cores.Package , trusted bool ) error {
123
126
outPlatform := outPackage .GetOrCreatePlatform (inPlatformRelease .Architecture )
124
127
// FIXME: shall we use the Name and Category of the latest release? or maybe move Name and Category in PlatformRelease?
125
128
outPlatform .Name = inPlatformRelease .Name
@@ -133,6 +136,7 @@ func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *core
133
136
if err != nil {
134
137
return fmt .Errorf ("creating release: %s" , err )
135
138
}
139
+ outPlatformRelease .IsTrusted = trusted
136
140
outPlatformRelease .Resource = & resources.DownloadResource {
137
141
ArchiveFileName : inPlatformRelease .ArchiveFileName ,
138
142
Checksum : inPlatformRelease .Checksum ,
@@ -213,5 +217,19 @@ func LoadIndex(jsonIndexFile *paths.Path) (*Index, error) {
213
217
return nil , err
214
218
}
215
219
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
+ }
216
234
return & index , nil
217
235
}
0 commit comments