Skip to content

Commit

Permalink
Do not fail abruptly if signature verification fails
Browse files Browse the repository at this point in the history
If the package_index.json signature is not valid, a dialog box asking
the user to "update" the index is shown. Previously a java-exception
was printed if running from terminal or the IDE would not start at
all (with no apparent reason) if lanched from GUI.
  • Loading branch information
cmaglie committed Aug 20, 2019
1 parent 842c35b commit 5bb9f87
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 57 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@

import cc.arduino.Constants;
import cc.arduino.contributions.DownloadableContribution;
import cc.arduino.contributions.SignatureVerificationFailedException;
import cc.arduino.contributions.SignatureVerifier;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
import org.apache.commons.compress.utils.IOUtils;

import processing.app.BaseNoGui;
import processing.app.Platform;
import processing.app.PreferencesData;
import processing.app.debug.TargetPackage;
Expand Down Expand Up @@ -86,15 +87,21 @@ public void parseIndex() throws Exception {
File defaultIndexFile = getIndexFile(Constants.DEFAULT_INDEX_FILE_NAME);
if (defaultIndexFile.exists()) {
// Check main index signature
if (!signatureVerifier.isSigned(defaultIndexFile)) {
if (PreferencesData.areInsecurePackagesAllowed()) {
System.err.println(format(tr("Warning: forced trusting untrusted contributions")));
} else {
throw new SignatureVerificationFailedException(Constants.DEFAULT_INDEX_FILE_NAME);
}
if (signatureVerifier.isSigned(defaultIndexFile)) {
mergeContributions(defaultIndexFile);
} else if (PreferencesData.areInsecurePackagesAllowed()) {
System.err.println(format(tr("Warning: forced trusting untrusted contributions")));
mergeContributions(defaultIndexFile);
} else {
BaseNoGui
.showWarning(Constants.DEFAULT_INDEX_FILE_NAME,
tr("A package index has an invalid signature and needs to be updated.\n"
+ "Please open the Board Manager from the menu\n"
+ "\n" //
+ " Tools -> Board -> Board Manager\n"
+ "\nto update it"),
null);
}

mergeContributions(defaultIndexFile);
}

// Set main and bundled indexes as trusted
Expand Down
3 changes: 1 addition & 2 deletions arduino-core/src/processing/app/BaseNoGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import cc.arduino.Constants;
import cc.arduino.contributions.GPGDetachedSignatureVerifier;
import cc.arduino.contributions.SignatureVerificationFailedException;
import cc.arduino.contributions.VersionComparator;
import cc.arduino.contributions.libraries.LibrariesIndexer;
import cc.arduino.contributions.packages.ContributedPlatform;
Expand Down Expand Up @@ -482,7 +481,7 @@ static public void initPackages() throws Exception {

try {
indexer.parseIndex();
} catch (JsonProcessingException | SignatureVerificationFailedException e) {
} catch (JsonProcessingException e) {
File indexFile = indexer.getIndexFile(Constants.DEFAULT_INDEX_FILE_NAME);
File indexSignatureFile = indexer.getIndexFile(Constants.DEFAULT_INDEX_FILE_NAME + ".sig");
indexFile.delete();
Expand Down

0 comments on commit 5bb9f87

Please sign in to comment.