diff --git a/.gitignore b/.gitignore index af0bdd5..6298a9f 100644 --- a/.gitignore +++ b/.gitignore @@ -21,8 +21,8 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* -/swarmit/nbproject/private/ -/swarmit/build/ -/swarmit/release/modules +/polyswarm/nbproject/private/ +/polyswarm/nbproject/private/ +/polyswarm/build/ .idea/ diff --git a/swarmit/build.xml b/polyswarm/build.xml similarity index 79% rename from swarmit/build.xml rename to polyswarm/build.xml index b68c6b4..a86217c 100644 --- a/swarmit/build.xml +++ b/polyswarm/build.xml @@ -1,8 +1,8 @@ - - - - - - Builds, tests, and runs the project io.polyswarm.swarmit. - - + + + + + + Builds, tests, and runs the project io.polyswarm.app. + + diff --git a/swarmit/license-polyswarm.txt b/polyswarm/license-polyswarm.txt similarity index 100% rename from swarmit/license-polyswarm.txt rename to polyswarm/license-polyswarm.txt diff --git a/polyswarm/manifest.mf b/polyswarm/manifest.mf new file mode 100644 index 0000000..950a8f1 --- /dev/null +++ b/polyswarm/manifest.mf @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +AutoUpdate-Show-In-Client: true +OpenIDE-Module: io.polyswarm.app +OpenIDE-Module-Localizing-Bundle: io/polyswarm/app/Bundle.properties +OpenIDE-Module-Specification-Version: 2.1.0 diff --git a/swarmit/nbproject/build-impl.xml b/polyswarm/nbproject/build-impl.xml similarity index 95% rename from swarmit/nbproject/build-impl.xml rename to polyswarm/nbproject/build-impl.xml index ac5f640..54c6cd4 100644 --- a/swarmit/nbproject/build-impl.xml +++ b/polyswarm/nbproject/build-impl.xml @@ -1,42 +1,42 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/swarmit/nbproject/genfiles.properties b/polyswarm/nbproject/genfiles.properties similarity index 98% rename from swarmit/nbproject/genfiles.properties rename to polyswarm/nbproject/genfiles.properties index 161dc66..542ad7b 100644 --- a/swarmit/nbproject/genfiles.properties +++ b/polyswarm/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=a5e198ae -build.xml.script.CRC32=4a22439a -build.xml.stylesheet.CRC32=15ca8a54@2.74.1 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=a5e198ae -nbproject/build-impl.xml.script.CRC32=573e5ded -nbproject/build-impl.xml.stylesheet.CRC32=49aa68b0@2.74.1 +build.xml.data.CRC32=a5e198ae +build.xml.script.CRC32=4a22439a +build.xml.stylesheet.CRC32=15ca8a54@2.74.1 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=a5e198ae +nbproject/build-impl.xml.script.CRC32=573e5ded +nbproject/build-impl.xml.stylesheet.CRC32=49aa68b0@2.74.1 diff --git a/swarmit/nbproject/platform.properties b/polyswarm/nbproject/platform.properties similarity index 96% rename from swarmit/nbproject/platform.properties rename to polyswarm/nbproject/platform.properties index cd28279..14c90ba 100644 --- a/swarmit/nbproject/platform.properties +++ b/polyswarm/nbproject/platform.properties @@ -1,7 +1,7 @@ -cluster.path=\ - ${nbplatform.active.dir}/autopsy:\ - ${nbplatform.active.dir}/harness:\ - ${nbplatform.active.dir}/java:\ - ${nbplatform.active.dir}/platform -nbjdk.active=JDK_1.8 -nbplatform.active=Autopsy_4.15.0 +cluster.path=\ + ${nbplatform.active.dir}/autopsy:\ + ${nbplatform.active.dir}/harness:\ + ${nbplatform.active.dir}/java:\ + ${nbplatform.active.dir}/platform +nbjdk.active=JDK_1.8 +nbplatform.active=Autopsy_4.15.0 diff --git a/swarmit/nbproject/project.properties b/polyswarm/nbproject/project.properties similarity index 98% rename from swarmit/nbproject/project.properties rename to polyswarm/nbproject/project.properties index 1d997bc..78bd89c 100644 --- a/swarmit/nbproject/project.properties +++ b/polyswarm/nbproject/project.properties @@ -1,18 +1,18 @@ -auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml -file.reference.commons-codec-1.10.jar=release/modules/ext/commons-codec-1.10.jar -file.reference.commons-dbcp2-2.1.1.jar=release/modules/ext/commons-dbcp2-2.1.1.jar -file.reference.commons-logging-1.2.jar=release/modules/ext/commons-logging-1.2.jar -file.reference.commons-pool2-2.6.0.jar=release/modules/ext/commons-pool2-2.6.0.jar -file.reference.guava-26.0-jre.jar=release/modules/ext/guava-26.0-jre.jar -file.reference.httpclient-4.5.6.jar=release/modules/ext/httpclient-4.5.6.jar -file.reference.httpcore-4.4.10.jar=release/modules/ext/httpcore-4.4.10.jar -file.reference.httpmime-4.5.6.jar=release/modules/ext/httpmime-4.5.6.jar -file.reference.json-20180813.jar=release/modules/ext/json-20180813.jar -file.reference.sqlite-jdbc-3.25.2.jar=release/modules/ext/sqlite-jdbc-3.25.2.jar -javac.source=1.8 -javac.compilerargs=-Xlint -Xlint:-serial -license.file=../LICENSE -project.license=polyswarm -nbm.homepage=https://polyswarm.io -nbm.module.author=PolySwarm Dev Team -nbm.needs.restart=true +auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml +file.reference.commons-codec-1.10.jar=release/modules/ext/commons-codec-1.10.jar +file.reference.commons-dbcp2-2.1.1.jar=release/modules/ext/commons-dbcp2-2.1.1.jar +file.reference.commons-logging-1.2.jar=release/modules/ext/commons-logging-1.2.jar +file.reference.commons-pool2-2.6.0.jar=release/modules/ext/commons-pool2-2.6.0.jar +file.reference.guava-26.0-jre.jar=release/modules/ext/guava-26.0-jre.jar +file.reference.httpclient-4.5.6.jar=release/modules/ext/httpclient-4.5.6.jar +file.reference.httpcore-4.4.10.jar=release/modules/ext/httpcore-4.4.10.jar +file.reference.httpmime-4.5.6.jar=release/modules/ext/httpmime-4.5.6.jar +file.reference.json-20180813.jar=release/modules/ext/json-20180813.jar +file.reference.sqlite-jdbc-3.25.2.jar=release/modules/ext/sqlite-jdbc-3.25.2.jar +javac.source=1.8 +javac.compilerargs=-Xlint -Xlint:-serial +license.file=../LICENSE +project.license=polyswarm +nbm.homepage=https://polyswarm.io +nbm.module.author=PolySwarm Dev Team +nbm.needs.restart=true diff --git a/swarmit/nbproject/project.xml b/polyswarm/nbproject/project.xml similarity index 97% rename from swarmit/nbproject/project.xml rename to polyswarm/nbproject/project.xml index 4c8fb5d..36c4646 100644 --- a/swarmit/nbproject/project.xml +++ b/polyswarm/nbproject/project.xml @@ -1,136 +1,136 @@ - - - org.netbeans.modules.apisupport.project - - - io.polyswarm.swarmit - - - - org.netbeans.api.progress - - - - 1 - 1.47.1 - - - - org.netbeans.modules.options.api - - - - 1 - 1.45.1 - - - - org.openide.awt - - - - 7.67.1 - - - - org.openide.modules - - - - 7.48.1 - - - - org.openide.nodes - - - - 7.45.1 - - - - org.openide.util - - - - 9.7.1 - - - - org.openide.util.lookup - - - - 8.33.1 - - - - org.openide.util.ui - - - - 9.6.1 - - - - org.openide.windows - - - - 6.75.1 - - - - org.sleuthkit.autopsy.core - - - - 10 - 10.12.24 - - - - - - ext/commons-dbcp2-2.1.1.jar - release/modules/ext/commons-dbcp2-2.1.1.jar - - - ext/httpmime-4.5.6.jar - release/modules/ext/httpmime-4.5.6.jar - - - ext/httpclient-4.5.6.jar - release/modules/ext/httpclient-4.5.6.jar - - - ext/sqlite-jdbc-3.25.2.jar - release/modules/ext/sqlite-jdbc-3.25.2.jar - - - ext/commons-pool2-2.6.0.jar - release/modules/ext/commons-pool2-2.6.0.jar - - - ext/commons-logging-1.2.jar - release/modules/ext/commons-logging-1.2.jar - - - ext/json-20180813.jar - release/modules/ext/json-20180813.jar - - - ext/commons-codec-1.10.jar - release/modules/ext/commons-codec-1.10.jar - - - ext/httpcore-4.4.10.jar - release/modules/ext/httpcore-4.4.10.jar - - - ext/guava-26.0-jre.jar - release/modules/ext/guava-26.0-jre.jar - - - - + + + org.netbeans.modules.apisupport.project + + + io.polyswarm.app + + + + org.netbeans.api.progress + + + + 1 + 1.47.1 + + + + org.netbeans.modules.options.api + + + + 1 + 1.45.1 + + + + org.openide.awt + + + + 7.67.1 + + + + org.openide.modules + + + + 7.48.1 + + + + org.openide.nodes + + + + 7.45.1 + + + + org.openide.util + + + + 9.7.1 + + + + org.openide.util.lookup + + + + 8.33.1 + + + + org.openide.util.ui + + + + 9.6.1 + + + + org.openide.windows + + + + 6.75.1 + + + + org.sleuthkit.autopsy.core + + + + 10 + 10.12.24 + + + + + + ext/commons-dbcp2-2.1.1.jar + release/modules/ext/commons-dbcp2-2.1.1.jar + + + ext/httpmime-4.5.6.jar + release/modules/ext/httpmime-4.5.6.jar + + + ext/httpclient-4.5.6.jar + release/modules/ext/httpclient-4.5.6.jar + + + ext/sqlite-jdbc-3.25.2.jar + release/modules/ext/sqlite-jdbc-3.25.2.jar + + + ext/commons-pool2-2.6.0.jar + release/modules/ext/commons-pool2-2.6.0.jar + + + ext/commons-logging-1.2.jar + release/modules/ext/commons-logging-1.2.jar + + + ext/json-20180813.jar + release/modules/ext/json-20180813.jar + + + ext/commons-codec-1.10.jar + release/modules/ext/commons-codec-1.10.jar + + + ext/httpcore-4.4.10.jar + release/modules/ext/httpcore-4.4.10.jar + + + ext/guava-26.0-jre.jar + release/modules/ext/guava-26.0-jre.jar + + + + diff --git a/swarmit/release/modules/ext/commons-codec-1.10.jar b/polyswarm/release/modules/ext/commons-codec-1.10.jar similarity index 100% rename from swarmit/release/modules/ext/commons-codec-1.10.jar rename to polyswarm/release/modules/ext/commons-codec-1.10.jar diff --git a/swarmit/release/modules/ext/commons-dbcp2-2.1.1.jar b/polyswarm/release/modules/ext/commons-dbcp2-2.1.1.jar similarity index 100% rename from swarmit/release/modules/ext/commons-dbcp2-2.1.1.jar rename to polyswarm/release/modules/ext/commons-dbcp2-2.1.1.jar diff --git a/swarmit/release/modules/ext/commons-logging-1.2.jar b/polyswarm/release/modules/ext/commons-logging-1.2.jar similarity index 100% rename from swarmit/release/modules/ext/commons-logging-1.2.jar rename to polyswarm/release/modules/ext/commons-logging-1.2.jar diff --git a/swarmit/release/modules/ext/commons-pool2-2.6.0.jar b/polyswarm/release/modules/ext/commons-pool2-2.6.0.jar similarity index 100% rename from swarmit/release/modules/ext/commons-pool2-2.6.0.jar rename to polyswarm/release/modules/ext/commons-pool2-2.6.0.jar diff --git a/swarmit/thirdparty/httpcomponents-client-4.5.6/lib/fluent-hc-4.5.6.jar b/polyswarm/release/modules/ext/fluent-hc-4.5.6.jar similarity index 100% rename from swarmit/thirdparty/httpcomponents-client-4.5.6/lib/fluent-hc-4.5.6.jar rename to polyswarm/release/modules/ext/fluent-hc-4.5.6.jar diff --git a/swarmit/release/modules/ext/guava-26.0-jre.jar b/polyswarm/release/modules/ext/guava-26.0-jre.jar similarity index 100% rename from swarmit/release/modules/ext/guava-26.0-jre.jar rename to polyswarm/release/modules/ext/guava-26.0-jre.jar diff --git a/swarmit/release/modules/ext/httpclient-4.5.6.jar b/polyswarm/release/modules/ext/httpclient-4.5.6.jar similarity index 100% rename from swarmit/release/modules/ext/httpclient-4.5.6.jar rename to polyswarm/release/modules/ext/httpclient-4.5.6.jar diff --git a/swarmit/thirdparty/httpcomponents-client-4.5.6/lib/httpclient-cache-4.5.6.jar b/polyswarm/release/modules/ext/httpclient-cache-4.5.6.jar similarity index 100% rename from swarmit/thirdparty/httpcomponents-client-4.5.6/lib/httpclient-cache-4.5.6.jar rename to polyswarm/release/modules/ext/httpclient-cache-4.5.6.jar diff --git a/swarmit/thirdparty/httpcomponents-client-4.5.6/lib/httpclient-win-4.5.6.jar b/polyswarm/release/modules/ext/httpclient-win-4.5.6.jar similarity index 100% rename from swarmit/thirdparty/httpcomponents-client-4.5.6/lib/httpclient-win-4.5.6.jar rename to polyswarm/release/modules/ext/httpclient-win-4.5.6.jar diff --git a/swarmit/release/modules/ext/httpcore-4.4.10.jar b/polyswarm/release/modules/ext/httpcore-4.4.10.jar similarity index 100% rename from swarmit/release/modules/ext/httpcore-4.4.10.jar rename to polyswarm/release/modules/ext/httpcore-4.4.10.jar diff --git a/swarmit/release/modules/ext/httpmime-4.5.6.jar b/polyswarm/release/modules/ext/httpmime-4.5.6.jar similarity index 100% rename from swarmit/release/modules/ext/httpmime-4.5.6.jar rename to polyswarm/release/modules/ext/httpmime-4.5.6.jar diff --git a/swarmit/thirdparty/httpcomponents-client-4.5.6/lib/jna-4.4.0.jar b/polyswarm/release/modules/ext/jna-4.4.0.jar similarity index 100% rename from swarmit/thirdparty/httpcomponents-client-4.5.6/lib/jna-4.4.0.jar rename to polyswarm/release/modules/ext/jna-4.4.0.jar diff --git a/swarmit/thirdparty/httpcomponents-client-4.5.6/lib/jna-platform-4.4.0.jar b/polyswarm/release/modules/ext/jna-platform-4.4.0.jar similarity index 100% rename from swarmit/thirdparty/httpcomponents-client-4.5.6/lib/jna-platform-4.4.0.jar rename to polyswarm/release/modules/ext/jna-platform-4.4.0.jar diff --git a/swarmit/release/modules/ext/json-20180813.jar b/polyswarm/release/modules/ext/json-20180813.jar similarity index 100% rename from swarmit/release/modules/ext/json-20180813.jar rename to polyswarm/release/modules/ext/json-20180813.jar diff --git a/swarmit/release/modules/ext/sqlite-jdbc-3.25.2.jar b/polyswarm/release/modules/ext/sqlite-jdbc-3.25.2.jar similarity index 100% rename from swarmit/release/modules/ext/sqlite-jdbc-3.25.2.jar rename to polyswarm/release/modules/ext/sqlite-jdbc-3.25.2.jar diff --git a/swarmit/src/io/polyswarm/swarmit/Bundle.properties b/polyswarm/src/io/polyswarm/app/Bundle.properties similarity index 74% rename from swarmit/src/io/polyswarm/swarmit/Bundle.properties rename to polyswarm/src/io/polyswarm/app/Bundle.properties index be78d89..9c07b3f 100644 --- a/swarmit/src/io/polyswarm/swarmit/Bundle.properties +++ b/polyswarm/src/io/polyswarm/app/Bundle.properties @@ -1,2 +1,2 @@ -OpenIDE-Module-Name=SwarmIt -OpenIDE-Module-Short-Description=Plugin to submit artifacts to the PolySwarm marketplace +OpenIDE-Module-Name=PolySwarm +OpenIDE-Module-Short-Description=Plugin to submit artifacts to the PolySwarm marketplace diff --git a/swarmit/src/io/polyswarm/swarmit/OnStart.java b/polyswarm/src/io/polyswarm/app/OnStart.java similarity index 80% rename from swarmit/src/io/polyswarm/swarmit/OnStart.java rename to polyswarm/src/io/polyswarm/app/OnStart.java index bb1ae45..3a61154 100644 --- a/swarmit/src/io/polyswarm/swarmit/OnStart.java +++ b/polyswarm/src/io/polyswarm/app/OnStart.java @@ -1,40 +1,38 @@ -/* - * The MIT License - * - * Copyright 2018 PolySwarm PTE. LTD. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.polyswarm.swarmit; - -/** - * Start the background thread to process SwarmIt requests - * and store results as artifacts - * - * The org.openide.modulesOnStart annotation tells NetBeans to - * invoke this class's run method. - */ -@org.openide.modules.OnStart -public class OnStart implements Runnable { - - @Override - public void run() { - SwarmItModule.onStart(); - } -} +/* + * The MIT License + * + * Copyright 2018 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app; + +/** + * Start the background thread to process PolySwarm requests and store results as artifacts + * + * The org.openide.modulesOnStart annotation tells NetBeans to invoke this class's run method. + */ +@org.openide.modules.OnStart +public class OnStart implements Runnable { + + @Override + public void run() { + PolySwarmModule.onStart(); + } +} diff --git a/swarmit/src/io/polyswarm/swarmit/SwarmItController.java b/polyswarm/src/io/polyswarm/app/PolySwarmController.java similarity index 57% rename from swarmit/src/io/polyswarm/swarmit/SwarmItController.java rename to polyswarm/src/io/polyswarm/app/PolySwarmController.java index 539450b..3d360e9 100644 --- a/swarmit/src/io/polyswarm/swarmit/SwarmItController.java +++ b/polyswarm/src/io/polyswarm/app/PolySwarmController.java @@ -1,159 +1,192 @@ -/* - * The MIT License - * - * Copyright 2018 PolySwarm PTE. LTD. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.polyswarm.swarmit; - -import com.google.common.util.concurrent.ListeningScheduledExecutorService; -import com.google.common.util.concurrent.MoreExecutors; -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import io.polyswarm.swarmit.datamodel.SwarmItDb; -import io.polyswarm.swarmit.datamodel.SwarmItDbException; -import io.polyswarm.swarmit.optionspanel.SwarmItMarketplaceSettings; -import io.polyswarm.swarmit.tasks.ProcessPendingTask; -import java.util.Objects; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.datamodel.BlackboardAttribute; -import org.sleuthkit.datamodel.BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE; -import org.sleuthkit.datamodel.TskCoreException; -import org.sleuthkit.datamodel.TskDataException; - -/** - * Thread that runs in the background to process AbstractFiles that have - * been submitted using SwarmIt right-click menu option. - * - * AbstractFile ID and PolySwarm UUID are kept in sqlite db. - * - * This process will periodically check the sqlite db for new entries. - * For each entry, this process will contact the PolySwarm API - * to get the analysis results. - * It will then add a PolySwarm Results artifact to the AbstractFile. - * These artifacts will be displayed in the left pane in a sub-tree - * called "PolySwarm Results." - * - */ -public class SwarmItController { - private static final Logger LOGGER = Logger.getLogger(SwarmItController.class.getName()); - - private final Case autopsyCase; - private final SwarmItMarketplaceSettings apiSettings; - private final SwarmItDb dbInstance; - private ListeningScheduledExecutorService dbExecutor; - public static final String POLYSWARM_ARTIFACT_TYPE_NAME = "POLYSWARM_RESULTS"; - public static final String POLYSWARM_ARTIFACT_TYPE_DISPLAY_NAME = "PolySwarm Results"; - - public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_MALICIOUS_DETECTIONS_NAME = "POLYSWARM_MALICIOUS_DETECTIONS"; - public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_MALICIOUS_DETECTIONS_DISPLAY = "Malicious Detections"; - public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_BENIGN_DETECTIONS_NAME = "POLYSWARM_BENIGN_DETECTIONS"; - public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_BENIGN_DETECTIONS_DISPLAY = "Benign Detections"; - public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_TOTAL_DETECTIONS_NAME = "POLYSWARM_TOTAL_DETECTIONS"; - public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_TOTAL_DETECTIONS_DISPLAY = "Total Detections"; - public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_MALWARE_FAMILY_NAME = "POLYSWARM_MALWARE_FAMILY"; - public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_MALWARE_FAMILY_DISPLAY = "Malware Family"; - public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_POLYSCORE_NAME = "POLYSWARM_POLYSCORE_STRING"; - public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_POLYSCORE_DISPLAY = "PolyScore\u2122"; - public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_TAG_NAME = "POLYSWARM_TAG"; - public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_TAG_DISPLAY = "Tag"; - - public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_ASSERTION_NAME_FORMAT = "POLYSWARM_%s"; - - public Case getAutopsyCase() { - return autopsyCase; - } - - SwarmItController(Case newCase) throws TskCoreException, SwarmItDbException { - this.autopsyCase = Objects.requireNonNull(newCase); - this.apiSettings = new SwarmItMarketplaceSettings(); - this.dbInstance = SwarmItDb.getInstance(); - - dbExecutor = getNewDBExecutor(); - createCustomArtifactType(this.autopsyCase, POLYSWARM_ARTIFACT_TYPE_NAME, POLYSWARM_ARTIFACT_TYPE_DISPLAY_NAME); - createCustomArtifactAttributes(this.autopsyCase); - dbExecutor.scheduleAtFixedRate(new ProcessPendingTask(this.dbInstance, this.autopsyCase), 0, 2, TimeUnit.SECONDS); - } - - /** - * Create the POLYSWARM_VERDICT custom artifact type and add it to the blackboard. - * - * @param autopsyCase Open Case - */ - private static void createCustomArtifactType(Case autopsyCase, String name, String display) { - try { - if (autopsyCase.getSleuthkitCase().getArtifactType(name) == null) { - LOGGER.log(Level.INFO, "Adding POLYSWARM_VERDICT custom artifact type"); - autopsyCase.getSleuthkitCase().addBlackboardArtifactType(name, display); - } - } catch (TskCoreException | TskDataException ex) { - LOGGER.log(Level.SEVERE, "Failed to create POLYSWARM_VERDICT custom artifact type", ex); - } - } - - private static void createCustomArtifactAttributes(Case autopsyCase) { - createCustomArtifactAttribute(autopsyCase, POLYSWARM_ARTIFACT_ATTRIBUTE_MALICIOUS_DETECTIONS_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.INTEGER, POLYSWARM_ARTIFACT_ATTRIBUTE_MALICIOUS_DETECTIONS_DISPLAY); - createCustomArtifactAttribute(autopsyCase, POLYSWARM_ARTIFACT_ATTRIBUTE_BENIGN_DETECTIONS_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.INTEGER, POLYSWARM_ARTIFACT_ATTRIBUTE_BENIGN_DETECTIONS_DISPLAY); - createCustomArtifactAttribute(autopsyCase, POLYSWARM_ARTIFACT_ATTRIBUTE_TOTAL_DETECTIONS_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.INTEGER, POLYSWARM_ARTIFACT_ATTRIBUTE_TOTAL_DETECTIONS_DISPLAY); - createCustomArtifactAttribute(autopsyCase, POLYSWARM_ARTIFACT_ATTRIBUTE_POLYSCORE_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING, POLYSWARM_ARTIFACT_ATTRIBUTE_POLYSCORE_DISPLAY); - createCustomArtifactAttribute(autopsyCase, POLYSWARM_ARTIFACT_ATTRIBUTE_MALWARE_FAMILY_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING, POLYSWARM_ARTIFACT_ATTRIBUTE_MALWARE_FAMILY_DISPLAY); - createCustomArtifactAttribute(autopsyCase, POLYSWARM_ARTIFACT_ATTRIBUTE_TAG_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING, POLYSWARM_ARTIFACT_ATTRIBUTE_TAG_DISPLAY); - } - - public static void createCustomArtifactAttribute(Case autopsyCase, String name, TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE valueType, String display) { - try { - if (autopsyCase.getSleuthkitCase().getAttributeType(name) == null) { - autopsyCase.getSleuthkitCase().addArtifactAttributeType(name, valueType, display); - } - } catch (TskCoreException | TskDataException ex) { - LOGGER.log(Level.SEVERE, "Failed to create custom artifact attribute type", ex); - } - } - - public void reset() { - try { - // close all connections to the REST API and db. - dbInstance.shutdownConnections(); - shutDownDBExecutor(); - dbExecutor = getNewDBExecutor(); - } catch (SwarmItDbException ex) { - LOGGER.log(Level.SEVERE, "Failed to shutdown database connections.", ex); // NON-NLS - } - } - - synchronized private void shutDownDBExecutor() { - if (dbExecutor != null) { - dbExecutor.shutdownNow(); - try { - dbExecutor.awaitTermination(30, TimeUnit.SECONDS); - } catch (InterruptedException ex) { - LOGGER.log(Level.WARNING, "SwarmIt failed to shutdown DB Task Executor in a timely fashion.", ex); - } - } - } - - private static ListeningScheduledExecutorService getNewDBExecutor() { - return MoreExecutors.listeningDecorator(Executors.newSingleThreadScheduledExecutor( - new ThreadFactoryBuilder().setNameFormat("SwarmIt-DB-Worker-Thread-%d").build())); - } -} +/* + * The MIT License + * + * Copyright 2018 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app; + +import com.google.common.util.concurrent.ListeningScheduledExecutorService; +import com.google.common.util.concurrent.MoreExecutors; +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import io.polyswarm.app.datamodel.PolySwarmDb; +import io.polyswarm.app.datamodel.PolySwarmDbException; +import io.polyswarm.app.optionspanel.PolySwarmMarketplaceSettings; +import io.polyswarm.app.tasks.ProcessPendingTask; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.netbeans.api.progress.ProgressHandle; +import org.openide.util.NbBundle; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.datamodel.AbstractFile; +import org.sleuthkit.datamodel.BlackboardArtifact; +import org.sleuthkit.datamodel.BlackboardAttribute; +import org.sleuthkit.datamodel.BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE; +import org.sleuthkit.datamodel.TskCoreException; +import org.sleuthkit.datamodel.TskDataException; + +/** + * Thread that runs in the background to process AbstractFiles that have been submitted using PolySwarm right-click menu + * option. + * + * AbstractFile ID and PolySwarm UUID are kept in sqlite db. + * + * This process will periodically check the sqlite db for new entries. For each entry, this process will contact the + * PolySwarm API to get the analysis results. It will then add a PolySwarm Results artifact to the AbstractFile. These + * artifacts will be displayed in the left pane in a sub-tree called "PolySwarm Results." + * + */ +public class PolySwarmController { + + private static final Logger LOGGER = Logger.getLogger(PolySwarmController.class.getName()); + + private final Case autopsyCase; + private final PolySwarmMarketplaceSettings apiSettings; + private final PolySwarmDb dbInstance; + public ProgressHandle progressHandle; + private ListeningScheduledExecutorService dbExecutor; + public static final String POLYSWARM_ARTIFACT_TYPE_NAME = "POLYSWARM_RESULTS"; + public static final String POLYSWARM_ARTIFACT_TYPE_DISPLAY_NAME = "PolySwarm Results"; + + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_MALICIOUS_DETECTIONS_NAME = "POLYSWARM_MALICIOUS_DETECTIONS"; + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_MALICIOUS_DETECTIONS_DISPLAY = "Malicious Detections"; + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_BENIGN_DETECTIONS_NAME = "POLYSWARM_BENIGN_DETECTIONS"; + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_BENIGN_DETECTIONS_DISPLAY = "Benign Detections"; + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_TOTAL_DETECTIONS_NAME = "POLYSWARM_TOTAL_DETECTIONS"; + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_TOTAL_DETECTIONS_DISPLAY = "Total Detections"; + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_MALWARE_FAMILY_NAME = "POLYSWARM_MALWARE_FAMILY"; + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_MALWARE_FAMILY_DISPLAY = "Malware Family"; + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_POLYSCORE_NAME = "POLYSWARM_POLYSCORE_STRING"; + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_POLYSCORE_DISPLAY = "PolyScore\u2122"; + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_TAG_NAME = "POLYSWARM_TAG"; + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_TAG_DISPLAY = "Tag"; + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_FIRST_SEEN_NAME = "POLYSWARM_FIRST_SEEN"; + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_FIRST_SEEN_DISPLAY = "First Seen"; + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_LAST_SCANNED_NAME = "POLYSWARM_LAST_SCANNED"; + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_LAST_SCANNED_DISPLAY = "Last Scanned"; + + public static final String POLYSWARM_ARTIFACT_ATTRIBUTE_ASSERTION_NAME_FORMAT = "POLYSWARM_%s"; + + public Case getAutopsyCase() { + return autopsyCase; + } + + PolySwarmController(Case newCase) throws TskCoreException, PolySwarmDbException { + this.autopsyCase = Objects.requireNonNull(newCase); + this.apiSettings = new PolySwarmMarketplaceSettings(); + this.dbInstance = PolySwarmDb.getInstance(); + + dbExecutor = getNewDBExecutor(); + createCustomArtifactType(this.autopsyCase, POLYSWARM_ARTIFACT_TYPE_NAME, POLYSWARM_ARTIFACT_TYPE_DISPLAY_NAME); + createCustomArtifactAttributes(this.autopsyCase); + dbExecutor.scheduleAtFixedRate(new ProcessPendingTask(this.dbInstance, this.autopsyCase), 0, 2, TimeUnit.SECONDS); + } + + /** + * Create the POLYSWARM_VERDICT custom artifact type and add it to the blackboard. + * + * @param autopsyCase Open Case + */ + private static void createCustomArtifactType(Case autopsyCase, String name, String display) { + try { + if (autopsyCase.getSleuthkitCase().getArtifactType(name) == null) { + LOGGER.log(Level.INFO, "Adding POLYSWARM_VERDICT custom artifact type"); + autopsyCase.getSleuthkitCase().addBlackboardArtifactType(name, display); + } + } catch (TskCoreException | TskDataException ex) { + LOGGER.log(Level.SEVERE, "Failed to create POLYSWARM_VERDICT custom artifact type", ex); + } + } + + private static void createCustomArtifactAttributes(Case autopsyCase) { + createCustomArtifactAttribute(autopsyCase, POLYSWARM_ARTIFACT_ATTRIBUTE_MALICIOUS_DETECTIONS_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.INTEGER, POLYSWARM_ARTIFACT_ATTRIBUTE_MALICIOUS_DETECTIONS_DISPLAY); + createCustomArtifactAttribute(autopsyCase, POLYSWARM_ARTIFACT_ATTRIBUTE_BENIGN_DETECTIONS_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.INTEGER, POLYSWARM_ARTIFACT_ATTRIBUTE_BENIGN_DETECTIONS_DISPLAY); + createCustomArtifactAttribute(autopsyCase, POLYSWARM_ARTIFACT_ATTRIBUTE_TOTAL_DETECTIONS_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.INTEGER, POLYSWARM_ARTIFACT_ATTRIBUTE_TOTAL_DETECTIONS_DISPLAY); + createCustomArtifactAttribute(autopsyCase, POLYSWARM_ARTIFACT_ATTRIBUTE_POLYSCORE_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING, POLYSWARM_ARTIFACT_ATTRIBUTE_POLYSCORE_DISPLAY); + createCustomArtifactAttribute(autopsyCase, POLYSWARM_ARTIFACT_ATTRIBUTE_MALWARE_FAMILY_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING, POLYSWARM_ARTIFACT_ATTRIBUTE_MALWARE_FAMILY_DISPLAY); + createCustomArtifactAttribute(autopsyCase, POLYSWARM_ARTIFACT_ATTRIBUTE_TAG_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING, POLYSWARM_ARTIFACT_ATTRIBUTE_TAG_DISPLAY); + createCustomArtifactAttribute(autopsyCase, POLYSWARM_ARTIFACT_ATTRIBUTE_FIRST_SEEN_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING, POLYSWARM_ARTIFACT_ATTRIBUTE_FIRST_SEEN_DISPLAY); + createCustomArtifactAttribute(autopsyCase, POLYSWARM_ARTIFACT_ATTRIBUTE_LAST_SCANNED_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING, POLYSWARM_ARTIFACT_ATTRIBUTE_LAST_SCANNED_DISPLAY); + } + + public static void createCustomArtifactAttribute(Case autopsyCase, String name, TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE valueType, String display) { + try { + if (autopsyCase.getSleuthkitCase().getAttributeType(name) == null) { + autopsyCase.getSleuthkitCase().addArtifactAttributeType(name, valueType, display); + } + } catch (TskCoreException | TskDataException ex) { + LOGGER.log(Level.SEVERE, "Failed to create custom artifact attribute type", ex); + } + } + + public BlackboardArtifact getBlackboardArtifact(AbstractFile abstractFile) throws UnsupportedOperationException, TskCoreException { + List artifacts = abstractFile.getArtifacts(POLYSWARM_ARTIFACT_TYPE_NAME); + + if (artifacts.isEmpty()) { + throw new UnsupportedOperationException(); + } + + return artifacts.get(0); + } + + public String getSha256(AbstractFile abstractFile) throws NoCurrentCaseException, TskCoreException, UnsupportedOperationException { + BlackboardArtifact artifact = getBlackboardArtifact(abstractFile); + BlackboardAttribute.Type attributeType = new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_HASH_SHA2_256); + BlackboardAttribute attribute = artifact.getAttribute(attributeType); + if (attribute != null) { + return attribute.getValueString(); + } else { + throw new UnsupportedOperationException(); + } + } + + public void reset() { + try { + // close all connections to the REST API and db. + dbInstance.shutdownConnections(); + shutDownDBExecutor(); + dbExecutor = getNewDBExecutor(); + } catch (PolySwarmDbException ex) { + LOGGER.log(Level.SEVERE, "Failed to shutdown database connections.", ex); // NON-NLS + } + } + + synchronized private void shutDownDBExecutor() { + if (dbExecutor != null) { + dbExecutor.shutdownNow(); + try { + dbExecutor.awaitTermination(30, TimeUnit.SECONDS); + } catch (InterruptedException ex) { + LOGGER.log(Level.WARNING, "PolySwarm failed to shutdown DB Task Executor in a timely fashion.", ex); + } + } + } + + private static ListeningScheduledExecutorService getNewDBExecutor() { + return MoreExecutors.listeningDecorator(Executors.newSingleThreadScheduledExecutor( + new ThreadFactoryBuilder().setNameFormat("PolySwarm-DB-Worker-Thread-%d").build())); + } + +} diff --git a/swarmit/src/io/polyswarm/swarmit/SwarmItModule.java b/polyswarm/src/io/polyswarm/app/PolySwarmModule.java similarity index 73% rename from swarmit/src/io/polyswarm/swarmit/SwarmItModule.java rename to polyswarm/src/io/polyswarm/app/PolySwarmModule.java index 3c7be11..9bfe2fd 100644 --- a/swarmit/src/io/polyswarm/swarmit/SwarmItModule.java +++ b/polyswarm/src/io/polyswarm/app/PolySwarmModule.java @@ -1,130 +1,131 @@ -/* - * The MIT License - * - * Copyright 2018 PolySwarm PTE. LTD. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.polyswarm.swarmit; - -import io.polyswarm.swarmit.datamodel.SwarmItDbException; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.openide.util.NbBundle.Messages; -import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; -import org.sleuthkit.autopsy.core.RuntimeProperties; -import org.sleuthkit.datamodel.TskCoreException; - -/** - * - */ -@Messages({"SwarmItModule.moduleName=SwarmIt"}) -public class SwarmItModule { - private static final Logger LOGGER = Logger.getLogger(SwarmItModule.class.getName()); - private static final String MODULE_NAME = Bundle.SwarmItModule_moduleName(); - private static SwarmItController controller; - private static final Object CONTROLLER_LOCK = new Object(); - - public static SwarmItController getController() throws TskCoreException, NoCurrentCaseException, SwarmItDbException { - synchronized (CONTROLLER_LOCK) { - if (controller == null) { - controller = new SwarmItController(Case.getCurrentCaseThrows()); - } - return controller; - } - } - - /** - * Called by the run method in the OnStart class. - */ - static void onStart() { - LOGGER.log(Level.INFO, "Starting SwarmIt Module."); // NON-NLS - - Case.addPropertyChangeListener(new CaseEventListener()); - } - - public static String getModuleName() { - return MODULE_NAME; - } - - /* only static utilities, do not allow instantiation */ - private SwarmItModule() { - } - - /** - * Listener for case events. - */ - static private class CaseEventListener implements PropertyChangeListener { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (RuntimeProperties.runningWithGUI() == false) { - /* - * Running in "headless" mode, no need to process any events. - * This cannot be done earlier because the switch to core - * components inactive may not have been made at start up. - */ - Case.removePropertyChangeListener(this); - return; - } - SwarmItController con; - try { - con = getController(); - } catch (NoCurrentCaseException ex) { - LOGGER.log(Level.SEVERE, "Attempted to access SwarmIt Module with no case open.", ex); //NON-NLS - return; - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Error getting SwarmItController.", ex); //NON-NLS - return; - } catch (SwarmItDbException ex) { - LOGGER.log(Level.SEVERE, "Error getting SwarmitController's database.", ex); // NON-NLS - } - switch (Case.Events.valueOf(evt.getPropertyName())) { - case CURRENT_CASE: - synchronized (CONTROLLER_LOCK) { - // case has changes: reset everything - if (controller != null) { - controller.reset(); - } - controller = null; - - Case newCase = (Case) evt.getNewValue(); - if (newCase != null) { - // a new case has been opened: connect db, start worker thread - try { - controller = new SwarmItController(newCase); - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Error changing case in ImageGallery.", ex); - } catch (SwarmItDbException ex) { - LOGGER.log(Level.SEVERE, "Error getting SwarmitController's database.", ex); // NON-NLS - } - } - } - break; - default: - //we don't need to do anything for other events. - break; - } - } - } - -} +/* + * The MIT License + * + * Copyright 2018 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app; + +import io.polyswarm.app.datamodel.PolySwarmDbException; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.openide.util.NbBundle.Messages; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.core.RuntimeProperties; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * + */ +@Messages({"PolySwarmModule.moduleName=PolySwarm"}) +public class PolySwarmModule { + + private static final Logger LOGGER = Logger.getLogger(PolySwarmModule.class.getName()); + private static final String MODULE_NAME = Bundle.PolySwarmModule_moduleName(); + private static PolySwarmController controller; + private static final Object CONTROLLER_LOCK = new Object(); + + public static PolySwarmController getController() throws TskCoreException, NoCurrentCaseException, PolySwarmDbException { + synchronized (CONTROLLER_LOCK) { + if (controller == null) { + controller = new PolySwarmController(Case.getCurrentCaseThrows()); + } + return controller; + } + } + + /** + * Called by the run method in the OnStart class. + */ + static void onStart() { + LOGGER.log(Level.INFO, "Starting PolySwarm Module."); // NON-NLS + + Case.addPropertyChangeListener(new CaseEventListener()); + } + + public static String getModuleName() { + return MODULE_NAME; + } + + /* only static utilities, do not allow instantiation */ + private PolySwarmModule() { + } + + /** + * Listener for case events. + */ + static private class CaseEventListener implements PropertyChangeListener { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (RuntimeProperties.runningWithGUI() == false) { + /* + * Running in "headless" mode, no need to process any events. + * This cannot be done earlier because the switch to core + * components inactive may not have been made at start up. + */ + Case.removePropertyChangeListener(this); + return; + } + PolySwarmController con; + try { + con = getController(); + } catch (NoCurrentCaseException ex) { + LOGGER.log(Level.SEVERE, "Attempted to access PolySwarm Module with no case open.", ex); //NON-NLS + return; + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Error getting PolySwarmController.", ex); //NON-NLS + return; + } catch (PolySwarmDbException ex) { + LOGGER.log(Level.SEVERE, "Error getting PolySwarmController's database.", ex); // NON-NLS + } + switch (Case.Events.valueOf(evt.getPropertyName())) { + case CURRENT_CASE: + synchronized (CONTROLLER_LOCK) { + // case has changes: reset everything + if (controller != null) { + controller.reset(); + } + controller = null; + + Case newCase = (Case) evt.getNewValue(); + if (newCase != null) { + // a new case has been opened: connect db, start worker thread + try { + controller = new PolySwarmController(newCase); + } catch (TskCoreException ex) { + LOGGER.log(Level.SEVERE, "Error changing case.", ex); + } catch (PolySwarmDbException ex) { + LOGGER.log(Level.SEVERE, "Error getting PolySwarmController's database.", ex); // NON-NLS + } + } + } + break; + default: + //we don't need to do anything for other events. + break; + } + } + } + +} diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/ApiClientV2.java b/polyswarm/src/io/polyswarm/app/apiclient/ApiClientV2.java similarity index 74% rename from swarmit/src/io/polyswarm/swarmit/apiclient/ApiClientV2.java rename to polyswarm/src/io/polyswarm/app/apiclient/ApiClientV2.java index b981d01..2ba0e0b 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/ApiClientV2.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/ApiClientV2.java @@ -1,165 +1,183 @@ - - -/* - * The MIT License - * - * Copyright 2018 PolySwarm PTE. LTD. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.polyswarm.swarmit.apiclient; - -import io.polyswarm.swarmit.apiclient.v2.requests.HashSearchRequest; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.ArtifactInstance; -import io.polyswarm.swarmit.apiclient.v2.requests.ArtifactSubmissionStatusRequest; -import io.polyswarm.swarmit.apiclient.v2.requests.SubmitArtifactRequest; -import io.polyswarm.swarmit.apiclient.v2.requests.TagRequest; -import io.polyswarm.swarmit.apiclient.v2.requests.TestRequest; -import io.polyswarm.swarmit.apiclient.v2.requests.TestResponse; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.Tag; -import io.polyswarm.swarmit.optionspanel.SwarmItMarketplaceSettings; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.json.JSONException; -import org.sleuthkit.datamodel.AbstractFile; - -/** - * Make requests to PolySwarm API and manage responses and parse responses. - */ -public class ApiClientV2 { - private final static Logger LOGGER = Logger.getLogger(ApiClientV2.class.getName()); - - /** - * Make this all static methods. - */ - private ApiClientV2() { - } - - /** - * Submit file content to PolySwarm to scan - * API endpoint. - * - * @param abstractFile AbstractFile to scan - * @return ArtifactInstance - * - * @throws IOException, BadRequestException, RateLimitException, NotAuthorizedException, NotFoundException - */ - public static ArtifactInstance submitFile(AbstractFile abstractFile) throws IOException, BadRequestException, RateLimitException, NotAuthorizedException, NotFoundException { - try{ - return new SubmitArtifactRequest(abstractFile).makeRequest(); - } catch (URISyntaxException ex) { - LOGGER.log(Level.SEVERE, "Invalid API URI.", ex); - throw new IOException(ex); - } catch (JSONException ex) { - LOGGER.log(Level.SEVERE, "Invalid API Response.", ex); - throw new IOException(ex); - } - } - - - /** - * Check PolySwarm for results on a given md5 hash - * - * @param md5Hash String with the hash - * @return ArtifactInstance object - * - * @throws IOException, BadRequestException, RateLimitException, NotAuthorizedException, NotFoundException - */ - public static ArtifactInstance searchHash(String md5Hash) throws IOException, BadRequestException, RateLimitException, NotAuthorizedException, NotFoundException { - try { - return new HashSearchRequest(md5Hash).makeRequest(); - } catch (URISyntaxException ex) { - LOGGER.log(Level.SEVERE, "Invalid API URI.", ex); - throw new IOException(ex); - } catch (JSONException ex) { - LOGGER.log(Level.SEVERE, "Invalid API Response.", ex); - throw new IOException(ex); - } - } - - /** - * Check the submission status for a submission with the given id - * - * @param submissionId ID of the submission to check - * @return ArtifactInstance - * - * @throws IOException, BadRequestException, RateLimitException, NotAuthorizedException, NotFoundException - */ - public static ArtifactInstance getSubmissionStatus(String submissionId) throws IOException, BadRequestException, RateLimitException, NotAuthorizedException, NotFoundException { - try { - return new ArtifactSubmissionStatusRequest(submissionId).makeRequest(); - } catch (URISyntaxException ex) { - LOGGER.log(Level.SEVERE, "Invalid API URI.", ex); - throw new IOException(ex); - } catch (JSONException ex) { - LOGGER.log(Level.SEVERE, "Invalid API Response.", ex); - throw new IOException(ex); - } - } - - - /** - * Get a list of Tags for a file - * - * @param artifactInstance ArtifactInstance to get tags - * @return List of Tag objects - * - * @throws IOException, BadRequestException, RateLimitException - */ - public static List getTags(ArtifactInstance artifactInstance) throws IOException, BadRequestException, RateLimitException { - try { - return new TagRequest(artifactInstance).makeRequest(); - } catch (URISyntaxException ex) { - LOGGER.log(Level.SEVERE, "Invalid API URI.", ex); - throw new IOException(ex); - } catch (JSONException ex) { - LOGGER.log(Level.SEVERE, "Invalid API Response.", ex); - throw new IOException(ex); - } catch (NotFoundException | NotAuthorizedException ex) { - // Not found is fine, just empty list - return new ArrayList<>(); - } - } - - /** - * Do a GET request for the client API status. - * - * @param apiSettings - Instance of the API settings - * @return true if connection successful, else false - */ - public static TestResponse testConnection(SwarmItMarketplaceSettings apiSettings) { - - try { - return new TestRequest().makeRequest(); - } catch (URISyntaxException ex) { - LOGGER.log(Level.SEVERE, "Invalid API URI.", ex); - } catch (NotAuthorizedException ex) { - LOGGER.log(Level.SEVERE, "Invalid API Key.", ex); - } catch (BadRequestException ex) { - LOGGER.log(Level.SEVERE, "Invalid UUID.", ex); - } catch (IOException ex) { - LOGGER.log(Level.SEVERE, "Error testing connection", ex); - } - return new TestResponse(false); - } -} +/* + * The MIT License + * + * Copyright 2018 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app.apiclient; + +import io.polyswarm.app.apiclient.v2.requests.HashSearchRequest; +import io.polyswarm.app.apiclient.v2.requests.utils.ArtifactInstance; +import io.polyswarm.app.apiclient.v2.requests.ArtifactSubmissionStatusRequest; +import io.polyswarm.app.apiclient.v2.requests.RescanRequest; +import io.polyswarm.app.apiclient.v2.requests.SubmitArtifactRequest; +import io.polyswarm.app.apiclient.v2.requests.TagRequest; +import io.polyswarm.app.apiclient.v2.requests.TestRequest; +import io.polyswarm.app.apiclient.v2.requests.TestResponse; +import io.polyswarm.app.apiclient.v2.requests.utils.Tag; +import io.polyswarm.app.optionspanel.PolySwarmMarketplaceSettings; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.json.JSONException; +import org.sleuthkit.datamodel.AbstractFile; + +/** + * Make requests to PolySwarm API and manage responses and parse responses. + */ +public class ApiClientV2 { + + private final static Logger LOGGER = Logger.getLogger(ApiClientV2.class.getName()); + + /** + * Make this all static methods. + */ + private ApiClientV2() { + } + + /** + * Submit file content to PolySwarm to scan API endpoint. + * + * @param abstractFile AbstractFile to scan + * @return ArtifactInstance + * + * @throws IOException, BadRequestException, RateLimitException, NotAuthorizedException, NotFoundException + */ + public static ArtifactInstance submitFile(AbstractFile abstractFile) throws IOException, BadRequestException, RateLimitException, NotAuthorizedException, NotFoundException, ServerException { + try { + return new SubmitArtifactRequest(abstractFile).makeRequest(); + } catch (URISyntaxException ex) { + LOGGER.log(Level.SEVERE, "Invalid API URI.", ex); + throw new IOException(ex); + } catch (JSONException ex) { + LOGGER.log(Level.SEVERE, "Invalid API Response.", ex); + throw new IOException(ex); + } + } + + /** + * Rescan a file in PolySwarm by sha256 hash + * + * + * @param sha256Hash sha256 hash of the file to rescan + * @return ArtifactInstance + * + * @throws IOException, BadRequestException, RateLimitException, NotAuthorizedException, NotFoundException + */ + public static ArtifactInstance rescanFile(String sha256Hash) throws IOException, BadRequestException, RateLimitException, NotAuthorizedException, NotFoundException, ServerException { + try { + return new RescanRequest(sha256Hash).makeRequest(); + } catch (URISyntaxException ex) { + LOGGER.log(Level.SEVERE, "Invalid API URI.", ex); + throw new IOException(ex); + } catch (JSONException ex) { + LOGGER.log(Level.SEVERE, "Invalid API Response.", ex); + throw new IOException(ex); + } + } + + /** + * Check PolySwarm for results on a given md5 hash + * + * @param md5Hash String with the hash + * @return ArtifactInstance object + * + * @throws IOException, BadRequestException, RateLimitException, NotAuthorizedException, NotFoundException + */ + public static ArtifactInstance searchHash(String md5Hash) throws IOException, BadRequestException, RateLimitException, NotAuthorizedException, NotFoundException, ServerException { + try { + return new HashSearchRequest(md5Hash).makeRequest(); + } catch (URISyntaxException ex) { + LOGGER.log(Level.SEVERE, "Invalid API URI.", ex); + throw new IOException(ex); + } catch (JSONException ex) { + LOGGER.log(Level.SEVERE, "Invalid API Response.", ex); + throw new IOException(ex); + } + } + + /** + * Check the submission status for a submission with the given id + * + * @param submissionId ID of the submission to check + * @return ArtifactInstance + * + * @throws IOException, BadRequestException, RateLimitException, NotAuthorizedException, NotFoundException + */ + public static ArtifactInstance getSubmissionStatus(String submissionId) throws IOException, BadRequestException, RateLimitException, NotAuthorizedException, NotFoundException, ServerException { + try { + return new ArtifactSubmissionStatusRequest(submissionId).makeRequest(); + } catch (URISyntaxException ex) { + LOGGER.log(Level.SEVERE, "Invalid API URI.", ex); + throw new IOException(ex); + } catch (JSONException ex) { + LOGGER.log(Level.SEVERE, "Invalid API Response.", ex); + throw new IOException(ex); + } + } + + /** + * Get a list of Tags for a file + * + * @param artifactInstance ArtifactInstance to get tags + * @return List of Tag objects + * + * @throws IOException, BadRequestException, RateLimitException + */ + public static List getTags(ArtifactInstance artifactInstance) throws IOException, BadRequestException, RateLimitException, ServerException { + try { + return new TagRequest(artifactInstance).makeRequest(); + } catch (URISyntaxException ex) { + LOGGER.log(Level.SEVERE, "Invalid API URI.", ex); + throw new IOException(ex); + } catch (JSONException ex) { + LOGGER.log(Level.SEVERE, "Invalid API Response.", ex); + throw new IOException(ex); + } catch (NotFoundException | NotAuthorizedException ex) { + // Not found is fine, just empty list + return new ArrayList<>(); + } + } + + /** + * Do a GET request for the client API status. + * + * @param apiSettings - Instance of the API settings + * @return true if connection successful, else false + */ + public static TestResponse testConnection(PolySwarmMarketplaceSettings apiSettings) { + + try { + return new TestRequest().makeRequest(); + } catch (URISyntaxException ex) { + LOGGER.log(Level.SEVERE, "Invalid API URI.", ex); + } catch (NotAuthorizedException ex) { + LOGGER.log(Level.SEVERE, "Invalid API Key.", ex); + } catch (BadRequestException ex) { + LOGGER.log(Level.SEVERE, "Invalid UUID.", ex); + } catch (IOException ex) { + LOGGER.log(Level.SEVERE, "Error testing connection", ex); + } + return new TestResponse(false); + } +} diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/BadRequestException.java b/polyswarm/src/io/polyswarm/app/apiclient/BadRequestException.java similarity index 97% rename from swarmit/src/io/polyswarm/swarmit/apiclient/BadRequestException.java rename to polyswarm/src/io/polyswarm/app/apiclient/BadRequestException.java index ca52b1d..912b562 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/BadRequestException.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/BadRequestException.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient; +package io.polyswarm.app.apiclient; import java.io.IOException; diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/InputStreamKnownSizeBody.java b/polyswarm/src/io/polyswarm/app/apiclient/InputStreamKnownSizeBody.java similarity index 95% rename from swarmit/src/io/polyswarm/swarmit/apiclient/InputStreamKnownSizeBody.java rename to polyswarm/src/io/polyswarm/app/apiclient/InputStreamKnownSizeBody.java index c4c399c..4e7db8b 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/InputStreamKnownSizeBody.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/InputStreamKnownSizeBody.java @@ -1,51 +1,51 @@ -/* - * The MIT License - * - * Copyright 2018 PolySwarm PTE. LTD. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.polyswarm.swarmit.apiclient; - -import java.io.InputStream; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.mime.content.InputStreamBody; - -/** - * The consumer service is a Flask app, and Flask cannot handle file uploads - * having file size -1 (unknown file size). This class makes sure that - * we always provide an accurate file size. - */ -public class InputStreamKnownSizeBody extends InputStreamBody { - private final int length; - - public InputStreamKnownSizeBody( - InputStream in, - int length, - ContentType contentType, - String filename) { - super(in, contentType, filename); - this.length = length; - } - - @Override - public long getContentLength() { - return this.length; - } -} +/* + * The MIT License + * + * Copyright 2018 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app.apiclient; + +import java.io.InputStream; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.content.InputStreamBody; + +/** + * The consumer service is a Flask app, and Flask cannot handle file uploads + * having file size -1 (unknown file size). This class makes sure that + * we always provide an accurate file size. + */ +public class InputStreamKnownSizeBody extends InputStreamBody { + private final int length; + + public InputStreamKnownSizeBody( + InputStream in, + int length, + ContentType contentType, + String filename) { + super(in, contentType, filename); + this.length = length; + } + + @Override + public long getContentLength() { + return this.length; + } +} diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/NotAuthorizedException.java b/polyswarm/src/io/polyswarm/app/apiclient/NotAuthorizedException.java similarity index 97% rename from swarmit/src/io/polyswarm/swarmit/apiclient/NotAuthorizedException.java rename to polyswarm/src/io/polyswarm/app/apiclient/NotAuthorizedException.java index 9e32207..a20620d 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/NotAuthorizedException.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/NotAuthorizedException.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient; +package io.polyswarm.app.apiclient; import java.io.IOException; diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/NotFoundException.java b/polyswarm/src/io/polyswarm/app/apiclient/NotFoundException.java similarity index 97% rename from swarmit/src/io/polyswarm/swarmit/apiclient/NotFoundException.java rename to polyswarm/src/io/polyswarm/app/apiclient/NotFoundException.java index f3fde10..1b4c52c 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/NotFoundException.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/NotFoundException.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient; +package io.polyswarm.app.apiclient; import java.io.IOException; diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/RateLimitException.java b/polyswarm/src/io/polyswarm/app/apiclient/RateLimitException.java similarity index 97% rename from swarmit/src/io/polyswarm/swarmit/apiclient/RateLimitException.java rename to polyswarm/src/io/polyswarm/app/apiclient/RateLimitException.java index ab84ab0..1222432 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/RateLimitException.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/RateLimitException.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient; +package io.polyswarm.app.apiclient; import java.io.IOException; diff --git a/polyswarm/src/io/polyswarm/app/apiclient/ServerException.java b/polyswarm/src/io/polyswarm/app/apiclient/ServerException.java new file mode 100644 index 0000000..65afee7 --- /dev/null +++ b/polyswarm/src/io/polyswarm/app/apiclient/ServerException.java @@ -0,0 +1,41 @@ +/* + * The MIT License + * + * Copyright 2020 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app.apiclient; + +import java.io.IOException; + +/** + * Indicates a 5XX response from PolySwarm + */ +public class ServerException extends IOException { + + /** + * Constructs an instance of ServerErrorException with the specified detail message. + * + * @param msg the detail message. + */ + public ServerException(String msg) { + super(msg); + } +} diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/ArtifactInstanceResponseHandler.java b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/ArtifactInstanceResponseHandler.java similarity index 63% rename from swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/ArtifactInstanceResponseHandler.java rename to polyswarm/src/io/polyswarm/app/apiclient/v2/requests/ArtifactInstanceResponseHandler.java index 949d70e..6321d6e 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/ArtifactInstanceResponseHandler.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/ArtifactInstanceResponseHandler.java @@ -22,13 +22,14 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient.v2.requests; +package io.polyswarm.app.apiclient.v2.requests; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.ArtifactInstance; -import io.polyswarm.swarmit.apiclient.BadRequestException; -import io.polyswarm.swarmit.apiclient.NotAuthorizedException; -import io.polyswarm.swarmit.apiclient.NotFoundException; -import io.polyswarm.swarmit.apiclient.RateLimitException; +import io.polyswarm.app.apiclient.v2.requests.utils.ArtifactInstance; +import io.polyswarm.app.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.NotAuthorizedException; +import io.polyswarm.app.apiclient.NotFoundException; +import io.polyswarm.app.apiclient.RateLimitException; +import io.polyswarm.app.apiclient.ServerException; import java.io.IOException; import java.util.logging.Logger; import org.apache.http.HttpEntity; @@ -40,15 +41,15 @@ import org.json.JSONObject; import org.json.JSONTokener; - /** * Reads an artifact instance from json response */ public class ArtifactInstanceResponseHandler implements ResponseHandler { + private final static Logger LOGGER = Logger.getLogger(ArtifactInstanceResponseHandler.class.getName()); @Override - public ArtifactInstance handleResponse(HttpResponse response) throws NotAuthorizedException, BadRequestException, ClientProtocolException, RateLimitException, NotFoundException, IOException, JSONException { + public ArtifactInstance handleResponse(HttpResponse response) throws NotAuthorizedException, BadRequestException, ClientProtocolException, RateLimitException, NotFoundException, ServerException, IOException, JSONException { Integer statusCode = response.getStatusLine().getStatusCode(); HttpEntity responseEntity = response.getEntity(); String responseString = null; @@ -56,13 +57,16 @@ public ArtifactInstance handleResponse(HttpResponse response) throws NotAuthoriz responseString = EntityUtils.toString(responseEntity); } - if (statusCode / 100 == 2) { - JSONTokener tokener = new JSONTokener(responseString); - JSONObject topLevel = new JSONObject(tokener); - return new ArtifactInstance(topLevel.getJSONObject("result")); - } else { - handle4xx(statusCode, responseString); - throw new ClientProtocolException(String.format("Client request failed. Status code: %s, Response: %s.", statusCode, responseString)); + switch (statusCode / 100) { + case 2: + JSONTokener tokener = new JSONTokener(responseString); + JSONObject topLevel = new JSONObject(tokener); + return new ArtifactInstance(topLevel.getJSONObject("result")); + case 5: + throw new ServerException(String.format("Received a server error response. Status code: %s, Response: %s", statusCode, responseString)); + default: + handle4xx(statusCode, responseString); + throw new ClientProtocolException(String.format("Client request failed. Status code: %s, Response: %s.", statusCode, responseString)); } } @@ -74,10 +78,14 @@ public ArtifactInstance handleResponse(HttpResponse response) throws NotAuthoriz */ private void handle4xx(Integer statusCode, String responseString) throws BadRequestException, NotAuthorizedException, RateLimitException, NotFoundException { switch (statusCode) { - case 400: throw new BadRequestException(responseString); - case 401: throw new NotAuthorizedException(responseString); - case 404: throw new NotFoundException(responseString); - case 429: throw new RateLimitException(responseString); + case 400: + throw new BadRequestException(responseString); + case 401: + throw new NotAuthorizedException(responseString); + case 404: + throw new NotFoundException(responseString); + case 429: + throw new RateLimitException(responseString); } } } diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/ArtifactSubmissionStatusRequest.java b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/ArtifactSubmissionStatusRequest.java similarity index 87% rename from swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/ArtifactSubmissionStatusRequest.java rename to polyswarm/src/io/polyswarm/app/apiclient/v2/requests/ArtifactSubmissionStatusRequest.java index 525e08b..7cba984 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/ArtifactSubmissionStatusRequest.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/ArtifactSubmissionStatusRequest.java @@ -21,12 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient.v2.requests; +package io.polyswarm.app.apiclient.v2.requests; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.ArtifactInstance; -import io.polyswarm.swarmit.apiclient.BadRequestException; -import io.polyswarm.swarmit.apiclient.NotAuthorizedException; -import io.polyswarm.swarmit.optionspanel.SwarmItMarketplaceSettings; +import io.polyswarm.app.apiclient.v2.requests.utils.ArtifactInstance; +import io.polyswarm.app.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.NotAuthorizedException; +import io.polyswarm.app.optionspanel.PolySwarmMarketplaceSettings; import java.io.IOException; import java.net.URISyntaxException; import java.util.logging.Logger; @@ -50,7 +50,7 @@ public ArtifactSubmissionStatusRequest(String submissionId) { @Override public ArtifactInstance makeRequest() throws URISyntaxException, NotAuthorizedException, BadRequestException, IOException { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { - SwarmItMarketplaceSettings apiSettings = new SwarmItMarketplaceSettings(); + PolySwarmMarketplaceSettings apiSettings = new PolySwarmMarketplaceSettings(); String uri = String.format("%sconsumer/submission/%s/%s", apiSettings.getApiUrl(), apiSettings.getCommunity(), submissionId); URIBuilder builder = new URIBuilder(uri); diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/HashSearchRequest.java b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/HashSearchRequest.java similarity index 86% rename from swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/HashSearchRequest.java rename to polyswarm/src/io/polyswarm/app/apiclient/v2/requests/HashSearchRequest.java index 02273ac..c6502e9 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/HashSearchRequest.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/HashSearchRequest.java @@ -21,13 +21,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient.v2.requests; +package io.polyswarm.app.apiclient.v2.requests; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.ArtifactInstance; -import io.polyswarm.swarmit.apiclient.BadRequestException; -import io.polyswarm.swarmit.apiclient.NotAuthorizedException; -import io.polyswarm.swarmit.apiclient.NotFoundException; -import io.polyswarm.swarmit.optionspanel.SwarmItMarketplaceSettings; +import io.polyswarm.app.apiclient.v2.requests.utils.ArtifactInstance; +import io.polyswarm.app.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.NotAuthorizedException; +import io.polyswarm.app.apiclient.NotFoundException; +import io.polyswarm.app.optionspanel.PolySwarmMarketplaceSettings; import java.io.IOException; import java.net.URISyntaxException; import java.util.logging.Logger; @@ -56,7 +56,7 @@ public HashSearchRequest(AbstractFile abstractFile) { @Override public ArtifactInstance makeRequest() throws URISyntaxException, NotAuthorizedException, BadRequestException, IOException, NotFoundException { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { - SwarmItMarketplaceSettings apiSettings = new SwarmItMarketplaceSettings(); + PolySwarmMarketplaceSettings apiSettings = new PolySwarmMarketplaceSettings(); String uri = String.format("%ssearch/hash/md5", apiSettings.getApiUrl()); URIBuilder builder = new URIBuilder(uri); diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/HashSearchResponseHandler.java b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/HashSearchResponseHandler.java similarity index 74% rename from swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/HashSearchResponseHandler.java rename to polyswarm/src/io/polyswarm/app/apiclient/v2/requests/HashSearchResponseHandler.java index 74362a3..e9ebb39 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/HashSearchResponseHandler.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/HashSearchResponseHandler.java @@ -22,13 +22,14 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient.v2.requests; +package io.polyswarm.app.apiclient.v2.requests; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.ArtifactInstance; -import io.polyswarm.swarmit.apiclient.BadRequestException; -import io.polyswarm.swarmit.apiclient.NotAuthorizedException; -import io.polyswarm.swarmit.apiclient.NotFoundException; -import io.polyswarm.swarmit.apiclient.RateLimitException; +import io.polyswarm.app.apiclient.v2.requests.utils.ArtifactInstance; +import io.polyswarm.app.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.NotAuthorizedException; +import io.polyswarm.app.apiclient.NotFoundException; +import io.polyswarm.app.apiclient.RateLimitException; +import io.polyswarm.app.apiclient.ServerException; import java.io.IOException; import java.util.logging.Logger; import org.apache.http.HttpEntity; @@ -45,17 +46,19 @@ * Parses an ArtifactInstance from the response to a HashSearchRequest */ public class HashSearchResponseHandler implements ResponseHandler { + private final static Logger LOGGER = Logger.getLogger(HashSearchResponseHandler.class.getName()); @Override - public ArtifactInstance handleResponse(HttpResponse response) throws NotAuthorizedException, BadRequestException, ClientProtocolException, RateLimitException, IOException, JSONException { + public ArtifactInstance handleResponse(HttpResponse response) throws NotAuthorizedException, BadRequestException, ClientProtocolException, RateLimitException, ServerException, IOException, JSONException { Integer statusCode = response.getStatusLine().getStatusCode(); HttpEntity responseEntity = response.getEntity(); String responseString = null; if (responseEntity != null) { responseString = EntityUtils.toString(responseEntity); } - if (statusCode == 204 ) { + + if (statusCode == 204) { throw new NotFoundException(responseString); } else if (statusCode / 100 == 2) { JSONTokener tokener = new JSONTokener(responseString); @@ -67,13 +70,15 @@ public ArtifactInstance handleResponse(HttpResponse response) throws NotAuthoriz } else { throw new NotFoundException(responseString); } + } else if (statusCode / 100 == 5) { + throw new ServerException(String.format("Received a server error response. Status code: %s, Response: %s", statusCode, responseString)); } else { handle4xx(statusCode, responseString); throw new ClientProtocolException(String.format("Client request failed. Status code: %s, Response: %s.", statusCode, responseString)); } } -/** + /** * Throw exceptions based on statusCode * * @param statusCode Status code from PolySwarm @@ -81,10 +86,14 @@ public ArtifactInstance handleResponse(HttpResponse response) throws NotAuthoriz */ private void handle4xx(Integer statusCode, String responseString) throws BadRequestException, NotAuthorizedException, RateLimitException, ClientProtocolException { switch (statusCode) { - case 400: throw new BadRequestException(responseString); - case 401: throw new NotAuthorizedException(responseString); - case 429: throw new RateLimitException(responseString); - default: throw new ClientProtocolException(String.format("Client request failed. Status code: %s, Response: %s.", statusCode, responseString)); + case 400: + throw new BadRequestException(responseString); + case 401: + throw new NotAuthorizedException(responseString); + case 429: + throw new RateLimitException(responseString); + default: + throw new ClientProtocolException(String.format("Client request failed. Status code: %s, Response: %s.", statusCode, responseString)); } } } diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/Request.java b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/Request.java similarity index 88% rename from swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/Request.java rename to polyswarm/src/io/polyswarm/app/apiclient/v2/requests/Request.java index 2588463..3be5b84 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/Request.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/Request.java @@ -21,10 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient.v2.requests; +package io.polyswarm.app.apiclient.v2.requests; -import io.polyswarm.swarmit.apiclient.BadRequestException; -import io.polyswarm.swarmit.apiclient.NotAuthorizedException; +import io.polyswarm.app.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.NotAuthorizedException; import java.io.IOException; import java.net.URISyntaxException; diff --git a/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/RescanRequest.java b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/RescanRequest.java new file mode 100644 index 0000000..24238d8 --- /dev/null +++ b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/RescanRequest.java @@ -0,0 +1,71 @@ +/* + * The MIT License + * + * Copyright 2020 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app.apiclient.v2.requests; + +import io.polyswarm.app.apiclient.v2.requests.utils.ArtifactInstance; +import io.polyswarm.app.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.NotAuthorizedException; +import io.polyswarm.app.apiclient.NotFoundException; +import io.polyswarm.app.optionspanel.PolySwarmMarketplaceSettings; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.logging.Logger; +import org.apache.http.client.ResponseHandler; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; + +/** + * + * @author rl + */ +public class RescanRequest implements Request { + + private final static Logger LOGGER = Logger.getLogger(RescanRequest.class.getName()); + String sha256Hash; + + public RescanRequest(String sha256Hash) { + this.sha256Hash = sha256Hash; + } + + @Override + public ArtifactInstance makeRequest() throws URISyntaxException, NotAuthorizedException, BadRequestException, IOException, NotFoundException { + try ( CloseableHttpClient httpclient = HttpClients.createDefault()) { + PolySwarmMarketplaceSettings apiSettings = new PolySwarmMarketplaceSettings(); + + String uri = String.format("%s" + "consumer/submission/%s/rescan/sha256/%s", apiSettings.getApiUrl(), apiSettings.getCommunity(), sha256Hash); + URIBuilder builder = new URIBuilder(uri); + HttpPost httppost = new HttpPost(builder.build()); + + String apikey = apiSettings.getApiKey(); + if (apikey != null && !apikey.isEmpty()) { + httppost.addHeader("Authorization", apiSettings.getApiKey()); + } + + ResponseHandler responseHandler = new ArtifactInstanceResponseHandler(); + return httpclient.execute(httppost, responseHandler); + } + } +} diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/SubmitArtifactRequest.java b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/SubmitArtifactRequest.java similarity index 89% rename from swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/SubmitArtifactRequest.java rename to polyswarm/src/io/polyswarm/app/apiclient/v2/requests/SubmitArtifactRequest.java index 39384e3..656b7a3 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/SubmitArtifactRequest.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/SubmitArtifactRequest.java @@ -21,13 +21,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient.v2.requests; +package io.polyswarm.app.apiclient.v2.requests; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.ArtifactInstance; -import io.polyswarm.swarmit.apiclient.BadRequestException; -import io.polyswarm.swarmit.apiclient.InputStreamKnownSizeBody; -import io.polyswarm.swarmit.apiclient.NotAuthorizedException; -import io.polyswarm.swarmit.optionspanel.SwarmItMarketplaceSettings; +import io.polyswarm.app.apiclient.v2.requests.utils.ArtifactInstance; +import io.polyswarm.app.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.InputStreamKnownSizeBody; +import io.polyswarm.app.apiclient.NotAuthorizedException; +import io.polyswarm.app.optionspanel.PolySwarmMarketplaceSettings; import java.io.IOException; import java.net.URISyntaxException; import java.util.logging.Level; @@ -58,7 +58,7 @@ public SubmitArtifactRequest(AbstractFile abstractFile) { @Override public ArtifactInstance makeRequest() throws URISyntaxException, NotAuthorizedException, BadRequestException, IOException { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { - SwarmItMarketplaceSettings apiSettings = new SwarmItMarketplaceSettings(); + PolySwarmMarketplaceSettings apiSettings = new PolySwarmMarketplaceSettings(); String apikey = apiSettings.getApiKey(); // FIXME allow user to select community diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/TagRequest.java b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/TagRequest.java similarity index 84% rename from swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/TagRequest.java rename to polyswarm/src/io/polyswarm/app/apiclient/v2/requests/TagRequest.java index 587c714..463a5b1 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/TagRequest.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/TagRequest.java @@ -21,14 +21,14 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient.v2.requests; +package io.polyswarm.app.apiclient.v2.requests; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.ArtifactInstance; -import io.polyswarm.swarmit.apiclient.BadRequestException; -import io.polyswarm.swarmit.apiclient.NotAuthorizedException; -import io.polyswarm.swarmit.apiclient.NotFoundException; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.Tag; -import io.polyswarm.swarmit.optionspanel.SwarmItMarketplaceSettings; +import io.polyswarm.app.apiclient.v2.requests.utils.ArtifactInstance; +import io.polyswarm.app.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.NotAuthorizedException; +import io.polyswarm.app.apiclient.NotFoundException; +import io.polyswarm.app.apiclient.v2.requests.utils.Tag; +import io.polyswarm.app.optionspanel.PolySwarmMarketplaceSettings; import java.io.IOException; import java.net.URISyntaxException; import java.util.List; @@ -54,7 +54,7 @@ public TagRequest(ArtifactInstance artifactInstance) { @Override public List makeRequest() throws URISyntaxException, NotAuthorizedException, BadRequestException, IOException, NotFoundException { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { - SwarmItMarketplaceSettings apiSettings = new SwarmItMarketplaceSettings(); + PolySwarmMarketplaceSettings apiSettings = new PolySwarmMarketplaceSettings(); String uri = String.format("%stags/link", apiSettings.getApiUrl()); URIBuilder builder = new URIBuilder(uri); diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/TagResponseHandler.java b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/TagResponseHandler.java similarity index 59% rename from swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/TagResponseHandler.java rename to polyswarm/src/io/polyswarm/app/apiclient/v2/requests/TagResponseHandler.java index 050c3d4..d86ccb6 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/TagResponseHandler.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/TagResponseHandler.java @@ -21,21 +21,15 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient.v2.requests; +package io.polyswarm.app.apiclient.v2.requests; import java.util.List; import org.apache.http.client.ResponseHandler; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.Tag; +import io.polyswarm.app.apiclient.v2.requests.utils.Tag; -import io.polyswarm.swarmit.apiclient.BadRequestException; -import io.polyswarm.swarmit.apiclient.NotAuthorizedException; -import io.polyswarm.swarmit.apiclient.NotFoundException; -import io.polyswarm.swarmit.apiclient.RateLimitException; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.ArtifactInstance; import java.io.IOException; import java.util.logging.Logger; import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.util.EntityUtils; import org.json.JSONArray; @@ -43,10 +37,10 @@ import org.json.JSONObject; import org.json.JSONTokener; -import io.polyswarm.swarmit.apiclient.RateLimitException; -import io.polyswarm.swarmit.apiclient.NotAuthorizedException; -import io.polyswarm.swarmit.apiclient.NotFoundException; -import io.polyswarm.swarmit.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.RateLimitException; +import io.polyswarm.app.apiclient.NotAuthorizedException; +import io.polyswarm.app.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.ServerException; import java.util.ArrayList; import org.apache.http.HttpResponse; @@ -55,10 +49,11 @@ * Parse json response with a list of tags */ public class TagResponseHandler implements ResponseHandler> { + private final static Logger LOGGER = Logger.getLogger(TagResponseHandler.class.getName()); @Override - public List handleResponse(HttpResponse response) throws NotAuthorizedException, BadRequestException, ClientProtocolException, RateLimitException, IOException, JSONException { + public List handleResponse(HttpResponse response) throws NotAuthorizedException, BadRequestException, ClientProtocolException, RateLimitException, ServerException, IOException, JSONException { Integer statusCode = response.getStatusLine().getStatusCode(); HttpEntity responseEntity = response.getEntity(); String responseString = null; @@ -66,21 +61,23 @@ public List handleResponse(HttpResponse response) throws NotAuthorizedExcep responseString = EntityUtils.toString(responseEntity); } - if (statusCode / 100 == 2) { - JSONTokener tokener = new JSONTokener(responseString); - JSONObject output = new JSONObject(tokener); - JSONObject result = output.getJSONObject("result"); - JSONArray jsonArray = result.getJSONArray("tags"); - - List tags = new ArrayList<>(); - for (Object tag : jsonArray) { - tags.add(new Tag((String) tag)); - } - return tags; + switch (statusCode / 100) { + case 2: + JSONTokener tokener = new JSONTokener(responseString); + JSONObject output = new JSONObject(tokener); + JSONObject result = output.getJSONObject("result"); + JSONArray jsonArray = result.getJSONArray("tags"); - } else { - handle4xx(statusCode, responseString); - throw new ClientProtocolException(String.format("Client request failed. Status code: %s, Response: %s.", statusCode, responseString)); + List tags = new ArrayList<>(); + for (Object tag : jsonArray) { + tags.add(new Tag((String) tag)); + } + return tags; + case 5: + throw new ServerException(String.format("Received a server error response. Status code: %s, Response: %s", statusCode, responseString)); + default: + handle4xx(statusCode, responseString); + throw new ClientProtocolException(String.format("Client request failed. Status code: %s, Response: %s.", statusCode, responseString)); } } @@ -92,10 +89,14 @@ public List handleResponse(HttpResponse response) throws NotAuthorizedExcep */ private void handle4xx(Integer statusCode, String responseString) throws BadRequestException, NotAuthorizedException, RateLimitException, ClientProtocolException { switch (statusCode) { - case 400: throw new BadRequestException(responseString); - case 401: throw new NotAuthorizedException(responseString); - case 429: throw new RateLimitException(responseString); - default: throw new ClientProtocolException(String.format("Client request failed. Status code: %s, Response: %s.", statusCode, responseString)); + case 400: + throw new BadRequestException(responseString); + case 401: + throw new NotAuthorizedException(responseString); + case 429: + throw new RateLimitException(responseString); + default: + throw new ClientProtocolException(String.format("Client request failed. Status code: %s, Response: %s.", statusCode, responseString)); } } } diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/TestRequest.java b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/TestRequest.java similarity index 88% rename from swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/TestRequest.java rename to polyswarm/src/io/polyswarm/app/apiclient/v2/requests/TestRequest.java index a1e17ad..7434f53 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/TestRequest.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/TestRequest.java @@ -21,11 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient.v2.requests; +package io.polyswarm.app.apiclient.v2.requests; -import io.polyswarm.swarmit.apiclient.BadRequestException; -import io.polyswarm.swarmit.apiclient.NotAuthorizedException; -import io.polyswarm.swarmit.optionspanel.SwarmItMarketplaceSettings; +import io.polyswarm.app.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.NotAuthorizedException; +import io.polyswarm.app.optionspanel.PolySwarmMarketplaceSettings; import java.io.IOException; import java.net.URISyntaxException; import java.util.logging.Logger; @@ -47,7 +47,7 @@ public TestRequest() {} @Override public TestResponse makeRequest() throws URISyntaxException, NotAuthorizedException, BadRequestException, IOException { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { - SwarmItMarketplaceSettings apiSettings = new SwarmItMarketplaceSettings(); + PolySwarmMarketplaceSettings apiSettings = new PolySwarmMarketplaceSettings(); URIBuilder builder = new URIBuilder(apiSettings.getStatusUrl()); HttpGet httpget = new HttpGet(builder.build()); diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/TestResponse.java b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/TestResponse.java similarity index 96% rename from swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/TestResponse.java rename to polyswarm/src/io/polyswarm/app/apiclient/v2/requests/TestResponse.java index 87c9880..0698d10 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/TestResponse.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/TestResponse.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient.v2.requests; +package io.polyswarm.app.apiclient.v2.requests; /** * Test results from TestRequest diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/TestResponseHandler.java b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/TestResponseHandler.java similarity index 92% rename from swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/TestResponseHandler.java rename to polyswarm/src/io/polyswarm/app/apiclient/v2/requests/TestResponseHandler.java index a3c863b..3ce42c0 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/TestResponseHandler.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/TestResponseHandler.java @@ -21,10 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient.v2.requests; +package io.polyswarm.app.apiclient.v2.requests; -import io.polyswarm.swarmit.apiclient.BadRequestException; -import io.polyswarm.swarmit.apiclient.NotAuthorizedException; +import io.polyswarm.app.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.NotAuthorizedException; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/utils/ArtifactInstance.java b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/utils/ArtifactInstance.java similarity index 87% rename from swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/utils/ArtifactInstance.java rename to polyswarm/src/io/polyswarm/app/apiclient/v2/requests/utils/ArtifactInstance.java index b22b53f..63a4b19 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/utils/ArtifactInstance.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/utils/ArtifactInstance.java @@ -1,4 +1,4 @@ - /* +/* * The MIT License * * Copyright 2020 PolySwarm PTE. LTD. @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient.v2.requests.utils; +package io.polyswarm.app.apiclient.v2.requests.utils; import java.text.DecimalFormat; import java.util.ArrayList; @@ -32,19 +32,22 @@ import org.json.JSONObject; /** - * Represents an ArtifactInstance as returned from PolySwarm - * Only contains relevant data, leaving a lot out + * Represents an ArtifactInstance as returned from PolySwarm Only contains relevant data, leaving a lot out */ public class ArtifactInstance { + public final String id; public final List assertions; public final Detection detection; public final String sha256; public final String polyscore; public final boolean windowClosed; + public final String firstSeen; + public final String lastScanned; /** * Creates a HashSearchResponse from JSON + * * @param json JSON from a HashSearch in V2 * @throws JSONException */ @@ -52,7 +55,7 @@ public ArtifactInstance(JSONObject json) throws JSONException { JSONArray assertions_json = json.getJSONArray("assertions"); JSONObject detection_json = json.getJSONObject("detections"); assertions = new ArrayList<>(); - for (Object obj: assertions_json) { + for (Object obj : assertions_json) { if (obj instanceof JSONObject) { JSONObject assertion = (JSONObject) obj; assertions.add(new Assertion(assertion)); @@ -66,6 +69,8 @@ public ArtifactInstance(JSONObject json) throws JSONException { sha256 = json.getString("sha256"); windowClosed = json.getBoolean("window_closed"); id = json.getString("id"); + firstSeen = json.getString("first_seen"); + lastScanned = json.getString("last_scanned"); } @Override diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/utils/Assertion.java b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/utils/Assertion.java similarity index 97% rename from swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/utils/Assertion.java rename to polyswarm/src/io/polyswarm/app/apiclient/v2/requests/utils/Assertion.java index c445983..27fc5d7 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/utils/Assertion.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/utils/Assertion.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient.v2.requests.utils; +package io.polyswarm.app.apiclient.v2.requests.utils; import org.json.JSONException; import org.json.JSONObject; diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/utils/Detection.java b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/utils/Detection.java similarity index 96% rename from swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/utils/Detection.java rename to polyswarm/src/io/polyswarm/app/apiclient/v2/requests/utils/Detection.java index 1c33abb..f9f6957 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/utils/Detection.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/utils/Detection.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient.v2.requests.utils; +package io.polyswarm.app.apiclient.v2.requests.utils; import org.json.JSONException; import org.json.JSONObject; diff --git a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/utils/Tag.java b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/utils/Tag.java similarity index 95% rename from swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/utils/Tag.java rename to polyswarm/src/io/polyswarm/app/apiclient/v2/requests/utils/Tag.java index 53536be..a392771 100644 --- a/swarmit/src/io/polyswarm/swarmit/apiclient/v2/requests/utils/Tag.java +++ b/polyswarm/src/io/polyswarm/app/apiclient/v2/requests/utils/Tag.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.apiclient.v2.requests.utils; +package io.polyswarm.app.apiclient.v2.requests.utils; /** * A tag on an ArtifactInstance diff --git a/swarmit/src/io/polyswarm/swarmit/contextmenu/Bundle.properties b/polyswarm/src/io/polyswarm/app/contextmenu/Bundle.properties similarity index 100% rename from swarmit/src/io/polyswarm/swarmit/contextmenu/Bundle.properties rename to polyswarm/src/io/polyswarm/app/contextmenu/Bundle.properties diff --git a/swarmit/src/io/polyswarm/swarmit/contextmenu/HashLookupAction.java b/polyswarm/src/io/polyswarm/app/contextmenu/HashLookupAction.java similarity index 90% rename from swarmit/src/io/polyswarm/swarmit/contextmenu/HashLookupAction.java rename to polyswarm/src/io/polyswarm/app/contextmenu/HashLookupAction.java index fbad9ff..885786b 100644 --- a/swarmit/src/io/polyswarm/swarmit/contextmenu/HashLookupAction.java +++ b/polyswarm/src/io/polyswarm/app/contextmenu/HashLookupAction.java @@ -21,10 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.contextmenu; +package io.polyswarm.app.contextmenu; -import io.polyswarm.swarmit.datamodel.SwarmItDb; -import io.polyswarm.swarmit.datamodel.SwarmItDbException; +import io.polyswarm.app.datamodel.PolySwarmDb; +import io.polyswarm.app.datamodel.PolySwarmDbException; import java.awt.event.ActionEvent; import java.util.logging.Level; import java.util.logging.Logger; @@ -66,7 +66,7 @@ private void addPendingHashLookup(AbstractFile abstractFile) { try { String md5Hash = abstractFile.getMd5Hash(); Long abstractFileId = abstractFile.getId(); - SwarmItDb instance = SwarmItDb.getInstance(); + PolySwarmDb instance = PolySwarmDb.getInstance(); if (!instance.isPendingHashLookup(abstractFileId)) { // add hash to pending search instance.newPendingHashLookup(abstractFileId, md5Hash); @@ -76,12 +76,12 @@ private void addPendingHashLookup(AbstractFile abstractFile) { } else { LOGGER.log(Level.INFO, "Hash is already pending, not re-submitting."); JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), - Bundle.ScanAction_alreadyPending_message(), - Bundle.ScanAction_messageDialog_title(), + Bundle.HashLookupAction_alreadyPending_message(), + Bundle.HashLookupAction_messageDialog_title(), JOptionPane.ERROR_MESSAGE); } - } catch (SwarmItDbException ex) { + } catch (PolySwarmDbException ex) { LOGGER.log(Level.SEVERE, "Error adding new hash lookup to sqlite db.", ex); JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), Bundle.HashLookupAction_dbError_message(), diff --git a/swarmit/src/io/polyswarm/swarmit/contextmenu/SwarmItContextMenuActionsProvider.java b/polyswarm/src/io/polyswarm/app/contextmenu/PolySwarmContextMenuActionsProvider.java similarity index 53% rename from swarmit/src/io/polyswarm/swarmit/contextmenu/SwarmItContextMenuActionsProvider.java rename to polyswarm/src/io/polyswarm/app/contextmenu/PolySwarmContextMenuActionsProvider.java index 16c65ca..743b328 100644 --- a/swarmit/src/io/polyswarm/swarmit/contextmenu/SwarmItContextMenuActionsProvider.java +++ b/polyswarm/src/io/polyswarm/app/contextmenu/PolySwarmContextMenuActionsProvider.java @@ -1,64 +1,98 @@ -/* - * The MIT License - * - * Copyright 2018 PolySwarm PTE. LTD. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.polyswarm.swarmit.contextmenu; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.logging.Logger; -import javax.swing.Action; -import org.openide.util.Utilities; -import org.openide.util.lookup.ServiceProvider; -import org.sleuthkit.autopsy.corecomponentinterfaces.ContextMenuActionsProvider; -import org.sleuthkit.datamodel.AbstractFile; - -/** - * This creates context menu items for submitting an files/hashes to PolySwarm - */ -@ServiceProvider(service = ContextMenuActionsProvider.class) -public class SwarmItContextMenuActionsProvider implements ContextMenuActionsProvider { - private static final Logger LOGGER = Logger.getLogger(SwarmItContextMenuActionsProvider.class.getName()); - - @Override - @org.openide.util.NbBundle.Messages({"SwarmItContextMenuActionsProvider.scan.text=Scan on PolySwarm", - "SwarmItContextMenuActionsProvider.hash.text=Lookup Hash on PolySwarm"}) - public List getActions() { - ArrayList actions = new ArrayList<>(); - - final Collection selectedFiles = Utilities.actionsGlobalContext().lookupAll(AbstractFile.class); - - for (AbstractFile abstractFile : selectedFiles) { - - if (abstractFile != null && abstractFile.isFile()) { - String scanTitle = Bundle.SwarmItContextMenuActionsProvider_scan_text(); - String hashLookupTitle = Bundle.SwarmItContextMenuActionsProvider_hash_text(); - actions.add(new ScanAction(scanTitle, abstractFile)); - if (abstractFile.getMd5Hash() != null) { - actions.add(new HashLookupAction(hashLookupTitle, abstractFile)); - } - } - } - return actions; - } -} +/* + * The MIT License + * + * Copyright 2018 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app.contextmenu; + +import io.polyswarm.app.PolySwarmController; +import io.polyswarm.app.PolySwarmModule; +import io.polyswarm.app.datamodel.PolySwarmDbException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.logging.Logger; +import javax.swing.Action; +import org.openide.util.Utilities; +import org.openide.util.lookup.ServiceProvider; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.corecomponentinterfaces.ContextMenuActionsProvider; +import org.sleuthkit.datamodel.AbstractFile; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * This creates context menu items for submitting an files/hashes to PolySwarm + */ +@ServiceProvider(service = ContextMenuActionsProvider.class) +public class PolySwarmContextMenuActionsProvider implements ContextMenuActionsProvider { + + private static final Logger LOGGER = Logger.getLogger(PolySwarmContextMenuActionsProvider.class.getName()); + + @Override + @org.openide.util.NbBundle.Messages({"PolySwarmContextMenuActionsProvider.scan.text=Scan on PolySwarm", + "PolySwarmContextMenuActionsProvider.hash.text=Lookup Hash on PolySwarm", + "PolySwarmContextMenuActionsProvider.rescan.text=Rescan on PolySwarm"}) + public List getActions() { + ArrayList actions = new ArrayList<>(); + + final Collection selectedFiles = Utilities.actionsGlobalContext().lookupAll(AbstractFile.class); + + for (AbstractFile abstractFile : selectedFiles) { + + if (abstractFile != null && abstractFile.isFile()) { + String scanTitle = Bundle.PolySwarmContextMenuActionsProvider_scan_text(); + actions.add(new ScanAction(scanTitle, abstractFile)); + + if (abstractFile.getMd5Hash() != null) { + String hashLookupTitle = Bundle.PolySwarmContextMenuActionsProvider_hash_text(); + actions.add(new HashLookupAction(hashLookupTitle, abstractFile)); + } + + if (isInPolyswarm(abstractFile)) { + String rescanTitle = Bundle.PolySwarmContextMenuActionsProvider_rescan_text(); + actions.add(new RescanAction(rescanTitle, abstractFile)); + } + } + } + return actions; + } + + /** + * Checks to see if the artifact is in polyswarm. + * + * First, tries to get a polyswarm results BlackboardArtifact. If bbartifact, checks to see if there is a polyscore + * attribute. + * + * It checks for polyscore, because there is a not found attribute that is added when a hash search resutnrs nothing + * + * @param abstractFile file to check + * @return + */ + private boolean isInPolyswarm(AbstractFile abstractFile) { + try { + PolySwarmController controller = PolySwarmModule.getController(); + controller.getSha256(abstractFile); + return true; + } catch (TskCoreException | NoCurrentCaseException | PolySwarmDbException | UnsupportedOperationException ex) { + return false; + } + } +} diff --git a/polyswarm/src/io/polyswarm/app/contextmenu/RescanAction.java b/polyswarm/src/io/polyswarm/app/contextmenu/RescanAction.java new file mode 100644 index 0000000..adf279b --- /dev/null +++ b/polyswarm/src/io/polyswarm/app/contextmenu/RescanAction.java @@ -0,0 +1,112 @@ + /* + * The MIT License + * + * Copyright 2020 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app.contextmenu; + +import io.polyswarm.app.PolySwarmController; +import static io.polyswarm.app.PolySwarmController.POLYSWARM_ARTIFACT_TYPE_NAME; +import io.polyswarm.app.PolySwarmModule; +import io.polyswarm.app.datamodel.PolySwarmDb; +import io.polyswarm.app.datamodel.PolySwarmDbException; +import java.awt.event.ActionEvent; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.AbstractAction; +import javax.swing.JOptionPane; +import org.openide.windows.WindowManager; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.datamodel.AbstractFile; +import org.sleuthkit.datamodel.BlackboardArtifact; +import org.sleuthkit.datamodel.BlackboardAttribute; +import org.sleuthkit.datamodel.TskCoreException; + + +/** + * Adds a hash lookup action that queries polyswarm about the artifact in question + * Update the blackboard with results from the hash lookup + */ +public class RescanAction extends AbstractAction { + private static final long serivalVersionUID = 1L; + private static final Logger LOGGER = Logger.getLogger(RescanAction.class.getName()); + private final AbstractFile abstractFile; + + RescanAction(String menuItemStr, AbstractFile abstractFile) { + super(menuItemStr); + this.abstractFile = abstractFile; + } + + @Override + @org.openide.util.NbBundle.Messages({"RescanAction.submitError.message=Failed to submit rescan to PolySwarm.", + "RescanAction.dbError.message=Failed to record rescan in pending task database.", + "RescanAction.alreadyPending.message=Rescan is already in progress.", + "RescanAction.missingArtifact.message=Must have performed a valid hash lookup or scan on file before rescan.", + "RescanAction.messageDialog.title=Rescan on PolySwarm"}) + public void actionPerformed(ActionEvent event) { + if (abstractFile != null) { + addPendingRescan(abstractFile); + } + } + + /** + * Write the new hash lookup to the DB + */ + private void addPendingRescan(AbstractFile abstractFile) { + try { + + PolySwarmController controller = PolySwarmModule.getController(); + String sha256Hash = controller.getSha256(abstractFile); + Long abstractFileId = abstractFile.getId(); + PolySwarmDb instance = PolySwarmDb.getInstance(); + if (!instance.isPendingRescan(abstractFileId)) { + // add hash to pending search + instance.newPendingRescan(abstractFileId, sha256Hash); + LOGGER.log(Level.FINE, String.format("Added rescan to pending db: abstractFileId: %s, sha256Hash: %s.", + abstractFileId.toString(), + sha256Hash)); + } else { + LOGGER.log(Level.INFO, "Rescan is already pending, not re-submitting."); + JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), + Bundle.RescanAction_alreadyPending_message(), + Bundle.RescanAction_messageDialog_title(), + JOptionPane.ERROR_MESSAGE); + } + } catch (NoCurrentCaseException | TskCoreException ex) { + + } catch (UnsupportedOperationException ex) { + LOGGER.log(Level.SEVERE, "Error no PolySwarm Results artifact.", ex); + JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), + Bundle.RescanAction_missingArtifact_message(), + Bundle.RescanAction_messageDialog_title(), + JOptionPane.ERROR_MESSAGE); + } catch (PolySwarmDbException ex) { + LOGGER.log(Level.SEVERE, "Error adding new rescan to sqlite db.", ex); + JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), + Bundle.RescanAction_dbError_message(), + Bundle.RescanAction_messageDialog_title(), + JOptionPane.ERROR_MESSAGE); + } + } + + +} diff --git a/swarmit/src/io/polyswarm/swarmit/contextmenu/ScanAction.java b/polyswarm/src/io/polyswarm/app/contextmenu/ScanAction.java similarity index 63% rename from swarmit/src/io/polyswarm/swarmit/contextmenu/ScanAction.java rename to polyswarm/src/io/polyswarm/app/contextmenu/ScanAction.java index bdd1da1..0a9a88f 100644 --- a/swarmit/src/io/polyswarm/swarmit/contextmenu/ScanAction.java +++ b/polyswarm/src/io/polyswarm/app/contextmenu/ScanAction.java @@ -1,86 +1,123 @@ -/* - * The MIT License - * - * Copyright 2018 PolySwarm PTE. LTD. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.polyswarm.swarmit.contextmenu; - -import io.polyswarm.swarmit.datamodel.SwarmItDb; -import io.polyswarm.swarmit.datamodel.SwarmItDbException; -import java.awt.event.ActionEvent; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.AbstractAction; -import javax.swing.JOptionPane; -import org.openide.windows.WindowManager; -import org.sleuthkit.datamodel.AbstractFile; - -/** - * Action added to right-click menu on an abstractFile. - */ -public class ScanAction extends AbstractAction { - - private static final long serivalVersionUID = 1L; - private static final Logger LOGGER = Logger.getLogger(ScanAction.class.getName()); - private final AbstractFile abstractFile; - - ScanAction(String menuItemStr, AbstractFile abstractFile) { - super(menuItemStr); - this.abstractFile = abstractFile; - } - - @Override - @org.openide.util.NbBundle.Messages({"ScanAction.dbError.message=Failed to record submission in pending submissions database.", - "ScanAction.submitError.message=Failed to submit file to PolySwarm.", - "ScanAction.messageDialog.title=SwarmIt", - "ScanAction.alreadyPending.message=This file was already submitted."}) - public void actionPerformed(ActionEvent event) { - - if (abstractFile != null) { - Long abstractFileId = abstractFile.getId(); - - try { - SwarmItDb instance = SwarmItDb.getInstance(); - // TODO: here we check to see if a file was already submitted before re-submitting - // we should allow the user to click YES/NO to force a re-submit. - if (!instance.isPending(abstractFileId)) { - // add file info to pending submissions db - instance.newPendingSubmission(abstractFileId); - LOGGER.log(Level.FINE, String.format("Added submission to pending submissions db: abstractFileId: {0}.", - abstractFileId.toString())); - } else { - LOGGER.log(Level.INFO, "File is already pending, not re-submitting."); - JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), - Bundle.ScanAction_alreadyPending_message(), - Bundle.ScanAction_messageDialog_title(), - JOptionPane.ERROR_MESSAGE); - } - - } catch (SwarmItDbException ex) { - LOGGER.log(Level.SEVERE, "Error adding new submission data to sqlite db.", ex); - JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), - Bundle.ScanAction_dbError_message(), - Bundle.ScanAction_messageDialog_title(), - JOptionPane.ERROR_MESSAGE); - } - } - } -} +/* + * The MIT License + * + * Copyright 2018 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app.contextmenu; + +import io.polyswarm.app.datamodel.PolySwarmDb; +import io.polyswarm.app.datamodel.PolySwarmDbException; +import java.awt.event.ActionEvent; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.AbstractAction; +import javax.swing.JOptionPane; +import org.openide.windows.WindowManager; +import org.sleuthkit.datamodel.AbstractFile; + +/** + * Action added to right-click menu on an abstractFile. + */ +public class ScanAction extends AbstractAction { + + private static final long serivalVersionUID = 1L; + private static final Logger LOGGER = Logger.getLogger(ScanAction.class.getName()); + private static final int MAX_SIZE = 33554432; + private final AbstractFile abstractFile; + + ScanAction(String menuItemStr, AbstractFile abstractFile) { + super(menuItemStr); + this.abstractFile = abstractFile; + } + + @Override + @org.openide.util.NbBundle.Messages({"ScanAction.dbError.message=Failed to record submission in pending submissions database.", + "ScanAction.submitError.message=Failed to submit file to PolySwarm.", + "ScanAction.messageDialog.title=PolySwarm Scan", + "ScanAction.sendFiles.message=Scanning files requires sending the file to PolySwarm.\nDo you want to continue?", + "ScanAction.tooLarge.message=File too large to submit to PolySwarm", + "ScanAction.alreadyPending.message=This file was already submitted."}) + public void actionPerformed(ActionEvent event) { + + if (abstractFile != null) { + Long abstractFileId = abstractFile.getId(); + if (!askScanPermission()) { + return; + } + + if (!isUnderSizeLimit()) { + JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), + Bundle.ScanAction_tooLarge_message(), + Bundle.ScanAction_messageDialog_title(), + JOptionPane.ERROR_MESSAGE); + return; + } + + try { + PolySwarmDb instance = PolySwarmDb.getInstance(); + // TODO: here we check to see if a file was already submitted before re-submitting + // we should allow the user to click YES/NO to force a re-submit. + if (!instance.isPendingSubmission(abstractFileId)) { + // add file info to pending submissions db + instance.newPendingSubmission(abstractFileId); + LOGGER.log(Level.FINE, String.format("Added submission to pending submissions db: abstractFileId: {0}.", + abstractFileId.toString())); + } else { + LOGGER.log(Level.INFO, "File is already pending, not re-submitting."); + JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), + Bundle.ScanAction_alreadyPending_message(), + Bundle.ScanAction_messageDialog_title(), + JOptionPane.ERROR_MESSAGE); + } + + } catch (PolySwarmDbException ex) { + LOGGER.log(Level.SEVERE, "Error adding new submission data to sqlite db.", ex); + JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), + Bundle.ScanAction_dbError_message(), + Bundle.ScanAction_messageDialog_title(), + JOptionPane.ERROR_MESSAGE); + } + } + } + + public boolean isUnderSizeLimit() { + return abstractFile.getSize() < MAX_SIZE; + } + + public boolean askScanPermission() { + try { + if (PolySwarmDb.getInstance().isFirstScan()) { + int response = JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(), + Bundle.ScanAction_sendFiles_message(), + Bundle.ScanAction_messageDialog_title(), + JOptionPane.YES_NO_OPTION); + + if (response == JOptionPane.NO_OPTION) { + return false; + } + PolySwarmDb.getInstance().approvedScan(); + } + return true; + } catch (PolySwarmDbException ex) { + return false; + } + } +} diff --git a/swarmit/src/io/polyswarm/swarmit/datamodel/SwarmItDb.java b/polyswarm/src/io/polyswarm/app/datamodel/PolySwarmDb.java similarity index 51% rename from swarmit/src/io/polyswarm/swarmit/datamodel/SwarmItDb.java rename to polyswarm/src/io/polyswarm/app/datamodel/PolySwarmDb.java index d759375..579997c 100644 --- a/swarmit/src/io/polyswarm/swarmit/datamodel/SwarmItDb.java +++ b/polyswarm/src/io/polyswarm/app/datamodel/PolySwarmDb.java @@ -1,629 +1,834 @@ -/* - * The MIT License - * - * Copyright 2018 PolySwarm PTE. LTD. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.polyswarm.swarmit.datamodel; - -import io.polyswarm.swarmit.tasks.PendingHashLookup; -import io.polyswarm.swarmit.tasks.PendingSubmission; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.locks.ReentrantReadWriteLock; -import java.util.logging.Logger; -import org.apache.commons.dbcp2.BasicDataSource; - - -/** - * Manage the database content and connections to the database. - * - * Note: code largely based off of Autopsy's centralrepository sqlite implementation. - */ -public class SwarmItDb { - private final static Logger LOGGER = Logger.getLogger(SwarmItDb.class.getName()); - private static SwarmItDb instance; - private BasicDataSource connectionPool = null; - private final SwarmItDbSettings dbSettings; - - private final ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock(true); - - /** - * Get the singleton instance of SwarmItDb - * - * @return the singleton instance of SwarmItDb - * - * @throws SwarmItDbException - */ - public synchronized static SwarmItDb getInstance() throws SwarmItDbException { - if (instance == null) { - instance = new SwarmItDb(); - } - - return instance; - } - - /** - * Constructor. Loads db settings. - * - * @throws SwarmItDbException - */ - private SwarmItDb() throws SwarmItDbException { - dbSettings = new SwarmItDbSettings(); - dbSettings.initialize(); - } - - public void shutdownConnections() throws SwarmItDbException { - try { - synchronized (this) { - if (null != connectionPool) { - connectionPool.close(); - connectionPool = null; // for it to be re-created on next connect() - } - - } - // TODO: clearCaches(); // where did this come from? - } catch (SQLException ex) { - throw new SwarmItDbException("Failed to close existing database connections.", ex); // NON-NLS - } - } - - /** - * Setup a connection pool for sqlite db connections. - * - * @throws SwarmItDbException - */ - private void setupConnectionPool() throws SwarmItDbException { - if (dbSettings.dbFileExists() == false) { - throw new SwarmItDbException("Swarmit database missing."); // NON-NLS - } - - connectionPool = new BasicDataSource(); - connectionPool.setDriverClassName(dbSettings.getDriver()); - connectionPool.setUrl(dbSettings.getConnectionURL()); - - // adjust pool configuration - connectionPool.setInitialSize(4); - connectionPool.setMaxWaitMillis(1000); - connectionPool.setValidationQuery(dbSettings.getValidationQuery()); - connectionPool.setConnectionInitSqls(Arrays.asList("PRAGMA foreign_keys = ON")); - } - - /** - * Lazily setup Singleton connection on first connection request - * - * @return A connection from the connection pool - * - * @throws SwarmItDbException - */ - protected Connection connect() throws SwarmItDbException { - synchronized (this) { - if (connectionPool == null) { - setupConnectionPool(); - } - - try { - return connectionPool.getConnection(); - } catch (SQLException ex) { - throw new SwarmItDbException("Error getting connectin from connection pool.", ex); // NON-NLS - } - } - } - - /** - * Add a new name/value pair to the db_info table - * - * @param name Key to set - * @param value Value to set for the name/value key pair. - * - * @throws SwarmItDbException - */ - public void newDbInfo(String name, String value) throws SwarmItDbException { - try { - acquireExclusiveLock(); - - Connection conn = connect(); - - PreparedStatement preparedStatement = null; - String sql = "INSERT INTO db_info (name, value) VALUES (?, ?)"; - - try { - preparedStatement = conn.prepareStatement(sql); - preparedStatement.setString(1, name); - preparedStatement.setString(2, value); - preparedStatement.executeUpdate(); - } catch (SQLException ex) { - throw new SwarmItDbException("Error adding name/value pair to db_info.", ex); // NON-NLS - } finally { - SwarmItDbUtils.closeStatement(preparedStatement); - SwarmItDbUtils.closeConnection(conn); - } - } finally { - releaseExclusiveLock(); - } - } - - /** - * Get the value for the given name (key) from the db_info table. - * - * @param name Key to lookup - * - * @return Value associated with the name/value key pair. - * - * @throws SwarmItDbException - */ - public String getDbInfo(String name) throws SwarmItDbException { - try { - acquireSharedLock(); - - Connection conn = connect(); - - PreparedStatement preparedStatement = null; - ResultSet resultSet = null; - String value = null; - String sql = "SELECT value from db_info WHERE name=?"; - try { - preparedStatement = conn.prepareStatement(sql); - preparedStatement.setString(1, name); - resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - value = resultSet.getString("value"); - } - } catch (SQLException ex) { - throw new SwarmItDbException("Error getting value for name.", ex); // NON-NLS - } finally { - SwarmItDbUtils.closeStatement(preparedStatement); - SwarmItDbUtils.closeResultSet(resultSet); - SwarmItDbUtils.closeConnection(conn); - } - return value; - } finally { - releaseSharedLock(); - } - } - - /** - * Update the value for a name in the db_info table. - * - * @param name Key to lookup - * @param value Value to set for the name/value key pair - */ - public void updateDbInfo(String name, String value) throws SwarmItDbException { - try { - acquireExclusiveLock(); - - Connection conn = connect(); - - PreparedStatement preparedStatement = null; - String sql = "UPDATE db_info SET value=? WHERE name=?"; - try { - preparedStatement = conn.prepareStatement(sql); - preparedStatement.setString(1, value); - preparedStatement.setString(2, name); - preparedStatement.executeUpdate(); - } catch (SQLException ex) { - throw new SwarmItDbException("Error updating value for name.", ex); // NON-NLS - } finally { - SwarmItDbUtils.closeStatement(preparedStatement); - SwarmItDbUtils.closeConnection(conn); - } - } finally { - releaseExclusiveLock(); - } - } - - /** - * Add a new file to the pending_submissions table - * - * @param abstractFileId Autopsy AbstractFile ID number - * @param submissionUUID UUID returned in result of file submission to PolySwarm API - * - * @throws SwarmItDbException - */ - public void newPendingSubmission(Long abstractFileId) throws SwarmItDbException { - try { - acquireExclusiveLock(); - - Connection conn = connect(); - - PreparedStatement preparedStatement = null; - String sql = "INSERT INTO pending_submissions (abstract_file_id, submission_uuid) VALUES (?, ?)"; - - try { - preparedStatement = conn.prepareStatement(sql); - preparedStatement.setLong(1, abstractFileId); - preparedStatement.setString(2, ""); - preparedStatement.executeUpdate(); - } catch (SQLException ex) { - throw new SwarmItDbException("Error adding new file to pending_submissions table.", ex); // NON-NLS - } finally { - SwarmItDbUtils.closeStatement(preparedStatement); - SwarmItDbUtils.closeConnection(conn); - } - } finally { - releaseExclusiveLock(); - } - } - - /** - * Add a new file to the pending_submissions table - * - * @param abstractFileId Autopsy AbstractFile ID number - * @param submissionUUID UUID returned in result of file submission to PolySwarm API - * - * @throws SwarmItDbException - */ - public void newPendingSubmissionId(Long abstractFileId, String submissionUUID) throws SwarmItDbException { - try { - acquireExclusiveLock(); - - Connection conn = connect(); - - PreparedStatement preparedStatement = null; - String sql = "UPDATE pending_submissions SET submission_uuid=? WHERE abstract_file_id=?"; - - try { - preparedStatement = conn.prepareStatement(sql); - preparedStatement.setString(1, submissionUUID); - preparedStatement.setLong(2, abstractFileId); - preparedStatement.executeUpdate(); - } catch (SQLException ex) { - throw new SwarmItDbException("Error updating pending_submissions table.", ex); // NON-NLS - } finally { - SwarmItDbUtils.closeStatement(preparedStatement); - SwarmItDbUtils.closeConnection(conn); - } - } finally { - releaseExclusiveLock(); - } - } - - /** - * Check to see if a file is already in the pending_submissions table. - * - * @param abstractFileId Autopsy AbstractFile ID number - * @return Boolean true if in the table, else false. - * - * @throws SwarmItDbException - */ - public Boolean isPending(Long abstractFileId) throws SwarmItDbException { - try { - acquireSharedLock(); - - Connection conn = connect(); - - Boolean isFound = false; - PreparedStatement preparedStatement = null; - ResultSet resultSet = null; - String sql = "SELECT count(*) as quantity FROM pending_submissions WHERE abstract_file_id=?"; - try { - preparedStatement = conn.prepareStatement(sql); - preparedStatement.setLong(1, abstractFileId); - resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - Long count = resultSet.getLong("quantity"); - if (count > 0) { - isFound = true; - } - } - } catch (SQLException ex) { - throw new SwarmItDbException("Error getting all pending submissions.", ex); // NON-NLS - } finally { - SwarmItDbUtils.closeStatement(preparedStatement); - SwarmItDbUtils.closeResultSet(resultSet); - SwarmItDbUtils.closeConnection(conn); - } - return isFound; - } finally { - releaseSharedLock(); - } - } - - - /** - * Get the list of pending submissions from the pending_submissions table. - * - * @return List of SwarmItPendingSubmission's. - * - * @throws SwarmItDbException - */ - public List getPendingSubmissions() throws SwarmItDbException { - try { - acquireSharedLock(); - - Connection conn = connect(); - - List pendingSubmissions = new ArrayList<>(); - PendingSubmission psResult; - PreparedStatement preparedStatement = null; - ResultSet resultSet = null; - String sql = "SELECT abstract_file_id, submission_uuid FROM pending_submissions"; - try { - preparedStatement = conn.prepareStatement(sql); - resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - psResult = getPendingSubmissionFromResultSet(resultSet); - pendingSubmissions.add(psResult); - } - } catch (SQLException ex) { - throw new SwarmItDbException("Error getting all pending submissions.", ex); // NON-NLS - } finally { - SwarmItDbUtils.closeStatement(preparedStatement); - SwarmItDbUtils.closeResultSet(resultSet); - SwarmItDbUtils.closeConnection(conn); - } - return pendingSubmissions; - } finally { - releaseSharedLock(); - } - } - - /** - * Delete the pending submission from the pending_submissions table. - * - * @param pendingSubmission SwarmItPendingSubmission object - * - * @throws SwarmItDbException - */ - public void deletePendingSubmission(PendingSubmission pendingSubmission) throws SwarmItDbException { - try { - acquireExclusiveLock(); - - Connection conn = connect(); - - PreparedStatement preparedStatement = null; - String sql = "DELETE from pending_submissions WHERE abstract_file_id=? AND submission_uuid=?"; - try { - preparedStatement = conn.prepareStatement(sql); - preparedStatement.setLong(1, pendingSubmission.getAbstractFileId()); - preparedStatement.setString(2, pendingSubmission.getSubmissionId()); - preparedStatement.executeUpdate(); - } catch (SQLException ex) { - throw new SwarmItDbException("Error deleteing pending submission: " + pendingSubmission.toString(), ex); // NON-NLS - } finally { - SwarmItDbUtils.closeStatement(preparedStatement); - SwarmItDbUtils.closeConnection(conn); - } - } finally { - releaseExclusiveLock(); - } - } - - /** - * Convert a ResultSet into a PendingSubmission object. - * - * @param resultSet ResultSet row returned from db query - * @return PendingSubmission object - * @throws SQLException - */ - private PendingSubmission getPendingSubmissionFromResultSet(ResultSet resultSet) throws SQLException { - if (null == resultSet) { - return null; - } - - return new PendingSubmission(resultSet.getLong("abstract_file_id"), resultSet.getString("submission_uuid")); - } - - - /** - * Add a new file to the pending_hashes table - * - * @param abstractFileId Autopsy AbstractFile ID number - * @param md5Hash hash of the file - * - * @throws SwarmItDbException - */ - public void newPendingHashLookup(Long abstractFileId, String md5Hash) throws SwarmItDbException { - try { - acquireExclusiveLock(); - - Connection conn = connect(); - - PreparedStatement preparedStatement = null; - String sql = "INSERT INTO pending_hashes (abstract_file_id, md5_hash) VALUES (?, ?)"; - - try { - preparedStatement = conn.prepareStatement(sql); - preparedStatement.setLong(1, abstractFileId); - preparedStatement.setString(2, md5Hash); - preparedStatement.executeUpdate(); - } catch (SQLException ex) { - throw new SwarmItDbException("Error adding new file to pending_hashes table.", ex); // NON-NLS - } finally { - SwarmItDbUtils.closeStatement(preparedStatement); - SwarmItDbUtils.closeConnection(conn); - } - } finally { - releaseExclusiveLock(); - } - } - - - /** - * Check to see if a hash is already in the pending_hashes table. - * - * @param abstractFileId Autopsy AbstractFile ID number - * @return Boolean true if in the table, else false. - * - * @throws SwarmItDbException - */ - public Boolean isPendingHashLookup(Long abstractFileId) throws SwarmItDbException { - try { - acquireSharedLock(); - - Connection conn = connect(); - - Boolean isFound = false; - PreparedStatement preparedStatement = null; - ResultSet resultSet = null; - String sql = "SELECT count(*) as quantity FROM pending_hashes WHERE abstract_file_id=?"; - try { - preparedStatement = conn.prepareStatement(sql); - preparedStatement.setLong(1, abstractFileId); - resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - Long count = resultSet.getLong("quantity"); - if (count > 0) { - isFound = true; - } - } - } catch (SQLException ex) { - throw new SwarmItDbException("Error getting all pending hashes.", ex); // NON-NLS - } finally { - SwarmItDbUtils.closeStatement(preparedStatement); - SwarmItDbUtils.closeResultSet(resultSet); - SwarmItDbUtils.closeConnection(conn); - } - return isFound; - } finally { - releaseSharedLock(); - } - } - - - /** - * Get the list of pending hashes from the pending_hashes table. - * - * @return List of SwarmItPendingHashLookups's. - * - * @throws SwarmItDbException - */ - public List getPendingHashLookups() throws SwarmItDbException { - try { - acquireSharedLock(); - - Connection conn = connect(); - - List pendingHashLookups = new ArrayList<>(); - PendingHashLookup psResult; - PreparedStatement preparedStatement = null; - ResultSet resultSet = null; - String sql = "SELECT abstract_file_id, md5_hash FROM pending_hashes"; - try { - preparedStatement = conn.prepareStatement(sql); - resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - psResult = getPendingHashLookupFromResultSet(resultSet); - pendingHashLookups.add(psResult); - } - } catch (SQLException ex) { - throw new SwarmItDbException("Error getting all pending submissions.", ex); // NON-NLS - } finally { - SwarmItDbUtils.closeStatement(preparedStatement); - SwarmItDbUtils.closeResultSet(resultSet); - SwarmItDbUtils.closeConnection(conn); - } - return pendingHashLookups; - } finally { - releaseSharedLock(); - } - } - - - /** - * Delete the pending submission from the pending_submissions table. - * - * @param pendingSubmission SwarmItPendingSubmission object - * - * @throws SwarmItDbException - */ - public void deletePendingHashLookup(PendingHashLookup pendingHashLookup) throws SwarmItDbException { - try { - acquireExclusiveLock(); - - Connection conn = connect(); - - PreparedStatement preparedStatement = null; - String sql = "DELETE from pending_hashes WHERE abstract_file_id=? AND md5_hash=?"; - try { - preparedStatement = conn.prepareStatement(sql); - preparedStatement.setLong(1, pendingHashLookup.getAbstractFileId()); - preparedStatement.setString(2, pendingHashLookup.getMd5Hash()); - preparedStatement.executeUpdate(); - } catch (SQLException ex) { - throw new SwarmItDbException("Error deleteing pending hash look up: " + pendingHashLookup.toString(), ex); // NON-NLS - } finally { - SwarmItDbUtils.closeStatement(preparedStatement); - SwarmItDbUtils.closeConnection(conn); - } - } finally { - releaseExclusiveLock(); - } - } - - - - /** - * Convert a ResultSet into a PendingHashLookupobject. - * - * @param resultSet ResultSet row returned from db query - * @return PendingHashLookup object - * @throws SQLException - */ - private PendingHashLookup getPendingHashLookupFromResultSet(ResultSet resultSet) throws SQLException { - if (null == resultSet) { - return null; - } - - return new PendingHashLookup(resultSet.getLong("abstract_file_id"), resultSet.getString("md5_hash")); - } - - /** - * Acquire the lock that provides exclusive access to the database. - * Call this method in a try block with a call to the release method - * in an associated finally block. - */ - private void acquireExclusiveLock() { - rwLock.writeLock().lock(); - } - - /** - * Release the lock that provides exclusive access to the database. - * This method should be called in the finally block of a try block - * in which the lock was acquired. - */ - private void releaseExclusiveLock() { - rwLock.writeLock().unlock(); - } - - /** - * Acquire the lock that provides shared access to the database. - * Call this method in a try block with a call to the release method - * in an associated finally block. - */ - private void acquireSharedLock() { - rwLock.readLock().lock(); - } - - /** - * Release the lock that provides shared access to the database. - * This method should be called in the finally block of a try block - * in which the lock was acquired. - */ - private void releaseSharedLock() { - rwLock.readLock().unlock(); - } -} +/* + * The MIT License + * + * Copyright 2018 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app.datamodel; + +import io.polyswarm.app.tasks.PendingHashLookup; +import io.polyswarm.app.tasks.PendingRescan; +import io.polyswarm.app.tasks.PendingSubmission; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.logging.Logger; +import org.apache.commons.dbcp2.BasicDataSource; + +/** + * Manage the database content and connections to the database. + * + * Note: code largely based off of Autopsy's centralrepository sqlite implementation. + */ +public class PolySwarmDb { + + private final static Logger LOGGER = Logger.getLogger(PolySwarmDb.class.getName()); + private final static String FIRST_SCAN_KEY = "FIRST_SCAN"; + private static PolySwarmDb instance; + private BasicDataSource connectionPool = null; + private final PolySwarmDbSettings dbSettings; + + private final ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock(true); + + /** + * Get the singleton instance of PolySwarmDb + * + * @return the singleton instance of PolySwarmDb + * + * @throws PolySwarmDbException + */ + public synchronized static PolySwarmDb getInstance() throws PolySwarmDbException { + if (instance == null) { + instance = new PolySwarmDb(); + } + + return instance; + } + + /** + * Constructor. Loads db settings. + * + * @throws PolySwarmDbException + */ + private PolySwarmDb() throws PolySwarmDbException { + dbSettings = new PolySwarmDbSettings(); + dbSettings.initialize(); + } + + public void shutdownConnections() throws PolySwarmDbException { + try { + synchronized (this) { + if (null != connectionPool) { + connectionPool.close(); + connectionPool = null; // for it to be re-created on next connect() + } + + } + // TODO: clearCaches(); // where did this come from? + } catch (SQLException ex) { + throw new PolySwarmDbException("Failed to close existing database connections.", ex); // NON-NLS + } + } + + /** + * Setup a connection pool for sqlite db connections. + * + * @throws PolySwarmDbException + */ + private void setupConnectionPool() throws PolySwarmDbException { + if (dbSettings.dbFileExists() == false) { + throw new PolySwarmDbException("PolySwarm database missing."); // NON-NLS + } + + connectionPool = new BasicDataSource(); + connectionPool.setDriverClassName(dbSettings.getDriver()); + connectionPool.setUrl(dbSettings.getConnectionURL()); + + // adjust pool configuration + connectionPool.setInitialSize(4); + connectionPool.setMaxWaitMillis(1000); + connectionPool.setValidationQuery(dbSettings.getValidationQuery()); + connectionPool.setConnectionInitSqls(Arrays.asList("PRAGMA foreign_keys = ON")); + } + + /** + * Lazily setup Singleton connection on first connection request + * + * @return A connection from the connection pool + * + * @throws PolySwarmDbException + */ + protected Connection connect() throws PolySwarmDbException { + synchronized (this) { + if (connectionPool == null) { + setupConnectionPool(); + } + + try { + return connectionPool.getConnection(); + } catch (SQLException ex) { + throw new PolySwarmDbException("Error getting connectin from connection pool.", ex); // NON-NLS + } + } + } + + /** + * Check if any scans have been performed + * + * @return boolean, true if first scan + */ + public boolean isFirstScan() { + try { + String value = getDbInfo(FIRST_SCAN_KEY); + return value == null; + } catch (PolySwarmDbException e) { + return true; + } + } + + /** + * Mark that a scan has been performed + * + */ + public void approvedScan() throws PolySwarmDbException { + newDbInfo(FIRST_SCAN_KEY, ""); + } + + /** + * Add a new name/value pair to the db_info table + * + * @param name Key to set + * @param value Value to set for the name/value key pair. + * + * @throws PolySwarmDbException + */ + public void newDbInfo(String name, String value) throws PolySwarmDbException { + try { + acquireExclusiveLock(); + + Connection conn = connect(); + + PreparedStatement preparedStatement = null; + String sql = "INSERT INTO db_info (name, value) VALUES (?, ?)"; + + try { + preparedStatement = conn.prepareStatement(sql); + preparedStatement.setString(1, name); + preparedStatement.setString(2, value); + preparedStatement.executeUpdate(); + } catch (SQLException ex) { + throw new PolySwarmDbException("Error adding name/value pair to db_info.", ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeConnection(conn); + } + } finally { + releaseExclusiveLock(); + } + } + + /** + * Get the value for the given name (key) from the db_info table. + * + * @param name Key to lookup + * + * @return Value associated with the name/value key pair. + * + * @throws PolySwarmDbException + */ + public String getDbInfo(String name) throws PolySwarmDbException { + try { + acquireSharedLock(); + + Connection conn = connect(); + + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + String value = null; + String sql = "SELECT value from db_info WHERE name=?"; + try { + preparedStatement = conn.prepareStatement(sql); + preparedStatement.setString(1, name); + resultSet = preparedStatement.executeQuery(); + if (resultSet.next()) { + value = resultSet.getString("value"); + } + } catch (SQLException ex) { + throw new PolySwarmDbException("Error getting value for name.", ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeResultSet(resultSet); + PolySwarmDbUtils.closeConnection(conn); + } + return value; + } finally { + releaseSharedLock(); + } + } + + /** + * Update the value for a name in the db_info table. + * + * @param name Key to lookup + * @param value Value to set for the name/value key pair + */ + public void updateDbInfo(String name, String value) throws PolySwarmDbException { + try { + acquireExclusiveLock(); + + Connection conn = connect(); + + PreparedStatement preparedStatement = null; + String sql = "UPDATE db_info SET value=? WHERE name=?"; + try { + preparedStatement = conn.prepareStatement(sql); + preparedStatement.setString(1, value); + preparedStatement.setString(2, name); + preparedStatement.executeUpdate(); + } catch (SQLException ex) { + throw new PolySwarmDbException("Error updating value for name.", ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeConnection(conn); + } + } finally { + releaseExclusiveLock(); + } + } + + /** + * Add a new file to the pending_submissions table + * + * @param abstractFileId Autopsy AbstractFile ID number + * @param submissionUUID UUID returned in result of file submission to PolySwarm API + * + * @throws PolySwarmDbException + */ + public void newPendingSubmission(Long abstractFileId) throws PolySwarmDbException { + try { + acquireExclusiveLock(); + + Connection conn = connect(); + + PreparedStatement preparedStatement = null; + String sql = "INSERT INTO pending_submissions (abstract_file_id, submission_uuid) VALUES (?, ?)"; + + try { + preparedStatement = conn.prepareStatement(sql); + preparedStatement.setLong(1, abstractFileId); + preparedStatement.setString(2, ""); + preparedStatement.executeUpdate(); + } catch (SQLException ex) { + throw new PolySwarmDbException("Error adding new file to pending_submissions table.", ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeConnection(conn); + } + } finally { + releaseExclusiveLock(); + } + } + + /** + * Add a new file to the pending_submissions table + * + * @param abstractFileId Autopsy AbstractFile ID number + * @param submissionUUID UUID returned in result of file submission to PolySwarm API + * + * @throws PolySwarmDbException + */ + public void updatePendingSubmissionId(Long abstractFileId, String submissionUUID) throws PolySwarmDbException { + try { + acquireExclusiveLock(); + + Connection conn = connect(); + + PreparedStatement preparedStatement = null; + String sql = "UPDATE pending_submissions SET submission_uuid=? WHERE abstract_file_id=?"; + + try { + preparedStatement = conn.prepareStatement(sql); + preparedStatement.setString(1, submissionUUID); + preparedStatement.setLong(2, abstractFileId); + preparedStatement.executeUpdate(); + } catch (SQLException ex) { + throw new PolySwarmDbException("Error updating pending_submissions table.", ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeConnection(conn); + } + } finally { + releaseExclusiveLock(); + } + } + + /** + * Check to see if a file is already in the pending_submissions table. + * + * @param abstractFileId Autopsy AbstractFile ID number + * @return Boolean true if in the table, else false. + * + * @throws PolySwarmDbException + */ + public Boolean isPendingSubmission(Long abstractFileId) throws PolySwarmDbException { + try { + acquireSharedLock(); + + Connection conn = connect(); + + Boolean isFound = false; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + String sql = "SELECT count(*) as quantity FROM pending_submissions WHERE abstract_file_id=?"; + try { + preparedStatement = conn.prepareStatement(sql); + preparedStatement.setLong(1, abstractFileId); + resultSet = preparedStatement.executeQuery(); + if (resultSet.next()) { + Long count = resultSet.getLong("quantity"); + if (count > 0) { + isFound = true; + } + } + } catch (SQLException ex) { + throw new PolySwarmDbException("Error getting all pending submissions.", ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeResultSet(resultSet); + PolySwarmDbUtils.closeConnection(conn); + } + return isFound; + } finally { + releaseSharedLock(); + } + } + + /** + * Get the list of pending submissions from the pending_submissions table. + * + * @return List of PendingSubmission's. + * + * @throws PolySwarmDbException + */ + public List getPendingSubmissions() throws PolySwarmDbException { + try { + acquireSharedLock(); + + Connection conn = connect(); + + List pendingSubmissions = new ArrayList<>(); + PendingSubmission psResult; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + String sql = "SELECT abstract_file_id, submission_uuid FROM pending_submissions"; + try { + preparedStatement = conn.prepareStatement(sql); + resultSet = preparedStatement.executeQuery(); + if (resultSet.next()) { + psResult = getPendingSubmissionFromResultSet(resultSet); + pendingSubmissions.add(psResult); + } + } catch (SQLException ex) { + throw new PolySwarmDbException("Error getting all pending submissions.", ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeResultSet(resultSet); + PolySwarmDbUtils.closeConnection(conn); + } + return pendingSubmissions; + } finally { + releaseSharedLock(); + } + } + + /** + * Delete the pending submission from the pending_submissions table. + * + * @param pendingSubmission PendingSubmission object + * + * @throws PolySwarmDbException + */ + public void deletePendingSubmission(PendingSubmission pendingSubmission) throws PolySwarmDbException { + try { + acquireExclusiveLock(); + + Connection conn = connect(); + + PreparedStatement preparedStatement = null; + String sql = "DELETE from pending_submissions WHERE abstract_file_id=? AND submission_uuid=?"; + try { + preparedStatement = conn.prepareStatement(sql); + preparedStatement.setLong(1, pendingSubmission.getAbstractFileId()); + preparedStatement.setString(2, pendingSubmission.getSubmissionId()); + preparedStatement.executeUpdate(); + } catch (SQLException ex) { + throw new PolySwarmDbException("Error deleteing pending submission: " + pendingSubmission.toString(), ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeConnection(conn); + } + } finally { + releaseExclusiveLock(); + } + } + + /** + * Convert a ResultSet into a PendingSubmission object. + * + * @param resultSet ResultSet row returned from db query + * @return PendingSubmission object + * @throws SQLException + */ + private PendingSubmission getPendingSubmissionFromResultSet(ResultSet resultSet) throws SQLException { + if (null == resultSet) { + return null; + } + + return new PendingSubmission(resultSet.getLong("abstract_file_id"), resultSet.getString("submission_uuid")); + } + + /** + * Add a new file to the pending_submissions table + * + * @param abstractFileId Autopsy AbstractFile ID number + * @param submissionUUID UUID returned in result of file submission to PolySwarm API + * + * @throws PolySwarmDbException + */ + public void newPendingRescan(Long abstractFileId, String sha256Hash) throws PolySwarmDbException { + try { + acquireExclusiveLock(); + + Connection conn = connect(); + + PreparedStatement preparedStatement = null; + String sql = "INSERT INTO pending_rescans (abstract_file_id, sha256_hash, rescan_uuid) VALUES (?, ?, ?)"; + + try { + preparedStatement = conn.prepareStatement(sql); + preparedStatement.setLong(1, abstractFileId); + preparedStatement.setString(2, sha256Hash); + preparedStatement.setString(3, ""); + preparedStatement.executeUpdate(); + } catch (SQLException ex) { + throw new PolySwarmDbException("Error adding new file to pending_rescans table.", ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeConnection(conn); + } + } finally { + releaseExclusiveLock(); + } + } + + /** + * Add a new file to the pending_submissions table + * + * @param abstractFileId Autopsy AbstractFile ID number + * @param rescanUuid UUID returned in result of file submission to PolySwarm API + * + * @throws PolySwarmDbException + */ + public void updatePendingRescanId(Long abstractFileId, String rescanUuid) throws PolySwarmDbException { + try { + acquireExclusiveLock(); + + Connection conn = connect(); + + PreparedStatement preparedStatement = null; + String sql = "UPDATE pending_rescans SET rescan_uuid=? WHERE abstract_file_id=?"; + + try { + preparedStatement = conn.prepareStatement(sql); + preparedStatement.setString(1, rescanUuid); + preparedStatement.setLong(2, abstractFileId); + preparedStatement.executeUpdate(); + } catch (SQLException ex) { + throw new PolySwarmDbException("Error updating pending_rescans table.", ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeConnection(conn); + } + } finally { + releaseExclusiveLock(); + } + } + + /** + * Check to see if a file is already in the pending_submissions table. + * + * @param abstractFileId Autopsy AbstractFile ID number + * @return Boolean true if in the table, else false. + * + * @throws PolySwarmDbException + */ + public Boolean isPendingRescan(Long abstractFileId) throws PolySwarmDbException { + try { + acquireSharedLock(); + + Connection conn = connect(); + + Boolean isFound = false; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + String sql = "SELECT count(*) as quantity FROM pending_rescans WHERE abstract_file_id=?"; + try { + preparedStatement = conn.prepareStatement(sql); + preparedStatement.setLong(1, abstractFileId); + resultSet = preparedStatement.executeQuery(); + if (resultSet.next()) { + Long count = resultSet.getLong("quantity"); + if (count > 0) { + isFound = true; + } + } + } catch (SQLException ex) { + throw new PolySwarmDbException("Error getting all pending rescans.", ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeResultSet(resultSet); + PolySwarmDbUtils.closeConnection(conn); + } + return isFound; + } finally { + releaseSharedLock(); + } + } + + /** + * Get the list of pending submissions from the pending_submissions table. + * + * @return List of PendingSubmission's. + * + * @throws PolySwarmDbException + */ + public List getPendingRescans() throws PolySwarmDbException { + try { + acquireSharedLock(); + + Connection conn = connect(); + + List pendingRescans = new ArrayList<>(); + PendingRescan psResult; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + String sql = "SELECT abstract_file_id, sha256_hash, rescan_uuid FROM pending_rescans"; + try { + preparedStatement = conn.prepareStatement(sql); + resultSet = preparedStatement.executeQuery(); + if (resultSet.next()) { + psResult = getPendingRescanFromResultSet(resultSet); + pendingRescans.add(psResult); + } + } catch (SQLException ex) { + throw new PolySwarmDbException("Error getting all pending rescans.", ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeResultSet(resultSet); + PolySwarmDbUtils.closeConnection(conn); + } + return pendingRescans; + } finally { + releaseSharedLock(); + } + } + + /** + * Delete the pending submission from the pending_submissions table. + * + * @param pendingRescan PendingRescan object + * + * @throws PolySwarmDbException + */ + public void deletePendingRescan(PendingRescan pendingRescan) throws PolySwarmDbException { + try { + acquireExclusiveLock(); + + Connection conn = connect(); + + PreparedStatement preparedStatement = null; + String sql = "DELETE from pending_rescans WHERE abstract_file_id=? AND rescan_uuid=?"; + try { + preparedStatement = conn.prepareStatement(sql); + preparedStatement.setLong(1, pendingRescan.getAbstractFileId()); + preparedStatement.setString(2, pendingRescan.getRescanId()); + preparedStatement.executeUpdate(); + } catch (SQLException ex) { + throw new PolySwarmDbException("Error deleteing pending submission: " + pendingRescan.toString(), ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeConnection(conn); + } + } finally { + releaseExclusiveLock(); + } + } + + /** + * Convert a ResultSet into a PendingSubmission object. + * + * @param resultSet ResultSet row returned from db query + * @return PendingSubmission object + * @throws SQLException + */ + private PendingRescan getPendingRescanFromResultSet(ResultSet resultSet) throws SQLException { + if (null == resultSet) { + return null; + } + + return new PendingRescan(resultSet.getLong("abstract_file_id"), resultSet.getString("sha256_hash"), resultSet.getString("rescan_uuid")); + } + + /** + * Add a new file to the pending_hashes table + * + * @param abstractFileId Autopsy AbstractFile ID number + * @param md5Hash hash of the file + * + * @throws PolySwarmDbException + */ + public void newPendingHashLookup(Long abstractFileId, String md5Hash) throws PolySwarmDbException { + try { + acquireExclusiveLock(); + + Connection conn = connect(); + + PreparedStatement preparedStatement = null; + String sql = "INSERT INTO pending_hashes (abstract_file_id, md5_hash) VALUES (?, ?)"; + + try { + preparedStatement = conn.prepareStatement(sql); + preparedStatement.setLong(1, abstractFileId); + preparedStatement.setString(2, md5Hash); + preparedStatement.executeUpdate(); + } catch (SQLException ex) { + throw new PolySwarmDbException("Error adding new file to pending_hashes table.", ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeConnection(conn); + } + } finally { + releaseExclusiveLock(); + } + } + + /** + * Check to see if a hash is already in the pending_hashes table. + * + * @param abstractFileId Autopsy AbstractFile ID number + * @return Boolean true if in the table, else false. + * + * @throws PolySwarmDbException + */ + public Boolean isPendingHashLookup(Long abstractFileId) throws PolySwarmDbException { + try { + acquireSharedLock(); + + Connection conn = connect(); + + Boolean isFound = false; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + String sql = "SELECT count(*) as quantity FROM pending_hashes WHERE abstract_file_id=?"; + try { + preparedStatement = conn.prepareStatement(sql); + preparedStatement.setLong(1, abstractFileId); + resultSet = preparedStatement.executeQuery(); + if (resultSet.next()) { + Long count = resultSet.getLong("quantity"); + if (count > 0) { + isFound = true; + } + } + } catch (SQLException ex) { + throw new PolySwarmDbException("Error getting all pending hashes.", ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeResultSet(resultSet); + PolySwarmDbUtils.closeConnection(conn); + } + return isFound; + } finally { + releaseSharedLock(); + } + } + + /** + * Get the list of pending hashes from the pending_hashes table. + * + * @return List of PendingHashLookups's. + * + * @throws PolySwarmDbException + */ + public List getPendingHashLookups() throws PolySwarmDbException { + try { + acquireSharedLock(); + + Connection conn = connect(); + + List pendingHashLookups = new ArrayList<>(); + PendingHashLookup psResult; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + String sql = "SELECT abstract_file_id, md5_hash FROM pending_hashes"; + try { + preparedStatement = conn.prepareStatement(sql); + resultSet = preparedStatement.executeQuery(); + if (resultSet.next()) { + psResult = getPendingHashLookupFromResultSet(resultSet); + pendingHashLookups.add(psResult); + } + } catch (SQLException ex) { + throw new PolySwarmDbException("Error getting all pending submissions.", ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeResultSet(resultSet); + PolySwarmDbUtils.closeConnection(conn); + } + return pendingHashLookups; + } finally { + releaseSharedLock(); + } + } + + /** + * Delete the pending submission from the pending_submissions table. + * + * @param pendingSubmission PendingSubmission object + * + * @throws PolySwarmDbException + */ + public void deletePendingHashLookup(PendingHashLookup pendingHashLookup) throws PolySwarmDbException { + try { + acquireExclusiveLock(); + + Connection conn = connect(); + + PreparedStatement preparedStatement = null; + String sql = "DELETE from pending_hashes WHERE abstract_file_id=? AND md5_hash=?"; + try { + preparedStatement = conn.prepareStatement(sql); + preparedStatement.setLong(1, pendingHashLookup.getAbstractFileId()); + preparedStatement.setString(2, pendingHashLookup.getMd5Hash()); + preparedStatement.executeUpdate(); + } catch (SQLException ex) { + throw new PolySwarmDbException("Error deleteing pending hash look up: " + pendingHashLookup.toString(), ex); // NON-NLS + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeConnection(conn); + } + } finally { + releaseExclusiveLock(); + } + } + + /** + * Convert a ResultSet into a PendingHashLookupobject. + * + * @param resultSet ResultSet row returned from db query + * @return PendingHashLookup object + * @throws SQLException + */ + private PendingHashLookup getPendingHashLookupFromResultSet(ResultSet resultSet) throws SQLException { + if (null == resultSet) { + return null; + } + + return new PendingHashLookup(resultSet.getLong("abstract_file_id"), resultSet.getString("md5_hash")); + } + + /** + * Acquire the lock that provides exclusive access to the database. Call this method in a try block with a call to + * the release method in an associated finally block. + */ + private void acquireExclusiveLock() { + rwLock.writeLock().lock(); + } + + /** + * Release the lock that provides exclusive access to the database. This method should be called in the finally + * block of a try block in which the lock was acquired. + */ + private void releaseExclusiveLock() { + rwLock.writeLock().unlock(); + } + + /** + * Acquire the lock that provides shared access to the database. Call this method in a try block with a call to the + * release method in an associated finally block. + */ + private void acquireSharedLock() { + rwLock.readLock().lock(); + } + + /** + * Release the lock that provides shared access to the database. This method should be called in the finally block + * of a try block in which the lock was acquired. + */ + private void releaseSharedLock() { + rwLock.readLock().unlock(); + } +} diff --git a/swarmit/src/io/polyswarm/swarmit/datamodel/SwarmItDbException.java b/polyswarm/src/io/polyswarm/app/datamodel/PolySwarmDbException.java similarity index 86% rename from swarmit/src/io/polyswarm/swarmit/datamodel/SwarmItDbException.java rename to polyswarm/src/io/polyswarm/app/datamodel/PolySwarmDbException.java index fb315ec..c572642 100644 --- a/swarmit/src/io/polyswarm/swarmit/datamodel/SwarmItDbException.java +++ b/polyswarm/src/io/polyswarm/app/datamodel/PolySwarmDbException.java @@ -1,50 +1,50 @@ -/* - * The MIT License - * - * Copyright 2018 PolySwarm PTE. LTD. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.polyswarm.swarmit.datamodel; - -/** - * An exception thrown by sqlite db settings. - */ -public class SwarmItDbException extends Exception { - - private static final long serialVersionUID = 1L; - - /** - * COnstructs an exception to be thrown - * @param message The exception message - */ - public SwarmItDbException(String message) { - super(message); - } - - /** - * Construction an exception to be thrown - * - * @param message The exception message - * @param cause The exception cause - */ - public SwarmItDbException(String message, Throwable cause) { - super(message, cause); - } -} +/* + * The MIT License + * + * Copyright 2018 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app.datamodel; + +/** + * An exception thrown by sqlite db settings. + */ +public class PolySwarmDbException extends Exception { + + private static final long serialVersionUID = 1L; + + /** + * COnstructs an exception to be thrown + * @param message The exception message + */ + public PolySwarmDbException(String message) { + super(message); + } + + /** + * Construction an exception to be thrown + * + * @param message The exception message + * @param cause The exception cause + */ + public PolySwarmDbException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/swarmit/src/io/polyswarm/swarmit/datamodel/SwarmItDbSettings.java b/polyswarm/src/io/polyswarm/app/datamodel/PolySwarmDbSettings.java similarity index 84% rename from swarmit/src/io/polyswarm/swarmit/datamodel/SwarmItDbSettings.java rename to polyswarm/src/io/polyswarm/app/datamodel/PolySwarmDbSettings.java index 70a6bc4..0cedc6b 100644 --- a/swarmit/src/io/polyswarm/swarmit/datamodel/SwarmItDbSettings.java +++ b/polyswarm/src/io/polyswarm/app/datamodel/PolySwarmDbSettings.java @@ -1,302 +1,305 @@ -/* - * The MIT License - * - * Copyright 2018 PolySwarm PTE. LTD. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.polyswarm.swarmit.datamodel; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.InvalidPathException; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; - -/** - * Manage settings for the sqlite db it uses. - * - * REQUIRES AN OPEN CASE! - */ -public final class SwarmItDbSettings { - - private final static Logger LOGGER = Logger.getLogger(SwarmItDbSettings.class.getName()); - private final String DB_NAME = "swarmit.db"; // NON-NLS - private final String DB_DIRECTORY_NAME = "polyswarm"; // NON-NLS - private final String JDBC_DRIVER = "org.sqlite.JDBC"; // NON-NLS - private final String JDBC_BASE_URI = "jdbc:sqlite:"; // NON-NLS - private final String VALIDATION_QUERY = "SELECT count(*) from sqlite_master"; // NON-NLS - private static final Integer DB_SCHEMA_VERSION_MAJOR = 1; - private static final Integer DB_SCHEMA_VERSION_MINOR = 1; - private static final String PRAGMA_SYNC_OFF = "PRAGMA synchronous = OFF"; // NON-NLS - private static final String PRAGMA_SYNC_NORMAL = "PRAGMA synchronous = NORMAL"; // NON-NLS - private static final String PRAGMA_JOURNAL_WAL = "PRAGMA journal_mode = WAL"; // NON-NLS - private static final String PRAGMA_READ_UNCOMMITTED_TRUE = "PRAGMA read_uncommitted = True"; // NON-NLS - private static final String PRAGMA_ENCODING_UTF8 = "PRAGMA encoding = 'UTF-8'"; // NON-NLS - private static final String PRAGMA_PAGE_SIZE_4096 = "PRAGMA page_size = 4096"; // NON-NLS - private String baseDirPath; - - public SwarmItDbSettings() { - - } - - public boolean initialize() { - try { - baseDirPath = Case.getCurrentCaseThrows().getModuleDirectory(); - } catch (NoCurrentCaseException ex) { - LOGGER.log(Level.SEVERE, "Cannot determine base directory for sqlite db. Case is not open.", ex); // NON-NLS - return false; - } - - if (createDbDirectory() == false) { - LOGGER.log(Level.SEVERE, "Unable to initialize sqlite db. Failed to create base directory."); // NON-NLS - return false; - } - - boolean result = initializeDatabaseSchema() && insertDefaultDatabaseContent(); - if (result == false) { - LOGGER.log(Level.SEVERE, "Unable to initialize sqlite db."); // NON-NLS - } - return result; - - } - - private boolean createDbDirectory() { - if (!dbDirectoryExists()) { - try { - File dbDir = new File(getDbDirectory()); - Files.createDirectories(dbDir.toPath()); - LOGGER.log(Level.INFO, "sqlite directory did not exist, create it at {0}.", getDbDirectory()); // NON-NLS - } catch (IOException | InvalidPathException | SecurityException exs) { - LOGGER.log(Level.SEVERE, "Failed to create sqlite database directory.", exs); // NON-NLS - return false; - } - } - return true; - } - - /** - * Determine whether the db file exists. - * - * @return true if exists, else false - */ - public boolean dbFileExists() { - File dbFile = new File(getDbFilePath()); - if (! dbFile.exists()) { - return false; - } - return ( ! dbFile.isDirectory()); - } - - /** - * Get the full path to the db file in the db directory. - * - * @return Full path - */ - private String getDbFilePath() { - return getDbDirectory() + File.separator + DB_NAME; - } - - /** - * Determine whether the db directory exists. - * - * @return true if exists, else false - */ - private boolean dbDirectoryExists() { - File dbDir = new File(getDbDirectory()); - - if (!dbDir.exists()) { - return false; - } else if (!dbDir.isDirectory()) { - return false; - } - return true; - } - - /** - * Get the full path to the db directory. - * - * @return Full path - */ - private String getDbDirectory() { - return baseDirPath + File.separator + DB_DIRECTORY_NAME; - } - - public String getConnectionURL() { - StringBuilder connUrl = new StringBuilder(); - connUrl.append(getJDBCBaseURI()); - connUrl.append(getDbFilePath()); - return connUrl.toString(); - } - - /** - * Get an ephemeral client connection for db initialization and testing. - * - * @return Connection or null - */ - private Connection getEphemeralConnection() { - if (!dbDirectoryExists()) { - return null; - } - - Connection conn; - try { - String url = getConnectionURL(); - Class.forName(getDriver()); - conn = DriverManager.getConnection(url); - } catch (ClassNotFoundException | SQLException ex) { - LOGGER.log(Level.SEVERE, "Failed to acquire ephemeral connection to sqlite.", ex); // NON-NLS - conn = null; - } - - return conn; - } - - /** - * Verify connection to the database - * - * @return true if successful connection, else false - */ - public boolean verifyConnection() { - Connection conn = getEphemeralConnection(); - if (null == conn) { - return false; - } - - boolean result = SwarmItDbUtils.executeValidationQuery(conn, VALIDATION_QUERY); - SwarmItDbUtils.closeConnection(conn); - return result; - } - - public boolean verifyDatabaseSchema() { - Connection conn = getEphemeralConnection(); - if (null == conn) { - return false; - } - - boolean result = SwarmItDbUtils.schemaVersionIsSet(conn); - SwarmItDbUtils.closeConnection(conn); - return result; - } - - private boolean initializeDatabaseSchema() { - - StringBuilder createPendingSubmissionsTable = new StringBuilder(); - createPendingSubmissionsTable.append("CREATE TABLE IF NOT EXISTS pending_submissions ("); - createPendingSubmissionsTable.append("id integer primary key autoincrement NOT NULL,"); - createPendingSubmissionsTable.append("abstract_file_id integer NOT NULL,"); - createPendingSubmissionsTable.append("submission_uuid text NOT NULL,"); - createPendingSubmissionsTable.append("CONSTRAINT abstract_file_id_unique UNIQUE (abstract_file_id)"); - createPendingSubmissionsTable.append(")"); - - StringBuilder createDbInfoTable = new StringBuilder(); - createDbInfoTable.append("CREATE TABLE IF NOT EXISTS db_info ("); - createDbInfoTable.append("id integer primary key NOT NULL,"); - createDbInfoTable.append("name text NOT NULL,"); - createDbInfoTable.append("value text NOT NULL"); - createDbInfoTable.append(")"); - - - StringBuilder createPendingHashLookupTable = new StringBuilder(); - createPendingHashLookupTable.append("CREATE TABLE IF NOT EXISTS pending_hashes("); - createPendingHashLookupTable.append("id integer primary key autoincrement NOT NULL,"); - createPendingHashLookupTable.append("abstract_file_id integer NOT NULL,"); - createPendingHashLookupTable.append("md5_hash text NOT NULL,"); - createPendingHashLookupTable.append("CONSTRAINT abstract_file_id_unique UNIQUE (abstract_file_id)"); - createPendingHashLookupTable.append(")"); - - Connection conn = null; - try { - conn = getEphemeralConnection(); - if (null == conn) { - return false; - } - - Statement stmt = conn.createStatement(); - stmt.execute(PRAGMA_JOURNAL_WAL); - stmt.execute(PRAGMA_SYNC_OFF); - stmt.execute(PRAGMA_READ_UNCOMMITTED_TRUE); - stmt.execute(PRAGMA_ENCODING_UTF8); - stmt.execute(PRAGMA_PAGE_SIZE_4096); - - stmt.execute(createPendingSubmissionsTable.toString()); - stmt.execute(createDbInfoTable.toString()); - stmt.execute(createPendingHashLookupTable.toString()); - - } catch (SQLException ex) { - LOGGER.log(Level.SEVERE, "Failed to initialize sqlite db schema.", ex); // NON-NLS - return false; - } finally { - SwarmItDbUtils.closeConnection(conn); - } - - return true; - } - - /** - * Insert initial/default content into the database. - * Here we insert the database schema major and minor version. - * - * @return true on success, else false - */ - private boolean insertDefaultDatabaseContent() { - - Connection conn = null; - try { - conn = getEphemeralConnection(); - if (null == conn) { - return false; - } - - return SwarmItDbUtils.updateSchemaVersion(conn, - DB_SCHEMA_VERSION_MAJOR.toString(), - DB_SCHEMA_VERSION_MINOR.toString()); - } finally { - SwarmItDbUtils.closeConnection(conn); - } - } - - /** - * @return the DRIVER - */ - String getDriver() { - return JDBC_DRIVER; - } - - /** - * @return the VALIDATION_QUERY - */ - String getValidationQuery() { - return VALIDATION_QUERY; - } - - /** - * @return the JDBC_BASE_URI - */ - String getJDBCBaseURI() { - return JDBC_BASE_URI; - } -} +/* + * The MIT License + * + * Copyright 2018 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app.datamodel; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.InvalidPathException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; + +/** + * Manage settings for the sqlite db it uses. + * + * REQUIRES AN OPEN CASE! + */ +public final class PolySwarmDbSettings { + + private final static Logger LOGGER = Logger.getLogger(PolySwarmDbSettings.class.getName()); + private final String DB_NAME = "polyswarm.db"; // NON-NLS + private final String DB_DIRECTORY_NAME = "polyswarm"; // NON-NLS + private final String JDBC_DRIVER = "org.sqlite.JDBC"; // NON-NLS + private final String JDBC_BASE_URI = "jdbc:sqlite:"; // NON-NLS + private final String VALIDATION_QUERY = "SELECT count(*) from sqlite_master"; // NON-NLS + private static final Integer DB_SCHEMA_VERSION_MAJOR = 1; + private static final Integer DB_SCHEMA_VERSION_MINOR = 1; + private static final String PRAGMA_SYNC_OFF = "PRAGMA synchronous = OFF"; // NON-NLS + private static final String PRAGMA_SYNC_NORMAL = "PRAGMA synchronous = NORMAL"; // NON-NLS + private static final String PRAGMA_JOURNAL_WAL = "PRAGMA journal_mode = WAL"; // NON-NLS + private static final String PRAGMA_READ_UNCOMMITTED_TRUE = "PRAGMA read_uncommitted = True"; // NON-NLS + private static final String PRAGMA_ENCODING_UTF8 = "PRAGMA encoding = 'UTF-8'"; // NON-NLS + private static final String PRAGMA_PAGE_SIZE_4096 = "PRAGMA page_size = 4096"; // NON-NLS + private String baseDirPath; + + public PolySwarmDbSettings() { + + } + + public boolean initialize() { + try { + baseDirPath = Case.getCurrentCaseThrows().getModuleDirectory(); + } catch (NoCurrentCaseException ex) { + LOGGER.log(Level.SEVERE, "Cannot determine base directory for sqlite db. Case is not open.", ex); // NON-NLS + return false; + } + + if (!createDbDirectory()) { + LOGGER.log(Level.SEVERE, "Unable to initialize sqlite db. Failed to create base directory."); // NON-NLS + return false; + } + + boolean result = initializeDatabaseSchema() && insertDefaultDatabaseContent(); + if (!result) { + LOGGER.log(Level.SEVERE, "Unable to initialize sqlite db."); // NON-NLS + } + return result; + + } + + private boolean createDbDirectory() { + if (!dbDirectoryExists()) { + try { + File dbDir = new File(getDbDirectory()); + Files.createDirectories(dbDir.toPath()); + LOGGER.log(Level.INFO, "sqlite directory did not exist, create it at {0}.", getDbDirectory()); // NON-NLS + } catch (IOException | InvalidPathException | SecurityException exs) { + LOGGER.log(Level.SEVERE, "Failed to create sqlite database directory.", exs); // NON-NLS + return false; + } + } + return true; + } + + /** + * Determine whether the db file exists. + * + * @return true if exists, else false + */ + public boolean dbFileExists() { + File dbFile = new File(getDbFilePath()); + if (!dbFile.exists()) { + return false; + } + return (!dbFile.isDirectory()); + } + + /** + * Get the full path to the db file in the db directory. + * + * @return Full path + */ + private String getDbFilePath() { + return getDbDirectory() + File.separator + DB_NAME; + } + + /** + * Determine whether the db directory exists. + * + * @return true if exists, else false + */ + private boolean dbDirectoryExists() { + File dbDir = new File(getDbDirectory()); + + return dbDir.exists() && dbDir.isDirectory(); + } + + /** + * Get the full path to the db directory. + * + * @return Full path + */ + private String getDbDirectory() { + return baseDirPath + File.separator + DB_DIRECTORY_NAME; + } + + public String getConnectionURL() { + StringBuilder connUrl = new StringBuilder(); + connUrl.append(getJDBCBaseURI()); + connUrl.append(getDbFilePath()); + return connUrl.toString(); + } + + /** + * Get an ephemeral client connection for db initialization and testing. + * + * @return Connection or null + */ + private Connection getEphemeralConnection() { + if (!dbDirectoryExists()) { + return null; + } + + Connection conn; + try { + String url = getConnectionURL(); + Class.forName(getDriver()); + conn = DriverManager.getConnection(url); + } catch (ClassNotFoundException | SQLException ex) { + LOGGER.log(Level.SEVERE, "Failed to acquire ephemeral connection to sqlite.", ex); // NON-NLS + conn = null; + } + + return conn; + } + + /** + * Verify connection to the database + * + * @return true if successful connection, else false + */ + public boolean verifyConnection() { + Connection conn = getEphemeralConnection(); + if (null == conn) { + return false; + } + + boolean result = PolySwarmDbUtils.executeValidationQuery(conn, VALIDATION_QUERY); + PolySwarmDbUtils.closeConnection(conn); + return result; + } + + public boolean verifyDatabaseSchema() { + Connection conn = getEphemeralConnection(); + if (null == conn) { + return false; + } + + boolean result = PolySwarmDbUtils.schemaVersionIsSet(conn); + PolySwarmDbUtils.closeConnection(conn); + return result; + } + + private boolean initializeDatabaseSchema() { + + StringBuilder createPendingSubmissionsTable = new StringBuilder(); + createPendingSubmissionsTable.append("CREATE TABLE IF NOT EXISTS pending_submissions ("); + createPendingSubmissionsTable.append("id integer primary key autoincrement NOT NULL,"); + createPendingSubmissionsTable.append("abstract_file_id integer NOT NULL,"); + createPendingSubmissionsTable.append("submission_uuid text NOT NULL,"); + createPendingSubmissionsTable.append("CONSTRAINT abstract_file_id_unique UNIQUE (abstract_file_id)"); + createPendingSubmissionsTable.append(")"); + + StringBuilder createDbInfoTable = new StringBuilder(); + createDbInfoTable.append("CREATE TABLE IF NOT EXISTS db_info ("); + createDbInfoTable.append("id integer primary key NOT NULL,"); + createDbInfoTable.append("name text NOT NULL,"); + createDbInfoTable.append("value text NOT NULL"); + createDbInfoTable.append(")"); + + StringBuilder createPendingHashLookupTable = new StringBuilder(); + createPendingHashLookupTable.append("CREATE TABLE IF NOT EXISTS pending_hashes("); + createPendingHashLookupTable.append("id integer primary key autoincrement NOT NULL,"); + createPendingHashLookupTable.append("abstract_file_id integer NOT NULL,"); + createPendingHashLookupTable.append("md5_hash text NOT NULL,"); + createPendingHashLookupTable.append("CONSTRAINT abstract_file_id_unique UNIQUE (abstract_file_id)"); + createPendingHashLookupTable.append(")"); + + StringBuilder createPendingRescanTable = new StringBuilder(); + createPendingRescanTable.append("CREATE TABLE IF NOT EXISTS pending_rescans("); + createPendingRescanTable.append("id integer primary key autoincrement NOT NULL,"); + createPendingRescanTable.append("abstract_file_id integer NOT NULL,"); + createPendingRescanTable.append("sha256_hash text NOT NULL,"); + createPendingRescanTable.append("rescan_uuid text NOT NULL,"); + createPendingRescanTable.append("CONSTRAINT abstract_file_id_unique UNIQUE (abstract_file_id)"); + createPendingRescanTable.append(")"); + + Connection conn = null; + try { + conn = getEphemeralConnection(); + if (null == conn) { + return false; + } + + Statement stmt = conn.createStatement(); + stmt.execute(PRAGMA_JOURNAL_WAL); + stmt.execute(PRAGMA_SYNC_OFF); + stmt.execute(PRAGMA_READ_UNCOMMITTED_TRUE); + stmt.execute(PRAGMA_ENCODING_UTF8); + stmt.execute(PRAGMA_PAGE_SIZE_4096); + + stmt.execute(createPendingSubmissionsTable.toString()); + stmt.execute(createDbInfoTable.toString()); + stmt.execute(createPendingHashLookupTable.toString()); + stmt.execute(createPendingRescanTable.toString()); + + } catch (SQLException ex) { + LOGGER.log(Level.SEVERE, "Failed to initialize sqlite db schema.", ex); // NON-NLS + return false; + } finally { + PolySwarmDbUtils.closeConnection(conn); + } + + return true; + } + + /** + * Insert initial/default content into the database. Here we insert the database schema major and minor version. + * + * @return true on success, else false + */ + private boolean insertDefaultDatabaseContent() { + + Connection conn = null; + try { + conn = getEphemeralConnection(); + if (null == conn) { + return false; + } + + return PolySwarmDbUtils.updateSchemaVersion(conn, + DB_SCHEMA_VERSION_MAJOR.toString(), + DB_SCHEMA_VERSION_MINOR.toString()); + } finally { + PolySwarmDbUtils.closeConnection(conn); + } + } + + /** + * @return the DRIVER + */ + String getDriver() { + return JDBC_DRIVER; + } + + /** + * @return the VALIDATION_QUERY + */ + String getValidationQuery() { + return VALIDATION_QUERY; + } + + /** + * @return the JDBC_BASE_URI + */ + String getJDBCBaseURI() { + return JDBC_BASE_URI; + } +} diff --git a/swarmit/src/io/polyswarm/swarmit/datamodel/SwarmItDbUtils.java b/polyswarm/src/io/polyswarm/app/datamodel/PolySwarmDbUtils.java similarity index 92% rename from swarmit/src/io/polyswarm/swarmit/datamodel/SwarmItDbUtils.java rename to polyswarm/src/io/polyswarm/app/datamodel/PolySwarmDbUtils.java index df62732..fd78b76 100644 --- a/swarmit/src/io/polyswarm/swarmit/datamodel/SwarmItDbUtils.java +++ b/polyswarm/src/io/polyswarm/app/datamodel/PolySwarmDbUtils.java @@ -1,203 +1,203 @@ -/* - * The MIT License - * - * Copyright 2018 PolySwarm PTE. LTD. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.polyswarm.swarmit.datamodel; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Static functions to manage initialization, version, and closing of the - * database and connections. - */ -public class SwarmItDbUtils { - private final static Logger LOGGER = Logger.getLogger(SwarmItDbUtils.class.getName()); - - /** - * Close the statement. - * - * @param statement The statement to be closed. - * - * @throws EamDbException - */ - public static void closeStatement(Statement statement) { - if (null != statement) { - try { - statement.close(); - } catch (SQLException ex) { - LOGGER.log(Level.SEVERE, "Error closing Statement.", ex); // NON-NLS - } - } - } - - /** - * Close the resultSet. - * - * @param resultSet - * - * @throws EamDbException - */ - public static void closeResultSet(ResultSet resultSet) { - if (null != resultSet) { - try { - resultSet.close(); - } catch (SQLException ex) { - LOGGER.log(Level.SEVERE, "Error closing ResultSet.", ex); // NON-NLS - } - } - } - - /** - * Close the in-use connection and return it to the pool. - * - * @param conn An open connection - * - * @throws EamDbException - */ - public static void closeConnection(Connection conn) { - if (null != conn) { - try { - conn.close(); - } catch (SQLException ex) { - LOGGER.log(Level.SEVERE, "Error closing Connection.", ex); // NON-NLS - } - } - } - - /** - * Store the SCHEMA VERSION in the db_info table or update it. - * - * @param conn An open database connection - * - * @return true on success, else false - */ - public static boolean updateSchemaVersion(Connection conn, String majorVersion, String minorVersion) { - - PreparedStatement preparedStatement = null; - ResultSet resultSet = null; - String sqlUpdate = "UPDATE db_info SET value=? WHERE id=?"; // NON-NLS - String sqlInsert = "INSERT INTO db_info (name, value) VALUES (?, ?)"; // NON-NLS - String sqlQueryMajor = "SELECT id FROM db_info WHERE name='SCHEMA_VERSION'"; // NON-NLS - String sqlQueryMinor = "SELECT id FROM db_info WHERE name='SCHEMA_VERSION_MINOR'"; // NON-NLS - try { - preparedStatement = conn.prepareStatement(sqlQueryMajor); - resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - int id = resultSet.getInt("id"); - preparedStatement = conn.prepareStatement(sqlUpdate); - preparedStatement.setString(1, majorVersion); - preparedStatement.setInt(2, id); - preparedStatement.executeUpdate(); - } else { - preparedStatement = conn.prepareStatement(sqlInsert); - preparedStatement.setString(1, "SCHEMA_VERSION"); - preparedStatement.setString(2, majorVersion); - preparedStatement.executeUpdate(); - } - - preparedStatement = conn.prepareStatement(sqlQueryMinor); - resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - int id = resultSet.getInt("id"); - preparedStatement = conn.prepareStatement(sqlUpdate); - preparedStatement.setString(1, minorVersion); - preparedStatement.setInt(2, id); - preparedStatement.executeUpdate(); - } else { - preparedStatement = conn.prepareStatement(sqlInsert); - preparedStatement.setString(1, "SCHEMA_VERSION_MINOR"); - preparedStatement.setString(2, minorVersion); - preparedStatement.executeUpdate(); - } - } catch (SQLException ex) { - LOGGER.log(Level.SEVERE, "Error adding schema version to db_info table.", ex); // NON-NLS - return false; - } finally { - SwarmItDbUtils.closeStatement(preparedStatement); - SwarmItDbUtils.closeResultSet(resultSet); - } - - return true; - } - - /** - * Query to see if the SCHEMA_VERSION is set in the db. - * - * @param conn An open database connection - * - * @return true if set, else false. - */ - public static boolean schemaVersionIsSet(Connection conn) { - if (null == conn) { - return false; - } - - ResultSet resultSet = null; - try { - Statement tester = conn.createStatement(); - String sql = "SELECT value FROM db_info WHERE name='SCHEMA_VERSION'"; // NON-NLS - resultSet = tester.executeQuery(sql); - if (resultSet.next()) { - String value = resultSet.getString("value"); - } - } catch (SQLException ex) { - return false; - } finally { - SwarmItDbUtils.closeResultSet(resultSet); - } - return true; - } - - - /** - * Use the current settings and the validation query to test the connection - * to the database. - * - * @return true if successful query execution, else false. - */ - public static boolean executeValidationQuery(Connection conn, String validationQuery) { - if (null == conn) { - return false; - } - - ResultSet resultSet = null; - try { - Statement tester = conn.createStatement(); - resultSet = tester.executeQuery(validationQuery); - if (resultSet.next()) { - return true; - } - } catch (SQLException ex) { - return false; - } finally { - SwarmItDbUtils.closeResultSet(resultSet); - } - - return false; - } -} +/* + * The MIT License + * + * Copyright 2018 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app.datamodel; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Static functions to manage initialization, version, and closing of the + * database and connections. + */ +public class PolySwarmDbUtils { + private final static Logger LOGGER = Logger.getLogger(PolySwarmDbUtils.class.getName()); + + /** + * Close the statement. + * + * @param statement The statement to be closed. + * + * @throws EamDbException + */ + public static void closeStatement(Statement statement) { + if (null != statement) { + try { + statement.close(); + } catch (SQLException ex) { + LOGGER.log(Level.SEVERE, "Error closing Statement.", ex); // NON-NLS + } + } + } + + /** + * Close the resultSet. + * + * @param resultSet + * + * @throws EamDbException + */ + public static void closeResultSet(ResultSet resultSet) { + if (null != resultSet) { + try { + resultSet.close(); + } catch (SQLException ex) { + LOGGER.log(Level.SEVERE, "Error closing ResultSet.", ex); // NON-NLS + } + } + } + + /** + * Close the in-use connection and return it to the pool. + * + * @param conn An open connection + * + * @throws EamDbException + */ + public static void closeConnection(Connection conn) { + if (null != conn) { + try { + conn.close(); + } catch (SQLException ex) { + LOGGER.log(Level.SEVERE, "Error closing Connection.", ex); // NON-NLS + } + } + } + + /** + * Store the SCHEMA VERSION in the db_info table or update it. + * + * @param conn An open database connection + * + * @return true on success, else false + */ + public static boolean updateSchemaVersion(Connection conn, String majorVersion, String minorVersion) { + + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + String sqlUpdate = "UPDATE db_info SET value=? WHERE id=?"; // NON-NLS + String sqlInsert = "INSERT INTO db_info (name, value) VALUES (?, ?)"; // NON-NLS + String sqlQueryMajor = "SELECT id FROM db_info WHERE name='SCHEMA_VERSION'"; // NON-NLS + String sqlQueryMinor = "SELECT id FROM db_info WHERE name='SCHEMA_VERSION_MINOR'"; // NON-NLS + try { + preparedStatement = conn.prepareStatement(sqlQueryMajor); + resultSet = preparedStatement.executeQuery(); + if (resultSet.next()) { + int id = resultSet.getInt("id"); + preparedStatement = conn.prepareStatement(sqlUpdate); + preparedStatement.setString(1, majorVersion); + preparedStatement.setInt(2, id); + preparedStatement.executeUpdate(); + } else { + preparedStatement = conn.prepareStatement(sqlInsert); + preparedStatement.setString(1, "SCHEMA_VERSION"); + preparedStatement.setString(2, majorVersion); + preparedStatement.executeUpdate(); + } + + preparedStatement = conn.prepareStatement(sqlQueryMinor); + resultSet = preparedStatement.executeQuery(); + if (resultSet.next()) { + int id = resultSet.getInt("id"); + preparedStatement = conn.prepareStatement(sqlUpdate); + preparedStatement.setString(1, minorVersion); + preparedStatement.setInt(2, id); + preparedStatement.executeUpdate(); + } else { + preparedStatement = conn.prepareStatement(sqlInsert); + preparedStatement.setString(1, "SCHEMA_VERSION_MINOR"); + preparedStatement.setString(2, minorVersion); + preparedStatement.executeUpdate(); + } + } catch (SQLException ex) { + LOGGER.log(Level.SEVERE, "Error adding schema version to db_info table.", ex); // NON-NLS + return false; + } finally { + PolySwarmDbUtils.closeStatement(preparedStatement); + PolySwarmDbUtils.closeResultSet(resultSet); + } + + return true; + } + + /** + * Query to see if the SCHEMA_VERSION is set in the db. + * + * @param conn An open database connection + * + * @return true if set, else false. + */ + public static boolean schemaVersionIsSet(Connection conn) { + if (null == conn) { + return false; + } + + ResultSet resultSet = null; + try { + Statement tester = conn.createStatement(); + String sql = "SELECT value FROM db_info WHERE name='SCHEMA_VERSION'"; // NON-NLS + resultSet = tester.executeQuery(sql); + if (resultSet.next()) { + String value = resultSet.getString("value"); + } + } catch (SQLException ex) { + return false; + } finally { + PolySwarmDbUtils.closeResultSet(resultSet); + } + return true; + } + + + /** + * Use the current settings and the validation query to test the connection + * to the database. + * + * @return true if successful query execution, else false. + */ + public static boolean executeValidationQuery(Connection conn, String validationQuery) { + if (null == conn) { + return false; + } + + ResultSet resultSet = null; + try { + Statement tester = conn.createStatement(); + resultSet = tester.executeQuery(validationQuery); + if (resultSet.next()) { + return true; + } + } catch (SQLException ex) { + return false; + } finally { + PolySwarmDbUtils.closeResultSet(resultSet); + } + + return false; + } +} diff --git a/swarmit/src/io/polyswarm/swarmit/images/polyswarm-logo-32x32.png b/polyswarm/src/io/polyswarm/app/images/polyswarm-logo-32x32.png similarity index 100% rename from swarmit/src/io/polyswarm/swarmit/images/polyswarm-logo-32x32.png rename to polyswarm/src/io/polyswarm/app/images/polyswarm-logo-32x32.png diff --git a/polyswarm/src/io/polyswarm/app/optionspanel/Bundle.properties b/polyswarm/src/io/polyswarm/app/optionspanel/Bundle.properties new file mode 100644 index 0000000..946eca3 --- /dev/null +++ b/polyswarm/src/io/polyswarm/app/optionspanel/Bundle.properties @@ -0,0 +1,17 @@ +PolySwarmPanel.apiUrlTitle.text=PolySwarm API URL +PolySwarmPanel.apiKeyTitle.text=PolySwarm API Key +PolySwarmPanel.apiKeyTextField.toolTipText=Enter your API KEY for access to the PolySwarm API Service +PolySwarmPanel.apiKeyHelpLabel.text=Get your API key from https://polyswarm.network/account/api-keys +PolySwarmPanel.communityTextField.toolTipText=Enter the community for the PolySwarm API Service +PolySwarmPanel.communityTitle.text=PolySwarm Community +PolySwarmPanel.testConnectionStatusLabel.text=Connection Status Message +PolySwarmPanel.testButton.text=Test Connection +PolySwarmPanel.apiKeyTextField.text= +PolySwarmPanel.apiKeyErrorMsgLabel.text=Invalid API Key +PolySwarmPanel.apiUrlErrorMsgLabel.text=Invalid API URL +PolySwarmPanel.apiUrlTextField.toolTipText=Enter the URL for the PolySwarm API Service +PolySwarmPanel.apiUrlTextField.text=https://api.polyswarm.network/v2/ +PolySwarmPanel.communityTextField.text=default +PolySwarmPanel.communityErrorMsgLabel.text=Invalid Community +PolySwarmPanel.communityPanel.border.title=PolySwarm Community +PolySwarmPanel.testConnectionStatusLabel.AccessibleContext.accessibleDescription= diff --git a/swarmit/src/io/polyswarm/swarmit/optionspanel/SwarmItMarketplaceSettings.java b/polyswarm/src/io/polyswarm/app/optionspanel/PolySwarmMarketplaceSettings.java similarity index 86% rename from swarmit/src/io/polyswarm/swarmit/optionspanel/SwarmItMarketplaceSettings.java rename to polyswarm/src/io/polyswarm/app/optionspanel/PolySwarmMarketplaceSettings.java index 411d775..5c86cca 100644 --- a/swarmit/src/io/polyswarm/swarmit/optionspanel/SwarmItMarketplaceSettings.java +++ b/polyswarm/src/io/polyswarm/app/optionspanel/PolySwarmMarketplaceSettings.java @@ -1,165 +1,160 @@ -/* - * The MIT License - * - * Copyright 2018 PolySwarm PTE. LTD. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.polyswarm.swarmit.optionspanel; - -import io.polyswarm.swarmit.apiclient.ApiClientV2; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.sleuthkit.autopsy.coreutils.ModuleSettings; - -/** - * Manage settings for the connection to the PolySwarm marketplace - */ -public final class SwarmItMarketplaceSettings { - - - private final static Logger LOGGER = Logger.getLogger(SwarmItMarketplaceSettings.class.getName()); - private final String DEFAULT_API_KEY = ""; // NON-NLS - private final String DEFAULT_URL = "https://api.polyswarm.network/v2"; // NON-NLS - private final String DEFAULT_COMMUNITY = "default"; // NON-NLS - private final String API_STATUS_ENDPOINT = "status"; // NON-NLS - private final String MODULE_NAME = "PolySwarm"; // NON-NLS - private final String SETTINGS_TAG_API_URL = "polyswarm.url"; // NON-NLS - private final String SETTINGS_TAG_API_KEY = "polyswarm.apikey"; // NON-NLS - private final String SETTINGS_TAG_COMMUNITY = "polyswarm.community"; // NON-NLS - private String apiUrl; - private String apiKey; - private String community; - - public SwarmItMarketplaceSettings() { - loadSettings(); - } - - /** - * Read the settings from the module's config. If any are missing, set to defaults. - */ - public void loadSettings() { - apiUrl = ModuleSettings.getConfigSetting(MODULE_NAME, SETTINGS_TAG_API_URL); - if (apiUrl == null || apiUrl.isEmpty()) { - apiUrl = DEFAULT_URL; - } - - apiKey = ModuleSettings.getConfigSetting(MODULE_NAME, SETTINGS_TAG_API_KEY); - if (apiKey == null || apiKey.isEmpty()) { - apiKey = DEFAULT_API_KEY; - } - - community = ModuleSettings.getConfigSetting(MODULE_NAME, SETTINGS_TAG_COMMUNITY); - if (community == null || community.isEmpty()) { - community = DEFAULT_COMMUNITY; - } - } - - public void saveSettings() { - ModuleSettings.setConfigSetting(MODULE_NAME, SETTINGS_TAG_API_URL, getApiUrl()); - ModuleSettings.setConfigSetting(MODULE_NAME, SETTINGS_TAG_API_KEY, getApiKey()); - ModuleSettings.setConfigSetting(MODULE_NAME, SETTINGS_TAG_COMMUNITY, getCommunity()); - } - - public boolean testSettings() { - return ApiClientV2.testConnection(this).passed; - } - - public boolean isChanged() { - String urlString = ModuleSettings.getConfigSetting(MODULE_NAME, SETTINGS_TAG_API_URL); - String jsonString = ModuleSettings.getConfigSetting(MODULE_NAME, SETTINGS_TAG_API_KEY); - - return !getApiUrl().equals(urlString) - || !getApiKey().equals(jsonString); - } - - public String getApiUrl() { - return apiUrl; - } - - /** - * Get the URI object containing the URI for the status endpoint. - * - * The status endpoint is /status - * - * @return URI object - * @throws URISyntaxException - */ - public String getStatusUrl() throws URISyntaxException { - return getApiUrl().concat(String.format("consumer/community/%s/status", getCommunity())); - } - - public String getApiKey() { - return apiKey; - } - - public String getCommunity() { - return community; - } - - /** - * Set the new URL and test if it's a valid URI. - * If valid, save it to this instance. - * - * @param newUrl New URL - * @return true if valid and set, else false - */ - public boolean setApiUrl(String newUrl) { - - if (!newUrl.isEmpty()) { - try { - apiUrl = newUrl; - if (!newUrl.endsWith("/")) { - apiUrl = String.format("%s/", newUrl); - } - URI u = new URI(newUrl); - return true; - } catch (URISyntaxException ex) { - return false; - } - } - - return false; - } - - /** - * Set the new API Key and test if it's valid. - * - * The service works with API Keys or without, depending on the setup - * We allow the user to clear the API key if they want - * - * @param newApiKey New API Key - * @return true if valid and set, else false - */ - public boolean setApiKey(String newApiKey) { - apiKey = newApiKey; - return true; - } - - public boolean setCommunity(String newCommunity) { - if (newCommunity != null && !newCommunity.isEmpty()) { - community = newCommunity; - return true; - } - return false; - } -} +/* + * The MIT License + * + * Copyright 2018 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app.optionspanel; + +import io.polyswarm.app.apiclient.ApiClientV2; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.logging.Logger; +import org.sleuthkit.autopsy.coreutils.ModuleSettings; + +/** + * Manage settings for the connection to the PolySwarm marketplace + */ +public final class PolySwarmMarketplaceSettings { + + private final static Logger LOGGER = Logger.getLogger(PolySwarmMarketplaceSettings.class.getName()); + private final String DEFAULT_API_KEY = ""; // NON-NLS + private final String DEFAULT_URL = "https://api.polyswarm.network/v2/"; // NON-NLS + private final String DEFAULT_COMMUNITY = "default"; // NON-NLS + private final String MODULE_NAME = "PolySwarm"; // NON-NLS + private final String SETTINGS_TAG_API_URL = "polyswarm.url"; // NON-NLS + private final String SETTINGS_TAG_API_KEY = "polyswarm.apikey"; // NON-NLS + private final String SETTINGS_TAG_COMMUNITY = "polyswarm.community"; // NON-NLS + private String apiUrl; + private String apiKey; + private String community; + + public PolySwarmMarketplaceSettings() { + loadSettings(); + } + + /** + * Read the settings from the module's config. If any are missing, set to defaults. + */ + public void loadSettings() { + apiUrl = ModuleSettings.getConfigSetting(MODULE_NAME, SETTINGS_TAG_API_URL); + if (apiUrl == null || apiUrl.isEmpty()) { + apiUrl = DEFAULT_URL; + } + + apiKey = ModuleSettings.getConfigSetting(MODULE_NAME, SETTINGS_TAG_API_KEY); + if (apiKey == null || apiKey.isEmpty()) { + apiKey = DEFAULT_API_KEY; + } + + community = ModuleSettings.getConfigSetting(MODULE_NAME, SETTINGS_TAG_COMMUNITY); + if (community == null || community.isEmpty()) { + community = DEFAULT_COMMUNITY; + } + } + + public void saveSettings() { + ModuleSettings.setConfigSetting(MODULE_NAME, SETTINGS_TAG_API_URL, getApiUrl()); + ModuleSettings.setConfigSetting(MODULE_NAME, SETTINGS_TAG_API_KEY, getApiKey()); + ModuleSettings.setConfigSetting(MODULE_NAME, SETTINGS_TAG_COMMUNITY, getCommunity()); + } + + public boolean testSettings() { + return ApiClientV2.testConnection(this).passed; + } + + public boolean isChanged() { + String urlString = ModuleSettings.getConfigSetting(MODULE_NAME, SETTINGS_TAG_API_URL); + String jsonString = ModuleSettings.getConfigSetting(MODULE_NAME, SETTINGS_TAG_API_KEY); + + return !getApiUrl().equals(urlString) + || !getApiKey().equals(jsonString); + } + + public String getApiUrl() { + return apiUrl; + } + + /** + * Get the URI object containing the URI for the status endpoint. + * + * The status endpoint is /status + * + * @return URI object + * @throws URISyntaxException + */ + public String getStatusUrl() throws URISyntaxException { + return getApiUrl().concat(String.format("consumer/community/%s/status", getCommunity())); + } + + public String getApiKey() { + return apiKey; + } + + public String getCommunity() { + return community; + } + + /** + * Set the new URL and test if it's a valid URI. If valid, save it to this instance. + * + * @param newUrl New URL + * @return true if valid and set, else false + */ + public boolean setApiUrl(String newUrl) { + + if (!newUrl.isEmpty()) { + try { + apiUrl = newUrl; + if (!newUrl.endsWith("/")) { + apiUrl = String.format("%s/", newUrl); + } + URI u = new URI(newUrl); + return true; + } catch (URISyntaxException ex) { + return false; + } + } + + return false; + } + + /** + * Set the new API Key and test if it's valid. + * + * The service works with API Keys or without, depending on the setup We allow the user to clear the API key if they + * want + * + * @param newApiKey New API Key + * @return true if valid and set, else false + */ + public boolean setApiKey(String newApiKey) { + apiKey = newApiKey; + return true; + } + + public boolean setCommunity(String newCommunity) { + if (newCommunity != null && !newCommunity.isEmpty()) { + community = newCommunity; + return true; + } + return false; + } +} diff --git a/swarmit/src/io/polyswarm/swarmit/optionspanel/SwarmItOptionsPanelController.java b/polyswarm/src/io/polyswarm/app/optionspanel/PolySwarmOptionsPanelController.java similarity index 76% rename from swarmit/src/io/polyswarm/swarmit/optionspanel/SwarmItOptionsPanelController.java rename to polyswarm/src/io/polyswarm/app/optionspanel/PolySwarmOptionsPanelController.java index 5bca3e5..950383b 100644 --- a/swarmit/src/io/polyswarm/swarmit/optionspanel/SwarmItOptionsPanelController.java +++ b/polyswarm/src/io/polyswarm/app/optionspanel/PolySwarmOptionsPanelController.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.optionspanel; +package io.polyswarm.app.optionspanel; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -33,19 +33,19 @@ import org.openide.util.Lookup; @OptionsPanelController.TopLevelRegistration( - categoryName = "#OptionsCategory_Name_SwarmIt", + categoryName = "#OptionsCategory_Name_PolySwarm", position = 25, - iconBase = "io/polyswarm/swarmit/images/polyswarm-logo-32x32.png", - keywords = "#OptionsCategory_Keywords_SwarmIt", - keywordsCategory = "SwarmIt" + iconBase = "io/polyswarm/app/images/polyswarm-logo-32x32.png", + keywords = "#OptionsCategory_Keywords_PolySwarm", + keywordsCategory = "PolySwarm" ) -@org.openide.util.NbBundle.Messages({"OptionsCategory_Name_SwarmIt=SwarmIt", "OptionsCategory_Keywords_SwarmIt=PolySwarm Marketplace Scanning"}) -public final class SwarmItOptionsPanelController extends OptionsPanelController { +@org.openide.util.NbBundle.Messages({"OptionsCategory_Name_PolySwarm=PolySwarm", "OptionsCategory_Keywords_PolySwarm=PolySwarm Marketplace Scanning SwarmIt"}) +public final class PolySwarmOptionsPanelController extends OptionsPanelController { - private SwarmItPanel panel; + private PolySwarmPanel panel; private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); private boolean changed; - private static final Logger LOGGER = Logger.getLogger(SwarmItOptionsPanelController.class.getName()); + private static final Logger LOGGER = Logger.getLogger(PolySwarmOptionsPanelController.class.getName()); @Override public void update() { @@ -96,9 +96,9 @@ public void removePropertyChangeListener(PropertyChangeListener l) { pcs.removePropertyChangeListener(l); } - private SwarmItPanel getPanel() { + private PolySwarmPanel getPanel() { if (panel == null) { - panel = new SwarmItPanel(this); + panel = new PolySwarmPanel(this); } return panel; } @@ -106,18 +106,18 @@ private SwarmItPanel getPanel() { void changed() { if (!changed) { changed = true; - + try { pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true); } catch (Exception e) { - LOGGER.log(Level.SEVERE, "SwarmItOptionsPanelController listener threw exception on PROP_CHANGED.", e); + LOGGER.log(Level.SEVERE, "PolySwarmOptionsPanelController listener threw exception on PROP_CHANGED.", e); } } - + try { pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null); } catch (Exception e) { - LOGGER.log(Level.SEVERE, "SwarmItOptionsPanelController listener threw exception on PROP_VALID.", e); + LOGGER.log(Level.SEVERE, "PolySwarmOptionsPanelController listener threw exception on PROP_VALID.", e); } } } diff --git a/swarmit/src/io/polyswarm/swarmit/optionspanel/SwarmItPanel.form b/polyswarm/src/io/polyswarm/app/optionspanel/PolySwarmPanel.form similarity index 63% rename from swarmit/src/io/polyswarm/swarmit/optionspanel/SwarmItPanel.form rename to polyswarm/src/io/polyswarm/app/optionspanel/PolySwarmPanel.form index 442a778..b8bba2d 100644 --- a/swarmit/src/io/polyswarm/swarmit/optionspanel/SwarmItPanel.form +++ b/polyswarm/src/io/polyswarm/app/optionspanel/PolySwarmPanel.form @@ -24,7 +24,7 @@ - + @@ -50,12 +50,17 @@ - + + + + + + @@ -66,7 +71,7 @@ - + @@ -89,12 +94,15 @@ - + - + + + + @@ -108,7 +116,7 @@ - + @@ -118,8 +126,8 @@ - - + + @@ -127,7 +135,16 @@ + + + + + + + + + @@ -135,8 +152,11 @@ - - + + + + + @@ -145,11 +165,12 @@ - + - - - + + + + @@ -164,14 +185,37 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + @@ -207,7 +251,7 @@ - + @@ -220,9 +264,17 @@ - + + + + + + + + + @@ -231,7 +283,7 @@ - + @@ -240,6 +292,11 @@ + + + + + @@ -276,14 +333,14 @@ - + - + diff --git a/swarmit/src/io/polyswarm/swarmit/optionspanel/SwarmItPanel.java b/polyswarm/src/io/polyswarm/app/optionspanel/PolySwarmPanel.java similarity index 73% rename from swarmit/src/io/polyswarm/swarmit/optionspanel/SwarmItPanel.java rename to polyswarm/src/io/polyswarm/app/optionspanel/PolySwarmPanel.java index 1be5f39..ec58d96 100644 --- a/swarmit/src/io/polyswarm/swarmit/optionspanel/SwarmItPanel.java +++ b/polyswarm/src/io/polyswarm/app/optionspanel/PolySwarmPanel.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.optionspanel; +package io.polyswarm.app.optionspanel; import java.util.logging.Logger; import javax.swing.event.DocumentEvent; @@ -29,27 +29,26 @@ import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; -final class SwarmItPanel extends javax.swing.JPanel { +final class PolySwarmPanel extends javax.swing.JPanel { private static final long serialVersionUID = 1L; - private static final Logger LOGGER = Logger.getLogger(SwarmItPanel.class.getName()); - private final SwarmItOptionsPanelController controller; - private final SwarmItMarketplaceSettings settings; + private static final Logger LOGGER = Logger.getLogger(PolySwarmPanel.class.getName()); + private final PolySwarmOptionsPanelController controller; + private final PolySwarmMarketplaceSettings settings; private ConnectionTestResult connectionTestStatus; - - SwarmItPanel(SwarmItOptionsPanelController controller) { + + PolySwarmPanel(PolySwarmOptionsPanelController controller) { this.controller = controller; - this.settings = new SwarmItMarketplaceSettings(); + this.settings = new PolySwarmMarketplaceSettings(); initComponents(); customizeComponents(); } /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. + * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The + * content of this method is always regenerated by the Form Editor. */ // //GEN-BEGIN:initComponents private void initComponents() { @@ -60,6 +59,7 @@ private void initComponents() { apiKeyPanel = new javax.swing.JPanel(); apiKeyErrorMsgLabel = new javax.swing.JLabel(); apiKeyTextField = new javax.swing.JTextField(); + jTextField1 = new javax.swing.JTextField(); testConnectionButtonPanel = new javax.swing.JPanel(); testButton = new javax.swing.JButton(); testConnectionStatusLabel = new javax.swing.JLabel(); @@ -67,11 +67,11 @@ private void initComponents() { communityErrorMsgLabel = new javax.swing.JLabel(); communityTextField = new javax.swing.JTextField(); - apiUrlPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, org.openide.util.NbBundle.getMessage(SwarmItPanel.class, "SwarmItPanel.apiUrlTitle.text"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N + apiUrlPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.apiUrlTitle.text"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N apiUrlTextField.setFont(new java.awt.Font("Monospaced", 0, 13)); // NOI18N - apiUrlTextField.setText(org.openide.util.NbBundle.getMessage(SwarmItPanel.class, "SwarmItPanel.apiUrlTextField.text")); // NOI18N - apiUrlTextField.setToolTipText(org.openide.util.NbBundle.getMessage(SwarmItPanel.class, "SwarmItPanel.apiUrlTextField.toolTipText")); // NOI18N + apiUrlTextField.setText(org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.apiUrlTextField.text")); // NOI18N + apiUrlTextField.setToolTipText(org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.apiUrlTextField.toolTipText")); // NOI18N apiUrlTextField.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { apiUrlTextFieldActionPerformed(evt); @@ -80,7 +80,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { apiUrlErrorMsgLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N apiUrlErrorMsgLabel.setForeground(new java.awt.Color(255, 0, 0)); - org.openide.awt.Mnemonics.setLocalizedText(apiUrlErrorMsgLabel, org.openide.util.NbBundle.getMessage(SwarmItPanel.class, "SwarmItPanel.apiUrlErrorMsgLabel.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(apiUrlErrorMsgLabel, org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.apiUrlErrorMsgLabel.text")); // NOI18N javax.swing.GroupLayout apiUrlPanelLayout = new javax.swing.GroupLayout(apiUrlPanel); apiUrlPanel.setLayout(apiUrlPanelLayout); @@ -91,7 +91,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(apiUrlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(apiUrlTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 588, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(apiUrlErrorMsgLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 576, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap(54, Short.MAX_VALUE)) + .addContainerGap(154, Short.MAX_VALUE)) ); apiUrlPanelLayout.setVerticalGroup( apiUrlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -103,14 +103,29 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addContainerGap(16, Short.MAX_VALUE)) ); - apiKeyPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, org.openide.util.NbBundle.getMessage(SwarmItPanel.class, "SwarmItPanel.apiKeyTitle.text"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N + apiUrlTextField.getAccessibleContext().setAccessibleName(""); + + apiKeyPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.apiKeyTitle.text"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N apiKeyPanel.setFont(new java.awt.Font("Monospaced", 0, 13)); // NOI18N + apiKeyPanel.setName(org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.apiKeyTitle.text")); // NOI18N apiKeyErrorMsgLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N apiKeyErrorMsgLabel.setForeground(new java.awt.Color(255, 0, 0)); - org.openide.awt.Mnemonics.setLocalizedText(apiKeyErrorMsgLabel, org.openide.util.NbBundle.getMessage(SwarmItPanel.class, "SwarmItPanel.apiKeyErrorMsgLabel.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(apiKeyErrorMsgLabel, org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.apiKeyErrorMsgLabel.text")); // NOI18N + + apiKeyTextField.setText(org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.apiKeyTextField.text")); // NOI18N + apiKeyTextField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + apiKeyTextFieldActionPerformed(evt); + } + }); - apiKeyTextField.setText(org.openide.util.NbBundle.getMessage(SwarmItPanel.class, "SwarmItPanel.apiKeyTextField.text")); // NOI18N + jTextField1.setEditable(false); + jTextField1.setBackground(java.awt.SystemColor.menu); + jTextField1.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N + jTextField1.setForeground(new java.awt.Color(0, 0, 0)); + jTextField1.setText(org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.apiKeyHelpLabel.text")); // NOI18N + jTextField1.setBorder(null); javax.swing.GroupLayout apiKeyPanelLayout = new javax.swing.GroupLayout(apiKeyPanel); apiKeyPanel.setLayout(apiKeyPanelLayout); @@ -119,21 +134,24 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(apiKeyPanelLayout.createSequentialGroup() .addContainerGap() .addGroup(apiKeyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(apiKeyErrorMsgLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 586, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(apiKeyTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 586, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(apiKeyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(apiKeyTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE) + .addComponent(apiKeyErrorMsgLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE)) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); apiKeyPanelLayout.setVerticalGroup( apiKeyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, apiKeyPanelLayout.createSequentialGroup() - .addContainerGap() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(apiKeyTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(apiKeyErrorMsgLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(16, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(apiKeyErrorMsgLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)) ); - org.openide.awt.Mnemonics.setLocalizedText(testButton, org.openide.util.NbBundle.getMessage(SwarmItPanel.class, "SwarmItPanel.testButton.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(testButton, org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.testButton.text")); // NOI18N testButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { testButtonActionPerformed(evt); @@ -141,7 +159,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { }); testConnectionStatusLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(testConnectionStatusLabel, org.openide.util.NbBundle.getMessage(SwarmItPanel.class, "SwarmItPanel.testConnectionStatusLabel.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(testConnectionStatusLabel, org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.testConnectionStatusLabel.text")); // NOI18N javax.swing.GroupLayout testConnectionButtonPanelLayout = new javax.swing.GroupLayout(testConnectionButtonPanel); testConnectionButtonPanel.setLayout(testConnectionButtonPanelLayout); @@ -163,14 +181,17 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addContainerGap()) ); - communityPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, org.openide.util.NbBundle.getMessage(SwarmItPanel.class, "SwarmItPanel.communityPanel.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N + testConnectionStatusLabel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.testConnectionStatusLabel.text")); // NOI18N + testConnectionStatusLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.testConnectionStatusLabel.AccessibleContext.accessibleDescription")); // NOI18N + + communityPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.communityPanel.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N communityPanel.setFont(new java.awt.Font("Monospaced", 0, 13)); // NOI18N communityErrorMsgLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N communityErrorMsgLabel.setForeground(new java.awt.Color(255, 0, 0)); - org.openide.awt.Mnemonics.setLocalizedText(communityErrorMsgLabel, org.openide.util.NbBundle.getMessage(SwarmItPanel.class, "SwarmItPanel.communityErrorMsgLabel.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(communityErrorMsgLabel, org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.communityErrorMsgLabel.text")); // NOI18N - communityTextField.setText(org.openide.util.NbBundle.getMessage(SwarmItPanel.class, "SwarmItPanel.communityTextField.text")); // NOI18N + communityTextField.setText(org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.communityTextField.text")); // NOI18N javax.swing.GroupLayout communityPanelLayout = new javax.swing.GroupLayout(communityPanel); communityPanel.setLayout(communityPanelLayout); @@ -204,7 +225,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(testConnectionButtonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(apiKeyPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(communityPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap(10, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -219,10 +240,15 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(testConnectionButtonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(35, 35, 35)) ); + + apiUrlPanel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.apiUrlTitle.text")); // NOI18N + apiKeyPanel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.apiKeyTitle.text")); // NOI18N + apiKeyPanel.getAccessibleContext().setAccessibleDescription(""); + communityPanel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PolySwarmPanel.class, "PolySwarmPanel.communityTitle.text")); // NOI18N }// //GEN-END:initComponents - @Messages({"SwarmItPanel.testConnectionStatusFailedLabel.text=Connection Failed.", - "SwarmItPanel.testConnectionStatusSuccessLabel.text=Connection Successful."}) + @Messages({"PolySwarmPanel.testConnectionStatusFailedLabel.text=Connection Failed.", + "PolySwarmPanel.testConnectionStatusSuccessLabel.text=Connection Successful."}) private void testButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_testButtonActionPerformed connectionTestStatus = ConnectionTestResult.TESTEDOK; @@ -231,10 +257,10 @@ private void testButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI } if (connectionTestStatus == ConnectionTestResult.TESTEDOK) { - testConnectionStatusLabel.setText(Bundle.SwarmItPanel_testConnectionStatusSuccessLabel_text()); + testConnectionStatusLabel.setText(Bundle.PolySwarmPanel_testConnectionStatusSuccessLabel_text()); testConnectionStatusLabel.setForeground(new java.awt.Color(0, 0, 0)); } else { - testConnectionStatusLabel.setText(Bundle.SwarmItPanel_testConnectionStatusFailedLabel_text()); + testConnectionStatusLabel.setText(Bundle.PolySwarmPanel_testConnectionStatusFailedLabel_text()); testConnectionStatusLabel.setForeground(new java.awt.Color(255, 0, 0)); } controller.changed(); @@ -244,6 +270,10 @@ private void apiUrlTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//G // TODO add your handling code here: }//GEN-LAST:event_apiUrlTextFieldActionPerformed + private void apiKeyTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_apiKeyTextFieldActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_apiKeyTextFieldActionPerformed + private void customizeComponents() { // read settings and initialize GUI communityTextField.setText(settings.getCommunity()); @@ -280,12 +310,12 @@ boolean testedOk() { return connectionTestStatus == ConnectionTestResult.TESTEDOK; } - @Messages({"SwarmItPanel.testConnectionStatusUntestedLabel.text=Click Test Connection button to verify connectivity."}) + @Messages({"PolySwarmPanel.testConnectionStatusUntestedLabel.text=Click Test Connection button to verify connectivity."}) boolean enableTestButton(boolean enable) { testButton.setEnabled(enable); if (enable && connectionTestStatus == ConnectionTestResult.UNTESTED) { - testConnectionStatusLabel.setText(Bundle.SwarmItPanel_testConnectionStatusUntestedLabel_text()); + testConnectionStatusLabel.setText(Bundle.PolySwarmPanel_testConnectionStatusUntestedLabel_text()); testConnectionStatusLabel.setForeground(new java.awt.Color(255, 0, 0)); } return true; @@ -293,27 +323,27 @@ boolean enableTestButton(boolean enable) { /** * Validate the API Key. Set error message if invalid. - * + * * @return true if valid, else false */ boolean validApiKey() { boolean isValid = settings.setApiKey(apiKeyTextField.getText()); if (!isValid) { - apiKeyErrorMsgLabel.setText(NbBundle.getMessage(this.getClass(), "SwarmItPanel.apiKeyErrorMsgLabel.text")); + apiKeyErrorMsgLabel.setText(NbBundle.getMessage(this.getClass(), "PolySwarmPanel.apiKeyErrorMsgLabel.text")); } return isValid; } - - /** + + /** * Validate the API Key. Set error message if invalid. - * + * * @return true if valid, else false */ boolean validCommunity() { boolean isValid = settings.setCommunity(communityTextField.getText()); if (!isValid) { - communityErrorMsgLabel.setText(NbBundle.getMessage(this.getClass(), "SwarmItPanel.communityErrorMsgLabel.text")); + communityErrorMsgLabel.setText(NbBundle.getMessage(this.getClass(), "PolySwarmPanel.communityErrorMsgLabel.text")); } return isValid; @@ -321,23 +351,21 @@ boolean validCommunity() { /** * Validate the URL - * + * * @return true if valid, else false */ boolean validURL() { boolean isValid = settings.setApiUrl(apiUrlTextField.getText()); if (!isValid) { - apiUrlErrorMsgLabel.setText(NbBundle.getMessage(this.getClass(), "SwarmItPanel.apiUrlErrorMsgLabel.text")); + apiUrlErrorMsgLabel.setText(NbBundle.getMessage(this.getClass(), "PolySwarmPanel.apiUrlErrorMsgLabel.text")); } - + return isValid; } - /** - * Validate the fields are completed correctly and that a connection test - * was successful. - * + * Validate the fields are completed correctly and that a connection test was successful. + * * @return true if all valid and successful test, else false */ boolean valid() { @@ -348,16 +376,16 @@ boolean valid() { result &= validApiKey(); result &= validURL(); result &= validCommunity(); - + // if fields are populated correctly, enable the test button enableTestButton(result); - + return result; } /** - * Used to listen for changes in text boxes. It lets the panel know things - * have been updated and that validation needs to happen. + * Used to listen for changes in text boxes. It lets the panel know things have been updated and that validation + * needs to happen. */ private class MyDocumentListener implements DocumentListener { @@ -389,20 +417,18 @@ private enum ConnectionTestResult { CONNECTION_FAILED, TESTEDOK; } - + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel apiKeyErrorMsgLabel; - private javax.swing.JLabel apiKeyErrorMsgLabel2; private javax.swing.JPanel apiKeyPanel; - private javax.swing.JPanel apiKeyPanel2; private javax.swing.JTextField apiKeyTextField; - private javax.swing.JTextField apiKeyTextField2; private javax.swing.JLabel apiUrlErrorMsgLabel; private javax.swing.JPanel apiUrlPanel; private javax.swing.JTextField apiUrlTextField; private javax.swing.JLabel communityErrorMsgLabel; private javax.swing.JPanel communityPanel; private javax.swing.JTextField communityTextField; + private javax.swing.JTextField jTextField1; private javax.swing.JButton testButton; private javax.swing.JPanel testConnectionButtonPanel; private javax.swing.JLabel testConnectionStatusLabel; diff --git a/swarmit/src/io/polyswarm/swarmit/tasks/BackgroundTask.java b/polyswarm/src/io/polyswarm/app/tasks/BackgroundTask.java similarity index 98% rename from swarmit/src/io/polyswarm/swarmit/tasks/BackgroundTask.java rename to polyswarm/src/io/polyswarm/app/tasks/BackgroundTask.java index d19a35f..5e6bf81 100644 --- a/swarmit/src/io/polyswarm/swarmit/tasks/BackgroundTask.java +++ b/polyswarm/src/io/polyswarm/app/tasks/BackgroundTask.java @@ -1,4 +1,4 @@ -package io.polyswarm.swarmit.tasks; +package io.polyswarm.app.tasks; /* * The MIT License diff --git a/swarmit/src/io/polyswarm/swarmit/tasks/PendingHashLookup.java b/polyswarm/src/io/polyswarm/app/tasks/PendingHashLookup.java similarity index 76% rename from swarmit/src/io/polyswarm/swarmit/tasks/PendingHashLookup.java rename to polyswarm/src/io/polyswarm/app/tasks/PendingHashLookup.java index ef48326..b293043 100644 --- a/swarmit/src/io/polyswarm/swarmit/tasks/PendingHashLookup.java +++ b/polyswarm/src/io/polyswarm/app/tasks/PendingHashLookup.java @@ -1,4 +1,4 @@ - /* +/* * The MIT License * * Copyright 2020 PolySwarm PTE. LTD. @@ -21,16 +21,17 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.tasks; +package io.polyswarm.app.tasks; -import io.polyswarm.swarmit.apiclient.ApiClientV2; -import io.polyswarm.swarmit.apiclient.BadRequestException; -import io.polyswarm.swarmit.apiclient.NotAuthorizedException; -import io.polyswarm.swarmit.apiclient.NotFoundException; -import io.polyswarm.swarmit.apiclient.RateLimitException; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.ArtifactInstance; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.Tag; -import io.polyswarm.swarmit.datamodel.SwarmItDbException; +import io.polyswarm.app.apiclient.ApiClientV2; +import io.polyswarm.app.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.NotAuthorizedException; +import io.polyswarm.app.apiclient.NotFoundException; +import io.polyswarm.app.apiclient.RateLimitException; +import io.polyswarm.app.apiclient.ServerException; +import io.polyswarm.app.apiclient.v2.requests.utils.ArtifactInstance; +import io.polyswarm.app.apiclient.v2.requests.utils.Tag; +import io.polyswarm.app.datamodel.PolySwarmDbException; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -44,7 +45,9 @@ * Pending task to do a hash search in the ProcessPendingTask background task. */ public class PendingHashLookup extends PendingTask { + private static final Logger LOGGER = Logger.getLogger(PendingHashLookup.class.getName()); + private final String md5Hash; private final long abstractFileId; @@ -68,11 +71,12 @@ public long getAbstractFileId() { } /** - * Makes the hash search request on PolySwarm and updates the blackboard with results, either the ArtifactInstance, or the Not Found message + * Makes the hash search request on PolySwarm and updates the blackboard with results, either the ArtifactInstance, + * or the Not Found message * * @param autopsyCase open case */ - public void lookupHash(Case autopsyCase) throws SwarmItDbException, NotAuthorizedException, BadRequestException, RateLimitException, IOException, TskCoreException { + public void lookupHash(Case autopsyCase) throws PolySwarmDbException, NotAuthorizedException, BadRequestException, RateLimitException, IOException, TskCoreException { LOGGER.log(Level.FINE, "Looking up Hash {0}", md5Hash); try { ArtifactInstance artifactInstance = ApiClientV2.searchHash(md5Hash); @@ -95,13 +99,15 @@ public void lookupHash(Case autopsyCase) throws SwarmItDbException, NotAuthorize LOGGER.log(Level.SEVERE, "Invalid API Key.", ex); } catch (NotFoundException ex) { updateNotFound(autopsyCase, abstractFileId); + } catch (ServerException ex) { + LOGGER.log(Level.SEVERE, "Server Error.", ex); } finally { getDbInstance().deletePendingHashLookup(this); } } @Override - public boolean process(Case autopsyCase) throws SwarmItDbException, NotAuthorizedException, BadRequestException, NotFoundException, RateLimitException, IOException, TskCoreException { + public boolean process(Case autopsyCase) throws PolySwarmDbException, NotAuthorizedException, BadRequestException, NotFoundException, RateLimitException, IOException, TskCoreException { lookupHash(autopsyCase); return true; } diff --git a/polyswarm/src/io/polyswarm/app/tasks/PendingRescan.java b/polyswarm/src/io/polyswarm/app/tasks/PendingRescan.java new file mode 100644 index 0000000..412c452 --- /dev/null +++ b/polyswarm/src/io/polyswarm/app/tasks/PendingRescan.java @@ -0,0 +1,164 @@ +/* + * The MIT License + * + * Copyright 2018 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app.tasks; + +import io.polyswarm.app.apiclient.ApiClientV2; +import io.polyswarm.app.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.NotAuthorizedException; +import io.polyswarm.app.apiclient.NotFoundException; +import io.polyswarm.app.apiclient.RateLimitException; +import io.polyswarm.app.apiclient.ServerException; +import io.polyswarm.app.apiclient.v2.requests.utils.ArtifactInstance; +import io.polyswarm.app.apiclient.v2.requests.utils.Tag; +import io.polyswarm.app.datamodel.PolySwarmDbException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * Pending task to submit a file & get results in ProcessPendingTask background task + */ +public class PendingRescan extends PendingTask { + + private static final Logger LOGGER = Logger.getLogger(PendingRescan.class.getName()); + private final String rescanId; + private final String sha256Hash; + private final Long abstractFileID; + + public PendingRescan(Long abstractFileID, String sha256Hash, String uuid) { + this.abstractFileID = abstractFileID; + this.sha256Hash = sha256Hash; + this.rescanId = uuid; + } + + /** + * @return the submissionId + */ + public String getRescanId() { + return rescanId; + } + + public String getSha256Hash() { + return sha256Hash; + } + + /** + * @return the abstractFileID + */ + public Long getAbstractFileId() { + return abstractFileID; + } + + /** + * Uploads the file to PolySwarm, and updates the task with the submissionId + * + * @param autopsyCase open case + */ + public void submitRescan() throws PolySwarmDbException, NotAuthorizedException, BadRequestException, NotFoundException, RateLimitException, IOException, TskCoreException { + ArtifactInstance artifactInstance = ApiClientV2.rescanFile(sha256Hash); + getDbInstance().updatePendingRescanId(abstractFileID, artifactInstance.id); + } + + /** + * + * Checks to see if a scan has finished. Fills in the ArtifactInstance if so. Also, deletes the task on successful + * scan completion. + * + * @param autopsyCase open case + */ + public boolean checkSubmission(Case autopsyCase) throws PolySwarmDbException, NotAuthorizedException, BadRequestException, NotFoundException, RateLimitException, IOException, TskCoreException { + LOGGER.log(Level.FINE, "Checking Rescan {0}", abstractFileID); + ArtifactInstance artifactInstance = ApiClientV2.getSubmissionStatus(rescanId); + LOGGER.log(Level.FINE, "Got response{0}", artifactInstance.toString()); + if (!artifactInstance.windowClosed) { + // Exit if not done + return false; + } + + List tags; + try { + tags = ApiClientV2.getTags(artifactInstance); + } catch (IOException ex) { + LOGGER.log(Level.WARNING, "Failed to read tags from PolySwarm", ex); + tags = new ArrayList<>(); + } + + try { + updateBlackboard(autopsyCase, abstractFileID, artifactInstance, tags); + } catch (TskCoreException ex) { + throw ex; + } finally { + removeFromDB(); + } + return true; + } + + @Override + public boolean process(Case autopsyCase) throws PolySwarmDbException, BadRequestException, RateLimitException, IOException, TskCoreException { + if (rescanId.isEmpty()) { + try { + submitRescan(); + } catch (NotAuthorizedException ex) { + LOGGER.log(Level.SEVERE, "Error fetching rescan results: Invalid API Key.", ex); + removeFromDB(); + } catch (NotFoundException ex) { + LOGGER.log(Level.SEVERE, "Error fetching rescan results: Not found.", ex); + removeFromDB(); + } catch (ServerException ex) { + LOGGER.log(Level.SEVERE, "Error fetching rescan results: Server Error.", ex); + removeFromDB(); + } + return true; + // Check results of files with submission ID + } else { + try { + return checkSubmission(autopsyCase); + } catch (NotAuthorizedException ex) { + LOGGER.log(Level.SEVERE, "Error fetching rescan results: Invalid API Key.", ex); + removeFromDB(); + } catch (NotFoundException ex) { + LOGGER.log(Level.SEVERE, "Error fetching rescan results: Not found.", ex); + removeFromDB(); + } catch (ServerException ex) { + LOGGER.log(Level.SEVERE, "Error fetching rescan results: Server Error.", ex); + removeFromDB(); + } + // Return true these exceptions + return true; + } + } + + private void removeFromDB() throws PolySwarmDbException { + getDbInstance().deletePendingRescan(this); + } + + @Override + public String toString() { + return String.format("PendingRescan(abstractFileID: {0}, sha256Hash:{1} rescanUuid:{1})", getAbstractFileId().toString(), getSha256Hash(), getRescanId()); + } +} diff --git a/swarmit/src/io/polyswarm/swarmit/tasks/PendingSubmission.java b/polyswarm/src/io/polyswarm/app/tasks/PendingSubmission.java similarity index 60% rename from swarmit/src/io/polyswarm/swarmit/tasks/PendingSubmission.java rename to polyswarm/src/io/polyswarm/app/tasks/PendingSubmission.java index 63437d1..b2e9556 100644 --- a/swarmit/src/io/polyswarm/swarmit/tasks/PendingSubmission.java +++ b/polyswarm/src/io/polyswarm/app/tasks/PendingSubmission.java @@ -1,140 +1,160 @@ -/* - * The MIT License - * - * Copyright 2018 PolySwarm PTE. LTD. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.polyswarm.swarmit.tasks; - -import io.polyswarm.swarmit.apiclient.ApiClientV2; -import io.polyswarm.swarmit.apiclient.BadRequestException; -import io.polyswarm.swarmit.apiclient.NotAuthorizedException; -import io.polyswarm.swarmit.apiclient.NotFoundException; -import io.polyswarm.swarmit.apiclient.RateLimitException; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.ArtifactInstance; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.Tag; -import io.polyswarm.swarmit.datamodel.SwarmItDbException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.datamodel.AbstractFile; -import org.sleuthkit.datamodel.TskCoreException; - -/** - * Pending task to submit a file & get results in ProcessPendingTask background task - */ -public class PendingSubmission extends PendingTask { - private static final Logger LOGGER = Logger.getLogger(PendingSubmission.class.getName()); - private final String submissionId; - private final Long abstractFileID; - - public PendingSubmission(Long abstractFileID, String uuid) { - this.abstractFileID = abstractFileID; - this.submissionId = uuid; - } - - /** - * @return the submissionId - */ - public String getSubmissionId() { - return submissionId; - } - - /** - * @return the abstractFileID - */ - public Long getAbstractFileId() { - return abstractFileID; - } - - /** - * Uploads the file to PolySwarm, and updates the task with the submissionId - * - * @param autopsyCase open case - */ - public void submitFile(Case autopsyCase) throws SwarmItDbException, NotAuthorizedException, BadRequestException, NotFoundException, RateLimitException, IOException, TskCoreException { - AbstractFile abstractFile = autopsyCase.getSleuthkitCase().getAbstractFileById(abstractFileID); - ArtifactInstance artifactInstance = ApiClientV2.submitFile(abstractFile); - getDbInstance().newPendingSubmissionId(abstractFileID, artifactInstance.id); - } - - /** - * - * Checks to see if a scan has finished. Fills in the ArtifactInstance if so. - * Also, deletes the task on successful scan completion. - * - * @param autopsyCase open case - */ - public void checkSubmission(Case autopsyCase) throws SwarmItDbException, NotAuthorizedException, BadRequestException, NotFoundException, RateLimitException, IOException, TskCoreException { - LOGGER.log(Level.FINE, "Checking Submission {0}", abstractFileID); - ArtifactInstance artifactInstance = ApiClientV2.getSubmissionStatus(submissionId); - LOGGER.log(Level.FINE, "Got response{0}", artifactInstance.toString()); - if (!artifactInstance.windowClosed) { - // Exit if not done - return; - } - - List tags; - try { - tags = ApiClientV2.getTags(artifactInstance); - } catch (IOException ex) { - LOGGER.log(Level.WARNING, "Failed to read tags from PolySwarm", ex); - tags = new ArrayList<>(); - } - - try{ - updateBlackboard(autopsyCase, abstractFileID, artifactInstance, tags); - } finally { - getDbInstance().deletePendingSubmission(this); - } - } - - @Override - public boolean process(Case autopsyCase) throws SwarmItDbException, NotAuthorizedException, BadRequestException, RateLimitException, IOException, TskCoreException { - if (submissionId.isEmpty()) { - try { - submitFile(autopsyCase); - } catch (NotAuthorizedException ex) { - LOGGER.log(Level.SEVERE, "Invalid API Key.", ex); - } catch (NotFoundException ex) { - LOGGER.log(Level.SEVERE, "Error fetching submission results: Not found.", ex); - return false; - } - return false; - // Check results of files with submission ID - } else { - try { - checkSubmission(autopsyCase); - } catch (NotFoundException ex) { - LOGGER.log(Level.SEVERE, "Error fetching submission results: Not found.", ex); - return false; - } - return true; - } - } - - @Override - public String toString() { - return String.format("PendingSubmission(abstractFileID: {0}, submission_uuid:{1})", getAbstractFileId().toString(), getSubmissionId()); - } -} +/* + * The MIT License + * + * Copyright 2018 PolySwarm PTE. LTD. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.polyswarm.app.tasks; + +import io.polyswarm.app.apiclient.ApiClientV2; +import io.polyswarm.app.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.NotAuthorizedException; +import io.polyswarm.app.apiclient.NotFoundException; +import io.polyswarm.app.apiclient.RateLimitException; +import io.polyswarm.app.apiclient.ServerException; +import io.polyswarm.app.apiclient.v2.requests.utils.ArtifactInstance; +import io.polyswarm.app.apiclient.v2.requests.utils.Tag; +import io.polyswarm.app.datamodel.PolySwarmDbException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.datamodel.AbstractFile; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * Pending task to submit a file & get results in ProcessPendingTask background task + */ +public class PendingSubmission extends PendingTask { + + private static final Logger LOGGER = Logger.getLogger(PendingSubmission.class.getName()); + private final String submissionId; + private final Long abstractFileID; + + public PendingSubmission(Long abstractFileID, String uuid) { + this.abstractFileID = abstractFileID; + this.submissionId = uuid; + } + + /** + * @return the submissionId + */ + public String getSubmissionId() { + return submissionId; + } + + /** + * @return the abstractFileID + */ + public Long getAbstractFileId() { + return abstractFileID; + } + + /** + * Uploads the file to PolySwarm, and updates the task with the submissionId + * + * @param autopsyCase open case + */ + public void submitFile(Case autopsyCase) throws PolySwarmDbException, NotAuthorizedException, BadRequestException, NotFoundException, RateLimitException, ServerException, IOException, TskCoreException { + AbstractFile abstractFile = autopsyCase.getSleuthkitCase().getAbstractFileById(abstractFileID); + ArtifactInstance artifactInstance = ApiClientV2.submitFile(abstractFile); + getDbInstance().updatePendingSubmissionId(abstractFileID, artifactInstance.id); + } + + /** + * + * Checks to see if a scan has finished. Fills in the ArtifactInstance if so. Also, deletes the task on successful + * scan completion. + * + * @param autopsyCase open case + */ + public boolean checkSubmission(Case autopsyCase) throws PolySwarmDbException, NotAuthorizedException, BadRequestException, NotFoundException, RateLimitException, IOException, TskCoreException { + LOGGER.log(Level.FINE, "Checking Submission {0}", abstractFileID); + ArtifactInstance artifactInstance = ApiClientV2.getSubmissionStatus(submissionId); + LOGGER.log(Level.FINE, "Got response{0}", artifactInstance.toString()); + if (!artifactInstance.windowClosed) { + // Exit if not done + return false; + } + + List tags; + try { + tags = ApiClientV2.getTags(artifactInstance); + } catch (IOException ex) { + LOGGER.log(Level.WARNING, "Failed to read tags from PolySwarm", ex); + tags = new ArrayList<>(); + } + + try { + updateBlackboard(autopsyCase, abstractFileID, artifactInstance, tags); + } catch (TskCoreException ex) { + throw ex; + } finally { + removeFromDB(); + } + return true; + } + + @Override + public boolean process(Case autopsyCase) throws PolySwarmDbException, BadRequestException, RateLimitException, IOException, TskCoreException { + if (submissionId.isEmpty()) { + try { + submitFile(autopsyCase); + } catch (NotAuthorizedException ex) { + LOGGER.log(Level.SEVERE, "Error fetching rescan results: Invalid API Key.", ex); + removeFromDB(); + } catch (NotFoundException ex) { + LOGGER.log(Level.SEVERE, "Error fetching rescan results: Not found.", ex); + removeFromDB(); + } catch (ServerException ex) { + LOGGER.log(Level.SEVERE, "Error fetching rescan results: Server Error.", ex); + removeFromDB(); + } + return true; + // Check results of files with submission ID + } else { + try { + return checkSubmission(autopsyCase); + } catch (NotAuthorizedException ex) { + LOGGER.log(Level.SEVERE, "Error fetching rescan results: Invalid API Key.", ex); + removeFromDB(); + } catch (NotFoundException ex) { + LOGGER.log(Level.SEVERE, "Error fetching rescan results: Not found.", ex); + removeFromDB(); + } catch (ServerException ex) { + LOGGER.log(Level.SEVERE, "Error fetching rescan results: Server Error.", ex); + removeFromDB(); + } + // Return true on these exceptions + return true; + } + } + + private void removeFromDB() throws PolySwarmDbException { + getDbInstance().deletePendingSubmission(this); + } + + @Override + public String toString() { + return String.format("PendingSubmission(abstractFileID: {0}, submission_uuid:{1})", getAbstractFileId().toString(), getSubmissionId()); + } +} diff --git a/swarmit/src/io/polyswarm/swarmit/tasks/PendingTask.java b/polyswarm/src/io/polyswarm/app/tasks/PendingTask.java similarity index 64% rename from swarmit/src/io/polyswarm/swarmit/tasks/PendingTask.java rename to polyswarm/src/io/polyswarm/app/tasks/PendingTask.java index 78c4d67..602b2db 100644 --- a/swarmit/src/io/polyswarm/swarmit/tasks/PendingTask.java +++ b/polyswarm/src/io/polyswarm/app/tasks/PendingTask.java @@ -1,4 +1,4 @@ - /* +/* * The MIT License * * Copyright 2020 PolySwarm PTE. LTD. @@ -21,21 +21,19 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.tasks; - -import io.polyswarm.swarmit.SwarmItController; -import io.polyswarm.swarmit.SwarmItModule; -import io.polyswarm.swarmit.apiclient.BadRequestException; -import io.polyswarm.swarmit.apiclient.NotAuthorizedException; -import io.polyswarm.swarmit.apiclient.RateLimitException; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.ArtifactInstance; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.Assertion; -import io.polyswarm.swarmit.apiclient.v2.requests.utils.Tag; -import io.polyswarm.swarmit.datamodel.SwarmItDbException; -import io.polyswarm.swarmit.datamodel.SwarmItDb; +package io.polyswarm.app.tasks; + +import io.polyswarm.app.PolySwarmController; +import io.polyswarm.app.PolySwarmModule; +import io.polyswarm.app.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.RateLimitException; +import io.polyswarm.app.apiclient.v2.requests.utils.ArtifactInstance; +import io.polyswarm.app.apiclient.v2.requests.utils.Assertion; +import io.polyswarm.app.apiclient.v2.requests.utils.Tag; +import io.polyswarm.app.datamodel.PolySwarmDbException; +import io.polyswarm.app.datamodel.PolySwarmDb; import java.io.IOException; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.ingest.IngestServices; @@ -52,11 +50,13 @@ * All children classes must implement `process(Case autopsyCase)` */ public abstract class PendingTask { + private static final Logger LOGGER = Logger.getLogger(PendingTask.class.getName()); - public abstract boolean process(Case autopsyCase) throws SwarmItDbException, NotAuthorizedException, BadRequestException, RateLimitException, IOException, TskCoreException; - public SwarmItDb getDbInstance() throws SwarmItDbException { - return SwarmItDb.getInstance(); + public abstract boolean process(Case autopsyCase) throws PolySwarmDbException, BadRequestException, RateLimitException, IOException, TskCoreException; + + public PolySwarmDb getDbInstance() throws PolySwarmDbException { + return PolySwarmDb.getInstance(); } /** @@ -67,16 +67,14 @@ public SwarmItDb getDbInstance() throws SwarmItDbException { */ public static void updateNotFound(Case autopsyCase, Long abstractFileId) throws TskCoreException { AbstractFile abstractFile = autopsyCase.getSleuthkitCase().getAbstractFileById(abstractFileId); - BlackboardArtifact artifact = getBlackboardArtifact(autopsyCase, abstractFile, SwarmItController.POLYSWARM_ARTIFACT_TYPE_NAME); - artifact.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT, SwarmItModule.getModuleName(), "Not Found in PolySwarm")); + BlackboardArtifact artifact = getBlackboardArtifact(autopsyCase, abstractFile, PolySwarmController.POLYSWARM_ARTIFACT_TYPE_NAME); + artifact.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT, PolySwarmModule.getModuleName(), "Not Found in PolySwarm")); } /** - * Fills in all the blackboard fields under a new BlackboardArtifact. - * Also sets the known status of an AbstractFile + * Fills in all the blackboard fields under a new BlackboardArtifact. Also sets the known status of an AbstractFile * - * Fills in the following attributes: - * PolyScore, Sha256, Assertions, Malware Families, Tags + * Fills in the following attributes: PolyScore, Sha256, Assertions, Malware Families, Tags * * @param autopsyCase open case * @param abstractFileId id of the file in question @@ -85,19 +83,20 @@ public static void updateNotFound(Case autopsyCase, Long abstractFileId) throws public static void updateBlackboard(Case autopsyCase, Long abstractFileId, ArtifactInstance artifactInstance, List tags) throws TskCoreException { AbstractFile abstractFile = autopsyCase.getSleuthkitCase().getAbstractFileById(abstractFileId); - // Set file to known bad when polyscore > 0.7 and at least 2 malicious responses if (artifactInstance.detection.malicious >= 2 && Double.parseDouble(artifactInstance.polyscore) > 0.7d) { abstractFile.setKnown(TskData.FileKnown.BAD); } // Add all results attributes - BlackboardArtifact artifact = getBlackboardArtifact(autopsyCase, abstractFile, SwarmItController.POLYSWARM_ARTIFACT_TYPE_NAME); - artifact.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_HASH_SHA2_256, SwarmItModule.getModuleName(), artifactInstance.sha256)); - addArtifactAttribute(autopsyCase, artifact, SwarmItController.POLYSWARM_ARTIFACT_ATTRIBUTE_POLYSCORE_NAME, artifactInstance.polyscore); - addArtifactAttribute(autopsyCase, artifact, SwarmItController.POLYSWARM_ARTIFACT_ATTRIBUTE_MALICIOUS_DETECTIONS_NAME, artifactInstance.detection.malicious); - addArtifactAttribute(autopsyCase, artifact, SwarmItController.POLYSWARM_ARTIFACT_ATTRIBUTE_BENIGN_DETECTIONS_NAME, artifactInstance.detection.benign); - addArtifactAttribute(autopsyCase, artifact, SwarmItController.POLYSWARM_ARTIFACT_ATTRIBUTE_TOTAL_DETECTIONS_NAME, artifactInstance.detection.total); + BlackboardArtifact artifact = getBlackboardArtifact(autopsyCase, abstractFile, PolySwarmController.POLYSWARM_ARTIFACT_TYPE_NAME); + artifact.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_HASH_SHA2_256, PolySwarmModule.getModuleName(), artifactInstance.sha256)); + addArtifactAttribute(autopsyCase, artifact, PolySwarmController.POLYSWARM_ARTIFACT_ATTRIBUTE_POLYSCORE_NAME, artifactInstance.polyscore); + addArtifactAttribute(autopsyCase, artifact, PolySwarmController.POLYSWARM_ARTIFACT_ATTRIBUTE_MALICIOUS_DETECTIONS_NAME, artifactInstance.detection.malicious); + addArtifactAttribute(autopsyCase, artifact, PolySwarmController.POLYSWARM_ARTIFACT_ATTRIBUTE_BENIGN_DETECTIONS_NAME, artifactInstance.detection.benign); + addArtifactAttribute(autopsyCase, artifact, PolySwarmController.POLYSWARM_ARTIFACT_ATTRIBUTE_TOTAL_DETECTIONS_NAME, artifactInstance.detection.total); + addArtifactAttribute(autopsyCase, artifact, PolySwarmController.POLYSWARM_ARTIFACT_ATTRIBUTE_FIRST_SEEN_NAME, artifactInstance.firstSeen); + addArtifactAttribute(autopsyCase, artifact, PolySwarmController.POLYSWARM_ARTIFACT_ATTRIBUTE_LAST_SCANNED_NAME, artifactInstance.lastScanned); // notify UI to update and display this result for (Assertion assertion : artifactInstance.assertions) { @@ -106,38 +105,38 @@ public static void updateBlackboard(Case autopsyCase, Long abstractFileId, Artif } } - for (Assertion assertion: artifactInstance.assertions) { + for (Assertion assertion : artifactInstance.assertions) { if (!assertion.malwareFamily.isEmpty()) { - addArtifactAttribute(autopsyCase, artifact, SwarmItController.POLYSWARM_ARTIFACT_ATTRIBUTE_MALWARE_FAMILY_NAME, assertion.malwareFamily); + addArtifactAttribute(autopsyCase, artifact, PolySwarmController.POLYSWARM_ARTIFACT_ATTRIBUTE_MALWARE_FAMILY_NAME, assertion.malwareFamily); } } - for (Tag tag: tags) { - addArtifactAttribute(autopsyCase, artifact, SwarmItController.POLYSWARM_ARTIFACT_ATTRIBUTE_TAG_NAME, tag.name); + for (Tag tag : tags) { + addArtifactAttribute(autopsyCase, artifact, PolySwarmController.POLYSWARM_ARTIFACT_ATTRIBUTE_TAG_NAME, tag.name); } - IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent(SwarmItModule.getModuleName(), - autopsyCase.getSleuthkitCase().getArtifactType(SwarmItController.POLYSWARM_ARTIFACT_TYPE_NAME))); + IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent(PolySwarmModule.getModuleName(), + autopsyCase.getSleuthkitCase().getArtifactType(PolySwarmController.POLYSWARM_ARTIFACT_TYPE_NAME))); } /** - * - * Adds an assertion to the blackboard. - * Creates a new BlackboardAttribute.Type per assertion author - * - * @param autopsyCase open case - * @param artifact BlackboardArtifact to add the result - * @param assertion Assertion from PolySwarm - */ + * + * Adds an assertion to the blackboard. Creates a new BlackboardAttribute.Type per assertion author + * + * @param autopsyCase open case + * @param artifact BlackboardArtifact to add the result + * @param assertion Assertion from PolySwarm + */ public static void addAssertion(Case autopsyCase, BlackboardArtifact artifact, Assertion assertion) throws TskCoreException { - String attributeName = String.format(SwarmItController.POLYSWARM_ARTIFACT_ATTRIBUTE_ASSERTION_NAME_FORMAT, assertion.name.toUpperCase()); - SwarmItController.createCustomArtifactAttribute(autopsyCase, attributeName, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING, assertion.name); + String attributeName = String.format(PolySwarmController.POLYSWARM_ARTIFACT_ATTRIBUTE_ASSERTION_NAME_FORMAT, assertion.name.toUpperCase()); + PolySwarmController.createCustomArtifactAttribute(autopsyCase, attributeName, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING, assertion.name); addArtifactAttribute(autopsyCase, artifact, attributeName, assertion.getHumanReadableVerdict()); } /** - * Creates a new BlackboardArtifact and adds the the AbstractFile - * We create a new one each task so the results are easy to read & easy to associate + * Creates a new BlackboardArtifact for tracking scan/lookup results. + * + * A new artifact is added per scan/lookup * * @param autopsyCase Open case * @param abstractFile File in in being updated @@ -164,11 +163,12 @@ public static void addArtifactAttribute(Case autopsyCase, BlackboardArtifact art return; } - artifact.addAttribute(new BlackboardAttribute(attributeType, SwarmItModule.getModuleName(), data)); + artifact.addAttribute(new BlackboardAttribute(attributeType, PolySwarmModule.getModuleName(), data)); } /** * Adds a double field to the blackboard + * * @param autopsyCase open case * @param artifact BlackboardArtifact to add the result * @param attributeName String name of the attribute to add the data in @@ -180,11 +180,12 @@ public static void addArtifactAttribute(Case autopsyCase, BlackboardArtifact art return; } - artifact.addAttribute(new BlackboardAttribute(attributeType, SwarmItModule.getModuleName(), data)); + artifact.addAttribute(new BlackboardAttribute(attributeType, PolySwarmModule.getModuleName(), data)); } /** * Adds an int field to the blackboard + * * @param autopsyCase open case * @param artifact BlackboardArtifact to add the result * @param attributeName String name of the attribute to add the data in @@ -196,6 +197,6 @@ public static void addArtifactAttribute(Case autopsyCase, BlackboardArtifact art return; } - artifact.addAttribute(new BlackboardAttribute(attributeType, SwarmItModule.getModuleName(), data)); + artifact.addAttribute(new BlackboardAttribute(attributeType, PolySwarmModule.getModuleName(), data)); } } diff --git a/swarmit/src/io/polyswarm/swarmit/tasks/ProcessPendingTask.java b/polyswarm/src/io/polyswarm/app/tasks/ProcessPendingTask.java similarity index 64% rename from swarmit/src/io/polyswarm/swarmit/tasks/ProcessPendingTask.java rename to polyswarm/src/io/polyswarm/app/tasks/ProcessPendingTask.java index 1e1020f..24e7e7f 100644 --- a/swarmit/src/io/polyswarm/swarmit/tasks/ProcessPendingTask.java +++ b/polyswarm/src/io/polyswarm/app/tasks/ProcessPendingTask.java @@ -21,13 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package io.polyswarm.swarmit.tasks; +package io.polyswarm.app.tasks; -import io.polyswarm.swarmit.apiclient.BadRequestException; -import io.polyswarm.swarmit.apiclient.NotAuthorizedException; -import io.polyswarm.swarmit.apiclient.RateLimitException; -import io.polyswarm.swarmit.datamodel.SwarmItDb; -import io.polyswarm.swarmit.datamodel.SwarmItDbException; +import io.polyswarm.app.apiclient.BadRequestException; +import io.polyswarm.app.apiclient.RateLimitException; +import io.polyswarm.app.datamodel.PolySwarmDb; +import io.polyswarm.app.datamodel.PolySwarmDbException; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -38,19 +37,18 @@ import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.datamodel.TskCoreException; - /** * Processes all Tasks in a background thread so the UI is not blocked during file & network IO. * */ public class ProcessPendingTask extends BackgroundTask { + private static final Logger LOGGER = Logger.getLogger(ProcessPendingTask.class.getName()); - private final SwarmItDb dbInstance; + private final PolySwarmDb dbInstance; private final Case autopsyCase; - private ProgressHandle progressHandle; - public SwarmItDb getDbInstance() { + public PolySwarmDb getDbInstance() { return dbInstance; } @@ -58,7 +56,7 @@ public Case getAutopsyCase() { return autopsyCase; } - public ProcessPendingTask(SwarmItDb dbInstance, Case autopsyCase) { + public ProcessPendingTask(PolySwarmDb dbInstance, Case autopsyCase) { super(); this.dbInstance = dbInstance; this.autopsyCase = autopsyCase; @@ -66,38 +64,38 @@ public ProcessPendingTask(SwarmItDb dbInstance, Case autopsyCase) { @Override public void run() { - progressHandle = getInitialProgressHandle(); - progressHandle.start(); - try { // check db for any pending tasks + PolySwarmDb db = getDbInstance(); + List pendingList = new ArrayList<>(); - pendingList.addAll(getDbInstance().getPendingHashLookups()); - pendingList.addAll(getDbInstance().getPendingSubmissions()); + pendingList.addAll(db.getPendingHashLookups()); + pendingList.addAll(db.getPendingSubmissions()); + pendingList.addAll(db.getPendingRescans()); if (pendingList.isEmpty()) { + if (progressHandle != null) { + progressHandle.finish(); + progressHandle = null; + } LOGGER.log(Level.INFO, "No pending submissions found."); return; + } else if (progressHandle == null) { + progressHandle = getInitialProgressHandle(); + progressHandle.start(); + progressHandle.switchToIndeterminate(); } LOGGER.log(Level.INFO, "Found {0} pending tasks. Starting processing...", pendingList.size()); - progressHandle.switchToDeterminate(pendingList.size()); - updateProgress(0.0); - int workDone = 0; - // for each pending submission entry, contact API to get status info for (PendingTask pendingTask : pendingList) { - boolean success = false; try { - // allow the task to do all the work - success = pendingTask.process(getAutopsyCase()); - } catch (NotAuthorizedException ex) { - LOGGER.log(Level.SEVERE, "Invalid API Key"); + pendingTask.process(getAutopsyCase()); } catch (RateLimitException ex) { - LOGGER.log(Level.SEVERE, "Exeeded rate limits, you need to purchase a larger package, or wait a moment before trying again.", ex); + LOGGER.log(Level.SEVERE, "Exeeded rate limits, you need to purchase a larger package, or wait a moment before trying again."); } catch (BadRequestException ex) { LOGGER.log(Level.SEVERE, "Bad Request", ex); - } catch (SwarmItDbException ex) { - LOGGER.log(Level.SEVERE, "Failed to update pending task in db.",ex); + } catch (PolySwarmDbException ex) { + LOGGER.log(Level.SEVERE, "Failed to update pending task in db.", ex); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to get abstractFile from current case", ex); } catch (IOException ex) { @@ -105,25 +103,17 @@ public void run() { } catch (Exception ex) { LOGGER.log(Level.SEVERE, "Unexpected exception while processing task", ex); } - if (success) { - workDone++; - progressHandle.progress(pendingTask.toString(), workDone); - updateProgress(workDone - 1 / (double) pendingList.size()); - updateMessage(pendingTask.toString()); - } } + LOGGER.log(Level.INFO, "Completed a pass on pending tasks."); - LOGGER.log(Level.INFO, "Completed processing pending tasks."); - - } catch (SwarmItDbException ex) { - LOGGER.log(Level.SEVERE, "Failed to get list of pending tasks from db.",ex); - } finally { - progressHandle.finish(); + } catch (PolySwarmDbException ex) { + LOGGER.log(Level.SEVERE, "Failed to get list of pending tasks from db.", ex); } } @NbBundle.Messages({"ProcessPendingTask.populatingDb.status=Processing Requests to PolySwarm.",}) - ProgressHandle getInitialProgressHandle() { - return ProgressHandle.createHandle(Bundle.ProcessPendingTask_populatingDb_status(), this); + private ProgressHandle getInitialProgressHandle() { + return ProgressHandle.createHandle(io.polyswarm.app.tasks.Bundle.ProcessPendingTask_populatingDb_status(), this); } + } diff --git a/swarmit/test/files/benign.txt b/polyswarm/test/files/benign.txt similarity index 100% rename from swarmit/test/files/benign.txt rename to polyswarm/test/files/benign.txt diff --git a/swarmit/thirdparty/apache-commons/commons-pool2-2.6.0.jar b/polyswarm/thirdparty/apache-commons/commons-pool2-2.6.0.jar similarity index 100% rename from swarmit/thirdparty/apache-commons/commons-pool2-2.6.0.jar rename to polyswarm/thirdparty/apache-commons/commons-pool2-2.6.0.jar diff --git a/swarmit/thirdparty/guava/guava-26.0-jre.jar b/polyswarm/thirdparty/guava/guava-26.0-jre.jar similarity index 100% rename from swarmit/thirdparty/guava/guava-26.0-jre.jar rename to polyswarm/thirdparty/guava/guava-26.0-jre.jar diff --git a/swarmit/thirdparty/httpcomponents-client-4.5.6/LICENSE.txt b/polyswarm/thirdparty/httpcomponents-client-4.5.6/LICENSE.txt similarity index 97% rename from swarmit/thirdparty/httpcomponents-client-4.5.6/LICENSE.txt rename to polyswarm/thirdparty/httpcomponents-client-4.5.6/LICENSE.txt index e9bd0ea..32f01ed 100644 --- a/swarmit/thirdparty/httpcomponents-client-4.5.6/LICENSE.txt +++ b/polyswarm/thirdparty/httpcomponents-client-4.5.6/LICENSE.txt @@ -1,558 +1,558 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - -========================================================================= - -This project includes Public Suffix List copied from - -licensed under the terms of the Mozilla Public License, v. 2.0 - -Full license text: - -Mozilla Public License Version 2.0 -================================== - -1. Definitions --------------- - -1.1. "Contributor" - means each individual or legal entity that creates, contributes to - the creation of, or owns Covered Software. - -1.2. "Contributor Version" - means the combination of the Contributions of others (if any) used - by a Contributor and that particular Contributor's Contribution. - -1.3. "Contribution" - means Covered Software of a particular Contributor. - -1.4. "Covered Software" - means Source Code Form to which the initial Contributor has attached - the notice in Exhibit A, the Executable Form of such Source Code - Form, and Modifications of such Source Code Form, in each case - including portions thereof. - -1.5. "Incompatible With Secondary Licenses" - means - - (a) that the initial Contributor has attached the notice described - in Exhibit B to the Covered Software; or - - (b) that the Covered Software was made available under the terms of - version 1.1 or earlier of the License, but not also under the - terms of a Secondary License. - -1.6. "Executable Form" - means any form of the work other than Source Code Form. - -1.7. "Larger Work" - means a work that combines Covered Software with other material, in - a separate file or files, that is not Covered Software. - -1.8. "License" - means this document. - -1.9. "Licensable" - means having the right to grant, to the maximum extent possible, - whether at the time of the initial grant or subsequently, any and - all of the rights conveyed by this License. - -1.10. "Modifications" - means any of the following: - - (a) any file in Source Code Form that results from an addition to, - deletion from, or modification of the contents of Covered - Software; or - - (b) any new file in Source Code Form that contains any Covered - Software. - -1.11. "Patent Claims" of a Contributor - means any patent claim(s), including without limitation, method, - process, and apparatus claims, in any patent Licensable by such - Contributor that would be infringed, but for the grant of the - License, by the making, using, selling, offering for sale, having - made, import, or transfer of either its Contributions or its - Contributor Version. - -1.12. "Secondary License" - means either the GNU General Public License, Version 2.0, the GNU - Lesser General Public License, Version 2.1, the GNU Affero General - Public License, Version 3.0, or any later versions of those - licenses. - -1.13. "Source Code Form" - means the form of the work preferred for making modifications. - -1.14. "You" (or "Your") - means an individual or a legal entity exercising rights under this - License. For legal entities, "You" includes any entity that - controls, is controlled by, or is under common control with You. For - purposes of this definition, "control" means (a) the power, direct - or indirect, to cause the direction or management of such entity, - whether by contract or otherwise, or (b) ownership of more than - fifty percent (50%) of the outstanding shares or beneficial - ownership of such entity. - -2. License Grants and Conditions --------------------------------- - -2.1. Grants - -Each Contributor hereby grants You a world-wide, royalty-free, -non-exclusive license: - -(a) under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or - as part of a Larger Work; and - -(b) under Patent Claims of such Contributor to make, use, sell, offer - for sale, have made, import, and otherwise transfer either its - Contributions or its Contributor Version. - -2.2. Effective Date - -The licenses granted in Section 2.1 with respect to any Contribution -become effective for each Contribution on the date the Contributor first -distributes such Contribution. - -2.3. Limitations on Grant Scope - -The licenses granted in this Section 2 are the only rights granted under -this License. No additional rights or licenses will be implied from the -distribution or licensing of Covered Software under this License. -Notwithstanding Section 2.1(b) above, no patent license is granted by a -Contributor: - -(a) for any code that a Contributor has removed from Covered Software; - or - -(b) for infringements caused by: (i) Your and any other third party's - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - -(c) under Patent Claims infringed by Covered Software in the absence of - its Contributions. - -This License does not grant any rights in the trademarks, service marks, -or logos of any Contributor (except as may be necessary to comply with -the notice requirements in Section 3.4). - -2.4. Subsequent Licenses - -No Contributor makes additional grants as a result of Your choice to -distribute the Covered Software under a subsequent version of this -License (see Section 10.2) or under the terms of a Secondary License (if -permitted under the terms of Section 3.3). - -2.5. Representation - -Each Contributor represents that the Contributor believes its -Contributions are its original creation(s) or it has sufficient rights -to grant the rights to its Contributions conveyed by this License. - -2.6. Fair Use - -This License is not intended to limit any rights You have under -applicable copyright doctrines of fair use, fair dealing, or other -equivalents. - -2.7. Conditions - -Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted -in Section 2.1. - -3. Responsibilities -------------------- - -3.1. Distribution of Source Form - -All distribution of Covered Software in Source Code Form, including any -Modifications that You create or to which You contribute, must be under -the terms of this License. You must inform recipients that the Source -Code Form of the Covered Software is governed by the terms of this -License, and how they can obtain a copy of this License. You may not -attempt to alter or restrict the recipients' rights in the Source Code -Form. - -3.2. Distribution of Executable Form - -If You distribute Covered Software in Executable Form then: - -(a) such Covered Software must also be made available in Source Code - Form, as described in Section 3.1, and You must inform recipients of - the Executable Form how they can obtain a copy of such Source Code - Form by reasonable means in a timely manner, at a charge no more - than the cost of distribution to the recipient; and - -(b) You may distribute such Executable Form under the terms of this - License, or sublicense it under different terms, provided that the - license for the Executable Form does not attempt to limit or alter - the recipients' rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - -You may create and distribute a Larger Work under terms of Your choice, -provided that You also comply with the requirements of this License for -the Covered Software. If the Larger Work is a combination of Covered -Software with a work governed by one or more Secondary Licenses, and the -Covered Software is not Incompatible With Secondary Licenses, this -License permits You to additionally distribute such Covered Software -under the terms of such Secondary License(s), so that the recipient of -the Larger Work may, at their option, further distribute the Covered -Software under the terms of either this License or such Secondary -License(s). - -3.4. Notices - -You may not remove or alter the substance of any license notices -(including copyright notices, patent notices, disclaimers of warranty, -or limitations of liability) contained within the Source Code Form of -the Covered Software, except that You may alter any license notices to -the extent required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - -You may choose to offer, and to charge a fee for, warranty, support, -indemnity or liability obligations to one or more recipients of Covered -Software. However, You may do so only on Your own behalf, and not on -behalf of any Contributor. You must make it absolutely clear that any -such warranty, support, indemnity, or liability obligation is offered by -You alone, and You hereby agree to indemnify every Contributor for any -liability incurred by such Contributor as a result of warranty, support, -indemnity or liability terms You offer. You may include additional -disclaimers of warranty and limitations of liability specific to any -jurisdiction. - -4. Inability to Comply Due to Statute or Regulation ---------------------------------------------------- - -If it is impossible for You to comply with any of the terms of this -License with respect to some or all of the Covered Software due to -statute, judicial order, or regulation then You must: (a) comply with -the terms of this License to the maximum extent possible; and (b) -describe the limitations and the code they affect. Such description must -be placed in a text file included with all distributions of the Covered -Software under this License. Except to the extent prohibited by statute -or regulation, such description must be sufficiently detailed for a -recipient of ordinary skill to be able to understand it. - -5. Termination --------------- - -5.1. The rights granted under this License will terminate automatically -if You fail to comply with any of its terms. However, if You become -compliant, then the rights granted under this License from a particular -Contributor are reinstated (a) provisionally, unless and until such -Contributor explicitly and finally terminates Your grants, and (b) on an -ongoing basis, if such Contributor fails to notify You of the -non-compliance by some reasonable means prior to 60 days after You have -come back into compliance. Moreover, Your grants from a particular -Contributor are reinstated on an ongoing basis if such Contributor -notifies You of the non-compliance by some reasonable means, this is the -first time You have received notice of non-compliance with this License -from such Contributor, and You become compliant prior to 30 days after -Your receipt of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent -infringement claim (excluding declaratory judgment actions, -counter-claims, and cross-claims) alleging that a Contributor Version -directly or indirectly infringes any patent, then the rights granted to -You by any and all Contributors for the Covered Software under Section -2.1 of this License shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all -end user license agreements (excluding distributors and resellers) which -have been validly granted by You or Your distributors under this License -prior to termination shall survive termination. - -************************************************************************ -* * -* 6. Disclaimer of Warranty * -* ------------------------- * -* * -* Covered Software is provided under this License on an "as is" * -* basis, without warranty of any kind, either expressed, implied, or * -* statutory, including, without limitation, warranties that the * -* Covered Software is free of defects, merchantable, fit for a * -* particular purpose or non-infringing. The entire risk as to the * -* quality and performance of the Covered Software is with You. * -* Should any Covered Software prove defective in any respect, You * -* (not any Contributor) assume the cost of any necessary servicing, * -* repair, or correction. This disclaimer of warranty constitutes an * -* essential part of this License. No use of any Covered Software is * -* authorized under this License except under this disclaimer. * -* * -************************************************************************ - -************************************************************************ -* * -* 7. Limitation of Liability * -* -------------------------- * -* * -* Under no circumstances and under no legal theory, whether tort * -* (including negligence), contract, or otherwise, shall any * -* Contributor, or anyone who distributes Covered Software as * -* permitted above, be liable to You for any direct, indirect, * -* special, incidental, or consequential damages of any character * -* including, without limitation, damages for lost profits, loss of * -* goodwill, work stoppage, computer failure or malfunction, or any * -* and all other commercial damages or losses, even if such party * -* shall have been informed of the possibility of such damages. This * -* limitation of liability shall not apply to liability for death or * -* personal injury resulting from such party's negligence to the * -* extent applicable law prohibits such limitation. Some * -* jurisdictions do not allow the exclusion or limitation of * -* incidental or consequential damages, so this exclusion and * -* limitation may not apply to You. * -* * -************************************************************************ - -8. Litigation -------------- - -Any litigation relating to this License may be brought only in the -courts of a jurisdiction where the defendant maintains its principal -place of business and such litigation shall be governed by laws of that -jurisdiction, without reference to its conflict-of-law provisions. -Nothing in this Section shall prevent a party's ability to bring -cross-claims or counter-claims. - -9. Miscellaneous ----------------- - -This License represents the complete agreement concerning the subject -matter hereof. If any provision of this License is held to be -unenforceable, such provision shall be reformed only to the extent -necessary to make it enforceable. Any law or regulation which provides -that the language of a contract shall be construed against the drafter -shall not be used to construe this License against a Contributor. - -10. Versions of the License ---------------------------- - -10.1. New Versions - -Mozilla Foundation is the license steward. Except as provided in Section -10.3, no one other than the license steward has the right to modify or -publish new versions of this License. Each version will be given a -distinguishing version number. - -10.2. Effect of New Versions - -You may distribute the Covered Software under the terms of the version -of the License under which You originally received the Covered Software, -or under the terms of any subsequent version published by the license -steward. - -10.3. Modified Versions - -If you create software not governed by this License, and you want to -create a new license for such software, you may create and use a -modified version of this License if you rename the license and remove -any references to the name of the license steward (except to note that -such modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary -Licenses - -If You choose to distribute Source Code Form that is Incompatible With -Secondary Licenses under the terms of this version of the License, the -notice described in Exhibit B of this License must be attached. - -Exhibit A - Source Code Form License Notice -------------------------------------------- - - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular -file, then You may include the notice in a location (such as a LICENSE -file in a relevant directory) where a recipient would be likely to look -for such a notice. - -You may add additional accurate notices of copyright ownership. - -Exhibit B - "Incompatible With Secondary Licenses" Notice ---------------------------------------------------------- - - This Source Code Form is "Incompatible With Secondary Licenses", as - defined by the Mozilla Public License, v. 2.0. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + +========================================================================= + +This project includes Public Suffix List copied from + +licensed under the terms of the Mozilla Public License, v. 2.0 + +Full license text: + +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/swarmit/thirdparty/httpcomponents-client-4.5.6/NOTICE.txt b/polyswarm/thirdparty/httpcomponents-client-4.5.6/NOTICE.txt similarity index 96% rename from swarmit/thirdparty/httpcomponents-client-4.5.6/NOTICE.txt rename to polyswarm/thirdparty/httpcomponents-client-4.5.6/NOTICE.txt index 7b76205..8d4aa6d 100644 --- a/swarmit/thirdparty/httpcomponents-client-4.5.6/NOTICE.txt +++ b/polyswarm/thirdparty/httpcomponents-client-4.5.6/NOTICE.txt @@ -1,6 +1,6 @@ -Apache HttpComponents Client -Copyright 1999-2018 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). - +Apache HttpComponents Client +Copyright 1999-2018 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). + diff --git a/swarmit/thirdparty/httpcomponents-client-4.5.6/README.txt b/polyswarm/thirdparty/httpcomponents-client-4.5.6/README.txt similarity index 97% rename from swarmit/thirdparty/httpcomponents-client-4.5.6/README.txt rename to polyswarm/thirdparty/httpcomponents-client-4.5.6/README.txt index 907db2c..eb7212a 100644 --- a/swarmit/thirdparty/httpcomponents-client-4.5.6/README.txt +++ b/polyswarm/thirdparty/httpcomponents-client-4.5.6/README.txt @@ -1,77 +1,77 @@ -Apache HttpComponents Client -============================ - -Welcome to the HttpClient component of the Apache HttpComponents project. - -Building Instructions ---------------------- - -For building from source instructions please refer to BUILDING.txt. - -Dependencies ------------- - -HttpClient main module requires Java 6 compatible runtime and -depends on the following external libraries: - -* Apache HttpComponents HttpCore -* Apache Commons Logging -* Apache Commons Codec - -(for detailed information on external dependencies please see pom.xml) - -HttpMime module is optional and requires Java 6 compatible runtime -and depends on the following external libraries: - -* Apache HttpComponents HttpCore -* Apache Commons Logging - -(for detailed information on external dependencies please see pom.xml) - -Licensing ---------- - -Apache HttpComponents Client is licensed under the Apache License 2.0. -See the files called LICENSE.txt and NOTICE.txt for more information. - -Cryptographic Software Notice ------------------------------ - -This distribution may include software that has been designed for use -with cryptographic software. The country in which you currently reside -may have restrictions on the import, possession, use, and/or re-export -to another country, of encryption software. BEFORE using any encryption -software, please check your country's laws, regulations and policies -concerning the import, possession, or use, and re-export of encryption -software, to see if this is permitted. See -for more information. - -The U.S. Government Department of Commerce, Bureau of Industry and -Security (BIS), has classified this software as Export Commodity -Control Number (ECCN) 5D002.C.1, which includes information security -software using or performing cryptographic functions with asymmetric -algorithms. The form and manner of this Apache Software Foundation -distribution makes it eligible for export under the License Exception -ENC Technology Software Unrestricted (TSU) exception (see the BIS -Export Administration Regulations, Section 740.13) for both object -code and source code. - -The following provides more details on the included software that -may be subject to export controls on cryptographic software: - - Apache HttpComponents Client interfaces with the - Java Secure Socket Extension (JSSE) API to provide - - - HTTPS support - - Apache HttpComponents Client does not include any - implementation of JSSE. - -Contact -------- - - o For general information visit the main project site at - http://hc.apache.org/ - - o For current status information visit the status page at - http://hc.apache.org/status.html +Apache HttpComponents Client +============================ + +Welcome to the HttpClient component of the Apache HttpComponents project. + +Building Instructions +--------------------- + +For building from source instructions please refer to BUILDING.txt. + +Dependencies +------------ + +HttpClient main module requires Java 6 compatible runtime and +depends on the following external libraries: + +* Apache HttpComponents HttpCore +* Apache Commons Logging +* Apache Commons Codec + +(for detailed information on external dependencies please see pom.xml) + +HttpMime module is optional and requires Java 6 compatible runtime +and depends on the following external libraries: + +* Apache HttpComponents HttpCore +* Apache Commons Logging + +(for detailed information on external dependencies please see pom.xml) + +Licensing +--------- + +Apache HttpComponents Client is licensed under the Apache License 2.0. +See the files called LICENSE.txt and NOTICE.txt for more information. + +Cryptographic Software Notice +----------------------------- + +This distribution may include software that has been designed for use +with cryptographic software. The country in which you currently reside +may have restrictions on the import, possession, use, and/or re-export +to another country, of encryption software. BEFORE using any encryption +software, please check your country's laws, regulations and policies +concerning the import, possession, or use, and re-export of encryption +software, to see if this is permitted. See +for more information. + +The U.S. Government Department of Commerce, Bureau of Industry and +Security (BIS), has classified this software as Export Commodity +Control Number (ECCN) 5D002.C.1, which includes information security +software using or performing cryptographic functions with asymmetric +algorithms. The form and manner of this Apache Software Foundation +distribution makes it eligible for export under the License Exception +ENC Technology Software Unrestricted (TSU) exception (see the BIS +Export Administration Regulations, Section 740.13) for both object +code and source code. + +The following provides more details on the included software that +may be subject to export controls on cryptographic software: + + Apache HttpComponents Client interfaces with the + Java Secure Socket Extension (JSSE) API to provide + + - HTTPS support + + Apache HttpComponents Client does not include any + implementation of JSSE. + +Contact +------- + + o For general information visit the main project site at + http://hc.apache.org/ + + o For current status information visit the status page at + http://hc.apache.org/status.html diff --git a/swarmit/thirdparty/httpcomponents-client-4.5.6/RELEASE_NOTES.txt b/polyswarm/thirdparty/httpcomponents-client-4.5.6/RELEASE_NOTES.txt similarity index 97% rename from swarmit/thirdparty/httpcomponents-client-4.5.6/RELEASE_NOTES.txt rename to polyswarm/thirdparty/httpcomponents-client-4.5.6/RELEASE_NOTES.txt index 17061a2..0d96723 100644 --- a/swarmit/thirdparty/httpcomponents-client-4.5.6/RELEASE_NOTES.txt +++ b/polyswarm/thirdparty/httpcomponents-client-4.5.6/RELEASE_NOTES.txt @@ -1,2354 +1,2354 @@ -Release 4.5.6 -------------------- - -This is a maintenance release that adds Automatic-Module-Name to the manifest for compatibility -with Java 9 Platform Module System and fixes a number of issues discovered since 4.5.5 - -Please note that as of 4.4 HttpClient requires Java 1.6 or newer. - -Changelog: -------------------- - -* [HTTPCLIENT-1882=: reset authentication state on I/O or runtime error for connection based - authentication schemes (such as NTLM) - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1924]: HttpClient to shut down the connection manager if a fatal error occurs - in the course of a request execution. - Contributed by Oleg Kalnichevski - -* Add Automatic-Module-Name in manifest so Java9 modular applications can depend on this library - Contributed by Varun Nandi - -* [HTTPCLIENT-1923]: fixed incorrect connection close on shutdown + fixed corresponding test - Contributed by Aleksei Arsenev - -* [HTTPCLIENT-1906]: certificates containing alternative subject names other than DNS and IP - (such as RFC822) get rejected as invalid - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1904]: check cookie domain for null - Contributed by Hans-Peter Keck - -* [HTTPCLIENT-1900]: proxy protocol processor does not post-process CONNECT response messages - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1911]: Failing tests on Fedora 28 due to weak encryption algorithms in test - keystore. - Contributed by Gary Gregory and Michael Simacek - - -Release 4.5.5 -------------------- - -HttpClient 4.5.5 (GA) is a maintenance release that fixes a regression introduced -by the previous release causing a NPE in SystemDefaultCredentialsProvider. - -Please note that as of 4.4 HttpClient requires Java 1.6 or newer. - -Changelog: -------------------- - -* [HTTPCLIENT-1690] Avoid merging Content-Encoding headers coming with 304 status to cache entry. - Contributed by Sudheera Palihakkara - -* [HTTPCLIENT-1888] Regression in SystemDefaultCredentialsProvider#getCredentials causing NPE. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1886] Update HttpClient 4.5.x from HttpCore 4.4.7 to 4.4.9 - Contributed by Gary Gregory - -* [HTTPCLIENT-1889] org.apache.http.client.utils.URLEncodedUtils.parse() - should return a new ArrayList when there are no query parameters. - Contributed by Gary Gregory - - -Release 4.5.4 -------------------- - -HttpClient 4.5.4 (GA) is a maintenance release that fixes a number of defects found since 4.5.3. - -Please note that as of 4.4 HttpClient requires Java 1.6 or newer. - -Changelog: -------------------- - -* [HTTPCLIENT-1883] SystemDefaultCredentialsProvider to use https.proxy* system properties - for origins with port 443. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1881] Allow truncated NTLM packets to work with this client. - Contributed by Karl Wright - -* [HTTPCLIENT-1855] Disabled caching of DIGEST auth scheme instances due to unreliability of nonce counter - when the auth cache is shared by multiple sessions. - Contributed by Oleg Kalnichevski - -* BasicCookieStore uses a ReentrantReadWriteLock to avoid synchronization on #getCookies/#toString - while maintaining thread safety. - Contributed by Carter Kozak - -* [HTTPCLIENT-1865] DefaultServiceUnavailableRetryStrategy does not respect HttpEntity#isRepeatable. - Contributed by Tomas Celaya - -* [HTTPCLIENT-1859] Encode Content-Disposition name and filename elements appropriately. - Contributed by Karl Wright - -* Avoid fetching the cached entity twice on cache hit. - Contributed by Leandro Nunes - -* [HTTPCLIENT-1835] #evictExpiredConnections no longer causes the #evictIdleConnections behaviour - to be implicitly enabled. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1831= URIBuilder should not prepend a leading slash to relative URIs. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1833] Fix Windows Negotiate-NTLM handling of proxies. - Contributed by Roman Stoffel - -* [HTTPCLIENT-1817] Add a "Trust All" TrustStrategy implementation. - Contributed by Gary Gregory - -* [HTTPCLIENT-1816] Update Apache Commons Codec 1.9 to 1.10. - Contributed by Gary Gregory - -* [HTTPCLIENT-1836] DefaultHostnameVerifier#getSubjectAltNames(X509Certificate) throws java.lang.ClassCastException. - Contributed by Gary Gregory , Ilian Iliev - -* [HTTPCLIENT-1845]: Extract InputStreamFactory classes out of GzipDecompressingEntity and - DeflateDecompressingEntity for reuse and to create less garbage. - Contributed by Gary Gregory - -* [HTTPCLIENT-1847] Update Ehcache from 2.6.9 to 2.6.11. - Contributed by Gary Gregory - -* [HTTPCLIENT-1848] Update spymemcached from 2.11.4 to 2.12.3. - Contributed by Gary Gregory - -* [HTTPCLIENT-1849] Update JNA from 4.1.0 to 4.4.0. - Contributed by Gary Gregory - -* [HTTPCLIENT-1850] Update SLF4J from 1.7.6 to 1.7.25. - Contributed by Gary Gregory - - -Release 4.5.3 -------------------- - -HttpClient 4.5.3 (GA) is a maintenance release that fixes a number of defects found since 4.5.2. - -Please note that as of 4.4 HttpClient requires Java 1.6 or newer. - -Changelog: -------------------- - -* [HTTPCLIENT-1803] Improved handling of malformed paths by URIBuilder. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1802] Do not attempt to match SSL host to subject CN if subject alternative name of any type are given. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1788] RFC 6265 policy must not reject cookies with paths that are no prefix of the uri path. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1792] SSLConnectionSocketFactory to throw SSLPeerUnverifiedException with a better error message - when hostname verification fails. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1779] [OSGi] support NTLM proxy authentication. - Contributed by Julian Sedding - -* [HTTPCLIENT-1773] [OSGi] HttpProxyConfigurationActivator does not unregister HttpClientBuilderFactory. - Contributed by Julian Sedding - -* [HTTPCLIENT-1771] improve OSGi webconsole display for org.apache.http.proxyconfigurator. - Contributed by Julian Sedding - -* [HTTPCLIENT-1770] OSGi metatype for org.apache.http.proxyconfigurator missing factoryPid. - Contributed by Julian Sedding - -* [HTTPCLIENT-1767] Null pointer dereference in EofSensorInputStream and ResponseEntityProxy. - Contributed by Peter Ansell - -* Support changing system default ProxySelector. - Contributed by Robin Stevens - -* All services registered in the OSGi service registry provide the whole bundle header dictionary as vendor - property value. - Contributed by Christoph Fiehe - -* [HTTPCLIENT-1750] OSGi support for CachingHttpClientBuilder. - Contributed by Justin Edelson - -* [HTTPCLIENT-1749] OSGi client builder to use weak references to track HttpClient instances. - Contributed by Justin Edelson - -* [HTTPCLIENT-1747] apply RequestConfig defaults when using HttpParams values in backward compatibility mode. - Contributed by Oleg Kalnichevski - -* Override LaxRedirectStrategy's INSTANCE field. - Contributed by Eric Wu - -* [HTTPCLIENT-1736] do not request cred delegation by default when using Kerberos auth. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1744] normalize hostname and certificate CN when matching to CN. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1732] SystemDefaultCredentialsProvider to take http.proxyHost and http.proxyPort system - properties into account. - Contributed by Oleg Kalnichevski - -* Revert "HTTPCLIENT-1712: SPNego schemes to take service scheme into account when generating auth token". - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1727] AbstractHttpClient#createClientConnectionManager does not account for context class loader. - Contributed by Charles Allen - -* [HTTPCLIENT-1726:] Copy the SNI fix from SSLConnectionSocketFactory to the deprecated SSLSocketFactory class. - Contributed by David Black - - -Release 4.5.2 -------------------- - -HttpClient 4.5.2 (GA) is a maintenance release that fixes a number of minor defects found since 4.5.1. - -Please note that as of 4.4 HttpClient requires Java 1.6 or newer. - -Changelog: -------------------- - -* [HTTPCLIENT-1710, HTTPCLIENT-1718, HTTPCLEINT-1719] OSGi container compatibility improvements. - Contributed by 212427891 - -* [HTTPCLIENT-1717] Make fluent API Content#Content(byte[], ContentType) public. - Contributed by Cash Costello - -* [HTTPCLIENT-1715] NTLMEngineImpl#Type1Message not thread safe but declared as a constant. - Contributed by Olivier Lafontaine , Gary Gregory - -* [HTTPCLIENT-1714] Add HttpClientBuilder#setDnsResolver(DnsResolver). - Contributed by Alexis Thaveau - -* [HTTPCLIENT-1712] SPNego schemes to take service scheme into account when generating auth token. - Contributed by Georg Romstorfer - -* [HTTPCLIENT-1700] Netscape draft, browser compatibility, RFC 2109, RFC 2965 and default cookie - specs to ignore cookies with empty name for consistency with RFC 6265 specs. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1704] IgnoreSpec#match to always return false. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1550] Fixed 'deflate' zlib header check. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1698] Fixed matching of IPv6 addresses by DefaultHostnameVerifier - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1695] RFC 6265 compliant cookie spec to ignore cookies with empty name / missing - value. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1216] Removed ThreadLocal subclass from DateUtils. - Contributed by Jochen Kemnade - -* [HTTPCLIENT-1685] PublicSuffixDomainFilter to ignore local hosts and local domains. - Contributed by Oleg Kalnichevski - - - -Release 4.5.1 -------------------- - -HttpClient 4.5.1 (GA) is a maintenance release that fixes a number of minor defects found since 4.5. - -Please note that as of 4.4 HttpClient requires Java 1.6 or newer. - -Changelog: -------------------- - -* [HTTPCLIENT-1680] redirect of a POST request causes ClientProtocolException. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1673] org.apache.http.entity.mime.content.* missing from OSGi exports. - Contributed by Benson Margulies - -* [HTTPCLIENT-1668] Fluent request incorrectly handles connect timeout setting. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1667] RequestBuilder does not take charset into account when creating - UrlEncodedFormEntity. - Contributed by Sergey Smith - -* [HTTPCLIENT-1655] HttpClient sends RST instead of FIN ACK sequence when using non-persistant - connections. - Contributed by Oleg Kalnichevski - - - -Release 4.5 -------------------- - -HttpClient 4.5 (GA) is a minor feature release that includes several incremental enhancements -to the exisitng functionality such as support for private domains in the Mozilla Public Suffix List. - -Changelog: -------------------- - -* Reduced default validate after inactivity setting from 5 sec to 2 sec - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1649] Fixed serialization of auth schemes - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1645]: Fluent requests to inherit config parameters of the executor. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1640]: RFC6265 lax cookie policy fails to parse 'max-age' attribute. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1633]: RFC6265CookieSpecProvider compatibility level setting has no effect. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1613]: Support for private domains in Mozilla Public Suffix List. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1651]: Add ability to disable content compression on a request basis - Contributed by Michael Osipov - -* [HTTPCLIENT-1654]: Deprecate/remove RequestConfig#decompressionEnabled in favor of #contentCompressionEnabled - Contributed by Michael Osipov - - - -Release 4.4.1 -------------------- - -HttpClient 4.4.1 (GA) is a maintenance release that fixes a number of defects in new functionality -introduced in version 4.4. - -Users of HttpClient 4.4 are encouraged to upgrade. - -Please note that as of 4.4 HttpClient requires Java 1.6 or newer. - -Changelog: -------------------- - -* Marked RFC 2109, RFC 2965, Netscape draft cookie specs as obsolete - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1633] RFC6265CookieSpecProvider compatibility level setting has no effect. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1628]: Auth cache can fail when domain name contains uppercase characters. - Contributed by Dennis Ju - -* [HTTPCLIENT-1609] Stale connection check in PoolingHttpClientConnectionManager has no effect. - Internal connection pool does not correctly implement connection validation. - Contributed by Charles Lip - - - -Release 4.4 Final -------------------- - -This is the first stable (GA) release of HttpClient 4.4. Notable features and enhancements included -in 4.4 series are: - -* Support for the latest HTTP state management specification (RFC 6265). Please note that the old -cookie policy is still used by default for compatibility reasons. RFC 6265 compliant cookie -policies need to be explicitly configured by the user. Please also note that as of next feature -release support for Netscape draft, RFC 2109 and RFC 2965 cookie policies will be deprecated -and disabled by default. It is recommended to use RFC 6265 compliant policies for new applications -unless compatibility with RFC 2109 and RFC 2965 is required and to migrate existing applications -to the default cookie policy. - -* Enhanced, redesigned and rewritten default SSL hostname verifier with improved RFC 2818 -compliance - -* Default SSL hostname verifier and default cookie policy now validate certificate identity -and cookie domain of origin against the public suffix list maintained by Mozilla.org - - -* More efficient stale connection checking: indiscriminate connection checking which results -in approximately 20 to 50 ms overhead per request has been deprecated in favor of conditional -connection state validation (persistent connections are to be re-validated only if a specified -period inactivity has elapsed) - -* Authentication cache thread-safety: authentication cache used by HttpClient is now thread-safe -and can be shared by multiple threads in order to re-use authentication state for subsequent -requests - -* Native Windows Negotiate and NTLM via SSPI through JNA: when running on Windows OS HttpClient -configured to use native NTLM or SPNEGO authentication schemes can make use of platform specific -functionality via JNA and current user credentials. This functionality is still considered -experimental, known to have compatibility issues and subject to change without prior notice. -Use at your discretion. - -This release also includes all fixes from the stable 4.3.x release branch. - -Please note that as of 4.4 HttpClient requires Java 1.6 or newer. - - -Changelog: -------------------- - -* Support for the latest HTTP state management specification (RFC 6265). - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1515] Caching of responses to HEAD requests - Contributed by Tyrone Cutajar and - Francois-Xavier Bonnet - -* [HTTPCLIENT-1560] Native Windows auth improvements - Contributed by Michael Osipov - -* Update Apache Commons Logging version from 1.1.3 to 1.2. - Contributed by Gary Gregory - -* Update Apache Commons Codec version from 1.6 to 1.9. - Contributed by Gary Gregory - -* Update Ehcache version from 2.2.0 to 2.6.9. - Contributed by Gary Gregory - -* Update Ehcache version from 2.2.0 to 2.6.9. - Contributed by Gary Gregory - -* Update Spymemcached version from 2.6 to 2.11.4. - Contributed by Gary Gregory - -* Update SLF4J version from 1.5.11 to 1.7.7. - Contributed by Gary Gregory - - - - - -Release 4.4 BETA1 -------------------- - -This is the first BETA release of HttpClient 4.4. Notable features and enhancements included -in 4.4 series are: - -* Enhanced redesigned and rewritten default SSL hostname verifier with improved RFC 2818 -compliance - -* Default SSL hostname verifier and default cookie policy now validate certificate identity -and cookie domain of origin against the public suffix list maintained by Mozilla.org - - -* Native windows Negotiate/NTLM via JNA: when running on Windows OS HttpClient configured to use -native NTLM or SPNEGO authentication schemes can make use of platform specific functionality -via JNA and current user system credentials - -* More efficient stale connection checking: indiscriminate connection checking which results -in approximately 20 to 50 ms overhead per request has been deprecated in favor of conditional -connection state validation (persistent connections are to be re-validated only if a specified -period inactivity has elapsed) - -* Authentication cache thread-safety: authentication caches used by HttpClient is now thread-safe -and can be shared by multiple threads in order to re-use authentication state for subsequent -requests - -This release also includes all fixes from the stable 4.3.x release branch. - -Please note that as of 4.4 HttpClient requires Java 1.6 or newer. - - -Changelog: -------------------- - -* [HTTPCLIENT-1547] HttpClient OSGi bundle doesn't import the package "javax.naming". - Contributed by Willem Jiang - -* [HTTPCLIENT-1541] Use correct (HTTP/hostname) service principal name for Windows native - Negotiate/NTLM auth schemes. - Contributed by Ka-Lok Fung - -* Improved compliance with RFC 2818: default hostname verifier to ignore the common name of the - certificate subject if alternative subject names (dNSName or iPAddress) are present. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1540] Support delegated credentials (ISC_REQ_DELEGATE) by Native windows - native Negotiate/NTLM auth schemes. - Contributed by Ka-Lok Fung - - - -Release 4.4 ALPHA1 -------------------- - -This is the first ALPHA release of HttpClient 4.4. Notable features and enhancements included -in the 4.4 branch are: - -* More efficient stale connection checking: indiscriminate connection checking which results -in approximately 20 to 50 ms overhead per request has been deprecated in favor of conditional -connection state validation (persistent connections are to be re-validated only if a specified -period inactivity has elapsed) - -* Native windows Negotiate/NTLM via JNA: when running on Windows OS HttpClient configured to use -native NTLM or SPNEGO authentication schemes can make use of platform specific functionality -via JNA and current user system credentials - -* Authentication cache thread-safety: authentication caches used by HttpClient is now thread-safe -and can be shared by multiple threads in order to re-use authentication state for subsequent -requests - -This release also includes all fixes from the stable 4.3.x release branch. - -Please note that as of 4.4 HttpClient requires Java 1.6 or newer. - -Please note that new features included in this release are still considered experimental and -their API may change in the future 4.4 alpha and beta releases. - - -Changelog: -------------------- - -* [HTTPCLIENT-1493] Indiscriminate connection checking has been deprecated in favor of conditional - connection state validation. Persistent connections are to be re-validated only after a defined - period inactivity prior to being leased to the consumer. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1519] Use the original HttpHost instance passed as a parameter to - HttpClient#execute when generating 'Host' request header. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1491] Enable provision of Service Principal Name in Windows native - auth scheme. - Contributed by Malcolm Smith - -* [HTTPCLIENT-1403] Pluggable content decoders. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1466] FileBodyPart#generateContentType() ignores custom ContentType values. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1461] fixed performance degradation in gzip encoded content processing - introduced by HTTPCLIENT-1432. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1457] Incorrect handling of Windows (NT) credentials by - SystemDefaultCredentialsProvider. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1456] Request retrial after status 503 causes ClientProtocolException. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1454] Make connection operator APIs public. - Contributed by Tamas Cservenak - -* Update JUnit to version 4.11 from 4.9 - Contributed by Gary Gregory - - - -Release 4.3.4 -------------------- - -HttpClient 4.3.4 (GA) is a maintenance release that improves performance in high concurrency -scenarios. This version replaces dynamic proxies with custom proxy classes and eliminates thread -contention in java.reflect.Proxy.newInstance() when leasing connections from the connection pool -and processing response messages. - - -Changelog: -------------------- - -* Replaced dynamic proxies with custom proxy classes to reduce thread contention. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1484] GzipCompressingEntity should not close the underlying output stream - if the entity has not been fully written out due to an exception. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1474] Fixed broken entity enclosing requests in HC Fluent. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1470] CachingExec(ClientExecChain, HttpCache, CacheConfig, AsynchronousValidator) - throws NPE if config is null - - - - -Release 4.3.3 -------------------- - -HttpClient 4.3.3 (GA) is a bug fix release that fixes a regression introduced by the previous -release causing a significant performance degradation in compressed content processing. - -Users of HttpClient 4.3 are encouraged to upgrade. - -Changelog: -------------------- - -* [HTTPCLIENT-1466] FileBodyPart#generateContentType() ignores custom ContentType values. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1453] Thread safety regression in PoolingHttpClientConnectionManager - #closeExpiredConnections that can lead to ConcurrentModificationException. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1461] fixed performance degradation in compressed content processing - introduced by HTTPCLIENT-1432. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1457] Incorrect handling of Windows (NT) credentials by - SystemDefaultCredentialsProvider. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1456] Request retrial after status 503 causes ClientProtocolException. - Contributed by Oleg Kalnichevski - - -Release 4.3.2 -------------------- - -HttpClient 4.3.2 (GA) is a maintenance release that delivers a number of improvements -as well as bug fixes for issues reported since 4.3.1 release. SNI support for -Oracle JRE 1.7+ is being among the most notable improvements. - -Users of HttpClient 4.3 are encouraged to upgrade. - -Changelog: -------------------- - -* [HTTPCLIENT-1447] Clients created with HttpClients.createMinimal do not work with absolute URIs - Contributed by Joseph Walton - -* [HTTPCLIENT-1446] NTLM proxy + BASIC target auth fails with 'Unexpected state: - MSG_TYPE3_GENERATED'. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1443] HttpCache uses the physical host instead of the virtual host as a cache key. - Contributed by Francois-Xavier Bonnet - -* [HTTPCLIENT-1442] Authentication header set by the user gets removed in case - of proxy authentication (affects plan HTTP requests only). - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1441] Caching AsynchronousValidationRequest leaks connections. - Contributed by Dominic Tootell - -* [HTTPCLIENT-1440] 'file' scheme in redirect location URI causes NPE. - Contributed by James Leigh - -* [HTTPCLIENT-1437] Made Executor#execute thread safe. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1119] SNI support (Oracle Java 1.7+ only). - Contributed by Bruno Harbulot - -* [HTTPCLIENT-1435] Fluent Executor ignores custom request properties. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1432] Lazy decompressing of HttpEntity#getContent() to avoid EOFException - in case of an empty response with 'Content-Encoding: gzip' header. - Contributed by Yihua Huang - -* [HTTPCLIENT-1431] (Regression) deprecated connection manager cannot be used with - a custom LayeredSchemeSocketFactory. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1425] Fixed socket closed exception thrown by caching HttpClient when the origin - server sends a long chunked response. - Contributed by James Leigh - -* [HTTPCLIENT-1417] Fixed NPE in BrowserCompatSpec#formatCookies caused by version 1 - cookies with null cookie value. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1416] Fixed NPE in CachingHttpClientBuilder#build(). - Contributed by Oleg Kalnichevski - - - -Release 4.3.1 -------------------- - -HttpClient 4.3.1 (GA) is a bug fix release that addresses a number of issues reported since -release 4.3. - -Users of HttpClient 4.3 are strongly encouraged to upgrade. - -Changelog -------------------- - -* [HTTPCLIENT-1410] Browser compatible hostname verifier no longer rejects - *.co., *.gov., *.info., etc as invalid. - Contributed by Oleg Kalnichevski - -* Ensure X509HostnameVerifier is never null. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1405] CONNECT HTTP/1.1 requests lack mandatory 'Host' header. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1402] Cache default User-Agent value. - Contributed by yuexiaojun - -* [HTTPCLIENT-1398] Fixed invalid OSGi metadata caused by corrupted Maven bundle plugin metadata. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1399] Fixed NPE in RequestBuilder. - Contributed by Oleg Kalnichevski - - - - -Release 4.3 Final -------------------- - -This is the first stable (GA) release of HttpClient 4.3. The most notable enhancements included -in this release are: - -* Support for Java 7 try-with-resources for resource management (connection release.) - -* Added fluent Builder classes for HttpEntity, HttpRequest, HttpClient and SSLContext instances. - -* Deprecation of preference and configuration API based on HttpParams interface in favor of -constructor injection and plain configuration objects. - -* Reliance on object immutability instead of access synchronization for thread safety. -Several old classes whose instances can be shared by multiple request exchanges have -been replaced by immutable equivalents. - -* DefaultHttpClient, DecompressingHttpClient, CachingHttpClient and similar classes are -deprecated in favor of builder classes that produce immutable HttpClient instances. - -* HttpClient builders now dynamically construct a request execution pipeline tailored -specifically to the user configuration by physically excluding unnecessary protocol components. - -* There is now an option to construct a minimal HttpClient implementation that can only execute -basic HTTP message exchanges without redirects, authentication, state management or proxy support. -This feature might be of particular use in web crawler development. - -* There is now option to avoid strict URI syntax for request URIs by executing HTTP requests -with an explicitly specified target host. HttpClient will no longer attempt to parse the request -URI if it does not need to extract the target host from it. - -This release also includes all fixes from the stable 4.2.x release branch. - - -Changelog -------------------- -* [HTTPCLIENT-1371] Weak ETag Validation is Useful On PUT With If-Match - Contributed by James Leigh - -* [HTTPCLIENT-1394] Support for Native windows Negotiate/NTLM via JNA - Contributed by Ryan McKinley - -* [HTTPCLIENT-1384] Expose CacheInvalidator interface. - Contributed by Nicolas Richeton - -* [HTTPCLIENT-1385] Fixed path normalization in CacheKeyGenerator - Contributed by James Leigh - -* [HTTPCLIENT-1370] Response to non-GET requests should never be cached with the default - ResponseCachingPolicy - Contributed by James Leigh - -* [HTTPCLIENT-1373] OPTIONS and TRACE should not invalidate cache - Contributed by James Leigh - -* [HTTPCLIENT-1383] HttpClient enters an infinite loop during NTLM authentication if the opposite - endpoint keeps responding with a type 2 NTLM response after type 3 MTLM message has already been - sent by the client. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1372] Refactor HttpMultipart, and add RFC6532 mode, so that headers in post - are no longer constrained to ASCII values. - Contributed by Karl Wright - -* [HTTPCLIENT-1377] User principal for non-NTLM authentication is incorrectly generated when using - user credentials are specified as NTCredentials - Contributed by Gary Gregory - - - -Release 4.3 BETA2 -------------------- - -This is the second BETA release of HttpClient 4.3. The most notable features and improvements -in the 4.3 branch are: Support for Java 7 try-with-resources for resource management (connection -release); fluent Builder classes for HttpEntity, HttpRequest and HttpClient instances, deprecation -of preference and configuration API based on HttpParams interface in favor of constructor injection -and plain configuration objects, reliance on object immutability instead of access synchronization -for thread safety. - -This release also includes all fixes from the stable 4.2.x release branch. - -Changelog -------------------- - - -* [HTTPCLIENT-1366] org.apache.http.client.utils.URLEncodedUtils should parse the semicolon as a query parameter separator. - Contributed by Gary Gregory - -* [HTTPCLIENT-1365] NPE when ManagedHttpClientConnectionFactory.create(ConnectionConfig) is called with null. - Contributed by Gary Gregory - -* [HTTPCLIENT-1362] Better error messages for connect timed out and connection refused - exceptions. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1360] separate out DeflateInputStream as an independent class, - so it can be used by others. - Contributed by Karl Wright - -* [HTTPCLIENT-1359] repeated requests using the same context fail if they redirect. - Contributed by James Leigh - -* [HTTPCLIENT-1354] do not quote algorithm parameter in DIGEST auth response. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1351] Added utility method to resolve final location from original request, - target host and a list of redirects. - Contributed by James Leigh - -* [HTTPCLIENT-1344] Userinfo credentials in URI should not default to preemptive BASIC - authentication. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1345] Useinfo credentials ignored in redirect location header. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1294] HttpClient to rewrite host name of the redirect location URI in order - to avoid circular redirect exception due to host name case mismatch. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1264] Add support for multiple levels of browser compatibility - to BrowserCompatSpec and BrowserCompatSpecFactory. Include constructor - argument for IE medium-security compatibility. - Contributed by Karl Wright (kwright at apache.org) - -* [HTTPCLIENT-1349] SSLSocketFactory incorrectly identifies key passed with keystore as - the keystore password. - Contributed by David Graff - -* [HTTPCLIENT-1346] Ensure propagation of SSL handshake exceptions. - Contributed by Pasi Eronen - -* [HTTPCLIENT-1343] SSLSocketFactory optional parameters for supported SSL protocols and cipher - suites. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1238] Contribute Bundle Activator And Central Proxy Configuration. - Contributed by Simone Tripodi - -* [HTTPCLIENT-1299] (regression) cache incorrectly disposes of the underlying cache resource - when storing variant entry. - Contributed by James Leigh - -* [HTTPCLIENT-1342] Redirects with underscore character in the location hostname cause - "java.lang.IllegalArgumentException: Host name may not be null". - Contributed by Oleg Kalnichevski - - - -Release 4.3 BETA1 -------------------- - -This is the first BETA release of HttpClient 4.3. The 4.3 branch enhances HttpClient in several -key areas and includes several notable features and improvements: Support for Java 7 -try-with-resources for resource management (connection release); fluent Builder classes for -HttpEntity, HttpRequest and HttpClient instances, deprecation of preference and configuration API -based on HttpParams interface in favor of constructor injection and plain configuration objects, -reliance on object immutability instead of access synchronization for thread safety. - -This release also includes all fixes from the stable 4.2.x release branch. - - -Changelog -------------------- - -* [HTTPCLIENT-1317] InetAddressUtils should handle IPv6 Addresses with Embedded IPv4 Addresses - Contributed Sebastian Bazley . - -* [HTTPCLIENT-1320] Leverage javax.net.ssl.SSLSocketFactory#getDefault() to initialize SSL context - based on system defaults instead of using an internal custom routine. - Contributed by Abe Backus and Oleg Kalnichevski - -* [HTTPCLIENT-1316] Certificate verification rejects IPv6 addresses which are not String-equal. - Contributed Sebastian Bazley . - -* [HTTPCLIENT-1307] Future based asynchronous request execution. - Contributed by Jilles van Gurp - -* [HTTPCLIENT-1313] Fixed IllegalStateException in deprecated ThreadSafeClientConnManager. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1298] Add AsynchronousValidator in HttpClientBuilder's list of closeable objects. - Contributed by Martin Meinhold - - - -Release 4.3 ALPHA1 -------------------- - -This is the first ALPHA release of HttpClient 4.3. The 4.3 branch enhances HttpClient in several -key areas and includes several notable features and improvements: Support for Java 7 -try-with-resources for resource management (connection release); fluent Builder classes for -HttpEntity, HttpRequest and HttpClient instances, deprecation of preference and configuration API -based on HttpParams interface in favor of constructor injection and plain configuration objects, -reliance on object immutability instead of access synchronization for thread safety. - -We are kindly asking all upstream projects to review API changes and help us improve -the APIs by providing feedback and sharing ideas on dev@hc.apache.org. - -This release also includes all fixes from the stable 4.2.x release branch. - -Please note that new features included in this release are still considered experimental and -their API may change in the future 4.3 alpha and beta releases. - - -Changelog -------------------- - -* [HTTPCLIENT-1250] Allow query string to be ignored when determining cacheability for - HTTP 1.0 responses. - Contributed by Don Brown - -* [HTTPCLIENT-1261] Make SystemDefaultHttpClient honor http.agent system property. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-900] Don't enforce URI syntax for messages with an explicit target host. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1190] HttpClient cache does not support "Vary: Cookie" - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1259] Calling #abort() on requests executed with DecompressingHttpClient has no - effect. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1253] URIBuilder setParameter() method could exceed the HTTP header size. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1216] Added method to force clean thread-local used by DateUtils. - Contributed by Oleg Kalnichevski - - -Release 4.2.3 -------------------- - -HttpClient 4.2.3 (GA) is a bug fix release that addresses a number of issues reported since -release 4.2.2. This release also includes a thoroughly reworked NTLM authentication engine -which should result in a better compatibility with the newest Microsoft products. - -Users of HttpClient 4.x are advised to upgrade. - -Changelog -------------------- - -* [HTTPCLIENT-1296] NPE gets thrown if you combine a default host with a virtual host - that has a -1 value for the port. - Contributed by Karl Wright - -* [HTTPCLIENT-1290] 304 cached response never reused with If-modified-since conditional - requests. - Contributed by Francois-Xavier Bonnet - -* [HTTPCLIENT-1291] Absolute request URIs without an explicitly specified path are rewritten - to have "/" path). - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1286] Request URI rewriting is inconsistent - URI fragments are not removed - from absolute request URIs. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1284] HttpClient incorrectly generates Host header when physical connection - route differs from the host name specified in the request URI. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1293] Kerberos and SPNego auth schemes use incorrect authorization header name - when authenticating with a proxy. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1283] NTLM needs to use Locale-independent form of - toUpperCase(). - Contributed by Karl Wright - -* [HTTPCLIENT-1279] Target host responding with status 407 (proxy authentication required) - causes an NPE. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1281] GzipDecompressingEntity does not release InputStream when an IOException - occurs while reading the Gzip header - Contributed by Francois-Xavier Bonnet - -* [HTTPCLIENT-1277] Caching client sends a 304 to an unconditional request. - Contributed by Francois-Xavier Bonnet - -* [HTTPCLIENT-1278] Update NTLM documentation. - Contributed by Karl Wright - -* SystemDefaultHttpClient misinterprets 'http.keepAlive' default value and disables - connection persistence if the system property is not set. This causes connection - based authentication schemes such as NTLM to fail. - -* [HTTPCLIENT-1276] cache update on a 304 response causes NPE. - Contributed by Francois-Xavier Bonnet - -* [HTTPCLIENT-1273] DecompressingHttpClient does not automatically consume response - content in case of an i/o, HTTP or runtime exception thrown by the decompressing - protocol interceptor leading to a potential connection leak. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1268] NTLM engine refactor fix, to correct a buffer overrun, and get NTLMv2 - flags right. - Contributed by Karl Wright - -* [HTTPCLIENT-1266] NTLM engine refactoring and compatibility improvements. - Contributed by Karl Wright - -* [HTTPCLIENT-1263] BrowserCompatSpec: attribute values containing spaces or special characters - should be enclosed with quotes marks for version 1 cookies. - Contributed by Francois-Xavier Bonnet - -* [HTTPCLIENT-1263] CachingHttpClient fails to release connections back to the connection - manager for some type of HTTP response messages when used together with DecompressingHttpClient. - Contributed by Francois-Xavier Bonnet - -* [HTTPCLIENT-1258] Fixed NullPointerException in NTLMEngineImpl caused by null NT domain - attribute. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1254] Redirect with underscore in hostname causes ProtocolException. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1255] AbstractVerifier incorrectly parses certificate CN containing wildcard. - Contributed by Oleg Kalnichevski - - - -Release 4.2.2 -------------------- - -HttpClient 4.2.2 (GA) is a bug fix release that addresses a number of issues reported since -release 4.2.1. - -Users of HttpClient 4.2 are advised to upgrade. - -Changelog -------------------- - -* [HTTPCLIENT-1248] Default and lax redirect strategies should not convert requests redirected - with 307 status to GET method. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1215] BasicAuthCache does not take default ports into consideration when - looking up cached authentication details by HttpHost key. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1241] (regression) Preemptive BASIC authentication failure should be considered - final and no further attempts to re-authenticate using the same credentials should be made. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1229] Fixed NPE in BasicClientConnectionManager that can be triggered by releasing - connection after the connection manager has already been shut down. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1227] Date parsing in DateUtils made more efficient. - Contributed by Patrick Linskey - -* [HTTPCLIENT-1224] (regression) NTLM auth not retried after a redirect over a non-persistent - connection. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1223] Cache could be more aggressive on cache invalidations - from Content-Location. Contributed by Jon Moore . - Contributed by Jon Moore - -* [HTTPCLIENT-1217] AutoRetryHttpClient does not release connection used by the previous response - when request is retried - Contributed by Oleg Kalnichevski - - - -Release 4.2.1 -------------------- - -HttpClient 4.2.1 (GA) is a bug fix release that addresses a number of issues reported since -release 4.2. - -Users of HttpClient 4.2 are advised to upgrade. - -Changelog -------------------- - -* [HTTPCLIENT-1209] Redirect URIs are now normalized. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1202] ResponseCachingPolicy should honor explicit cache-control - directives for other status codes - Contributed by Jon Moore - -* [HTTPCLIENT-1199] DecompressingHttpClient strips content from entity enclosing requests - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1198] HttpHost is not set in HttpContext in CachingHttpClient. - Contributed by Jon Moore - -* [HTTPCLIENT-1200] DecompressingHttpClient fails to generate correct HttpHost context attribute. - Contributed by Guillaume Castagnino - -* [HTTPCLIENT-1192] URIBuilder encodes query parameters twice. - Contributed by Oleg Kalnichevski and Sebastian Bazley . - -* [HTTPCLIENT-1196] Fixed NPE in UrlEncodedFormEntity constructor thrown if charset is null. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1193] Fixed regression in the route tracking logic of the default connection manager - causing cross-site redirect failures. - Contributed by Oleg Kalnichevski - -Release 4.2 -------------------- - -This is the first stable (GA) release of HttpClient 4.2. The most notable enhancements included -in this release are: - -* New facade API for HttpClient based on the concept of a fluent interface. The fluent API exposes - only the most fundamental functions of HttpClient and is intended for relatively simple use cases - that do not require the full flexibility of HttpClient. However, the fluent API almost fully - relieves the users from having to deal with connection management and resource deallocation. - -* Redesigned and rewritten connection management code. - -* Enhanced HTTP authentication API that enables HttpClient to handle more complex authentication - scenarios. HttpClient 4.2 is now capable of making use of multiple authentication challenges - and retry authentication with a fall-back scheme in case the primary one fails. This can be - important for compatibility with Microsoft products that are often configured to use - SPNEGO/Kerberos as the preferred authentication scheme. - - -Changelog -------------------- - -* [HTTPCLIENT-1187] If a revalidation response is deemed too old CachingHttpClient fails to - consume its content resulting in a connection leak. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1186] State of newly created connections in the connection pool is not always - correctly updated potentially allowing those connections to be leased to users with a different - security context. - Contributed by Ralf Poehlmann - -* [HTTPCLIENT-1179] Upgraded Commons Codec dependency to version 1.6 - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1177] always remove fragments from request URIs - Contributed by Oleg Kalnichevski - -Incompatible changes --------------------- -[Compared to release version 4.1.3] - -The following fields have been deprecated for some time now and have been deleted: - -org.apache.http.client.params.ClientPNames#CONNECTION_MANAGER_FACTORY -org.apache.http.impl.cookie.BrowserCompatSpec#DATE_PATTERNS - -The following methods have been deprecated for some time now and have been deleted: - -org.apache.http.client.params.ClientParamBean#setConnectionManagerFactory(org.apache.http.conn.ClientConnectionManagerFactory) -org.apache.http.client.protocol.ClientContextConfigurer#setAuthSchemePref(java.util.List) -org.apache.http.entity.mime.content.FileBody#writeTo(java.io.OutputStream, int) -org.apache.http.entity.mime.content.InputStreamBody#writeTo(java.io.OutputStream, int) -org.apache.http.entity.mime.content.StringBody#writeTo(java.io.OutputStream, int) - -The following classes have been deprecated for some while now and have been deleted: - -org.apache.http.impl.conn.tsccm.RefQueueHandler -org.apache.http.impl.conn.tsccm.AbstractConnPool no longer implements interface org.apache.http.impl.conn.tsccm.RefQueueHandler -org.apache.http.impl.conn.tsccm.ConnPoolByRoute no longer implements interface org.apache.http.impl.conn.tsccm.RefQueueHandler -org.apache.http.impl.conn.tsccm.RefQueueWorker - - - -Release 4.2 BETA1 -------------------- - -This is the first BETA release of HttpClient 4.2. This release completes development of several -notable enhancements in HttpClient: - -* New facade API for HttpClient based on the concept of a fluent interface. The fluent API exposes - only the most fundamental functions of HttpClient and is intended for relatively simple use cases - that do not require the full flexibility of HttpClient. However, the fluent API almost fully - relieves the users from having to deal with connection management and resource deallocation. - -* Redesigned and rewritten connection management code. As of release 4.2 HttpClient will be using - pooling connection manager per default. - -* Enhanced HTTP authentication API that enables HttpClient to handle more complex authentication - scenarios. HttpClient 4.2 is now capable of making use of multiple authentication challenges - and retry authentication with a fall-back scheme in case the primary one fails. This can be - important for compatibility with Microsoft products that are often configured to use - SPNEGO/Kerberos as the preferred authentication scheme. - - -Changelog -------------------- - -* [HTTPCLIENT-1164] Compressed entities are not being cached properly. - Contributed by Jon Moore . - -* [HTTPCLIENT-1154] MemcachedHttpCacheStorage should allow client to - specify custom prefix string for keys. - Contributed by Jon Moore . - -* [HTTPCLIENT-1153] MemcachedHttpCacheStorage uses URL as cache key; - shouldn't due to fixed maximum-length memcached keys. - Contributed by Jon Moore . - -* [HTTPCLIENT-1157] MemcachedHttpCacheStroage should throw IOExceptions - instead of RuntimeExceptions. - Contributed by James Miller . - -* [HTTPCLIENT-1152] MemcachedHttpCacheStorage should verify class of - returned object before casting. - Contributed by Rajika Kumarasiri . - -* [HTTPCLIENT-1155] CachingHttpClient fails to ensure that the response content gets fully consumed - when using a ResponseHandler, which can potentially lead to connection leaks. - Contributed by James Miller - -* [HTTPCLIENT-1147] When HttpClient-Cache cannot open cache file, should act like miss. - Contributed by Joe Campbell - -* [HTTPCLIENT-1137] Values for the Via header are cached and reused by httpclient-cache. - Contributed by Alin Vasile - -* [HTTPCLIENT-1142] Infinite loop on NTLM authentication failure. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1143] CachingHttpClient leaks connections with stale-if-error. - Contributed by James Miller - -Release 4.2 ALPHA1 -------------------- - -This is the first ALPHA release of HttpClient 4.2. The 4.2 branch enhances HttpClient in several -key areas and includes several notable features and improvements: - -* New facade API for HttpClient based on the concept of a fluent interface. The fluent API exposes - only the most fundamental functions of HttpClient and is intended for relatively simple use cases - that do not require the full flexibility of HttpClient. However, the fluent API almost fully - relieves the users from having to deal with connection management and resource deallocation. - -* Redesigned and rewritten connection management code. As of release 4.2 HttpClient will be using - pooling connection manager per default. - -* Enhanced HTTP authentication API that enables HttpClient to handle more complex authentication - scenarios. HttpClient 4.2 is now capable of making use of multiple authentication challenges - and retry authentication with a fall-back scheme in case the primary one fails. This can be - important for compatibility with Microsoft products that are often configured to use - SPNEGO/Kerberos as the preferred authentication scheme. - -Please note that new features included in this release are still considered experimental and -their API may change in the future ALPHA releases. - -Changelog -------------------- - -* [HTTPCLIENT-1128] SystemDefaultHttpClient (HttpClient implementation initialized using system - properties). - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1135] RandomAccessFile mode 'w' used by HttpClientCache is not valid. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1131] HttpClient to authenticate preemptively using BASIC scheme if a userinfo - attribute is specified in the request URI. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1134] make BasicResponseHandler consume response content in case of an unsuccessful - result (status code >= 300). - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1132] ProxyClient implementation. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1127] fixed dead-lock between SingleClientConnManager and AbstractPooledConnAdapter. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1107] Auth framework redesign. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1116] ResponseCachingPolicy uses integers for sizes - Contributed by Greg Bowyer - -* [HTTPCLIENT-1123] Support for pluggable DNS resolvers. - Contributed by Alin Vasile - -* [HTTPCLIENT-1120] DefaultHttpRequestRetryHandler#retryRequest should not retry aborted requests. - Contributed by Alin Vasile - -* Support for auth-int qop (quality of protection) option in Digest auth scheme. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1076] Fluent facade API (Google summer of code 2011 project). - Contributed by Xu Lilu - -* UriBuilder implementation. - Contributed by Xu Lilu - -* Redesign of connection management classes based on new pooling components from HttpCore. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1111] Added #prepareSocket method to SSLSocketFactory. - Contributed by Pasi Eronen - -* Added #reset() and #releaseConnection() methods to HttpRequestBase. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1105] AutoRetryHttpClient: built-in way to do auto-retry for certain status codes. - Contributed by Dan Checkoway - -* [HTTPCLIENT-1094] Digest auth scheme refactoring. - Contributed by Oleg Kalnichevski - -* Lax implementation of RedirectStrategy. - Contributed by Bartosz Firyn - -* [HTTPCLIENT-1044] HttpRequestRetryHandler implementation compliant with the definition of - idempotent methods given in the RFC 2616. - Contributed by Oleg Kalnichevski - - -Release 4.1.2 -------------------- - -The HttpClient 4.1.2 is a bug fix release that addresses a number of non-critical issues reported -since release 4.1.1. - -* [HTTPCLIENT-1100] Missing Content-Length header makes cached entry invalid - Contributed by Bart Robeyns - -* [HTTPCLIENT-1098] Avoid expensive reverse DNS lookup on connect timeout exception. - Contributed by Thomas Boettcher - -* [HTTPCLIENT-1097] BrowserCompatHostnameVerifier and StrictHostnameVerifier should handle - wildcards in SSL certificates better. - Contributed by Sebastian Bazley - -* [HTTPCLIENT-1092] If ClientPNames.VIRTUAL_HOST does not provide the port, derive it from the - current request. - Contributed by Sebastian Bazley - -* [HTTPCLIENT-1087] NTLM proxy authentication fails on retry if the underlying connection is closed - as a result of a target authentication failure. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1079] Fixed Kerberos cross-realm support - Contributed by Michael Osipov <1983-01-06 at gmx.net> - -* [HTTPCLIENT-1078] Decompressing entities (DeflateDecompressingEntity, GzipDecompressingEntity) - do not close content stream in #writeTo() method. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1075] Decompressing entities (DeflateDecompressingEntity, GzipDecompressingEntity) - do not correctly handle content streaming. - Contributed by James Abley - -* [HTTPCLIENT-1051] Avoid reverse DNS lookups when opening SSL connections by IP address. - Contributed by Oleg Kalnichevski - - -Release 4.1.1 -------------------- - -HttpClient v4.1.1 is a bug fix release that addresses a number of issues reported since -release 4.1, including one critical security issue (HTTPCLIENT-1061). All users of HttpClient 4.0.x -and 4.1 are strongly encouraged to upgrade. - -* [HTTPCLIENT-1069] HttpHostConnectException not correctly retried for direct and non-tunnelled - proxy connections. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1066] Changed the way URIUtils#rewriteURI handles multiple consecutive slashes in the - URI path component: multiple leading slashes will be replaced by one slash in order to avoid - confusion with the authority component. The remaining content of the path will not be modified. - (also see HTTPCLIENT-929). - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1061] Fixed critical bug causing Proxy-Authorization header to be sent to the target - host when tunneling requests through a proxy server that requires authentication. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1056] Fixed bug causing the RequestAuthCache protocol interceptor to generate - an invalid AuthScope instance when looking up user credentials for preemptive authentication. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1053] Fixed the way DigestScheme generates nonce-count values. - Contributed by Oleg Kalnichevski - - -Release 4.1 -------------------- - -The HttpClient 4.1 release builds upon the stable foundation laid by HttpClient 4.0 and adds several -functional improvements and popular features. - -* Response caching conditionally compliant with HTTP/1.1 specification (full compliance with - MUST requirements, partial compliance with SHOULD requirements) - -* Full support for NTLMv1, NTLMv2, and NTLM2 Session authentication. The NTLM protocol code - was kindly contributed by the Lucene Connector Framework project. - -* Support for SPNEGO/Kerberos authentication. - -* Persistence of authentication data between request executions within the same execution context. - -* Support for preemptive authentication for BASIC and DIGEST schemes. - -* Support for transparent content encoding. Please note transparent content encoding is not - enabled per default in order to avoid conflicts with already existing custom content encoding - solutions. - -* Mechanism to bypass the standard certificate trust verification (useful when dealing with - self-signed certificates). - -* Simplified configuration for connection managers. - -* Transparent support for host multihoming. - -IMPORTANT: please note that the HttpClient 3.x branch is now officially END OF LIFE and is no longer -maintained and supported by the Apache HttpComponents project. - -Changelog -------------------- -* The public API for the caching module had a minor change between 4.1-beta and 4.1-GA to the - HttpCacheEntry class - the deprecated public Set getVariantURIs() method and constructor - public HttpCacheEntry(Date requestDate, Date responseDate, - StatusLine statusLine, Header[] responseHeaders, - Resource resource, Set variants) - were both removed. This will not affect you unless you are implementing new storage backends - that use the deprecated code and/or are implementing custom serializers for cache entries. - -* Changed Browser-Compatibility and Best-Match cookie policies to emulate the behaviour of FireFox - more closely when parsing Netscape style cookies. Comma will no longer be treated as a header - element separator if Set-Cookie does not contain a Version attribute mandated by the - RFC2109 / RFC 2965 cookie specifications. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1036] StringBody has incorrect default for characterset. (Default changed - to US-ASCII) - Contributed by Sebastian Bazley - -* [HTTPCLIENT-975] Support stale-if-error and stale-while-revalidate extension directive (RFC5861). - Contributed by Mohammed Azeem Uddin , - Michajlo Matijkiw , and - Matthew Hawthorne . - -* [HTTPCLIENT-1033] HttpRoute.equals(Object o) is quite inefficient, as it does not take full - advantage of shortcut logic. - Contributed by Sebastian Bazley - -* [HTTPCLIENT-1030] Implement "ignoreCookies" CookieSpec - Contributed by Sebastian Bazley - -Release 4.1 BETA1 -------------------- - -HttpClient 4.1 BETA1 finalizes the 4.1 API and brings a number of major improvements to the HTTP -caching module. This release also adds full support for NTLMv1, NTLMv2, and NTLM2 Session -authentication. The NTLM protocol code was kindly contributed by the Lucene Connector Framework -project. - -Changelog -------------------- -* [HTTPCLIENT-1015] Support only-if-cached directive. - Contributed by Michajlo Matijkiw - -* [HTTPCLIENT-990] Allow heuristic freshness caching. - Contributed by Michajlo Matijkiw - -* [HTTPCLIENT-919] Support for NTLMv1, NTLMv2, and NTLM2 Session authentication. - Contributed by Karl Wright - -* [HTTPCLIENT-1008] Send all variants' ETags on "variant miss". - Contributed by Michajlo Matijkiw and - Mohammed Azeem Uddin - -* [HTTPCLIENT-1011] Handling of IOExceptions thrown by cache components. - Contributed by Jonathan Moore - -* [HTTPCLIENT-1003] Handle conditional requests in cache. - Contributed by Michajlo Matijkiw and - Mohammed Azeem Uddin - -* [HTTPCLIENT-1002] Stale connection check fails if wire logging is on. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-1000] Maximum connection lifetimes settings for ThreadSafeClientConnManager. - Contributed by Michajlo Matijkiw - -* [HTTPCLIENT-960] HttpMultipart doesn't generate Content-Type header for binary parts in - BROWSER_COMPATIBLE mode. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-998] Cache should use both Last-Modified and ETag for validations when available. - Contributed by Jonathan Moore - -* [HTTPCLIENT-997] Cache module should handle out-of-order validations properly and unconditionally - refresh. - Contributed by Jonathan Moore - -* [HTTPCLIENT-994] Cache does not allow client to override origin-specified freshness using - max-stale. - Contributed by Jonathan Moore - -* [HTTPCLIENT-995] Cache returns cached responses even if validators not consistent with all - conditional headers. - Contributed by Jonathan Moore - -* [HTTPCLIENT-977] Memcached implementation for HttpCache. - Contributed by Mohammed Azeem Uddin - -* [HTTPCLIENT-992] cache should not generate stale responses to requests explicitly requesting - first-hand or fresh ones. - Contributed by Jonathan Moore - -* [HTTPCLIENT-991] cache module produces improperly formatted Warning header when revalidation - fails. - Contributed by Jonathan Moore - -* [HTTPCLIENT-989] DefaultHttpRequestRetryHandler no longer retries non-idempotent http methods - if NoHttpResponseException is thrown. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-988] Cache module should strip 'Content-Encoding: identity' from responses - Contributed by Jonathan Moore - -* [HTTPCLIENT-987] cache module does not recognize equivalent URIs. - Contributed by Jonathan Moore - -* [HTTPCLIENT-986] cache module does not completely handle upstream Warning headers correctly - Contributed by Jonathan Moore - -* [HTTPCLIENT-985] cache module should populate Via header to capture upstream and downstream protocols - Contributed by Jonathan Moore - -* [HTTPCLIENT-984] Additional conditional compliance tests for the caching module for - Content-Encoding, Content-Location, Date, Expires, Server, Transfer-Encoding, and Vary headers. - Contributed by Jonathan Moore - -* [HTTPCLIENT-978] HTTP cache update exception handling - Contributed by Michajlo Matijkiw - -* [HTTPCLIENT-981] CachingHttpClient returns a 411 respones when executing a POST (HttpPost) - request. - Contributed by Joe Campbell - -* [HTTPCLIENT-980] CachingHttpClient returns a 503 response when the backend HttpClient produces - an IOException. - Contributed by Jonathan Moore - -* [HTTPCLIENT-978] Ehcache based HTTP cache implementation - Contributed by Michajlo Matijkiw - -* [HTTPCLIENT-967] support for non-shared (private) caches - Contributed by Jonathan Moore - -* [HTTPCLIENT-969] BasicCookieStore#getCookies() to return a copy of Cookie list - Contributed by David Smiley - -* [HTTPCLIENT-965] Fixed problem with cache not honoring must-revalidate or - proxy-revalidate Cache-Control directives. - Contributed by Jonathan Moore - -* [HTTPCLIENT-964] 'no-cache' directives with field names are no longer transmitted - downstream. - Contributed by Jonathan Moore - -* [HTTPCLIENT-963] Fixed handling of 'Cache-Control: no-store' on requests. - Contributed by Jonathan Moore - -* [HTTPCLIENT-962] Fixed handling of Authorization headers in shared cache mode. - Contributed by Jonathan Moore - -* [HTTPCLIENT-961] Not all applicable URIs are invalidated on PUT/POST/DELETEs - that pass through client cache. - Contributed by Jonathan Moore - -* [HTTPCLIENT-958] Client cache no longer allows incomplete responses to be - passed on to the client. - Contributed by Jonathan Moore - -* [HTTPCLIENT-951] Non-repeatable entity enclosing requests are not correctly - retried when 'expect-continue' handshake is active. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-948] In rare circumstances the idle connection handling code - can leave closed connections in a inconsistent state. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-953] IllegalStateException thrown by RouteSpecificPool. - Contributed by Guillaume - -* [HTTPCLIENT-952] Trust store parameter is ignored by SSLSocketFactory - (affects version 4.1-alpha2 only) - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-937] CacheEntry made immutable; now uses immutable HttpEntity - to store cached content. - Contributed by David Mays and - Oleg Kalnichevski - -Release 4.1 ALPHA2 -------------------- - -HttpClient 4.1 ALPHA2 fixes a number of non-severe bugs discovered since -the last release and introduces support for two frequently requested features: - -* HTTP/1.1 response caching - -* transparent support for host multihoming - -* a mechanism to bypass the standard certificate trust verification -(useful when dealing with self-signed certificates) - -Compatibility notes -------------------- -(1) Please note the HTTP caching module is still considered experimental and -its API may change significantly in the future releases. - -(2) This release eliminates Mime4J as a dependency for the HttpMime module. -HttpMime is no longer binary compatible with the previous releases. -Full API and binary compatibility between minor versions of HttpMime will be -maintained as of 4.1 GA release. - -Changelog -------------------- - -* [HTTPCLIENT-936] Fixed bug causing NPE or an infinite loop in - the authentication code in case of a SPNEGO authentication failure. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-427] HTTP caching support - Contributed by Joe Campbell, David Cleaver, David Mays, Jon Moore, Brad Spenla - -* Dropped dependency on Mime4j for HttpMime. - Contributed by Oleg Kalnichevski - -* Extended SSLSocketFactory with a mechanism to bypass the standard certificate - trust verification (primarily to simplify dealing with self-signed - certificates) - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-898] Improved support for host multihoming - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-916] UsernamePasswordCredentials, NTUserPrincipal, - BasicClientCookie, BasicClientCookie2 and BasicCookieStore made Serializable. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-914] Upgraded Commons Codec dependency to version 1.4 - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-903] Use ConcurrentHashMap instead of [Linked]HashMap for - thread-safety. Improve performance of AuthSchemeRegistry, CookieSpecRegistry - and SchemeRegistry classes. - Contributed by Sebastian Bazley - -* [HTTPCLIENT-902] HttpRequestRetryHandler not called on I/O exceptions - thrown when opening a new connection. - Contributed by Olivier Lamy and - Oleg Kalnichevski - -Release 4.1 ALPHA1 -------------------- - -HttpClient 4.1 ALPHA1 builds on the stable 4.0 release and adds several -functionality improvements and new features. - -* Simplified configuration of connection managers. - -* Persistence of authentication data between request executions within - the same execution context. - -* Support for SPNEGO/Kerberos authentication scheme - -* Support for transparent content encoding. Please note transparent content - encoding is not enabled per default in order to avoid conflicts with - already existing custom content encoding solutions. - -* 5 to 10% performance increase due to elimination of unnecessary Log object - lookups by short-lived components. - -Please note all methods and classes added in this release and marked as -4.1 are API unstable and can change in the future 4.1 ALPHA releases. - -Changelog -------------------- - -* [HTTPCLIENT-889] 'expect: continue' handshake disabled per default. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-862] Extended client's redirect handling interface to allow - control of the content of the redirect. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-872] HttpClient can now persist authentication data between request - executions as long as they share the same execution context. It has also become - much easier to make HttpClient authenticate preemptively by pre-populating - authentication data cache. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-883] SO_TIMEOUT is not reset on persistent (re-used) connections. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-832] Distinguish cookie format errors from violations of - restrictions imposed by a cookie specification. In the latter case - CookieRestrictionViolationException will be thrown. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-523] Support for SPNEGO authentication scheme. - Contributed by Matthew Stevenson - -* Simplified configuration of connection managers. Total connection maximum - and maximum connection per route limits can be set using methods of - the class instead of HTTP parameters. - Contributed by Oleg Kalnichevski - -* Added parameters to define the order of preference for supported auth - schemes for target host and proxy authentication. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-875] DefaultClientConnectionOperator#openConnection doesn't - update the connection state if the connection socket changed after - the call to SocketFactory#connectSocket(). - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-834] Transparent content encoding support. - Contributed by James Abley - -Release 4.0.1 -------------------- - -This is a bug fix release that addresses a number of issues discovered since -the previous stable release. None of the fixed bugs is considered critical. -Most notably this release eliminates eliminates dependency on JCIP annotations. - -This release is also expected to improve performance by 5 to 10% due to -elimination of unnecessary Log object lookups by short-lived components. - -Changelog -------------------- - -* [HTTPCLIENT-895] Eliminated Log lookups in short lived objects impairing - performance. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-885] URLEncodedUtils now correctly parses form-url-encoded - entities that specify a charset. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-884] UrlEncodedFormEntity now sets charset on the Content-Type - header. - Contributed by Jared Jacobs - -* [HTTPCLIENT-883] SO_TIMEOUT is not reset on persistent (re-used) connections. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-882] Auth state is now correctly updated if a successful NTLM - authentication results in a redirect. This is a minor bug as HttpClient - manages to recover from the problem automatically. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-881] Fixed race condition in AbstractClientConnAdapter that makes - it possible for an aborted connection to be returned to the pool. - Contributed by Tim Boemker and - Oleg Kalnichevski - -* [HTTPCLIENT-866] Removed dependency on jcip-annotations.jar. - Contributed by Oleg Kalnichevski - and Sebastian Bazley - - -Release 4.0 -------------------- - -HttpClient 4.0 represents a complete, ground-up redesign and almost a complete -rewrite of the HttpClient 3.x codeline. This release finally addresses several -design flaws that existed since the 1.0 release and could not be fixed without -a major code overhaul and breaking API compatibility. - - -Architectural changes ---------------------- - -* Redesign of the HttpClient internals addressing all known major - architectural shortcomings of the 3.x codeline. - -* Cleaner, more flexible and expressive API. - -* More modular structure. - -* Better performance and smaller memory footprint due to a more efficient HTTP - transport based on HttpCore. - -* Implementation of cross-cutting HTTP protocol aspects through protocol - interceptors. - -* Improved connection management, better handling of persistent connections, - support for stateful connections - -* Pluggable redirect and authentication handlers. - -* Improved support for sending requests via a proxy or a chain of proxies - -* More flexible SSL context customization - -* Reduced intermediate garbage in the process of generating HTTP requests - and parsing HTTP responses - - -Important notes -------------------- - -* Future releases of HttpMime module may be binary incompatible with this - release due to possible API changes in Apache Mime4J. Apache Mime4J is - still being actively developed and its API is considered unstable. - -* HttpClient 4.0 is not fully binary compatible with 4.0 BETA1 release. - Some protected variables in connection management class have been - made final in order to help ensure their thread safety: - - org.apache.http.conn.BasicEofSensorWatcher#attemptReuse - org.apache.http.conn.BasicEofSensorWatcher#managedConn - org.apache.http.impl.conn.DefaultClientConnectionOperator#schemeRegistry - org.apache.http.impl.conn.DefaultHttpRoutePlanner#schemeRegistry - org.apache.http.impl.conn.ProxySelectorRoutePlanner#schemeRegistry - org.apache.http.impl.conn.SingleClientConnManager#alwaysShutDown - org.apache.http.impl.conn.SingleClientConnManager#connOperator - org.apache.http.impl.conn.SingleClientConnManager#schemeRegistry - org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager#connOperator - org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager#schemeRegistry - - -Bug fixes since 4.0 BETA2 release -------------------- - -* [HTTPCLIENT-861] URIUtils#resolve is now compatible with all examples given - in RFC 3986. - Contributed by Johannes Koch - -* [HTTPCLIENT-860] HttpClient no longer converts redirects of PUT/POST to GET - for status codes 301, 302, 307, as required by the HTTP spec. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-859] CookieIdentityComparator now takes path attribute into - consideration when comparing cookies. - Contributed by Oleg Kalnichevski - -* HttpClient will no longer send expired cookies back to the origin server. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-856] Proxy NTLM authentication no longer fails on a redirect to - a different host. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-841] Removed automatic connection release using garbage collection - due to a memory leak. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-853] Fixed bug causing invalid cookie origin port to be selected - when the target is accessed on the default port and the connection is - established via a proxy. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-852] Fixed bug causing automatically retried redirects fail with - CircularRedirectException. - Contributed by Oleg Kalnichevski - -* Fixed problem with the default HTTP response parser failing to handle garbage - preceding a valid HTTP response. - Contributed by Oleg Kalnichevski - -* NonRepeatableRequestExceptions now include the cause that the original - request failed. - Contributed by Sam Berlin - -* [HTTPCLIENT-837] Fixed problem with the wire log skipping zero byte values - if read one byte at a time. - Contributed by Kirill Safonov - -* [HTTPCLIENT-823] 'http.conn-manager.max-total' parameter can be adjusted - dynamically. However, the size of existing connection pools per route, - once allocated, will not be adjusted. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-822] Default socket factories to rethrow SocketTimeoutException - as ConnectTimeoutException in case of connect failure due to a time out. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-813] Fixed default port resolution. Invalid ports no longer - get replaced with the default port value. - Contributed by Oleg Kalnichevski - -Release 4.0 beta 2 -------------------- - -BETA2 is a maintenance release, which addresses a number of issues -discovered since the previous release. - -The only significant new feature is an addition of an OSGi compliant -bundle combining HttpClient and HttpMime jars. - -All upstream projects are strongly encouraged to upgrade. - -* Fixed NPE in DefaultRequestDirector thrown when retrying a failed - request over a proxied connection. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-803] Fixed bug in SSL host verifier implementations - causing the SSL certificate to be rejected as invalid if the connection - is established using an IP address. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-806] DefaultHttpMethodRetryHandler will no longer retry - on ConnectExceptions. - Contributed by Oleg Kalnichevski - -* DigestScheme can use an arbitrary digest algorithm requested by the - target server (such as SHA) as long as this algorithm is supported by - the Java runtime. - Contributed by Oleg Kalnichevski - -* Fixed parsing and validation of RFC2109 compliant Set-Cookie headers - by the Best-Match cookie spec. - Contributed by Oleg Kalnichevski - -* Fixed bug that can cause a managed connection to be returned from the - pool in an inconsistent state. - Contributed by Oleg Kalnichevski - - -4.0 Beta 1 -------------------- - -BETA1 release brings yet another round of API enhancements and -improvements in the area of connection management. Among the most notable -ones is the capability to handle stateful connections such as persistent -NTLM connections and private key authenticated SSL connections. - -This is the first API stable release of HttpClient 4.0. All further -releases in the 4.0 code line will maintain API compatibility with this -release. - -There has been a number of important bug fixes since ALPHA4. All upstream -projects are encouraged to upgrade to the latest release. - -Please note HttpClient currently provides only limited support for NTLM -authentication. For details please see NTLM_SUPPORT.txt. - -------------------- - -Changelog: -------------------- - -* [HTTPCLIENT-790] Protocol interceptors are now correctly invoked when - executing CONNECT methods. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-668] Do not use static loggers. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-781] Respect Keep-Alive header's timeout value. - Contributed by Sam Berlin - -* [HTTPCLIENT-779] Top-level classes (HttpClient, and HttpGet, HttpPut - and similar HttpMethods) throw fewer checked exceptions. - Contributed by Sam Berlin - -* HttpClient will throw an exception if an attempt is made to retry - a request with a non-repeatable request entity. - Contributed by Oleg Kalnichevski - -* Fixed request re-generation logic when retrying a failed request. - Auto-generated headers will no accumulate. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-424] Preemptive authentication no longer limited to BASIC - scheme only. HttpClient can be customized to authenticate preemptively - with DIGEST scheme. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-670] Pluggable hostname resolver. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-719] Clone support for HTTP request and cookie objects. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-776] Fixed concurrency issues with AbstractPoolEntry. - Contributed by Sam Berlin - -* Resolved a long standing problem with HttpClient not taking into account - the user context when pooling / re-using connections. HttpClient now - correctly handles stateful / user specific connections such as persistent - NTLM connections and SSL connections with client side authentication. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-773] Improved handling of the 'expires' attribute by the - 'Best Match' cookie spec. - Contributed by Oleg Kalnichevski - -* Partial NTLM support (requires an external NTLM engine). For details see - NTLM_SUPPORT.txt - Contributed by Oleg Kalnichevski - -* Redesigned local execution context management. - Contributed by Oleg Kalnichevski - --------------------------------------- - -Release 4.0 Alpha 4 -------------------- - -ALPHA4 marks the completion of the overhaul of the connection management -code in HttpClient. All known shortcomings of the old HttpClient 3.x -connection management API have been addressed. - -NTLM authentication remains the only missing major feature in the new -codeline that prevents us from moving awards the API freeze. - -There has been a number of important bug fixes since ALPHA3. All upstream -projects are encouraged to upgrade to the latest release. - -------------------- - -HttpClient 3.x features that have NOT yet been ported: -------------------- - -* NTLM authentication scheme - -------------------- - -Changelog: -------------------- - -* [HTTPCLIENT-765] String.toLowerCase() / toUpperCase() should specify - Locale.ENGLISH - Contributed by Sebastian Bazley - -* [HTTPCLIENT-769] Do not pool connection marked non-reusable. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-763] Fixed problem with AbstractClientConnAdapter#abortConnection() - not releasing the connection if called from the main execution thread while - there is no blocking I/O operation. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-652] Added optional state attribute to managed client connections. - This enables connection managers to correctly handle stateful connections. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-673] Revised max connections per route configuration - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-753] Class Scheme and related classes moved to a separate package - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-757] Improved request wrapping in the DefaultClientRequestDirector. - This also fixed the problem with the default proxy set at the client level - having no effect. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-734] Request abort will unblock the thread waiting for a connection - Contributed by Sam Berlin - -* [HTTPCLIENT-759] Ensure release of connections back to the connection manager - on exceptions. - Contributed by Sam Berlin - -* [HTTPCLIENT-758] Fixed the use of generics in AbstractHttpClient - #removeRequestInterceptorByClass and #removeResponseInterceptorByClass - Contributed by Johannes Koch - -* [HTTPCLIENT-749] HttpParams beans - Contributed by Stojce Dimski - -* [HTTPCLIENT-755] Workaround for known bugs in java.net.URI.resolve() - Bug ID: 4708535 - Contributed by Johannes Koch - --------------------------------------- - -Release 4.0 Alpha 3 -------------------- - -ALPHA3 release brings another round of API refinements and improvements in -functionality. As of this release HttpClient requires Java 5 compatible -runtime environment and takes full advantage of generics and new concurrency -primitives. - -This release also introduces new default cookie policy that selects a cookie -specification depending on the format of cookies sent by the target host. -It is no longer necessary to know beforehand what kind of HTTP cookie support -the target host provides. HttpClient is now able to pick up either a lenient -or a strict cookie policy depending on the compliance level of the target host. - -Another notable improvement is a completely reworked support for multipart -entities based on Apache mime4j library. - -------------------- - -HttpClient 3.x features that have NOT yet been ported: -------------------- - -* NTLM authentication scheme - -------------------- - -Changelog: -------------------- - -* [HTTPCLIENT-742] common interface for HttpRoute and RouteTracker - Contributed by Roland Weber - -* [HTTPCLIENT-741] Fixed concurrency issues in AbstractClientConnAdapter. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-726] testcase for spurious wakeups in ThreadSafeClientConnManager - Contributed by Roland Weber - -* [HTTPCLIENT-643] Automatic connect fail-over for multi-home remote servers. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-735] unsetting of DEFAULT_PROXY and FORCED_ROUTE in hierarchies - Contributed by Roland Weber - -* [HTTPCLIENT-723] route planner based on java.net.ProxySelector - Contributed by Roland Weber - -* [HTTPCLIENT-740] don't start connection GC thread in pool constructor - Contributed by Roland Weber - -* [HTTPCLIENT-736] route planners use SchemeRegistry instead of ConnManager - Contributed by Roland Weber - -* [HTTPCLIENT-730] Fixed rewriting of URIs containing escaped characters - Contributed by Sam Berlin and - Oleg Kalnichevski - -* [HTTPCLIENT-667] Added 'Meta' cookie policy that selects a cookie - specification depending on the format of the cookie(s). - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-729] Move HttpRoute and related classes to routing package. - Contributed by Roland Weber - -* [HTTPCLIENT-725] Use TimeUnit arguments for timeouts in connection manager. - Contributed by Roland Weber - -* [HTTPCLIENT-677] Connection manager no longer uses Thread.interrupt(). - Contributed by Roland Weber - -* [HTTPCLIENT-716] Allow application-defined routes. - Contributed by Roland Weber - -* [HTTPCLIENT-712] Improve HttpRoute API - Contributed by Roland Weber - -* [HTTPCLIENT-711] Bad route computed for redirected requests - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-715] Remove RoutedRequest from API - Contributed by Roland Weber - -* [HTTPCLIENT-705] Fixed incorrect handling of URIs with null path component. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-688] HttpOptions#getAllowedMethods can now handle multiple - Allow headers. - Contributed by Andrea Selva - --------------------------------------- - -Release 4.0 Alpha 2 -------------------- - -ALPHA2 release is another milestone in the redesign of HttpClient. It includes -a number of improvements since ALPHA1, among which are improved connection -pooling, support for proxy chains, redesigned HTTP state and authentication -credentials management API, improved RFC 2965 cookie specification. - -------------------- - -HttpClient 3.x features that have NOT yet been ported -------------------- -* NTLM authentication scheme - -* Support for multipart MIME coded entities - -------------------- - -Changelog -------------------- - -* [HTTPCLIENT-698] Resolve non-absolute redirect URIs relative to - the request URI - Contributed by Johannes Koch - -* [HTTPCLIENT-697] Throw a more intelligible exception when connection - to a remote host cannot be established. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-689] Caching of SimpleDateFormat in DateUtils - Contributed by Daniel Müller - -* [HTTPCLIENT-689] stackable parameters in AbstractHttpClient - Contributed by Roland Weber - -* [HTTPCLIENT-477] Use distinct instances of the authentication handler - interface for authentication with target and proxy hosts - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-690] ManagedClientConnection provides access to SSLSession - Contributed by Roland Weber - -* [HTTPCLIENT-692] ClientConnectionManager throws InterruptedException - Contributed by Roland Weber - -* [HTTPCORE-116] moved parameter names to interfaces - Contributed by Roland Weber - -* [HTTPCLIENT-649] support for proxy chains in HttpConn - Contributed by Roland Weber - -* [HTTPCLIENT-636] refactor ThreadSafeClientConnManager in separate package - Contributed by Roland Weber - -* [HTTPCLIENT-669] new HttpRoutePlanner interface and implementation - Contributed by Andrea Selva - -* [HTTPCLIENT-653] detached connection wrapper no longer prevents - garbage collection of ThreadSafeClientConnManager - Contributed by Roland Weber - -* [HTTPCLIENT-674] use org.apache.http.util.VersionInfo instead of a local one - Contributed by Roland Weber - -* [HTTPCLIENT-666] Replaced HttpState with CredentialsProvier and CookieStore interfaces - Contributed by Oleg Kalnichevski - -* [HTTPCORE-100] revised HttpContext hierarchy - Contributed by Roland Weber - -* [HTTPCLIENT-618] eliminate class HostConfiguration - Contributed by Roland Weber - -* [HTTPCLIENT-672] re-sync with API changes in core alpha6-SNAPSHOT - Contributed by Roland Weber - --------------------------------------- - -Release 4.0 Alpha 1 -------------------- - -HttpClient 4.0 represents a complete, ground-up redesign and almost a complete -rewrite of the HttpClient 3.x codeline. This release finally addresses several -design flaws that existed since the 1.0 release and could not be fixed without -a major code overhaul and breaking API compatibility. - -The HttpClient 4.0 API is still very experimental and is bound to change -during the course of the ALPHA development phase. Several important features -have not yet been ported to the new API. - -Architectural changes ---------------------- - -* Redesign of the HttpClient internals addressing all known - major architectural shortcomings of the 3.x codeline - -* Cleaner, more flexible and expressive API - -* Better performance and smaller memory footprint due to a more - efficient HTTP transport based on HttpCore. HttpClient 4.0 is - expected to be 10% to 25% faster than HttpClient 3.x codeline - -* More modular structure - -* Pluggable redirect and authentication handlers - -* Support for protocol incerceptors - -* Improved connection management - -* Improved support for sending requests via a proxy or a chain of - proxies - -* Improved handling redirects of entity enclosing requests - -* More flexible SSL context customization - -* Reduced intermediate garbage in the process of - generating HTTP requests and parsing HTTP responses - -------------------- - -HttpClient 3.x features that have NOT yet been ported -------------------- -* NTLM authentication scheme - -* RFC2965 cookie policy (Cookie2) - -* Support for multipart MIME coded entities - -------------------- - -Changelog -------------------- - -The following is a list of contributions tracked in JIRA. -Note that this is not a complete list of contributions or changes. -Since the API was redesigned completely, tracking everything outside -of the source code repository would have been too burdensome. - -* [HTTPCLIENT-655] User-Agent string no longer violates RFC - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-541] Virtual host API redesign - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-614] Allow for different strategies when checking - CN of x509 certificates - Contributed by Julius Davies - -* [HTTPCLIENT-136] Fixed inadequate proxy support - Long standing architectural problem. Issue opened on 19/Dec/2002. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-63] Support for pluggable redirect and authentication handlers - Long standing architectural problem. Issue opened on 15/Jul/2002. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-245] Fixed redirect handling. HttpClient can now automatically - handle redirects of entity enclosing requests. - Long standing architectural problem. Issue opened on 14/Jul/2003. - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-613] HTTPS connections now verify CN of x509 certificates - Contributed by Julius Davies - -* [HTTPCLIENT-497] Wire/header logger names consistent with class loggers - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-484] AuthSSLProtocolSocketFactory in the main distribution - Contributed by Oleg Kalnichevski - -* [HTTPCLIENT-589] Do not consume the remaining response content if - the connection is to be closed - Contributed by Roland Weber - -* [HTTPCLIENT-475] Support for unconnected sockets. HTTP requests can now be - aborted while network socket is still being connected. - Contributed by Roland Weber - +Release 4.5.6 +------------------- + +This is a maintenance release that adds Automatic-Module-Name to the manifest for compatibility +with Java 9 Platform Module System and fixes a number of issues discovered since 4.5.5 + +Please note that as of 4.4 HttpClient requires Java 1.6 or newer. + +Changelog: +------------------- + +* [HTTPCLIENT-1882=: reset authentication state on I/O or runtime error for connection based + authentication schemes (such as NTLM) + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1924]: HttpClient to shut down the connection manager if a fatal error occurs + in the course of a request execution. + Contributed by Oleg Kalnichevski + +* Add Automatic-Module-Name in manifest so Java9 modular applications can depend on this library + Contributed by Varun Nandi + +* [HTTPCLIENT-1923]: fixed incorrect connection close on shutdown + fixed corresponding test + Contributed by Aleksei Arsenev + +* [HTTPCLIENT-1906]: certificates containing alternative subject names other than DNS and IP + (such as RFC822) get rejected as invalid + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1904]: check cookie domain for null + Contributed by Hans-Peter Keck + +* [HTTPCLIENT-1900]: proxy protocol processor does not post-process CONNECT response messages + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1911]: Failing tests on Fedora 28 due to weak encryption algorithms in test + keystore. + Contributed by Gary Gregory and Michael Simacek + + +Release 4.5.5 +------------------- + +HttpClient 4.5.5 (GA) is a maintenance release that fixes a regression introduced +by the previous release causing a NPE in SystemDefaultCredentialsProvider. + +Please note that as of 4.4 HttpClient requires Java 1.6 or newer. + +Changelog: +------------------- + +* [HTTPCLIENT-1690] Avoid merging Content-Encoding headers coming with 304 status to cache entry. + Contributed by Sudheera Palihakkara + +* [HTTPCLIENT-1888] Regression in SystemDefaultCredentialsProvider#getCredentials causing NPE. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1886] Update HttpClient 4.5.x from HttpCore 4.4.7 to 4.4.9 + Contributed by Gary Gregory + +* [HTTPCLIENT-1889] org.apache.http.client.utils.URLEncodedUtils.parse() + should return a new ArrayList when there are no query parameters. + Contributed by Gary Gregory + + +Release 4.5.4 +------------------- + +HttpClient 4.5.4 (GA) is a maintenance release that fixes a number of defects found since 4.5.3. + +Please note that as of 4.4 HttpClient requires Java 1.6 or newer. + +Changelog: +------------------- + +* [HTTPCLIENT-1883] SystemDefaultCredentialsProvider to use https.proxy* system properties + for origins with port 443. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1881] Allow truncated NTLM packets to work with this client. + Contributed by Karl Wright + +* [HTTPCLIENT-1855] Disabled caching of DIGEST auth scheme instances due to unreliability of nonce counter + when the auth cache is shared by multiple sessions. + Contributed by Oleg Kalnichevski + +* BasicCookieStore uses a ReentrantReadWriteLock to avoid synchronization on #getCookies/#toString + while maintaining thread safety. + Contributed by Carter Kozak + +* [HTTPCLIENT-1865] DefaultServiceUnavailableRetryStrategy does not respect HttpEntity#isRepeatable. + Contributed by Tomas Celaya + +* [HTTPCLIENT-1859] Encode Content-Disposition name and filename elements appropriately. + Contributed by Karl Wright + +* Avoid fetching the cached entity twice on cache hit. + Contributed by Leandro Nunes + +* [HTTPCLIENT-1835] #evictExpiredConnections no longer causes the #evictIdleConnections behaviour + to be implicitly enabled. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1831= URIBuilder should not prepend a leading slash to relative URIs. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1833] Fix Windows Negotiate-NTLM handling of proxies. + Contributed by Roman Stoffel + +* [HTTPCLIENT-1817] Add a "Trust All" TrustStrategy implementation. + Contributed by Gary Gregory + +* [HTTPCLIENT-1816] Update Apache Commons Codec 1.9 to 1.10. + Contributed by Gary Gregory + +* [HTTPCLIENT-1836] DefaultHostnameVerifier#getSubjectAltNames(X509Certificate) throws java.lang.ClassCastException. + Contributed by Gary Gregory , Ilian Iliev + +* [HTTPCLIENT-1845]: Extract InputStreamFactory classes out of GzipDecompressingEntity and + DeflateDecompressingEntity for reuse and to create less garbage. + Contributed by Gary Gregory + +* [HTTPCLIENT-1847] Update Ehcache from 2.6.9 to 2.6.11. + Contributed by Gary Gregory + +* [HTTPCLIENT-1848] Update spymemcached from 2.11.4 to 2.12.3. + Contributed by Gary Gregory + +* [HTTPCLIENT-1849] Update JNA from 4.1.0 to 4.4.0. + Contributed by Gary Gregory + +* [HTTPCLIENT-1850] Update SLF4J from 1.7.6 to 1.7.25. + Contributed by Gary Gregory + + +Release 4.5.3 +------------------- + +HttpClient 4.5.3 (GA) is a maintenance release that fixes a number of defects found since 4.5.2. + +Please note that as of 4.4 HttpClient requires Java 1.6 or newer. + +Changelog: +------------------- + +* [HTTPCLIENT-1803] Improved handling of malformed paths by URIBuilder. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1802] Do not attempt to match SSL host to subject CN if subject alternative name of any type are given. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1788] RFC 6265 policy must not reject cookies with paths that are no prefix of the uri path. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1792] SSLConnectionSocketFactory to throw SSLPeerUnverifiedException with a better error message + when hostname verification fails. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1779] [OSGi] support NTLM proxy authentication. + Contributed by Julian Sedding + +* [HTTPCLIENT-1773] [OSGi] HttpProxyConfigurationActivator does not unregister HttpClientBuilderFactory. + Contributed by Julian Sedding + +* [HTTPCLIENT-1771] improve OSGi webconsole display for org.apache.http.proxyconfigurator. + Contributed by Julian Sedding + +* [HTTPCLIENT-1770] OSGi metatype for org.apache.http.proxyconfigurator missing factoryPid. + Contributed by Julian Sedding + +* [HTTPCLIENT-1767] Null pointer dereference in EofSensorInputStream and ResponseEntityProxy. + Contributed by Peter Ansell + +* Support changing system default ProxySelector. + Contributed by Robin Stevens + +* All services registered in the OSGi service registry provide the whole bundle header dictionary as vendor + property value. + Contributed by Christoph Fiehe + +* [HTTPCLIENT-1750] OSGi support for CachingHttpClientBuilder. + Contributed by Justin Edelson + +* [HTTPCLIENT-1749] OSGi client builder to use weak references to track HttpClient instances. + Contributed by Justin Edelson + +* [HTTPCLIENT-1747] apply RequestConfig defaults when using HttpParams values in backward compatibility mode. + Contributed by Oleg Kalnichevski + +* Override LaxRedirectStrategy's INSTANCE field. + Contributed by Eric Wu + +* [HTTPCLIENT-1736] do not request cred delegation by default when using Kerberos auth. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1744] normalize hostname and certificate CN when matching to CN. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1732] SystemDefaultCredentialsProvider to take http.proxyHost and http.proxyPort system + properties into account. + Contributed by Oleg Kalnichevski + +* Revert "HTTPCLIENT-1712: SPNego schemes to take service scheme into account when generating auth token". + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1727] AbstractHttpClient#createClientConnectionManager does not account for context class loader. + Contributed by Charles Allen + +* [HTTPCLIENT-1726:] Copy the SNI fix from SSLConnectionSocketFactory to the deprecated SSLSocketFactory class. + Contributed by David Black + + +Release 4.5.2 +------------------- + +HttpClient 4.5.2 (GA) is a maintenance release that fixes a number of minor defects found since 4.5.1. + +Please note that as of 4.4 HttpClient requires Java 1.6 or newer. + +Changelog: +------------------- + +* [HTTPCLIENT-1710, HTTPCLIENT-1718, HTTPCLEINT-1719] OSGi container compatibility improvements. + Contributed by 212427891 + +* [HTTPCLIENT-1717] Make fluent API Content#Content(byte[], ContentType) public. + Contributed by Cash Costello + +* [HTTPCLIENT-1715] NTLMEngineImpl#Type1Message not thread safe but declared as a constant. + Contributed by Olivier Lafontaine , Gary Gregory + +* [HTTPCLIENT-1714] Add HttpClientBuilder#setDnsResolver(DnsResolver). + Contributed by Alexis Thaveau + +* [HTTPCLIENT-1712] SPNego schemes to take service scheme into account when generating auth token. + Contributed by Georg Romstorfer + +* [HTTPCLIENT-1700] Netscape draft, browser compatibility, RFC 2109, RFC 2965 and default cookie + specs to ignore cookies with empty name for consistency with RFC 6265 specs. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1704] IgnoreSpec#match to always return false. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1550] Fixed 'deflate' zlib header check. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1698] Fixed matching of IPv6 addresses by DefaultHostnameVerifier + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1695] RFC 6265 compliant cookie spec to ignore cookies with empty name / missing + value. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1216] Removed ThreadLocal subclass from DateUtils. + Contributed by Jochen Kemnade + +* [HTTPCLIENT-1685] PublicSuffixDomainFilter to ignore local hosts and local domains. + Contributed by Oleg Kalnichevski + + + +Release 4.5.1 +------------------- + +HttpClient 4.5.1 (GA) is a maintenance release that fixes a number of minor defects found since 4.5. + +Please note that as of 4.4 HttpClient requires Java 1.6 or newer. + +Changelog: +------------------- + +* [HTTPCLIENT-1680] redirect of a POST request causes ClientProtocolException. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1673] org.apache.http.entity.mime.content.* missing from OSGi exports. + Contributed by Benson Margulies + +* [HTTPCLIENT-1668] Fluent request incorrectly handles connect timeout setting. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1667] RequestBuilder does not take charset into account when creating + UrlEncodedFormEntity. + Contributed by Sergey Smith + +* [HTTPCLIENT-1655] HttpClient sends RST instead of FIN ACK sequence when using non-persistant + connections. + Contributed by Oleg Kalnichevski + + + +Release 4.5 +------------------- + +HttpClient 4.5 (GA) is a minor feature release that includes several incremental enhancements +to the exisitng functionality such as support for private domains in the Mozilla Public Suffix List. + +Changelog: +------------------- + +* Reduced default validate after inactivity setting from 5 sec to 2 sec + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1649] Fixed serialization of auth schemes + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1645]: Fluent requests to inherit config parameters of the executor. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1640]: RFC6265 lax cookie policy fails to parse 'max-age' attribute. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1633]: RFC6265CookieSpecProvider compatibility level setting has no effect. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1613]: Support for private domains in Mozilla Public Suffix List. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1651]: Add ability to disable content compression on a request basis + Contributed by Michael Osipov + +* [HTTPCLIENT-1654]: Deprecate/remove RequestConfig#decompressionEnabled in favor of #contentCompressionEnabled + Contributed by Michael Osipov + + + +Release 4.4.1 +------------------- + +HttpClient 4.4.1 (GA) is a maintenance release that fixes a number of defects in new functionality +introduced in version 4.4. + +Users of HttpClient 4.4 are encouraged to upgrade. + +Please note that as of 4.4 HttpClient requires Java 1.6 or newer. + +Changelog: +------------------- + +* Marked RFC 2109, RFC 2965, Netscape draft cookie specs as obsolete + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1633] RFC6265CookieSpecProvider compatibility level setting has no effect. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1628]: Auth cache can fail when domain name contains uppercase characters. + Contributed by Dennis Ju + +* [HTTPCLIENT-1609] Stale connection check in PoolingHttpClientConnectionManager has no effect. + Internal connection pool does not correctly implement connection validation. + Contributed by Charles Lip + + + +Release 4.4 Final +------------------- + +This is the first stable (GA) release of HttpClient 4.4. Notable features and enhancements included +in 4.4 series are: + +* Support for the latest HTTP state management specification (RFC 6265). Please note that the old +cookie policy is still used by default for compatibility reasons. RFC 6265 compliant cookie +policies need to be explicitly configured by the user. Please also note that as of next feature +release support for Netscape draft, RFC 2109 and RFC 2965 cookie policies will be deprecated +and disabled by default. It is recommended to use RFC 6265 compliant policies for new applications +unless compatibility with RFC 2109 and RFC 2965 is required and to migrate existing applications +to the default cookie policy. + +* Enhanced, redesigned and rewritten default SSL hostname verifier with improved RFC 2818 +compliance + +* Default SSL hostname verifier and default cookie policy now validate certificate identity +and cookie domain of origin against the public suffix list maintained by Mozilla.org + + +* More efficient stale connection checking: indiscriminate connection checking which results +in approximately 20 to 50 ms overhead per request has been deprecated in favor of conditional +connection state validation (persistent connections are to be re-validated only if a specified +period inactivity has elapsed) + +* Authentication cache thread-safety: authentication cache used by HttpClient is now thread-safe +and can be shared by multiple threads in order to re-use authentication state for subsequent +requests + +* Native Windows Negotiate and NTLM via SSPI through JNA: when running on Windows OS HttpClient +configured to use native NTLM or SPNEGO authentication schemes can make use of platform specific +functionality via JNA and current user credentials. This functionality is still considered +experimental, known to have compatibility issues and subject to change without prior notice. +Use at your discretion. + +This release also includes all fixes from the stable 4.3.x release branch. + +Please note that as of 4.4 HttpClient requires Java 1.6 or newer. + + +Changelog: +------------------- + +* Support for the latest HTTP state management specification (RFC 6265). + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1515] Caching of responses to HEAD requests + Contributed by Tyrone Cutajar and + Francois-Xavier Bonnet + +* [HTTPCLIENT-1560] Native Windows auth improvements + Contributed by Michael Osipov + +* Update Apache Commons Logging version from 1.1.3 to 1.2. + Contributed by Gary Gregory + +* Update Apache Commons Codec version from 1.6 to 1.9. + Contributed by Gary Gregory + +* Update Ehcache version from 2.2.0 to 2.6.9. + Contributed by Gary Gregory + +* Update Ehcache version from 2.2.0 to 2.6.9. + Contributed by Gary Gregory + +* Update Spymemcached version from 2.6 to 2.11.4. + Contributed by Gary Gregory + +* Update SLF4J version from 1.5.11 to 1.7.7. + Contributed by Gary Gregory + + + + + +Release 4.4 BETA1 +------------------- + +This is the first BETA release of HttpClient 4.4. Notable features and enhancements included +in 4.4 series are: + +* Enhanced redesigned and rewritten default SSL hostname verifier with improved RFC 2818 +compliance + +* Default SSL hostname verifier and default cookie policy now validate certificate identity +and cookie domain of origin against the public suffix list maintained by Mozilla.org + + +* Native windows Negotiate/NTLM via JNA: when running on Windows OS HttpClient configured to use +native NTLM or SPNEGO authentication schemes can make use of platform specific functionality +via JNA and current user system credentials + +* More efficient stale connection checking: indiscriminate connection checking which results +in approximately 20 to 50 ms overhead per request has been deprecated in favor of conditional +connection state validation (persistent connections are to be re-validated only if a specified +period inactivity has elapsed) + +* Authentication cache thread-safety: authentication caches used by HttpClient is now thread-safe +and can be shared by multiple threads in order to re-use authentication state for subsequent +requests + +This release also includes all fixes from the stable 4.3.x release branch. + +Please note that as of 4.4 HttpClient requires Java 1.6 or newer. + + +Changelog: +------------------- + +* [HTTPCLIENT-1547] HttpClient OSGi bundle doesn't import the package "javax.naming". + Contributed by Willem Jiang + +* [HTTPCLIENT-1541] Use correct (HTTP/hostname) service principal name for Windows native + Negotiate/NTLM auth schemes. + Contributed by Ka-Lok Fung + +* Improved compliance with RFC 2818: default hostname verifier to ignore the common name of the + certificate subject if alternative subject names (dNSName or iPAddress) are present. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1540] Support delegated credentials (ISC_REQ_DELEGATE) by Native windows + native Negotiate/NTLM auth schemes. + Contributed by Ka-Lok Fung + + + +Release 4.4 ALPHA1 +------------------- + +This is the first ALPHA release of HttpClient 4.4. Notable features and enhancements included +in the 4.4 branch are: + +* More efficient stale connection checking: indiscriminate connection checking which results +in approximately 20 to 50 ms overhead per request has been deprecated in favor of conditional +connection state validation (persistent connections are to be re-validated only if a specified +period inactivity has elapsed) + +* Native windows Negotiate/NTLM via JNA: when running on Windows OS HttpClient configured to use +native NTLM or SPNEGO authentication schemes can make use of platform specific functionality +via JNA and current user system credentials + +* Authentication cache thread-safety: authentication caches used by HttpClient is now thread-safe +and can be shared by multiple threads in order to re-use authentication state for subsequent +requests + +This release also includes all fixes from the stable 4.3.x release branch. + +Please note that as of 4.4 HttpClient requires Java 1.6 or newer. + +Please note that new features included in this release are still considered experimental and +their API may change in the future 4.4 alpha and beta releases. + + +Changelog: +------------------- + +* [HTTPCLIENT-1493] Indiscriminate connection checking has been deprecated in favor of conditional + connection state validation. Persistent connections are to be re-validated only after a defined + period inactivity prior to being leased to the consumer. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1519] Use the original HttpHost instance passed as a parameter to + HttpClient#execute when generating 'Host' request header. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1491] Enable provision of Service Principal Name in Windows native + auth scheme. + Contributed by Malcolm Smith + +* [HTTPCLIENT-1403] Pluggable content decoders. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1466] FileBodyPart#generateContentType() ignores custom ContentType values. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1461] fixed performance degradation in gzip encoded content processing + introduced by HTTPCLIENT-1432. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1457] Incorrect handling of Windows (NT) credentials by + SystemDefaultCredentialsProvider. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1456] Request retrial after status 503 causes ClientProtocolException. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1454] Make connection operator APIs public. + Contributed by Tamas Cservenak + +* Update JUnit to version 4.11 from 4.9 + Contributed by Gary Gregory + + + +Release 4.3.4 +------------------- + +HttpClient 4.3.4 (GA) is a maintenance release that improves performance in high concurrency +scenarios. This version replaces dynamic proxies with custom proxy classes and eliminates thread +contention in java.reflect.Proxy.newInstance() when leasing connections from the connection pool +and processing response messages. + + +Changelog: +------------------- + +* Replaced dynamic proxies with custom proxy classes to reduce thread contention. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1484] GzipCompressingEntity should not close the underlying output stream + if the entity has not been fully written out due to an exception. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1474] Fixed broken entity enclosing requests in HC Fluent. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1470] CachingExec(ClientExecChain, HttpCache, CacheConfig, AsynchronousValidator) + throws NPE if config is null + + + + +Release 4.3.3 +------------------- + +HttpClient 4.3.3 (GA) is a bug fix release that fixes a regression introduced by the previous +release causing a significant performance degradation in compressed content processing. + +Users of HttpClient 4.3 are encouraged to upgrade. + +Changelog: +------------------- + +* [HTTPCLIENT-1466] FileBodyPart#generateContentType() ignores custom ContentType values. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1453] Thread safety regression in PoolingHttpClientConnectionManager + #closeExpiredConnections that can lead to ConcurrentModificationException. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1461] fixed performance degradation in compressed content processing + introduced by HTTPCLIENT-1432. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1457] Incorrect handling of Windows (NT) credentials by + SystemDefaultCredentialsProvider. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1456] Request retrial after status 503 causes ClientProtocolException. + Contributed by Oleg Kalnichevski + + +Release 4.3.2 +------------------- + +HttpClient 4.3.2 (GA) is a maintenance release that delivers a number of improvements +as well as bug fixes for issues reported since 4.3.1 release. SNI support for +Oracle JRE 1.7+ is being among the most notable improvements. + +Users of HttpClient 4.3 are encouraged to upgrade. + +Changelog: +------------------- + +* [HTTPCLIENT-1447] Clients created with HttpClients.createMinimal do not work with absolute URIs + Contributed by Joseph Walton + +* [HTTPCLIENT-1446] NTLM proxy + BASIC target auth fails with 'Unexpected state: + MSG_TYPE3_GENERATED'. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1443] HttpCache uses the physical host instead of the virtual host as a cache key. + Contributed by Francois-Xavier Bonnet + +* [HTTPCLIENT-1442] Authentication header set by the user gets removed in case + of proxy authentication (affects plan HTTP requests only). + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1441] Caching AsynchronousValidationRequest leaks connections. + Contributed by Dominic Tootell + +* [HTTPCLIENT-1440] 'file' scheme in redirect location URI causes NPE. + Contributed by James Leigh + +* [HTTPCLIENT-1437] Made Executor#execute thread safe. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1119] SNI support (Oracle Java 1.7+ only). + Contributed by Bruno Harbulot + +* [HTTPCLIENT-1435] Fluent Executor ignores custom request properties. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1432] Lazy decompressing of HttpEntity#getContent() to avoid EOFException + in case of an empty response with 'Content-Encoding: gzip' header. + Contributed by Yihua Huang + +* [HTTPCLIENT-1431] (Regression) deprecated connection manager cannot be used with + a custom LayeredSchemeSocketFactory. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1425] Fixed socket closed exception thrown by caching HttpClient when the origin + server sends a long chunked response. + Contributed by James Leigh + +* [HTTPCLIENT-1417] Fixed NPE in BrowserCompatSpec#formatCookies caused by version 1 + cookies with null cookie value. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1416] Fixed NPE in CachingHttpClientBuilder#build(). + Contributed by Oleg Kalnichevski + + + +Release 4.3.1 +------------------- + +HttpClient 4.3.1 (GA) is a bug fix release that addresses a number of issues reported since +release 4.3. + +Users of HttpClient 4.3 are strongly encouraged to upgrade. + +Changelog +------------------- + +* [HTTPCLIENT-1410] Browser compatible hostname verifier no longer rejects + *.co., *.gov., *.info., etc as invalid. + Contributed by Oleg Kalnichevski + +* Ensure X509HostnameVerifier is never null. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1405] CONNECT HTTP/1.1 requests lack mandatory 'Host' header. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1402] Cache default User-Agent value. + Contributed by yuexiaojun + +* [HTTPCLIENT-1398] Fixed invalid OSGi metadata caused by corrupted Maven bundle plugin metadata. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1399] Fixed NPE in RequestBuilder. + Contributed by Oleg Kalnichevski + + + + +Release 4.3 Final +------------------- + +This is the first stable (GA) release of HttpClient 4.3. The most notable enhancements included +in this release are: + +* Support for Java 7 try-with-resources for resource management (connection release.) + +* Added fluent Builder classes for HttpEntity, HttpRequest, HttpClient and SSLContext instances. + +* Deprecation of preference and configuration API based on HttpParams interface in favor of +constructor injection and plain configuration objects. + +* Reliance on object immutability instead of access synchronization for thread safety. +Several old classes whose instances can be shared by multiple request exchanges have +been replaced by immutable equivalents. + +* DefaultHttpClient, DecompressingHttpClient, CachingHttpClient and similar classes are +deprecated in favor of builder classes that produce immutable HttpClient instances. + +* HttpClient builders now dynamically construct a request execution pipeline tailored +specifically to the user configuration by physically excluding unnecessary protocol components. + +* There is now an option to construct a minimal HttpClient implementation that can only execute +basic HTTP message exchanges without redirects, authentication, state management or proxy support. +This feature might be of particular use in web crawler development. + +* There is now option to avoid strict URI syntax for request URIs by executing HTTP requests +with an explicitly specified target host. HttpClient will no longer attempt to parse the request +URI if it does not need to extract the target host from it. + +This release also includes all fixes from the stable 4.2.x release branch. + + +Changelog +------------------- +* [HTTPCLIENT-1371] Weak ETag Validation is Useful On PUT With If-Match + Contributed by James Leigh + +* [HTTPCLIENT-1394] Support for Native windows Negotiate/NTLM via JNA + Contributed by Ryan McKinley + +* [HTTPCLIENT-1384] Expose CacheInvalidator interface. + Contributed by Nicolas Richeton + +* [HTTPCLIENT-1385] Fixed path normalization in CacheKeyGenerator + Contributed by James Leigh + +* [HTTPCLIENT-1370] Response to non-GET requests should never be cached with the default + ResponseCachingPolicy + Contributed by James Leigh + +* [HTTPCLIENT-1373] OPTIONS and TRACE should not invalidate cache + Contributed by James Leigh + +* [HTTPCLIENT-1383] HttpClient enters an infinite loop during NTLM authentication if the opposite + endpoint keeps responding with a type 2 NTLM response after type 3 MTLM message has already been + sent by the client. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1372] Refactor HttpMultipart, and add RFC6532 mode, so that headers in post + are no longer constrained to ASCII values. + Contributed by Karl Wright + +* [HTTPCLIENT-1377] User principal for non-NTLM authentication is incorrectly generated when using + user credentials are specified as NTCredentials + Contributed by Gary Gregory + + + +Release 4.3 BETA2 +------------------- + +This is the second BETA release of HttpClient 4.3. The most notable features and improvements +in the 4.3 branch are: Support for Java 7 try-with-resources for resource management (connection +release); fluent Builder classes for HttpEntity, HttpRequest and HttpClient instances, deprecation +of preference and configuration API based on HttpParams interface in favor of constructor injection +and plain configuration objects, reliance on object immutability instead of access synchronization +for thread safety. + +This release also includes all fixes from the stable 4.2.x release branch. + +Changelog +------------------- + + +* [HTTPCLIENT-1366] org.apache.http.client.utils.URLEncodedUtils should parse the semicolon as a query parameter separator. + Contributed by Gary Gregory + +* [HTTPCLIENT-1365] NPE when ManagedHttpClientConnectionFactory.create(ConnectionConfig) is called with null. + Contributed by Gary Gregory + +* [HTTPCLIENT-1362] Better error messages for connect timed out and connection refused + exceptions. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1360] separate out DeflateInputStream as an independent class, + so it can be used by others. + Contributed by Karl Wright + +* [HTTPCLIENT-1359] repeated requests using the same context fail if they redirect. + Contributed by James Leigh + +* [HTTPCLIENT-1354] do not quote algorithm parameter in DIGEST auth response. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1351] Added utility method to resolve final location from original request, + target host and a list of redirects. + Contributed by James Leigh + +* [HTTPCLIENT-1344] Userinfo credentials in URI should not default to preemptive BASIC + authentication. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1345] Useinfo credentials ignored in redirect location header. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1294] HttpClient to rewrite host name of the redirect location URI in order + to avoid circular redirect exception due to host name case mismatch. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1264] Add support for multiple levels of browser compatibility + to BrowserCompatSpec and BrowserCompatSpecFactory. Include constructor + argument for IE medium-security compatibility. + Contributed by Karl Wright (kwright at apache.org) + +* [HTTPCLIENT-1349] SSLSocketFactory incorrectly identifies key passed with keystore as + the keystore password. + Contributed by David Graff + +* [HTTPCLIENT-1346] Ensure propagation of SSL handshake exceptions. + Contributed by Pasi Eronen + +* [HTTPCLIENT-1343] SSLSocketFactory optional parameters for supported SSL protocols and cipher + suites. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1238] Contribute Bundle Activator And Central Proxy Configuration. + Contributed by Simone Tripodi + +* [HTTPCLIENT-1299] (regression) cache incorrectly disposes of the underlying cache resource + when storing variant entry. + Contributed by James Leigh + +* [HTTPCLIENT-1342] Redirects with underscore character in the location hostname cause + "java.lang.IllegalArgumentException: Host name may not be null". + Contributed by Oleg Kalnichevski + + + +Release 4.3 BETA1 +------------------- + +This is the first BETA release of HttpClient 4.3. The 4.3 branch enhances HttpClient in several +key areas and includes several notable features and improvements: Support for Java 7 +try-with-resources for resource management (connection release); fluent Builder classes for +HttpEntity, HttpRequest and HttpClient instances, deprecation of preference and configuration API +based on HttpParams interface in favor of constructor injection and plain configuration objects, +reliance on object immutability instead of access synchronization for thread safety. + +This release also includes all fixes from the stable 4.2.x release branch. + + +Changelog +------------------- + +* [HTTPCLIENT-1317] InetAddressUtils should handle IPv6 Addresses with Embedded IPv4 Addresses + Contributed Sebastian Bazley . + +* [HTTPCLIENT-1320] Leverage javax.net.ssl.SSLSocketFactory#getDefault() to initialize SSL context + based on system defaults instead of using an internal custom routine. + Contributed by Abe Backus and Oleg Kalnichevski + +* [HTTPCLIENT-1316] Certificate verification rejects IPv6 addresses which are not String-equal. + Contributed Sebastian Bazley . + +* [HTTPCLIENT-1307] Future based asynchronous request execution. + Contributed by Jilles van Gurp + +* [HTTPCLIENT-1313] Fixed IllegalStateException in deprecated ThreadSafeClientConnManager. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1298] Add AsynchronousValidator in HttpClientBuilder's list of closeable objects. + Contributed by Martin Meinhold + + + +Release 4.3 ALPHA1 +------------------- + +This is the first ALPHA release of HttpClient 4.3. The 4.3 branch enhances HttpClient in several +key areas and includes several notable features and improvements: Support for Java 7 +try-with-resources for resource management (connection release); fluent Builder classes for +HttpEntity, HttpRequest and HttpClient instances, deprecation of preference and configuration API +based on HttpParams interface in favor of constructor injection and plain configuration objects, +reliance on object immutability instead of access synchronization for thread safety. + +We are kindly asking all upstream projects to review API changes and help us improve +the APIs by providing feedback and sharing ideas on dev@hc.apache.org. + +This release also includes all fixes from the stable 4.2.x release branch. + +Please note that new features included in this release are still considered experimental and +their API may change in the future 4.3 alpha and beta releases. + + +Changelog +------------------- + +* [HTTPCLIENT-1250] Allow query string to be ignored when determining cacheability for + HTTP 1.0 responses. + Contributed by Don Brown + +* [HTTPCLIENT-1261] Make SystemDefaultHttpClient honor http.agent system property. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-900] Don't enforce URI syntax for messages with an explicit target host. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1190] HttpClient cache does not support "Vary: Cookie" + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1259] Calling #abort() on requests executed with DecompressingHttpClient has no + effect. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1253] URIBuilder setParameter() method could exceed the HTTP header size. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1216] Added method to force clean thread-local used by DateUtils. + Contributed by Oleg Kalnichevski + + +Release 4.2.3 +------------------- + +HttpClient 4.2.3 (GA) is a bug fix release that addresses a number of issues reported since +release 4.2.2. This release also includes a thoroughly reworked NTLM authentication engine +which should result in a better compatibility with the newest Microsoft products. + +Users of HttpClient 4.x are advised to upgrade. + +Changelog +------------------- + +* [HTTPCLIENT-1296] NPE gets thrown if you combine a default host with a virtual host + that has a -1 value for the port. + Contributed by Karl Wright + +* [HTTPCLIENT-1290] 304 cached response never reused with If-modified-since conditional + requests. + Contributed by Francois-Xavier Bonnet + +* [HTTPCLIENT-1291] Absolute request URIs without an explicitly specified path are rewritten + to have "/" path). + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1286] Request URI rewriting is inconsistent - URI fragments are not removed + from absolute request URIs. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1284] HttpClient incorrectly generates Host header when physical connection + route differs from the host name specified in the request URI. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1293] Kerberos and SPNego auth schemes use incorrect authorization header name + when authenticating with a proxy. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1283] NTLM needs to use Locale-independent form of + toUpperCase(). + Contributed by Karl Wright + +* [HTTPCLIENT-1279] Target host responding with status 407 (proxy authentication required) + causes an NPE. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1281] GzipDecompressingEntity does not release InputStream when an IOException + occurs while reading the Gzip header + Contributed by Francois-Xavier Bonnet + +* [HTTPCLIENT-1277] Caching client sends a 304 to an unconditional request. + Contributed by Francois-Xavier Bonnet + +* [HTTPCLIENT-1278] Update NTLM documentation. + Contributed by Karl Wright + +* SystemDefaultHttpClient misinterprets 'http.keepAlive' default value and disables + connection persistence if the system property is not set. This causes connection + based authentication schemes such as NTLM to fail. + +* [HTTPCLIENT-1276] cache update on a 304 response causes NPE. + Contributed by Francois-Xavier Bonnet + +* [HTTPCLIENT-1273] DecompressingHttpClient does not automatically consume response + content in case of an i/o, HTTP or runtime exception thrown by the decompressing + protocol interceptor leading to a potential connection leak. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1268] NTLM engine refactor fix, to correct a buffer overrun, and get NTLMv2 + flags right. + Contributed by Karl Wright + +* [HTTPCLIENT-1266] NTLM engine refactoring and compatibility improvements. + Contributed by Karl Wright + +* [HTTPCLIENT-1263] BrowserCompatSpec: attribute values containing spaces or special characters + should be enclosed with quotes marks for version 1 cookies. + Contributed by Francois-Xavier Bonnet + +* [HTTPCLIENT-1263] CachingHttpClient fails to release connections back to the connection + manager for some type of HTTP response messages when used together with DecompressingHttpClient. + Contributed by Francois-Xavier Bonnet + +* [HTTPCLIENT-1258] Fixed NullPointerException in NTLMEngineImpl caused by null NT domain + attribute. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1254] Redirect with underscore in hostname causes ProtocolException. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1255] AbstractVerifier incorrectly parses certificate CN containing wildcard. + Contributed by Oleg Kalnichevski + + + +Release 4.2.2 +------------------- + +HttpClient 4.2.2 (GA) is a bug fix release that addresses a number of issues reported since +release 4.2.1. + +Users of HttpClient 4.2 are advised to upgrade. + +Changelog +------------------- + +* [HTTPCLIENT-1248] Default and lax redirect strategies should not convert requests redirected + with 307 status to GET method. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1215] BasicAuthCache does not take default ports into consideration when + looking up cached authentication details by HttpHost key. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1241] (regression) Preemptive BASIC authentication failure should be considered + final and no further attempts to re-authenticate using the same credentials should be made. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1229] Fixed NPE in BasicClientConnectionManager that can be triggered by releasing + connection after the connection manager has already been shut down. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1227] Date parsing in DateUtils made more efficient. + Contributed by Patrick Linskey + +* [HTTPCLIENT-1224] (regression) NTLM auth not retried after a redirect over a non-persistent + connection. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1223] Cache could be more aggressive on cache invalidations + from Content-Location. Contributed by Jon Moore . + Contributed by Jon Moore + +* [HTTPCLIENT-1217] AutoRetryHttpClient does not release connection used by the previous response + when request is retried + Contributed by Oleg Kalnichevski + + + +Release 4.2.1 +------------------- + +HttpClient 4.2.1 (GA) is a bug fix release that addresses a number of issues reported since +release 4.2. + +Users of HttpClient 4.2 are advised to upgrade. + +Changelog +------------------- + +* [HTTPCLIENT-1209] Redirect URIs are now normalized. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1202] ResponseCachingPolicy should honor explicit cache-control + directives for other status codes + Contributed by Jon Moore + +* [HTTPCLIENT-1199] DecompressingHttpClient strips content from entity enclosing requests + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1198] HttpHost is not set in HttpContext in CachingHttpClient. + Contributed by Jon Moore + +* [HTTPCLIENT-1200] DecompressingHttpClient fails to generate correct HttpHost context attribute. + Contributed by Guillaume Castagnino + +* [HTTPCLIENT-1192] URIBuilder encodes query parameters twice. + Contributed by Oleg Kalnichevski and Sebastian Bazley . + +* [HTTPCLIENT-1196] Fixed NPE in UrlEncodedFormEntity constructor thrown if charset is null. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1193] Fixed regression in the route tracking logic of the default connection manager + causing cross-site redirect failures. + Contributed by Oleg Kalnichevski + +Release 4.2 +------------------- + +This is the first stable (GA) release of HttpClient 4.2. The most notable enhancements included +in this release are: + +* New facade API for HttpClient based on the concept of a fluent interface. The fluent API exposes + only the most fundamental functions of HttpClient and is intended for relatively simple use cases + that do not require the full flexibility of HttpClient. However, the fluent API almost fully + relieves the users from having to deal with connection management and resource deallocation. + +* Redesigned and rewritten connection management code. + +* Enhanced HTTP authentication API that enables HttpClient to handle more complex authentication + scenarios. HttpClient 4.2 is now capable of making use of multiple authentication challenges + and retry authentication with a fall-back scheme in case the primary one fails. This can be + important for compatibility with Microsoft products that are often configured to use + SPNEGO/Kerberos as the preferred authentication scheme. + + +Changelog +------------------- + +* [HTTPCLIENT-1187] If a revalidation response is deemed too old CachingHttpClient fails to + consume its content resulting in a connection leak. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1186] State of newly created connections in the connection pool is not always + correctly updated potentially allowing those connections to be leased to users with a different + security context. + Contributed by Ralf Poehlmann + +* [HTTPCLIENT-1179] Upgraded Commons Codec dependency to version 1.6 + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1177] always remove fragments from request URIs + Contributed by Oleg Kalnichevski + +Incompatible changes +-------------------- +[Compared to release version 4.1.3] + +The following fields have been deprecated for some time now and have been deleted: + +org.apache.http.client.params.ClientPNames#CONNECTION_MANAGER_FACTORY +org.apache.http.impl.cookie.BrowserCompatSpec#DATE_PATTERNS + +The following methods have been deprecated for some time now and have been deleted: + +org.apache.http.client.params.ClientParamBean#setConnectionManagerFactory(org.apache.http.conn.ClientConnectionManagerFactory) +org.apache.http.client.protocol.ClientContextConfigurer#setAuthSchemePref(java.util.List) +org.apache.http.entity.mime.content.FileBody#writeTo(java.io.OutputStream, int) +org.apache.http.entity.mime.content.InputStreamBody#writeTo(java.io.OutputStream, int) +org.apache.http.entity.mime.content.StringBody#writeTo(java.io.OutputStream, int) + +The following classes have been deprecated for some while now and have been deleted: + +org.apache.http.impl.conn.tsccm.RefQueueHandler +org.apache.http.impl.conn.tsccm.AbstractConnPool no longer implements interface org.apache.http.impl.conn.tsccm.RefQueueHandler +org.apache.http.impl.conn.tsccm.ConnPoolByRoute no longer implements interface org.apache.http.impl.conn.tsccm.RefQueueHandler +org.apache.http.impl.conn.tsccm.RefQueueWorker + + + +Release 4.2 BETA1 +------------------- + +This is the first BETA release of HttpClient 4.2. This release completes development of several +notable enhancements in HttpClient: + +* New facade API for HttpClient based on the concept of a fluent interface. The fluent API exposes + only the most fundamental functions of HttpClient and is intended for relatively simple use cases + that do not require the full flexibility of HttpClient. However, the fluent API almost fully + relieves the users from having to deal with connection management and resource deallocation. + +* Redesigned and rewritten connection management code. As of release 4.2 HttpClient will be using + pooling connection manager per default. + +* Enhanced HTTP authentication API that enables HttpClient to handle more complex authentication + scenarios. HttpClient 4.2 is now capable of making use of multiple authentication challenges + and retry authentication with a fall-back scheme in case the primary one fails. This can be + important for compatibility with Microsoft products that are often configured to use + SPNEGO/Kerberos as the preferred authentication scheme. + + +Changelog +------------------- + +* [HTTPCLIENT-1164] Compressed entities are not being cached properly. + Contributed by Jon Moore . + +* [HTTPCLIENT-1154] MemcachedHttpCacheStorage should allow client to + specify custom prefix string for keys. + Contributed by Jon Moore . + +* [HTTPCLIENT-1153] MemcachedHttpCacheStorage uses URL as cache key; + shouldn't due to fixed maximum-length memcached keys. + Contributed by Jon Moore . + +* [HTTPCLIENT-1157] MemcachedHttpCacheStroage should throw IOExceptions + instead of RuntimeExceptions. + Contributed by James Miller . + +* [HTTPCLIENT-1152] MemcachedHttpCacheStorage should verify class of + returned object before casting. + Contributed by Rajika Kumarasiri . + +* [HTTPCLIENT-1155] CachingHttpClient fails to ensure that the response content gets fully consumed + when using a ResponseHandler, which can potentially lead to connection leaks. + Contributed by James Miller + +* [HTTPCLIENT-1147] When HttpClient-Cache cannot open cache file, should act like miss. + Contributed by Joe Campbell + +* [HTTPCLIENT-1137] Values for the Via header are cached and reused by httpclient-cache. + Contributed by Alin Vasile + +* [HTTPCLIENT-1142] Infinite loop on NTLM authentication failure. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1143] CachingHttpClient leaks connections with stale-if-error. + Contributed by James Miller + +Release 4.2 ALPHA1 +------------------- + +This is the first ALPHA release of HttpClient 4.2. The 4.2 branch enhances HttpClient in several +key areas and includes several notable features and improvements: + +* New facade API for HttpClient based on the concept of a fluent interface. The fluent API exposes + only the most fundamental functions of HttpClient and is intended for relatively simple use cases + that do not require the full flexibility of HttpClient. However, the fluent API almost fully + relieves the users from having to deal with connection management and resource deallocation. + +* Redesigned and rewritten connection management code. As of release 4.2 HttpClient will be using + pooling connection manager per default. + +* Enhanced HTTP authentication API that enables HttpClient to handle more complex authentication + scenarios. HttpClient 4.2 is now capable of making use of multiple authentication challenges + and retry authentication with a fall-back scheme in case the primary one fails. This can be + important for compatibility with Microsoft products that are often configured to use + SPNEGO/Kerberos as the preferred authentication scheme. + +Please note that new features included in this release are still considered experimental and +their API may change in the future ALPHA releases. + +Changelog +------------------- + +* [HTTPCLIENT-1128] SystemDefaultHttpClient (HttpClient implementation initialized using system + properties). + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1135] RandomAccessFile mode 'w' used by HttpClientCache is not valid. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1131] HttpClient to authenticate preemptively using BASIC scheme if a userinfo + attribute is specified in the request URI. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1134] make BasicResponseHandler consume response content in case of an unsuccessful + result (status code >= 300). + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1132] ProxyClient implementation. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1127] fixed dead-lock between SingleClientConnManager and AbstractPooledConnAdapter. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1107] Auth framework redesign. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1116] ResponseCachingPolicy uses integers for sizes + Contributed by Greg Bowyer + +* [HTTPCLIENT-1123] Support for pluggable DNS resolvers. + Contributed by Alin Vasile + +* [HTTPCLIENT-1120] DefaultHttpRequestRetryHandler#retryRequest should not retry aborted requests. + Contributed by Alin Vasile + +* Support for auth-int qop (quality of protection) option in Digest auth scheme. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1076] Fluent facade API (Google summer of code 2011 project). + Contributed by Xu Lilu + +* UriBuilder implementation. + Contributed by Xu Lilu + +* Redesign of connection management classes based on new pooling components from HttpCore. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1111] Added #prepareSocket method to SSLSocketFactory. + Contributed by Pasi Eronen + +* Added #reset() and #releaseConnection() methods to HttpRequestBase. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1105] AutoRetryHttpClient: built-in way to do auto-retry for certain status codes. + Contributed by Dan Checkoway + +* [HTTPCLIENT-1094] Digest auth scheme refactoring. + Contributed by Oleg Kalnichevski + +* Lax implementation of RedirectStrategy. + Contributed by Bartosz Firyn + +* [HTTPCLIENT-1044] HttpRequestRetryHandler implementation compliant with the definition of + idempotent methods given in the RFC 2616. + Contributed by Oleg Kalnichevski + + +Release 4.1.2 +------------------- + +The HttpClient 4.1.2 is a bug fix release that addresses a number of non-critical issues reported +since release 4.1.1. + +* [HTTPCLIENT-1100] Missing Content-Length header makes cached entry invalid + Contributed by Bart Robeyns + +* [HTTPCLIENT-1098] Avoid expensive reverse DNS lookup on connect timeout exception. + Contributed by Thomas Boettcher + +* [HTTPCLIENT-1097] BrowserCompatHostnameVerifier and StrictHostnameVerifier should handle + wildcards in SSL certificates better. + Contributed by Sebastian Bazley + +* [HTTPCLIENT-1092] If ClientPNames.VIRTUAL_HOST does not provide the port, derive it from the + current request. + Contributed by Sebastian Bazley + +* [HTTPCLIENT-1087] NTLM proxy authentication fails on retry if the underlying connection is closed + as a result of a target authentication failure. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1079] Fixed Kerberos cross-realm support + Contributed by Michael Osipov <1983-01-06 at gmx.net> + +* [HTTPCLIENT-1078] Decompressing entities (DeflateDecompressingEntity, GzipDecompressingEntity) + do not close content stream in #writeTo() method. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1075] Decompressing entities (DeflateDecompressingEntity, GzipDecompressingEntity) + do not correctly handle content streaming. + Contributed by James Abley + +* [HTTPCLIENT-1051] Avoid reverse DNS lookups when opening SSL connections by IP address. + Contributed by Oleg Kalnichevski + + +Release 4.1.1 +------------------- + +HttpClient v4.1.1 is a bug fix release that addresses a number of issues reported since +release 4.1, including one critical security issue (HTTPCLIENT-1061). All users of HttpClient 4.0.x +and 4.1 are strongly encouraged to upgrade. + +* [HTTPCLIENT-1069] HttpHostConnectException not correctly retried for direct and non-tunnelled + proxy connections. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1066] Changed the way URIUtils#rewriteURI handles multiple consecutive slashes in the + URI path component: multiple leading slashes will be replaced by one slash in order to avoid + confusion with the authority component. The remaining content of the path will not be modified. + (also see HTTPCLIENT-929). + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1061] Fixed critical bug causing Proxy-Authorization header to be sent to the target + host when tunneling requests through a proxy server that requires authentication. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1056] Fixed bug causing the RequestAuthCache protocol interceptor to generate + an invalid AuthScope instance when looking up user credentials for preemptive authentication. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1053] Fixed the way DigestScheme generates nonce-count values. + Contributed by Oleg Kalnichevski + + +Release 4.1 +------------------- + +The HttpClient 4.1 release builds upon the stable foundation laid by HttpClient 4.0 and adds several +functional improvements and popular features. + +* Response caching conditionally compliant with HTTP/1.1 specification (full compliance with + MUST requirements, partial compliance with SHOULD requirements) + +* Full support for NTLMv1, NTLMv2, and NTLM2 Session authentication. The NTLM protocol code + was kindly contributed by the Lucene Connector Framework project. + +* Support for SPNEGO/Kerberos authentication. + +* Persistence of authentication data between request executions within the same execution context. + +* Support for preemptive authentication for BASIC and DIGEST schemes. + +* Support for transparent content encoding. Please note transparent content encoding is not + enabled per default in order to avoid conflicts with already existing custom content encoding + solutions. + +* Mechanism to bypass the standard certificate trust verification (useful when dealing with + self-signed certificates). + +* Simplified configuration for connection managers. + +* Transparent support for host multihoming. + +IMPORTANT: please note that the HttpClient 3.x branch is now officially END OF LIFE and is no longer +maintained and supported by the Apache HttpComponents project. + +Changelog +------------------- +* The public API for the caching module had a minor change between 4.1-beta and 4.1-GA to the + HttpCacheEntry class - the deprecated public Set getVariantURIs() method and constructor + public HttpCacheEntry(Date requestDate, Date responseDate, + StatusLine statusLine, Header[] responseHeaders, + Resource resource, Set variants) + were both removed. This will not affect you unless you are implementing new storage backends + that use the deprecated code and/or are implementing custom serializers for cache entries. + +* Changed Browser-Compatibility and Best-Match cookie policies to emulate the behaviour of FireFox + more closely when parsing Netscape style cookies. Comma will no longer be treated as a header + element separator if Set-Cookie does not contain a Version attribute mandated by the + RFC2109 / RFC 2965 cookie specifications. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1036] StringBody has incorrect default for characterset. (Default changed + to US-ASCII) + Contributed by Sebastian Bazley + +* [HTTPCLIENT-975] Support stale-if-error and stale-while-revalidate extension directive (RFC5861). + Contributed by Mohammed Azeem Uddin , + Michajlo Matijkiw , and + Matthew Hawthorne . + +* [HTTPCLIENT-1033] HttpRoute.equals(Object o) is quite inefficient, as it does not take full + advantage of shortcut logic. + Contributed by Sebastian Bazley + +* [HTTPCLIENT-1030] Implement "ignoreCookies" CookieSpec + Contributed by Sebastian Bazley + +Release 4.1 BETA1 +------------------- + +HttpClient 4.1 BETA1 finalizes the 4.1 API and brings a number of major improvements to the HTTP +caching module. This release also adds full support for NTLMv1, NTLMv2, and NTLM2 Session +authentication. The NTLM protocol code was kindly contributed by the Lucene Connector Framework +project. + +Changelog +------------------- +* [HTTPCLIENT-1015] Support only-if-cached directive. + Contributed by Michajlo Matijkiw + +* [HTTPCLIENT-990] Allow heuristic freshness caching. + Contributed by Michajlo Matijkiw + +* [HTTPCLIENT-919] Support for NTLMv1, NTLMv2, and NTLM2 Session authentication. + Contributed by Karl Wright + +* [HTTPCLIENT-1008] Send all variants' ETags on "variant miss". + Contributed by Michajlo Matijkiw and + Mohammed Azeem Uddin + +* [HTTPCLIENT-1011] Handling of IOExceptions thrown by cache components. + Contributed by Jonathan Moore + +* [HTTPCLIENT-1003] Handle conditional requests in cache. + Contributed by Michajlo Matijkiw and + Mohammed Azeem Uddin + +* [HTTPCLIENT-1002] Stale connection check fails if wire logging is on. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-1000] Maximum connection lifetimes settings for ThreadSafeClientConnManager. + Contributed by Michajlo Matijkiw + +* [HTTPCLIENT-960] HttpMultipart doesn't generate Content-Type header for binary parts in + BROWSER_COMPATIBLE mode. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-998] Cache should use both Last-Modified and ETag for validations when available. + Contributed by Jonathan Moore + +* [HTTPCLIENT-997] Cache module should handle out-of-order validations properly and unconditionally + refresh. + Contributed by Jonathan Moore + +* [HTTPCLIENT-994] Cache does not allow client to override origin-specified freshness using + max-stale. + Contributed by Jonathan Moore + +* [HTTPCLIENT-995] Cache returns cached responses even if validators not consistent with all + conditional headers. + Contributed by Jonathan Moore + +* [HTTPCLIENT-977] Memcached implementation for HttpCache. + Contributed by Mohammed Azeem Uddin + +* [HTTPCLIENT-992] cache should not generate stale responses to requests explicitly requesting + first-hand or fresh ones. + Contributed by Jonathan Moore + +* [HTTPCLIENT-991] cache module produces improperly formatted Warning header when revalidation + fails. + Contributed by Jonathan Moore + +* [HTTPCLIENT-989] DefaultHttpRequestRetryHandler no longer retries non-idempotent http methods + if NoHttpResponseException is thrown. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-988] Cache module should strip 'Content-Encoding: identity' from responses + Contributed by Jonathan Moore + +* [HTTPCLIENT-987] cache module does not recognize equivalent URIs. + Contributed by Jonathan Moore + +* [HTTPCLIENT-986] cache module does not completely handle upstream Warning headers correctly + Contributed by Jonathan Moore + +* [HTTPCLIENT-985] cache module should populate Via header to capture upstream and downstream protocols + Contributed by Jonathan Moore + +* [HTTPCLIENT-984] Additional conditional compliance tests for the caching module for + Content-Encoding, Content-Location, Date, Expires, Server, Transfer-Encoding, and Vary headers. + Contributed by Jonathan Moore + +* [HTTPCLIENT-978] HTTP cache update exception handling + Contributed by Michajlo Matijkiw + +* [HTTPCLIENT-981] CachingHttpClient returns a 411 respones when executing a POST (HttpPost) + request. + Contributed by Joe Campbell + +* [HTTPCLIENT-980] CachingHttpClient returns a 503 response when the backend HttpClient produces + an IOException. + Contributed by Jonathan Moore + +* [HTTPCLIENT-978] Ehcache based HTTP cache implementation + Contributed by Michajlo Matijkiw + +* [HTTPCLIENT-967] support for non-shared (private) caches + Contributed by Jonathan Moore + +* [HTTPCLIENT-969] BasicCookieStore#getCookies() to return a copy of Cookie list + Contributed by David Smiley + +* [HTTPCLIENT-965] Fixed problem with cache not honoring must-revalidate or + proxy-revalidate Cache-Control directives. + Contributed by Jonathan Moore + +* [HTTPCLIENT-964] 'no-cache' directives with field names are no longer transmitted + downstream. + Contributed by Jonathan Moore + +* [HTTPCLIENT-963] Fixed handling of 'Cache-Control: no-store' on requests. + Contributed by Jonathan Moore + +* [HTTPCLIENT-962] Fixed handling of Authorization headers in shared cache mode. + Contributed by Jonathan Moore + +* [HTTPCLIENT-961] Not all applicable URIs are invalidated on PUT/POST/DELETEs + that pass through client cache. + Contributed by Jonathan Moore + +* [HTTPCLIENT-958] Client cache no longer allows incomplete responses to be + passed on to the client. + Contributed by Jonathan Moore + +* [HTTPCLIENT-951] Non-repeatable entity enclosing requests are not correctly + retried when 'expect-continue' handshake is active. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-948] In rare circumstances the idle connection handling code + can leave closed connections in a inconsistent state. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-953] IllegalStateException thrown by RouteSpecificPool. + Contributed by Guillaume + +* [HTTPCLIENT-952] Trust store parameter is ignored by SSLSocketFactory + (affects version 4.1-alpha2 only) + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-937] CacheEntry made immutable; now uses immutable HttpEntity + to store cached content. + Contributed by David Mays and + Oleg Kalnichevski + +Release 4.1 ALPHA2 +------------------- + +HttpClient 4.1 ALPHA2 fixes a number of non-severe bugs discovered since +the last release and introduces support for two frequently requested features: + +* HTTP/1.1 response caching + +* transparent support for host multihoming + +* a mechanism to bypass the standard certificate trust verification +(useful when dealing with self-signed certificates) + +Compatibility notes +------------------- +(1) Please note the HTTP caching module is still considered experimental and +its API may change significantly in the future releases. + +(2) This release eliminates Mime4J as a dependency for the HttpMime module. +HttpMime is no longer binary compatible with the previous releases. +Full API and binary compatibility between minor versions of HttpMime will be +maintained as of 4.1 GA release. + +Changelog +------------------- + +* [HTTPCLIENT-936] Fixed bug causing NPE or an infinite loop in + the authentication code in case of a SPNEGO authentication failure. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-427] HTTP caching support + Contributed by Joe Campbell, David Cleaver, David Mays, Jon Moore, Brad Spenla + +* Dropped dependency on Mime4j for HttpMime. + Contributed by Oleg Kalnichevski + +* Extended SSLSocketFactory with a mechanism to bypass the standard certificate + trust verification (primarily to simplify dealing with self-signed + certificates) + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-898] Improved support for host multihoming + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-916] UsernamePasswordCredentials, NTUserPrincipal, + BasicClientCookie, BasicClientCookie2 and BasicCookieStore made Serializable. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-914] Upgraded Commons Codec dependency to version 1.4 + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-903] Use ConcurrentHashMap instead of [Linked]HashMap for + thread-safety. Improve performance of AuthSchemeRegistry, CookieSpecRegistry + and SchemeRegistry classes. + Contributed by Sebastian Bazley + +* [HTTPCLIENT-902] HttpRequestRetryHandler not called on I/O exceptions + thrown when opening a new connection. + Contributed by Olivier Lamy and + Oleg Kalnichevski + +Release 4.1 ALPHA1 +------------------- + +HttpClient 4.1 ALPHA1 builds on the stable 4.0 release and adds several +functionality improvements and new features. + +* Simplified configuration of connection managers. + +* Persistence of authentication data between request executions within + the same execution context. + +* Support for SPNEGO/Kerberos authentication scheme + +* Support for transparent content encoding. Please note transparent content + encoding is not enabled per default in order to avoid conflicts with + already existing custom content encoding solutions. + +* 5 to 10% performance increase due to elimination of unnecessary Log object + lookups by short-lived components. + +Please note all methods and classes added in this release and marked as +4.1 are API unstable and can change in the future 4.1 ALPHA releases. + +Changelog +------------------- + +* [HTTPCLIENT-889] 'expect: continue' handshake disabled per default. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-862] Extended client's redirect handling interface to allow + control of the content of the redirect. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-872] HttpClient can now persist authentication data between request + executions as long as they share the same execution context. It has also become + much easier to make HttpClient authenticate preemptively by pre-populating + authentication data cache. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-883] SO_TIMEOUT is not reset on persistent (re-used) connections. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-832] Distinguish cookie format errors from violations of + restrictions imposed by a cookie specification. In the latter case + CookieRestrictionViolationException will be thrown. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-523] Support for SPNEGO authentication scheme. + Contributed by Matthew Stevenson + +* Simplified configuration of connection managers. Total connection maximum + and maximum connection per route limits can be set using methods of + the class instead of HTTP parameters. + Contributed by Oleg Kalnichevski + +* Added parameters to define the order of preference for supported auth + schemes for target host and proxy authentication. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-875] DefaultClientConnectionOperator#openConnection doesn't + update the connection state if the connection socket changed after + the call to SocketFactory#connectSocket(). + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-834] Transparent content encoding support. + Contributed by James Abley + +Release 4.0.1 +------------------- + +This is a bug fix release that addresses a number of issues discovered since +the previous stable release. None of the fixed bugs is considered critical. +Most notably this release eliminates eliminates dependency on JCIP annotations. + +This release is also expected to improve performance by 5 to 10% due to +elimination of unnecessary Log object lookups by short-lived components. + +Changelog +------------------- + +* [HTTPCLIENT-895] Eliminated Log lookups in short lived objects impairing + performance. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-885] URLEncodedUtils now correctly parses form-url-encoded + entities that specify a charset. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-884] UrlEncodedFormEntity now sets charset on the Content-Type + header. + Contributed by Jared Jacobs + +* [HTTPCLIENT-883] SO_TIMEOUT is not reset on persistent (re-used) connections. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-882] Auth state is now correctly updated if a successful NTLM + authentication results in a redirect. This is a minor bug as HttpClient + manages to recover from the problem automatically. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-881] Fixed race condition in AbstractClientConnAdapter that makes + it possible for an aborted connection to be returned to the pool. + Contributed by Tim Boemker and + Oleg Kalnichevski + +* [HTTPCLIENT-866] Removed dependency on jcip-annotations.jar. + Contributed by Oleg Kalnichevski + and Sebastian Bazley + + +Release 4.0 +------------------- + +HttpClient 4.0 represents a complete, ground-up redesign and almost a complete +rewrite of the HttpClient 3.x codeline. This release finally addresses several +design flaws that existed since the 1.0 release and could not be fixed without +a major code overhaul and breaking API compatibility. + + +Architectural changes +--------------------- + +* Redesign of the HttpClient internals addressing all known major + architectural shortcomings of the 3.x codeline. + +* Cleaner, more flexible and expressive API. + +* More modular structure. + +* Better performance and smaller memory footprint due to a more efficient HTTP + transport based on HttpCore. + +* Implementation of cross-cutting HTTP protocol aspects through protocol + interceptors. + +* Improved connection management, better handling of persistent connections, + support for stateful connections + +* Pluggable redirect and authentication handlers. + +* Improved support for sending requests via a proxy or a chain of proxies + +* More flexible SSL context customization + +* Reduced intermediate garbage in the process of generating HTTP requests + and parsing HTTP responses + + +Important notes +------------------- + +* Future releases of HttpMime module may be binary incompatible with this + release due to possible API changes in Apache Mime4J. Apache Mime4J is + still being actively developed and its API is considered unstable. + +* HttpClient 4.0 is not fully binary compatible with 4.0 BETA1 release. + Some protected variables in connection management class have been + made final in order to help ensure their thread safety: + + org.apache.http.conn.BasicEofSensorWatcher#attemptReuse + org.apache.http.conn.BasicEofSensorWatcher#managedConn + org.apache.http.impl.conn.DefaultClientConnectionOperator#schemeRegistry + org.apache.http.impl.conn.DefaultHttpRoutePlanner#schemeRegistry + org.apache.http.impl.conn.ProxySelectorRoutePlanner#schemeRegistry + org.apache.http.impl.conn.SingleClientConnManager#alwaysShutDown + org.apache.http.impl.conn.SingleClientConnManager#connOperator + org.apache.http.impl.conn.SingleClientConnManager#schemeRegistry + org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager#connOperator + org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager#schemeRegistry + + +Bug fixes since 4.0 BETA2 release +------------------- + +* [HTTPCLIENT-861] URIUtils#resolve is now compatible with all examples given + in RFC 3986. + Contributed by Johannes Koch + +* [HTTPCLIENT-860] HttpClient no longer converts redirects of PUT/POST to GET + for status codes 301, 302, 307, as required by the HTTP spec. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-859] CookieIdentityComparator now takes path attribute into + consideration when comparing cookies. + Contributed by Oleg Kalnichevski + +* HttpClient will no longer send expired cookies back to the origin server. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-856] Proxy NTLM authentication no longer fails on a redirect to + a different host. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-841] Removed automatic connection release using garbage collection + due to a memory leak. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-853] Fixed bug causing invalid cookie origin port to be selected + when the target is accessed on the default port and the connection is + established via a proxy. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-852] Fixed bug causing automatically retried redirects fail with + CircularRedirectException. + Contributed by Oleg Kalnichevski + +* Fixed problem with the default HTTP response parser failing to handle garbage + preceding a valid HTTP response. + Contributed by Oleg Kalnichevski + +* NonRepeatableRequestExceptions now include the cause that the original + request failed. + Contributed by Sam Berlin + +* [HTTPCLIENT-837] Fixed problem with the wire log skipping zero byte values + if read one byte at a time. + Contributed by Kirill Safonov + +* [HTTPCLIENT-823] 'http.conn-manager.max-total' parameter can be adjusted + dynamically. However, the size of existing connection pools per route, + once allocated, will not be adjusted. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-822] Default socket factories to rethrow SocketTimeoutException + as ConnectTimeoutException in case of connect failure due to a time out. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-813] Fixed default port resolution. Invalid ports no longer + get replaced with the default port value. + Contributed by Oleg Kalnichevski + +Release 4.0 beta 2 +------------------- + +BETA2 is a maintenance release, which addresses a number of issues +discovered since the previous release. + +The only significant new feature is an addition of an OSGi compliant +bundle combining HttpClient and HttpMime jars. + +All upstream projects are strongly encouraged to upgrade. + +* Fixed NPE in DefaultRequestDirector thrown when retrying a failed + request over a proxied connection. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-803] Fixed bug in SSL host verifier implementations + causing the SSL certificate to be rejected as invalid if the connection + is established using an IP address. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-806] DefaultHttpMethodRetryHandler will no longer retry + on ConnectExceptions. + Contributed by Oleg Kalnichevski + +* DigestScheme can use an arbitrary digest algorithm requested by the + target server (such as SHA) as long as this algorithm is supported by + the Java runtime. + Contributed by Oleg Kalnichevski + +* Fixed parsing and validation of RFC2109 compliant Set-Cookie headers + by the Best-Match cookie spec. + Contributed by Oleg Kalnichevski + +* Fixed bug that can cause a managed connection to be returned from the + pool in an inconsistent state. + Contributed by Oleg Kalnichevski + + +4.0 Beta 1 +------------------- + +BETA1 release brings yet another round of API enhancements and +improvements in the area of connection management. Among the most notable +ones is the capability to handle stateful connections such as persistent +NTLM connections and private key authenticated SSL connections. + +This is the first API stable release of HttpClient 4.0. All further +releases in the 4.0 code line will maintain API compatibility with this +release. + +There has been a number of important bug fixes since ALPHA4. All upstream +projects are encouraged to upgrade to the latest release. + +Please note HttpClient currently provides only limited support for NTLM +authentication. For details please see NTLM_SUPPORT.txt. + +------------------- + +Changelog: +------------------- + +* [HTTPCLIENT-790] Protocol interceptors are now correctly invoked when + executing CONNECT methods. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-668] Do not use static loggers. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-781] Respect Keep-Alive header's timeout value. + Contributed by Sam Berlin + +* [HTTPCLIENT-779] Top-level classes (HttpClient, and HttpGet, HttpPut + and similar HttpMethods) throw fewer checked exceptions. + Contributed by Sam Berlin + +* HttpClient will throw an exception if an attempt is made to retry + a request with a non-repeatable request entity. + Contributed by Oleg Kalnichevski + +* Fixed request re-generation logic when retrying a failed request. + Auto-generated headers will no accumulate. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-424] Preemptive authentication no longer limited to BASIC + scheme only. HttpClient can be customized to authenticate preemptively + with DIGEST scheme. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-670] Pluggable hostname resolver. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-719] Clone support for HTTP request and cookie objects. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-776] Fixed concurrency issues with AbstractPoolEntry. + Contributed by Sam Berlin + +* Resolved a long standing problem with HttpClient not taking into account + the user context when pooling / re-using connections. HttpClient now + correctly handles stateful / user specific connections such as persistent + NTLM connections and SSL connections with client side authentication. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-773] Improved handling of the 'expires' attribute by the + 'Best Match' cookie spec. + Contributed by Oleg Kalnichevski + +* Partial NTLM support (requires an external NTLM engine). For details see + NTLM_SUPPORT.txt + Contributed by Oleg Kalnichevski + +* Redesigned local execution context management. + Contributed by Oleg Kalnichevski + +-------------------------------------- + +Release 4.0 Alpha 4 +------------------- + +ALPHA4 marks the completion of the overhaul of the connection management +code in HttpClient. All known shortcomings of the old HttpClient 3.x +connection management API have been addressed. + +NTLM authentication remains the only missing major feature in the new +codeline that prevents us from moving awards the API freeze. + +There has been a number of important bug fixes since ALPHA3. All upstream +projects are encouraged to upgrade to the latest release. + +------------------- + +HttpClient 3.x features that have NOT yet been ported: +------------------- + +* NTLM authentication scheme + +------------------- + +Changelog: +------------------- + +* [HTTPCLIENT-765] String.toLowerCase() / toUpperCase() should specify + Locale.ENGLISH + Contributed by Sebastian Bazley + +* [HTTPCLIENT-769] Do not pool connection marked non-reusable. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-763] Fixed problem with AbstractClientConnAdapter#abortConnection() + not releasing the connection if called from the main execution thread while + there is no blocking I/O operation. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-652] Added optional state attribute to managed client connections. + This enables connection managers to correctly handle stateful connections. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-673] Revised max connections per route configuration + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-753] Class Scheme and related classes moved to a separate package + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-757] Improved request wrapping in the DefaultClientRequestDirector. + This also fixed the problem with the default proxy set at the client level + having no effect. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-734] Request abort will unblock the thread waiting for a connection + Contributed by Sam Berlin + +* [HTTPCLIENT-759] Ensure release of connections back to the connection manager + on exceptions. + Contributed by Sam Berlin + +* [HTTPCLIENT-758] Fixed the use of generics in AbstractHttpClient + #removeRequestInterceptorByClass and #removeResponseInterceptorByClass + Contributed by Johannes Koch + +* [HTTPCLIENT-749] HttpParams beans + Contributed by Stojce Dimski + +* [HTTPCLIENT-755] Workaround for known bugs in java.net.URI.resolve() + Bug ID: 4708535 + Contributed by Johannes Koch + +-------------------------------------- + +Release 4.0 Alpha 3 +------------------- + +ALPHA3 release brings another round of API refinements and improvements in +functionality. As of this release HttpClient requires Java 5 compatible +runtime environment and takes full advantage of generics and new concurrency +primitives. + +This release also introduces new default cookie policy that selects a cookie +specification depending on the format of cookies sent by the target host. +It is no longer necessary to know beforehand what kind of HTTP cookie support +the target host provides. HttpClient is now able to pick up either a lenient +or a strict cookie policy depending on the compliance level of the target host. + +Another notable improvement is a completely reworked support for multipart +entities based on Apache mime4j library. + +------------------- + +HttpClient 3.x features that have NOT yet been ported: +------------------- + +* NTLM authentication scheme + +------------------- + +Changelog: +------------------- + +* [HTTPCLIENT-742] common interface for HttpRoute and RouteTracker + Contributed by Roland Weber + +* [HTTPCLIENT-741] Fixed concurrency issues in AbstractClientConnAdapter. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-726] testcase for spurious wakeups in ThreadSafeClientConnManager + Contributed by Roland Weber + +* [HTTPCLIENT-643] Automatic connect fail-over for multi-home remote servers. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-735] unsetting of DEFAULT_PROXY and FORCED_ROUTE in hierarchies + Contributed by Roland Weber + +* [HTTPCLIENT-723] route planner based on java.net.ProxySelector + Contributed by Roland Weber + +* [HTTPCLIENT-740] don't start connection GC thread in pool constructor + Contributed by Roland Weber + +* [HTTPCLIENT-736] route planners use SchemeRegistry instead of ConnManager + Contributed by Roland Weber + +* [HTTPCLIENT-730] Fixed rewriting of URIs containing escaped characters + Contributed by Sam Berlin and + Oleg Kalnichevski + +* [HTTPCLIENT-667] Added 'Meta' cookie policy that selects a cookie + specification depending on the format of the cookie(s). + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-729] Move HttpRoute and related classes to routing package. + Contributed by Roland Weber + +* [HTTPCLIENT-725] Use TimeUnit arguments for timeouts in connection manager. + Contributed by Roland Weber + +* [HTTPCLIENT-677] Connection manager no longer uses Thread.interrupt(). + Contributed by Roland Weber + +* [HTTPCLIENT-716] Allow application-defined routes. + Contributed by Roland Weber + +* [HTTPCLIENT-712] Improve HttpRoute API + Contributed by Roland Weber + +* [HTTPCLIENT-711] Bad route computed for redirected requests + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-715] Remove RoutedRequest from API + Contributed by Roland Weber + +* [HTTPCLIENT-705] Fixed incorrect handling of URIs with null path component. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-688] HttpOptions#getAllowedMethods can now handle multiple + Allow headers. + Contributed by Andrea Selva + +-------------------------------------- + +Release 4.0 Alpha 2 +------------------- + +ALPHA2 release is another milestone in the redesign of HttpClient. It includes +a number of improvements since ALPHA1, among which are improved connection +pooling, support for proxy chains, redesigned HTTP state and authentication +credentials management API, improved RFC 2965 cookie specification. + +------------------- + +HttpClient 3.x features that have NOT yet been ported +------------------- +* NTLM authentication scheme + +* Support for multipart MIME coded entities + +------------------- + +Changelog +------------------- + +* [HTTPCLIENT-698] Resolve non-absolute redirect URIs relative to + the request URI + Contributed by Johannes Koch + +* [HTTPCLIENT-697] Throw a more intelligible exception when connection + to a remote host cannot be established. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-689] Caching of SimpleDateFormat in DateUtils + Contributed by Daniel Müller + +* [HTTPCLIENT-689] stackable parameters in AbstractHttpClient + Contributed by Roland Weber + +* [HTTPCLIENT-477] Use distinct instances of the authentication handler + interface for authentication with target and proxy hosts + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-690] ManagedClientConnection provides access to SSLSession + Contributed by Roland Weber + +* [HTTPCLIENT-692] ClientConnectionManager throws InterruptedException + Contributed by Roland Weber + +* [HTTPCORE-116] moved parameter names to interfaces + Contributed by Roland Weber + +* [HTTPCLIENT-649] support for proxy chains in HttpConn + Contributed by Roland Weber + +* [HTTPCLIENT-636] refactor ThreadSafeClientConnManager in separate package + Contributed by Roland Weber + +* [HTTPCLIENT-669] new HttpRoutePlanner interface and implementation + Contributed by Andrea Selva + +* [HTTPCLIENT-653] detached connection wrapper no longer prevents + garbage collection of ThreadSafeClientConnManager + Contributed by Roland Weber + +* [HTTPCLIENT-674] use org.apache.http.util.VersionInfo instead of a local one + Contributed by Roland Weber + +* [HTTPCLIENT-666] Replaced HttpState with CredentialsProvier and CookieStore interfaces + Contributed by Oleg Kalnichevski + +* [HTTPCORE-100] revised HttpContext hierarchy + Contributed by Roland Weber + +* [HTTPCLIENT-618] eliminate class HostConfiguration + Contributed by Roland Weber + +* [HTTPCLIENT-672] re-sync with API changes in core alpha6-SNAPSHOT + Contributed by Roland Weber + +-------------------------------------- + +Release 4.0 Alpha 1 +------------------- + +HttpClient 4.0 represents a complete, ground-up redesign and almost a complete +rewrite of the HttpClient 3.x codeline. This release finally addresses several +design flaws that existed since the 1.0 release and could not be fixed without +a major code overhaul and breaking API compatibility. + +The HttpClient 4.0 API is still very experimental and is bound to change +during the course of the ALPHA development phase. Several important features +have not yet been ported to the new API. + +Architectural changes +--------------------- + +* Redesign of the HttpClient internals addressing all known + major architectural shortcomings of the 3.x codeline + +* Cleaner, more flexible and expressive API + +* Better performance and smaller memory footprint due to a more + efficient HTTP transport based on HttpCore. HttpClient 4.0 is + expected to be 10% to 25% faster than HttpClient 3.x codeline + +* More modular structure + +* Pluggable redirect and authentication handlers + +* Support for protocol incerceptors + +* Improved connection management + +* Improved support for sending requests via a proxy or a chain of + proxies + +* Improved handling redirects of entity enclosing requests + +* More flexible SSL context customization + +* Reduced intermediate garbage in the process of + generating HTTP requests and parsing HTTP responses + +------------------- + +HttpClient 3.x features that have NOT yet been ported +------------------- +* NTLM authentication scheme + +* RFC2965 cookie policy (Cookie2) + +* Support for multipart MIME coded entities + +------------------- + +Changelog +------------------- + +The following is a list of contributions tracked in JIRA. +Note that this is not a complete list of contributions or changes. +Since the API was redesigned completely, tracking everything outside +of the source code repository would have been too burdensome. + +* [HTTPCLIENT-655] User-Agent string no longer violates RFC + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-541] Virtual host API redesign + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-614] Allow for different strategies when checking + CN of x509 certificates + Contributed by Julius Davies + +* [HTTPCLIENT-136] Fixed inadequate proxy support + Long standing architectural problem. Issue opened on 19/Dec/2002. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-63] Support for pluggable redirect and authentication handlers + Long standing architectural problem. Issue opened on 15/Jul/2002. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-245] Fixed redirect handling. HttpClient can now automatically + handle redirects of entity enclosing requests. + Long standing architectural problem. Issue opened on 14/Jul/2003. + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-613] HTTPS connections now verify CN of x509 certificates + Contributed by Julius Davies + +* [HTTPCLIENT-497] Wire/header logger names consistent with class loggers + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-484] AuthSSLProtocolSocketFactory in the main distribution + Contributed by Oleg Kalnichevski + +* [HTTPCLIENT-589] Do not consume the remaining response content if + the connection is to be closed + Contributed by Roland Weber + +* [HTTPCLIENT-475] Support for unconnected sockets. HTTP requests can now be + aborted while network socket is still being connected. + Contributed by Roland Weber + diff --git a/swarmit/thirdparty/httpcomponents-client-4.5.6/lib/commons-codec-1.10.jar b/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/commons-codec-1.10.jar similarity index 100% rename from swarmit/thirdparty/httpcomponents-client-4.5.6/lib/commons-codec-1.10.jar rename to polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/commons-codec-1.10.jar diff --git a/swarmit/thirdparty/httpcomponents-client-4.5.6/lib/commons-logging-1.2.jar b/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/commons-logging-1.2.jar similarity index 100% rename from swarmit/thirdparty/httpcomponents-client-4.5.6/lib/commons-logging-1.2.jar rename to polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/commons-logging-1.2.jar diff --git a/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/fluent-hc-4.5.6.jar b/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/fluent-hc-4.5.6.jar new file mode 100644 index 0000000..8fbaf98 Binary files /dev/null and b/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/fluent-hc-4.5.6.jar differ diff --git a/swarmit/thirdparty/httpcomponents-client-4.5.6/lib/httpclient-4.5.6.jar b/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/httpclient-4.5.6.jar similarity index 100% rename from swarmit/thirdparty/httpcomponents-client-4.5.6/lib/httpclient-4.5.6.jar rename to polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/httpclient-4.5.6.jar diff --git a/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/httpclient-cache-4.5.6.jar b/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/httpclient-cache-4.5.6.jar new file mode 100644 index 0000000..df529e3 Binary files /dev/null and b/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/httpclient-cache-4.5.6.jar differ diff --git a/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/httpclient-win-4.5.6.jar b/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/httpclient-win-4.5.6.jar new file mode 100644 index 0000000..cd8fedf Binary files /dev/null and b/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/httpclient-win-4.5.6.jar differ diff --git a/swarmit/thirdparty/httpcomponents-client-4.5.6/lib/httpcore-4.4.10.jar b/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/httpcore-4.4.10.jar similarity index 100% rename from swarmit/thirdparty/httpcomponents-client-4.5.6/lib/httpcore-4.4.10.jar rename to polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/httpcore-4.4.10.jar diff --git a/swarmit/thirdparty/httpcomponents-client-4.5.6/lib/httpmime-4.5.6.jar b/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/httpmime-4.5.6.jar similarity index 100% rename from swarmit/thirdparty/httpcomponents-client-4.5.6/lib/httpmime-4.5.6.jar rename to polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/httpmime-4.5.6.jar diff --git a/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/jna-4.4.0.jar b/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/jna-4.4.0.jar new file mode 100644 index 0000000..521bd92 Binary files /dev/null and b/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/jna-4.4.0.jar differ diff --git a/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/jna-platform-4.4.0.jar b/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/jna-platform-4.4.0.jar new file mode 100644 index 0000000..ce54d8f Binary files /dev/null and b/polyswarm/thirdparty/httpcomponents-client-4.5.6/lib/jna-platform-4.4.0.jar differ diff --git a/swarmit/thirdparty/json/json-20180813.jar b/polyswarm/thirdparty/json/json-20180813.jar similarity index 100% rename from swarmit/thirdparty/json/json-20180813.jar rename to polyswarm/thirdparty/json/json-20180813.jar diff --git a/swarmit/thirdparty/sqlite-jdbc-3.25.2/sqlite-jdbc-3.25.2.jar b/polyswarm/thirdparty/sqlite-jdbc-3.25.2/sqlite-jdbc-3.25.2.jar similarity index 100% rename from swarmit/thirdparty/sqlite-jdbc-3.25.2/sqlite-jdbc-3.25.2.jar rename to polyswarm/thirdparty/sqlite-jdbc-3.25.2/sqlite-jdbc-3.25.2.jar diff --git a/swarmit/manifest.mf b/swarmit/manifest.mf deleted file mode 100644 index 28b2fcd..0000000 --- a/swarmit/manifest.mf +++ /dev/null @@ -1,5 +0,0 @@ -Manifest-Version: 1.0 -AutoUpdate-Show-In-Client: true -OpenIDE-Module: io.polyswarm.swarmit -OpenIDE-Module-Localizing-Bundle: io/polyswarm/swarmit/Bundle.properties -OpenIDE-Module-Specification-Version: 2.0.1 diff --git a/swarmit/src/io/polyswarm/swarmit/optionspanel/Bundle.properties b/swarmit/src/io/polyswarm/swarmit/optionspanel/Bundle.properties deleted file mode 100644 index 142d0f4..0000000 --- a/swarmit/src/io/polyswarm/swarmit/optionspanel/Bundle.properties +++ /dev/null @@ -1,15 +0,0 @@ -SwarmItPanel.testConnectionStatusLabel.text=Connection Status Message -SwarmItPanel.testButton.text=Test Connection -SwarmItPanel.apiUrlTitle.text=PolySwarm API URL -SwarmItPanel.apiUrlTextField.toolTipText=Enter the URL for the PolySwarm API Service -SwarmItPanel.apiUrlTextField.text=https://api.polyswarm.network/v2/ -SwarmItPanel.apiUrlErrorMsgLabel.text=Invalid API URL -SwarmItPanel.apiKeyTitle.text=PolySwarm API KEY -SwarmItPanel.apiKeyTextField.text= -SwarmItPanel.apiKeyTextField.toolTipText=Enter your API KEY for access to the PolySwarm API Service -SwarmItPanel.apiKeyErrorMsgLabel.text=Invalid API Key -SwarmItPanel.communityPanel.border.title=PolySwarm Community -SwarmItPanel.communityTextField.text=default -SwarmItPanel.communityErrorMsgLabel.text=Invalid Community -SwarmItPanel.communityTextField.toolTipText=Enter the community for the PolySwarm API Service -SwarmItPanel.communityTitle.text=PolySwarm Community