Skip to content
This repository was archived by the owner on Feb 26, 2021. It is now read-only.

Commit 8ef31b4

Browse files
committed
Merge branch 'develop' into feature/new-api-structure
2 parents 65423b2 + 9e29215 commit 8ef31b4

15 files changed

Lines changed: 427 additions & 11 deletions

File tree

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ COPY --from=builder ./scb-persistenceproviders/elasticsearch-persistenceprovider
2626

2727
WORKDIR /scb-engine
2828

29+
COPY dockerfiles/init.sh .
30+
RUN chmod +x ./init.sh
31+
2932
EXPOSE 8080
33+
EXPOSE 8443
3034

3135
LABEL org.opencontainers.image.title="secureCodeBox Engine" \
3236
org.opencontainers.image.description="Orchestrating various security scans." \
@@ -40,4 +44,4 @@ LABEL org.opencontainers.image.title="secureCodeBox Engine" \
4044
org.opencontainers.image.revision=$COMMIT_ID \
4145
org.opencontainers.image.created=$BUILD_DATE
4246

43-
ENTRYPOINT ["java", "-Dloader.path=./lib/,./plugins/", "-jar", "app.jar"]
47+
ENTRYPOINT ["./init.sh"]

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
![Build Status](https://travis-ci.com/secureCodeBox/engine.svg?token=N5PJUt4SAUxNTYFZNtLj&branch=develop)
2-
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
3-
[![Known Vulnerabilities](https://snyk.io/test/github/secureCodeBox/engine/badge.svg)](https://snyk.io/test/github/secureCodeBox/engine)
4-
[![GitHub release](https://img.shields.io/github/release/secureCodeBox/engine.svg)](https://github.com/secureCodeBox/engine/releases/latest)
1+
[![Build Status](https://travis-ci.com/secureCodeBox/engine.svg?branch=develop)](https://travis-ci.com/secureCodeBox/engine)
2+
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
3+
[![Known Vulnerabilities](https://snyk.io/test/github/secureCodeBox/engine/badge.svg)](https://snyk.io/test/github/secureCodeBox/engine)
4+
[![GitHub release](https://img.shields.io/github/release/secureCodeBox/engine.svg)](https://github.com/secureCodeBox/engine/releases/latest)
55

66
# SecureCodeBox Engine – the Core
77

@@ -26,6 +26,16 @@ To configure the SCB engine specify the following environment variables:
2626
| SECURECODEBOX_USER_SCANNER | Default user for scanner services | default-scanner |
2727
| SECURECODEBOX_USER_SCANNER_PW | Default password for scanner services | AStrongPassword-NotThisOne! |
2828

29+
## Server Configuration
30+
Additionally all properties defined in scb-engine/src/main/resources/application.yaml can be overwritten via environment variables.
31+
This allows you to e.g. enable https using:
32+
33+
| Environment Variable | Description | Example Value |
34+
| ------------------------------------- | ------------------------------------- | --------------------------- |
35+
| SERVER_PORT | Defines the server port | 8443 |
36+
| SERVER_SSL_ENABLED | Enables http over ssl | true |
37+
| SERVER_SSL_KEY_STORE_PASSWORD | Password to the java keystore | AStrongPassword-NotThisOne! |
38+
2939
# Development
3040

3141
## Local setup

dockerfiles/init.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
3+
cd /scb-engine
4+
5+
create_self_signed_certificate()
6+
{
7+
echo "Creating self signed certificate..."
8+
keytool -genkey -alias scb-engine -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore keystore.p12 -validity 3650 \
9+
-dname "CN=secureCodeBoxEngine, OU=secureCodeBox.io, O=secureCodeBox.io, C=DE, ST=HH, L=Hamburg" \
10+
-storepass "${SERVER_SSL_KEY_STORE_PASSWORD}"
11+
}
12+
13+
create_certificate_if_not_available()
14+
{
15+
echo "Check if keystore already exists"
16+
if [ ! -f ./keystore.p12 ]
17+
then
18+
echo "Keystore not found."
19+
create_self_signed_certificate
20+
else
21+
echo "Keystore already exists"
22+
fi
23+
}
24+
25+
echo "Execute init script:"
26+
echo "Check if HTTPS is enabled..."
27+
if [ "${SERVER_SSL_ENABLED}" == "true" ]
28+
then
29+
echo "Https enabled"
30+
create_certificate_if_not_available
31+
else
32+
echo "No HTTPS enabled. You can use environment variables to enable HTTPS."
33+
fi
34+
35+
echo "Starting secureCodeBox engine..."
36+
java -Dloader.path="./lib/,./plugins/" -jar ./app.jar

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@
160160
<version>${swagger-version}</version>
161161
</dependency>
162162

163-
164163
<dependency>
165164
<groupId>io.securecodebox.core</groupId>
166165
<artifactId>sdk</artifactId>

scb-engine/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@
156156
<version>1.0-SNAPSHOT</version>
157157
<scope>runtime</scope>
158158
</dependency>
159+
<dependency>
160+
<groupId>io.securecodebox.scanprocesses</groupId>
161+
<artifactId>combined-amass-nmap-process</artifactId>
162+
<version>0.0.1-SNAPSHOT</version>
163+
<scope>runtime</scope>
164+
</dependency>
159165
<dependency>
160166
<groupId>io.securecodebox.scanprocesses</groupId>
161167
<artifactId>combined-nmap-nikto-scanprocess</artifactId>

scb-engine/src/main/java/io/securecodebox/engine/helper/DefaultUserConfiguration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package io.securecodebox.engine.helper;
2121

22-
import org.camunda.bpm.engine.AuthorizationService;
2322
import org.camunda.bpm.engine.IdentityService;
2423
import org.camunda.bpm.engine.ProcessEngine;
2524
import org.camunda.bpm.engine.identity.User;

scb-engine/src/main/resources/application.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
# mvn spring-boot:run -Pdev
44
spring.profiles.active: ${activatedProfiles}
55

6+
# Server configuration
7+
# These properties can be overwritten by environment variables to enable https
8+
server.port: 8080
9+
server.ssl:
10+
enabled: false
11+
key-store-password:
12+
key-store: keystore.p12
13+
key-store-type: PKCS12
14+
key-alias: scb-engine
15+
616
camunda.bpm:
717
webapp.index-redirect-enabled: true
818
authorization.enabled: true
@@ -15,6 +25,10 @@ logging.level.io.securecodebox: INFO
1525
# - elasticsearch
1626
securecodebox.persistence.provider: none
1727

28+
# Configuration for the s3 persistence provider:
29+
securecodebox.persistence.s3.bucket: abc-def
30+
securecodebox.persistence.s3.region: eu-central-1
31+
1832
# Configuration for the elasticsearch persistence provider:
1933
securecodebox.persistence.elasticsearch.host: persistence-elasticsearch
2034
securecodebox.persistence.elasticsearch.port: 9200

scb-persistenceproviders/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<modules>
3636
<module>elasticsearch-persistenceprovider</module>
3737
<module>empty-persistenceprovider</module>
38+
<module>s3-persistenceprovider</module>
3839
</modules>
3940

4041
<dependencyManagement>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<!--
2+
~ /*
3+
~ * SecureCodeBox (SCB)
4+
~ * Copyright 2015-2018 iteratec GmbH
5+
~ *
6+
~ * Licensed under the Apache License, Version 2.0 (the "License");
7+
~ * you may not use this file except in compliance with the License.
8+
~ * You may obtain a copy of the License at
9+
~ *
10+
~ * http://www.apache.org/licenses/LICENSE-2.0
11+
~ *
12+
~ * Unless required by applicable law or agreed to in writing, software
13+
~ * distributed under the License is distributed on an "AS IS" BASIS,
14+
~ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ * See the License for the specific language governing permissions and
16+
~ * limitations under the License.
17+
~ */
18+
-->
19+
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
24+
<parent>
25+
<groupId>io.securecodebox.persistenceproviders</groupId>
26+
<artifactId>default-persistence-collection</artifactId>
27+
<version>0.0.1-SNAPSHOT</version>
28+
</parent>
29+
30+
<artifactId>s3-persistenceprovider</artifactId>
31+
<version>0.0.1-SNAPSHOT</version>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>io.securecodebox.core</groupId>
36+
<artifactId>sdk</artifactId>
37+
<scope>provided</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>com.amazonaws</groupId>
41+
<artifactId>aws-java-sdk-s3</artifactId>
42+
<version>1.11.424</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.mockito</groupId>
46+
<artifactId>mockito-core</artifactId>
47+
<scope>test</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>junit</groupId>
51+
<artifactId>junit</artifactId>
52+
<scope>test</scope>
53+
</dependency>
54+
<dependency>
55+
<groupId>commons-io</groupId>
56+
<artifactId>commons-io</artifactId>
57+
<version>RELEASE</version>
58+
</dependency>
59+
</dependencies>
60+
61+
<build>
62+
<plugins>
63+
<plugin>
64+
<artifactId>maven-assembly-plugin</artifactId>
65+
<version>3.1.0</version>
66+
<configuration>
67+
<descriptorRefs>
68+
<descriptorRef>jar-with-dependencies</descriptorRef>
69+
</descriptorRefs>
70+
</configuration>
71+
<executions>
72+
<execution>
73+
<id>make-assembly</id>
74+
<phase>package</phase>
75+
<goals>
76+
<goal>single</goal>
77+
</goals>
78+
</execution>
79+
</executions>
80+
</plugin>
81+
</plugins>
82+
</build>
83+
84+
</project>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
*
3+
* SecureCodeBox (SCB)
4+
* Copyright 2015-2018 iteratec GmbH
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
* /
18+
*/
19+
package io.securecodebox.persistence.s3;
20+
21+
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
22+
import com.amazonaws.services.s3.AmazonS3;
23+
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
24+
import com.amazonaws.services.s3.model.ObjectMetadata;
25+
import com.amazonaws.services.s3.model.PutObjectRequest;
26+
import com.fasterxml.jackson.databind.ObjectMapper;
27+
import io.securecodebox.model.Report;
28+
import io.securecodebox.persistence.PersistenceProvider;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
31+
import org.springframework.beans.factory.annotation.Autowired;
32+
import org.springframework.beans.factory.annotation.Value;
33+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
34+
import org.springframework.stereotype.Component;
35+
36+
import java.io.File;
37+
import java.io.IOException;
38+
import java.util.UUID;
39+
40+
@ConditionalOnProperty(name = "securecodebox.persistence.provider", havingValue = "s3")
41+
@Component
42+
public class S3PersistenceProvider implements PersistenceProvider {
43+
44+
private static final Logger LOG = LoggerFactory.getLogger(S3PersistenceProvider.class);
45+
46+
@Autowired
47+
private ObjectMapper mapper;
48+
49+
@Value("${securecodebox.persistence.s3.bucket}")
50+
private String bucketName;
51+
52+
@Value("${securecodebox.persistence.s3.region}")
53+
private String awsRegion;
54+
55+
@Override
56+
public void persist(Report report) {
57+
58+
if (report == null) {
59+
LOG.warn("Report is null, nothing to persist.");
60+
} else {
61+
// Upload a file as a new object with ContentType and title specified.
62+
63+
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
64+
.withRegion(awsRegion)
65+
.withCredentials(new ProfileCredentialsProvider())
66+
.build();
67+
File file = writeReportToFile(report);
68+
69+
String fileName = report.getExecution().getContext().replace('/', '-') + '/';
70+
fileName += UUID.randomUUID();
71+
PutObjectRequest request = new PutObjectRequest(bucketName, fileName, file);
72+
ObjectMetadata metadata = new ObjectMetadata();
73+
metadata.setContentType("application/json");
74+
request.setMetadata(metadata);
75+
s3Client.putObject(request);
76+
}
77+
}
78+
79+
File writeReportToFile(Report report) {
80+
File tempFile = null;
81+
try {
82+
tempFile = File.createTempFile(UUID.randomUUID().toString(), ".json");
83+
mapper.writeValue(tempFile, report);
84+
} catch (IOException exception) {
85+
LOG.error("Could not write tempfile: ", exception);
86+
}
87+
return tempFile;
88+
}
89+
}

0 commit comments

Comments
 (0)