Skip to content

Commit 163a1f7

Browse files
author
Federico
authored
Add checksum check before installing a package (#947)
1 parent 1e5354b commit 163a1f7

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

Diff for: arduino/resources/install.go

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ import (
3232
// Note that tempPath and destDir must be on the same filesystem partition
3333
// otherwise the last step will fail.
3434
func (release *DownloadResource) Install(downloadDir, tempPath, destDir *paths.Path) error {
35+
// Check the integrity of the package
36+
if ok, err := release.TestLocalArchiveIntegrity(downloadDir); err != nil {
37+
return fmt.Errorf("testing local archive integrity: %s", err)
38+
} else if !ok {
39+
return fmt.Errorf("checking local archive integrity")
40+
}
41+
3542
// Create a temporary dir to extract package
3643
if err := tempPath.MkdirAll(); err != nil {
3744
return fmt.Errorf("creating temp dir for extraction: %s", err)

Diff for: test/test_core.py

+6
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,9 @@ def test_core_zipslip(run_command):
203203
# Install a core and check if malicious content has been extracted.
204204
run_command("core install zipslip:x86 --additional-urls={}".format(url))
205205
assert os.path.exists("/tmp/evil.txt") is False
206+
207+
208+
def test_core_broken_install(run_command):
209+
url = "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/test_index.json"
210+
assert run_command("core update-index --additional-urls={}".format(url))
211+
assert not run_command("core install brokenchecksum:x86 --additional-urls={}".format(url))

Diff for: test/testdata/test_index.json

+35-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
"online": "https://github.com/Arduino/arduino-cli"
1414
},
1515
"url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/core.zip",
16-
"checksum": "SHA-256:1ba93f6aea56842dfef065c0f5eb0a34c1f78b72b3f2426c94e47ba3a359c9ff",
16+
"checksum": "SHA-256:6a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092",
1717
"name": "test_core",
1818
"version": "1.0.0",
1919
"architecture": "x86",
2020
"archiveFileName": "core.zip",
21-
"size": "2799",
21+
"size": "486",
2222
"toolsDependencies": [],
2323
"boards": [
2424
{
@@ -32,12 +32,12 @@
3232
"online": "https://github.com/Arduino/arduino-cli"
3333
},
3434
"url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/core.zip",
35-
"checksum": "SHA-256:1ba93f6aea56842dfef065c0f5eb0a34c1f78b72b3f2426c94e47ba3a359c9ff",
35+
"checksum": "SHA-256:6a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092",
3636
"name": "test_core",
3737
"version": "2.0.0",
3838
"architecture": "x86",
3939
"archiveFileName": "core.zip",
40-
"size": "2799",
40+
"size": "486",
4141
"toolsDependencies": [],
4242
"boards": [
4343
{
@@ -80,6 +80,37 @@
8080
]
8181
}
8282
]
83+
},
84+
{
85+
"name": "brokenchecksum",
86+
"tools": [],
87+
"email": "[email protected]",
88+
"maintainer": "Arduino",
89+
"help": {
90+
"online": "https://github.com/Arduino/arduino-cli"
91+
},
92+
"websiteURL": "https://github.com/Arduino/arduino-cli",
93+
"platforms": [
94+
{
95+
"category": "BrokenChecksum Test",
96+
"help": {
97+
"online": "https://github.com/Arduino/arduino-cli"
98+
},
99+
"url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/core.zip",
100+
"checksum": "SHA-256:1a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092",
101+
"name": "zipslip",
102+
"version": "1.0.0",
103+
"architecture": "x86",
104+
"archiveFileName": "core.zip",
105+
"size": "486",
106+
"toolsDependencies": [],
107+
"boards": [
108+
{
109+
"name": "Test Board"
110+
}
111+
]
112+
}
113+
]
83114
}
84115
]
85116
}

0 commit comments

Comments
 (0)