Skip to content

Add checksum check before installing a package #947

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 15, 2020
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
7 changes: 7 additions & 0 deletions arduino/resources/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ import (
// Note that tempPath and destDir must be on the same filesystem partition
// otherwise the last step will fail.
func (release *DownloadResource) Install(downloadDir, tempPath, destDir *paths.Path) error {
// Check the integrity of the package
if ok, err := release.TestLocalArchiveIntegrity(downloadDir); err != nil {
return fmt.Errorf("testing local archive integrity: %s", err)
} else if !ok {
return fmt.Errorf("checking local archive integrity")
}

// Create a temporary dir to extract package
if err := tempPath.MkdirAll(); err != nil {
return fmt.Errorf("creating temp dir for extraction: %s", err)
Expand Down
6 changes: 6 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,9 @@ def test_core_zipslip(run_command):
# Install a core and check if malicious content has been extracted.
run_command("core install zipslip:x86 --additional-urls={}".format(url))
assert os.path.exists("/tmp/evil.txt") is False


def test_core_broken_install(run_command):
url = "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/test_index.json"
assert run_command("core update-index --additional-urls={}".format(url))
assert not run_command("core install brokenchecksum:x86 --additional-urls={}".format(url))
39 changes: 35 additions & 4 deletions test/testdata/test_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"online": "https://github.com/Arduino/arduino-cli"
},
"url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/core.zip",
"checksum": "SHA-256:1ba93f6aea56842dfef065c0f5eb0a34c1f78b72b3f2426c94e47ba3a359c9ff",
"checksum": "SHA-256:6a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092",
"name": "test_core",
"version": "1.0.0",
"architecture": "x86",
"archiveFileName": "core.zip",
"size": "2799",
"size": "486",
"toolsDependencies": [],
"boards": [
{
Expand All @@ -32,12 +32,12 @@
"online": "https://github.com/Arduino/arduino-cli"
},
"url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/core.zip",
"checksum": "SHA-256:1ba93f6aea56842dfef065c0f5eb0a34c1f78b72b3f2426c94e47ba3a359c9ff",
"checksum": "SHA-256:6a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092",
"name": "test_core",
"version": "2.0.0",
"architecture": "x86",
"archiveFileName": "core.zip",
"size": "2799",
"size": "486",
"toolsDependencies": [],
"boards": [
{
Expand Down Expand Up @@ -80,6 +80,37 @@
]
}
]
},
{
"name": "brokenchecksum",
"tools": [],
"email": "[email protected]",
"maintainer": "Arduino",
"help": {
"online": "https://github.com/Arduino/arduino-cli"
},
"websiteURL": "https://github.com/Arduino/arduino-cli",
"platforms": [
{
"category": "BrokenChecksum Test",
"help": {
"online": "https://github.com/Arduino/arduino-cli"
},
"url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/core.zip",
"checksum": "SHA-256:1a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092",
"name": "zipslip",
"version": "1.0.0",
"architecture": "x86",
"archiveFileName": "core.zip",
"size": "486",
"toolsDependencies": [],
"boards": [
{
"name": "Test Board"
}
]
}
]
}
]
}