Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot] 3cadd5a300
Bump junit from 4.11 to 4.13.1 in /mirror
5 years ago

5
.gitignore vendored

@ -1,5 +0,0 @@
*.iml
**/.idea/
**/target/
**/config.properties
*.env

@ -1 +0,0 @@
java temurin-17.0.9+9

@ -9,16 +9,6 @@ The `Ride` object is then sent back to `reverse`.
Upon recieving a reply with data from `app`, `reverse` will forward this data to `forward`,
which in turn will finally forward it to the `user`.
#### Control
##### Routing / Access Control
* currently, there is a 1:1 mapping between `forward` and `reverse`.
* thus any `Ride` "submitted" to `forward` will
naturally be selected, and circle back to `reverse`.
* thus `forward` and `Ride` can both be stateless.
* if any access control, name resolution, port forwarding were to happen,
it would be done in `reverse`.
<br>
### Overview
@ -29,6 +19,13 @@ which in turn will finally forward it to the `user`.
#### What does not work:
* Handling 301 (Moved Permanently).
* Forwarding PUT requests - if needed, the logic might be quickly added to `doPut` in `forward`.
* The `forward.war` has issues - meanwhile run `forward` embedded with Jetty.
<br>
### Demo
[![IMAGE ALT TEXT](http://img.youtube.com/vi/WcSvzeu6nKo/0.jpg)](https://youtu.be/WcSvzeu6nKo "misp Demo")
<br>
@ -44,24 +41,3 @@ which in turn will finally forward it to the `user`.
* Build (e.g. with `build-install-all.sh`)
* Put the generated `forward-0.1.war` in a servlet container (e.g. Jetty).
* Launch the `reverse-0.1.jar` on your host.
### Security Considerations
* user might access other resources (i.e. another app)
* user might manipulate the `app` URL
* the URL of the app is provided as ENV
* `reverse` calls said URL.
* the URL is never transmitted over the network
* the `Ride` object which `forward` receives contains only the _original_ request and the response payload from `app`
* user might use redirect magic
* user can not manipulate URL directly
* but if the server is not properly configured, the user might exploit that
* thus only expose local servers that you consider hardened.
* TODO possibly do some Header editing, before calling `app` URL in `Tools.send()`
### Considerations How to add multiple host mapping
* keep `forward` agnostic
* supply parameter to `/` indicating desired target service
* in `reverse`
* maintain a map of desired service -> URL

@ -1,19 +0,0 @@
#!/bin/bash
cd ./helper &&
mvn clean install &&
cd ../mirror &&
./build.sh &&
cd ../reverse &&
./build.sh &&
cd ../forward &&
./build.sh &

@ -0,0 +1,13 @@
#!/bin/bash
cd ./forward
./install-locally.sh
cd ..
cd ./helper
./install-locally.sh
cd ..
cd ./mirror
./install-locally.sh
cd ..
cd ./reverse
./install-locally.sh
cd ..

@ -1,31 +0,0 @@
version: '3'
services:
# forward:
# container_name: forward
# image: io42630/forward:0.1
# ports:
# - "42001:8080"
# - "42002:5005"
# See .env for vars.
reverse:
container_name: reverse
image: io42630/reverse:0.1
ports:
- "42005:8090"
- "42006:5005"
environment:
- forward.url=${FORWARD_URL}
- app.url=${APP_URL}
- check.supply.interval.ms=${CHECK_SUPPLY_INTERVAL_MS}
mirror:
container_name: mirror
image: io42630/mirror:0.1
ports:
- "42003:8080"
- "42004:5005"

@ -1,3 +0,0 @@
#!/bin/bash
docker compose down &

@ -1,3 +0,0 @@
#!/bin/bash
docker compose up --force-recreate &

@ -0,0 +1,5 @@
#### About
* Uses `com.olexyn.min.http.server.MinJettyServer` to host the servlets.
* Where to adjust the parameters:
* for `forward` -> `EmbeddedR`
* for `reverse` -> `RunAll`

@ -0,0 +1,208 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.olexyn.misp.embedded</groupId>
<artifactId>embedded</artifactId>
<version>0.1</version>
<name>embedded</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.11</maven.compiler.source>
<maven.compiler.target>1.11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.olexyn.min.http.server</groupId>
<artifactId>min-http-server</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.helper</groupId>
<artifactId>misp-helper</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-servlet</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-api</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all</artifactId>
<version>9.4.28.v20200408</version>
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.mirror</groupId>
<artifactId>misp-mirror</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.rev</groupId>
<artifactId>misp-rev</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.reverse</groupId>
<artifactId>reverse</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.fwd</groupId>
<artifactId>misp-fwd</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.forward</groupId>
<artifactId>forward</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.mirror</groupId>
<artifactId>mirror</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

@ -0,0 +1,28 @@
package com.olexyn.misp.embedded;
import com.olexyn.min.http.server.MinJettyServer;
import com.olexyn.misp.forward.Forward;
import com.olexyn.misp.mirror.Mirror;
public class EmbeddedR implements Runnable {
@Override
public void run() {
MinJettyServer server = new MinJettyServer();
server.PORT = 8090;
server.MAX_THREADS = 100;
server.MIN_THREADS = 10;
server.IDLE_TIMEOUT = 120;
server.addServletWithMapping("/mirror", Mirror.class);
server.addServletWithMapping("/app", Mirror.class);
server.addServletWithMapping("/forward", Forward.class);
server.start();
}
}

@ -0,0 +1,23 @@
package com.olexyn.misp.embedded;
import com.olexyn.misp.reverse.Reverse;
public class RunAll {
public static void main(String... args) throws InterruptedException {
Thread embeddedT = new Thread(new EmbeddedR());
embeddedT.start();
Thread.sleep(2000);
Reverse reverse = new Reverse();
reverse.FORWARD_URL = "http://localhost:8090/forward";
reverse.APP_URL = "http://localhost:8090/app";
//reverse.APP_URL = "https://olexyn.com/wp/";
Thread reverseT = new Thread(reverse);
reverseT.start();
}
}

@ -1,4 +0,0 @@
FROM eclipse-temurin:17-alpine
COPY /target/forward-0.1.jar /usr/local/lib/forward.jar
EXPOSE 8080 5005
ENTRYPOINT ["java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", "-jar","/usr/local/lib/forward.jar"]

@ -0,0 +1,9 @@
#### About
The `forward` servlet.
#### Deploy (TODO)
* Run `install-locally.sh`
* Find the `forward-0.1.war` in `./target`
* Copy it to `tomcat/webapps`.
* Assuming tomcat runs at `http://localhost:9090`
* Then the servlet will be at `http://localhost:9090/forward-0.1/mirror`

@ -1,9 +0,0 @@
#!/bin/bash
mvn clean install &&
docker build -t io42630/forward:0.1 .

@ -0,0 +1,10 @@
#!/bin/bash
version="0.1"
file="target/forward-${version}.war"
groupId="com.olexyn.misp.forward"
artifactId="forward"
mvn package
mvn install:install-file -Dfile=${file} -DgroupId=${groupId} -DartifactId=${artifactId} -Dversion=${version} -Dpackaging=war -DgeneratePom=true

@ -1,59 +1,124 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.olexyn</groupId>
<artifactId>zeeroot</artifactId>
<version>spring-boot-jdk17-0.1</version>
</parent>
<groupId>com.olexyn.misp</groupId>
<artifactId>forward</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<name>forward</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.olexyn</groupId>
<artifactId>zeebom</artifactId>
<version>1.1.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.olexyn.misp</groupId>
<artifactId>helper</artifactId>
<version>0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<!-- for some godforsaken reason this is required. -->
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
</dependencies>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.olexyn.misp.forward</groupId>
<artifactId>forward</artifactId>
<version>0.1</version>
<packaging>war</packaging>
<name>forward Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.helper</groupId>
<artifactId>helper</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>javax.servlet</artifactId>
<version>3.0.0.v201112011016</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>com.olexyn.min.http.server</groupId>
<artifactId>min-http-server</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

@ -1,13 +0,0 @@
package com.olexyn.misp.forward;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class App {
public static void main(String... args) {
SpringApplication.run(App.class, args);
}
}

@ -1,14 +1,12 @@
package com.olexyn.misp.forward.web;
package com.olexyn.misp.forward;
import com.olexyn.misp.helper.JsonHelper;
import com.olexyn.misp.helper.Ride;
import org.apache.commons.io.IOUtils;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@ -16,10 +14,7 @@ import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import static com.olexyn.misp.helper.Constants.AVAILABLE;
@RestController
public class Forward {
public class Forward extends HttpServlet {
private static final long WAIT_FOR_USER_REQUEST = 500;
@ -28,10 +23,10 @@ public class Forward {
private final Map<Long, Ride> loaded = new HashMap<>();
@GetMapping("/")
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
Thread handleGetRequestThread = new Thread(() -> handleGetRequest(request, response));
Thread handleGetRequestThread = new Thread(() -> { handleGetRequest(request, response); });
handleGetRequestThread.setName("handleGetRequestThread");
handleGetRequestThread.start();
try {handleGetRequestThread.join(); } catch (InterruptedException ignored) { }
@ -45,7 +40,7 @@ public class Forward {
* Wait for Ride to appear in `loaded`. This happens due to POST (Ride)(Request)(Data) from `reverse`.
* Finally send OK (Data) to `user`.
*/
private void handleGetRequest(HttpServletRequest request, HttpServletResponse response) {
protected void handleGetRequest(HttpServletRequest request, HttpServletResponse response) {
try {
final Ride ride;
@ -61,8 +56,8 @@ public class Forward {
}
// ride exists only locally, thus safe
ride = available.entrySet().iterator().next().getValue();
// ride exists only in AVAILABLE, access through which is sync, thus safe
available.remove(ride.getId());
// ride exists only in "available", access through which is sync, thus safe
available.remove(ride.getID());
// needed because POST (Ride) wait()s
available.notify();
}
@ -70,7 +65,7 @@ public class Forward {
synchronized (booked) {
// ride exists only locally, thus safe
booked.put(ride.getId(), ride);
booked.put(ride.getID(), ride);
// ride exists only in "booked", access through which is sync, thus safe
ride.setRequest(parsedRequest);
// POST (Ride) wait()s
@ -80,7 +75,7 @@ public class Forward {
synchronized (loaded) {
while (!loaded.containsKey(ride.getId())) {
while (!loaded.containsKey(ride.getID())) {
loaded.notify();
if (loaded.size() > 0) { break; }
@ -91,7 +86,7 @@ public class Forward {
// what if ride exists in another map, e.g. "available'
// in that case illegal access is possible
// be carefull to removing ride from all other references, when adding it to "loaded".
ride.setData(loaded.remove(ride.getId()).getData());
ride.setData(loaded.remove(ride.getID()).getData());
}
response.setStatus(200);
@ -104,7 +99,7 @@ public class Forward {
}
@PostMapping("/")
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
String payload = IOUtils.toString(request.getReader());
@ -113,7 +108,7 @@ public class Forward {
JSONObject obj = new JSONObject(payload);
if (obj.has(AVAILABLE)) {
if (obj.has("available")) {
Thread handlePostAvailableT = new Thread(() -> { handlePostAvailable(request, response); });
handlePostAvailableT.setName("handlePostAvailableT");
handlePostAvailableT.start();
@ -131,7 +126,7 @@ public class Forward {
}
if (obj.has("id") && hasData) {
Thread handlePostRideRequestDataT = new Thread(() -> { handlePostRideRequestData(payload); });
Thread handlePostRideRequestDataT = new Thread(() -> { handlePostRideRequestData(request, response, payload); });
handlePostRideRequestDataT.setName("handlePostRideRequestDataT");
handlePostRideRequestDataT.start();
try {handlePostRideRequestDataT.join(); } catch (InterruptedException ignored) { }
@ -143,16 +138,16 @@ public class Forward {
* Handle POST (Ride)(Request)(Data)
* Move the Ride from `booked` to `loaded`, so it can be picked up by OK (Data) of GET (Request).
*/
private void handlePostRideRequestData(String payload) {
protected void handlePostRideRequestData(HttpServletRequest request, HttpServletResponse response, String payload) {
final Ride ride = new Ride(payload);
synchronized (booked) {
booked.remove(ride.getId());
booked.remove(ride.getID());
}
synchronized (loaded) {
loaded.put(ride.getId(), ride);
loaded.put(ride.getID(), ride);
loaded.notify();
}
}
@ -162,17 +157,17 @@ public class Forward {
* Handle POST (Available).
* Send current # of available Rides to `reverse`.
*/
private void handlePostAvailable(HttpServletRequest req, HttpServletResponse res) {
protected void handlePostAvailable(HttpServletRequest request, HttpServletResponse response) {
JSONObject obj = new JSONObject().put(AVAILABLE, available.size());
JSONObject obj = new JSONObject().put("available", available.size());
res.setStatus(200);
response.setStatus(200);
try {
PrintWriter writer = res.getWriter();
PrintWriter writer = response.getWriter();
writer.write(obj.toString());
writer.flush();
writer.close();
} catch (Exception ignored) { /* ignored */ }
} catch (Exception ignored) {}
}
@ -182,24 +177,24 @@ public class Forward {
* Wait till a GET (Request) arrives from `user`.
* Return OK (Ride)(Request) to `reverse`.
*/
private void handlePostRide(HttpServletRequest request, HttpServletResponse response, String payload) {
protected void handlePostRide(HttpServletRequest request, HttpServletResponse response, String payload) {
try {
final Ride ride = new Ride(payload);
synchronized (available) {
available.put(ride.getId(), ride);
available.put(ride.getID(), ride);
available.notify();
}
// ID is final/threadsafe
while (!(booked.containsKey(ride.getId()))) {
while (!(booked.containsKey(ride.getID()))) {
Thread.sleep(WAIT_FOR_USER_REQUEST);
}
synchronized (booked) {
// ride = booked.get(ride.getId());
ride.setRequest(booked.get(ride.getId()).getRequest());
// ride = booked.get(ride.getID());
ride.setRequest(booked.get(ride.getID()).getRequest());
}
response.setStatus(200);
@ -208,6 +203,6 @@ public class Forward {
writer.flush();
writer.close();
} catch (Exception ignored) { /* ignored */ }
} catch (Exception ignored) {}
}
}

@ -0,0 +1,22 @@
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>misp-fwd</display-name>
<servlet>
<servlet-name>misp-fwd</servlet-name>
<servlet-class>com.olexyn.misp.forward.Forward</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>misp-fwd</servlet-name>
<url-pattern>/forward</url-pattern>
</servlet-mapping>
</web-app>

Binary file not shown.

After

Width:  |  Height:  |  Size: 617 B

@ -0,0 +1,20 @@
<html>
<head>
<title>misp-fwd</title>
</head>
<body bgcolor=white>
<table border="0">
<tr>
<td align=center>
<img src="images/io42630.png">
</td>
</tr>
<tr>
<td>
<h1>misp-fwd</h1>
</td>
</tr>
</table>
</body>
</html>

@ -1,7 +0,0 @@
#POST http://localhost:42001
GET http://node175251-env-1739619.sh1.hidora.com:11231/
Content-Type: application/json
{
"hello": "world"
}

@ -1,7 +0,0 @@
#POST http://localhost:42001
POST http://node175251-env-1739619.sh1.hidora.com:11231/
Content-Type: application/json
{
"hello": "world"
}

@ -1,6 +0,0 @@
### MISP Helper
#### Build
* do `mvn clean install` for local
* or `mvn deploy` for local nexus

@ -0,0 +1,10 @@
#!/bin/bash
version="0.1"
file="target/helper-${version}.jar"
groupId="com.olexyn.misp.helper"
artifactId="helper"
mvn package
mvn install:install-file -Dfile=${file} -DgroupId=${groupId} -DartifactId=${artifactId} -Dversion=${version} -Dpackaging=jar -DgeneratePom=true

@ -1,34 +1,84 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.olexyn</groupId>
<artifactId>zeeroot</artifactId>
<version>17.0.1</version>
</parent>
<groupId>com.olexyn.misp</groupId>
<artifactId>helper</artifactId>
<version>0.2</version>
<name>helper</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.olexyn</groupId>
<artifactId>zeebom</artifactId>
<version>1.1.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.olexyn.misp.helper</groupId>
<artifactId>helper</artifactId>
<version>0.1</version>
<name>helper</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
</plugin>
</plugins>
</reporting>
</project>

@ -1,9 +0,0 @@
package com.olexyn.misp.helper;
public interface Constants {
String AVAILABLE = "available";
String POST = "POST";
String GET = "GET";
String EMPTY = "";
}

@ -1,7 +1,5 @@
package com.olexyn.misp.helper;
import lombok.Getter;
import lombok.Setter;
import org.json.JSONException;
import org.json.JSONObject;
@ -10,28 +8,50 @@ public class Ride {
private static long count = 0L;
@Getter
private Long id;
@Getter
@Setter
final private Long id;
private String request;
@Getter
@Setter
private String data;
public Ride() { id = count++; }
public Ride() {
id = count++;
}
public Ride(String jsonString) { this(new JSONObject(jsonString)); }
public Ride(JSONObject obj) {
try { id = obj.getLong("id"); } catch (JSONException e) { id = count++; }
long _id;
try { _id = obj.getLong("id"); } catch (JSONException e) { _id = count++; }
id = _id;
try { request = obj.getString("request"); } catch (JSONException e) { request = null; }
try { data = obj.getString("data"); } catch (JSONException e) { data = null; }
}
public void setRequest(String request) {
this.request = request;
}
public void setData(String data) {
this.data = data;
}
public String getRequest() {
return this.request;
}
public String getData() {
return this.data;
}
public Long getID() {
return this.id;
}
public String json() {
JSONObject obj = new JSONObject();
obj.put("id", id);

@ -1,29 +0,0 @@
package com.olexyn.misp.helper;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
public class SymEnc {
public static void main(String[] args) throws Exception {
// Step 1: Generate a symmetric AES key (alternatively, you can specify your own)
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
keyGenerator.init(128); // Key size
SecretKey secretKey = keyGenerator.generateKey();
// Step 2: Create and initialize the Cipher for AES encryption
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
// Step 3: Encrypt the string
String inputString = "Your String Here";
byte[] encryptedBytes = cipher.doFinal(inputString.getBytes());
// Convert encrypted bytes to Base64 to get a string representation
String encryptedString = Base64.getEncoder().encodeToString(encryptedBytes);
System.out.println("Encrypted String: " + encryptedString);
}
}

@ -0,0 +1,26 @@
#!/bin/bash
tomcat_webapps="${HOME}/app/tomcat/webapps"
jetty_webapps="${HOME}/app/jetty9.4/webapps"
webapps=$jetty_webapps
cwd=$(pwd)
/home/user/app/tomcat/bin/shutdown.sh
echo "================"
echo "END TOMCAT STOP "
echo "================"
cp -v "${cwd}/misp-mirror/target/misp-mirror-0.1.war" "${webapps}"
cp -v "${cwd}/misp-rev/target/misp-rev-0.1.war" "${webapps}"
cp -v "${cwd}/test-proxy/target/test-proxy-0.1.war" "${webapps}"
echo "================"
echo "END COPY"
echo "================"
# /home/user/app/tomcat/bin/startup.sh
echo "================"
echo "END TOMCAT START "
echo "================"

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

@ -4,12 +4,49 @@
<element>
<id>UMLClass</id>
<coordinates>
<x>1420</x>
<y>610</y>
<x>910</x>
<y>50</y>
<w>90</w>
<h>30</h>
</coordinates>
<panel_attributes>inet
lt=-</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>680</x>
<y>50</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>webhost
lt=-
layer=-1</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>910</x>
<y>90</y>
<w>90</w>
<h>30</h>
</coordinates>
<panel_attributes>user
bg=#90CAF9</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>680</x>
<y>90</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>forward
<panel_attributes>mispbridge
bg=#B39DDB
layer=-1</panel_attributes>
<additional_attributes/>
@ -17,46 +54,85 @@ layer=-1</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>1170</x>
<y>680</y>
<w>280</w>
<x>410</x>
<y>140</y>
<w>300</w>
<h>50</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-
POST (Ride)
Generated by Loop</panel_attributes>
<additional_attributes>260.0;20.0;10.0;20.0</additional_attributes>
<additional_attributes>280.0;20.0;10.0;20.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>1170</x>
<y>830</y>
<w>280</w>
<x>760</x>
<y>180</y>
<w>200</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-
GET (Request)
fg=#1E88E5</panel_attributes>
<additional_attributes>10.0;20.0;180.0;20.0</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>350</x>
<y>90</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>mispclient
bg=#B39DDB
layer=-1</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>410</x>
<y>290</y>
<w>300</w>
<h>50</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-
POST (Ride)(Request)
GET (Ride)(Request)
(Data)</panel_attributes>
<additional_attributes>260.0;20.0;10.0;20.0</additional_attributes>
<additional_attributes>280.0;20.0;10.0;20.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>1170</x>
<y>880</y>
<w>280</w>
<x>760</x>
<y>310</y>
<w>190</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;.
OK (Data)
fg=#1E88E5</panel_attributes>
<additional_attributes>170.0;20.0;10.0;20.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>410</x>
<y>350</y>
<w>300</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;.
OK (Ride)</panel_attributes>
<additional_attributes>10.0;20.0;260.0;20.0</additional_attributes>
<additional_attributes>10.0;20.0;280.0;20.0</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>760</x>
<y>610</y>
<x>150</x>
<y>90</y>
<w>80</w>
<h>30</h>
</coordinates>
@ -67,116 +143,97 @@ bg=#90CAF9</panel_attributes>
<element>
<id>Relation</id>
<coordinates>
<x>800</x>
<y>760</y>
<w>400</w>
<x>200</x>
<y>220</y>
<w>200</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-
GET (Request)
fg=#1E88E5</panel_attributes>
<additional_attributes>10.0;20.0;380.0;20.0</additional_attributes>
<additional_attributes>10.0;20.0;180.0;20.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>800</x>
<y>810</y>
<w>400</w>
<x>200</x>
<y>270</y>
<w>200</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;.
OK (Data)
fg=#1E88E5</panel_attributes>
<additional_attributes>380.0;20.0;10.0;20.0</additional_attributes>
<additional_attributes>180.0;20.0;10.0;20.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>1170</x>
<y>740</y>
<w>280</w>
<x>410</x>
<y>200</y>
<w>300</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;.
OK (Ride)(Request)</panel_attributes>
<additional_attributes>10.0;20.0;260.0;20.0</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>630</x>
<y>320</y>
<w>1330</w>
<h>640</h>
</coordinates>
<panel_attributes>
lt=..
layer=-10</panel_attributes>
<additional_attributes/>
<additional_attributes>10.0;20.0;280.0;20.0</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>1430</x>
<y>700</y>
<w>80</w>
<h>40</h>
<x>150</x>
<y>50</y>
<w>300</w>
<h>30</h>
</coordinates>
<panel_attributes>Available
Rides
bg=#FFF59D
transparency=0</panel_attributes>
<panel_attributes>localhost
lt=-</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>1430</x>
<y>740</y>
<w>80</w>
<h>110</h>
<x>120</x>
<y>20</y>
<w>910</w>
<h>400</h>
</coordinates>
<panel_attributes>Booked
Rides
bg=#E6EE9C
transparency=0
layer=1</panel_attributes>
<panel_attributes>
lt=..
layer=-10</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<id>Relation</id>
<coordinates>
<x>1430</x>
<y>850</y>
<w>80</w>
<h>60</h>
<x>940</x>
<y>110</y>
<w>30</w>
<h>310</h>
</coordinates>
<panel_attributes>Loaded
Rides
bg=#A5D6A7
transparency=0</panel_attributes>
<additional_attributes/>
<panel_attributes>lt=-
fg=#1E88E5</panel_attributes>
<additional_attributes>10.0;10.0;10.0;290.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>790</x>
<y>630</y>
<x>180</x>
<y>110</y>
<w>30</w>
<h>320</h>
<h>310</h>
</coordinates>
<panel_attributes>lt=-
fg=#1E88E5</panel_attributes>
<additional_attributes>10.0;10.0;10.0;300.0</additional_attributes>
<additional_attributes>10.0;10.0;10.0;290.0</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>790</x>
<y>780</y>
<w>20</w>
<h>50</h>
<x>930</x>
<y>200</y>
<w>40</w>
<h>130</h>
</coordinates>
<panel_attributes>
bg=#F6F6F6
@ -184,211 +241,100 @@ transparency=0
layer=4</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>1460</x>
<y>630</y>
<w>30</w>
<h>320</h>
</coordinates>
<panel_attributes>lt=-
fg=#5E35B1
layer=-4</panel_attributes>
<additional_attributes>10.0;10.0;10.0;300.0</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>1420</x>
<y>340</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>forward
bg=#B39DDB
layer=-1</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>860</x>
<y>340</y>
<w>410</w>
<h>30</h>
</coordinates>
<panel_attributes>reverse
bg=#B39DDB
layer=-1</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>1430</x>
<y>450</y>
<w>80</w>
<x>170</x>
<y>240</y>
<w>40</w>
<h>50</h>
</coordinates>
<panel_attributes>Available
Rides
bg=#FFF59D
transparency=0</panel_attributes>
<panel_attributes>
bg=#F6F6F6
transparency=0
layer=4</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>1460</x>
<y>360</y>
<x>720</x>
<y>110</y>
<w>30</w>
<h>180</h>
<h>310</h>
</coordinates>
<panel_attributes>lt=-
fg=#5E35B1
layer=-4</panel_attributes>
<additional_attributes>10.0;10.0;10.0;160.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>1170</x>
<y>440</y>
<w>280</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-
POST (Available)</panel_attributes>
<additional_attributes>260.0;20.0;10.0;20.0</additional_attributes>
<additional_attributes>10.0;10.0;10.0;290.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>1170</x>
<y>470</y>
<w>280</w>
<h>40</h>
<x>390</x>
<y>110</y>
<w>30</w>
<h>310</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;.
OK (# Available)</panel_attributes>
<additional_attributes>10.0;20.0;260.0;20.0</additional_attributes>
<panel_attributes>lt=-
fg=#5E35B1
layer=-4</panel_attributes>
<additional_attributes>10.0;10.0;10.0;290.0</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>860</x>
<y>390</y>
<w>140</w>
<h>40</h>
<x>380</x>
<y>160</y>
<w>40</w>
<h>210</h>
</coordinates>
<panel_attributes>Reverse.main()
bg=#FFF59D
transparency=0</panel_attributes>
<panel_attributes>
bg=#F6F6F6
transparency=0
layer=4</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>1090</x>
<y>390</y>
<w>150</w>
<h>40</h>
<x>690</x>
<y>160</y>
<w>40</w>
<h>60</h>
</coordinates>
<panel_attributes>CheckSuppyR
(Runnable)
bg=#FFF59D
transparency=0</panel_attributes>
<panel_attributes>
bg=#F6F6F6
transparency=0
layer=4</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>1090</x>
<y>550</y>
<w>150</w>
<h>40</h>
<x>690</x>
<y>310</y>
<w>40</w>
<h>60</h>
</coordinates>
<panel_attributes>JourneyGeneratorR
(Runnable)
bg=#FFF59D
transparency=0</panel_attributes>
<panel_attributes>
bg=#F6F6F6
transparency=0
layer=4</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>1090</x>
<y>640</y>
<w>150</w>
<h>40</h>
</coordinates>
<panel_attributes>JourneyR
(Runnable)
bg=#FFF59D
transparency=0</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>990</x>
<y>390</y>
<w>120</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-
1</panel_attributes>
<additional_attributes>100.0;20.0;10.0;20.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>990</x>
<y>410</y>
<w>120</w>
<h>180</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-
1</panel_attributes>
<additional_attributes>100.0;160.0;10.0;10.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>1170</x>
<y>580</y>
<w>80</w>
<h>80</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-
1-1000</panel_attributes>
<additional_attributes>10.0;60.0;10.0;10.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>1170</x>
<y>670</y>
<w>30</w>
<h>280</h>
</coordinates>
<panel_attributes>lt=-
fg=#5E35B1
layer=-4</panel_attributes>
<additional_attributes>10.0;10.0;10.0;260.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>1170</x>
<y>420</y>
<w>30</w>
<x>730</x>
<y>200</y>
<w>40</w>
<h>130</h>
</coordinates>
<panel_attributes>lt=-
fg=#5E35B1
layer=-4</panel_attributes>
<additional_attributes>10.0;10.0;10.0;110.0</additional_attributes>
<panel_attributes>
bg=#F6F6F6
transparency=0
layer=4</panel_attributes>
<additional_attributes/>
</element>
</diagram>

@ -1,4 +0,0 @@
FROM eclipse-temurin:17-alpine
COPY /target/mirror-0.1.jar /usr/local/lib/mirror-0.1.jar
EXPOSE 8080 5005
ENTRYPOINT ["java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", "-jar","/usr/local/lib/mirror-0.1.jar"]

@ -1,9 +0,0 @@
#!/bin/bash
mvn clean install &&
docker build -t io42630/mirror:0.1 .

@ -0,0 +1,10 @@
#!/bin/bash
version="0.1"
file="target/misp-mirror-${version}.war"
groupId="com.olexyn.misp.mirror"
artifactId="misp-mirror"
mvn package
mvn install:install-file -Dfile=${file} -DgroupId=${groupId} -DartifactId=${artifactId} -Dversion=${version} -Dpackaging=war -DgeneratePom=true

@ -1,60 +1,90 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.olexyn</groupId>
<artifactId>zeeroot</artifactId>
<version>spring-boot-jdk17-0.1</version>
</parent>
<groupId>com.olexyn.misp</groupId>
<artifactId>mirror</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<name>mirror</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.olexyn</groupId>
<artifactId>zeebom</artifactId>
<version>1.1.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.olexyn.misp</groupId>
<artifactId>helper</artifactId>
<version>0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<!-- for some godforsaken reason this is required. -->
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
</dependencies>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.olexyn.misp.mirror</groupId>
<artifactId>mirror</artifactId>
<version>0.1</version>
<packaging>war</packaging>
<name>mirror Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.helper</groupId>
<artifactId>helper</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>javax.servlet</artifactId>
<version>3.0.0.v201112011016</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

@ -1,13 +0,0 @@
package com.olexyn.misp.mirror;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class App {
public static void main(String... args) {
SpringApplication.run(App.class, args);
}
}

@ -1,11 +1,9 @@
package com.olexyn.misp.mirror.web;
package com.olexyn.misp.mirror;
import com.olexyn.misp.helper.WebPrint;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@ -13,8 +11,7 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
@RestController
public class Mirror {
public class Mirror extends HttpServlet {
private final List<String> list = new ArrayList<>();
@ -35,7 +32,7 @@ public class Mirror {
}
@GetMapping("/")
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
addRequest(request);
@ -56,9 +53,13 @@ public class Mirror {
}
@PostMapping("/")
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) { addRequest(request); }
@Override
public void doPut(HttpServletRequest request, HttpServletResponse response) { addRequest(request); }
}

@ -0,0 +1,23 @@
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>misp-mirror</display-name>
<servlet>
<servlet-name>misp-mirror</servlet-name>
<servlet-class>com.olexyn.misp.mirror.Mirror</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>misp-mirror</servlet-name>
<url-pattern>/mirror</url-pattern>
</servlet-mapping>
</web-app>

Binary file not shown.

After

Width:  |  Height:  |  Size: 617 B

@ -0,0 +1,20 @@
<html>
<head>
<title>misp-mirror</title>
</head>
<body bgcolor=white>
<table border="0">
<tr>
<td align=center>
<img src="images/io42630.png">
</td>
</tr>
<tr>
<td>
<h1>misp-mirror</h1>
</td>
</tr>
</table>
</body>
</html>

@ -1,7 +0,0 @@
#!/bin/bash
docker push io42630/forward:0.1

@ -1,4 +0,0 @@
FROM eclipse-temurin:17-alpine
COPY /target/reverse-0.1-jar-with-dependencies.jar /usr/local/lib/reverse-0.1-jar-with-dependencies.jar
EXPOSE 8090 5005
ENTRYPOINT ["java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", "-jar","/usr/local/lib/reverse-0.1-jar-with-dependencies.jar"]

@ -1,8 +0,0 @@
#!/bin/bash
mvn clean install &&
docker build -t io42630/reverse:0.1 .

@ -0,0 +1,11 @@
#!/bin/bash
version="0.1"
artifactId="reverse"
file="target/${artifactId}-${version}.jar"
groupId="com.olexyn.misp.reverse"
mvn package
mvn install:install-file -Dfile=${file} -DgroupId=${groupId} -DartifactId=${artifactId} -Dversion=${version} -Dpackaging=jar -DgeneratePom=true

@ -3,74 +3,84 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.olexyn</groupId>
<artifactId>zeeroot</artifactId>
<version>17.0.1</version>
</parent>
<groupId>com.olexyn.misp</groupId>
<groupId>com.olexyn.misp.reverse</groupId>
<artifactId>reverse</artifactId>
<version>0.1</version>
<name>reverse</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.olexyn</groupId>
<artifactId>zeebom</artifactId>
<version>1.1.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp</groupId>
<groupId>com.olexyn.misp.helper</groupId>
<artifactId>helper</artifactId>
<version>0.2</version>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.olexyn.misp.reverse.Reverse</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

@ -1,12 +1,3 @@
### MISP Reverse
#### What it is...
* JAR / adapter / reverse proxy.
* connects to MISP forward server.
#### Overview
* `Reverse`
* Core
@ -22,8 +13,4 @@
* Runnable
* Journey fo a `Ride` through the App.
* `Tools`
* Performs the actual request.
### Build
* maven clean package
* Dockerfile -> build
* Performs the actual request.

@ -6,23 +6,19 @@ import com.olexyn.misp.reverse.runnable.JourneyGeneratorR;
public class Reverse implements Runnable {
public static final String FORWARD_URL = System.getenv("forward.url");
public static final String APP_URL = System.getenv("app.url");
public static final int CHECK_SUPPLY_INTERVAL_MS = Integer.parseInt(System.getenv("check.supply.interval.ms"));
public static final int OVERHEAD = 8;
public static final int CHECK_DEPLETION_INTERVAL = 500;
public static final int START_NEW_JOURNEY_INTERVAL = 100;
public String FORWARD_URL = "http://localhost:8090/forward";
public String APP_URL = "http://localhost:8090/app";
public void start() {
CheckSuppyR checkSuppyR = new CheckSuppyR();
CheckSuppyR checkSuppyR = new CheckSuppyR(this);
Thread checkSupplyT = new Thread(checkSuppyR);
checkSupplyT.setName("checkSupplyT");
checkSupplyT.start();
Thread journeyGeneratorT = new Thread(new JourneyGeneratorR(checkSuppyR));
Thread journeyGeneratorT = new Thread(new JourneyGeneratorR(this, checkSuppyR));
journeyGeneratorT.setName("journeyGeneratorT");
journeyGeneratorT.start();
}

@ -5,19 +5,16 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
public class Tools {
public static String send(String method, String urlString, String body) throws IOException {
URL url = URI.create(urlString).toURL();
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(method);
connection.getHeaderFields(); // TODO
boolean getToForward = method.equals("GET") && urlString.contains("forward");

@ -1,32 +1,34 @@
package com.olexyn.misp.reverse.runnable;
import com.olexyn.misp.reverse.Reverse;
import com.olexyn.misp.reverse.Tools;
import lombok.Getter;
import org.json.JSONObject;
import static com.olexyn.misp.helper.Constants.POST;
import static com.olexyn.misp.reverse.Reverse.CHECK_SUPPLY_INTERVAL_MS;
import static com.olexyn.misp.reverse.Reverse.FORWARD_URL;
import static com.olexyn.misp.helper.Constants.AVAILABLE;
public class CheckSuppyR implements Runnable {
@Getter
private int available;
public int CHECK_SUPPLY_INTERVAL = 100;
private Reverse reverse;
public CheckSuppyR(Reverse reverse) {
this.reverse = reverse;
}
@Override
public void run() {
while (true) {
JSONObject obj = new JSONObject().put(AVAILABLE, 0);
JSONObject obj = new JSONObject().put("available", 0);
try {
String result = Tools.send(POST, FORWARD_URL, obj.toString());
String result = Tools.send("POST", reverse.FORWARD_URL, obj.toString());
JSONObject resultObj = new JSONObject(result);
available = resultObj.getInt(AVAILABLE);
available = resultObj.getInt("available");
Thread.sleep(CHECK_SUPPLY_INTERVAL_MS);
Thread.sleep(CHECK_SUPPLY_INTERVAL);
} catch (Exception ignored) { }
}
@ -34,4 +36,6 @@ public class CheckSuppyR implements Runnable {
}
public int getAvailable() { return available; }
}

@ -1,25 +1,31 @@
package com.olexyn.misp.reverse.runnable;
import static com.olexyn.misp.reverse.Reverse.CHECK_DEPLETION_INTERVAL;
import static com.olexyn.misp.reverse.Reverse.OVERHEAD;
import static com.olexyn.misp.reverse.Reverse.START_NEW_JOURNEY_INTERVAL;
import com.olexyn.misp.reverse.Reverse;
public class JourneyGeneratorR implements Runnable {
private final CheckSuppyR checkSuppyR;
public int OVERHEAD = 8;
public int CHECK_DEPLETION_INTERVAL = 500;
public int START_NEW_JOURNEY_INTERVAL = 100;
public JourneyGeneratorR(CheckSuppyR checkSuppyR) {
private Reverse reverse;
private CheckSuppyR checkSuppyR;
public JourneyGeneratorR(Reverse reverse , CheckSuppyR checkSuppyR) {
this.reverse = reverse;
this.checkSuppyR = checkSuppyR;
}
@Override
public void run() {
int LIMIT = 0;
while (true) {
try {
Thread journeyT = new Thread(new JourneyR());
Thread journeyT = new Thread(new JourneyR(reverse));
journeyT.setName("journeyT");
journeyT.start();
LIMIT++;
@ -33,7 +39,7 @@ public class JourneyGeneratorR implements Runnable {
}
// TODO rework this, so it sends - but not too much, and so it wais - but not too long.
} catch (Exception ignored) { /* ignored */ }
} catch (Exception ignored) { }
}
}
}

@ -1,49 +1,55 @@
package com.olexyn.misp.reverse.runnable;
import com.olexyn.misp.helper.Ride;
import com.olexyn.misp.reverse.Reverse;
import com.olexyn.misp.reverse.Tools;
import java.io.IOException;
import static com.olexyn.misp.helper.Constants.EMPTY;
import static com.olexyn.misp.helper.Constants.GET;
import static com.olexyn.misp.helper.Constants.POST;
import static com.olexyn.misp.reverse.Reverse.APP_URL;
import static com.olexyn.misp.reverse.Reverse.FORWARD_URL;
public class JourneyR implements Runnable {
private Reverse reverse;
public JourneyR(Reverse reverse) {
this.reverse = reverse;
}
@Override
public void run() {
try {
var ride = sendPostRide();
sendGetRequest(ride);
sendPostRideRequestData(ride);
} catch (Exception ignored) { /* ignored */ }
Ride _ride = sendPostRide();
_ride = sendGetRequest(_ride);
sendPostRideRequestData(_ride);
} catch (Exception ignored) { }
}
private Ride sendPostRide() throws IOException {
Ride sendPostRide() throws IOException {
Ride ride = new Ride();
final Ride ride = new Ride();
String result = Tools.send(POST, FORWARD_URL, ride.json());
final String result = Tools.send("POST", reverse.FORWARD_URL, ride.json());
String reqStr = new Ride(result).getRequest();
reqStr = (reqStr == null) ? EMPTY : reqStr;
ride.setRequest(reqStr);
String _req = new Ride(result).getRequest();
String request = (_req == null) ? "" : _req;
ride.setRequest(request);
return ride;
}
private Ride sendGetRequest(Ride ride) throws IOException {
String result = Tools.send(GET, APP_URL, ride.getRequest());
Ride sendGetRequest(Ride ride) throws IOException {
final String result = Tools.send("GET", reverse.APP_URL, ride.getRequest());
ride.setData(result);
return ride;
}
private void sendPostRideRequestData(Ride ride) throws IOException {
Tools.send(POST, FORWARD_URL, ride.json());
}
void sendPostRideRequestData(Ride ride) throws IOException {
Tools.send("POST", reverse.FORWARD_URL, ride.json());
}
}
Loading…
Cancel
Save