1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-26 20:54:22 +01:00

Merge pull request #11730 from cmaglie/remove_log4j

Remove log4j, to fix current and future CVEs.
This commit is contained in:
Cristian Maglie 2021-12-20 16:11:24 +01:00 committed by GitHub
commit c4078e7f70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 31 additions and 188 deletions

View File

@ -38,8 +38,6 @@
<classpathentry kind="lib" path="lib/jmdns-3.5.5.jar"/> <classpathentry kind="lib" path="lib/jmdns-3.5.5.jar"/>
<classpathentry kind="lib" path="lib/slf4j-api-1.7.22.jar"/> <classpathentry kind="lib" path="lib/slf4j-api-1.7.22.jar"/>
<classpathentry kind="lib" path="lib/slf4j-simple-1.7.22.jar"/> <classpathentry kind="lib" path="lib/slf4j-simple-1.7.22.jar"/>
<classpathentry kind="lib" path="lib/log4j-api-2.16.0.jar"/>
<classpathentry kind="lib" path="lib/log4j-core-2.16.0.jar"/>
<classpathentry kind="lib" path="lib/jsch-0.1.50.jar"/> <classpathentry kind="lib" path="lib/jsch-0.1.50.jar"/>
<classpathentry kind="lib" path="lib/rsyntaxtextarea-3.0.3-SNAPSHOT.jar"/> <classpathentry kind="lib" path="lib/rsyntaxtextarea-3.0.3-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/xml-apis-1.3.04.jar"/> <classpathentry kind="lib" path="lib/xml-apis-1.3.04.jar"/>

View File

@ -80,10 +80,6 @@
includeAntRuntime="false" includeAntRuntime="false"
debug="true" debug="true"
classpathref="class.path" /> classpathref="class.path" />
<!-- If you want to add files in the jars -->
<copy todir="bin" overwrite="true" verbose="true">
<fileset dir="src" includes="log4j2.xml" />
</copy>
</target> </target>
<target name="test" depends="compile" description="Runs the test"> <target name="test" depends="compile" description="Runs the test">

Binary file not shown.

Binary file not shown.

View File

