Рефакторинг
This commit is contained in:
@@ -101,8 +101,9 @@ public class PatternMatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addIfPossible(FoundPattern found) {
|
private void addIfPossible(FoundPattern found) {
|
||||||
if (result.stream().noneMatch(match -> between(match.getStartPosition(), match.getEndPosition(), found.getStartPosition()) ||
|
if (result.stream().noneMatch(match ->
|
||||||
between(match.getStartPosition(), match.getEndPosition(), found.getEndPosition()))) {
|
between(match.getStartPosition(), match.getEndPosition(), found.getStartPosition()) ||
|
||||||
|
between(match.getStartPosition(), match.getEndPosition(), found.getEndPosition()))) {
|
||||||
result.add(found);
|
result.add(found);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ import java.util.regex.Pattern;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class TlsDecryptor {
|
public class TlsDecryptor {
|
||||||
|
|
||||||
private static final Pattern cipherSuitePattern = Pattern.compile("TLS_RSA_WITH_([A-Z0-9_]+)_([A-Z0-9]+)");
|
private static final Pattern cipherSuitePattern = Pattern.compile("TLS_RSA_WITH_([A-Z0-9_]+)_[A-Z0-9]+");
|
||||||
|
|
||||||
private final List<Packet> packets;
|
private final List<Packet> packets;
|
||||||
private final RsaKeysHolder keysHolder;
|
private final RsaKeysHolder keysHolder;
|
||||||
@@ -91,24 +91,23 @@ public class TlsDecryptor {
|
|||||||
Matcher matcher = cipherSuitePattern.matcher(cipherSuite.name());
|
Matcher matcher = cipherSuitePattern.matcher(cipherSuite.name());
|
||||||
//noinspection ResultOfMethodCallIgnored
|
//noinspection ResultOfMethodCallIgnored
|
||||||
matcher.find();
|
matcher.find();
|
||||||
String blockCipher = matcher.group(1); //TODO использовать не только AES256
|
String blockCipher = matcher.group(1);
|
||||||
String hashAlgo = matcher.group(2);
|
|
||||||
|
|
||||||
clientRandom = clientHello.getRandom();
|
clientRandom = clientHello.getRandom();
|
||||||
serverRandom = serverHello.getRandom();
|
serverRandom = serverHello.getRandom();
|
||||||
|
|
||||||
decryptTlsRsa(blockCipher, hashAlgo);
|
decryptTlsRsa(blockCipher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
private void decryptTlsRsa(String blockCipher, String hashAlgo) {
|
private void decryptTlsRsa(String blockCipher) {
|
||||||
String[] blockCipherParts = blockCipher.split("_");
|
String[] blockCipherParts = blockCipher.split("_");
|
||||||
String blockCipherAlgo = blockCipherParts[0];
|
String blockCipherAlgo = blockCipherParts[0];
|
||||||
int blockCipherSize = Integer.parseInt(blockCipherParts[1]);
|
int blockCipherSize = Integer.parseInt(blockCipherParts[1]);
|
||||||
String blockCipherMode = blockCipherParts[2];
|
String blockCipherMode = blockCipherParts[2];
|
||||||
|
|
||||||
if (!blockCipherAlgo.equals("AES")) {
|
if (!blockCipherAlgo.equals("AES")) { //TODO использовать не только AES256
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +140,7 @@ public class TlsDecryptor {
|
|||||||
TlsSecret masterSecret = preMaster.deriveUsingPRF(
|
TlsSecret masterSecret = preMaster.deriveUsingPRF(
|
||||||
PRFAlgorithm.tls_prf_sha256, ExporterLabel.master_secret, randomCS, 48);
|
PRFAlgorithm.tls_prf_sha256, ExporterLabel.master_secret, randomCS, 48);
|
||||||
byte[] expanded = masterSecret.deriveUsingPRF(
|
byte[] expanded = masterSecret.deriveUsingPRF(
|
||||||
PRFAlgorithm.tls_prf_sha256, ExporterLabel.key_expansion, randomSC, 72 + keyLength * 2).extract(); // для sha256
|
PRFAlgorithm.tls_prf_sha256, ExporterLabel.key_expansion, randomSC, 72 + keyLength * 2).extract();
|
||||||
|
|
||||||
byte[] clientMacKey = new byte[20];
|
byte[] clientMacKey = new byte[20];
|
||||||
byte[] serverMacKey = new byte[20];
|
byte[] serverMacKey = new byte[20];
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package ru.serega6531.packmate;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import ru.serega6531.packmate.model.CtfService;
|
|
||||||
import ru.serega6531.packmate.model.Packet;
|
import ru.serega6531.packmate.model.Packet;
|
||||||
import ru.serega6531.packmate.service.optimization.HttpGzipProcessor;
|
import ru.serega6531.packmate.service.optimization.HttpGzipProcessor;
|
||||||
import ru.serega6531.packmate.service.optimization.HttpUrldecodeProcessor;
|
import ru.serega6531.packmate.service.optimization.HttpUrldecodeProcessor;
|
||||||
@@ -34,9 +33,6 @@ class StreamOptimizerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testUrldecodeRequests() {
|
void testUrldecodeRequests() {
|
||||||
CtfService service = new CtfService();
|
|
||||||
service.setUrldecodeHttpRequests(true);
|
|
||||||
|
|
||||||
Packet p = createPacket("GET /?q=%D0%B0+%D0%B1 HTTP/1.1\r\n\r\n".getBytes(), true);
|
Packet p = createPacket("GET /?q=%D0%B0+%D0%B1 HTTP/1.1\r\n\r\n".getBytes(), true);
|
||||||
List<Packet> list = new ArrayList<>();
|
List<Packet> list = new ArrayList<>();
|
||||||
list.add(p);
|
list.add(p);
|
||||||
@@ -48,9 +44,6 @@ class StreamOptimizerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testMergeAdjacentPackets() {
|
void testMergeAdjacentPackets() {
|
||||||
CtfService service = new CtfService();
|
|
||||||
service.setMergeAdjacentPackets(true);
|
|
||||||
|
|
||||||
Packet p1 = createPacket(1, false);
|
Packet p1 = createPacket(1, false);
|
||||||
Packet p2 = createPacket(2, true);
|
Packet p2 = createPacket(2, true);
|
||||||
Packet p3 = createPacket(3, true);
|
Packet p3 = createPacket(3, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user