Skip to content

Commit 28fc9d6

Browse files
authored
Enforce signature check on library_index.json (#2326)
1 parent 29c70df commit 28fc9d6

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Diff for: arduino/resources/index.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package resources
1717

1818
import (
1919
"context"
20+
"errors"
2021
"net/url"
2122
"path"
2223
"strings"
@@ -33,8 +34,9 @@ import (
3334

3435
// IndexResource is a reference to an index file URL with an optional signature.
3536
type IndexResource struct {
36-
URL *url.URL
37-
SignatureURL *url.URL
37+
URL *url.URL
38+
SignatureURL *url.URL
39+
EnforceSignatureVerification bool
3840
}
3941

4042
// IndexFileName returns the index file name as it is saved in data dir (package_xxx_index.json).
@@ -140,6 +142,10 @@ func (res *IndexResource) Download(destDir *paths.Path, downloadCB rpc.DownloadP
140142
} else if !valid {
141143
return &arduino.SignatureVerificationFailedError{File: res.URL.String()}
142144
}
145+
} else {
146+
if res.EnforceSignatureVerification {
147+
return &arduino.PermissionDeniedError{Message: tr("Error verifying signature"), Cause: errors.New(tr("missing signature"))}
148+
}
143149
}
144150

145151
// TODO: Implement a ResourceValidator

Diff for: commands/instances.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,8 @@ func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexRequ
511511
defer tmp.RemoveAll()
512512

513513
indexResource := resources.IndexResource{
514-
URL: librariesmanager.LibraryIndexWithSignatureArchiveURL,
514+
URL: librariesmanager.LibraryIndexWithSignatureArchiveURL,
515+
EnforceSignatureVerification: true,
515516
}
516517
if err := indexResource.Download(lm.IndexFile.Parent(), downloadCB); err != nil {
517518
return err

0 commit comments

Comments
 (0)