@ -35,7 +35,6 @@ import cc.arduino.contributions.libraries.filters.UpdatableLibraryPredicate;
import cc.arduino.contributions.packages.ContributionInstaller; import cc.arduino.contributions.packages.ContributionInstaller;
import cc.arduino.contributions.packages.filters.UpdatablePlatformPredicate; import cc.arduino.contributions.packages.filters.UpdatablePlatformPredicate;
import cc.arduino.view.NotificationPopup; import cc.arduino.view.NotificationPopup;
import org.apache.logging.log4j.LogManager;
import processing.app.*; import processing.app.*;
import javax.swing.*; import javax.swing.*;
@ -160,12 +159,14 @@ public class ContributionsSelfCheck extends TimerTask implements NotificationPop
private void goToManager(String link) { private void goToManager(String link) {
try { try {
((UpdatableBoardsLibsFakeURLsHandler) hyperlinkListener).openBoardLibManager(new URL(link)); ((UpdatableBoardsLibsFakeURLsHandler) hyperlinkListener)
} .openBoardLibManager(new URL(link));
catch (Exception e){ } catch (Exception e) {
LogManager.getLogger(ContributionsSelfCheck.class).warn("Exception while attempting to go to board manager", e); System.err.println("Error while attempting to open board manager: "
+ e.getMessage());
} }
} }
// callback for boards button // callback for boards button
public void onOptionalButton1Callback() { public void onOptionalButton1Callback() {
goToManager(boardsManagerURL); goToManager(boardsManagerURL);

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="Arduino" packages="cc.arduino">
<Appenders>
<!-- Console Appender -->
<Console name="Console" target="SYSTEM_ERR">
<PatternLayout pattern="%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}{UTC} %p %c{1.}:%L [%t] %m%n"/>
</Console>
<!-- Rolling File Appender -->
<RollingFile name="RollingFile" fileName="${sys:log4j.dir}/logs/application.log"
filePattern="${sys:log4j.dir}/logs/application-%d{MM-dd-yyyy}-%i.log.gz"
ignoreExceptions="false">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}{UTC} %p %c{1.}:%L [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="50 MB"/>
</Policies>
<DefaultRolloverStrategy max="20"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console" level="info" />
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>

View File

@ -220,12 +220,6 @@ public class Base {
parser.parseArgumentsPhase1(); parser.parseArgumentsPhase1();
commandLine = !parser.isGuiMode(); commandLine = !parser.isGuiMode();
// This configure the logs root folder
if (parser.isGuiMode()) {
System.out.println("Set log4j store directory " + BaseNoGui.getSettingsFolder().getAbsolutePath());
}
System.setProperty("log4j.dir", BaseNoGui.getSettingsFolder().getAbsolutePath());
BaseNoGui.checkInstallationFolder(); BaseNoGui.checkInstallationFolder();
// If no path is set, get the default sketchbook folder for this platform // If no path is set, get the default sketchbook folder for this platform

View File

@ -8,8 +8,6 @@
<classpathentry kind="lib" path="lib/jmdns-3.5.5.jar"/> <classpathentry kind="lib" path="lib/jmdns-3.5.5.jar"/>
<classpathentry kind="lib" path="lib/slf4j-api-1.7.22.jar"/> <classpathentry kind="lib" path="lib/slf4j-api-1.7.22.jar"/>
<classpathentry kind="lib" path="lib/slf4j-simple-1.7.22.jar"/> <classpathentry kind="lib" path="lib/slf4j-simple-1.7.22.jar"/>
<classpathentry kind="lib" path="lib/log4j-api-2.16.0.jar"/>
<classpathentry kind="lib" path="lib/log4j-core-2.16.0.jar"/>
<classpathentry kind="lib" path="lib/jsch-0.1.50.jar"/> <classpathentry kind="lib" path="lib/jsch-0.1.50.jar"/>
<classpathentry kind="lib" path="lib/commons-exec-1.1.jar"/> <classpathentry kind="lib" path="lib/commons-exec-1.1.jar"/>
<classpathentry kind="lib" path="../app/lib/commons-httpclient-3.1.jar"/> <classpathentry kind="lib" path="../app/lib/commons-httpclient-3.1.jar"/>

View File

@ -34,8 +34,6 @@ import cc.arduino.utils.MultiStepProgress;
import cc.arduino.utils.Progress; import cc.arduino.utils.Progress;
import cc.arduino.utils.network.FileDownloader; import cc.arduino.utils.network.FileDownloader;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import processing.app.BaseNoGui; import processing.app.BaseNoGui;
import processing.app.PreferencesData; import processing.app.PreferencesData;
@ -48,8 +46,6 @@ import static processing.app.I18n.format;
import static processing.app.I18n.tr; import static processing.app.I18n.tr;
public class DownloadableContributionsDownloader { public class DownloadableContributionsDownloader {
private static Logger log = LogManager.getLogger(DownloadableContributionsDownloader.class);
private final File stagingFolder; private final File stagingFolder;
public DownloadableContributionsDownloader(File _stagingFolder) { public DownloadableContributionsDownloader(File _stagingFolder) {
@ -151,7 +147,6 @@ public class DownloadableContributionsDownloader {
} }
public void downloadIndexAndSignature(MultiStepProgress progress, URL packageIndexUrl, ProgressListener progressListener, SignatureVerifier signatureVerifier) throws Exception { public void downloadIndexAndSignature(MultiStepProgress progress, URL packageIndexUrl, ProgressListener progressListener, SignatureVerifier signatureVerifier) throws Exception {
// Extract the file name from the url // Extract the file name from the url
final String indexFileName = FilenameUtils.getName(packageIndexUrl.getPath()); final String indexFileName = FilenameUtils.getName(packageIndexUrl.getPath());
final File packageIndex = BaseNoGui.indexer.getIndexFile(indexFileName); final File packageIndex = BaseNoGui.indexer.getIndexFile(indexFileName);
@ -169,16 +164,13 @@ public class DownloadableContributionsDownloader {
if (checkSignature(progress, signatureUrl, progressListener, signatureVerifier, statusText, packageIndexTemp)) { if (checkSignature(progress, signatureUrl, progressListener, signatureVerifier, statusText, packageIndexTemp)) {
Files.move(packageIndexTemp.toPath(), packageIndex.toPath(), StandardCopyOption.REPLACE_EXISTING); Files.move(packageIndexTemp.toPath(), packageIndex.toPath(), StandardCopyOption.REPLACE_EXISTING);
} else { } else {
log.info("The cached files have been removed. {} {}", packageIndexUrl, signatureUrl);
FileDownloader.invalidateFiles(packageIndexUrl, signatureUrl); FileDownloader.invalidateFiles(packageIndexUrl, signatureUrl);
} }
} else { } else {
// Move the package index to the destination when the signature is not necessary // Move the package index to the destination when the signature is not necessary
Files.move(packageIndexTemp.toPath(), packageIndex.toPath(), StandardCopyOption.REPLACE_EXISTING); Files.move(packageIndexTemp.toPath(), packageIndex.toPath(), StandardCopyOption.REPLACE_EXISTING);
log.info("The domain is not selected to verify the signature. will be copied into this path {}, packageIndex url: {}", packageIndex, packageIndexUrl);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Cannot download the package index from {} the package will be discard", packageIndexUrl, e);
throw e; throw e;
} finally { } finally {
// Delete useless temp file // Delete useless temp file
@ -196,49 +188,39 @@ public class DownloadableContributionsDownloader {
if (domain.contains(url.getHost())) { if (domain.contains(url.getHost())) {
return true; return true;
} else { } else {
log.info("The domain is not selected to verify the signature. domain list: {}, url: {}", domain, url);
return false; return false;
} }
} }
public boolean checkSignature(MultiStepProgress progress, URL signatureUrl, ProgressListener progressListener, SignatureVerifier signatureVerifier, String statusText, File fileToVerify) throws Exception { public boolean checkSignature(MultiStepProgress progress, URL signatureUrl, ProgressListener progressListener, SignatureVerifier signatureVerifier, String statusText, File fileToVerify) throws Exception {
// Signature file name // Signature file name
final String signatureFileName = FilenameUtils.getName(signatureUrl.getPath()); final String signatureFileName = FilenameUtils.getName(signatureUrl.getPath());
final File packageIndexSignature = BaseNoGui.indexer.getIndexFile(signatureFileName); final File packageIndexSignature = BaseNoGui.indexer.getIndexFile(signatureFileName);
final File packageIndexSignatureTemp = File.createTempFile(signatureFileName, ".tmp"); final File packageIndexSignatureTemp = File.createTempFile(signatureFileName, ".tmp");
try { try {
// Download signature // Download signature
download(signatureUrl, packageIndexSignatureTemp, progress, statusText, progressListener, true); download(signatureUrl, packageIndexSignatureTemp, progress, statusText, progressListener, true);
if (PreferencesData.areInsecurePackagesAllowed()) { if (PreferencesData.areInsecurePackagesAllowed()) {
Files.move(packageIndexSignatureTemp.toPath(), packageIndexSignature.toPath(), StandardCopyOption.REPLACE_EXISTING); Files.move(packageIndexSignatureTemp.toPath(), packageIndexSignature.toPath(), StandardCopyOption.REPLACE_EXISTING);
log.info("Allowing insecure packages because allow_insecure_packages is set to true in preferences.txt" +
" but the signature was download");
return true; return true;
} }
// Verify the signature before move the files // Verify the signature before move the files
final boolean signatureVerified = signatureVerifier.isSigned(fileToVerify, packageIndexSignatureTemp); final boolean signatureVerified = signatureVerifier.isSigned(fileToVerify, packageIndexSignatureTemp);
if (signatureVerified) { if (signatureVerified) {
log.info("Signature verified. url={}, signature url={}, file to verify={}, signature file={}", signatureUrl, signatureUrl, fileToVerify, packageIndexSignatureTemp);
// Move if the signature is ok // Move if the signature is ok
Files.move(packageIndexSignatureTemp.toPath(), packageIndexSignature.toPath(), StandardCopyOption.REPLACE_EXISTING); Files.move(packageIndexSignatureTemp.toPath(), packageIndexSignature.toPath(), StandardCopyOption.REPLACE_EXISTING);
} else { } else {
log.error("{} file signature verification failed. File ignored.", signatureUrl);
System.err.println(format(tr("{0} file signature verification failed. File ignored."), signatureUrl.toString())); System.err.println(format(tr("{0} file signature verification failed. File ignored."), signatureUrl.toString()));
} }
return signatureVerified; return signatureVerified;
} catch (Exception e) { } catch (Exception e) {
log.error("Cannot download the signature from {} the package will be discard", signatureUrl, e);
throw e; throw e;
} finally { } finally {
Files.deleteIfExists(packageIndexSignatureTemp.toPath()); Files.deleteIfExists(packageIndexSignatureTemp.toPath());
} }
} }
} }

View File

@ -38,8 +38,6 @@ import cc.arduino.utils.ArchiveExtractor;
import cc.arduino.utils.MultiStepProgress; import cc.arduino.utils.MultiStepProgress;
import cc.arduino.utils.network.FileDownloader; import cc.arduino.utils.network.FileDownloader;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import processing.app.BaseNoGui; import processing.app.BaseNoGui;
import processing.app.I18n; import processing.app.I18n;
import processing.app.Platform; import processing.app.Platform;
@ -57,8 +55,6 @@ import java.util.Optional;
import static processing.app.I18n.tr; import static processing.app.I18n.tr;
public class LibraryInstaller { public class LibraryInstaller {
private static Logger log = LogManager.getLogger(LibraryInstaller.class);
private final Platform platform; private final Platform platform;
private final GPGDetachedSignatureVerifier signatureVerifier; private final GPGDetachedSignatureVerifier signatureVerifier;
@ -97,10 +93,7 @@ public class LibraryInstaller {
} }
} else { } else {
FileDownloader.invalidateFiles(libraryGzURL, libraryURL, signatureUrl); FileDownloader.invalidateFiles(libraryGzURL, libraryURL, signatureUrl);
log.error("Fail to verify the signature of {} the cached files have been removed", libraryURL);
} }
} else {
log.info("The domain is not selected to verify the signature. library index: {}", signatureUrl);
} }
// Step 2: Parse index // Step 2: Parse index

View File

@ -41,8 +41,6 @@ import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.Executor; import org.apache.commons.exec.Executor;
import org.apache.commons.exec.PumpStreamHandler; import org.apache.commons.exec.PumpStreamHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import processing.app.BaseNoGui; import processing.app.BaseNoGui;
import processing.app.I18n; import processing.app.I18n;
import processing.app.Platform; import processing.app.Platform;
@ -64,8 +62,6 @@ import static processing.app.I18n.format;
import static processing.app.I18n.tr; import static processing.app.I18n.tr;
public class ContributionInstaller { public class ContributionInstaller {
private static Logger log = LogManager.getLogger(ContributionInstaller.class);
private final Platform platform; private final Platform platform;
private final SignatureVerifier signatureVerifier; private final SignatureVerifier signatureVerifier;
@ -271,8 +267,6 @@ public class ContributionInstaller {
Files.delete(destFolder.getParentFile().toPath()); Files.delete(destFolder.getParentFile().toPath());
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
log.info("The directory is not empty there is another version installed. directory {}",
destFolder.getParentFile().toPath(), e);
} }
} }
@ -298,15 +292,12 @@ public class ContributionInstaller {
// Extract the file name from the URL // Extract the file name from the URL
final URL packageIndexURL = new URL(packageIndexURLString); final URL packageIndexURL = new URL(packageIndexURLString);
log.info("Start download and signature check of={}", packageIndexURLs);
downloader.downloadIndexAndSignature(progress, packageIndexURL, progressListener, signatureVerifier); downloader.downloadIndexAndSignature(progress, packageIndexURL, progressListener, signatureVerifier);
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e);
System.err.println(e.getMessage()); System.err.println(e.getMessage());
} }
} }
progress.stepDone(); progress.stepDone();
log.info("Downloaded package index URL={}", packageIndexURLs);
} }
} }

