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 1c1051c

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

File tree

5 files changed

+23
-24
lines changed

5 files changed

+23
-24
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
package cc.arduino.contributions;
3131

32-
import cc.arduino.Constants;
3332
import cc.arduino.utils.FileHash;
3433
import cc.arduino.utils.MultiStepProgress;
3534
import cc.arduino.utils.Progress;
@@ -199,10 +198,6 @@ public boolean verifyDomain(URL url) {
199198

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

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;
206201

207202
// Signature file name
208203
final String signatureFileName = FilenameUtils.getName(signatureUrl.getPath());
@@ -214,7 +209,7 @@ public boolean checkSignature(MultiStepProgress progress, URL signatureUrl, Prog
214209
// Download signature
215210
download(signatureUrl, packageIndexSignatureTemp, progress, statusText, progressListener, true);
216211

217-
if (skipVerification) {
212+
if (PreferencesData.areInsecurePackagesAllowed()) {
218213
Files.move(packageIndexSignatureTemp.toPath(), packageIndexSignature.toPath(), StandardCopyOption.REPLACE_EXISTING);
219214
log.info("Allowing insecure packages because allow_insecure_packages is set to true in preferences.txt" +
220215
" 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/Platform.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
* know if name is proper Java package syntax.)
6161
*/
6262
public class Platform {
63-
private static Logger log = LogManager.getLogger(Platform.class);
6463

6564
/**
6665
* Set the default L & F. While I enjoy the bounty of the sixteen possible
@@ -196,12 +195,10 @@ public synchronized void getBoardWithMatchingVidPidFromCloud(String vid, String
196195
.makeConnection();
197196
int code = httpConnection.getResponseCode();
198197
if (code == 404) {
199-
log.warn("Fail to get the Vid Pid information from the builder response code={}", code);
200198
return;
201199
}
202200
InputStream is = httpConnection.getInputStream();
203201
BoardCloudAPIid board = mapper.readValue(is, BoardCloudAPIid.class);
204-
log.info("Board info from the cloud {}", board);
205202
// Launch a popup with a link to boardmanager#board.getName()
206203
// replace spaces with &
207204
String realBoardName = board.getName().replaceAll("\\(.*?\\)", "").trim();

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
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 processing.app.helpers.PreferencesHelper;
7+
import processing.app.helpers.PreferencesMap;
8+
import processing.app.legacy.PApplet;
9+
import processing.app.legacy.PConstants;
510

6-
import java.awt.Font;
11+
import java.awt.*;
712
import java.io.File;
813
import java.io.IOException;
914
import java.io.PrintWriter;
@@ -13,13 +18,8 @@
1318
import java.util.MissingResourceException;
1419
import java.util.stream.Collectors;
1520

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;
21+
import static processing.app.I18n.format;
22+
import static processing.app.I18n.tr;
2323

2424

2525
public class PreferencesData {
@@ -275,4 +275,11 @@ public static void setCollection(String key, Collection<String> values) {
275275
String value = values.stream().collect(Collectors.joining(","));
276276
set(key, value);
277277
}
278+
279+
public static boolean areInsecurePackagesAllowed() {
280+
if (getBoolean(Constants.ALLOW_INSECURE_PACKAGES, false)) {
281+
return true;
282+
}
283+
return getBoolean(Constants.PREF_CONTRIBUTIONS_TRUST_ALL, false);
284+
}
278285
}

0 commit comments

Comments
(0)

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