Skip to content

Commit 987cad2

Browse files
author
Federico Fissore
committed
Added core "post install" and "pre uninstall" script support.
If a core has a post/pre install/uninstall script, it will be execute at the appropriate time IF: 1) source (package_*_index) is trusted (GPG signed) 2) or users have explicitly added line "contributions.trust.all=true" to their preferences.txt Some minor refactor and clean up while I was at it
1 parent 7cc7d47 commit 987cad2

File tree

17 files changed

+209
-102
lines changed

17 files changed

+209
-102
lines changed

app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
package cc.arduino.contributions.packages.ui;
3131

3232
import cc.arduino.contributions.DownloadableContribution;
33+
import cc.arduino.contributions.GPGDetachedSignatureVerifier;
3334
import cc.arduino.contributions.packages.ContributedPlatform;
3435
import cc.arduino.contributions.packages.ContributionInstaller;
3536
import cc.arduino.contributions.packages.ContributionsIndexer;
@@ -116,7 +117,7 @@ public void setIndexer(ContributionsIndexer indexer) {
116117
}
117118

118119
// Create ConstributionInstaller tied with the provided index
119-
installer = new ContributionInstaller(indexer, platform) {
120+
installer = new ContributionInstaller(indexer, platform, new GPGDetachedSignatureVerifier()) {
120121
@Override
121122
public void onProgress(Progress progress) {
122123
setProgress(progress);

app/src/processing/app/Base.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import cc.arduino.contributions.BuiltInCoreIsNewerCheck;
2626
import cc.arduino.contributions.DownloadableContributionVersionComparator;
27+
import cc.arduino.contributions.GPGDetachedSignatureVerifier;
2728
import cc.arduino.contributions.VersionHelper;
2829
import cc.arduino.contributions.libraries.*;
2930
import cc.arduino.contributions.libraries.ui.LibraryManagerUI;
@@ -345,8 +346,8 @@ public Base(String[] args) throws Exception {
345346
PreferencesData.save();
346347

347348
if (parser.isInstallBoard()) {
348-
ContributionsIndexer indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder(), BaseNoGui.getPlatform());
349-
ContributionInstaller installer = new ContributionInstaller(indexer, BaseNoGui.getPlatform()) {
349+
ContributionsIndexer indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder(), BaseNoGui.getPlatform(), new GPGDetachedSignatureVerifier());
350+
ContributionInstaller installer = new ContributionInstaller(indexer, BaseNoGui.getPlatform(), new GPGDetachedSignatureVerifier()) {
350351
private String lastStatus = "";
351352

352353
@Override
@@ -392,7 +393,7 @@ protected void onProgress(Progress progress) {
392393
System.exit(0);
393394

394395
} else if (parser.isInstallLibrary()) {
395-
LibrariesIndexer indexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder(), new ContributionsIndexer(BaseNoGui.getSettingsFolder(), BaseNoGui.getPlatform()));
396+
LibrariesIndexer indexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder(), new ContributionsIndexer(BaseNoGui.getSettingsFolder(), BaseNoGui.getPlatform(), new GPGDetachedSignatureVerifier()));
396397
LibraryInstaller installer = new LibraryInstaller(indexer, BaseNoGui.getPlatform()) {
397398
private String lastStatus = "";
398399

app/test/cc/arduino/packages/contributions/GPGDetachedSignatureVerifierTest.java renamed to app/test/cc/arduino/contributions/GPGDetachedSignatureVerifierTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
* the GNU General Public License.
2828
*/
2929

30-
package cc.arduino.packages.contributions;
30+
package cc.arduino.contributions;
3131

32-
import cc.arduino.contributions.GPGDetachedSignatureVerifier;
3332
import org.junit.Before;
3433
import org.junit.Test;
3534

arduino-core/src/cc/arduino/contributions/packages/Constants.java renamed to arduino-core/src/cc/arduino/contributions/Constants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* the GNU General Public License.
2828
*/
2929

30-
package cc.arduino.contributions.packages;
30+
package cc.arduino.contributions;
3131

3232
import java.util.Arrays;
3333
import java.util.List;
@@ -39,6 +39,7 @@ public class Constants {
3939
public static final String PACKAGE_INDEX_URL;
4040

4141
public static final String PREFERENCES_BOARDS_MANAGER_ADDITIONAL_URLS = "boardsmanager.additional.urls";
42+
public static final String PREF_CONTRIBUTIONS_TRUST_ALL = "contributions.trust.all";
4243

4344
static {
4445
String extenalPackageIndexUrl = System.getProperty("PACKAGE_INDEX_URL");

arduino-core/src/cc/arduino/contributions/GPGDetachedSignatureVerifier.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* This file is part of Arduino.
33
*
4+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
5+
*
46
* Arduino is free software; you can redistribute it and/or modify
57
* it under the terms of the GNU General Public License as published by
68
* the Free Software Foundation; either version 2 of the License, or
@@ -23,8 +25,6 @@
2325
* the GNU General Public License. This exception does not however
2426
* invalidate any other reasons why the executable file might be covered by
2527
* the GNU General Public License.
26-
*
27-
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
2828
*/
2929

3030
package cc.arduino.contributions;
@@ -37,7 +37,7 @@
3737
import java.io.*;
3838
import java.util.Iterator;
3939

40-
public class GPGDetachedSignatureVerifier {
40+
public class GPGDetachedSignatureVerifier extends SignatureVerifier {
4141

4242
private String keyId;
4343

@@ -49,9 +49,7 @@ public GPGDetachedSignatureVerifier(String keyId) {
4949
this.keyId = keyId;
5050
}
5151

52-
public boolean verify(File signedFile, File signature, File publicKey) throws IOException, PGPException {
53-
PGPPublicKey pgpPublicKey = readPublicKey(publicKey, keyId);
54-
52+
protected boolean verify(File signedFile, File signature, File publicKey) throws IOException {
5553
FileInputStream signatureInputStream = null;
5654
FileInputStream signedFileInputStream = null;
5755
try {
@@ -71,11 +69,15 @@ public boolean verify(File signedFile, File signature, File publicKey) throws IO
7169
assert pgpSignatureList.size() == 1;
7270
PGPSignature pgpSignature = pgpSignatureList.get(0);
7371

72+
PGPPublicKey pgpPublicKey = readPublicKey(publicKey, keyId);
73+
7474
pgpSignature.init(new BcPGPContentVerifierBuilderProvider(), pgpPublicKey);
7575
signedFileInputStream = new FileInputStream(signedFile);
7676
pgpSignature.update(IOUtils.toByteArray(signedFileInputStream));
7777

7878
return pgpSignature.verify();
79+
} catch (PGPException e) {
80+
throw new IOException(e);
7981
} finally {
8082
IOUtils.closeQuietly(signatureInputStream);
8183
IOUtils.closeQuietly(signedFileInputStream);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
5+
*
6+
* Arduino is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
* As a special exception, you may use this file as part of a free software
21+
* library without restriction. Specifically, if other files instantiate
22+
* templates or use macros or inline functions from this file, or you compile
23+
* this file and link it with other files to produce an executable, this
24+
* file does not by itself cause the resulting executable to be covered by
25+
* the GNU General Public License. This exception does not however
26+
* invalidate any other reasons why the executable file might be covered by
27+
* the GNU General Public License.
28+
*/
29+
30+
package cc.arduino.contributions;
31+
32+
import processing.app.BaseNoGui;
33+
34+
import java.io.File;
35+
import java.io.IOException;
36+
37+
public abstract class SignatureVerifier {
38+
39+
public boolean isSigned(File indexFile) {
40+
File signature = new File(indexFile.getParent(), indexFile.getName() + ".sig");
41+
if (!signature.exists()) {
42+
return false;
43+
}
44+
45+
try {
46+
return verify(indexFile, signature, new File(BaseNoGui.getContentFile("lib"), "public.gpg.key"));
47+
} catch (Exception e) {
48+
BaseNoGui.showWarning(e.getMessage(), e.getMessage(), e);
49+
return false;
50+
}
51+
}
52+
53+
protected abstract boolean verify(File signedFile, File signature, File publicKey) throws IOException;
54+
55+
}

arduino-core/src/cc/arduino/contributions/packages/ContributedPackage.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public abstract class ContributedPackage {
4747

4848
public abstract ContributedHelp getHelp();
4949

50+
private boolean trusted;
51+
5052
public ContributedPlatform findPlatform(String architecture, String version) {
5153
if (architecture == null || version == null) {
5254
return null;
@@ -66,6 +68,14 @@ public ContributedTool findTool(String name, String version) {
6668
return null;
6769
}
6870

71+
public boolean isTrusted() {
72+
return trusted;
73+
}
74+
75+
public void setTrusted(boolean trusted) {
76+
this.trusted = trusted;
77+
}
78+
6979
@Override
7080
public String toString() {
7181
String res;

0 commit comments

Comments
 (0)