View File

@ -30,8 +30,6 @@
package cc.arduino.utils.network; package cc.arduino.utils.network;
import org.apache.commons.compress.utils.IOUtils; import org.apache.commons.compress.utils.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import processing.app.helpers.FileUtils; import processing.app.helpers.FileUtils;
import javax.script.ScriptException; import javax.script.ScriptException;
@ -50,8 +48,6 @@ import java.util.Observable;
import java.util.Optional; import java.util.Optional;
public class FileDownloader extends Observable { public class FileDownloader extends Observable {
private static Logger log = LogManager.getLogger(FileDownloader.class);
public enum Status { public enum Status {
CONNECTING, // CONNECTING, //
CONNECTION_TIMEOUT_ERROR, // CONNECTION_TIMEOUT_ERROR, //
@ -146,17 +142,16 @@ public class FileDownloader extends Observable {
try { try {
FileDownloaderCache.getFileCached(url).ifPresent(fileCached -> { FileDownloaderCache.getFileCached(url).ifPresent(fileCached -> {
try { try {
log.info("Invalidate this file {} that comes from {}", fileCached.getLocalPath(), fileCached.getRemoteURL());
fileCached.invalidateCache(); fileCached.invalidateCache();
} catch (Exception e) { } catch (Exception e) {
log.warn("Fail to invalidate cache", e); System.err.println("Error invalidating cached file " + fileCached.getLocalPath() + " that comes from "
+ fileCached.getRemoteURL() + ": " + e.getMessage());
} }
}); });
} catch (URISyntaxException | NoSuchMethodException | ScriptException | IOException e) { } catch (URISyntaxException | NoSuchMethodException | ScriptException | IOException e) {
log.warn("Fail to get the file cached during the file invalidation", e); System.err.println("Fail to get the file cached during the file invalidation" + e.getMessage());
} }
}); });
} }
private void downloadFile(boolean noResume) throws InterruptedException { private void downloadFile(boolean noResume) throws InterruptedException {
@ -171,7 +166,6 @@ public class FileDownloader extends Observable {
final Optional<File> fileFromCache = getFileCached(fileCached); final Optional<File> fileFromCache = getFileCached(fileCached);
if (fileCached.isNotChange() && fileFromCache.isPresent()) { if (fileCached.isNotChange() && fileFromCache.isPresent()) {
// Copy the cached file in the destination file // Copy the cached file in the destination file
log.info("The file will be taken from the cache {}", fileFromCache);
FileUtils.copyFile(fileFromCache.get(), outputFile); FileUtils.copyFile(fileFromCache.get(), outputFile);
} else { } else {
openConnectionAndFillTheFile(noResume); openConnectionAndFillTheFile(noResume);
@ -191,34 +185,23 @@ public class FileDownloader extends Observable {
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
setStatus(Status.CONNECTION_TIMEOUT_ERROR); setStatus(Status.CONNECTION_TIMEOUT_ERROR);
setError(e); setError(e);
log.error("The request went in socket timeout", e);
} catch (Exception e) { } catch (Exception e) {
setStatus(Status.ERROR); setStatus(Status.ERROR);
setError(e); setError(e);
log.error("The request stop", e);
} }
} }
private Optional<File> getFileCached(FileDownloaderCache.FileCached fileCached) { private Optional<File> getFileCached(FileDownloaderCache.FileCached fileCached) {
try { try {
final Optional<File> fileFromCache = final Optional<File> fileFromCache = fileCached.getFileFromCache();
fileCached.getFileFromCache();
if (fileFromCache.isPresent()) { if (fileFromCache.isPresent()) {
log.info("No need to download using cached file: {}", fileCached);
return fileFromCache; return fileFromCache;
} else {
log.info(
"The file in the cache is not in the path or the md5 validation failed: path={}, file exist={}, md5 validation={}",
fileCached.getLocalPath(), fileCached.exists(), fileCached.md5Check());
} }
} catch (Exception e) { } catch (Exception e) {
log.warn( // Cannot get the file from the cache, download a new one
"Cannot get the file from the cache, will be downloaded a new one ", e);
} }
log.info("The file is change {}", fileCached);
return Optional.empty(); return Optional.empty();
} }

View File

@ -38,8 +38,6 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import processing.app.BaseNoGui; import processing.app.BaseNoGui;
import processing.app.PreferencesData; import processing.app.PreferencesData;
import processing.app.helpers.FileUtils; import processing.app.helpers.FileUtils;
@ -64,8 +62,6 @@ import java.util.stream.Collectors;
public class FileDownloaderCache { public class FileDownloaderCache {
private final static String CACHE_ENABLE_PREFERENCE_KEY = "cache.enable"; private final static String CACHE_ENABLE_PREFERENCE_KEY = "cache.enable";
private final static Logger log = LogManager
.getLogger(FileDownloaderCache.class);
private final static Map<String, FileCached> cachedFiles = Collections private final static Map<String, FileCached> cachedFiles = Collections
.synchronizedMap(new HashMap<>()); .synchronizedMap(new HashMap<>());
private final static String cacheFolder; private final static String cacheFolder;
@ -73,9 +69,6 @@ public class FileDownloaderCache {
static { static {
enableCache = Boolean.valueOf(PreferencesData.get(CACHE_ENABLE_PREFERENCE_KEY, "true")); enableCache = Boolean.valueOf(PreferencesData.get(CACHE_ENABLE_PREFERENCE_KEY, "true"));
if (!enableCache) {
log.info("The cache is disable cache.enable=false");
}
PreferencesData.set(CACHE_ENABLE_PREFERENCE_KEY, Boolean.toString(enableCache)); PreferencesData.set(CACHE_ENABLE_PREFERENCE_KEY, Boolean.toString(enableCache));
final File settingsFolder; final File settingsFolder;
@ -86,10 +79,8 @@ public class FileDownloaderCache {
} else { } else {
enableCache = false; enableCache = false;
cacheFolder = null; cacheFolder = null;
log.error("The cache will disable because the setting folder is null, cannot generate the cache path");
} }
final Path pathCacheInfo = getCachedInfoPath(); final Path pathCacheInfo = getCachedInfoPath();
log.info("Cache folder {}", cacheFolder);
try { try {
if (Files.exists(pathCacheInfo)) { if (Files.exists(pathCacheInfo)) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
@ -109,31 +100,26 @@ public class FileDownloaderCache {
.collect(Collectors.toMap(FileCached::getRemoteURL, Function.identity())) .collect(Collectors.toMap(FileCached::getRemoteURL, Function.identity()))
) )
); );
log.info("Number of file already in the cache {}", cachedFiles.size());
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Cannot initialized the cache", e); System.err.println("Cannot initialized the cache: " + e.getMessage());
} }
} }
public static Optional<FileCached> getFileCached(final URL remoteURL) public static Optional<FileCached> getFileCached(final URL remoteURL)
throws URISyntaxException, NoSuchMethodException, ScriptException, throws URISyntaxException, NoSuchMethodException, ScriptException, IOException {
IOException {
return getFileCached(remoteURL, true); return getFileCached(remoteURL, true);
} }
public static Optional<FileCached> getFileCached(final URL remoteURL, boolean enableCache) public static Optional<FileCached> getFileCached(final URL remoteURL, boolean enableCache)
throws URISyntaxException, NoSuchMethodException, ScriptException, throws URISyntaxException, NoSuchMethodException, ScriptException, IOException {
IOException {
// Return always and empty file if the cache is not enable // Return always and empty file if the cache is not enable
if (!(enableCache && FileDownloaderCache.enableCache)) { if (!(enableCache && FileDownloaderCache.enableCache)) {
log.info("The cache is not enable.");
return Optional.empty(); return Optional.empty();
} }
final String[] splitPath = remoteURL.getPath().split("/"); final String[] splitPath = remoteURL.getPath().split("/");
if (splitPath.length == 0) { if (splitPath.length == 0) {
log.warn("The remote path as no file name {}", remoteURL);
return Optional.empty(); return Optional.empty();
} }
// Create the path where the cached file should exist // Create the path where the cached file should exist
@ -146,19 +132,14 @@ public class FileDownloaderCache {
.orElseGet(() -> new FileCached(remoteURL.toString(), cacheFilePath.toString())); .orElseGet(() -> new FileCached(remoteURL.toString(), cacheFilePath.toString()));
// If the file is change of the cache is disable run the HEAD request to check if the file is changed // If the file is change of the cache is disable run the HEAD request to check if the file is changed
log.info("Get file cached is expire {}, exist {}, info {} ", fileCached.isExpire(), fileCached.exists(), fileCached);
if (fileCached.isExpire() || !fileCached.exists()) { if (fileCached.isExpire() || !fileCached.exists()) {
// Update remote etag and cache control header // Update remote etag and cache control header
final Optional<FileCached> fileCachedInfoUpdated = final Optional<FileCached> fileCachedInfoUpdated =
FileDownloaderCache.updateCacheInfo(remoteURL, (remoteETagClean, cacheControl) -> { FileDownloaderCache.updateCacheInfo(remoteURL, (remoteETagClean, cacheControl) -> {
// Check cache control data // Check cache control data
if (cacheControl.isNoCache() || cacheControl.isMustRevalidate() || cacheControl.isNoStore()) { if (cacheControl.isNoCache() || cacheControl.isMustRevalidate() || cacheControl.isNoStore()) {
log.warn("The file {} must not be cache due to cache control header {}",
remoteURL, cacheControl);
return Optional.empty(); return Optional.empty();
} }
log.info("Update cached info of {}, createdAt {}, previous eTag {}, last eTag {}, cache control header {} ",
remoteURL, fileCached.createdAt, fileCached.eTag, remoteETagClean, cacheControl);
final FileCached fileCachedUpdateETag = new FileCached( final FileCached fileCachedUpdateETag = new FileCached(
remoteURL.toString(), remoteURL.toString(),
cacheFilePath.toString(), cacheFilePath.toString(),
@ -180,20 +161,18 @@ public class FileDownloaderCache {
throws URISyntaxException, NoSuchMethodException, ScriptException, throws URISyntaxException, NoSuchMethodException, ScriptException,
IOException { IOException {
// Update the headers of the cached file // Update the headers of the cached file
final HttpURLConnection headRequest = new HttpConnectionManager( final HttpURLConnection headRequest = new HttpConnectionManager(remoteURL).makeConnection((connection) -> {
remoteURL).makeConnection((connection) -> {
try { try {
connection.setRequestMethod("HEAD"); connection.setRequestMethod("HEAD");
} catch (ProtocolException e) { } catch (ProtocolException e) {
log.error("Invalid protocol", e); System.err.println(e.getMessage());
} }
}); });
final int responseCode = headRequest.getResponseCode(); final int responseCode = headRequest.getResponseCode();
headRequest.disconnect(); headRequest.disconnect();
// Something bad is happening return a conservative true to try to download the file // Something bad is happening return a conservative true to try to download the file
if (responseCode < 200 || responseCode >= 300) { if (responseCode < 200 || responseCode >= 300) {
log.warn("The head request return a bad response code " + responseCode); // if something bad happened
// if something bad happend
return Optional.empty(); return Optional.empty();
} }
// Get all the useful headers // Get all the useful headers
@ -204,7 +183,7 @@ public class FileDownloaderCache {
final CacheControl cacheControl = CacheControl.valueOf(cacheControlHeader); final CacheControl cacheControl = CacheControl.valueOf(cacheControlHeader);
return getNewFile.apply(remoteETagClean, cacheControl); return getNewFile.apply(remoteETagClean, cacheControl);
} }
log.warn("The head request do not return the ETag {} or the Cache-Control {}", remoteETag, cacheControlHeader); // the head request do not return the ETag or the Cache-Control
return Optional.empty(); return Optional.empty();
} }
@ -223,7 +202,6 @@ public class FileDownloaderCache {
if (Files.notExists(cachedFileInfo)) { if (Files.notExists(cachedFileInfo)) {
Files.createDirectories(cachedFileInfo.getParent()); Files.createDirectories(cachedFileInfo.getParent());
} }
log.info("Update cache file info in {}, number of cached files is {}", cachedFileInfo.toFile(), cachedFiles.size());
// Write to cache.json // Write to cache.json
mapper.writeValue(cachedFileInfo.toFile(), objectNode); mapper.writeValue(cachedFileInfo.toFile(), objectNode);
} }
@ -287,19 +265,16 @@ public class FileDownloaderCache {
@JsonIgnore @JsonIgnore
public boolean isChange() { public boolean isChange() {
// Check if the file is expire // Check if the file is expire
boolean isChange = false; boolean isChanged = false;
if (isExpire()) { if (isExpire()) {
log.debug("The file \"{}\" is expire. Expire time: {}", localPath, isChanged = true;
this.getExpiresTime().format(DateTimeFormatter.ISO_DATE_TIME));
isChange = true;
} }
if (lastETag != null && !lastETag.equals(eTag)) { if (lastETag != null && !lastETag.equals(eTag)) {
// If are different means that the file is change // Different ETag means that the file is changed
log.debug("The file \"{}\" is changed last ETag != now Etag ({}!={})", localPath, lastETag, eTag); isChanged = true;
isChange = true;
} }
return isChange; return isChanged;
} }
@JsonIgnore @JsonIgnore
@ -327,7 +302,6 @@ public class FileDownloaderCache {
final String md5 = this.calculateMD5(); final String md5 = this.calculateMD5();
final String eTag; final String eTag;
if (lastETag == null) { if (lastETag == null) {
log.warn("The eTag was not calculate this time, is not the right behaviour fileCached={}, md5={}", this, md5);
eTag = this.eTag; eTag = this.eTag;
} else { } else {
eTag = this.lastETag; eTag = this.lastETag;
@ -340,10 +314,8 @@ public class FileDownloaderCache {
md5, md5,
this.cacheControl this.cacheControl
); );
log.info("Update cache file: {}", newFileCached);
cachedFiles.put(remoteURL, newFileCached); cachedFiles.put(remoteURL, newFileCached);
updateCacheFilesInfo(); updateCacheFilesInfo();
} }
public synchronized void invalidateCache() throws IOException { public synchronized void invalidateCache() throws IOException {
@ -363,7 +335,6 @@ public class FileDownloaderCache {
try { try {
return !Objects.isNull(getMD5()) && Objects.equals(calculateMD5(), getMD5()); return !Objects.isNull(getMD5()) && Objects.equals(calculateMD5(), getMD5());
} catch (Exception e) { } catch (Exception e) {
log.error("Fail to calculate the MD5. file={}", this, e);
return false; return false;
} }
} }

View File

@ -31,9 +31,6 @@ package cc.arduino.utils.network;
import cc.arduino.net.CustomProxySelector; import cc.arduino.net.CustomProxySelector;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import processing.app.BaseNoGui; import processing.app.BaseNoGui;
import processing.app.PreferencesData; import processing.app.PreferencesData;
@ -47,7 +44,6 @@ import java.util.UUID;
import java.util.function.Consumer; import java.util.function.Consumer;
public class HttpConnectionManager { public class HttpConnectionManager {
private static Logger log = LogManager.getLogger(HttpConnectionManager.class);
private static final String userAgent; private static final String userAgent;
private static final int connectTimeout; private static final int connectTimeout;
private static final int maxRedirectNumber; private static final int maxRedirectNumber;
@ -69,23 +65,17 @@ public class HttpConnectionManager {
userAgent = PreferencesData.get("http.user_agent", defaultUserAgent); userAgent = PreferencesData.get("http.user_agent", defaultUserAgent);
int connectTimeoutFromConfig = 5000; int connectTimeoutFromConfig = 5000;
try { try {
connectTimeoutFromConfig = connectTimeoutFromConfig = PreferencesData.getInteger("http.connection_timeout_ms", 5000);
Integer.parseInt(
PreferencesData.get("http.connection_timeout_ms", "5000"));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
log.warn( System.err.println("Error parsing http.connection_timeout_ms config: " + e.getMessage());
"Cannot parse the http.connection_timeout configuration switch to default {} milliseconds", connectTimeoutFromConfig, e.getCause());
} }
connectTimeout = connectTimeoutFromConfig; connectTimeout = connectTimeoutFromConfig;
// Set by default 20 max redirect to follow // Set by default 20 max redirect to follow
int maxRedirectNumberConfig = 20; int maxRedirectNumberConfig = 20;
try { try {
maxRedirectNumberConfig = maxRedirectNumberConfig = PreferencesData.getInteger("http.max_redirect_number", 20);
Integer.parseInt(
PreferencesData.get("http.max_redirect_number", "20"));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
log.warn( System.err.println("Error parsing http.max_redirect_number config: " + e.getMessage());
"Cannot parse the http.max_redirect_number configuration switch to default {}", maxRedirectNumberConfig, e.getCause());
} }
maxRedirectNumber = maxRedirectNumberConfig; maxRedirectNumber = maxRedirectNumberConfig;
} }
@ -116,18 +106,13 @@ public class HttpConnectionManager {
private HttpURLConnection makeConnection(URL requestURL, int movedTimes, private HttpURLConnection makeConnection(URL requestURL, int movedTimes,
Consumer<HttpURLConnection> beforeConnection) throws IOException, URISyntaxException, ScriptException, NoSuchMethodException { Consumer<HttpURLConnection> beforeConnection) throws IOException, URISyntaxException, ScriptException, NoSuchMethodException {
if (movedTimes > maxRedirectNumber) { if (movedTimes > maxRedirectNumber) {
log.warn("Too many redirect " + requestURL);
throw new IOException("Too many redirect " + requestURL); throw new IOException("Too many redirect " + requestURL);
} }
Proxy proxy = new CustomProxySelector(PreferencesData.getMap()) Proxy proxy = new CustomProxySelector(PreferencesData.getMap()).getProxyFor(requestURL.toURI());
.getProxyFor(requestURL.toURI());
log.debug("Using proxy {}", proxy);
final String requestId = UUID.randomUUID().toString() final String requestId = UUID.randomUUID().toString().toUpperCase().replace("-", "").substring(0, 16);
.toUpperCase().replace("-", "").substring(0, 16); HttpURLConnection connection = (HttpURLConnection) requestURL.openConnection(proxy);
HttpURLConnection connection = (HttpURLConnection) requestURL
.openConnection(proxy);
// see https://github.com/arduino/Arduino/issues/10264 // see https://github.com/arduino/Arduino/issues/10264
// Workaround for https://bugs.openjdk.java.net/browse/JDK-8163921 // Workaround for https://bugs.openjdk.java.net/browse/JDK-8163921
@ -150,19 +135,11 @@ public class HttpConnectionManager {
beforeConnection.accept(connection); beforeConnection.accept(connection);
// Connect // Connect
log.info("Connect to {}, method={}, request id={}", requestURL, connection.getRequestMethod(), requestId);
connection.connect(); connection.connect();
int resp = connection.getResponseCode(); int resp = connection.getResponseCode();
log.info("Request complete URL=\"{}\", method={}, response code={}, request id={}, headers={}",
requestURL, connection.getRequestMethod(), resp, requestId, StringUtils.join(connection.getHeaderFields()));
if (resp == HttpURLConnection.HTTP_MOVED_PERM
|| resp == HttpURLConnection.HTTP_MOVED_TEMP) {
if (resp == HttpURLConnection.HTTP_MOVED_PERM || resp == HttpURLConnection.HTTP_MOVED_TEMP) {
URL newUrl = new URL(connection.getHeaderField("Location")); URL newUrl = new URL(connection.getHeaderField("Location"));
log.info("The response code was a 301,302 so try again with the new URL " + newUrl);
return this.makeConnection(newUrl, movedTimes + 1, beforeConnection); return this.makeConnection(newUrl, movedTimes + 1, beforeConnection);
} }

View File

@ -52,7 +52,6 @@ import static processing.app.I18n.tr;
* know if name is proper Java package syntax.) * know if name is proper Java package syntax.)
*/ */
public class Platform { public class Platform {
// DO NOT USE log4j here otherwise the root path of the logs will no be initialize correctly
/** /**
* Set the default L & F. While I enjoy the bounty of the sixteen possible * Set the default L & F. While I enjoy the bounty of the sixteen possible
* exception types that this UIManager method might throw, I feel that in * exception types that this UIManager method might throw, I feel that in

View File

@ -32,8 +32,6 @@ package processing.app.helpers;
import cc.arduino.utils.network.HttpConnectionManager; import cc.arduino.utils.network.HttpConnectionManager;
import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import processing.app.BaseNoGui; import processing.app.BaseNoGui;
import processing.app.I18n; import processing.app.I18n;
import processing.app.debug.TargetBoard; import processing.app.debug.TargetBoard;
@ -48,7 +46,6 @@ import java.util.Map;
import static processing.app.I18n.tr; import static processing.app.I18n.tr;
public class BoardCloudResolver { public class BoardCloudResolver {
private static Logger log = LogManager.getLogger(BoardCloudResolver.class);
public synchronized void getBoardBy(String vid, String pid) { public synchronized void getBoardBy(String vid, String pid) {
// this method is less useful in Windows < WIN10 since you need drivers to be already installed // this method is less useful in Windows < WIN10 since you need drivers to be already installed
@ -61,12 +58,10 @@ public class BoardCloudResolver {
.makeConnection(); .makeConnection();
int code = httpConnection.getResponseCode(); int code = httpConnection.getResponseCode();
if (code == 404) { if (code == 404) {
log.warn("Fail to get the Vid Pid information from the builder response code={}", code);
return; return;
} }
InputStream is = httpConnection.getInputStream(); InputStream is = httpConnection.getInputStream();
BoardCloudAPIid board = mapper.readValue(is, BoardCloudAPIid.class); BoardCloudAPIid board = mapper.readValue(is, BoardCloudAPIid.class);
log.info("Board info from the cloud {}", board);
// Launch a popup with a link to boardmanager#board.getName() // Launch a popup with a link to boardmanager#board.getName()
// replace spaces with & // replace spaces with &
String realBoardName = board.getName().replaceAll("\\(.*?\\)", "").trim(); String realBoardName = board.getName().replaceAll("\\(.*?\\)", "").trim();
@ -76,8 +71,6 @@ public class BoardCloudResolver {
} catch (Exception e) { } catch (Exception e) {
// No connection no problem, fail silently // No connection no problem, fail silently
//e.printStackTrace(); //e.printStackTrace();
log.warn("Error during get board information by vid, pid", e);
} }
} }

View File

@ -43,8 +43,6 @@
<cp>%EXEDIR%/lib/java-semver-0.8.0.jar</cp> <cp>%EXEDIR%/lib/java-semver-0.8.0.jar</cp>
<cp>%EXEDIR%/lib/jmdns-3.5.5.jar</cp> <cp>%EXEDIR%/lib/jmdns-3.5.5.jar</cp>
<cp>%EXEDIR%/lib/jtouchbar-1.0.0.jar</cp> <cp>%EXEDIR%/lib/jtouchbar-1.0.0.jar</cp>
<cp>%EXEDIR%/lib/log4j-api-2.16.0.jar</cp>
<cp>%EXEDIR%/lib/log4j-core-2.16.0.jar</cp>
<cp>%EXEDIR%/lib/slf4j-simple-1.7.22.jar</cp> <cp>%EXEDIR%/lib/slf4j-simple-1.7.22.jar</cp>
<cp>%EXEDIR%/lib/slf4j-api-1.7.22.jar</cp> <cp>%EXEDIR%/lib/slf4j-api-1.7.22.jar</cp>
<cp>%EXEDIR%/lib/jna-4.2.2.jar</cp> <cp>%EXEDIR%/lib/jna-4.2.2.jar</cp>

View File

@ -43,8 +43,6 @@
<cp>%EXEDIR%/lib/java-semver-0.8.0.jar</cp> <cp>%EXEDIR%/lib/java-semver-0.8.0.jar</cp>
<cp>%EXEDIR%/lib/jmdns-3.5.5.jar</cp> <cp>%EXEDIR%/lib/jmdns-3.5.5.jar</cp>
<cp>%EXEDIR%/lib/jtouchbar-1.0.0.jar</cp> <cp>%EXEDIR%/lib/jtouchbar-1.0.0.jar</cp>
<cp>%EXEDIR%/lib/log4j-api-2.16.0.jar</cp>
<cp>%EXEDIR%/lib/log4j-core-2.16.0.jar</cp>
<cp>%EXEDIR%/lib/slf4j-simple-1.7.22.jar</cp> <cp>%EXEDIR%/lib/slf4j-simple-1.7.22.jar</cp>
<cp>%EXEDIR%/lib/slf4j-api-1.7.22.jar</cp> <cp>%EXEDIR%/lib/slf4j-api-1.7.22.jar</cp>
<cp>%EXEDIR%/lib/jna-4.2.2.jar</cp> <cp>%EXEDIR%/lib/jna-4.2.2.jar</cp>