Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b0ebd79

Browse files
committed
When updating splash image check for valid signature
1 parent 764b586 commit b0ebd79

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

‎app/src/processing/app/UpdateCheck.java‎

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
import org.apache.commons.compress.utils.IOUtils;
4444

45+
import cc.arduino.contributions.SignatureVerifier;
46+
import cc.arduino.utils.FileHash;
4547
import processing.app.legacy.PApplet;
4648

4749

@@ -125,27 +127,48 @@ public void run() {
125127
//System.err.println("Error while trying to check for an update.");
126128
}
127129

130+
File tmp = null;
128131
try {
132+
tmp = File.createTempFile("arduino_splash_update", ".txt.asc");
129133
// Check for updates of the splash screen
130-
List<String> lines = readFileFromURL("https://go.bug.st/latest_splash.txt");
131-
if (lines.size() > 0) {
132-
// if the splash image has been changed download the new file
133-
String newSplashUrl = lines.get(0);
134-
String oldSplashUrl = PreferencesData.get("splash.imageurl");
135-
if (!newSplashUrl.equals(oldSplashUrl)) {
136-
File tmpFile = BaseNoGui.getSettingsFile("splash.png.tmp");
137-
downloadFileFromURL(newSplashUrl, tmpFile);
138-
File destFile = BaseNoGui.getSettingsFile("splash.png");
139-
Files.move(tmpFile.toPath(), destFile.toPath(),
140-
StandardCopyOption.REPLACE_EXISTING);
141-
PreferencesData.set("splash.imageurl", newSplashUrl);
134+
downloadFileFromURL("https://go.bug.st/latest_splash.txt.asc", tmp);
135+
SignatureVerifier verifier = new SignatureVerifier();
136+
if (!verifier.verifyCleartextSignature(tmp)) {
137+
throw new Exception("Invalid signature");
138+
}
139+
String[] lines = verifier.extractTextFromCleartextSignature(tmp);
140+
if (lines.length < 2) {
141+
throw new Exception("Invalid splash image update");
142+
}
143+
String newSplashUrl = lines[0];
144+
String checksum = lines[1];
145+
146+
// if the splash image has been changed download the new file
147+
String oldSplashUrl = PreferencesData.get("splash.imageurl");
148+
if (!newSplashUrl.equals(oldSplashUrl)) {
149+
File tmpFile = BaseNoGui.getSettingsFile("splash.png.tmp");
150+
downloadFileFromURL(newSplashUrl, tmpFile);
151+
152+
String algo = checksum.split(":")[0];
153+
String crc = FileHash.hash(tmpFile, algo);
154+
if (!crc.equalsIgnoreCase(checksum)) {
155+
throw new Exception("Invalid splash image checksum");
142156
}
143157

144-
// extend expiration by 24h
145-
PreferencesData.setLong("splash.expire", now + ONE_DAY);
158+
File destFile = BaseNoGui.getSettingsFile("splash.png");
159+
Files.move(tmpFile.toPath(), destFile.toPath(),
160+
StandardCopyOption.REPLACE_EXISTING);
161+
PreferencesData.set("splash.imageurl", newSplashUrl);
146162
}
163+
164+
// extend expiration by 24h
165+
PreferencesData.setLong("splash.expire", now + ONE_DAY);
147166
} catch (Exception e) {
148167
// e.printStackTrace();
168+
} finally {
169+
if (tmp != null) {
170+
tmp.delete();
171+
}
149172
}
150173
}
151174

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /