Skip to content

Vulnerability Consumer #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 76 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
cecebce
Dummy Kafka Producer and Thread Updater
elanzini Apr 30, 2020
845c3c9
Utils Parsing Vulnerabilities
elanzini May 2, 2020
cf05ba3
Vulnerability Publisher Implementation
elanzini May 2, 2020
8517c11
Retrieval of vulnerable_files
elanzini May 3, 2020
8c04ba2
Switched to JSONObject instead of raw Strings
elanzini May 4, 2020
d7ff081
Dependency Injection refactoring for Testing
elanzini May 4, 2020
0d3de55
Thread Updater Functionality
elanzini May 5, 2020
25eb697
Commit Parser from Github API
elanzini May 11, 2020
43cdc87
Merge remote-tracking branch 'origin/master' into vulnerability-plugin
elanzini May 18, 2020
c3d0076
Refactoring Plugin to new Server Architecture
elanzini May 18, 2020
9382c51
Mongo Connector + Github API support
elanzini May 24, 2020
6aec304
Parser Test + License information
elanzini May 27, 2020
2080b65
Git PRs and Issues support
elanzini May 28, 2020
661a206
Integration Testing Plugin
elanzini Jun 2, 2020
fb206b0
Support to include https://arxiv.org/abs/1902.02595
elanzini Jun 10, 2020
5131aa1
Parsing for CPE mappers + GH API v4
elanzini Jun 25, 2020
15e2d3c
JSON Mapper GH v4
elanzini Jun 28, 2020
f6619a1
Refactor Parsers + Mappers
elanzini Jun 30, 2020
4c9c4da
ParserManager + Licenses files
elanzini Jun 30, 2020
015219c
Testing Parser Manager Merging
elanzini Jul 1, 2020
a6a25c7
Integration Testing YAML Parser
elanzini Jul 1, 2020
e02fc56
Switch to JUnit 5 + Inject Version Farmer
elanzini Jul 2, 2020
8783e89
Integration with Nitrite for resilience
elanzini Jul 2, 2020
102ff39
Serialization Objects + pom.xml to run jUnit 5
elanzini Jul 2, 2020
c28ecca
Documentation + purl-spec
elanzini Jul 3, 2020
abed1da
Merge remote-tracking branch 'origin/master' into vulnerability-plugin
elanzini Jul 3, 2020
c828ff3
Integration Testing Nitrite + Logger + Thread Safe tests
elanzini Jul 3, 2020
bf3f18f
Merge remote-tracking branch 'origin/master' into vulnerability-plugin
elanzini Aug 10, 2020
6e4e1bf
Update analyzer pom.xml
elanzini Aug 12, 2020
06f1832
Add MSR2020 CPP Dataset to sources of info
elanzini Aug 12, 2020
19287b5
Add readme template
ilyagrishkov Aug 12, 2020
14a05f3
OVALParser logic + VersionRanger for Debian
elanzini Aug 22, 2020
0c3add9
Switch to MR - JSON source for Debian versions
elanzini Aug 22, 2020
57e9f28
Unit testing OVAL Parser
elanzini Aug 23, 2020
8588bb3
Refactor Merger + OVAL Integration
elanzini Aug 23, 2020
428fd3b
PURL to Object conversion
elanzini Aug 27, 2020
c35a8f8
Helper functions to inject in the DB
elanzini Aug 30, 2020
0383af6
Injection callable + appending JSONB to metadata
elanzini Aug 31, 2020
3cb4454
Include option to pass JSON with data
elanzini Sep 1, 2020
2688dd2
Multiple modules fix + data + instructions demo
elanzini Sep 2, 2020
6842552
Merge remote-tracking branch 'origin/develop' into vulnerability-plugin
elanzini Sep 2, 2020
1a21ff3
Fix dependency issue of vulnerability analyzer when running its stand…
mir-am Sep 2, 2020
0e174ce
Update architecture info + demo info callables
elanzini Sep 4, 2020
75f25ca
SQL procedure + update data.json
elanzini Sep 5, 2020
060e0c2
Multiple callables handler + fasten_uri of callables
elanzini Sep 6, 2020
667cd75
Move injection logic to core
elanzini Sep 8, 2020
64c2303
Revert logic to plugin for maintainability
elanzini Sep 9, 2020
abfa757
Refactor Vulnerability + Patch classes
elanzini Sep 9, 2020
aec4794
Procedure checks for internal calls + pkg metadata
elanzini Sep 9, 2020
9430f16
Include injection in the pipeline
elanzini Sep 10, 2020
d4bd010
Merge remote-tracking branch 'origin/develop' into vulnerability-plugin
elanzini Sep 10, 2020
d1c61fc
Integration with server
elanzini Sep 10, 2020
f9b6bca
Separate Producer and Consumer
elanzini Sep 16, 2020
a701101
Merge remote-tracking branch 'origin/develop' into vulnerability-plugin
elanzini Sep 17, 2020
b2bac61
Updating README + additional logger info
elanzini Sep 17, 2020
74b3ddb
Improvement Patch Farmer
elanzini Sep 18, 2020
c7c657f
Moved vulnerability-producer to a separate repo
elanzini Sep 29, 2020
b01d760
Fix dependencies vulnerability-consumer
elanzini Sep 29, 2020
55620a3
Merge remote-tracking branch 'origin/develop' into vulnerability-plugin
elanzini Nov 27, 2020
0734939
update logic to handle multiple DBs
elanzini Nov 27, 2020
27a97fc
refactor to optimize JOOQ + switch to Jackson
elanzini Nov 30, 2020
0f02504
injection with JOOQ + serialization with fasten_uris
elanzini Dec 1, 2020
924a2b9
integration testing + jooq fasten_uri
elanzini Dec 2, 2020
dbd9bbe
Merge branch 'develop' into vulnerability-plugin
elanzini Dec 2, 2020
ed6ab65
filtering modules on pkg_id + add patch_date field
elanzini Dec 4, 2020
28ceec7
check first patched version + handle different base PURLs
elanzini Dec 7, 2020
e9fefca
save vulnerability to system + produce
elanzini Dec 7, 2020
a8ebc18
include purge option + write data to output_path
elanzini Dec 8, 2020
f01268d
change logic to always publish
elanzini Dec 9, 2020
03ef95b
Merge remote-tracking branch 'origin/develop' into vulnerability-plugin
elanzini Dec 9, 2020
a9d746c
write full_fasten_uri in the vuln
elanzini Dec 9, 2020
ba95ed0
remove unused class
elanzini Dec 9, 2020
398851d
clean outdated producer dockerfile
elanzini Dec 10, 2020
bd33561
support different coordinateSeparators
elanzini Dec 10, 2020
7189301
Merge remote-tracking branch 'origin/develop' into vulnerability-plugin
elanzini Dec 10, 2020
fc03b48
use PostgresConnector from core
elanzini Dec 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions analyzer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<module>repo-cloner-plugin</module>
<module>quality-analyzer</module>
<module>restapi-plugin</module>
<module>vulnerability-consumer</module>
</modules>

