Skip to content

Commit

Permalink
Added new debugging functionalilities and fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ic0ns committed Jun 2, 2018
1 parent 8902878 commit f1b8a22
Show file tree
Hide file tree
Showing 11 changed files with 257 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target/
release.properties
/nbproject/
/nbproject/
apps/
13 changes: 9 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.rub.nds</groupId>
<artifactId>WS-TLS-Scanner</artifactId>
<version>2.2</version>
<version>2.3</version>
<packaging>war</packaging>
<name>WS-TLS-Scanner</name>
<properties>
Expand All @@ -18,12 +18,12 @@
<dependency>
<groupId>de.rub.nds.tlsattacker</groupId>
<artifactId>TLS-Core</artifactId>
<version>2.4</version>
<version>2.5</version>
</dependency>
<dependency>
<groupId>de.rub.nds.tlsscanner</groupId>
<artifactId>TLS-Scanner</artifactId>
<version>2.2</version>
<version>2.3</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
Expand Down Expand Up @@ -94,6 +94,11 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.58</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-debug-jdk15on</artifactId>
Expand Down Expand Up @@ -254,7 +259,7 @@
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<silent>false</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/de/rub/nds/siwecos/tls/DebugManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* SIWECOS-TLS-Scanner - A Webservice for the TLS-Scanner Module of TLS-Attacker
*
* Copyright 2014-2017 Ruhr University Bochum / Hackmanit GmbH
*
* Licensed under Apache License 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
*/
package de.rub.nds.siwecos.tls;

