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 e0374c1

Browse files
author
Mattia Bertorello
committed
Add areInsecurePackagesAllowed method
1 parent 2f2c2b4 commit e0374c1

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

‎arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,6 @@ public boolean verifyDomain(URL url) {
199199

200200
public boolean checkSignature(MultiStepProgress progress, URL signatureUrl, ProgressListener progressListener, SignatureVerifier signatureVerifier, String statusText, File fileToVerify) throws Exception {
201201

202-
final boolean allowInsecurePackages =
203-
PreferencesData.getBoolean(Constants.ALLOW_INSECURE_PACKAGES, false);
204-
final boolean trustAll = PreferencesData.getBoolean(Constants.PREF_CONTRIBUTIONS_TRUST_ALL);
205-
final boolean skipVerification = allowInsecurePackages || trustAll;
206202

207203
// Signature file name
208204
final String signatureFileName = FilenameUtils.getName(signatureUrl.getPath());
@@ -214,7 +210,7 @@ public boolean checkSignature(MultiStepProgress progress, URL signatureUrl, Prog
214210
// Download signature
215211
download(signatureUrl, packageIndexSignatureTemp, progress, statusText, progressListener, true);
216212

217-
if (skipVerification) {
213+
if (PreferencesData.areInsecurePackagesAllowed()) {
218214
Files.move(packageIndexSignatureTemp.toPath(), packageIndexSignature.toPath(), StandardCopyOption.REPLACE_EXISTING);
219215
log.info("Allowing insecure packages because allow_insecure_packages is set to true in preferences.txt" +
220216
" but the signature was download");

‎arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public synchronized List<String> install(ContributedPlatform contributedPlatform
145145
assert toolContrib.getDownloadedFile() != null;
146146
new ArchiveExtractor(platform).extract(toolContrib.getDownloadedFile(), destFolder.toFile(), 1);
147147
try {
148-
findAndExecutePostInstallScriptIfAny(destFolder.toFile(), contributedPlatform.getParentPackage().isTrusted(), PreferencesData.getBoolean(Constants.PREF_CONTRIBUTIONS_TRUST_ALL));
148+
findAndExecutePostInstallScriptIfAny(destFolder.toFile(), contributedPlatform.getParentPackage().isTrusted(), PreferencesData.areInsecurePackagesAllowed());
149149
} catch (IOException e) {
150150
errors.add(tr("Error running post install script"));
151151
}
@@ -164,7 +164,7 @@ public synchronized List<String> install(ContributedPlatform contributedPlatform
164164
contributedPlatform.setInstalled(true);
165165
contributedPlatform.setInstalledFolder(destFolder);
166166
try {
167-
findAndExecutePostInstallScriptIfAny(destFolder, contributedPlatform.getParentPackage().isTrusted(), PreferencesData.getBoolean(Constants.PREF_CONTRIBUTIONS_TRUST_ALL));
167+
findAndExecutePostInstallScriptIfAny(destFolder, contributedPlatform.getParentPackage().isTrusted(), PreferencesData.areInsecurePackagesAllowed());
168168
} catch (IOException e) {
169169
e.printStackTrace();
170170
errors.add(tr("Error running post install script"));
@@ -244,7 +244,7 @@ public synchronized List<String> remove(ContributedPlatform contributedPlatform)
244244
}
245245
List<String> errors = new LinkedList<>();
246246
try {
247-
findAndExecutePreUninstallScriptIfAny(contributedPlatform.getInstalledFolder(), contributedPlatform.getParentPackage().isTrusted(), PreferencesData.getBoolean(Constants.PREF_CONTRIBUTIONS_TRUST_ALL));
247+
findAndExecutePreUninstallScriptIfAny(contributedPlatform.getInstalledFolder(), contributedPlatform.getParentPackage().isTrusted(), PreferencesData.areInsecurePackagesAllowed());
248248
} catch (IOException e) {
249249
errors.add(tr("Error running post install script"));
250250
}

‎arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void parseIndex() throws Exception {
8686
File defaultIndexFile = getIndexFile(Constants.DEFAULT_INDEX_FILE_NAME);
8787
if (defaultIndexFile.exists()) {
8888
// Check main index signature
89-
if (!PreferencesData.getBoolean(Constants.ALLOW_INSECURE_PACKAGES) && !signatureVerifier.isSigned(defaultIndexFile)) {
89+
if (!PreferencesData.areInsecurePackagesAllowed() && !signatureVerifier.isSigned(defaultIndexFile)) {
9090
throw new SignatureVerificationFailedException(Constants.DEFAULT_INDEX_FILE_NAME);
9191
}
9292

@@ -142,7 +142,7 @@ private void mergeContributions(File indexFile) throws IOException {
142142

143143
ContributionsIndex contributionsIndex = parseIndex(indexFile);
144144
boolean signed = signatureVerifier.isSigned(indexFile);
145-
boolean trustall = PreferencesData.getBoolean(Constants.PREF_CONTRIBUTIONS_TRUST_ALL);
145+
boolean trustall = PreferencesData.areInsecurePackagesAllowed();
146146

147147
for (ContributedPackage contributedPackage : contributionsIndex.getPackages()) {
148148
contributedPackage.setTrusted(signed || trustall);

‎arduino-core/src/processing/app/PreferencesData.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
package processing.app;
22

3-
import static processing.app.I18n.format;
4-
import static processing.app.I18n.tr;
3+
import cc.arduino.Constants;
4+
import cc.arduino.i18n.Languages;
5+
import org.apache.commons.compress.utils.IOUtils;
6+
import org.apache.logging.log4j.LogManager;
7+
import org.apache.logging.log4j.Logger;
8+
import processing.app.helpers.PreferencesHelper;
9+
import processing.app.helpers.PreferencesMap;
10+
import processing.app.legacy.PApplet;
11+
import processing.app.legacy.PConstants;
512

6-
import java.awt.Font;
13+
import java.awt.*;
714
import java.io.File;
815
import java.io.IOException;
916
import java.io.PrintWriter;
@@ -13,13 +20,8 @@
1320
import java.util.MissingResourceException;
1421
import java.util.stream.Collectors;
1522

16-
import org.apache.commons.compress.utils.IOUtils;
17-
18-
import cc.arduino.i18n.Languages;
19-
import processing.app.helpers.PreferencesHelper;
20-
import processing.app.helpers.PreferencesMap;
21-
import processing.app.legacy.PApplet;
22-
import processing.app.legacy.PConstants;
23+
import static processing.app.I18n.format;
24+
import static processing.app.I18n.tr;
2325

2426

2527
public class PreferencesData {
@@ -275,4 +277,14 @@ public static void setCollection(String key, Collection<String> values) {
275277
String value = values.stream().collect(Collectors.joining(","));
276278
set(key, value);
277279
}
280+
281+
public static boolean areInsecurePackagesAllowed() {
282+
if (getBoolean(Constants.ALLOW_INSECURE_PACKAGES, false)) {
283+
return true;
284+
}
285+
if (getBoolean(Constants.PREF_CONTRIBUTIONS_TRUST_ALL, false)) {
286+
return true;
287+
}
288+
return false;
289+
}
278290
}

0 commit comments

Comments
(0)

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