<build>
Expand Down Expand Up @@ -59,5 +60,20 @@
</plugin>
</plugins>
</build>
<!-- Jacoco reporting -->
<reporting>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<configuration>
<excludes>
<exclude>**/Main.*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</reporting>

</project>
39 changes: 39 additions & 0 deletions analyzer/vulnerability-consumer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<p align="center">
<img src="https://user-images.githubusercontent.com/45048351/90056609-d2c67900-dce7-11ea-9f66-3717998d861d.jpg">
</p>
<br/>
<p align="center">
<a href="https://github.com/fasten-project/fasten/actions" alt="GitHub Workflow Status">
<img src="https://img.shields.io/github/workflow/status/fasten-project/fasten/Java%20CI?logo=GitHub%20Actions&logoColor=white&style=for-the-badge" /></a>
<!-- Here should be a link to Maven repo and version should be pulled from there. -->
<a href="https://github.com/fasten-project/fasten/" alt="GitHub Workflow Status">
<img src="https://img.shields.io/maven-central/v/fasten/vulnerability?label=version&logo=Apache%20Maven&style=for-the-badge" /></a>
</p>
<br/>


The FASTEN Vulnerability Consumer is used for inserting Vulnerability Information into the [Metadata Database](https://github.com/fasten-project/fasten/wiki/Metadata-Database-Schema). It can be used both as a standalone tool and as a part of FASTEN server.

## Arguments
- `-h` `--help` Show this help message and exit.
- `-d` `--database` Database URL for connection
- `-u` `--user` Database user name

## Usage

#### Injecting vulnerability information into the KB
```shell script
FASTEN_DBPASS=pass -d jdbc:postgresql:postgres -u postgres
```

## Join the community

The FASTEN software package management efficiency relies on an open community contributing to open technologies. Related research projects, R&D engineers, early users and open source contributors are welcome to join the [FASTEN community](https://www.fasten-project.eu/view/Main/Community), to try the tools, to participate in physical and remote worshops and to share our efforts using the project [community page](https://www.fasten-project.eu/view/Main/Community) and the social media buttons below.
<p>
<a href="http://www.twitter.com/FastenProject" alt="Fasten Twitter">
<img src="https://img.shields.io/badge/%20-Twitter-%231DA1F2?logo=Twitter&style=for-the-badge&logoColor=white" /></a>
<a href="http://www.slideshare.net/FastenProject" alt="GitHub Workflow Status">
<img src="https://img.shields.io/badge/%20-SlideShare-%230077B5?logo=slideshare&style=for-the-badge&logoColor=white" /></a>
<a href="http://www.linkedin.com/groups?gid=12172959" alt="Gitter">
<img src="https://img.shields.io/badge/%20-LinkedIn-%232867B2?logo=linkedin&style=for-the-badge&logoColor=white" /></a>
</p>
137 changes: 137 additions & 0 deletions analyzer/vulnerability-consumer/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<parent>
<artifactId>analyzer</artifactId>
<groupId>eu.fasten</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>vulnerability-consumer</artifactId>

<!-- Dependencies-->
<dependencies>
<dependency>
<groupId>eu.fasten</groupId>
<artifactId>server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>eu.fasten</groupId>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.0.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.0</version>
</dependency>
</dependencies>

<!-- Build-->
<build>
<testSourceDirectory>${project.basedir}/src/test/java/</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>false</minimizeJar>
<keepDependenciesWithProvidedScope>false</keepDependenciesWithProvidedScope>
<artifactSet>
<excludes>
<exclude>org.slf4j:slf4j-simple:*</exclude>
<exclude>org.slf4j:slf4j-api:*</exclude>
</excludes>
</artifactSet>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>eu.fasten.analyzer.vulnerabilityconsumer.Main</Main-Class>
<X-Compile-Source-JDK>11</X-Compile-Source-JDK>
<X-Compile-Target-JDK>11</X-Compile-Target-JDK>
<Plugin-Class>eu.fasten.analyzer.vulnerabilityconsumer.VulnerabilityConsumer</Plugin-Class>
<Plugin-Id>vulnerability-consumer</Plugin-Id>
<Plugin-Version>0.0.1</Plugin-Version>
<Plugin-Description>
Injects vulnerability information in the DB.
</Plugin-Description>
<Plugin-License>Apache License 2.0</Plugin-License>
</manifestEntries>
</transformer>
</transformers>
<!-- Note that this works when maven is ran in the root directory of the project -->
<outputDirectory>${session.executionRootDirectory}/docker/plugins/</outputDirectory>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>with-dependencies</shadedClassifierName>
</configuration>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>module-info.class</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>eu/fasten/core/plugins/*</exclude>
</excludes>
</filter>
<filter>
<artifact>org.apache.kafka:*</artifact>
<excludes>
<exclude>org/apache/kafka/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<annotationProcessors>
<annotationProcessor>org.pf4j.processor.ExtensionAnnotationProcessor</annotationProcessor>
</annotationProcessors>
<source>1.11</source>
<target>1.11</target>
</configuration>
</plugin>
</plugins>
</build>

<!-- Reporting-->
<reporting>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<configuration>
<excludes>
</excludes>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package eu.fasten.analyzer.vulnerabilityconsumer;

import eu.fasten.core.data.Constants;
import eu.fasten.core.dbconnectors.PostgresConnector;
import org.jooq.DSLContext;
import org.json.JSONArray;
import org.json.JSONTokener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.sql.SQLException;
import java.util.HashMap;

@CommandLine.Command(name = "Vulnerability Consumer")
public class Main implements Runnable {

private static final Logger logger = LoggerFactory.getLogger(Main.class);

@CommandLine.Option(names = {"-f", "--file"},
paramLabel = "JSON_FILE",
description = "Path to JSON file which contains the vulnerability")
String jsonFile;

@CommandLine.Option(names = {"-mdb", "--mvn_database"},
paramLabel = "MVN_DB_URL",
description = "Database URL for connection to mvn DB",
defaultValue = "jdbc:postgresql:fasten_java")
String mvnDbUrl;

@CommandLine.Option(names = {"-pdb", "--pypi_database"},
paramLabel = "PYPI_DB_URL",
description = "Database URL for connection to pypi DB",
defaultValue = "jdbc:postgresql:fasten_pypi")
String pypiDbUrl;

@CommandLine.Option(names = {"-cdb", "--debian_database"},
paramLabel = "DEB_DB_URL",
description = "Database URL for connection to debian KB",
defaultValue = "jdbc:postgresql:fasten_c")
String debianDbUrl;

@CommandLine.Option(names = {"-u", "--user"},
paramLabel = "DB_USER",
description = "Database user name",
defaultValue = "postgres")
String dbUser;

@CommandLine.Option(names = {"-p", "--path_folder"},
paramLabel = "PATH_FOLDER",
description = "Path to folder to store vulnearabilities",
defaultValue = "/root/mnt/vulnerabilities/")
String pathToFolder;

@CommandLine.Option(names = {"-P", "--PURGE"},
paramLabel = "PURGE_OPTION",
description = "If set to true, all DBS will be purged from all vulnerability entries.")
boolean purge;

public static void main(String[] args) {
final int exitCode = new CommandLine(new Main()).execute(args);
System.exit(exitCode);
}

@Override
public void run() {
var vulnerabilityConsumer = new VulnerabilityConsumer.VulnerabilityConsumerExtension();
try {
var mvnContext = PostgresConnector.getDSLContext(mvnDbUrl, dbUser);
var pypiContext = PostgresConnector.getDSLContext(pypiDbUrl, dbUser);
var debianContext = PostgresConnector.getDSLContext(debianDbUrl, dbUser);

var contexts = new HashMap<String, DSLContext>();
contexts.put(Constants.debianForge, debianContext);
contexts.put(Constants.mvnForge, mvnContext);
contexts.put(Constants.pypiForge, pypiContext);

vulnerabilityConsumer.setDBConnection(contexts);

if (purge) {
vulnerabilityConsumer.purgeVulnerabilitiesFromDB();
return;
}
} catch (IllegalArgumentException | SQLException e) {
logger.error("Could not connect to the database", e);
return;
}
final FileReader reader;
try {
reader = new FileReader(jsonFile);
} catch (FileNotFoundException e) {
logger.error("Could not find the JSON file at " + jsonFile, e);
return;
}
final JSONArray vulnsJson = new JSONArray(new JSONTokener(reader));
vulnsJson.forEach(v -> vulnerabilityConsumer.consume(v.toString()));
vulnerabilityConsumer.produce().ifPresent(System.out::println);
}
}
Loading