@@ -201,18 +201,40 @@ func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexRequ
201201 }
202202 }
203203
204+ // Download signature
205+ tmpSignature := tmp .Join ("library_index.json.sig" )
206+ if d , err := downloader .DownloadWithConfig (tmpSignature .String (), librariesmanager .LibraryIndexSignature .String (), * config , downloader .NoResume ); err != nil {
207+ return err
208+ } else {
209+ if err := Download (d , "Updating index: library_index.json.sig" , downloadCB ); err != nil {
210+ return errors .Wrap (err , "downloading library_index.json.sig" )
211+ }
212+ }
213+
204214 // Extract the real library_index
205215 tmpIndex := tmp .Join ("library_index.json" )
206216 if err := paths .GUnzip (tmpIndexGz , tmpIndex ); err != nil {
207217 return errors .Wrap (err , "unzipping library_index.json.gz" )
208218 }
209219
210- // Copy extracted library_index to final destination
220+ // Check signature
221+ if ok , _ , err := security .VerifyArduinoDetachedSignature (tmpIndex , tmpSignature ); err != nil {
222+ return errors .Wrap (err , "verifying signature" )
223+ } else if ! ok {
224+ return errors .New ("library_index.json has an invalid signature!" )
225+ }
226+
227+ // Copy extracted library_index and signature to final destination
211228 lm .IndexFile .Remove ()
229+ lm .IndexFileSignature .Remove ()
212230 if err := tmpIndex .CopyTo (lm .IndexFile ); err != nil {
213231 return errors .Wrap (err , "writing library_index.json" )
214232 }
233+ if err := tmpSignature .CopyTo (lm .IndexFileSignature ); err != nil {
234+ return errors .Wrap (err , "writing library_index.json.sig" )
235+ }
215236
237+ // Rescan libraries
216238 if _ , err := Rescan (req .GetInstance ().GetId ()); err != nil {
217239 return fmt .Errorf ("rescanning filesystem: %s" , err )
218240 }
0 commit comments