Добавлено общее хранилище ключей
This commit is contained in:
@@ -16,6 +16,8 @@ public class CtfService {
|
||||
|
||||
private String name;
|
||||
|
||||
private boolean decryptTls;
|
||||
|
||||
private boolean processChunkedEncoding;
|
||||
|
||||
private boolean ungzipHttp;
|
||||
|
||||
@@ -15,6 +15,7 @@ import ru.serega6531.packmate.model.pojo.Pagination;
|
||||
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
||||
import ru.serega6531.packmate.model.pojo.UnfinishedStream;
|
||||
import ru.serega6531.packmate.repository.StreamRepository;
|
||||
import ru.serega6531.packmate.service.optimization.RsaKeysHolder;
|
||||
import ru.serega6531.packmate.service.optimization.StreamOptimizer;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -33,6 +34,7 @@ public class StreamService {
|
||||
private final ServicesService servicesService;
|
||||
private final CountingService countingService;
|
||||
private final SubscriptionService subscriptionService;
|
||||
private final RsaKeysHolder keysHolder;
|
||||
|
||||
private final boolean ignoreEmptyPackets;
|
||||
|
||||
@@ -44,12 +46,14 @@ public class StreamService {
|
||||
ServicesService servicesService,
|
||||
CountingService countingService,
|
||||
SubscriptionService subscriptionService,
|
||||
RsaKeysHolder keysHolder,
|
||||
@Value("${ignore-empty-packets}") boolean ignoreEmptyPackets) {
|
||||
this.repository = repository;
|
||||
this.patternService = patternService;
|
||||
this.servicesService = servicesService;
|
||||
this.countingService = countingService;
|
||||
this.subscriptionService = subscriptionService;
|
||||
this.keysHolder = keysHolder;
|
||||
this.ignoreEmptyPackets = ignoreEmptyPackets;
|
||||
}
|
||||
|
||||
@@ -94,7 +98,7 @@ public class StreamService {
|
||||
|
||||
countingService.countStream(service.getPort(), packets.size());
|
||||
|
||||
packets = new StreamOptimizer(service, packets).optimizeStream();
|
||||
packets = new StreamOptimizer(keysHolder, service, packets).optimizeStream();
|
||||
processUserAgent(packets, stream);
|
||||
|
||||
Stream savedStream = save(stream);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package ru.serega6531.packmate.service.optimization;
|
||||
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.serega6531.packmate.utils.TlsUtils;
|
||||
|
||||
@@ -23,7 +25,6 @@ public class RsaKeysHolder {
|
||||
|
||||
X509KeyManager keyManager = TlsUtils.createKeyManager(pemFile, keyFile);
|
||||
|
||||
// X509Certificate[] certificateChain = keyManager.getCertificateChain("1");
|
||||
RSAPrivateKey privateKey = ((RSAPrivateKey) keyManager.getPrivateKey("1"));
|
||||
keys.put(privateKey.getModulus(), privateKey);
|
||||
}
|
||||
@@ -32,4 +33,9 @@ public class RsaKeysHolder {
|
||||
return keys.get(modulus);
|
||||
}
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void afterStartup(ApplicationReadyEvent event) {
|
||||
//TODO load keys
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.util.List;
|
||||
@Slf4j
|
||||
public class StreamOptimizer {
|
||||
|
||||
private final RsaKeysHolder keysHolder;
|
||||
private final CtfService service;
|
||||
private List<Packet> packets;
|
||||
|
||||
@@ -19,6 +20,10 @@ public class StreamOptimizer {
|
||||
* Вызвать для выполнения оптимизаций на переданном списке пакетов.
|
||||
*/
|
||||
public List<Packet> optimizeStream() {
|
||||
if (service.isDecryptTls()) {
|
||||
decryptTls();
|
||||
}
|
||||
|
||||
if (service.isProcessChunkedEncoding()) {
|
||||
processChunkedEncoding();
|
||||
}
|
||||
@@ -42,6 +47,11 @@ public class StreamOptimizer {
|
||||
return packets;
|
||||
}
|
||||
|
||||
private void decryptTls() {
|
||||
final TlsDecryptor tlsDecryptor = new TlsDecryptor(packets, keysHolder);
|
||||
tlsDecryptor.decryptTls(); // TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Сжать соседние пакеты в одном направлении в один.
|
||||
* Выполняется после других оптимизаций чтобы правильно определять границы пакетов.
|
||||
|
||||
Reference in New Issue
Block a user