public class DebugManager {

private boolean debugEnabled = false;

private static DebugManager instance = null;

private DebugManager() {
}

public synchronized boolean isDebugEnabled() {
return debugEnabled;
}

public synchronized void setDebugEnabled(boolean debugEnabled) {
this.debugEnabled = debugEnabled;
}

public static DebugManager getInstance() {
if (instance == null) {
instance = new DebugManager();
}
return instance;
}
}
1 change: 0 additions & 1 deletion src/main/java/de/rub/nds/siwecos/tls/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
public class Main {

public static void main(String args[]) {

}
}
15 changes: 14 additions & 1 deletion src/main/java/de/rub/nds/siwecos/tls/TlsScannerCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import de.rub.nds.siwecos.tls.json.TestResult;
import de.rub.nds.siwecos.tls.json.TranslateableMessage;
import de.rub.nds.siwecos.tls.json.ValuePair;
import de.rub.nds.siwecos.tls.ws.DebugOutput;
import de.rub.nds.siwecos.tls.ws.PoolManager;
import de.rub.nds.siwecos.tls.ws.ScanRequest;
import de.rub.nds.tlsattacker.core.config.delegate.ClientDelegate;
import de.rub.nds.tlsattacker.core.config.delegate.GeneralDelegate;
Expand Down Expand Up @@ -47,12 +49,18 @@ public class TlsScannerCallback implements Runnable {

private final ScanRequest request;

public TlsScannerCallback(ScanRequest request) {
private DebugOutput debugOutput;

public TlsScannerCallback(ScanRequest request, DebugOutput debugOutput) {
this.request = request;
this.debugOutput = debugOutput;
}

@Override
public void run() {
debugOutput.setLeftQueueAt(System.currentTimeMillis());
debugOutput.setScanStartedAt(System.currentTimeMillis());
debugOutput.setTimeInQueue(debugOutput.getLeftQueueAt() - debugOutput.getEnteredQueueAt());
LOGGER.info("Scanning: " + request.getUrl());
try {

Expand All @@ -64,6 +72,11 @@ public void run() {
SiteReport report = scanner.scan();
ScanResult result = reportToScanResult(report);
LOGGER.info("Finished scanning: " + request.getUrl());
debugOutput.setScanFinisedAt(System.currentTimeMillis());
debugOutput.setFinalQueueSize(PoolManager.getInstance().getService().getQueue().size());
if (DebugManager.getInstance().isDebugEnabled()) {
result.setDebugOutput(debugOutput);
}
answer(result);
} catch (Throwable T) {
LOGGER.warn("Failed to scan:" + request.getUrl());
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/de/rub/nds/siwecos/tls/json/ScanResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*/
package de.rub.nds.siwecos.tls.json;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import de.rub.nds.siwecos.tls.ws.DebugOutput;
import java.util.List;

/**
Expand All @@ -27,6 +30,9 @@ public class ScanResult {

private List<TestResult> tests;

@JsonInclude(Include.NON_EMPTY)
private DebugOutput debugOutput;

public ScanResult(String name, boolean hasError, TranslateableMessage errorMessage, int score,
List<TestResult> tests) {
this.name = name;
Expand All @@ -36,6 +42,14 @@ public ScanResult(String name, boolean hasError, TranslateableMessage errorMessa
this.tests = tests;
}

public DebugOutput getDebugOutput() {
return debugOutput;
}

public void setDebugOutput(DebugOutput debugOutput) {
this.debugOutput = debugOutput;
}

public String getName() {
return name;
}
Expand Down
89 changes: 89 additions & 0 deletions src/main/java/de/rub/nds/siwecos/tls/ws/DebugOutput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* SIWECOS-TLS-Scanner - A Webservice for the TLS-Scanner Module of TLS-Attacker
*
* Copyright 2014-2017 Ruhr University Bochum / Hackmanit GmbH
*
* Licensed under Apache License 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
*/
package de.rub.nds.siwecos.tls.ws;

public class DebugOutput {

private Integer initialQueueLenght;

private Integer finalQueueSize;

private Long timeInQueue;

private Long enteredQueueAt;

private Long leftQueueAt;

private Long scanStartedAt;

private Long scanFinisedAt;

public DebugOutput(Integer initialQueueLenght, long enteredQueueAt) {
this.initialQueueLenght = initialQueueLenght;
this.enteredQueueAt = enteredQueueAt;
}

public Integer getInitialQueueLenght() {
return initialQueueLenght;
}

public void setInitialQueueLenght(Integer initialQueueLenght) {
this.initialQueueLenght = initialQueueLenght;
}

public Integer getFinalQueueSize() {
return finalQueueSize;
}

public void setFinalQueueSize(Integer finalQueueSize) {
this.finalQueueSize = finalQueueSize;
}

public Long getTimeInQueue() {
return timeInQueue;
}

public void setTimeInQueue(Long timeInQueue) {
this.timeInQueue = timeInQueue;
}

public Long getEnteredQueueAt() {
return enteredQueueAt;
}

public void setEnteredQueueAt(Long enteredQueueAt) {
this.enteredQueueAt = enteredQueueAt;
}

public Long getLeftQueueAt() {
return leftQueueAt;
}

public void setLeftQueueAt(Long leftQueueAt) {
this.leftQueueAt = leftQueueAt;
}

public Long getScanStartedAt() {
return scanStartedAt;
}

public void setScanStartedAt(Long scanStartedAt) {
this.scanStartedAt = scanStartedAt;
}

public Long getScanFinisedAt() {
return scanFinisedAt;
}

public void setScanFinisedAt(Long scanFinisedAt) {
this.scanFinisedAt = scanFinisedAt;
}

}
17 changes: 16 additions & 1 deletion src/main/java/de/rub/nds/siwecos/tls/ws/PoolManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
*/
package de.rub.nds.siwecos.tls.ws;

import static de.rub.nds.siwecos.tls.ws.ScannerWS.LOGGER;
import java.security.Security;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.apache.logging.log4j.LogManager;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

/**
*
Expand All @@ -30,8 +33,11 @@ public class PoolManager {
private ThreadPoolExecutor service;

private PoolManager() {
LOGGER.info("Adding BC as a Security Provider");
Security.addProvider(new BouncyCastleProvider());
LOGGER.info("Starting thread pool");
service = new ThreadPoolExecutor(2, 10, 10, TimeUnit.MINUTES, new LinkedBlockingDeque<Runnable>());
service = new ThreadPoolExecutor(10, 10, 10, TimeUnit.MINUTES, new LinkedBlockingDeque<Runnable>());

}

public static PoolManager getInstance() {
Expand All @@ -46,4 +52,13 @@ private static class PoolManagerHolder {
public ThreadPoolExecutor getService() {
return service;
}

public void setPoolSize(int poolsize) {
boolean increasing = poolsize > service.getPoolSize();
service.setCorePoolSize(poolsize);
service.setMaximumPoolSize(poolsize);
if (!increasing) {
LOGGER.warn("You decreased the Threadpool Size! Changes take effect once all Tasks are completed or you restart the service!");
}
}
}
30 changes: 30 additions & 0 deletions src/main/java/de/rub/nds/siwecos/tls/ws/PoolsizeChangeRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* SIWECOS-TLS-Scanner - A Webservice for the TLS-Scanner Module of TLS-Attacker
*
* Copyright 2014-2017 Ruhr University Bochum / Hackmanit GmbH
*
* Licensed under Apache License 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
*/
package de.rub.nds.siwecos.tls.ws;

public class PoolsizeChangeRequest {

private int size;

public PoolsizeChangeRequest(int size) {
this.size = size;
}

public PoolsizeChangeRequest() {
}

public int getSize() {
return size;
}

public void setSize(int size) {
this.size = size;
}
}
Loading

0 comments on commit f1b8a22

Please sign in to comment.