Skip to content

Commit 1c3ea04

Browse files
authored
Merge pull request #85 from secure-software-engineering/develop
Restructure, bump and improve project modules
2 parents 38a73d9 + 8081d8d commit 1c3ea04

File tree

278 files changed

+6584
-20239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

278 files changed

+6584
-20239
lines changed

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
# SWAN (Security methods for WeAkNess detection)
22

3-
What is SWAN?
4-
-------------
5-
SWAN is a machine-learning approach used to detect of security-relevant methods (SRM) in Java programs.
3+
SWAN is a machine-learning approach that detects security-relevant methods (SRM) in Java programs.
64
SWAN should be used in combination with other static analyses tools and it helps the users to create a set of relevant methods required as an input for static analyses, e.g. taint- and type-state analysis.
75
The tool currently detects four types of security relevant methods, namely: source, sink, sanitizer, and authentication methods.
8-
The detected methods are further categorized according to relevant vulnerabilities from the [Common Weakness Enumeration (CWE)](https://cwe.mitre.org/). The following CWEs are currently supported: [CWE78 OS Command Injection](https://cwe.mitre.org/data/definitions/78.html), [CWE79 Cross-site Scripting](https://cwe.mitre.org/data/definitions/79.html), [CWE89 SQL Injection](https://cwe.mitre.org/data/definitions/89.html), [CWE306 Missing Authentication](https://cwe.mitre.org/data/definitions/306.html), [CWE601 Open Redirect](https://cwe.mitre.org/data/definitions/601.html), [CWE862 Missing Authorisation](https://cwe.mitre.org/data/definitions/862.html), and
6+
SWAN also labels methods as relevant for 7 [Common Weakness Enumeration (CWE)](https://cwe.mitre.org/), namely: [CWE78 OS Command Injection](https://cwe.mitre.org/data/definitions/78.html), [CWE79 Cross-site Scripting](https://cwe.mitre.org/data/definitions/79.html), [CWE89 SQL Injection](https://cwe.mitre.org/data/definitions/89.html), [CWE306 Missing Authentication](https://cwe.mitre.org/data/definitions/306.html), [CWE601 Open Redirect](https://cwe.mitre.org/data/definitions/601.html), [CWE862 Missing Authorisation](https://cwe.mitre.org/data/definitions/862.html), and
97
[CWE863 Incorrect Authorisation](https://cwe.mitre.org/data/definitions/863.html).
108

11-
The project contains the following modules:
12-
* **swan-pipeline**: core machine learning implementation for SWAN with components for data collection and preparation, feature engineering and model selection phases
13-
* **swan-assist**: IntelliJ plugin provides GUI support for SWAN and enables active machine learning.
14-
* **swan-javadoc-exporter**: Doclet exports doc comments to XML files so that they can be analyzed by the Natural Language Processing (NLP) module
15-
* **doc-coverage-doclet**: Doclet calculates the software documentation coverage of Java programs based on the presence of doc comments for classes, methods, and other objects.
9+
The project is divided into two main components: the command line tool [<code>**swan-cmd**</code>](https://github.com/secure-software-engineering/swan/tree/master/swan-cmd) and the IntelliJ plugin [<code>**dev-assist**</code>](https://github.com/secure-software-engineering/swan/tree/master/dev-assist) that provides a GUI for SWAN.
10+
11+
1. <code>**swan-cmd**</code> is the command line implementation for SWAN with components for data collection, feature engineering, model selection and SRM prediction. The command line tool uses the following Maven modules:
12+
- <code>**training-data-jars**</code> contains dependencies from which the training examples are extracted.
13+
- Java Doclets to process and export software documentation
14+
- <code>**coverage-doclet**</code> calculates the software documentation coverage of Java programs based on the presence of doc comments for classes, methods, and other objects.
15+
- <code>**xml-doclet**</code> exports doc comments to XML files so that they can be analyzed by the Natural Language Processing (NLP) module
16+
2. <code>**dev-assist**</code> provides GUI support for SWAN and enables active machine learning.
17+
1618

1719
How do I get started with SWAN?
1820
-------------
19-
The easiest way to get started with SWAN is to use the pre-built binary from the newest release. To run SWAN, we provide a path to the Java project to be analyzed (JAR files or compiled classes) as well an output directory where SWAN will export its results.
20-
21-
After downloading the necessary files from the most recent release, SWAN can be executed on the command line with the following command:
21+
To run SWAN, you will need to provide a path to the Java project to be analyzed (JAR files or compiled classes) as well an output directory where SWAN will export its results. The easiest way to get started with SWAN is to use the pre-built binary from the newest release. After downloading the necessary files from the most recent release, SWAN can be executed on the command line with the following command:
2222

23-
<code>java -jar swan-&lt;swan-version&gt;.jar-test <project-path> -output <output-directory></code>
23+
<code>**java -jar swan-cmd-3.x.x.jar -test** */path/to/project/files* **-o** */output/directory* </code>
2424

25-
This command runs the application and exports the detected security-relevant methods to a JSON file in the provided output directory. The available command line options can be found in the Wiki or by using the <code>-help</code> command line option.
25+
This command runs the application and exports the detected security-relevant methods to a JSON file in the provided output directory. This command uses the following default settings: training dataset <code>-in [dataset](/swan-cmd/src/main/resources/dataset)</code>, code features <code>-f code</code>, and the MEKA toolkit <code>-t meka</code>. The remaining default options are found in [CLIRunner](/swan-cmd/src/main/java/de/fraunhofer/iem/swan/cli/CliRunner.java). The available command line options can be found in the Wiki or by using the <code>-help</code> command line option.
2626

2727
How do I build SWAN?
2828
-------------
29-
If you downloaded SWAN as a compressed release (e.g. .zip or .tar.gz), you can use <code>mvn package</code> to package the project. The commands provided above can then be used to run the generated JAR file. Alternatively, you can import the project directly into your IDE from the repository and package the project via the terminal or the Maven plugin in your IDE.
29+
If you cloned the project or downloaded SWAN as a compressed release (e.g. .zip or .tar.gz), you can use <code>mvn package</code> to package the project. The commands provided above can then be used to run the generated JAR file. Alternatively, you can import the project directly into your IDE from the repository and package the project via the terminal or the Maven plugin in your IDE.
3030

3131

3232
Contributors
3333
-------------
34-
The following persons have contributed to SWAN: Goran Piskachev ([email protected].de), Lisa Nguyen ([email protected]), Oshando Johnson ([email protected]), Eric Bodden ([email protected])
34+
The following persons have contributed to SWAN: Goran Piskachev (gpiskach@amazon.de), Lisa Nguyen ([email protected]), Oshando Johnson (oshando.johnson@iem.fraunhofer.de), Eric Bodden ([email protected]).
3535

doc-coverage-doclet/pom.xml renamed to coverage-doclet/pom.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>de.fraunhofer.iem</groupId>
7+
<parent>
8+
<groupId>de.fraunhofer.iem</groupId>
9+
<artifactId>swan</artifactId>
10+
<version>3.3.1</version>
11+
</parent>
12+
813
<artifactId>coverage-doclet</artifactId>
9-
<version>1.1</version>
1014

1115
<properties>
1216
<maven.compiler.source>11</maven.compiler.source>

dev-assist/README.md

Lines changed: 30 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,32 @@
1-
# dev-assist
2-
IntelliJ IDEA Plug-in for the Security methods for WeAkNess detection (SWAN) tool.
3-
4-
Description:
5-
-------------
6-
SWAN_Assist provides a GUI support for SWAN. The user is able to interact with the learning process by giving feedback on the methods of interest.
7-
The tool helps users that write static analyses to create list of SWAN for their specific Java libraries.
8-
Moreover, users can manually inspect the proper usage of the methods detected by SWAN.
9-
10-
11-
## Downloading the Project
12-
13-
The project can be downloaded using either of the following methods:
14-
15-
##### Method 1: Cloning the Project
16-
1) Select the **File>Project from Version Control>Git** option, enter the repository’s URL and then select **Clone** to import the project. The project will contain the following directories: ``swan_core`` (SWAN core application), ``swan_assist`` (IntelliJ Plugin) and ``swan_datasets`` (datasets for the research paper).
17-
2) To configure the project settings and modules, go to **File>Project Structure**.
18-
3) For **Project SDK**, select the corresponding Java SDK version.
19-
4) Select **Modules** from the left panel and remove the existing module that was automatically created.
20-
5) Click the **Add** button and then **Import Module** to create the SWAN Core module. Follow the steps in the [Setting up the Project Modules](https://github.com/secure-software-engineering/swan/tree/master/swan_assist#setting-up-the-project-modules) section to finish configuring the core module as well as the plugin module.
21-
22-
23-
##### Method 2: Downloading Project ZIP
24-
1) Download and extract the project resources from GitHub.
25-
2) In Intellij, use the **File>Project from Existing Resources** to import the project modules. This can also be done from the IntelliJ start screen.
26-
3) Follow the steps in the [Setting up the Project Modules](https://github.com/secure-software-engineering/swan/tree/master/swan_assist#setting-up-the-project-modules) section to finish configuring the core module as well as the plugin module.
27-
28-
## Setting up the Project Modules
29-
30-
##### SWAN Core
31-
1) In the window that appears, open the ``/swan_core`` directory of the project.
32-
2) Select the **Import module from external Model** radio button and also select **Maven**.
33-
3) The default settings in the dialogs that appear can be used.
34-
4) Close the **Project Settings** dialog so that IntelliJ will index the new project module.
35-
36-
##### SWAN Assist
37-
1) Return to the **Project Structure** dialog and Select **Modules** from the left panel.
38-
2) Click the **Add** button and then **Import Module**.
39-
3) In the window that appears, open the ``/swan_assist`` directory. Select the **Import module from external Model** radio button and also select **Gradle**.
40-
4) The default settings in the dialogs that appear can be used. The plugin module should now be indexed.
41-
42-
The core and plugin modules should now be imported.
43-
44-
## Running the Plugin
45-
46-
The plugin uses ``swan_core`` dependency from [Maven Central](https://mvnrepository.com/artifact/de.upb.cs.swt/swan_core). If the version in the plugin's ``build.gradle`` file is not available on Maven Central, perform the following steps:
47-
1) Run the Maven ``install`` command of the ``swan_core`` project from the console or using the Maven Plugin.
48-
2) Add ``mavenLocal()`` in the ``repositories`` section of the ``build.gradle`` file. The locally installed library can now be use by the plugin.
49-
50-
##### To run the plugin:
51-
52-
1) Select the **Run Configuration** drop down menu and select **Edit Configurations** or from the **Run** menu, select **Edit Configurations**.
53-
2) Click the **Add** button and select **Gradle**.
54-
3) Select the **swan_assist** Gradle module that was just created and enter ``:runIde`` as the value for **Tasks** - this task will run the plugin in a new instance of IntelliJ. The plugin can also be executed using the Gradle Plugin in IntelliJ: Open the Gradle Tool Window, expand the ``intellij`` task and double click on ``runIde``. The other tasks can be used as necessary.
55-
4) When the new instance of IntelliJ launches, use the open option to select the project found in ``/test-project`` directory. You may need to set a project SDK, if one isn’t automatically configured for the project.
56-
57-
Logs for the plugin will appear in the initial instance of IntelliJ.
58-
1+
## Dev-Assist IntelliJ Plugin
2+
3+
Dev-Assist is an IntelliJ IDEA plugin that uses [SWAN](https://github.com/secure-software-engineering/swan) to detect security-relevant methods (SRMs) that are required when configuring static analysis tools. After automatically detecting SRMs, the plugin can be used to adjust the list of security-relevant methods and also generate the tainit-flow specifications required to run the taint analysis tool [SecuCheck](https://github.com/secure-software-engineering/secucheck/).
4+
5+
The plugin works with IntelliJ IDEA 2022.2 and higher.
6+
7+
### Plugin Features
8+
The plugin has the following main features which are accessible in the plugin's tool window and from the editor:
9+
10+
- Detect security-relevant methods in Java programs with SWAN's machine learning approach
11+
- Update security-relevant methods list using method dialog
12+
- Import existing SRM list
13+
- Add new SRMs from the editor
14+
- Update existing method (SRM labels, data-in/data-out and meta properties)
15+
- Delete SRMs
16+
- Filter SRM list
17+
- Expand/collapse method list
18+
- Export updated SRM list
19+
- Generate [*fluent*TQL](https://github.com/secure-software-engineering/secucheck/tree/master) taint-flow specifications necessary to configure SecuCheck in order to detect vulnerabilities
20+
- Run SecuCheck and displays results using Qodana
21+
22+
### Installation
23+
24+
To install the plugin in IntelliJ IDEA:
25+
- Download the [latest](https://github.com/secure-software-engineering/swan/releases) plugin archive file (ZIP or JAR)
26+
- Open the IDE settings and select <kbd>Plugins</kbd>
27+
- On the <kbd>Plugins</kbd> page, click <kbd>Gear</kbd> icon and then click <kbd>Install plugin from disk...</kbd>.
28+
- Select the Dev-Assist plugin archive file and select <kbd>OK</kbd>
29+
- Click <kbd>OK</kbd> to apply the changes.
30+
- Restart the IDE to complete the installation
5931

6032

dev-assist/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ repositories {
1313

1414
dependencies {
1515
implementation 'com.googlecode.json-simple:json-simple:1.1'
16-
implementation 'de.fraunhofer.iem:swan:3.2.2'
16+
implementation 'de.fraunhofer.iem:swan:3.3.1'
17+
implementation 'de.fraunhofer.iem:swan-cmd:3.3.1'
1718
implementation 'org.slf4j:slf4j-api:1.7.29'
1819
implementation 'org.slf4j:slf4j-simple:1.7.29'
1920
implementation 'org.apache.commons:commons-lang3:3.0'
@@ -32,7 +33,7 @@ patchPluginXml {
3233
"<br>- filter list" +
3334
"<br>- import and export configuration file"
3435
sinceBuild = "221.*"
35-
untilBuild = "233.*"
36+
untilBuild = "242.*"
3637
}
3738

3839
runIde {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package de.fraunhofer.iem.devassist.actions;
2+
3+
import com.intellij.ide.util.PropertiesComponent;
4+
import com.intellij.openapi.actionSystem.AnAction;
5+
import com.intellij.openapi.actionSystem.AnActionEvent;
6+
import com.intellij.openapi.actionSystem.CommonDataKeys;
7+
import com.intellij.openapi.progress.PerformInBackgroundOption;
8+
import com.intellij.openapi.progress.ProgressManager;
9+
import com.intellij.openapi.project.Project;
10+
import de.fraunhofer.iem.devassist.analysis.SecucheckBackgroundTask;
11+
import de.fraunhofer.iem.devassist.comm.SecucheckNotifier;
12+
import de.fraunhofer.iem.devassist.util.Constants;
13+
import org.jetbrains.annotations.NotNull;
14+
15+
import java.io.File;
16+
import java.util.Objects;
17+
18+
public class RunSecucheckAction extends AnAction {
19+
20+
@Override
21+
public void actionPerformed(@NotNull AnActionEvent e) {
22+
final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
23+
24+
if (!PropertiesComponent.getInstance(project).isTrueValue(Constants.SWAN_SETTINGS)) {
25+
e.getActionManager().getAction("Dev_Assist.SettingsAction").actionPerformed(e);
26+
//TODO Run SWAN if the tool has been configured
27+
} else {
28+
runSecucheck(project);
29+
}
30+
}
31+
32+
public void runSecucheck(Project project) {
33+
34+
File outputFolder = new File(Objects.requireNonNull(PropertiesComponent.getInstance(project).getValue(Constants.OUTPUT_DIRECTORY)));
35+
36+
if (!outputFolder.exists())
37+
outputFolder.mkdir();
38+
39+
ProgressManager.getInstance().run(new SecucheckBackgroundTask(project, "Running Taint Analysis", true,
40+
PerformInBackgroundOption.ALWAYS_BACKGROUND));
41+
42+
SecucheckNotifier publisher = project.getMessageBus().syncPublisher(SecucheckNotifier.START_SECUCHECK_PROCESS_TOPIC);
43+
publisher.launchSecuCheck();
44+
}
45+
}

dev-assist/src/main/java/de/fraunhofer/iem/devassist/actions/RunSwanAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void actionPerformed(AnActionEvent anActionEvent) {
6464
}
6565

6666
if (!PropertiesComponent.getInstance(project).isTrueValue(Constants.SWAN_SETTINGS)) {
67-
anActionEvent.getActionManager().getAction("SWAN_Assist.SettingsAction").actionPerformed(anActionEvent);
67+
anActionEvent.getActionManager().getAction("Dev_Assist.SettingsAction").actionPerformed(anActionEvent);
6868
//TODO Run SWAN if the tool has been configured
6969
} else {
7070
runSwan(project);

dev-assist/src/main/java/de/fraunhofer/iem/devassist/actions/SettingsAction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public void actionPerformed(AnActionEvent anActionEvent) {
6464

6565
HashMap<String, String> settings = dialog.getParameters();
6666

67-
System.out.println("PPP: "+settings);
6867
for (String property : settings.keySet())
6968
PropertiesComponent.getInstance(project).setValue(property, settings.get(property));
7069
}

dev-assist/src/main/java/de/fraunhofer/iem/devassist/analysis/SecucheckBackgroundTask.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
package de.fraunhofer.iem.devassist.analysis;
22

3+
import com.intellij.ide.util.PropertiesComponent;
34
import com.intellij.openapi.progress.PerformInBackgroundOption;
45
import com.intellij.openapi.progress.ProgressIndicator;
56
import com.intellij.openapi.progress.Task;
67
import com.intellij.openapi.project.Project;
78
import com.intellij.openapi.util.NlsContexts;
89
import com.intellij.util.messages.MessageBus;
10+
import de.fraunhofer.iem.aidevassist.sa.cli.AIDevAssistCli;
11+
import de.fraunhofer.iem.aidevassist.sa.cli.CliRunner;
912
import de.fraunhofer.iem.devassist.comm.SecucheckNotifier;
13+
import de.fraunhofer.iem.devassist.util.Constants;
1014
import org.jetbrains.annotations.NotNull;
1115
import org.jetbrains.annotations.Nullable;
16+
import picocli.CommandLine;
1217

1318
import java.time.LocalDateTime;
1419
import java.time.format.DateTimeFormatter;
1520
import java.util.HashMap;
21+
import java.util.Objects;
1622
import java.util.concurrent.TimeUnit;
1723

1824
public class SecucheckBackgroundTask extends Task.Backgroundable {
@@ -31,24 +37,25 @@ public void run(@NotNull ProgressIndicator indicator) {
3137

3238
long start = System.currentTimeMillis();
3339

34-
//TODO add implementation to run SecuCheck
35-
indicator.setText("Generating fluentTQL Specifications");
36-
3740
indicator.setText("Configuring SecuCheck");
3841

39-
try {
40-
TimeUnit.SECONDS.sleep(2);
41-
} catch (InterruptedException e) {
42-
throw new RuntimeException(e);
43-
}
44-
indicator.setText("Configuring analysis");
42+
String[] args = new String[]{
43+
"--analysis", "0",
44+
Objects.requireNonNull(PropertiesComponent.getInstance(project).getValue(Constants.SOURCE_DIRECTORY)),
45+
"--output", Objects.requireNonNull(PropertiesComponent.getInstance(project).getValue(Constants.OUTPUT_DIRECTORY)),
46+
"--inclusion", "*",
47+
"--entry", "*"};
48+
49+
CliRunner cliRunner = new CliRunner(args);
50+
CommandLine.ParseResult cmd = new CommandLine(cliRunner).parseArgs(args);
51+
52+
indicator.setText("Running analysis");
4553

46-
try {
47-
TimeUnit.SECONDS.sleep(2);
48-
} catch (InterruptedException e) {
49-
throw new RuntimeException(e);
54+
if (cmd.errors().isEmpty()) {
55+
AIDevAssistCli cli = new AIDevAssistCli();
56+
cli.run(cliRunner.createOptions());
57+
PropertiesComponent.getInstance(project).setValue(Constants.LAST_SARIF_FILE, cli.getResults().getResultFile());
5058
}
51-
indicator.setText("Exporting analysis results");
5259

5360
MessageBus messageBus = project.getMessageBus();
5461
SecucheckNotifier publisher = messageBus.syncPublisher(SecucheckNotifier.END_SECUCHECK_PROCESS_TOPIC);

0 commit comments

Comments
 (0)