Skip to content

Improve signature check on library_index.json #2326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions arduino/resources/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package resources

import (
"context"
"errors"
"net/url"
"path"
"strings"
Expand All @@ -33,8 +34,9 @@ import (

// IndexResource is a reference to an index file URL with an optional signature.
type IndexResource struct {
URL *url.URL
SignatureURL *url.URL
URL *url.URL
SignatureURL *url.URL
EnforceSignatureVerification bool
}

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

// TODO: Implement a ResourceValidator
Expand Down
3 changes: 2 additions & 1 deletion commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexRequ
defer tmp.RemoveAll()

indexResource := resources.IndexResource{
URL: librariesmanager.LibraryIndexWithSignatureArchiveURL,
URL: librariesmanager.LibraryIndexWithSignatureArchiveURL,
EnforceSignatureVerification: true,
}
if err := indexResource.Download(lm.IndexFile.Parent(), downloadCB); err != nil {
return err
Expand Down