feat: build wahrwelt A/D toolkit
This commit is contained in:
1 parent
303438d206
commit
653924d8c6
564 files changed
+36310
-49998
No files matched your search
@@ -0,0 +1,13 @@
|
||||
package ru.serega6531.packmate;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class PackmateApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(PackmateApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package ru.serega6531.packmate.configuration;
|
||||
|
||||
import org.modelmapper.Converter;
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.modelmapper.TypeMap;
|
||||
import org.pcap4j.core.PcapNativeException;
|
||||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import ru.serega6531.packmate.model.Pattern;
|
||||
import ru.serega6531.packmate.model.Stream;
|
||||
import ru.serega6531.packmate.model.pojo.StreamDto;
|
||||
import ru.serega6531.packmate.pcap.FilePcapWorker;
|
||||
import ru.serega6531.packmate.pcap.LivePcapWorker;
|
||||
import ru.serega6531.packmate.pcap.NoOpPcapWorker;
|
||||
import ru.serega6531.packmate.pcap.PcapWorker;
|
||||
import ru.serega6531.packmate.properties.PackmateProperties;
|
||||
import ru.serega6531.packmate.service.ServicesService;
|
||||
import ru.serega6531.packmate.service.StreamService;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Configuration
|
||||
@EnableScheduling
|
||||
@EnableAsync
|
||||
@ConfigurationPropertiesScan("ru.serega6531.packmate.properties")
|
||||
public class ApplicationConfiguration {
|
||||
|
||||
@Bean(destroyMethod = "shutdown")
|
||||
public PcapWorker pcapWorker(ServicesService servicesService,
|
||||
StreamService streamService,
|
||||
PackmateProperties properties
|
||||
) throws PcapNativeException, UnknownHostException {
|
||||
return switch (properties.captureMode()) {
|
||||
case LIVE -> new LivePcapWorker(servicesService, streamService, properties.localIp(), properties.interfaceName());
|
||||
case FILE ->
|
||||
new FilePcapWorker(servicesService, streamService, properties.localIp(), properties.pcapFile());
|
||||
case VIEW -> new NoOpPcapWorker();
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ModelMapper modelMapper() {
|
||||
ModelMapper modelMapper = new ModelMapper();
|
||||
|
||||
addStreamMapper(modelMapper);
|
||||
|
||||
return modelMapper;
|
||||
}
|
||||
|
||||
private void addStreamMapper(ModelMapper modelMapper) {
|
||||
TypeMap<Stream, StreamDto> streamMapper = modelMapper.createTypeMap(Stream.class, StreamDto.class);
|
||||
|
||||
Converter<Set<Pattern>, Set<Integer>> patternSetToIdSet = ctx -> ctx.getSource()
|
||||
.stream()
|
||||
.map(Pattern::getId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
streamMapper.addMappings(mapping ->
|
||||
mapping.using(patternSetToIdSet)
|
||||
.map(Stream::getFoundPatterns, StreamDto::setFoundPatternsIds)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package ru.serega6531.packmate.configuration;
|
||||
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
final class SameOriginMutationFilter extends OncePerRequestFilter {
|
||||
|
||||
private static final Set<String> SAFE_METHODS = Set.of("GET", "HEAD", "OPTIONS", "TRACE");
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
FilterChain filterChain
|
||||
) throws ServletException, IOException {
|
||||
String path = request.getRequestURI();
|
||||
boolean apiMutation = path.startsWith("/api/")
|
||||
&& !SAFE_METHODS.contains(request.getMethod().toUpperCase(Locale.ROOT));
|
||||
boolean websocketHandshake = (path.equals("/api/ws") || path.startsWith("/api/ws/"))
|
||||
&& "websocket".equalsIgnoreCase(request.getHeader("Upgrade"));
|
||||
if ((apiMutation || websocketHandshake)
|
||||
&& !isSameOrigin(request)) {
|
||||
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.getWriter().write("{\"message\":\"Источник запроса не совпадает с адресом Packmate.\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
|
||||
private boolean isSameOrigin(HttpServletRequest request) {
|
||||
String originHeader = request.getHeader("Origin");
|
||||
if (originHeader == null || originHeader.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
URI origin = new URI(originHeader);
|
||||
String scheme = request.getScheme();
|
||||
if (!origin.isAbsolute()
|
||||
|| origin.getHost() == null
|
||||
|| origin.getUserInfo() != null
|
||||
|| origin.getRawQuery() != null
|
||||
|| origin.getRawFragment() != null
|
||||
|| (origin.getRawPath() != null && !origin.getRawPath().isEmpty())
|
||||
|| scheme == null
|
||||
|| !origin.getScheme().equalsIgnoreCase(scheme)
|
||||
|| !origin.getHost().equalsIgnoreCase(request.getServerName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int originPort = origin.getPort() == -1 ? defaultPort(origin.getScheme()) : origin.getPort();
|
||||
return originPort == request.getServerPort();
|
||||
} catch (URISyntaxException | IllegalArgumentException exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private int defaultPort(String scheme) {
|
||||
if ("http".equalsIgnoreCase(scheme)) {
|
||||
return 80;
|
||||
}
|
||||
if ("https".equalsIgnoreCase(scheme)) {
|
||||
return 443;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package ru.serega6531.packmate.configuration;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
|
||||
import ru.serega6531.packmate.properties.PackmateProperties;
|
||||
import org.springframework.security.config.Customizer;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@Slf4j
|
||||
public class SecurityConfiguration {
|
||||
|
||||
@Bean
|
||||
public InMemoryUserDetailsManager userDetailsService(PackmateProperties properties, PasswordEncoder passwordEncoder) {
|
||||
if (properties.web().accountLogin() == null || properties.web().accountLogin().isBlank()) {
|
||||
throw new IllegalStateException("Нужно задать PACKMATE_USERNAME.");
|
||||
}
|
||||
if (properties.web().accountPassword() == null || properties.web().accountPassword().isBlank()) {
|
||||
throw new IllegalStateException("Нужно задать PACKMATE_PASSWORD.");
|
||||
}
|
||||
|
||||
UserDetails user = User.builder()
|
||||
.username(properties.web().accountLogin())
|
||||
.password(passwordEncoder.encode(properties.web().accountPassword()))
|
||||
.roles("USER")
|
||||
.build();
|
||||
|
||||
return new InMemoryUserDetailsManager(user);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
return http
|
||||
.csrf(csrf -> csrf.disable())
|
||||
.addFilterBefore(new SameOriginMutationFilter(), BasicAuthenticationFilter.class)
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers("/healthz", "/site.webmanifest").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.httpBasic(Customizer.withDefaults())
|
||||
.headers(headers -> headers.frameOptions(frameOptions -> frameOptions.sameOrigin()))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PasswordEncoder passwordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void authenticationFailed(AuthenticationFailureBadCredentialsEvent e) {
|
||||
log.info("Неудачная попытка входа");
|
||||
}
|
||||
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package ru.serega6531.packmate.configuration;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
||||
import ru.serega6531.packmate.controller.WebSocketHandler;
|
||||
|
||||
@EnableWebSocket
|
||||
@Configuration
|
||||
public class WebSocketConfiguration implements WebSocketConfigurer {
|
||||
|
||||
private final WebSocketHandler webSocketHandler;
|
||||
|
||||
@Autowired
|
||||
public WebSocketConfiguration(WebSocketHandler webSocketHandler) {
|
||||
this.webSocketHandler = webSocketHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||
registry.addHandler(webSocketHandler, "/api/ws");
|
||||
}
|
||||
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package ru.serega6531.packmate.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
public class FrontendController {
|
||||
|
||||
@GetMapping("/{servicePort:[0-9]+}")
|
||||
public String serviceRoute() {
|
||||
return "forward:/index.html";
|
||||
}
|
||||
|
||||
@GetMapping("/{servicePort:[0-9]+}/{streamId:[0-9]+}")
|
||||
public String streamRoute() {
|
||||
return "forward:/index.html";
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package ru.serega6531.packmate.controller;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class HealthController {
|
||||
|
||||
@GetMapping("/healthz")
|
||||
public ResponseEntity<Void> health() {
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package ru.serega6531.packmate.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.serega6531.packmate.model.pojo.PacketDto;
|
||||
import ru.serega6531.packmate.model.pojo.PacketPagination;
|
||||
import ru.serega6531.packmate.service.StreamService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/packet/")
|
||||
public class PacketController {
|
||||
|
||||
private final StreamService streamService;
|
||||
|
||||
@Autowired
|
||||
public PacketController(StreamService streamService) {
|
||||
this.streamService = streamService;
|
||||
}
|
||||
|
||||
@PostMapping("/{streamId}")
|
||||
public List<PacketDto> getPacketsForStream(@PathVariable long streamId, @RequestBody PacketPagination pagination) {
|
||||
return streamService.getPackets(streamId, pagination.getStartingFrom(), pagination.getPageSize());
|
||||
}
|
||||
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package ru.serega6531.packmate.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.serega6531.packmate.model.pojo.PatternCreateDto;
|
||||
import ru.serega6531.packmate.model.pojo.PatternDto;
|
||||
import ru.serega6531.packmate.model.pojo.PatternUpdateDto;
|
||||
import ru.serega6531.packmate.service.PatternService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/pattern/")
|
||||
public class PatternController {
|
||||
|
||||
private final PatternService service;
|
||||
|
||||
@Autowired
|
||||
public PatternController(PatternService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<PatternDto> getPatterns() {
|
||||
return service.findAll()
|
||||
.stream().map(service::toDto)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/enable")
|
||||
public void enable(@PathVariable int id, @RequestParam boolean enabled) {
|
||||
service.enable(id, enabled);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public void delete(@PathVariable int id) {
|
||||
service.delete(id);
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/lookback")
|
||||
public void lookBack(@PathVariable int id, @RequestBody int minutes) {
|
||||
service.lookBack(id, minutes);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public PatternDto addPattern(@RequestBody PatternCreateDto dto) {
|
||||
return service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/{id}")
|
||||
public PatternDto updatePattern(@PathVariable int id, @RequestBody PatternUpdateDto dto) {
|
||||
return service.update(id, dto);
|
||||
}
|
||||
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package ru.serega6531.packmate.controller;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import ru.serega6531.packmate.exception.PatternValidationException;
|
||||
import ru.serega6531.packmate.exception.RequestValidationException;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class PatternValidationHandler {
|
||||
|
||||
@ExceptionHandler(PatternValidationException.class)
|
||||
public ResponseEntity<Map<String, String>> handleInvalidPattern(PatternValidationException exception) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
|
||||
.body(Map.of("message", exception.getMessage()));
|
||||
}
|
||||
|
||||
@ExceptionHandler(RequestValidationException.class)
|
||||
public ResponseEntity<Map<String, String>> handleInvalidRequest(RequestValidationException exception) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
|
||||
.body(Map.of("message", exception.getMessage()));
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package ru.serega6531.packmate.controller;
|
||||
|
||||
import org.pcap4j.core.PcapNativeException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.serega6531.packmate.service.PcapService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/pcap/")
|
||||
public class PcapController {
|
||||
|
||||
private final PcapService service;
|
||||
|
||||
@Autowired
|
||||
public PcapController(PcapService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@GetMapping("/started")
|
||||
public boolean started() {
|
||||
return service.isStarted();
|
||||
}
|
||||
|
||||
@PostMapping("/start")
|
||||
public void start() throws PcapNativeException {
|
||||
service.start();
|
||||
}
|
||||
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package ru.serega6531.packmate.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.serega6531.packmate.model.pojo.ServiceCreateDto;
|
||||
import ru.serega6531.packmate.model.pojo.ServiceDto;
|
||||
import ru.serega6531.packmate.model.pojo.ServiceUpdateDto;
|
||||
import ru.serega6531.packmate.service.ServicesService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/service/")
|
||||
public class ServiceController {
|
||||
|
||||
private final ServicesService service;
|
||||
|
||||
@Autowired
|
||||
public ServiceController(ServicesService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<ServiceDto> getServices() {
|
||||
return service.findAll();
|
||||
}
|
||||
|
||||
@DeleteMapping("/{port}")
|
||||
public void deleteService(@PathVariable int port) {
|
||||
service.deleteByPort(port);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ServiceDto addService(@RequestBody ServiceCreateDto dto) {
|
||||
return this.service.create(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/{port}")
|
||||
public ServiceDto updateService(@PathVariable int port, @RequestBody ServiceUpdateDto dto) {
|
||||
return this.service.update(port, dto);
|
||||
}
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package ru.serega6531.packmate.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.serega6531.packmate.model.pojo.StreamDto;
|
||||
import ru.serega6531.packmate.model.pojo.StreamPagination;
|
||||
import ru.serega6531.packmate.service.StreamService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/stream/")
|
||||
public class StreamController {
|
||||
|
||||
private final StreamService service;
|
||||
|
||||
@Autowired
|
||||
public StreamController(StreamService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@PostMapping("/all")
|
||||
public List<StreamDto> getStreams(@RequestBody StreamPagination pagination) {
|
||||
return service.findAll(pagination, Optional.empty(), pagination.isFavorites());
|
||||
}
|
||||
|
||||
@PostMapping("/{port}")
|
||||
public List<StreamDto> getStreams(@PathVariable int port, @RequestBody StreamPagination pagination) {
|
||||
return service.findAll(pagination, Optional.of(port), pagination.isFavorites());
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/favorite")
|
||||
public void favoriteStream(@PathVariable long id) {
|
||||
service.setFavorite(id, true);
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/unfavorite")
|
||||
public void unfavoriteStream(@PathVariable long id) {
|
||||
service.setFavorite(id, false);
|
||||
}
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package ru.serega6531.packmate.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
import ru.serega6531.packmate.service.SubscriptionService;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Component
|
||||
public class WebSocketHandler extends TextWebSocketHandler {
|
||||
|
||||
private final SubscriptionService subscriptionService;
|
||||
|
||||
@Autowired
|
||||
public WebSocketHandler(SubscriptionService subscriptionService) {
|
||||
this.subscriptionService = subscriptionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterConnectionEstablished(WebSocketSession session) {
|
||||
subscriptionService.addSubscriber(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) {
|
||||
subscriptionService.removeSubscriber(session);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package ru.serega6531.packmate.exception;
|
||||
|
||||
public class PatternValidationException extends RuntimeException {
|
||||
|
||||
public PatternValidationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package ru.serega6531.packmate.exception;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class PcapFileNotFoundException extends RuntimeException {
|
||||
|
||||
private final File file;
|
||||
private final File directory;
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package ru.serega6531.packmate.exception;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class PcapInterfaceNotFoundException extends RuntimeException {
|
||||
|
||||
private final String requestedInterface;
|
||||
private final List<String> existingInterfaces;
|
||||
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package ru.serega6531.packmate.exception;
|
||||
|
||||
public class RequestValidationException extends RuntimeException {
|
||||
|
||||
public RequestValidationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package ru.serega6531.packmate.exception.analyzer;
|
||||
|
||||
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
|
||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
import ru.serega6531.packmate.exception.PcapFileNotFoundException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PcapFileNotFoundFailureAnalyzer extends AbstractFailureAnalyzer<PcapFileNotFoundException> {
|
||||
@Override
|
||||
protected FailureAnalysis analyze(Throwable rootFailure, PcapFileNotFoundException cause) {
|
||||
String description = "Файл " + cause.getFile().getAbsolutePath() + " не найден.";
|
||||
String existingFilesMessage;
|
||||
|
||||
File[] existingFiles = cause.getDirectory().listFiles();
|
||||
|
||||
if (existingFiles == null) {
|
||||
return new FailureAnalysis(
|
||||
description,
|
||||
"Поместите файл PCAP в каталог ./pcaps. Сейчас этого каталога нет.",
|
||||
cause
|
||||
);
|
||||
}
|
||||
|
||||
if (existingFiles.length == 0) {
|
||||
existingFilesMessage = "Каталог ./pcaps пуст.";
|
||||
} else {
|
||||
List<String> existingFilesNames = Arrays.stream(existingFiles).map(File::getName).toList();
|
||||
existingFilesMessage = "В каталоге " + cause.getDirectory().getAbsolutePath() + " найдены файлы: " + existingFilesNames;
|
||||
}
|
||||
|
||||
return new FailureAnalysis(
|
||||
description,
|
||||
"Проверьте имя файла и поместите его в каталог ./pcaps.\n" +
|
||||
existingFilesMessage,
|
||||
cause
|
||||
);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package ru.serega6531.packmate.exception.analyzer;
|
||||
|
||||
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
|
||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
import ru.serega6531.packmate.exception.PcapInterfaceNotFoundException;
|
||||
|
||||
public class PcapInterfaceNotFoundFailureAnalyzer extends AbstractFailureAnalyzer<PcapInterfaceNotFoundException> {
|
||||
@Override
|
||||
protected FailureAnalysis analyze(Throwable rootFailure, PcapInterfaceNotFoundException cause) {
|
||||
return new FailureAnalysis(
|
||||
"Сетевой интерфейс \"" + cause.getRequestedInterface() + "\" не найден.",
|
||||
"Проверьте PACKMATE_INTERFACE_NAME. Доступные интерфейсы: " + cause.getExistingInterfaces(),
|
||||
cause
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package ru.serega6531.packmate.model;
|
||||
|
||||
import lombok.*;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import java.util.Objects;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@RequiredArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "service")
|
||||
public class CtfService {
|
||||
|
||||
@Id
|
||||
private Integer port;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
|
||||
private boolean decryptTls;
|
||||
|
||||
private boolean http;
|
||||
|
||||
private boolean urldecodeHttpRequests;
|
||||
|
||||
private boolean mergeAdjacentPackets;
|
||||
|
||||
private boolean parseWebSockets;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
|
||||
CtfService that = (CtfService) o;
|
||||
return port != null && Objects.equals(port, that.port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getClass().hashCode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package ru.serega6531.packmate.model;
|
||||
|
||||
import lombok.*;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Parameter;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@GenericGenerator(
|
||||
name = "found_pattern_generator",
|
||||
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
|
||||
parameters = {
|
||||
@Parameter(name = "sequence_name", value = "found_pattern_seq"),
|
||||
@Parameter(name = "initial_value", value = "1"),
|
||||
@Parameter(name = "increment_size", value = "2000"),
|
||||
@Parameter(name = "optimizer", value = "hilo")
|
||||
}
|
||||
)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Getter
|
||||
@ToString
|
||||
@Table(indexes = { @Index(name = "found_pattern_packet_id_index", columnList = "packet_id DESC") })
|
||||
public class FoundPattern {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "found_pattern_generator")
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "packet_id", nullable = false)
|
||||
@Setter
|
||||
private Packet packet;
|
||||
|
||||
private int patternId;
|
||||
|
||||
private int startPosition;
|
||||
|
||||
private int endPosition;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
|
||||
FoundPattern that = (FoundPattern) o;
|
||||
return id != null && Objects.equals(id, that.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getClass().hashCode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package ru.serega6531.packmate.model;
|
||||
|
||||
import lombok.*;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Parameter;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@RequiredArgsConstructor
|
||||
@Entity
|
||||
@GenericGenerator(
|
||||
name = "packet_generator",
|
||||
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
|
||||
parameters = {
|
||||
@Parameter(name = "sequence_name", value = "packet_seq"),
|
||||
@Parameter(name = "initial_value", value = "1"),
|
||||
@Parameter(name = "increment_size", value = "20000"),
|
||||
@Parameter(name = "optimizer", value = "hilo")
|
||||
}
|
||||
)
|
||||
@AllArgsConstructor
|
||||
@Builder(toBuilder = true)
|
||||
@Table(indexes = { @Index(name = "stream_id_index", columnList = "stream_id") })
|
||||
public class Packet {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(generator = "packet_generator")
|
||||
private Long id;
|
||||
|
||||
@Transient
|
||||
private Long tempId;
|
||||
|
||||
@Transient
|
||||
private int ttl;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
||||
@JoinColumn(name = "stream_id", nullable = false)
|
||||
private Stream stream;
|
||||
|
||||
@OneToMany(mappedBy = "packet", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private Set<FoundPattern> matches;
|
||||
|
||||
private long timestamp;
|
||||
|
||||
private boolean incoming; // true, если пакет идет от клиента к серверу.
|
||||
|
||||
private boolean httpProcessed = false;
|
||||
|
||||
private boolean webSocketParsed = false;
|
||||
|
||||
private boolean tlsDecrypted = false;
|
||||
|
||||
private boolean hasHttpBody = false;
|
||||
|
||||
@Column(nullable = false)
|
||||
private byte[] content;
|
||||
|
||||
@Transient
|
||||
public String getContentString() {
|
||||
return new String(content);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Packet(id=" + id + ", content=" + getContentString() + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
|
||||
Packet packet = (Packet) o;
|
||||
return id != null && Objects.equals(id, packet.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getClass().hashCode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package ru.serega6531.packmate.model;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Parameter;
|
||||
import ru.serega6531.packmate.model.enums.PatternActionType;
|
||||
import ru.serega6531.packmate.model.enums.PatternDirectionType;
|
||||
import ru.serega6531.packmate.model.enums.PatternSearchType;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@RequiredArgsConstructor
|
||||
@ToString
|
||||
@Entity(name = "pattern")
|
||||
@GenericGenerator(
|
||||
name = "pattern_generator",
|
||||
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
|
||||
parameters = {
|
||||
@Parameter(name = "sequence_name", value = "pattern_seq"),
|
||||
@Parameter(name = "initial_value", value = "1"),
|
||||
@Parameter(name = "increment_size", value = "1")
|
||||
}
|
||||
)
|
||||
public class Pattern {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(generator = "pattern_generator")
|
||||
private Integer id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private boolean enabled;
|
||||
|
||||
@Column(nullable = false)
|
||||
private boolean deleted = false;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String value;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String color; // Цвет для CSS.
|
||||
|
||||
@Enumerated
|
||||
@Column(nullable = false)
|
||||
private PatternSearchType searchType;
|
||||
|
||||
@Enumerated
|
||||
@Column(nullable = false)
|
||||
private PatternDirectionType directionType;
|
||||
|
||||
@Enumerated
|
||||
@Column(nullable = false)
|
||||
private PatternActionType actionType;
|
||||
|
||||
private Integer serviceId;
|
||||
|
||||
private long searchStartTimestamp;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
|
||||
Pattern pattern = (Pattern) o;
|
||||
return id != null && Objects.equals(id, pattern.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getClass().hashCode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package ru.serega6531.packmate.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Parameter;
|
||||
import ru.serega6531.packmate.model.enums.Protocol;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@RequiredArgsConstructor
|
||||
@Entity
|
||||
@GenericGenerator(
|
||||
name = "stream_generator",
|
||||
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
|
||||
parameters = {
|
||||
@Parameter(name = "sequence_name", value = "stream_seq"),
|
||||
@Parameter(name = "initial_value", value = "1"),
|
||||
@Parameter(name = "increment_size", value = "1000"),
|
||||
@Parameter(name = "optimizer", value = "hilo")
|
||||
}
|
||||
)
|
||||
@Table(indexes = {@Index(name = "stream_id_desc_index", columnList = "id DESC")})
|
||||
public class Stream {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(generator = "stream_generator")
|
||||
private Long id;
|
||||
|
||||
@Column(name = "service_id", nullable = false)
|
||||
private int service;
|
||||
|
||||
@Enumerated
|
||||
@Column(nullable = false)
|
||||
private Protocol protocol;
|
||||
|
||||
@OneToMany(mappedBy = "stream", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@OrderBy("id")
|
||||
@ToString.Exclude
|
||||
private List<Packet> packets;
|
||||
|
||||
private long startTimestamp;
|
||||
|
||||
private long endTimestamp;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "stream_found_patterns",
|
||||
joinColumns = @JoinColumn(name = "stream_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "pattern_id")
|
||||
)
|
||||
@ToString.Exclude
|
||||
private Set<Pattern> foundPatterns = new HashSet<>();
|
||||
|
||||
private boolean favorite;
|
||||
|
||||
@Column(nullable = false, columnDefinition = "smallint")
|
||||
private int ttl;
|
||||
|
||||
@Column(columnDefinition = "char(3)")
|
||||
private String userAgentHash;
|
||||
|
||||
@Column(name = "size_bytes", nullable = false)
|
||||
private Integer sizeBytes;
|
||||
|
||||
@Column(name = "packets_count", nullable = false)
|
||||
private Integer packetsCount;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
|
||||
Stream stream = (Stream) o;
|
||||
return id != null && Objects.equals(id, stream.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getClass().hashCode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ru.serega6531.packmate.model.enums;
|
||||
|
||||
public enum CaptureMode {
|
||||
|
||||
LIVE, FILE, VIEW
|
||||
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package ru.serega6531.packmate.model.enums;
|
||||
|
||||
public enum PatternActionType {
|
||||
FIND, IGNORE
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package ru.serega6531.packmate.model.enums;
|
||||
|
||||
public enum PatternDirectionType {
|
||||
INPUT, OUTPUT, BOTH
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package ru.serega6531.packmate.model.enums;
|
||||
|
||||
public enum PatternSearchType {
|
||||
REGEX, SUBSTRING, SUBBYTES
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package ru.serega6531.packmate.model.enums;
|
||||
|
||||
public enum Protocol {
|
||||
TCP, UDP
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package ru.serega6531.packmate.model.enums;
|
||||
|
||||
public enum SubscriptionMessageType {
|
||||
SAVE_SERVICE, SAVE_PATTERN,
|
||||
DELETE_SERVICE,
|
||||
NEW_STREAM,
|
||||
FINISH_LOOKBACK,
|
||||
COUNTERS_UPDATE,
|
||||
ENABLE_PATTERN, DISABLE_PATTERN,
|
||||
PCAP_STARTED, PCAP_STOPPED
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package ru.serega6531.packmate.model.pojo;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class Counter {
|
||||
|
||||
private int value = 0;
|
||||
|
||||
public void increment() {
|
||||
value++;
|
||||
}
|
||||
|
||||
public void increment(int num) {
|
||||
value += num;
|
||||
}
|
||||
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package ru.serega6531.packmate.model.pojo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public record CountersHolder(Map<Integer, Integer> servicesPackets, Map<Integer, Integer> servicesStreams,
|
||||
int totalPackets, int totalStreams) {
|
||||
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package ru.serega6531.packmate.model.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FoundPatternDto {
|
||||
|
||||
private int patternId;
|
||||
private int startPosition;
|
||||
private int endPosition;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package ru.serega6531.packmate.model.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
public class PacketDto {
|
||||
|
||||
private Long id;
|
||||
private Set<FoundPatternDto> matches;
|
||||
private long timestamp;
|
||||
private boolean incoming;
|
||||
private boolean ungzipped;
|
||||
private boolean webSocketParsed;
|
||||
private boolean tlsDecrypted;
|
||||
private boolean hasHttpBody;
|
||||
private byte[] content;
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package ru.serega6531.packmate.model.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Data
|
||||
public class PacketPagination {
|
||||
|
||||
@Nullable
|
||||
private Long startingFrom;
|
||||
|
||||
private int pageSize;
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package ru.serega6531.packmate.model.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
import ru.serega6531.packmate.model.enums.PatternActionType;
|
||||
import ru.serega6531.packmate.model.enums.PatternDirectionType;
|
||||
import ru.serega6531.packmate.model.enums.PatternSearchType;
|
||||
|
||||
@Data
|
||||
public class PatternCreateDto {
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
private String color;
|
||||
private PatternSearchType searchType;
|
||||
private PatternDirectionType directionType;
|
||||
private PatternActionType actionType;
|
||||
private Integer serviceId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package ru.serega6531.packmate.model.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
import ru.serega6531.packmate.model.enums.PatternActionType;
|
||||
import ru.serega6531.packmate.model.enums.PatternDirectionType;
|
||||
import ru.serega6531.packmate.model.enums.PatternSearchType;
|
||||
|
||||
@Data
|
||||
public class PatternDto {
|
||||
|
||||
private int id;
|
||||
private boolean enabled;
|
||||
private boolean deleted;
|
||||
private String name;
|
||||
private String value;
|
||||
private String color;
|
||||
private PatternSearchType searchType;
|
||||
private PatternDirectionType directionType;
|
||||
private PatternActionType actionType;
|
||||
private Integer serviceId;
|
||||
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package ru.serega6531.packmate.model.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PatternUpdateDto {
|
||||
|
||||
private String name;
|
||||
private String color;
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package ru.serega6531.packmate.model.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ServiceCreateDto {
|
||||
|
||||
private int port;
|
||||
private String name;
|
||||
private boolean decryptTls;
|
||||
private boolean http;
|
||||
private boolean urldecodeHttpRequests;
|
||||
private boolean mergeAdjacentPackets;
|
||||
private boolean parseWebSockets;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package ru.serega6531.packmate.model.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ServiceDto {
|
||||
|
||||
private int port;
|
||||
private String name;
|
||||
private boolean decryptTls;
|
||||
private boolean http;
|
||||
private boolean urldecodeHttpRequests;
|
||||
private boolean mergeAdjacentPackets;
|
||||
private boolean parseWebSockets;
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package ru.serega6531.packmate.model.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ServiceUpdateDto {
|
||||
|
||||
private int port;
|
||||
private String name;
|
||||
private boolean decryptTls;
|
||||
private boolean http;
|
||||
private boolean urldecodeHttpRequests;
|
||||
private boolean mergeAdjacentPackets;
|
||||
private boolean parseWebSockets;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package ru.serega6531.packmate.model.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
import ru.serega6531.packmate.model.enums.Protocol;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
public class StreamDto {
|
||||
|
||||
private Long id;
|
||||
private int service;
|
||||
private Protocol protocol;
|
||||
private long startTimestamp;
|
||||
private long endTimestamp;
|
||||
private Set<Integer> foundPatternsIds;
|
||||
private boolean favorite;
|
||||
private int ttl;
|
||||
private String userAgentHash;
|
||||
private int sizeBytes;
|
||||
private int packetsCount;
|
||||
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package ru.serega6531.packmate.model.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.serega6531.packmate.model.Pattern;
|
||||
|
||||
@Data
|
||||
public class StreamPagination {
|
||||
|
||||
@Nullable
|
||||
private Long startingFrom;
|
||||
|
||||
private int pageSize;
|
||||
|
||||
private boolean favorites; // Искать только избранные потоки или все.
|
||||
|
||||
@Nullable
|
||||
private Pattern pattern; // Если задан, искать потоки с этим паттерном.
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package ru.serega6531.packmate.model.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class SubscriptionMessage {
|
||||
|
||||
private SubscriptionMessageType type;
|
||||
private Object value;
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package ru.serega6531.packmate.model.pojo;
|
||||
|
||||
import ru.serega6531.packmate.model.enums.Protocol;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
public record UnfinishedStream(InetAddress firstIp, InetAddress secondIp, int firstPort, int secondPort,
|
||||
Protocol protocol) {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof UnfinishedStream o)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean ipEq1 = firstIp.equals(o.firstIp) && secondIp.equals(o.secondIp);
|
||||
boolean ipEq2 = firstIp.equals(o.secondIp) && secondIp.equals(o.firstIp);
|
||||
boolean portEq1 = firstPort == o.firstPort && secondPort == o.secondPort;
|
||||
boolean portEq2 = firstPort == o.secondPort && secondPort == o.firstPort;
|
||||
|
||||
return (ipEq1 || ipEq2) && (portEq1 || portEq2) && protocol == o.protocol;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
|
||||
int result = firstIp.hashCode() * secondIp.hashCode();
|
||||
result = result * PRIME + (firstPort * secondPort);
|
||||
result = result * PRIME + protocol.hashCode();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+304
@@ -0,0 +1,304 @@
|
||||
package ru.serega6531.packmate.pcap;
|
||||
|
||||
import com.google.common.collect.*;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.pcap4j.core.BpfProgram;
|
||||
import org.pcap4j.core.PacketListener;
|
||||
import org.pcap4j.core.PcapHandle;
|
||||
import org.pcap4j.core.PcapPacket;
|
||||
import org.pcap4j.packet.*;
|
||||
import ru.serega6531.packmate.model.CtfService;
|
||||
import ru.serega6531.packmate.model.enums.Protocol;
|
||||
import ru.serega6531.packmate.model.pojo.UnfinishedStream;
|
||||
import ru.serega6531.packmate.service.ServicesService;
|
||||
import ru.serega6531.packmate.service.StreamService;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractPcapWorker implements PcapWorker, PacketListener {
|
||||
|
||||
private final ServicesService servicesService;
|
||||
private final StreamService streamService;
|
||||
|
||||
protected volatile PcapHandle pcap = null;
|
||||
protected final ExecutorService loopExecutorService;
|
||||
|
||||
protected String filter = "tcp or udp";
|
||||
|
||||
// Во время работы должен быть задан.
|
||||
protected ExecutorService processorExecutorService;
|
||||
|
||||
private final InetAddress localIp;
|
||||
|
||||
private long packetIdCounter = 0; // Доступ однопоточный, поэтому AtomicLong не требуется.
|
||||
|
||||
private final ListMultimap<UnfinishedStream, ru.serega6531.packmate.model.Packet> unfinishedTcpStreams = ArrayListMultimap.create();
|
||||
private final ListMultimap<UnfinishedStream, ru.serega6531.packmate.model.Packet> unfinishedUdpStreams = ArrayListMultimap.create();
|
||||
|
||||
// В следующих множествах хранятся адреса источника соответствующего пакета.
|
||||
private final SetMultimap<UnfinishedStream, Pair<InetAddress, Integer>> fins = HashMultimap.create();
|
||||
private final SetMultimap<UnfinishedStream, Pair<InetAddress, Integer>> acks = HashMultimap.create();
|
||||
|
||||
protected AbstractPcapWorker(ServicesService servicesService,
|
||||
StreamService streamService,
|
||||
InetAddress localIp) throws UnknownHostException {
|
||||
this.servicesService = servicesService;
|
||||
this.streamService = streamService;
|
||||
|
||||
this.localIp = localIp;
|
||||
|
||||
BasicThreadFactory factory = new BasicThreadFactory.Builder()
|
||||
.namingPattern("pcap-loop").build();
|
||||
loopExecutorService = Executors.newSingleThreadExecutor(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gotPacket(PcapPacket capturedPacket) {
|
||||
gotPacket(capturedPacket, pcap);
|
||||
}
|
||||
|
||||
protected void gotPacket(PcapPacket capturedPacket, PcapHandle capture) {
|
||||
if (capture == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Packet rawPacket = capturedPacket.getPacket();
|
||||
|
||||
InetAddress sourceIp;
|
||||
InetAddress destIp;
|
||||
int ttl;
|
||||
|
||||
if (rawPacket.contains(IpV4Packet.class)) {
|
||||
final IpV4Packet.IpV4Header ipHeader = rawPacket.get(IpV4Packet.class).getHeader();
|
||||
sourceIp = ipHeader.getSrcAddr();
|
||||
destIp = ipHeader.getDstAddr();
|
||||
ttl = Byte.toUnsignedInt(ipHeader.getTtl());
|
||||
} else if (rawPacket.contains(IpV6Packet.class)) {
|
||||
final IpV6Packet.IpV6Header ipHeader = rawPacket.get(IpV6Packet.class).getHeader();
|
||||
sourceIp = ipHeader.getSrcAddr();
|
||||
destIp = ipHeader.getDstAddr();
|
||||
ttl = Byte.toUnsignedInt(ipHeader.getHopLimit());
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
final long time = capturedPacket.getTimestamp().toEpochMilli();
|
||||
|
||||
if (rawPacket.contains(TcpPacket.class)) {
|
||||
final TcpPacket packet = rawPacket.get(TcpPacket.class);
|
||||
gotTcpPacket(packet, sourceIp, destIp, ttl, time);
|
||||
} else if (rawPacket.contains(UdpPacket.class)) {
|
||||
final UdpPacket packet = rawPacket.get(UdpPacket.class);
|
||||
gotUdpPacket(packet, sourceIp, destIp, ttl, time);
|
||||
}
|
||||
}
|
||||
|
||||
private void gotTcpPacket(TcpPacket packet, InetAddress sourceIp, InetAddress destIp, int ttl, long time) {
|
||||
final TcpPacket.TcpHeader tcpHeader = packet.getHeader();
|
||||
int sourcePort = tcpHeader.getSrcPort().valueAsInt();
|
||||
int destPort = tcpHeader.getDstPort().valueAsInt();
|
||||
boolean ack = tcpHeader.getAck();
|
||||
boolean fin = tcpHeader.getFin();
|
||||
boolean rst = tcpHeader.getRst();
|
||||
byte[] content = packet.getPayload() != null ? packet.getPayload().getRawData() : new byte[0];
|
||||
|
||||
String sourceIpString = sourceIp.getHostAddress();
|
||||
String destIpString = destIp.getHostAddress();
|
||||
|
||||
final Optional<CtfService> serviceOptional =
|
||||
servicesService.findService(sourceIp, sourcePort, destIp, destPort);
|
||||
|
||||
if (serviceOptional.isPresent()) {
|
||||
processorExecutorService.execute(() -> {
|
||||
UnfinishedStream stream = addNewPacket(sourceIp, destIp, time, sourcePort, destPort, ttl, content, Protocol.TCP);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("TCP {} {}:{} -> {}:{}, номер пакета {}",
|
||||
serviceOptional.get(), sourceIpString, sourcePort, destIpString, destPort,
|
||||
unfinishedTcpStreams.get(stream).size());
|
||||
}
|
||||
|
||||
checkTcpTermination(ack, fin, rst, new ImmutablePair<>(sourceIp, sourcePort), new ImmutablePair<>(destIp, destPort), stream);
|
||||
});
|
||||
} else { // сервис не найден
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("tcp {}:{} -> {}:{}", sourceIpString, sourcePort, destIpString, destPort);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void gotUdpPacket(UdpPacket packet, InetAddress sourceIp, InetAddress destIp, int ttl, long time) {
|
||||
final UdpPacket.UdpHeader udpHeader = packet.getHeader();
|
||||
int sourcePort = udpHeader.getSrcPort().valueAsInt();
|
||||
int destPort = udpHeader.getDstPort().valueAsInt();
|
||||
byte[] content = packet.getPayload() != null ? packet.getPayload().getRawData() : new byte[0];
|
||||
|
||||
String sourceIpString = sourceIp.getHostAddress();
|
||||
String destIpString = destIp.getHostAddress();
|
||||
|
||||
final Optional<CtfService> serviceOptional =
|
||||
servicesService.findService(sourceIp, sourcePort, destIp, destPort);
|
||||
|
||||
if (serviceOptional.isPresent()) {
|
||||
processorExecutorService.execute(() -> {
|
||||
UnfinishedStream stream = addNewPacket(sourceIp, destIp, time, sourcePort, destPort, ttl, content, Protocol.UDP);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("UDP {} {}:{} -> {}:{}, номер пакета {}",
|
||||
serviceOptional.get(), sourceIpString, sourcePort, destIpString, destPort,
|
||||
unfinishedUdpStreams.get(stream).size());
|
||||
}
|
||||
});
|
||||
} else { // сервис не найден
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("udp {}:{} -> {}:{}", sourceIpString, sourcePort, destIpString, destPort);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private UnfinishedStream addNewPacket(InetAddress sourceIp, InetAddress destIp, long time,
|
||||
int sourcePort, int destPort, int ttl, byte[] content, Protocol protocol) {
|
||||
var incoming = destIp.equals(localIp);
|
||||
var stream = new UnfinishedStream(sourceIp, destIp, sourcePort, destPort, protocol);
|
||||
|
||||
var packet = ru.serega6531.packmate.model.Packet.builder()
|
||||
.tempId(packetIdCounter++)
|
||||
.ttl(ttl)
|
||||
.timestamp(time)
|
||||
.incoming(incoming)
|
||||
.content(content)
|
||||
.build();
|
||||
|
||||
final var streams = (protocol == Protocol.TCP) ? this.unfinishedTcpStreams : this.unfinishedUdpStreams;
|
||||
|
||||
if (!streams.containsKey(stream)) {
|
||||
log.debug("Начат новый поток");
|
||||
}
|
||||
|
||||
streams.put(stream, packet);
|
||||
return stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Udp не имеет фазы закрытия, поэтому закрывается только по таймауту
|
||||
*/
|
||||
private void checkTcpTermination(boolean ack, boolean fin, boolean rst,
|
||||
Pair<InetAddress, Integer> sourceIpAndPort,
|
||||
Pair<InetAddress, Integer> destIpAndPort,
|
||||
UnfinishedStream stream) {
|
||||
|
||||
if (fin) {
|
||||
fins.put(stream, sourceIpAndPort);
|
||||
}
|
||||
|
||||
if (ack && fins.containsEntry(stream, destIpAndPort)) { // проверяем destIp, потому что ищем ответ на его fin
|
||||
acks.put(stream, sourceIpAndPort);
|
||||
}
|
||||
|
||||
// если соединение разорвано с помощью rst или закрыто с помощью fin-ack-fin-ack
|
||||
if (rst || (acks.containsEntry(stream, sourceIpAndPort) && acks.containsEntry(stream, destIpAndPort))) {
|
||||
streamService.saveNewStream(stream, unfinishedTcpStreams.get(stream));
|
||||
|
||||
unfinishedTcpStreams.removeAll(stream);
|
||||
fins.removeAll(stream);
|
||||
acks.removeAll(stream);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void closeAllStreams(Protocol protocol) {
|
||||
final var streams = (protocol == Protocol.TCP) ? this.unfinishedTcpStreams : this.unfinishedUdpStreams;
|
||||
|
||||
Multimaps.asMap(streams).forEach((key, value) ->
|
||||
streamService.saveNewStream(key, new ArrayList<>(value)));
|
||||
|
||||
streams.clear();
|
||||
if (protocol == Protocol.TCP) {
|
||||
fins.clear();
|
||||
acks.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public int closeTimeoutStreams(Protocol protocol, long timeoutMillis) {
|
||||
return processorExecutorService.submit(() -> {
|
||||
int streamsClosed = 0;
|
||||
|
||||
final long time = System.currentTimeMillis();
|
||||
final var streams = (protocol == Protocol.TCP) ? this.unfinishedTcpStreams : this.unfinishedUdpStreams;
|
||||
|
||||
final var oldStreams = Multimaps.asMap(streams).entrySet().stream()
|
||||
.filter(entry -> {
|
||||
final var packets = entry.getValue();
|
||||
return time - packets.get(packets.size() - 1).getTimestamp() > timeoutMillis;
|
||||
})
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
|
||||
for (var entry : oldStreams.entrySet()) {
|
||||
final UnfinishedStream stream = entry.getKey();
|
||||
final var packets = entry.getValue();
|
||||
|
||||
if (streamService.saveNewStream(stream, packets)) {
|
||||
streamsClosed++;
|
||||
}
|
||||
|
||||
if (protocol == Protocol.TCP) {
|
||||
fins.removeAll(stream);
|
||||
acks.removeAll(stream);
|
||||
}
|
||||
|
||||
streams.removeAll(stream);
|
||||
}
|
||||
|
||||
return streamsClosed;
|
||||
}).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFilter(String filter) {
|
||||
this.filter = filter;
|
||||
applyFilter();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
protected void applyFilter() {
|
||||
if(filter != null && pcap != null && pcap.isOpen()) {
|
||||
pcap.setFilter(filter, BpfProgram.BpfCompileMode.OPTIMIZE);
|
||||
}
|
||||
}
|
||||
|
||||
protected void shutdownExecutor(ExecutorService executor, String executorName) {
|
||||
if (executor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
executor.shutdown();
|
||||
try {
|
||||
if (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
|
||||
log.warn("Поток обработки {} не завершился вовремя, отправляется сигнал остановки", executorName);
|
||||
executor.shutdownNow();
|
||||
if (!executor.awaitTermination(5, TimeUnit.SECONDS)) {
|
||||
log.error("Поток обработки {} не завершился после сигнала остановки", executorName);
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException exception) {
|
||||
executor.shutdownNow();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
package ru.serega6531.packmate.pcap;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.tomcat.util.threads.InlineExecutorService;
|
||||
import org.pcap4j.core.PcapNativeException;
|
||||
import org.pcap4j.core.PcapHandle;
|
||||
import org.pcap4j.core.NotOpenException;
|
||||
import org.pcap4j.core.Pcaps;
|
||||
import org.pcap4j.core.PcapPacket;
|
||||
import ru.serega6531.packmate.exception.PcapFileNotFoundException;
|
||||
import ru.serega6531.packmate.model.enums.Protocol;
|
||||
import ru.serega6531.packmate.service.ServicesService;
|
||||
import ru.serega6531.packmate.service.StreamService;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@Slf4j
|
||||
public class FilePcapWorker extends AbstractPcapWorker {
|
||||
|
||||
private final File directory;
|
||||
|
||||
private final File file;
|
||||
private final AtomicBoolean running = new AtomicBoolean();
|
||||
private volatile Runnable stoppedCallback = () -> {};
|
||||
private volatile CountDownLatch loopFinished = new CountDownLatch(0);
|
||||
private volatile CountDownLatch stopFinished = new CountDownLatch(0);
|
||||
|
||||
public FilePcapWorker(ServicesService servicesService,
|
||||
StreamService streamService,
|
||||
InetAddress localIp,
|
||||
String filename) throws UnknownHostException {
|
||||
super(servicesService, streamService, localIp);
|
||||
|
||||
File configuredFile = new File(filename);
|
||||
if (configuredFile.isAbsolute()) {
|
||||
file = configuredFile;
|
||||
directory = configuredFile.getParentFile();
|
||||
} else {
|
||||
directory = new File("pcaps");
|
||||
file = new File(directory, filename);
|
||||
}
|
||||
validateFileExists();
|
||||
|
||||
processorExecutorService = new InlineExecutorService();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void start(Runnable onStarted, Runnable onStopped) {
|
||||
log.info("Открывается файл захвата: {}", file.getAbsolutePath());
|
||||
PcapHandle capture = openCapture();
|
||||
pcap = capture;
|
||||
CountDownLatch startGate = new CountDownLatch(1);
|
||||
CountDownLatch currentLoopFinished = new CountDownLatch(1);
|
||||
CountDownLatch currentStopFinished = new CountDownLatch(1);
|
||||
loopFinished = currentLoopFinished;
|
||||
stopFinished = currentStopFinished;
|
||||
try {
|
||||
applyFilter();
|
||||
stoppedCallback = onStopped;
|
||||
running.set(true);
|
||||
loopExecutorService.execute(() -> runAfterStart(startGate, currentLoopFinished, capture));
|
||||
onStarted.run();
|
||||
startGate.countDown();
|
||||
} catch (Throwable exception) {
|
||||
running.set(false);
|
||||
startGate.countDown();
|
||||
currentLoopFinished.countDown();
|
||||
currentStopFinished.countDown();
|
||||
if (capture.isOpen()) {
|
||||
capture.close();
|
||||
}
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
protected PcapHandle openCapture() throws PcapNativeException {
|
||||
return Pcaps.openOffline(file.getAbsolutePath());
|
||||
}
|
||||
|
||||
private void runAfterStart(CountDownLatch startGate, CountDownLatch loopFinished, PcapHandle capture) {
|
||||
try {
|
||||
startGate.await();
|
||||
if (running.get() && pcap == capture) {
|
||||
runScan(capture, loopFinished);
|
||||
}
|
||||
} catch (InterruptedException exception) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.info("Обработка файла захвата прервана");
|
||||
} catch (RuntimeException exception) {
|
||||
log.error("Не удалось обработать файл захвата", exception);
|
||||
} finally {
|
||||
loopFinished.countDown();
|
||||
stop(capture);
|
||||
}
|
||||
}
|
||||
|
||||
private void runScan(PcapHandle capture, CountDownLatch loopFinished) {
|
||||
try {
|
||||
while (running.get() && pcap == capture && capture.isOpen()) {
|
||||
try {
|
||||
final PcapPacket packet = capture.getNextPacketEx();
|
||||
gotPacket(packet, capture);
|
||||
} catch (PcapNativeException | NotOpenException | TimeoutException exception) {
|
||||
log.error("Ошибка чтения файла захвата: {}", exception.getMessage());
|
||||
break;
|
||||
} catch (EOFException exception) {
|
||||
log.info("Чтение файла захвата завершено");
|
||||
break;
|
||||
} catch (RuntimeException exception) {
|
||||
log.error("Ошибка обработки пакета из файла захвата", exception);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
loopFinished.countDown();
|
||||
stop(capture);
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void stop() {
|
||||
stop(pcap);
|
||||
}
|
||||
|
||||
private void stop(PcapHandle capture) {
|
||||
if (capture == null || pcap != capture) {
|
||||
return;
|
||||
}
|
||||
CountDownLatch currentStopFinished = stopFinished;
|
||||
if (!running.compareAndSet(true, false)) {
|
||||
awaitLoopFinished(currentStopFinished);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (capture.isOpen()) {
|
||||
capture.close();
|
||||
log.info("Файл захвата закрыт");
|
||||
}
|
||||
} catch (RuntimeException exception) {
|
||||
log.warn("Не удалось закрыть файл захвата", exception);
|
||||
}
|
||||
|
||||
try {
|
||||
awaitLoopFinished(loopFinished);
|
||||
closeAllStreams(Protocol.TCP);
|
||||
closeAllStreams(Protocol.UDP);
|
||||
} finally {
|
||||
try {
|
||||
stoppedCallback.run();
|
||||
} finally {
|
||||
currentStopFinished.countDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void awaitLoopFinished(CountDownLatch currentLoopFinished) {
|
||||
boolean interrupted = false;
|
||||
while (true) {
|
||||
try {
|
||||
currentLoopFinished.await();
|
||||
break;
|
||||
} catch (InterruptedException exception) {
|
||||
interrupted = true;
|
||||
}
|
||||
}
|
||||
if (interrupted) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
stop();
|
||||
shutdownExecutor(loopExecutorService, "pcap-loop");
|
||||
shutdownExecutor(processorExecutorService, "pcap-inline");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExecutorState() {
|
||||
return "inline";
|
||||
}
|
||||
|
||||
private void validateFileExists() {
|
||||
if (!file.exists()) {
|
||||
throw new PcapFileNotFoundException(file, directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
package ru.serega6531.packmate.pcap;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
||||
import org.pcap4j.core.PcapNativeException;
|
||||
import org.pcap4j.core.PcapHandle;
|
||||
import org.pcap4j.core.PcapNetworkInterface;
|
||||
import org.pcap4j.core.Pcaps;
|
||||
import ru.serega6531.packmate.model.enums.Protocol;
|
||||
import ru.serega6531.packmate.exception.PcapInterfaceNotFoundException;
|
||||
import ru.serega6531.packmate.service.ServicesService;
|
||||
import ru.serega6531.packmate.service.StreamService;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@Slf4j
|
||||
public class LivePcapWorker extends AbstractPcapWorker {
|
||||
|
||||
private static final int PROCESSOR_QUEUE_CAPACITY = 1024;
|
||||
|
||||
private final PcapNetworkInterface device;
|
||||
private final AtomicBoolean running = new AtomicBoolean();
|
||||
private volatile Runnable stoppedCallback = () -> {};
|
||||
private volatile CountDownLatch loopFinished = new CountDownLatch(0);
|
||||
private volatile CountDownLatch stopFinished = new CountDownLatch(0);
|
||||
|
||||
public LivePcapWorker(ServicesService servicesService,
|
||||
StreamService streamService,
|
||||
InetAddress localIp,
|
||||
String interfaceName) throws PcapNativeException, UnknownHostException {
|
||||
super(servicesService, streamService, localIp);
|
||||
device = Pcaps.getDevByName(interfaceName);
|
||||
|
||||
if (device == null) {
|
||||
List<String> existingInterfaces = Pcaps.findAllDevs().stream().map(PcapNetworkInterface::getName).toList();
|
||||
throw new PcapInterfaceNotFoundException(interfaceName, existingInterfaces);
|
||||
}
|
||||
|
||||
BasicThreadFactory factory = new BasicThreadFactory.Builder()
|
||||
.namingPattern("pcap-processor").build();
|
||||
processorExecutorService = new ThreadPoolExecutor(
|
||||
1,
|
||||
1,
|
||||
0L,
|
||||
TimeUnit.MILLISECONDS,
|
||||
new ArrayBlockingQueue<>(PROCESSOR_QUEUE_CAPACITY),
|
||||
factory,
|
||||
new BlockingBackpressurePolicy()
|
||||
);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void start(Runnable onStarted, Runnable onStopped) throws PcapNativeException {
|
||||
log.info("Открывается сетевой интерфейс: {}", device.getName());
|
||||
var capture = device.openLive(65536, PcapNetworkInterface.PromiscuousMode.PROMISCUOUS, 100);
|
||||
pcap = capture;
|
||||
CountDownLatch startGate = new CountDownLatch(1);
|
||||
CountDownLatch currentLoopFinished = new CountDownLatch(1);
|
||||
CountDownLatch currentStopFinished = new CountDownLatch(1);
|
||||
loopFinished = currentLoopFinished;
|
||||
stopFinished = currentStopFinished;
|
||||
try {
|
||||
applyFilter();
|
||||
stoppedCallback = onStopped;
|
||||
running.set(true);
|
||||
loopExecutorService.execute(() -> runAfterStart(startGate, currentLoopFinished, capture));
|
||||
onStarted.run();
|
||||
startGate.countDown();
|
||||
} catch (Throwable exception) {
|
||||
running.set(false);
|
||||
startGate.countDown();
|
||||
currentLoopFinished.countDown();
|
||||
currentStopFinished.countDown();
|
||||
if (capture.isOpen()) {
|
||||
capture.close();
|
||||
}
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
private void runAfterStart(CountDownLatch startGate, CountDownLatch currentLoopFinished, PcapHandle capture) {
|
||||
try {
|
||||
startGate.await();
|
||||
if (!running.get() || pcap != capture) {
|
||||
return;
|
||||
}
|
||||
log.info("Перехват сетевого трафика запущен");
|
||||
capture.loop(-1, this);
|
||||
} catch (InterruptedException exception) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.info("Перехват сетевого трафика прерван");
|
||||
} catch (Exception exception) {
|
||||
log.error("Ошибка при перехвате сетевого пакета", exception);
|
||||
} finally {
|
||||
currentLoopFinished.countDown();
|
||||
stop(capture);
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void stop() {
|
||||
stop(pcap);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private void stop(PcapHandle capture) {
|
||||
if (capture == null || pcap != capture) {
|
||||
return;
|
||||
}
|
||||
CountDownLatch currentStopFinished = stopFinished;
|
||||
if (!running.compareAndSet(true, false)) {
|
||||
awaitLoopFinished(currentStopFinished);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (capture.isOpen()) {
|
||||
capture.breakLoop();
|
||||
capture.close();
|
||||
}
|
||||
} catch (RuntimeException exception) {
|
||||
log.warn("Не удалось сразу закрыть интерфейс захвата", exception);
|
||||
}
|
||||
|
||||
try {
|
||||
awaitLoopFinished(loopFinished);
|
||||
flushProcessorQueue();
|
||||
} catch (RuntimeException exception) {
|
||||
log.error("Не удалось завершить обработку очереди захвата", exception);
|
||||
} finally {
|
||||
try {
|
||||
log.info("Перехват сетевого трафика остановлен");
|
||||
stoppedCallback.run();
|
||||
} finally {
|
||||
currentStopFinished.countDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void awaitLoopFinished(CountDownLatch currentLoopFinished) {
|
||||
boolean interrupted = false;
|
||||
while (true) {
|
||||
try {
|
||||
currentLoopFinished.await();
|
||||
break;
|
||||
} catch (InterruptedException exception) {
|
||||
interrupted = true;
|
||||
}
|
||||
}
|
||||
if (interrupted) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
private void flushProcessorQueue() {
|
||||
flushAndWait(processorExecutorService, () -> {
|
||||
closeAllStreams(Protocol.TCP);
|
||||
closeAllStreams(Protocol.UDP);
|
||||
});
|
||||
}
|
||||
|
||||
static void flushAndWait(ExecutorService executor, Runnable flushTask) {
|
||||
try {
|
||||
executor.submit(flushTask).get();
|
||||
} catch (InterruptedException exception) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException("Ожидание завершения очереди захвата прервано", exception);
|
||||
} catch (ExecutionException exception) {
|
||||
throw new IllegalStateException("Ошибка при сохранении незавершенных потоков", exception.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
stop();
|
||||
shutdownExecutor(processorExecutorService, "pcap-processor");
|
||||
shutdownExecutor(loopExecutorService, "pcap-loop");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExecutorState() {
|
||||
return processorExecutorService.toString();
|
||||
}
|
||||
|
||||
static final class BlockingBackpressurePolicy implements RejectedExecutionHandler {
|
||||
@Override
|
||||
public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) {
|
||||
while (!executor.isShutdown()) {
|
||||
try {
|
||||
if (executor.getQueue().offer(task, 100, TimeUnit.MILLISECONDS)) {
|
||||
if (executor.isShutdown() && executor.getQueue().remove(task)) {
|
||||
throw new RejectedExecutionException("Очередь обработки захвата уже остановлена");
|
||||
}
|
||||
return;
|
||||
}
|
||||
} catch (InterruptedException exception) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new RejectedExecutionException("Ожидание свободного места в очереди захвата прервано", exception);
|
||||
}
|
||||
}
|
||||
throw new RejectedExecutionException("Очередь обработки захвата уже остановлена");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package ru.serega6531.packmate.pcap;
|
||||
|
||||
import ru.serega6531.packmate.model.enums.Protocol;
|
||||
|
||||
public class NoOpPcapWorker implements PcapWorker {
|
||||
@Override
|
||||
public void start(Runnable onStarted, Runnable onStopped) {
|
||||
onStarted.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllStreams(Protocol protocol) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int closeTimeoutStreams(Protocol protocol, long timeoutMillis) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFilter(String filter) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExecutorState() {
|
||||
return "none";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package ru.serega6531.packmate.pcap;
|
||||
|
||||
import org.pcap4j.core.PcapNativeException;
|
||||
import ru.serega6531.packmate.model.enums.Protocol;
|
||||
|
||||
public interface PcapWorker {
|
||||
|
||||
void start(Runnable onStarted, Runnable onStopped) throws PcapNativeException;
|
||||
void stop();
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* Выполняется в вызывающем потоке
|
||||
*/
|
||||
void closeAllStreams(Protocol protocol);
|
||||
|
||||
/**
|
||||
* Выполняется в потоке обработчика
|
||||
*/
|
||||
int closeTimeoutStreams(Protocol protocol, long timeoutMillis);
|
||||
|
||||
void setFilter(String filter);
|
||||
|
||||
String getExecutorState();
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package ru.serega6531.packmate.properties;
|
||||
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import ru.serega6531.packmate.model.enums.CaptureMode;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
@ConfigurationProperties("packmate")
|
||||
public record PackmateProperties(
|
||||
CaptureMode captureMode,
|
||||
String interfaceName,
|
||||
String pcapFile,
|
||||
InetAddress localIp,
|
||||
WebProperties web,
|
||||
TimeoutProperties timeout,
|
||||
CleanupProperties cleanup,
|
||||
boolean ignoreEmptyPackets
|
||||
) {
|
||||
|
||||
public record WebProperties(
|
||||
String accountLogin,
|
||||
String accountPassword
|
||||
) {}
|
||||
|
||||
public record TimeoutProperties(
|
||||
int udpStreamTimeout,
|
||||
int tcpStreamTimeout,
|
||||
int checkInterval
|
||||
){}
|
||||
|
||||
public record CleanupProperties(
|
||||
boolean enabled,
|
||||
int threshold,
|
||||
int interval
|
||||
){}
|
||||
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package ru.serega6531.packmate.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.serega6531.packmate.model.Pattern;
|
||||
|
||||
public interface PatternRepository extends JpaRepository<Pattern, Integer> {
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package ru.serega6531.packmate.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.serega6531.packmate.model.CtfService;
|
||||
|
||||
public interface ServiceRepository extends JpaRepository<CtfService, Integer> {
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package ru.serega6531.packmate.repository;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import ru.serega6531.packmate.model.Packet;
|
||||
import ru.serega6531.packmate.model.Stream;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface StreamRepository extends JpaRepository<Stream, Long>, JpaSpecificationExecutor<Stream> {
|
||||
|
||||
@Query("UPDATE Stream SET favorite = :favorite WHERE id = :id")
|
||||
@Modifying
|
||||
void setFavorite(long id, boolean favorite);
|
||||
|
||||
long deleteByEndTimestampBeforeAndFavoriteIsFalse(long threshold);
|
||||
|
||||
@Query("SELECT p FROM Packet p " +
|
||||
"LEFT JOIN FETCH p.matches " +
|
||||
"WHERE p.stream.id = :streamId " +
|
||||
"AND (:startingFrom IS NULL OR p.id > :startingFrom) " +
|
||||
"ORDER BY p.id"
|
||||
)
|
||||
List<Packet> getPackets(long streamId, Long startingFrom, Pageable pageable);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package ru.serega6531.packmate.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
||||
import ru.serega6531.packmate.model.pojo.Counter;
|
||||
import ru.serega6531.packmate.model.pojo.CountersHolder;
|
||||
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class CountingService {
|
||||
|
||||
private final SubscriptionService subscriptionService;
|
||||
|
||||
private final Map<Integer, Counter> servicesPackets = new HashMap<>();
|
||||
private final Map<Integer, Counter> servicesStreams = new HashMap<>();
|
||||
|
||||
private Counter totalPackets = new Counter();
|
||||
private Counter totalStreams = new Counter();
|
||||
|
||||
@Autowired
|
||||
public CountingService(SubscriptionService subscriptionService) {
|
||||
this.subscriptionService = subscriptionService;
|
||||
}
|
||||
|
||||
synchronized void countStream(int serviceId, int packets) {
|
||||
getCounter(servicesPackets, serviceId).increment(packets);
|
||||
getCounter(servicesStreams, serviceId).increment();
|
||||
|
||||
totalPackets.increment(packets);
|
||||
totalStreams.increment();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 * * ? * *")
|
||||
public void sendCounters() {
|
||||
CountersHolder counters;
|
||||
synchronized (this) {
|
||||
counters = new CountersHolder(toIntegerMap(servicesPackets), toIntegerMap(servicesStreams),
|
||||
totalPackets.getValue(), totalStreams.getValue());
|
||||
servicesPackets.clear();
|
||||
servicesStreams.clear();
|
||||
totalPackets = new Counter();
|
||||
totalStreams = new Counter();
|
||||
}
|
||||
subscriptionService.broadcast(new SubscriptionMessage(SubscriptionMessageType.COUNTERS_UPDATE, counters));
|
||||
}
|
||||
|
||||
private Map<Integer, Integer> toIntegerMap(Map<Integer, Counter> map) {
|
||||
return map.entrySet().stream()
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
ent -> ent.getValue().getValue()));
|
||||
}
|
||||
|
||||
private Counter getCounter(Map<Integer, Counter> counters, int serviceId) {
|
||||
return counters.computeIfAbsent(serviceId, c -> new Counter());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package ru.serega6531.packmate.service;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import org.springframework.security.crypto.codec.Hex;
|
||||
import ru.serega6531.packmate.model.FoundPattern;
|
||||
import ru.serega6531.packmate.model.Pattern;
|
||||
import ru.serega6531.packmate.utils.KMPByteSearcher;
|
||||
import ru.serega6531.packmate.utils.KMPStringSearcher;
|
||||
import com.google.re2j.Matcher;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class PatternMatcher {
|
||||
|
||||
private static final Cache<String, com.google.re2j.Pattern> compiledRegexes = CacheBuilder.newBuilder()
|
||||
.maximumSize(256)
|
||||
.build();
|
||||
|
||||
private final byte[] contentBytes;
|
||||
private final String content;
|
||||
private final List<Pattern> patterns;
|
||||
|
||||
private final Set<FoundPattern> result = new HashSet<>();
|
||||
|
||||
public PatternMatcher(byte[] contentBytes, List<Pattern> patterns) {
|
||||
this.contentBytes = contentBytes;
|
||||
this.content = new String(contentBytes);
|
||||
this.patterns = patterns;
|
||||
}
|
||||
|
||||
public Set<FoundPattern> findMatches() {
|
||||
patterns.forEach(this::match);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void match(Pattern pattern) {
|
||||
switch (pattern.getSearchType()) {
|
||||
case REGEX -> matchRegex(pattern);
|
||||
case SUBSTRING -> matchSubstring(pattern);
|
||||
case SUBBYTES -> matchSubbytes(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
private void matchRegex(Pattern pattern) {
|
||||
final var regex = compileRegex(pattern.getValue());
|
||||
final Matcher matcher = regex.matcher(content);
|
||||
|
||||
while (matcher.find()) {
|
||||
if (matcher.start() == matcher.end()) {
|
||||
continue;
|
||||
}
|
||||
addIfPossible(FoundPattern.builder()
|
||||
.patternId(pattern.getId())
|
||||
.startPosition(matcher.start())
|
||||
.endPosition(matcher.end() - 1)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
private void matchSubstring(Pattern pattern) {
|
||||
final String value = pattern.getValue();
|
||||
if (value.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
KMPStringSearcher searcher = new KMPStringSearcher(value.toCharArray());
|
||||
StringReader reader = new StringReader(content);
|
||||
|
||||
while (true) {
|
||||
int end = searcher.search(reader) - 1;
|
||||
|
||||
if (end < 0) {
|
||||
searcher.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
int start = end - value.length() + 1;
|
||||
addIfPossible(FoundPattern.builder()
|
||||
.patternId(pattern.getId())
|
||||
.startPosition(start)
|
||||
.endPosition(end)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private void matchSubbytes(Pattern pattern) {
|
||||
final byte[] value = Hex.decode(pattern.getValue());
|
||||
if (value.length == 0) {
|
||||
return;
|
||||
}
|
||||
KMPByteSearcher searcher = new KMPByteSearcher(value);
|
||||
InputStream is = new ByteArrayInputStream(contentBytes);
|
||||
|
||||
while (true) {
|
||||
int end = searcher.search(is) - 1;
|
||||
|
||||
if (end < 0) {
|
||||
searcher.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
int start = end - value.length + 1;
|
||||
addIfPossible(FoundPattern.builder()
|
||||
.patternId(pattern.getId())
|
||||
.startPosition(start)
|
||||
.endPosition(end)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
private void addIfPossible(FoundPattern found) {
|
||||
if (result.stream().noneMatch(match ->
|
||||
between(match.getStartPosition(), match.getEndPosition(), found.getStartPosition()) ||
|
||||
between(match.getStartPosition(), match.getEndPosition(), found.getEndPosition()))) {
|
||||
result.add(found);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean between(int a, int b, int x) {
|
||||
return a <= x && x <= b;
|
||||
}
|
||||
|
||||
static void compilePattern(Pattern pattern) {
|
||||
switch (pattern.getSearchType()) {
|
||||
case REGEX -> compileRegex(pattern.getValue());
|
||||
case SUBSTRING -> {
|
||||
if (pattern.getValue().isEmpty()) {
|
||||
throw new IllegalArgumentException("Текстовый шаблон не может быть пустым.");
|
||||
}
|
||||
}
|
||||
case SUBBYTES -> {
|
||||
if (Hex.decode(pattern.getValue()).length == 0) {
|
||||
throw new IllegalArgumentException("Байтовый шаблон не может быть пустым.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static com.google.re2j.Pattern compileRegex(String expression) {
|
||||
try {
|
||||
return compiledRegexes.get(expression, () -> com.google.re2j.Pattern.compile(expression));
|
||||
} catch (ExecutionException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof RuntimeException runtimeException) {
|
||||
throw runtimeException;
|
||||
}
|
||||
throw new IllegalArgumentException("Некорректное регулярное выражение.", cause);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
package ru.serega6531.packmate.service;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.serega6531.packmate.model.CtfService;
|
||||
import ru.serega6531.packmate.model.FoundPattern;
|
||||
import ru.serega6531.packmate.model.Pattern;
|
||||
import ru.serega6531.packmate.model.enums.PatternActionType;
|
||||
import ru.serega6531.packmate.model.enums.PatternDirectionType;
|
||||
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
||||
import ru.serega6531.packmate.model.pojo.PatternCreateDto;
|
||||
import ru.serega6531.packmate.model.pojo.PatternDto;
|
||||
import ru.serega6531.packmate.model.pojo.PatternUpdateDto;
|
||||
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
||||
import ru.serega6531.packmate.repository.PatternRepository;
|
||||
import ru.serega6531.packmate.exception.PatternValidationException;
|
||||
import ru.serega6531.packmate.exception.RequestValidationException;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PatternService {
|
||||
|
||||
private final PatternRepository repository;
|
||||
private final StreamService streamService;
|
||||
private final SubscriptionService subscriptionService;
|
||||
|
||||
private final Map<Integer, Pattern> patterns = new ConcurrentHashMap<>();
|
||||
|
||||
@Autowired
|
||||
public PatternService(PatternRepository repository,
|
||||
@Lazy StreamService streamService,
|
||||
SubscriptionService subscriptionService) {
|
||||
this.repository = repository;
|
||||
this.streamService = streamService;
|
||||
this.subscriptionService = subscriptionService;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
repository.findAll().forEach(p -> patterns.put(p.getId(), p));
|
||||
log.info("Загружено паттернов: {}", patterns.size());
|
||||
}
|
||||
|
||||
public Pattern find(int id) {
|
||||
return patterns.get(id);
|
||||
}
|
||||
|
||||
public Collection<Pattern> findAll() {
|
||||
return patterns.values();
|
||||
}
|
||||
|
||||
public Set<FoundPattern> findMatches(byte[] bytes, CtfService service, PatternDirectionType directionType, PatternActionType actionType) {
|
||||
final List<Pattern> list = patterns.values().stream()
|
||||
.filter(pattern -> pattern.isEnabled() && !pattern.isDeleted())
|
||||
.filter(p -> p.getServiceId() == null || p.getServiceId().equals(service.getPort()))
|
||||
.filter(p -> p.getActionType() == actionType)
|
||||
.filter(p -> p.getDirectionType() == directionType || p.getDirectionType() == PatternDirectionType.BOTH)
|
||||
.toList();
|
||||
return new PatternMatcher(bytes, list).findMatches();
|
||||
}
|
||||
|
||||
public Set<FoundPattern> matchOne(byte[] bytes, Pattern pattern) {
|
||||
return new PatternMatcher(bytes, List.of(pattern)).findMatches();
|
||||
}
|
||||
|
||||
public void enable(int id, boolean enabled) {
|
||||
RequestValidation.requireIdentifier(id, "Идентификатор паттерна");
|
||||
final Pattern pattern = find(id);
|
||||
if (pattern != null) {
|
||||
pattern.setEnabled(enabled);
|
||||
final Pattern saved = repository.save(pattern);
|
||||
patterns.put(id, saved);
|
||||
|
||||
if (enabled) {
|
||||
log.info("Паттерн включен: id={}", id);
|
||||
subscriptionService.broadcast(new SubscriptionMessage(SubscriptionMessageType.ENABLE_PATTERN, id));
|
||||
} else {
|
||||
log.info("Паттерн приостановлен: id={}", id);
|
||||
subscriptionService.broadcast(new SubscriptionMessage(SubscriptionMessageType.DISABLE_PATTERN, id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(int id) {
|
||||
RequestValidation.requireIdentifier(id, "Идентификатор паттерна");
|
||||
final Pattern pattern = find(id);
|
||||
if (pattern != null) {
|
||||
pattern.setDeleted(true);
|
||||
final Pattern saved = repository.save(pattern);
|
||||
patterns.put(id, saved);
|
||||
|
||||
log.info("Паттерн удален: id={}", id);
|
||||
subscriptionService.broadcast(new SubscriptionMessage(SubscriptionMessageType.SAVE_PATTERN, toDto(saved)));
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public PatternDto create(PatternCreateDto dto) {
|
||||
validateCreate(dto);
|
||||
Pattern pattern = fromDto(dto);
|
||||
|
||||
pattern.setEnabled(true);
|
||||
pattern.setDeleted(false);
|
||||
pattern.setSearchStartTimestamp(System.currentTimeMillis());
|
||||
|
||||
Pattern saved = save(pattern);
|
||||
return toDto(saved);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public PatternDto update(int id, PatternUpdateDto dto) {
|
||||
RequestValidation.requireIdentifier(id, "Идентификатор паттерна");
|
||||
if (dto == null) {
|
||||
throw new RequestValidationException("Не переданы параметры паттерна.");
|
||||
}
|
||||
RequestValidation.requireName(dto.getName(), "Название паттерна");
|
||||
RequestValidation.requirePatternColor(dto.getColor());
|
||||
Pattern pattern = repository.findById(id).orElseThrow();
|
||||
|
||||
pattern.setName(dto.getName());
|
||||
pattern.setColor(dto.getColor());
|
||||
|
||||
Pattern saved = save(pattern);
|
||||
return toDto(saved);
|
||||
}
|
||||
|
||||
private Pattern save(Pattern pattern) {
|
||||
try {
|
||||
PatternMatcher.compilePattern(pattern);
|
||||
} catch (IllegalArgumentException e) {
|
||||
String message = pattern.getSearchType() == ru.serega6531.packmate.model.enums.PatternSearchType.REGEX
|
||||
? "Некорректный шаблон регулярного выражения. Используется RE2/J; lookaround и обратные ссылки не поддерживаются."
|
||||
: "Некорректное значение шаблона. Проверьте текст или шестнадцатеричную запись байтов.";
|
||||
throw new PatternValidationException(message, e);
|
||||
}
|
||||
|
||||
final Pattern saved = repository.save(pattern);
|
||||
patterns.put(saved.getId(), saved);
|
||||
|
||||
log.info("Создан паттерн id={}", saved.getId());
|
||||
subscriptionService.broadcast(new SubscriptionMessage(SubscriptionMessageType.SAVE_PATTERN, toDto(saved)));
|
||||
|
||||
return saved;
|
||||
}
|
||||
|
||||
public void lookBack(int id, int minutes) {
|
||||
RequestValidation.requireIdentifier(id, "Идентификатор паттерна");
|
||||
RequestValidation.requireLookback(minutes);
|
||||
final Pattern pattern = find(id);
|
||||
if (pattern != null && pattern.getActionType() == PatternActionType.FIND) {
|
||||
long end = pattern.getSearchStartTimestamp();
|
||||
long start = end - TimeUnit.MINUTES.toMillis(minutes);
|
||||
|
||||
pattern.setSearchStartTimestamp(start);
|
||||
repository.save(pattern);
|
||||
|
||||
log.info("Поиск по паттерну id={} с {} по {}", id,
|
||||
Instant.ofEpochMilli(start), Instant.ofEpochMilli(end));
|
||||
streamService.processLookbackPattern(pattern, start, end);
|
||||
}
|
||||
}
|
||||
|
||||
public Pattern fromDto(PatternCreateDto dto) {
|
||||
Pattern pattern = new Pattern();
|
||||
pattern.setName(dto.getName());
|
||||
pattern.setValue(dto.getValue());
|
||||
pattern.setColor(dto.getColor());
|
||||
pattern.setSearchType(dto.getSearchType());
|
||||
pattern.setDirectionType(dto.getDirectionType());
|
||||
pattern.setActionType(dto.getActionType());
|
||||
pattern.setServiceId(dto.getServiceId());
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public PatternDto toDto(Pattern pattern) {
|
||||
PatternDto dto = new PatternDto();
|
||||
dto.setId(pattern.getId());
|
||||
dto.setEnabled(pattern.isEnabled());
|
||||
dto.setDeleted(pattern.isDeleted());
|
||||
dto.setName(pattern.getName());
|
||||
dto.setValue(pattern.getValue());
|
||||
dto.setColor(pattern.getColor());
|
||||
dto.setSearchType(pattern.getSearchType());
|
||||
dto.setDirectionType(pattern.getDirectionType());
|
||||
dto.setActionType(pattern.getActionType());
|
||||
dto.setServiceId(pattern.getServiceId());
|
||||
return dto;
|
||||
}
|
||||
|
||||
private void validateCreate(PatternCreateDto dto) {
|
||||
if (dto == null) {
|
||||
throw new RequestValidationException("Не переданы параметры паттерна.");
|
||||
}
|
||||
RequestValidation.requireName(dto.getName(), "Название паттерна");
|
||||
RequestValidation.requirePatternValue(dto.getValue());
|
||||
RequestValidation.requirePatternColor(dto.getColor());
|
||||
if (dto.getSearchType() == null || dto.getDirectionType() == null || dto.getActionType() == null) {
|
||||
throw new RequestValidationException("Нужно указать способ поиска, направление и действие паттерна.");
|
||||
}
|
||||
if (dto.getServiceId() != null) {
|
||||
RequestValidation.requirePort(dto.getServiceId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package ru.serega6531.packmate.service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.pcap4j.core.PcapNativeException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
||||
import ru.serega6531.packmate.model.pojo.ServiceDto;
|
||||
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
||||
import ru.serega6531.packmate.pcap.NoOpPcapWorker;
|
||||
import ru.serega6531.packmate.pcap.PcapWorker;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PcapService {
|
||||
|
||||
private volatile boolean started = false;
|
||||
|
||||
private final SubscriptionService subscriptionService;
|
||||
private final PcapWorker worker;
|
||||
|
||||
@Autowired
|
||||
public PcapService(SubscriptionService subscriptionService, PcapWorker worker) {
|
||||
this.subscriptionService = subscriptionService;
|
||||
this.worker = worker;
|
||||
}
|
||||
|
||||
public boolean isStarted() {
|
||||
return started || worker instanceof NoOpPcapWorker;
|
||||
}
|
||||
|
||||
public synchronized void start() throws PcapNativeException {
|
||||
if (!started) {
|
||||
worker.start(this::markStarted, this::markStopped);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void markStarted() {
|
||||
started = true;
|
||||
subscriptionService.broadcast(new SubscriptionMessage(SubscriptionMessageType.PCAP_STARTED, null));
|
||||
}
|
||||
|
||||
private synchronized void markStopped() {
|
||||
if (started) {
|
||||
started = false;
|
||||
subscriptionService.broadcast(new SubscriptionMessage(SubscriptionMessageType.PCAP_STOPPED, null));
|
||||
}
|
||||
}
|
||||
|
||||
public void updateFilter(Collection<ServiceDto> services) {
|
||||
String filter;
|
||||
|
||||
if (services.isEmpty()) {
|
||||
filter = "tcp or udp";
|
||||
} else {
|
||||
final String ports = services.stream()
|
||||
.map(ServiceDto::getPort)
|
||||
.map(p -> "port " + p)
|
||||
.collect(Collectors.joining(" or "));
|
||||
|
||||
final String format = "(tcp or udp) and (%s)";
|
||||
filter = String.format(format, ports);
|
||||
}
|
||||
|
||||
log.debug("Новый фильтр: {}", filter);
|
||||
|
||||
worker.setFilter(filter);
|
||||
}
|
||||
|
||||
public String getExecutorState() {
|
||||
return worker.getExecutorState();
|
||||
}
|
||||
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package ru.serega6531.packmate.service;
|
||||
|
||||
import ru.serega6531.packmate.exception.RequestValidationException;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class RequestValidation {
|
||||
|
||||
private static final int MAX_PAGE_SIZE = 500;
|
||||
private static final int MAX_NAME_LENGTH = 100;
|
||||
private static final int MAX_PATTERN_LENGTH = 4096;
|
||||
private static final int MAX_LOOKBACK_MINUTES = 10_080;
|
||||
private static final Pattern COLOR = Pattern.compile(
|
||||
"(?i)^(#[0-9a-f]{3}(?:[0-9a-f]{3})?|red|green|blue|orange|purple|teal|yellow|white|black|gray|grey)$"
|
||||
);
|
||||
|
||||
private RequestValidation() {}
|
||||
|
||||
public static void requirePort(int port) {
|
||||
if (port < 1 || port > 65_535) {
|
||||
throw new RequestValidationException("Порт должен быть в диапазоне от 1 до 65535.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void requireIdentifier(long identifier, String label) {
|
||||
if (identifier < 1) {
|
||||
throw new RequestValidationException(label + " должен быть положительным числом.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void requireName(String value, String label) {
|
||||
if (value == null || value.isBlank() || value.length() > MAX_NAME_LENGTH) {
|
||||
throw new RequestValidationException(label + " должен содержать от 1 до 100 символов.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void requirePatternValue(String value) {
|
||||
if (value == null || value.isBlank() || value.length() > MAX_PATTERN_LENGTH) {
|
||||
throw new RequestValidationException("Значение паттерна должно содержать от 1 до 4096 символов.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void requirePatternColor(String value) {
|
||||
if (value == null || !COLOR.matcher(value).matches()) {
|
||||
throw new RequestValidationException("Цвет паттерна задан в неподдерживаемом формате.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void requirePage(Long startingFrom, int pageSize) {
|
||||
if (startingFrom != null && startingFrom < 1) {
|
||||
throw new RequestValidationException("Идентификатор начала страницы должен быть положительным.");
|
||||
}
|
||||
if (pageSize < 1 || pageSize > MAX_PAGE_SIZE) {
|
||||
throw new RequestValidationException("Размер страницы должен быть в диапазоне от 1 до 500.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void requireLookback(int minutes) {
|
||||
if (minutes < 1 || minutes > MAX_LOOKBACK_MINUTES) {
|
||||
throw new RequestValidationException("Период поиска должен быть от 1 до 10080 минут.");
|
||||
}
|
||||
}
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
package ru.serega6531.packmate.service;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.serega6531.packmate.properties.PackmateProperties;
|
||||
import ru.serega6531.packmate.model.CtfService;
|
||||
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
||||
import ru.serega6531.packmate.model.pojo.ServiceCreateDto;
|
||||
import ru.serega6531.packmate.model.pojo.ServiceDto;
|
||||
import ru.serega6531.packmate.model.pojo.ServiceUpdateDto;
|
||||
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
||||
import ru.serega6531.packmate.repository.ServiceRepository;
|
||||
import ru.serega6531.packmate.exception.RequestValidationException;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ServicesService {
|
||||
|
||||
private final ServiceRepository repository;
|
||||
private final SubscriptionService subscriptionService;
|
||||
private final PcapService pcapService;
|
||||
|
||||
private final InetAddress localIp;
|
||||
|
||||
private final Map<Integer, CtfService> services = new ConcurrentHashMap<>();
|
||||
private final ModelMapper modelMapper;
|
||||
|
||||
@Autowired
|
||||
public ServicesService(ServiceRepository repository,
|
||||
SubscriptionService subscriptionService,
|
||||
@Lazy PcapService pcapService,
|
||||
ModelMapper modelMapper,
|
||||
PackmateProperties properties) {
|
||||
this.repository = repository;
|
||||
this.subscriptionService = subscriptionService;
|
||||
this.pcapService = pcapService;
|
||||
this.modelMapper = modelMapper;
|
||||
this.localIp = properties.localIp();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
repository.findAll().forEach(s -> services.put(s.getPort(), s));
|
||||
log.info("Загружено служб: {}", services.size());
|
||||
}
|
||||
|
||||
public CtfService find(int id) {
|
||||
return services.get(id);
|
||||
}
|
||||
|
||||
public Optional<CtfService> findService(InetAddress firstIp, int firstPort, InetAddress secondIp, int secondPort) {
|
||||
if (firstIp.equals(localIp)) {
|
||||
return findByPort(firstPort);
|
||||
} else if (secondIp.equals(localIp)) {
|
||||
return findByPort(secondPort);
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private Optional<CtfService> findByPort(int port) {
|
||||
return Optional.ofNullable(services.get(port));
|
||||
}
|
||||
|
||||
public List<ServiceDto> findAll() {
|
||||
return services.values()
|
||||
.stream()
|
||||
.map(this::toDto)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public void deleteByPort(int port) {
|
||||
RequestValidation.requirePort(port);
|
||||
log.info("Удалена служба на порту {}", port);
|
||||
|
||||
services.remove(port);
|
||||
repository.deleteById(port);
|
||||
|
||||
subscriptionService.broadcast(new SubscriptionMessage(SubscriptionMessageType.DELETE_SERVICE, port));
|
||||
|
||||
updateFilter();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ServiceDto create(ServiceCreateDto dto) {
|
||||
if (dto == null) {
|
||||
throw new RequestValidationException("Не переданы параметры службы.");
|
||||
}
|
||||
RequestValidation.requirePort(dto.getPort());
|
||||
RequestValidation.requireName(dto.getName(), "Название службы");
|
||||
if (repository.existsById(dto.getPort())) {
|
||||
throw new RequestValidationException("Служба с таким портом уже существует.");
|
||||
}
|
||||
|
||||
CtfService service = fromDto(dto);
|
||||
|
||||
log.info("Добавлена служба на порту {}", service.getPort());
|
||||
|
||||
return save(service);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ServiceDto update(int port, ServiceUpdateDto dto) {
|
||||
RequestValidation.requirePort(port);
|
||||
if (dto == null) {
|
||||
throw new RequestValidationException("Не переданы параметры службы.");
|
||||
}
|
||||
RequestValidation.requireName(dto.getName(), "Название службы");
|
||||
CtfService service = repository.findById(port).orElseThrow();
|
||||
|
||||
log.info("Изменена служба на порту {}", service.getPort());
|
||||
|
||||
modelMapper.map(dto, service);
|
||||
service.setPort(port);
|
||||
return save(service);
|
||||
}
|
||||
|
||||
private ServiceDto save(CtfService service) {
|
||||
final CtfService saved = repository.save(service);
|
||||
services.put(saved.getPort(), saved);
|
||||
|
||||
subscriptionService.broadcast(new SubscriptionMessage(SubscriptionMessageType.SAVE_SERVICE, toDto(saved)));
|
||||
|
||||
updateFilter();
|
||||
|
||||
return toDto(saved);
|
||||
}
|
||||
|
||||
public void updateFilter() {
|
||||
pcapService.updateFilter(findAll());
|
||||
}
|
||||
|
||||
private ServiceDto toDto(CtfService service) {
|
||||
return modelMapper.map(service, ServiceDto.class);
|
||||
}
|
||||
|
||||
private CtfService fromDto(ServiceCreateDto dto) {
|
||||
return modelMapper.map(dto, CtfService.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
package ru.serega6531.packmate.service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.serega6531.packmate.properties.PackmateProperties;
|
||||
import ru.serega6531.packmate.model.CtfService;
|
||||
import ru.serega6531.packmate.model.FoundPattern;
|
||||
import ru.serega6531.packmate.model.Packet;
|
||||
import ru.serega6531.packmate.model.Pattern;
|
||||
import ru.serega6531.packmate.model.Stream;
|
||||
import ru.serega6531.packmate.model.enums.PatternActionType;
|
||||
import ru.serega6531.packmate.model.enums.PatternDirectionType;
|
||||
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
||||
import ru.serega6531.packmate.model.pojo.PacketDto;
|
||||
import ru.serega6531.packmate.model.pojo.StreamDto;
|
||||
import ru.serega6531.packmate.model.pojo.StreamPagination;
|
||||
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
||||
import ru.serega6531.packmate.model.pojo.UnfinishedStream;
|
||||
import ru.serega6531.packmate.exception.RequestValidationException;
|
||||
import ru.serega6531.packmate.repository.StreamRepository;
|
||||
import ru.serega6531.packmate.service.optimization.RsaKeysHolder;
|
||||
import ru.serega6531.packmate.service.optimization.StreamOptimizer;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class StreamService {
|
||||
|
||||
private final StreamRepository repository;
|
||||
private final PatternService patternService;
|
||||
private final ServicesService servicesService;
|
||||
private final CountingService countingService;
|
||||
private final SubscriptionService subscriptionService;
|
||||
private final RsaKeysHolder keysHolder;
|
||||
private final ModelMapper modelMapper;
|
||||
private final boolean ignoreEmptyPackets;
|
||||
|
||||
private final java.util.regex.Pattern userAgentPattern = java.util.regex.Pattern.compile("User-Agent: (.+)\\r\\n");
|
||||
|
||||
@Autowired
|
||||
public StreamService(StreamRepository repository,
|
||||
PatternService patternService,
|
||||
ServicesService servicesService,
|
||||
CountingService countingService,
|
||||
SubscriptionService subscriptionService,
|
||||
RsaKeysHolder keysHolder,
|
||||
ModelMapper modelMapper,
|
||||
PackmateProperties properties) {
|
||||
this.repository = repository;
|
||||
this.patternService = patternService;
|
||||
this.servicesService = servicesService;
|
||||
this.countingService = countingService;
|
||||
this.subscriptionService = subscriptionService;
|
||||
this.keysHolder = keysHolder;
|
||||
this.modelMapper = modelMapper;
|
||||
this.ignoreEmptyPackets = properties.ignoreEmptyPackets();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true, если поток сохранен
|
||||
*/
|
||||
@Transactional(propagation = Propagation.NEVER)
|
||||
public boolean saveNewStream(UnfinishedStream unfinishedStream, List<Packet> packets) {
|
||||
final var serviceOptional = servicesService.findService(
|
||||
unfinishedStream.firstIp(),
|
||||
unfinishedStream.firstPort(),
|
||||
unfinishedStream.secondIp(),
|
||||
unfinishedStream.secondPort()
|
||||
);
|
||||
|
||||
if (serviceOptional.isEmpty()) {
|
||||
log.warn("Не удалось сохранить поток: служба на порту {} или {} не существует",
|
||||
unfinishedStream.firstPort(), unfinishedStream.secondPort());
|
||||
return false;
|
||||
}
|
||||
CtfService service = serviceOptional.get();
|
||||
|
||||
if (ignoreEmptyPackets) {
|
||||
packets.removeIf(packet -> packet.getContent().length == 0);
|
||||
|
||||
if (packets.isEmpty()) {
|
||||
log.debug("Поток содержит только пустые пакеты и не будет сохранен");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
countingService.countStream(service.getPort(), packets.size());
|
||||
|
||||
int packetsSize = packets.stream().mapToInt(p -> p.getContent().length).sum();
|
||||
int packetsCount = packets.size();
|
||||
|
||||
List<Packet> optimizedPackets = new StreamOptimizer(keysHolder, service, packets).optimizeStream();
|
||||
|
||||
if (isStreamIgnored(optimizedPackets, service)) {
|
||||
log.debug("Новый поток пропущен");
|
||||
return false;
|
||||
}
|
||||
|
||||
Optional<Packet> firstIncoming = packets.stream()
|
||||
.filter(Packet::isIncoming)
|
||||
.findFirst();
|
||||
|
||||
final Stream stream = new Stream();
|
||||
stream.setProtocol(unfinishedStream.protocol());
|
||||
stream.setTtl(firstIncoming.map(Packet::getTtl).orElse(0));
|
||||
stream.setStartTimestamp(packets.get(0).getTimestamp());
|
||||
stream.setEndTimestamp(packets.get(packets.size() - 1).getTimestamp());
|
||||
stream.setService(service.getPort());
|
||||
|
||||
String userAgentHash = getUserAgentHash(optimizedPackets);
|
||||
stream.setUserAgentHash(userAgentHash);
|
||||
|
||||
stream.setSizeBytes(packetsSize);
|
||||
stream.setPacketsCount(packetsCount);
|
||||
|
||||
Set<Pattern> foundPatterns = matchPatterns(optimizedPackets, service);
|
||||
stream.setFoundPatterns(foundPatterns);
|
||||
stream.setPackets(optimizedPackets);
|
||||
|
||||
for (Packet packet : optimizedPackets) {
|
||||
packet.setStream(stream);
|
||||
}
|
||||
|
||||
Stream savedStream = save(stream);
|
||||
|
||||
subscriptionService.broadcast(new SubscriptionMessage(SubscriptionMessageType.NEW_STREAM, streamToDto(savedStream)));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Async
|
||||
@Transactional
|
||||
public void processLookbackPattern(Pattern pattern, long start, long end) {
|
||||
List<Stream> streams = findAllBetweenTimestamps(start, end);
|
||||
|
||||
for (Stream stream : streams) {
|
||||
boolean found = matchPattern(stream.getPackets(), pattern);
|
||||
if (found) {
|
||||
stream.getFoundPatterns().add(pattern);
|
||||
repository.save(stream);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Завершен поиск по паттерну '{}'", pattern.getName());
|
||||
subscriptionService.broadcast(new SubscriptionMessage(SubscriptionMessageType.FINISH_LOOKBACK, pattern.getId()));
|
||||
}
|
||||
|
||||
private String getUserAgentHash(List<Packet> packets) {
|
||||
String ua = null;
|
||||
for (Packet packet : packets) {
|
||||
String content = packet.getContentString();
|
||||
final Matcher matcher = userAgentPattern.matcher(content);
|
||||
if (matcher.find()) {
|
||||
ua = matcher.group(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ua != null) {
|
||||
return calculateUserAgentHash(ua);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String calculateUserAgentHash(String ua) {
|
||||
char[] alphabet = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray();
|
||||
int l = alphabet.length;
|
||||
int hashCode = ua.hashCode();
|
||||
if (hashCode == Integer.MIN_VALUE) { // abs(MIN_VALUE) вернет то же значение
|
||||
hashCode = Integer.MAX_VALUE;
|
||||
}
|
||||
final int hash = Math.abs(hashCode) % (l * l * l);
|
||||
return "" + alphabet[hash % l] + alphabet[(hash / l) % l] + alphabet[(hash / (l * l)) % l];
|
||||
}
|
||||
|
||||
private Set<Pattern> matchPatterns(List<Packet> packets, CtfService service) {
|
||||
Set<Pattern> foundPatterns = new HashSet<>();
|
||||
|
||||
for (Packet packet : packets) {
|
||||
PatternDirectionType direction = packet.isIncoming() ? PatternDirectionType.INPUT : PatternDirectionType.OUTPUT;
|
||||
final Set<FoundPattern> matches = patternService.findMatches(packet.getContent(), service,
|
||||
direction, PatternActionType.FIND);
|
||||
|
||||
packet.setMatches(matches);
|
||||
matches.forEach(m -> m.setPacket(packet));
|
||||
|
||||
foundPatterns.addAll(matches.stream()
|
||||
.map(FoundPattern::getPatternId)
|
||||
.map(patternService::find)
|
||||
.toList());
|
||||
}
|
||||
|
||||
return foundPatterns;
|
||||
}
|
||||
|
||||
private boolean matchPattern(List<Packet> packets, Pattern pattern) {
|
||||
boolean matched = false;
|
||||
|
||||
for (Packet packet : packets) {
|
||||
PatternDirectionType direction = packet.isIncoming() ? PatternDirectionType.INPUT : PatternDirectionType.OUTPUT;
|
||||
|
||||
if (pattern.getDirectionType() != PatternDirectionType.BOTH && pattern.getDirectionType() != direction) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final Set<FoundPattern> matches = patternService.matchOne(packet.getContent(), pattern);
|
||||
|
||||
if (!matches.isEmpty()) {
|
||||
packet.getMatches().addAll(matches);
|
||||
matches.forEach(m -> m.setPacket(packet));
|
||||
|
||||
matched = true;
|
||||
}
|
||||
}
|
||||
|
||||
return matched;
|
||||
}
|
||||
|
||||
private boolean isStreamIgnored(List<Packet> packets, CtfService service) {
|
||||
for (Packet packet : packets) {
|
||||
PatternDirectionType direction = packet.isIncoming() ? PatternDirectionType.INPUT : PatternDirectionType.OUTPUT;
|
||||
final Set<FoundPattern> matches = patternService.findMatches(packet.getContent(), service,
|
||||
direction, PatternActionType.IGNORE);
|
||||
if (!matches.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private Stream save(Stream stream) {
|
||||
Stream saved;
|
||||
if (stream.getId() == null) {
|
||||
saved = repository.save(stream);
|
||||
log.debug("Сохранен поток с идентификатором {}", saved.getId());
|
||||
} else {
|
||||
saved = repository.save(stream);
|
||||
}
|
||||
|
||||
return saved;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<PacketDto> getPackets(long streamId, @Nullable Long startingFrom, int pageSize) {
|
||||
RequestValidation.requireIdentifier(streamId, "Идентификатор потока");
|
||||
RequestValidation.requirePage(startingFrom, pageSize);
|
||||
return repository.getPackets(streamId, startingFrom, Pageable.ofSize(pageSize))
|
||||
.stream()
|
||||
.map(this::packetToDto)
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return количество удаленных записей
|
||||
*/
|
||||
@Transactional
|
||||
public long cleanupOldStreams(ZonedDateTime before) {
|
||||
return repository.deleteByEndTimestampBeforeAndFavoriteIsFalse(before.toEpochSecond() * 1000);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void setFavorite(long id, boolean favorite) {
|
||||
RequestValidation.requireIdentifier(id, "Идентификатор потока");
|
||||
repository.setFavorite(id, favorite);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<StreamDto> findAll(StreamPagination pagination, Optional<Integer> service, boolean onlyFavorites) {
|
||||
if (pagination == null) {
|
||||
throw new RequestValidationException("Не переданы параметры страницы.");
|
||||
}
|
||||
RequestValidation.requirePage(pagination.getStartingFrom(), pagination.getPageSize());
|
||||
service.ifPresent(RequestValidation::requirePort);
|
||||
if (pagination.getPattern() != null) {
|
||||
Integer patternId = pagination.getPattern().getId();
|
||||
if (patternId == null) {
|
||||
throw new RequestValidationException("Не указан идентификатор паттерна.");
|
||||
}
|
||||
RequestValidation.requireIdentifier(patternId, "Идентификатор паттерна");
|
||||
}
|
||||
PageRequest page = PageRequest.of(0, pagination.getPageSize(), Sort.Direction.DESC, "id");
|
||||
|
||||
Specification<Stream> spec = Specification.unrestricted();
|
||||
|
||||
if (pagination.getStartingFrom() != null) {
|
||||
spec = spec.and(streamIdLessThan(pagination.getStartingFrom()));
|
||||
}
|
||||
|
||||
if (service.isPresent()) {
|
||||
spec = spec.and(streamServiceEquals(service.get()));
|
||||
}
|
||||
|
||||
if (onlyFavorites) {
|
||||
spec = spec.and(streamIsFavorite());
|
||||
}
|
||||
|
||||
if (pagination.getPattern() != null) {
|
||||
spec = spec.and(streamPatternsContains(pagination.getPattern()));
|
||||
}
|
||||
|
||||
return repository.findAll(spec, page)
|
||||
.getContent()
|
||||
.stream()
|
||||
.map(this::streamToDto)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public List<Stream> findAllBetweenTimestamps(long start, long end) {
|
||||
Specification<Stream> spec = streamTimestampBetween(start, end);
|
||||
return repository.findAll(spec);
|
||||
}
|
||||
|
||||
public StreamDto streamToDto(Stream stream) {
|
||||
return modelMapper.map(stream, StreamDto.class);
|
||||
}
|
||||
|
||||
public PacketDto packetToDto(Packet packet) {
|
||||
return modelMapper.map(packet, PacketDto.class);
|
||||
}
|
||||
|
||||
private Specification<Stream> streamServiceEquals(long service) {
|
||||
return (root, query, cb) -> cb.equal(root.get("service"), service);
|
||||
}
|
||||
|
||||
private Specification<Stream> streamIsFavorite() {
|
||||
return (root, query, cb) -> cb.equal(root.get("favorite"), true);
|
||||
}
|
||||
|
||||
private Specification<Stream> streamIdLessThan(long id) {
|
||||
return (root, query, cb) -> cb.lessThan(root.get("id"), id);
|
||||
}
|
||||
|
||||
private Specification<Stream> streamTimestampBetween(long start, long end) {
|
||||
return (root, query, cb) -> cb.between(root.get("startTimestamp"), start, end);
|
||||
}
|
||||
|
||||
private Specification<Stream> streamPatternsContains(Pattern pattern) {
|
||||
return (root, query, cb) -> cb.isMember(pattern, root.get("foundPatterns"));
|
||||
}
|
||||
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package ru.serega6531.packmate.service;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator;
|
||||
import tools.jackson.core.JacksonException;
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SubscriptionService {
|
||||
|
||||
private final Map<String, WebSocketSession> subscribers = new ConcurrentHashMap<>();
|
||||
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
@Autowired
|
||||
public SubscriptionService(ObjectMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public void addSubscriber(WebSocketSession session) {
|
||||
subscribers.put(session.getId(), new ConcurrentWebSocketSessionDecorator(session, 5000, 1024 * 1024));
|
||||
log.info("Подписан клиент: {}", session.getId());
|
||||
}
|
||||
|
||||
public void removeSubscriber(WebSocketSession session) {
|
||||
subscribers.remove(session.getId());
|
||||
log.info("Отписан клиент: {}", session.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Вызов потокобезопасный
|
||||
*/
|
||||
@SneakyThrows
|
||||
public void broadcast(SubscriptionMessage message) {
|
||||
final TextMessage messageJson = objectToTextMessage(message);
|
||||
subscribers.forEach((id, s) -> {
|
||||
try {
|
||||
s.sendMessage(messageJson);
|
||||
} catch (IOException | IllegalStateException e) {
|
||||
subscribers.remove(id, s);
|
||||
log.warn("Соединение WebSocket закрыто после ошибки отправки: {}", id);
|
||||
try {
|
||||
s.close(CloseStatus.SERVER_ERROR);
|
||||
} catch (IOException ignored) {
|
||||
// Соединение уже недоступно.
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private TextMessage objectToTextMessage(SubscriptionMessage object) throws JacksonException {
|
||||
return new TextMessage(mapper.writeValueAsString(object));
|
||||
}
|
||||
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package ru.serega6531.packmate.service.optimization;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import rawhttp.core.HttpMessage;
|
||||
import rawhttp.core.RawHttp;
|
||||
import rawhttp.core.RawHttpOptions;
|
||||
import rawhttp.core.body.BodyReader;
|
||||
import rawhttp.core.errors.InvalidHttpHeader;
|
||||
import rawhttp.core.errors.InvalidHttpRequest;
|
||||
import rawhttp.core.errors.InvalidHttpResponse;
|
||||
import rawhttp.core.errors.InvalidMessageFrame;
|
||||
import rawhttp.core.errors.UnknownEncodingException;
|
||||
import ru.serega6531.packmate.model.Packet;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
public class HttpProcessor {
|
||||
|
||||
private static final RawHttp rawHttp = new RawHttp(RawHttpOptions.strict());
|
||||
|
||||
public void process(List<Packet> packets) {
|
||||
packets.stream()
|
||||
.filter(p -> !p.isWebSocketParsed())
|
||||
.forEach(this::processPacket);
|
||||
}
|
||||
|
||||
private void processPacket(Packet packet) {
|
||||
try {
|
||||
ByteArrayInputStream contentStream = new ByteArrayInputStream(packet.getContent());
|
||||
HttpMessage message;
|
||||
|
||||
if (packet.isIncoming()) {
|
||||
message = rawHttp.parseRequest(contentStream).eagerly();
|
||||
} else {
|
||||
message = rawHttp.parseResponse(contentStream).eagerly();
|
||||
}
|
||||
|
||||
packet.setContent(getDecodedMessage(message));
|
||||
packet.setHasHttpBody(message.getBody().isPresent());
|
||||
} catch (IOException | InvalidHttpRequest | InvalidHttpResponse | InvalidHttpHeader | InvalidMessageFrame |
|
||||
UnknownEncodingException e) {
|
||||
log.warn("Не удалось разобрать HTTP-пакет", e);
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] getDecodedMessage(HttpMessage message) throws IOException {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream(256);
|
||||
|
||||
message.getStartLine().writeTo(os);
|
||||
message.getHeaders().writeTo(os);
|
||||
|
||||
Optional<? extends BodyReader> body = message.getBody();
|
||||
if (body.isPresent()) {
|
||||
body.get().writeDecodedTo(os, 256);
|
||||
}
|
||||
|
||||
return os.toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package ru.serega6531.packmate.service.optimization;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import ru.serega6531.packmate.model.Packet;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public class HttpUrldecodeProcessor {
|
||||
|
||||
/**
|
||||
* Декодирует URL-кодирование HTTP-пакетов до смены направления или конца потока.
|
||||
*/
|
||||
@SneakyThrows
|
||||
public void urldecodeRequests(List<Packet> packets) {
|
||||
boolean httpStarted = false;
|
||||
|
||||
for (Packet packet : packets) {
|
||||
if (packet.isIncoming()) {
|
||||
String content = packet.getContentString();
|
||||
if (content.contains("HTTP/")) {
|
||||
httpStarted = true;
|
||||
}
|
||||
|
||||
if (httpStarted) {
|
||||
try {
|
||||
content = URLDecoder.decode(content, StandardCharsets.UTF_8);
|
||||
packet.setContent(content.getBytes());
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.warn("Не удалось декодировать URL-кодированные данные HTTP", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
httpStarted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package ru.serega6531.packmate.service.optimization;
|
||||
|
||||
import ru.serega6531.packmate.model.Packet;
|
||||
import ru.serega6531.packmate.utils.PacketUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PacketsMerger {
|
||||
|
||||
/**
|
||||
* Сжать соседние пакеты в одном направлении в один. Не склеивает WS и не-WS пакеты.
|
||||
*/
|
||||
public void mergeAdjacentPackets(List<Packet> packets) {
|
||||
int start = 0;
|
||||
int packetsInRow = 0;
|
||||
Packet previous = null;
|
||||
|
||||
for (int i = 0; i < packets.size(); i++) {
|
||||
Packet packet = packets.get(i);
|
||||
if (previous == null || !shouldBeInSameBatch(packet, previous)) {
|
||||
if (packetsInRow > 1) {
|
||||
compress(packets, start, i);
|
||||
|
||||
i = start + 1; // Переходим к элементу сразу после объединенного блока.
|
||||
}
|
||||
start = i;
|
||||
packetsInRow = 1;
|
||||
} else {
|
||||
packetsInRow++;
|
||||
}
|
||||
|
||||
previous = packet;
|
||||
}
|
||||
|
||||
if (packetsInRow > 1) {
|
||||
compress(packets, start, packets.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Объединяет элементы от start до end в один пакет.
|
||||
*/
|
||||
private void compress(List<Packet> packets, int start, int end) {
|
||||
final List<Packet> cut = packets.subList(start, end);
|
||||
final long timestamp = cut.get(0).getTimestamp();
|
||||
final boolean httpProcessed = cut.stream().anyMatch(Packet::isHttpProcessed);
|
||||
final boolean webSocketParsed = cut.stream().anyMatch(Packet::isWebSocketParsed);
|
||||
final boolean tlsDecrypted = cut.get(0).isTlsDecrypted();
|
||||
final boolean incoming = cut.get(0).isIncoming();
|
||||
final byte[] content = PacketUtils.mergePackets(cut);
|
||||
|
||||
packets.removeAll(cut);
|
||||
packets.add(start, Packet.builder()
|
||||
.incoming(incoming)
|
||||
.timestamp(timestamp)
|
||||
.httpProcessed(httpProcessed)
|
||||
.webSocketParsed(webSocketParsed)
|
||||
.tlsDecrypted(tlsDecrypted)
|
||||
.content(content)
|
||||
.build());
|
||||
}
|
||||
|
||||
private boolean shouldBeInSameBatch(Packet p1, Packet p2) {
|
||||
return p1.isIncoming() == p2.isIncoming() &&
|
||||
p1.isWebSocketParsed() == p2.isWebSocketParsed();
|
||||
}
|
||||
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package ru.serega6531.packmate.service.optimization;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.file.Files;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.interfaces.RSAPrivateKey;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class RsaKeysHolder {
|
||||
|
||||
// Ключ: модуль N открытого ключа RSA.
|
||||
private final Map<BigInteger, RSAPrivateKey> keys = new HashMap<>();
|
||||
|
||||
public RSAPrivateKey getKey(BigInteger modulus) {
|
||||
return keys.get(modulus);
|
||||
}
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void afterStartup(ApplicationReadyEvent event) {
|
||||
log.info("Загружаются ключи RSA");
|
||||
File dir = new File("rsa_keys");
|
||||
if (dir.exists() && dir.isDirectory()) {
|
||||
for (File keyFile : Objects.requireNonNull(dir.listFiles())) {
|
||||
addKey(keyFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void addKey(File keyFile) {
|
||||
if (!keyFile.exists()) {
|
||||
throw new IllegalArgumentException("Файл ключа не существует.");
|
||||
}
|
||||
|
||||
try {
|
||||
RSAPrivateKey privateKey = loadFromFile(keyFile);
|
||||
keys.put(privateKey.getModulus(), privateKey);
|
||||
log.info("Загружен ключ RSA");
|
||||
} catch (IOException | InvalidKeySpecException e) {
|
||||
log.error("Не удалось загрузить ключ RSA", e);
|
||||
}
|
||||
}
|
||||
|
||||
private RSAPrivateKey loadFromFile(File keyFile) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException {
|
||||
String content = Files.readString(keyFile.toPath());
|
||||
|
||||
content = content.replaceAll("-----BEGIN (RSA )?PRIVATE KEY-----", "")
|
||||
.replaceAll("-----END (RSA )?PRIVATE KEY-----", "")
|
||||
.replace("\n", "");
|
||||
|
||||
byte[] keyBytes = Base64.getDecoder().decode(content);
|
||||
|
||||
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
|
||||
KeyFactory kf = KeyFactory.getInstance("RSA");
|
||||
return (RSAPrivateKey) kf.generatePrivate(spec);
|
||||
}
|
||||
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package ru.serega6531.packmate.service.optimization;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import ru.serega6531.packmate.model.CtfService;
|
||||
import ru.serega6531.packmate.model.Packet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
public class StreamOptimizer {
|
||||
|
||||
private final RsaKeysHolder keysHolder;
|
||||
private final CtfService service;
|
||||
private List<Packet> packets;
|
||||
|
||||
private final PacketsMerger merger = new PacketsMerger();
|
||||
private final HttpUrldecodeProcessor urldecodeProcessor = new HttpUrldecodeProcessor();
|
||||
private final HttpProcessor httpProcessor = new HttpProcessor();
|
||||
|
||||
|
||||
/**
|
||||
* Вызвать для выполнения оптимизаций на переданном списке пакетов.
|
||||
*/
|
||||
public List<Packet> optimizeStream() {
|
||||
if (service.isDecryptTls()) {
|
||||
try {
|
||||
decryptTls();
|
||||
} catch (Exception e) {
|
||||
log.warn("Ошибка при разборе TLS-потока", e);
|
||||
return packets;
|
||||
}
|
||||
}
|
||||
|
||||
if (service.isParseWebSockets()) {
|
||||
try {
|
||||
parseWebSockets();
|
||||
} catch (Exception e) {
|
||||
log.warn("Ошибка при разборе WebSocket-потока", e);
|
||||
return packets;
|
||||
}
|
||||
}
|
||||
|
||||
if (service.isUrldecodeHttpRequests()) {
|
||||
try {
|
||||
urldecodeProcessor.urldecodeRequests(packets);
|
||||
} catch (Exception e) {
|
||||
log.warn("Ошибка при декодировании URL-кодированных данных", e);
|
||||
return packets;
|
||||
}
|
||||
}
|
||||
|
||||
if (service.isMergeAdjacentPackets() || service.isHttp()) {
|
||||
try {
|
||||
merger.mergeAdjacentPackets(packets);
|
||||
} catch (Exception e) {
|
||||
log.warn("Ошибка при объединении соседних пакетов", e);
|
||||
return packets;
|
||||
}
|
||||
}
|
||||
|
||||
if (service.isHttp()) {
|
||||
try {
|
||||
httpProcessor.process(packets);
|
||||
} catch (Exception e) {
|
||||
log.warn("Ошибка при разборе HTTP-потока", e);
|
||||
return packets;
|
||||
}
|
||||
}
|
||||
|
||||
return packets;
|
||||
}
|
||||
|
||||
private void decryptTls() {
|
||||
final TlsDecryptor tlsDecryptor = new TlsDecryptor(packets, keysHolder);
|
||||
tlsDecryptor.decryptTls();
|
||||
|
||||
if (tlsDecryptor.isParsed()) {
|
||||
packets = tlsDecryptor.getParsedPackets();
|
||||
}
|
||||
}
|
||||
|
||||
private void parseWebSockets() {
|
||||
if (!packets.get(0).getContentString().contains("HTTP/")) {
|
||||
return;
|
||||
}
|
||||
|
||||
final WebSocketsParser parser = new WebSocketsParser(packets);
|
||||
if (!parser.isParsed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
packets = parser.getParsedPackets();
|
||||
}
|
||||
|
||||
}
|
||||
+296
@@ -0,0 +1,296 @@
|
||||
package ru.serega6531.packmate.service.optimization;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.bouncycastle.tls.ExporterLabel;
|
||||
import org.bouncycastle.tls.PRFAlgorithm;
|
||||
import org.bouncycastle.tls.crypto.TlsSecret;
|
||||
import org.bouncycastle.tls.crypto.impl.bc.BcTlsCrypto;
|
||||
import org.bouncycastle.tls.crypto.impl.bc.BcTlsSecret;
|
||||
import org.pcap4j.packet.IllegalRawDataException;
|
||||
import org.pcap4j.util.ByteArrays;
|
||||
import ru.serega6531.packmate.model.Packet;
|
||||
import ru.serega6531.packmate.service.optimization.tls.TlsPacket;
|
||||
import ru.serega6531.packmate.service.optimization.tls.keys.TlsKeyUtils;
|
||||
import ru.serega6531.packmate.service.optimization.tls.numbers.CipherSuite;
|
||||
import ru.serega6531.packmate.service.optimization.tls.numbers.ContentType;
|
||||
import ru.serega6531.packmate.service.optimization.tls.numbers.HandshakeType;
|
||||
import ru.serega6531.packmate.service.optimization.tls.records.ApplicationDataRecord;
|
||||
import ru.serega6531.packmate.service.optimization.tls.records.HandshakeRecord;
|
||||
import ru.serega6531.packmate.service.optimization.tls.records.handshakes.*;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.interfaces.RSAPrivateKey;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class TlsDecryptor {
|
||||
|
||||
private static final Pattern cipherSuitePattern = Pattern.compile("TLS_RSA_WITH_([A-Z0-9_]+)_[A-Z0-9]+");
|
||||
|
||||
private final List<Packet> packets;
|
||||
private final RsaKeysHolder keysHolder;
|
||||
|
||||
@Getter
|
||||
private boolean parsed = false;
|
||||
private List<Packet> result;
|
||||
|
||||
private ListMultimap<Packet, TlsPacket.TlsHeader> tlsPackets;
|
||||
private byte[] clientRandom;
|
||||
private byte[] serverRandom;
|
||||
|
||||
public void decryptTls() {
|
||||
tlsPackets = ArrayListMultimap.create(packets.size(), 1);
|
||||
|
||||
try {
|
||||
for (Packet p : packets) {
|
||||
tlsPackets.putAll(p, createTlsHeaders(p));
|
||||
}
|
||||
} catch (IllegalRawDataException e) {
|
||||
log.warn("Не удалось разобрать TLS-пакеты", e);
|
||||
return;
|
||||
}
|
||||
|
||||
var clientHelloOpt = getHandshake(HandshakeType.CLIENT_HELLO);
|
||||
var serverHelloOpt = getHandshake(HandshakeType.SERVER_HELLO);
|
||||
|
||||
if (clientHelloOpt.isEmpty() || serverHelloOpt.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var clientHello = (ClientHelloHandshakeRecordContent) clientHelloOpt.get();
|
||||
var serverHello = (ServerHelloHandshakeRecordContent) serverHelloOpt.get();
|
||||
|
||||
CipherSuite cipherSuite = serverHello.getCipherSuite();
|
||||
|
||||
if (cipherSuite.name().startsWith("TLS_RSA_WITH_")) {
|
||||
Matcher matcher = cipherSuitePattern.matcher(cipherSuite.name());
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
matcher.find();
|
||||
String blockCipher = matcher.group(1);
|
||||
|
||||
clientRandom = clientHello.getRandom();
|
||||
serverRandom = serverHello.getRandom();
|
||||
|
||||
decryptTlsRsa(blockCipher);
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private void decryptTlsRsa(String blockCipher) {
|
||||
String[] blockCipherParts = blockCipher.split("_");
|
||||
String blockCipherAlgo = blockCipherParts[0];
|
||||
int blockCipherSize = Integer.parseInt(blockCipherParts[1]);
|
||||
String blockCipherMode = blockCipherParts[2];
|
||||
|
||||
if (!blockCipherAlgo.equals("AES")) {
|
||||
return;
|
||||
}
|
||||
|
||||
int keyLength = blockCipherSize / 8;
|
||||
|
||||
Optional<RSAPublicKey> publicKeyOpt = getRsaPublicKey();
|
||||
|
||||
if (publicKeyOpt.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RSAPublicKey publicKey = publicKeyOpt.get();
|
||||
RSAPrivateKey privateKey = keysHolder.getKey(publicKey.getModulus());
|
||||
if (privateKey == null) {
|
||||
log.warn("Не найден закрытый ключ RSA для модуля сертификата");
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<BcTlsSecret> preMasterOptional = getPreMaster(privateKey);
|
||||
if (preMasterOptional.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
BcTlsSecret preMaster = preMasterOptional.get();
|
||||
|
||||
byte[] randomCS = ArrayUtils.addAll(clientRandom, serverRandom);
|
||||
byte[] randomSC = ArrayUtils.addAll(serverRandom, clientRandom);
|
||||
|
||||
TlsSecret masterSecret = preMaster.deriveUsingPRF(
|
||||
PRFAlgorithm.tls_prf_sha256, ExporterLabel.master_secret, randomCS, 48);
|
||||
byte[] expanded = masterSecret.deriveUsingPRF(
|
||||
PRFAlgorithm.tls_prf_sha256, ExporterLabel.key_expansion, randomSC, 72 + keyLength * 2).extract();
|
||||
|
||||
byte[] clientMacKey = new byte[20];
|
||||
byte[] serverMacKey = new byte[20];
|
||||
byte[] clientEncryptionKey = new byte[keyLength];
|
||||
byte[] serverEncryptionKey = new byte[keyLength];
|
||||
byte[] clientIV = new byte[16];
|
||||
byte[] serverIV = new byte[16];
|
||||
|
||||
ByteBuffer bb = ByteBuffer.wrap(expanded);
|
||||
bb.get(clientMacKey);
|
||||
bb.get(serverMacKey);
|
||||
bb.get(clientEncryptionKey);
|
||||
bb.get(serverEncryptionKey);
|
||||
bb.get(clientIV);
|
||||
bb.get(serverIV);
|
||||
|
||||
Optional<Cipher> clientCipherOpt = createCipher(blockCipherMode, clientEncryptionKey, clientIV);
|
||||
Optional<Cipher> serverCipherOpt = createCipher(blockCipherMode, serverEncryptionKey, serverIV);
|
||||
|
||||
if (clientCipherOpt.isEmpty() || serverCipherOpt.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Cipher clientCipher = clientCipherOpt.get();
|
||||
Cipher serverCipher = serverCipherOpt.get();
|
||||
|
||||
result = new ArrayList<>(packets.size());
|
||||
|
||||
for (Packet packet : packets) {
|
||||
List<TlsPacket.TlsHeader> tlsData = tlsPackets.get(packet);
|
||||
|
||||
for (TlsPacket.TlsHeader tlsPacket : tlsData) {
|
||||
if (tlsPacket.getContentType() == ContentType.APPLICATION_DATA) {
|
||||
byte[] data = ((ApplicationDataRecord) tlsPacket.getRecord()).getData();
|
||||
boolean client = packet.isIncoming();
|
||||
|
||||
Cipher cipher = client ? clientCipher : serverCipher;
|
||||
byte[] decoded = cipher.doFinal(data);
|
||||
|
||||
decoded = clearDecodedData(decoded);
|
||||
|
||||
result.add(
|
||||
packet.toBuilder()
|
||||
.content(decoded)
|
||||
.tlsDecrypted(true)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parsed = true;
|
||||
}
|
||||
|
||||
@SneakyThrows(value = {NoSuchAlgorithmException.class, NoSuchPaddingException.class})
|
||||
private Optional<BcTlsSecret> getPreMaster(RSAPrivateKey privateKey) {
|
||||
Optional<HandshakeRecordContent> opt = getHandshake(HandshakeType.CLIENT_KEY_EXCHANGE);
|
||||
|
||||
if (opt.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
var clientKeyExchange = (BasicHandshakeRecordContent) opt.get();
|
||||
|
||||
try {
|
||||
byte[] encryptedPreMaster = TlsKeyUtils.getClientRsaPreMaster(clientKeyExchange.getContent(), 0);
|
||||
|
||||
Cipher rsa = Cipher.getInstance("RSA/ECB/PKCS1Padding");
|
||||
rsa.init(Cipher.DECRYPT_MODE, privateKey);
|
||||
byte[] preMaster = rsa.doFinal(encryptedPreMaster);
|
||||
return Optional.of(new BcTlsSecret(new BcTlsCrypto(null), preMaster));
|
||||
} catch (InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) {
|
||||
log.warn("Не удалось получить предварительный ключ TLS", e);
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<RSAPublicKey> getRsaPublicKey() {
|
||||
var certificateHandshakeOpt = getHandshake(HandshakeType.CERTIFICATE);
|
||||
|
||||
if (certificateHandshakeOpt.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
var certificateHandshake = (CertificateHandshakeRecordContent) certificateHandshakeOpt.get();
|
||||
List<byte[]> chain = certificateHandshake.getRawCertificates();
|
||||
byte[] rawCertificate = chain.get(0);
|
||||
|
||||
try {
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
Certificate certificate = cf.generateCertificate(new ByteArrayInputStream(rawCertificate));
|
||||
RSAPublicKey publicKey = (RSAPublicKey) certificate.getPublicKey();
|
||||
return Optional.of(publicKey);
|
||||
} catch (CertificateException e) {
|
||||
log.warn("Не удалось прочитать сертификат TLS", e);
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows(value = {NoSuchAlgorithmException.class, NoSuchPaddingException.class})
|
||||
private Optional<Cipher> createCipher(String mode, byte[] key, byte[] iv) {
|
||||
Cipher cipher = Cipher.getInstance("AES/" + mode + "/PKCS5Padding");
|
||||
SecretKeySpec serverSkeySpec = new SecretKeySpec(key, "AES");
|
||||
IvParameterSpec serverIvParameterSpec = new IvParameterSpec(iv);
|
||||
|
||||
try {
|
||||
cipher.init(Cipher.DECRYPT_MODE, serverSkeySpec, serverIvParameterSpec);
|
||||
|
||||
return Optional.of(cipher);
|
||||
} catch (InvalidKeyException | InvalidAlgorithmParameterException e) {
|
||||
log.warn("Не удалось расшифровать TLS", e);
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] clearDecodedData(byte[] decoded) {
|
||||
int start = 16;
|
||||
int end = decoded.length - 21; // почему?)
|
||||
decoded = ByteArrays.getSubArray(decoded, start, end - start);
|
||||
return decoded;
|
||||
}
|
||||
|
||||
private Optional<HandshakeRecordContent> getHandshake(HandshakeType handshakeType) {
|
||||
return tlsPackets.values().stream()
|
||||
.filter(p -> p.getContentType() == ContentType.HANDSHAKE)
|
||||
.map(p -> ((HandshakeRecord) p.getRecord()))
|
||||
.filter(r -> r.getHandshakeType() == handshakeType)
|
||||
.map(HandshakeRecord::getContent)
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
private List<TlsPacket.TlsHeader> createTlsHeaders(Packet p) throws IllegalRawDataException {
|
||||
List<TlsPacket.TlsHeader> headers = new ArrayList<>();
|
||||
TlsPacket tlsPacket = TlsPacket.newPacket(p.getContent(), 0, p.getContent().length);
|
||||
|
||||
headers.add(tlsPacket.getHeader());
|
||||
|
||||
while (tlsPacket.getPayload() != null) {
|
||||
tlsPacket = (TlsPacket) tlsPacket.getPayload();
|
||||
headers.add(tlsPacket.getHeader());
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
public List<Packet> getParsedPackets() {
|
||||
if (!parsed) {
|
||||
throw new IllegalStateException("Данные TLS не разобраны.");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
+238
@@ -0,0 +1,238 @@
|
||||
package ru.serega6531.packmate.service.optimization;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.java_websocket.drafts.Draft_6455;
|
||||
import org.java_websocket.exceptions.InvalidDataException;
|
||||
import org.java_websocket.exceptions.InvalidHandshakeException;
|
||||
import org.java_websocket.extensions.permessage_deflate.PerMessageDeflateExtension;
|
||||
import org.java_websocket.framing.DataFrame;
|
||||
import org.java_websocket.framing.Framedata;
|
||||
import org.java_websocket.handshake.HandshakeImpl1Client;
|
||||
import org.java_websocket.handshake.HandshakeImpl1Server;
|
||||
import ru.serega6531.packmate.model.Packet;
|
||||
import ru.serega6531.packmate.utils.BytesUtils;
|
||||
import ru.serega6531.packmate.utils.PacketUtils;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
public class WebSocketsParser {
|
||||
|
||||
private static final java.util.regex.Pattern WEBSOCKET_KEY_PATTERN =
|
||||
Pattern.compile("Sec-WebSocket-Key: (.+)\\r\\n");
|
||||
private static final java.util.regex.Pattern WEBSOCKET_EXTENSIONS_PATTERN =
|
||||
Pattern.compile("Sec-WebSocket-Extensions?: (.+)\\r\\n");
|
||||
private static final java.util.regex.Pattern WEBSOCKET_VERSION_PATTERN =
|
||||
Pattern.compile("Sec-WebSocket-Version: (\\d+)\\r\\n");
|
||||
private static final java.util.regex.Pattern WEBSOCKET_ACCEPT_PATTERN =
|
||||
Pattern.compile("Sec-WebSocket-Accept: (.+)\\r\\n");
|
||||
|
||||
private static final String WEBSOCKET_UPGRADE_HEADER = "upgrade: websocket\r\n";
|
||||
private static final String WEBSOCKET_CONNECTION_HEADER = "connection: upgrade\r\n";
|
||||
|
||||
private final List<Packet> packets;
|
||||
|
||||
@Getter
|
||||
private boolean parsed = false;
|
||||
private List<Packet> parsedPackets;
|
||||
|
||||
public WebSocketsParser(List<Packet> packets) {
|
||||
this.packets = packets;
|
||||
detectWebSockets();
|
||||
}
|
||||
|
||||
private void detectWebSockets() {
|
||||
final List<Packet> clientHandshakePackets = packets.stream()
|
||||
.takeWhile(Packet::isIncoming)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final String clientHandshake = getHandshake(clientHandshakePackets);
|
||||
if (clientHandshake == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int httpEnd = -1;
|
||||
for (int i = clientHandshakePackets.size(); i < packets.size(); i++) {
|
||||
Packet packet = packets.get(i);
|
||||
byte[] content = packet.getContent();
|
||||
if (BytesUtils.startsWith(content, "HTTP/1.1 101 Switching Protocols".getBytes())) {
|
||||
int endPos = BytesUtils.indexOf(content, "\r\n\r\n".getBytes()) + "\r\n\r\n".length();
|
||||
if (endPos != content.length) {
|
||||
byte[] handshakePart = ArrayUtils.subarray(content, 0, endPos);
|
||||
byte[] payloadPart = ArrayUtils.subarray(content, endPos, content.length);
|
||||
|
||||
Packet handshakePacket = mimicPacket(packet, handshakePart, false);
|
||||
Packet payloadPacket = mimicPacket(packet, payloadPart, true);
|
||||
|
||||
packets.add(i, handshakePacket);
|
||||
packets.set(i + 1, payloadPacket);
|
||||
}
|
||||
httpEnd = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (httpEnd == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Packet> serverHandshakePackets = packets.subList(clientHandshakePackets.size(), httpEnd);
|
||||
final String serverHandshake = getHandshake(serverHandshakePackets);
|
||||
if (serverHandshake == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
HandshakeImpl1Server serverHandshakeImpl = fillServerHandshake(serverHandshake);
|
||||
HandshakeImpl1Client clientHandshakeImpl = fillClientHandshake(clientHandshake);
|
||||
|
||||
if (serverHandshakeImpl == null || clientHandshakeImpl == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Draft_6455 draft = new Draft_6455(new PerMessageDeflateExtension());
|
||||
|
||||
try {
|
||||
draft.acceptHandshakeAsServer(clientHandshakeImpl);
|
||||
draft.acceptHandshakeAsClient(clientHandshakeImpl, serverHandshakeImpl);
|
||||
} catch (InvalidHandshakeException e) {
|
||||
log.warn("Не удалось разобрать рукопожатие WebSocket", e);
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Packet> wsPackets = packets.subList(
|
||||
httpEnd,
|
||||
packets.size());
|
||||
|
||||
if (wsPackets.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Packet> handshakes = packets.subList(0, httpEnd);
|
||||
|
||||
parse(wsPackets, handshakes, draft);
|
||||
}
|
||||
|
||||
private Packet mimicPacket(Packet packet, byte[] content, boolean ws) {
|
||||
return packet.toBuilder()
|
||||
.content(content)
|
||||
.webSocketParsed(ws)
|
||||
.build();
|
||||
}
|
||||
|
||||
private void parse(final List<Packet> wsPackets, final List<Packet> handshakes, Draft_6455 draft) {
|
||||
List<List<Packet>> sides = PacketUtils.sliceToSides(wsPackets);
|
||||
parsedPackets = new ArrayList<>(handshakes);
|
||||
|
||||
for (List<Packet> side : sides) {
|
||||
final Packet lastPacket = side.get(0);
|
||||
|
||||
final byte[] wsContent = PacketUtils.mergePackets(side);
|
||||
|
||||
final ByteBuffer buffer = ByteBuffer.wrap(wsContent);
|
||||
List<Framedata> frames;
|
||||
|
||||
try {
|
||||
frames = draft.translateFrame(buffer);
|
||||
} catch (InvalidDataException e) {
|
||||
log.warn("Не удалось разобрать данные WebSocket", e);
|
||||
return;
|
||||
}
|
||||
|
||||
for (Framedata frame : frames) {
|
||||
if (frame instanceof DataFrame) {
|
||||
parsedPackets.add(
|
||||
lastPacket.toBuilder()
|
||||
.content(frame.getPayloadData().array())
|
||||
.webSocketParsed(true)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parsed = true;
|
||||
}
|
||||
|
||||
public List<Packet> getParsedPackets() {
|
||||
if (!parsed) {
|
||||
throw new IllegalStateException("Данные WebSocket не разобраны.");
|
||||
}
|
||||
|
||||
return parsedPackets;
|
||||
}
|
||||
|
||||
private String getHandshake(final List<Packet> packets) {
|
||||
final String handshake = new String(PacketUtils.mergePackets(packets));
|
||||
|
||||
if (!handshake.toLowerCase().contains(WEBSOCKET_CONNECTION_HEADER)
|
||||
|| !handshake.toLowerCase().contains(WEBSOCKET_UPGRADE_HEADER)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return handshake;
|
||||
}
|
||||
|
||||
private HandshakeImpl1Client fillClientHandshake(String clientHandshake) {
|
||||
Matcher matcher = WEBSOCKET_VERSION_PATTERN.matcher(clientHandshake);
|
||||
if (!matcher.find()) {
|
||||
return null;
|
||||
}
|
||||
String version = matcher.group(1);
|
||||
|
||||
matcher = WEBSOCKET_KEY_PATTERN.matcher(clientHandshake);
|
||||
if (!matcher.find()) {
|
||||
return null;
|
||||
}
|
||||
String key = matcher.group(1);
|
||||
|
||||
matcher = WEBSOCKET_EXTENSIONS_PATTERN.matcher(clientHandshake);
|
||||
String extensions = null;
|
||||
if (matcher.find()) {
|
||||
extensions = matcher.group(1);
|
||||
}
|
||||
|
||||
HandshakeImpl1Client clientHandshakeImpl = new HandshakeImpl1Client();
|
||||
|
||||
clientHandshakeImpl.put("Upgrade", "websocket");
|
||||
clientHandshakeImpl.put("Connection", "Upgrade");
|
||||
clientHandshakeImpl.put("Sec-WebSocket-Version", version);
|
||||
clientHandshakeImpl.put("Sec-WebSocket-Key", key);
|
||||
|
||||
if (extensions != null) {
|
||||
clientHandshakeImpl.put("Sec-WebSocket-Extensions", extensions);
|
||||
}
|
||||
|
||||
return clientHandshakeImpl;
|
||||
}
|
||||
|
||||
private HandshakeImpl1Server fillServerHandshake(String serverHandshake) {
|
||||
Matcher matcher = WEBSOCKET_ACCEPT_PATTERN.matcher(serverHandshake);
|
||||
if (!matcher.find()) {
|
||||
return null;
|
||||
}
|
||||
String accept = matcher.group(1);
|
||||
|
||||
matcher = WEBSOCKET_EXTENSIONS_PATTERN.matcher(serverHandshake);
|
||||
String extensions = null;
|
||||
if (matcher.find()) {
|
||||
extensions = matcher.group(1);
|
||||
}
|
||||
|
||||
HandshakeImpl1Server serverHandshakeImpl = new HandshakeImpl1Server();
|
||||
|
||||
serverHandshakeImpl.put("Upgrade", "websocket");
|
||||
serverHandshakeImpl.put("Connection", "Upgrade");
|
||||
serverHandshakeImpl.put("Sec-WebSocket-Accept", accept);
|
||||
serverHandshakeImpl.put("Sec-WebSocket-Extensions", extensions);
|
||||
|
||||
return serverHandshakeImpl;
|
||||
}
|
||||
|
||||
}
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls;
|
||||
|
||||
import org.pcap4j.packet.AbstractPacket;
|
||||
import org.pcap4j.packet.IllegalRawDataException;
|
||||
import org.pcap4j.packet.Packet;
|
||||
import org.pcap4j.util.ByteArrays;
|
||||
import ru.serega6531.packmate.service.optimization.tls.numbers.ContentType;
|
||||
import ru.serega6531.packmate.service.optimization.tls.numbers.TlsVersion;
|
||||
import ru.serega6531.packmate.service.optimization.tls.records.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.pcap4j.util.ByteArrays.BYTE_SIZE_IN_BYTES;
|
||||
import static org.pcap4j.util.ByteArrays.SHORT_SIZE_IN_BYTES;
|
||||
|
||||
public class TlsPacket extends AbstractPacket {
|
||||
|
||||
private final TlsPacket.TlsHeader header;
|
||||
private final Packet payload;
|
||||
|
||||
public static TlsPacket newPacket(byte[] rawData, int offset, int length) throws IllegalRawDataException {
|
||||
ByteArrays.validateBounds(rawData, offset, length);
|
||||
return new TlsPacket(rawData, offset, length);
|
||||
}
|
||||
|
||||
private TlsPacket(byte[] rawData, int offset, int length) throws IllegalRawDataException {
|
||||
this.header = new TlsPacket.TlsHeader(rawData, offset, length);
|
||||
|
||||
int payloadLength = length - header.length();
|
||||
if (payloadLength > 0) {
|
||||
this.payload = TlsPacket.newPacket(rawData, offset + header.length(), payloadLength);
|
||||
} else {
|
||||
this.payload = null;
|
||||
}
|
||||
}
|
||||
|
||||
private TlsPacket(TlsPacket.Builder builder) {
|
||||
if (builder == null) {
|
||||
throw new NullPointerException("Построитель TLS-пакета не задан.");
|
||||
}
|
||||
|
||||
this.payload = builder.payloadBuilder != null ? builder.payloadBuilder.build() : null;
|
||||
this.header = new TlsPacket.TlsHeader(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TlsHeader getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder getBuilder() {
|
||||
return new Builder(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String buildString() {
|
||||
StringBuilder sb = new StringBuilder(getHeader().toString());
|
||||
|
||||
TlsPacket p = (TlsPacket) getPayload();
|
||||
|
||||
if (p != null) {
|
||||
sb.append('\n');
|
||||
sb.append(p.toString());
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static final class TlsHeader extends AbstractHeader {
|
||||
|
||||
/*
|
||||
0x0 - Тип содержимого
|
||||
0x1 - Версия
|
||||
0x3 - Длина
|
||||
0x5 - Содержимое записи
|
||||
*/
|
||||
|
||||
private static final int CONTENT_TYPE_OFFSET = 0;
|
||||
private static final int VERSION_OFFSET = CONTENT_TYPE_OFFSET + BYTE_SIZE_IN_BYTES;
|
||||
private static final int LENGTH_OFFSET = VERSION_OFFSET + SHORT_SIZE_IN_BYTES;
|
||||
private static final int RECORD_OFFSET = LENGTH_OFFSET + SHORT_SIZE_IN_BYTES;
|
||||
|
||||
private ContentType contentType;
|
||||
private TlsVersion version;
|
||||
private short recordLength;
|
||||
private TlsRecord record;
|
||||
|
||||
private TlsHeader(Builder builder) {
|
||||
// TODO: добавить построение заголовка TLS.
|
||||
}
|
||||
|
||||
private TlsHeader(byte[] rawData, int offset, int length) throws IllegalRawDataException {
|
||||
ByteArrays.validateBounds(rawData, offset, RECORD_OFFSET);
|
||||
this.contentType = ContentType.getInstance(ByteArrays.getByte(rawData, CONTENT_TYPE_OFFSET + offset));
|
||||
this.version = TlsVersion.getInstance(ByteArrays.getShort(rawData, VERSION_OFFSET + offset));
|
||||
this.recordLength = ByteArrays.getShort(rawData, LENGTH_OFFSET + offset);
|
||||
|
||||
if (contentType == ContentType.HANDSHAKE) {
|
||||
this.record = HandshakeRecord.newInstance(rawData, offset + RECORD_OFFSET, recordLength);
|
||||
} else if (contentType == ContentType.CHANGE_CIPHER_SPEC) {
|
||||
this.record = ChangeCipherSpecRecord.newInstance(rawData, offset + RECORD_OFFSET, recordLength);
|
||||
} else if (contentType == ContentType.APPLICATION_DATA) {
|
||||
this.record = ApplicationDataRecord.newInstance(rawData, offset + RECORD_OFFSET, recordLength);
|
||||
} else if (contentType == ContentType.ALERT) {
|
||||
this.record = AlertRecord.newInstance(rawData, offset + RECORD_OFFSET, recordLength);
|
||||
} else if (contentType == ContentType.HEARTBEAT) {
|
||||
this.record = HeartbeatRecord.newInstance(rawData, offset + RECORD_OFFSET, recordLength);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Неизвестный тип содержимого TLS: " + contentType);
|
||||
}
|
||||
}
|
||||
|
||||
public ContentType getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public TlsVersion getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public TlsRecord getRecord() {
|
||||
return record;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<byte[]> getRawFields() {
|
||||
List<byte[]> rawFields = new ArrayList<>();
|
||||
rawFields.add(new byte[]{contentType.value()});
|
||||
rawFields.add(ByteArrays.toByteArray(version.value()));
|
||||
rawFields.add(ByteArrays.toByteArray(recordLength));
|
||||
// TODO: добавить сериализацию содержимого записи.
|
||||
return rawFields;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return RECORD_OFFSET + recordLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String buildString() {
|
||||
return "Заголовок TLS [" + length() + " байт]\n" +
|
||||
" Версия: " + version + "\n" +
|
||||
" Тип: " + contentType + "\n" +
|
||||
record.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Builder extends AbstractBuilder {
|
||||
|
||||
private Packet.Builder payloadBuilder;
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
public Builder(TlsPacket packet) {
|
||||
this.payloadBuilder = packet.payload != null ? packet.payload.getBuilder() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet build() {
|
||||
return new TlsPacket(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.extensions;
|
||||
|
||||
import org.pcap4j.util.ByteArrays;
|
||||
import ru.serega6531.packmate.service.optimization.tls.extensions.keyshare.KeyShareExtension;
|
||||
import ru.serega6531.packmate.service.optimization.tls.numbers.ExtensionType;
|
||||
|
||||
public abstract class TlsExtension {
|
||||
|
||||
/*
|
||||
0x0 - Тип
|
||||
0x2 - Длина
|
||||
0x4 - Содержимое
|
||||
0x4+length - Конец
|
||||
*/
|
||||
|
||||
protected ExtensionType type;
|
||||
protected short extensionLength;
|
||||
|
||||
public static TlsExtension newInstance(ExtensionType type, byte[] rawData, int offset,
|
||||
short extensionLength, boolean client) {
|
||||
if (extensionLength > 0) {
|
||||
ByteArrays.validateBounds(rawData, offset, extensionLength);
|
||||
}
|
||||
|
||||
if (type == ExtensionType.KEY_SHARE) {
|
||||
return KeyShareExtension.newInstance(type, rawData, offset, extensionLength, client);
|
||||
} else {
|
||||
return new UnimplementedTlsExtension(type, rawData, offset, extensionLength);
|
||||
}
|
||||
}
|
||||
|
||||
public TlsExtension(ExtensionType type, short extensionLength) {
|
||||
this.type = type;
|
||||
this.extensionLength = extensionLength;
|
||||
}
|
||||
|
||||
public ExtensionType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public short getLength() {
|
||||
return extensionLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type.name();
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.extensions;
|
||||
|
||||
import ru.serega6531.packmate.service.optimization.tls.numbers.ExtensionType;
|
||||
|
||||
public class UnimplementedTlsExtension extends TlsExtension {
|
||||
|
||||
private byte[] data;
|
||||
|
||||
public UnimplementedTlsExtension(ExtensionType type, byte[] rawData, int offset, short extensionLength) {
|
||||
super(type, extensionLength);
|
||||
|
||||
data = new byte[extensionLength];
|
||||
System.arraycopy(rawData, offset, data, 0, extensionLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if(extensionLength > 0) {
|
||||
return type.name() + " [" + extensionLength + " bytes]";
|
||||
} else {
|
||||
return type.name();
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.extensions.keyshare;
|
||||
|
||||
import org.pcap4j.util.ByteArrays;
|
||||
import ru.serega6531.packmate.service.optimization.tls.numbers.ExtensionType;
|
||||
|
||||
import static org.pcap4j.util.ByteArrays.SHORT_SIZE_IN_BYTES;
|
||||
|
||||
public class ClientKeyShareExtension extends KeyShareExtension {
|
||||
|
||||
private static final int KEY_SHARE_LENGTH_OFFSET = 0;
|
||||
private static final int KEY_SHARE_ENTRY_OFFSET = KEY_SHARE_LENGTH_OFFSET + SHORT_SIZE_IN_BYTES;
|
||||
|
||||
private short keyShareLength;
|
||||
|
||||
public ClientKeyShareExtension(ExtensionType type, byte[] rawData, int offset, short extensionLength) {
|
||||
super(type, extensionLength);
|
||||
this.keyShareLength = ByteArrays.getShort(rawData, KEY_SHARE_LENGTH_OFFSET + offset); // Поле присутствует не всегда.
|
||||
int cursor = KEY_SHARE_ENTRY_OFFSET + offset;
|
||||
ByteArrays.validateBounds(rawData, cursor, keyShareLength);
|
||||
readEntries(rawData, KEY_SHARE_ENTRY_OFFSET + offset, offset + keyShareLength);
|
||||
}
|
||||
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.extensions.keyshare;
|
||||
|
||||
import org.pcap4j.util.ByteArrays;
|
||||
import ru.serega6531.packmate.service.optimization.tls.numbers.KeyGroup;
|
||||
|
||||
import static org.pcap4j.util.ByteArrays.SHORT_SIZE_IN_BYTES;
|
||||
|
||||
public class KeyShareEntry {
|
||||
|
||||
private static final int GROUP_OFFSET = 0;
|
||||
private static final int KEY_EXHANGE_LENGTH_OFFSET = GROUP_OFFSET + SHORT_SIZE_IN_BYTES;
|
||||
private static final int KEY_EXCHANGE_OFFSET = KEY_EXHANGE_LENGTH_OFFSET + SHORT_SIZE_IN_BYTES;
|
||||
|
||||
private KeyGroup group;
|
||||
private short keyExhangeLength;
|
||||
private byte[] keyExchange;
|
||||
|
||||
public KeyShareEntry(byte[] rawData, int offset) {
|
||||
this.group = KeyGroup.getInstance(ByteArrays.getShort(rawData, GROUP_OFFSET + offset));
|
||||
this.keyExhangeLength = ByteArrays.getShort(rawData, KEY_EXHANGE_LENGTH_OFFSET + offset);
|
||||
keyExchange = new byte[keyExhangeLength];
|
||||
System.arraycopy(rawData, KEY_EXCHANGE_OFFSET + offset, keyExchange, 0, keyExhangeLength);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return SHORT_SIZE_IN_BYTES + SHORT_SIZE_IN_BYTES + keyExhangeLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return group.name();
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.extensions.keyshare;
|
||||
|
||||
import org.pcap4j.util.ByteArrays;
|
||||
import ru.serega6531.packmate.service.optimization.tls.extensions.TlsExtension;
|
||||
import ru.serega6531.packmate.service.optimization.tls.numbers.ExtensionType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class KeyShareExtension extends TlsExtension {
|
||||
|
||||
private final List<KeyShareEntry> entries = new ArrayList<>();
|
||||
|
||||
public static KeyShareExtension newInstance(ExtensionType type, byte[] rawData, int offset,
|
||||
short extensionLength, boolean client) {
|
||||
ByteArrays.validateBounds(rawData, offset, extensionLength);
|
||||
|
||||
if(client) {
|
||||
return new ClientKeyShareExtension(type, rawData, offset, extensionLength);
|
||||
} else {
|
||||
return new ServerKeyShareExtension(type, rawData, offset, extensionLength);
|
||||
}
|
||||
}
|
||||
|
||||
protected KeyShareExtension(ExtensionType type, short extensionLength) {
|
||||
super(type, extensionLength);
|
||||
}
|
||||
|
||||
protected void readEntries(byte[] rawData, int cursor, int end) {
|
||||
while (cursor < end) {
|
||||
KeyShareEntry entry = readEntry(rawData, cursor);
|
||||
cursor += entry.size();
|
||||
}
|
||||
}
|
||||
|
||||
protected KeyShareEntry readEntry(byte[] rawData, int cursor) {
|
||||
KeyShareEntry entry = new KeyShareEntry(rawData, cursor);
|
||||
entries.add(entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type.name() + " " + entries.toString();
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.extensions.keyshare;
|
||||
|
||||
import ru.serega6531.packmate.service.optimization.tls.numbers.ExtensionType;
|
||||
|
||||
public class ServerKeyShareExtension extends KeyShareExtension {
|
||||
|
||||
private static final int KEY_SHARE_ENTRY_OFFSET = 0;
|
||||
|
||||
public ServerKeyShareExtension(ExtensionType type, byte[] rawData, int offset, short extensionLength) {
|
||||
super(type, extensionLength);
|
||||
readEntry(rawData, KEY_SHARE_ENTRY_OFFSET + offset);
|
||||
}
|
||||
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.keys;
|
||||
|
||||
import ru.serega6531.packmate.service.optimization.tls.keys.enums.SignatureScheme;
|
||||
|
||||
public class DhClientParams {
|
||||
|
||||
private final byte[] p;
|
||||
private final byte[] g;
|
||||
private final byte[] pubkey;
|
||||
private final SignatureScheme signatureScheme;
|
||||
private final byte[] signature;
|
||||
|
||||
public DhClientParams(byte[] p, byte[] g, byte[] pubkey,
|
||||
SignatureScheme signatureScheme,
|
||||
byte[] signature) {
|
||||
this.p = p;
|
||||
this.g = g;
|
||||
this.pubkey = pubkey;
|
||||
this.signatureScheme = signatureScheme;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public byte[] getP() {
|
||||
return p;
|
||||
}
|
||||
|
||||
public byte[] getG() {
|
||||
return g;
|
||||
}
|
||||
|
||||
public byte[] getPubkey() {
|
||||
return pubkey;
|
||||
}
|
||||
|
||||
public SignatureScheme getSignatureScheme() {
|
||||
return signatureScheme;
|
||||
}
|
||||
|
||||
public byte[] getSignature() {
|
||||
return signature;
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.keys;
|
||||
|
||||
import ru.serega6531.packmate.service.optimization.tls.keys.enums.CurveType;
|
||||
import ru.serega6531.packmate.service.optimization.tls.keys.enums.NamedCurve;
|
||||
import ru.serega6531.packmate.service.optimization.tls.keys.enums.SignatureScheme;
|
||||
|
||||
public class EcdheServerParams {
|
||||
|
||||
private final CurveType curveType;
|
||||
private final NamedCurve namedCurve;
|
||||
private final byte[] pubkey;
|
||||
private final SignatureScheme signatureScheme;
|
||||
private final byte[] signature;
|
||||
|
||||
public EcdheServerParams(CurveType curveType, NamedCurve namedCurve, byte[] pubkey,
|
||||
SignatureScheme signatureScheme,
|
||||
byte[] signature) {
|
||||
this.curveType = curveType;
|
||||
this.namedCurve = namedCurve;
|
||||
this.pubkey = pubkey;
|
||||
this.signatureScheme = signatureScheme;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public CurveType getCurveType() {
|
||||
return curveType;
|
||||
}
|
||||
|
||||
public NamedCurve getNamedCurve() {
|
||||
return namedCurve;
|
||||
}
|
||||
|
||||
public byte[] getPubkey() {
|
||||
return pubkey;
|
||||
}
|
||||
|
||||
public SignatureScheme getSignatureScheme() {
|
||||
return signatureScheme;
|
||||
}
|
||||
|
||||
public byte[] getSignature() {
|
||||
return signature;
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.keys;
|
||||
|
||||
import ru.serega6531.packmate.service.optimization.tls.keys.enums.CurveType;
|
||||
import ru.serega6531.packmate.service.optimization.tls.keys.enums.NamedCurve;
|
||||
import ru.serega6531.packmate.service.optimization.tls.keys.enums.SignatureScheme;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* Формат ключа нельзя определить только по записи KeyExchange.
|
||||
* Этот класс разбирает параметры ключей в TLS-трафике.
|
||||
*/
|
||||
public final class TlsKeyUtils {
|
||||
|
||||
// https://wiki.osdev.org/TLS_Handshake
|
||||
|
||||
public static DhClientParams parseServerDH(byte[] rawData, int offset) {
|
||||
ByteBuffer bb = ByteBuffer.wrap(rawData).position(offset);
|
||||
|
||||
short pLength = bb.getShort();
|
||||
byte[] p = new byte[pLength];
|
||||
bb.get(p);
|
||||
|
||||
short gLength = bb.getShort();
|
||||
byte[] g = new byte[gLength];
|
||||
bb.get(g);
|
||||
|
||||
short pubKeyLength = bb.getShort();
|
||||
byte[] pubKey = new byte[pubKeyLength]; // Значение Ys.
|
||||
bb.get(pubKey);
|
||||
|
||||
SignatureScheme signatureScheme = SignatureScheme.findByValue(bb.getShort());
|
||||
|
||||
if (signatureScheme == null) {
|
||||
throw new IllegalArgumentException("Неизвестный алгоритм подписи.");
|
||||
}
|
||||
|
||||
short signatureLength = bb.getShort();
|
||||
byte[] signature = new byte[signatureLength];
|
||||
|
||||
bb.get(signature);
|
||||
|
||||
return new DhClientParams(p, g, pubKey, signatureScheme, signature);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rawData содержимое записи рукопожатия
|
||||
*/
|
||||
public static EcdheServerParams parseServerECDHE(byte[] rawData, int offset) {
|
||||
ByteBuffer bb = ByteBuffer.wrap(rawData).position(offset);
|
||||
|
||||
byte curveTypeId = bb.get();
|
||||
if(curveTypeId != 0x03) {
|
||||
throw new IllegalArgumentException("Тип эллиптической кривой не поддерживается.");
|
||||
}
|
||||
|
||||
CurveType curveType = CurveType.NAMED;
|
||||
NamedCurve namedCurve = NamedCurve.findByValue(bb.getShort());
|
||||
|
||||
if (namedCurve == null) {
|
||||
throw new IllegalArgumentException("Именованная эллиптическая кривая не поддерживается.");
|
||||
}
|
||||
|
||||
byte pubkeyLength = bb.get();
|
||||
byte[] pubkey = new byte[pubkeyLength];
|
||||
bb.get(pubkey);
|
||||
|
||||
SignatureScheme signatureScheme = SignatureScheme.findByValue(bb.getShort());
|
||||
|
||||
if (signatureScheme == null) {
|
||||
throw new IllegalArgumentException("Неизвестный алгоритм подписи.");
|
||||
}
|
||||
|
||||
short signatureLength = bb.getShort();
|
||||
byte[] signature = new byte[signatureLength];
|
||||
|
||||
bb.get(signature);
|
||||
|
||||
return new EcdheServerParams(curveType, namedCurve, pubkey, signatureScheme, signature);
|
||||
}
|
||||
|
||||
// https://ldapwiki.com/wiki/ClientKeyExchange
|
||||
|
||||
/**
|
||||
* Подходит для DH и ECDHE.
|
||||
* @param rawData содержимое записи рукопожатия
|
||||
*/
|
||||
public static byte[] getClientDHPubkey(byte[] rawData, int offset) {
|
||||
ByteBuffer bb = ByteBuffer.wrap(rawData).position(offset);
|
||||
|
||||
byte length = bb.get();
|
||||
byte[] pubkey = new byte[length];
|
||||
bb.get(pubkey);
|
||||
|
||||
return pubkey;
|
||||
}
|
||||
|
||||
public static byte[] getClientRsaPreMaster(byte[] rawData, int offset) {
|
||||
ByteBuffer bb = ByteBuffer.wrap(rawData).position(offset);
|
||||
|
||||
int length = bb.getShort();
|
||||
byte[] encryptedPreMaster = new byte[length];
|
||||
bb.get(encryptedPreMaster);
|
||||
|
||||
return encryptedPreMaster;
|
||||
}
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.keys.enums;
|
||||
|
||||
public enum CurveType {
|
||||
|
||||
NAMED((byte) 0x03);
|
||||
|
||||
private final byte value;
|
||||
|
||||
CurveType(byte value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public byte getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.keys.enums;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum NamedCurve {
|
||||
|
||||
SECT163K1((short) 1),
|
||||
SECT163R1((short) 2),
|
||||
SECT163R2((short) 3),
|
||||
SECT193R1((short) 4),
|
||||
SECT193R2((short) 5),
|
||||
SECT233K1((short) 6),
|
||||
SECT233R1((short) 7),
|
||||
SECT239K1((short) 8),
|
||||
SECT283K1((short) 9),
|
||||
SECT283R1((short) 10),
|
||||
SECT409K1((short) 11),
|
||||
SECT409R1((short) 12),
|
||||
SECT571K1((short) 13),
|
||||
SECT571R1((short) 14),
|
||||
SECP160K1((short) 15),
|
||||
SECP160R1((short) 16),
|
||||
SECP160R2((short) 17),
|
||||
SECP192K1((short) 18),
|
||||
SECP192R1((short) 19),
|
||||
SECP224K1((short) 20),
|
||||
SECP224R1((short) 21),
|
||||
SECP256K1((short) 22),
|
||||
SECP256R1((short) 23),
|
||||
SECP384R1((short) 24),
|
||||
SECP521R1((short) 25),
|
||||
X25519((short) 29),
|
||||
X448((short) 30);
|
||||
|
||||
private final short value;
|
||||
|
||||
private static final Map<Short, NamedCurve> map = new HashMap<>();
|
||||
|
||||
NamedCurve(short value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
static {
|
||||
for (NamedCurve curve : values()) {
|
||||
map.put(curve.getValue(), curve);
|
||||
}
|
||||
}
|
||||
|
||||
public short getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static NamedCurve findByValue(short value) {
|
||||
return map.get(value);
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.keys.enums;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum SignatureScheme {
|
||||
|
||||
/* Алгоритмы RSASSA-PKCS1-v1_5. */
|
||||
RSA_PKCS1_SHA256((short) 0x0401),
|
||||
RSA_PKCS1_SHA384((short) 0x0501),
|
||||
RSA_PKCS1_SHA512((short) 0x0601),
|
||||
|
||||
/* Алгоритмы ECDSA. */
|
||||
ECDSA_SECP256R1_SHA256((short) 0x0403),
|
||||
ECDSA_SECP384R1_SHA384((short) 0x0503),
|
||||
ECDSA_SECP521R1_SHA512((short) 0x0603),
|
||||
|
||||
/* Алгоритмы RSASSA-PSS с открытым ключом OID RSAEncryption. */
|
||||
RSA_PSS_RSAE_SHA256((short) 0x0804),
|
||||
RSA_PSS_RSAE_SHA384((short) 0x0805),
|
||||
RSA_PSS_RSAE_SHA512((short) 0x0806),
|
||||
|
||||
/* Алгоритмы EdDSA. */
|
||||
ED25519((short) 0x0807),
|
||||
ED448((short) 0x0808),
|
||||
|
||||
/* Алгоритмы RSASSA-PSS с открытым ключом OID RSASSA-PSS. */
|
||||
RSA_PSS_PSS_SHA256((short) 0x0809),
|
||||
RSA_PSS_PSS_SHA384((short) 0x080a),
|
||||
RSA_PSS_PSS_SHA512((short) 0x080b),
|
||||
|
||||
/* Устаревшие алгоритмы. */
|
||||
RSA_PKCS1_SHA1((short) 0x0201),
|
||||
ECDSA_SHA1((short) 0x0203);
|
||||
|
||||
private final short value;
|
||||
|
||||
private static final Map<Short, SignatureScheme> map = new HashMap<>();
|
||||
|
||||
SignatureScheme(short value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
static {
|
||||
for (SignatureScheme curve : values()) {
|
||||
map.put(curve.getValue(), curve);
|
||||
}
|
||||
}
|
||||
|
||||
public short getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static SignatureScheme findByValue(short value) {
|
||||
return map.get(value);
|
||||
}
|
||||
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.numbers;
|
||||
|
||||
import org.pcap4j.packet.namednumber.NamedNumber;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AlertDescription extends NamedNumber<Byte, AlertDescription> {
|
||||
|
||||
private static final Map<Byte, AlertDescription> registry = new HashMap<>();
|
||||
|
||||
public static AlertDescription close_notify = new AlertDescription((byte) 0, "close_notify");
|
||||
public static AlertDescription unexpected_message = new AlertDescription((byte) 10, "unexpected_message");
|
||||
public static AlertDescription bad_record_mac = new AlertDescription((byte) 20, "bad_record_mac");
|
||||
public static AlertDescription decryption_failed_RESERVED = new AlertDescription((byte) 21, "decryption_failed_RESERVED");
|
||||
public static AlertDescription record_overflow = new AlertDescription((byte) 22, "record_overflow");
|
||||
public static AlertDescription decompression_failure_RESERVED = new AlertDescription((byte) 30, "decompression_failure_RESERVED");
|
||||
public static AlertDescription handshake_failure = new AlertDescription((byte) 40, "handshake_failure");
|
||||
public static AlertDescription no_certificate_RESERVED = new AlertDescription((byte) 41, "no_certificate_RESERVED");
|
||||
public static AlertDescription bad_certificate = new AlertDescription((byte) 42, "bad_certificate");
|
||||
public static AlertDescription unsupported_certificate = new AlertDescription((byte) 43, "unsupported_certificate");
|
||||
public static AlertDescription certificate_revoked = new AlertDescription((byte) 44, "certificate_revoked");
|
||||
public static AlertDescription certificate_expired = new AlertDescription((byte) 45, "certificate_expired");
|
||||
public static AlertDescription certificate_unknown = new AlertDescription((byte) 46, "certificate_unknown");
|
||||
public static AlertDescription illegal_parameter = new AlertDescription((byte) 47, "illegal_parameter");
|
||||
public static AlertDescription unknown_ca = new AlertDescription((byte) 48, "unknown_ca");
|
||||
public static AlertDescription access_denied = new AlertDescription((byte) 49, "access_denied");
|
||||
public static AlertDescription decode_error = new AlertDescription((byte) 50, "decode_error");
|
||||
public static AlertDescription decrypt_error = new AlertDescription((byte) 51, "decrypt_error");
|
||||
public static AlertDescription export_restriction_RESERVED = new AlertDescription((byte) 60, "export_restriction_RESERVED");
|
||||
public static AlertDescription protocol_version = new AlertDescription((byte) 70, "protocol_version");
|
||||
public static AlertDescription insufficient_security = new AlertDescription((byte) 71, "insufficient_security");
|
||||
public static AlertDescription internal_error = new AlertDescription((byte) 80, "internal_error");
|
||||
public static AlertDescription inappropriate_fallback = new AlertDescription((byte) 86, "inappropriate_fallback");
|
||||
public static AlertDescription user_canceled = new AlertDescription((byte) 90, "user_canceled");
|
||||
public static AlertDescription no_renegotiation_RESERVED = new AlertDescription((byte) 100, "no_renegotiation_RESERVED");
|
||||
public static AlertDescription missing_extension = new AlertDescription((byte) 109, "missing_extension");
|
||||
public static AlertDescription unsupported_extension = new AlertDescription((byte) 110, "unsupported_extension");
|
||||
public static AlertDescription certificate_unobtainable_RESERVED = new AlertDescription((byte) 111, "certificate_unobtainable_RESERVED");
|
||||
public static AlertDescription unrecognized_name = new AlertDescription((byte) 112, "unrecognized_name");
|
||||
public static AlertDescription bad_certificate_status_response = new AlertDescription((byte) 113, "bad_certificate_status_response");
|
||||
public static AlertDescription bad_certificate_hash_value_RESERVED = new AlertDescription((byte) 114, "bad_certificate_hash_value_RESERVED");
|
||||
public static AlertDescription unknown_psk_identity = new AlertDescription((byte) 115, "unknown_psk_identity");
|
||||
public static AlertDescription certificate_required = new AlertDescription((byte) 116, "certificate_required");
|
||||
public static AlertDescription no_application_protocol = new AlertDescription((byte) 120, "no_application_protocol");
|
||||
|
||||
public AlertDescription(Byte value, String name) {
|
||||
super(value, name);
|
||||
registry.put(value, this);
|
||||
}
|
||||
|
||||
public static AlertDescription getInstance(Byte value) {
|
||||
if (registry.containsKey(value)) {
|
||||
return registry.get(value);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Неизвестное описание предупреждения TLS: " + value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(AlertDescription o) {
|
||||
return value().compareTo(o.value());
|
||||
}
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.numbers;
|
||||
|
||||
import org.pcap4j.packet.namednumber.NamedNumber;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class AlertLevel extends NamedNumber<Byte, AlertLevel> {
|
||||
|
||||
private static final Map<Byte, AlertLevel> registry = new HashMap<>();
|
||||
|
||||
public static final AlertLevel WARNING = new AlertLevel((byte) 1, "warning");
|
||||
public static final AlertLevel FATAL = new AlertLevel((byte) 2, "fatal");
|
||||
|
||||
public static final AlertLevel ENCRYPTED_ALERT = new AlertLevel((byte) 0, "encrypted alert");
|
||||
|
||||
public AlertLevel(Byte value, String name) {
|
||||
super(value, name);
|
||||
registry.put(value, this);
|
||||
}
|
||||
|
||||
public static AlertLevel getInstance(Byte value) {
|
||||
return registry.getOrDefault(value, ENCRYPTED_ALERT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(AlertLevel o) {
|
||||
return value().compareTo(o.value());
|
||||
}
|
||||
|
||||
}
|
||||
+741
@@ -0,0 +1,741 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.numbers;
|
||||
|
||||
import org.pcap4j.packet.namednumber.NamedNumber;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class CipherSuite extends NamedNumber<Short, CipherSuite> {
|
||||
|
||||
private static final Map<Short, CipherSuite> registry = new HashMap<>();
|
||||
|
||||
// https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml
|
||||
|
||||
public static final CipherSuite TLS_NULL_WITH_NULL_NULL =
|
||||
new CipherSuite((short) 0x0000, "TLS_NULL_WITH_NULL_NULL");
|
||||
public static final CipherSuite TLS_RSA_WITH_NULL_MD5 =
|
||||
new CipherSuite((short) 0x0001, "TLS_RSA_WITH_NULL_MD5");
|
||||
public static final CipherSuite TLS_RSA_WITH_NULL_SHA =
|
||||
new CipherSuite((short) 0x0002, "TLS_RSA_WITH_NULL_SHA");
|
||||
public static final CipherSuite TLS_RSA_EXPORT_WITH_RC4_40_MD5 =
|
||||
new CipherSuite((short) 0x0003, "TLS_RSA_EXPORT_WITH_RC4_40_MD5");
|
||||
public static final CipherSuite TLS_RSA_WITH_RC4_128_MD5 =
|
||||
new CipherSuite((short) 0x0004, "TLS_RSA_WITH_RC4_128_MD5");
|
||||
public static final CipherSuite TLS_RSA_WITH_RC4_128_SHA =
|
||||
new CipherSuite((short) 0x0005, "TLS_RSA_WITH_RC4_128_SHA");
|
||||
public static final CipherSuite TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 =
|
||||
new CipherSuite((short) 0x0006, "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5");
|
||||
public static final CipherSuite TLS_RSA_WITH_IDEA_CBC_SHA =
|
||||
new CipherSuite((short) 0x0007, "TLS_RSA_WITH_IDEA_CBC_SHA");
|
||||
public static final CipherSuite TLS_RSA_EXPORT_WITH_DES40_CBC_SHA =
|
||||
new CipherSuite((short) 0x0008, "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA");
|
||||
public static final CipherSuite TLS_RSA_WITH_DES_CBC_SHA =
|
||||
new CipherSuite((short) 0x0009, "TLS_RSA_WITH_DES_CBC_SHA");
|
||||
public static final CipherSuite TLS_RSA_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0x000A, "TLS_RSA_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA =
|
||||
new CipherSuite((short) 0x000B, "TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_DES_CBC_SHA =
|
||||
new CipherSuite((short) 0x000C, "TLS_DH_DSS_WITH_DES_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0x000D, "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA =
|
||||
new CipherSuite((short) 0x000E, "TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_DES_CBC_SHA =
|
||||
new CipherSuite((short) 0x000F, "TLS_DH_RSA_WITH_DES_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0x0010, "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA =
|
||||
new CipherSuite((short) 0x0011, "TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_DES_CBC_SHA =
|
||||
new CipherSuite((short) 0x0012, "TLS_DHE_DSS_WITH_DES_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0x0013, "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA =
|
||||
new CipherSuite((short) 0x0014, "TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_DES_CBC_SHA =
|
||||
new CipherSuite((short) 0x0015, "TLS_DHE_RSA_WITH_DES_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0x0016, "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_anon_EXPORT_WITH_RC4_40_MD5 =
|
||||
new CipherSuite((short) 0x0017, "TLS_DH_anon_EXPORT_WITH_RC4_40_MD5");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_RC4_128_MD5 =
|
||||
new CipherSuite((short) 0x0018, "TLS_DH_anon_WITH_RC4_128_MD5");
|
||||
public static final CipherSuite TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA =
|
||||
new CipherSuite((short) 0x0019, "TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_DES_CBC_SHA =
|
||||
new CipherSuite((short) 0x001A, "TLS_DH_anon_WITH_DES_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0x001B, "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_KRB5_WITH_DES_CBC_SHA =
|
||||
new CipherSuite((short) 0x001E, "TLS_KRB5_WITH_DES_CBC_SHA");
|
||||
public static final CipherSuite TLS_KRB5_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0x001F, "TLS_KRB5_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_KRB5_WITH_RC4_128_SHA =
|
||||
new CipherSuite((short) 0x0020, "TLS_KRB5_WITH_RC4_128_SHA");
|
||||
public static final CipherSuite TLS_KRB5_WITH_IDEA_CBC_SHA =
|
||||
new CipherSuite((short) 0x0021, "TLS_KRB5_WITH_IDEA_CBC_SHA");
|
||||
public static final CipherSuite TLS_KRB5_WITH_DES_CBC_MD5 =
|
||||
new CipherSuite((short) 0x0022, "TLS_KRB5_WITH_DES_CBC_MD5");
|
||||
public static final CipherSuite TLS_KRB5_WITH_3DES_EDE_CBC_MD5 =
|
||||
new CipherSuite((short) 0x0023, "TLS_KRB5_WITH_3DES_EDE_CBC_MD5");
|
||||
public static final CipherSuite TLS_KRB5_WITH_RC4_128_MD5 =
|
||||
new CipherSuite((short) 0x0024, "TLS_KRB5_WITH_RC4_128_MD5");
|
||||
public static final CipherSuite TLS_KRB5_WITH_IDEA_CBC_MD5 =
|
||||
new CipherSuite((short) 0x0025, "TLS_KRB5_WITH_IDEA_CBC_MD5");
|
||||
public static final CipherSuite TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA =
|
||||
new CipherSuite((short) 0x0026, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA");
|
||||
public static final CipherSuite TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA =
|
||||
new CipherSuite((short) 0x0027, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA");
|
||||
public static final CipherSuite TLS_KRB5_EXPORT_WITH_RC4_40_SHA =
|
||||
new CipherSuite((short) 0x0028, "TLS_KRB5_EXPORT_WITH_RC4_40_SHA");
|
||||
public static final CipherSuite TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5 =
|
||||
new CipherSuite((short) 0x0029, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5");
|
||||
public static final CipherSuite TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5 =
|
||||
new CipherSuite((short) 0x002A, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5");
|
||||
public static final CipherSuite TLS_KRB5_EXPORT_WITH_RC4_40_MD5 =
|
||||
new CipherSuite((short) 0x002B, "TLS_KRB5_EXPORT_WITH_RC4_40_MD5");
|
||||
public static final CipherSuite TLS_PSK_WITH_NULL_SHA =
|
||||
new CipherSuite((short) 0x002C, "TLS_PSK_WITH_NULL_SHA");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_NULL_SHA =
|
||||
new CipherSuite((short) 0x002D, "TLS_DHE_PSK_WITH_NULL_SHA");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_NULL_SHA =
|
||||
new CipherSuite((short) 0x002E, "TLS_RSA_PSK_WITH_NULL_SHA");
|
||||
public static final CipherSuite TLS_RSA_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0x002F, "TLS_RSA_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0x0030, "TLS_DH_DSS_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0x0031, "TLS_DH_RSA_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0x0032, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0x0033, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0x0034, "TLS_DH_anon_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_RSA_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0x0035, "TLS_RSA_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0x0036, "TLS_DH_DSS_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0x0037, "TLS_DH_RSA_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0x0038, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0x0039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0x003A, "TLS_DH_anon_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_RSA_WITH_NULL_SHA256 =
|
||||
new CipherSuite((short) 0x003B, "TLS_RSA_WITH_NULL_SHA256");
|
||||
public static final CipherSuite TLS_RSA_WITH_AES_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x003C, "TLS_RSA_WITH_AES_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_RSA_WITH_AES_256_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x003D, "TLS_RSA_WITH_AES_256_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_AES_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x003E, "TLS_DH_DSS_WITH_AES_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_AES_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x003F, "TLS_DH_RSA_WITH_AES_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x0040, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_RSA_WITH_CAMELLIA_128_CBC_SHA =
|
||||
new CipherSuite((short) 0x0041, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA =
|
||||
new CipherSuite((short) 0x0042, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA =
|
||||
new CipherSuite((short) 0x0043, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA =
|
||||
new CipherSuite((short) 0x0044, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA =
|
||||
new CipherSuite((short) 0x0045, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA =
|
||||
new CipherSuite((short) 0x0046, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x0067, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_AES_256_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x0068, "TLS_DH_DSS_WITH_AES_256_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_AES_256_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x0069, "TLS_DH_RSA_WITH_AES_256_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x006A, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x006B, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_AES_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x006C, "TLS_DH_anon_WITH_AES_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_AES_256_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x006D, "TLS_DH_anon_WITH_AES_256_CBC_SHA256");
|
||||
public static final CipherSuite TLS_RSA_WITH_CAMELLIA_256_CBC_SHA =
|
||||
new CipherSuite((short) 0x0084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA =
|
||||
new CipherSuite((short) 0x0085, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA =
|
||||
new CipherSuite((short) 0x0086, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA =
|
||||
new CipherSuite((short) 0x0087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA =
|
||||
new CipherSuite((short) 0x0088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA =
|
||||
new CipherSuite((short) 0x0089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_PSK_WITH_RC4_128_SHA =
|
||||
new CipherSuite((short) 0x008A, "TLS_PSK_WITH_RC4_128_SHA");
|
||||
public static final CipherSuite TLS_PSK_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0x008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_PSK_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0x008C, "TLS_PSK_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_PSK_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0x008D, "TLS_PSK_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_RC4_128_SHA =
|
||||
new CipherSuite((short) 0x008E, "TLS_DHE_PSK_WITH_RC4_128_SHA");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0x008F, "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0x0090, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0x0091, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_RC4_128_SHA =
|
||||
new CipherSuite((short) 0x0092, "TLS_RSA_PSK_WITH_RC4_128_SHA");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0x0093, "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0x0094, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0x0095, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_RSA_WITH_SEED_CBC_SHA =
|
||||
new CipherSuite((short) 0x0096, "TLS_RSA_WITH_SEED_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_SEED_CBC_SHA =
|
||||
new CipherSuite((short) 0x0097, "TLS_DH_DSS_WITH_SEED_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_SEED_CBC_SHA =
|
||||
new CipherSuite((short) 0x0098, "TLS_DH_RSA_WITH_SEED_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_SEED_CBC_SHA =
|
||||
new CipherSuite((short) 0x0099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_SEED_CBC_SHA =
|
||||
new CipherSuite((short) 0x009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_SEED_CBC_SHA =
|
||||
new CipherSuite((short) 0x009B, "TLS_DH_anon_WITH_SEED_CBC_SHA");
|
||||
public static final CipherSuite TLS_RSA_WITH_AES_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0x009C, "TLS_RSA_WITH_AES_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_RSA_WITH_AES_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0x009D, "TLS_RSA_WITH_AES_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0x009E, "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0x009F, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_AES_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0x00A0, "TLS_DH_RSA_WITH_AES_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_AES_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0x00A1, "TLS_DH_RSA_WITH_AES_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_AES_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0x00A2, "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_AES_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0x00A3, "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_AES_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0x00A4, "TLS_DH_DSS_WITH_AES_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_AES_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0x00A5, "TLS_DH_DSS_WITH_AES_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_AES_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0x00A6, "TLS_DH_anon_WITH_AES_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_AES_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0x00A7, "TLS_DH_anon_WITH_AES_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_PSK_WITH_AES_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0x00A8, "TLS_PSK_WITH_AES_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_PSK_WITH_AES_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0x00A9, "TLS_PSK_WITH_AES_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0x00AA, "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0x00AB, "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0x00AC, "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0x00AD, "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_PSK_WITH_AES_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x00AE, "TLS_PSK_WITH_AES_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_PSK_WITH_AES_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0x00AF, "TLS_PSK_WITH_AES_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_PSK_WITH_NULL_SHA256 =
|
||||
new CipherSuite((short) 0x00B0, "TLS_PSK_WITH_NULL_SHA256");
|
||||
public static final CipherSuite TLS_PSK_WITH_NULL_SHA384 =
|
||||
new CipherSuite((short) 0x00B1, "TLS_PSK_WITH_NULL_SHA384");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x00B2, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0x00B3, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_NULL_SHA256 =
|
||||
new CipherSuite((short) 0x00B4, "TLS_DHE_PSK_WITH_NULL_SHA256");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_NULL_SHA384 =
|
||||
new CipherSuite((short) 0x00B5, "TLS_DHE_PSK_WITH_NULL_SHA384");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x00B6, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0x00B7, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_NULL_SHA256 =
|
||||
new CipherSuite((short) 0x00B8, "TLS_RSA_PSK_WITH_NULL_SHA256");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_NULL_SHA384 =
|
||||
new CipherSuite((short) 0x00B9, "TLS_RSA_PSK_WITH_NULL_SHA384");
|
||||
public static final CipherSuite TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x00BA, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x00BB, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x00BC, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x00BD, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x00BE, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x00BF, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x00C0, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x00C1, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x00C2, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x00C3, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x00C4, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256 =
|
||||
new CipherSuite((short) 0x00C5, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256");
|
||||
public static final CipherSuite TLS_EMPTY_RENEGOTIATION_INFO_SCSV =
|
||||
new CipherSuite((short) 0x00FF, "TLS_EMPTY_RENEGOTIATION_INFO_SCSV");
|
||||
public static final CipherSuite RESERVED_GREASE_0x0A0A =
|
||||
new CipherSuite((short) 0x0A0A, "Reserved (GREASE)");
|
||||
public static final CipherSuite TLS_AES_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0x1301, "TLS_AES_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_AES_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0x1302, "TLS_AES_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_CHACHA20_POLY1305_SHA256 =
|
||||
new CipherSuite((short) 0x1303, "TLS_CHACHA20_POLY1305_SHA256");
|
||||
public static final CipherSuite TLS_AES_128_CCM_SHA256 =
|
||||
new CipherSuite((short) 0x1304, "TLS_AES_128_CCM_SHA256");
|
||||
public static final CipherSuite RESERVED_GREASE_0x1A1A =
|
||||
new CipherSuite((short) 0x1A1A, "Reserved (GREASE)");
|
||||
public static final CipherSuite RESERVED_GREASE_0x2A2A =
|
||||
new CipherSuite((short) 0x2A2A, "Reserved (GREASE)");
|
||||
public static final CipherSuite RESERVED_GREASE_0x3A3A =
|
||||
new CipherSuite((short) 0x3A3A, "Reserved (GREASE)");
|
||||
public static final CipherSuite RESERVED_GREASE_0x4A4A =
|
||||
new CipherSuite((short) 0x4A4A, "Reserved (GREASE)");
|
||||
public static final CipherSuite TLS_FALLBACK_SCSV =
|
||||
new CipherSuite((short) 0x5600, "TLS_FALLBACK_SCSV");
|
||||
public static final CipherSuite RESERVED_GREASE_0x5A5A =
|
||||
new CipherSuite((short) 0x5A5A, "Reserved (GREASE)");
|
||||
public static final CipherSuite RESERVED_GREASE_0x6A6A =
|
||||
new CipherSuite((short) 0x6A6A, "Reserved (GREASE)");
|
||||
public static final CipherSuite RESERVED_GREASE_0x7A7A =
|
||||
new CipherSuite((short) 0x7A7A, "Reserved (GREASE)");
|
||||
public static final CipherSuite RESERVED_GREASE_0x8A8A =
|
||||
new CipherSuite((short) 0x8A8A, "Reserved (GREASE)");
|
||||
public static final CipherSuite RESERVED_GREASE_0x9A9A =
|
||||
new CipherSuite((short) 0x9A9A, "Reserved (GREASE)");
|
||||
public static final CipherSuite RESERVED_GREASE_0xAAAA =
|
||||
new CipherSuite((short) 0xAAAA, "Reserved (GREASE)");
|
||||
public static final CipherSuite RESERVED_GREASE_0xBABA =
|
||||
new CipherSuite((short) 0xBABA, "Reserved (GREASE)");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_NULL_SHA =
|
||||
new CipherSuite((short) 0xC001, "TLS_ECDH_ECDSA_WITH_NULL_SHA");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_RC4_128_SHA =
|
||||
new CipherSuite((short) 0xC002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0xC003, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0xC004, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0xC005, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_NULL_SHA =
|
||||
new CipherSuite((short) 0xC006, "TLS_ECDHE_ECDSA_WITH_NULL_SHA");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_RC4_128_SHA =
|
||||
new CipherSuite((short) 0xC007, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0xC008, "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0xC009, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0xC00A, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_NULL_SHA =
|
||||
new CipherSuite((short) 0xC00B, "TLS_ECDH_RSA_WITH_NULL_SHA");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_RC4_128_SHA =
|
||||
new CipherSuite((short) 0xC00C, "TLS_ECDH_RSA_WITH_RC4_128_SHA");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0xC00D, "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0xC00E, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0xC00F, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_NULL_SHA =
|
||||
new CipherSuite((short) 0xC010, "TLS_ECDHE_RSA_WITH_NULL_SHA");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_RC4_128_SHA =
|
||||
new CipherSuite((short) 0xC011, "TLS_ECDHE_RSA_WITH_RC4_128_SHA");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0xC012, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0xC013, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0xC014, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDH_anon_WITH_NULL_SHA =
|
||||
new CipherSuite((short) 0xC015, "TLS_ECDH_anon_WITH_NULL_SHA");
|
||||
public static final CipherSuite TLS_ECDH_anon_WITH_RC4_128_SHA =
|
||||
new CipherSuite((short) 0xC016, "TLS_ECDH_anon_WITH_RC4_128_SHA");
|
||||
public static final CipherSuite TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0xC017, "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDH_anon_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0xC018, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDH_anon_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0xC019, "TLS_ECDH_anon_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0xC01A, "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0xC01B, "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0xC01C, "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_SRP_SHA_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0xC01D, "TLS_SRP_SHA_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0xC01E, "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0xC01F, "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_SRP_SHA_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0xC020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0xC021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0xC022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC023, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC024, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC025, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC026, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC027, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC028, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC029, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC02A, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC02B, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC02C, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC02D, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC02E, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC02F, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC030, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC031, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC032, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_RC4_128_SHA =
|
||||
new CipherSuite((short) 0xC033, "TLS_ECDHE_PSK_WITH_RC4_128_SHA");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA =
|
||||
new CipherSuite((short) 0xC034, "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA =
|
||||
new CipherSuite((short) 0xC035, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA =
|
||||
new CipherSuite((short) 0xC036, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC037, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC038, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_NULL_SHA =
|
||||
new CipherSuite((short) 0xC039, "TLS_ECDHE_PSK_WITH_NULL_SHA");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_NULL_SHA256 =
|
||||
new CipherSuite((short) 0xC03A, "TLS_ECDHE_PSK_WITH_NULL_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_NULL_SHA384 =
|
||||
new CipherSuite((short) 0xC03B, "TLS_ECDHE_PSK_WITH_NULL_SHA384");
|
||||
public static final CipherSuite TLS_RSA_WITH_ARIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC03C, "TLS_RSA_WITH_ARIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_RSA_WITH_ARIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC03D, "TLS_RSA_WITH_ARIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_ARIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC03E, "TLS_DH_DSS_WITH_ARIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_ARIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC03F, "TLS_DH_DSS_WITH_ARIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_ARIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC040, "TLS_DH_RSA_WITH_ARIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_ARIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC041, "TLS_DH_RSA_WITH_ARIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_ARIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC042, "TLS_DHE_DSS_WITH_ARIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_ARIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC043, "TLS_DHE_DSS_WITH_ARIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC044, "TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC045, "TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_ARIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC046, "TLS_DH_anon_WITH_ARIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_ARIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC047, "TLS_DH_anon_WITH_ARIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC048, "TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC049, "TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC04A, "TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC04B, "TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC04C, "TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC04D, "TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC04E, "TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC04F, "TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_RSA_WITH_ARIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC050, "TLS_RSA_WITH_ARIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_RSA_WITH_ARIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC051, "TLS_RSA_WITH_ARIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC052, "TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC053, "TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_ARIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC054, "TLS_DH_RSA_WITH_ARIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_ARIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC055, "TLS_DH_RSA_WITH_ARIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_ARIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC056, "TLS_DHE_DSS_WITH_ARIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_ARIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC057, "TLS_DHE_DSS_WITH_ARIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_ARIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC058, "TLS_DH_DSS_WITH_ARIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_ARIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC059, "TLS_DH_DSS_WITH_ARIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_ARIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC05A, "TLS_DH_anon_WITH_ARIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_ARIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC05B, "TLS_DH_anon_WITH_ARIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC05C, "TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC05D, "TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC05E, "TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC05F, "TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC060, "TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC061, "TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC062, "TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC063, "TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_PSK_WITH_ARIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC064, "TLS_PSK_WITH_ARIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_PSK_WITH_ARIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC065, "TLS_PSK_WITH_ARIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC066, "TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC067, "TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC068, "TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC069, "TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_PSK_WITH_ARIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC06A, "TLS_PSK_WITH_ARIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_PSK_WITH_ARIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC06B, "TLS_PSK_WITH_ARIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC06C, "TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC06D, "TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC06E, "TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC06F, "TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC070, "TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC071, "TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC072, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC073, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC074, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC075, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC076, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC077, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC078, "TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC079, "TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC07A, "TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC07B, "TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC07C, "TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC07D, "TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC07E, "TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC07F, "TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC080, "TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC081, "TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC082, "TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC083, "TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC084, "TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC085, "TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC086, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC087, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC088, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC089, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC08A, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC08B, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC08C, "TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC08D, "TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC08E, "TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC08F, "TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC090, "TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC091, "TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC092, "TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC093, "TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC094, "TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC095, "TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC096, "TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC097, "TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC098, "TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC099, "TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 =
|
||||
new CipherSuite((short) 0xC09A, "TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 =
|
||||
new CipherSuite((short) 0xC09B, "TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384");
|
||||
public static final CipherSuite TLS_RSA_WITH_AES_128_CCM =
|
||||
new CipherSuite((short) 0xC09C, "TLS_RSA_WITH_AES_128_CCM");
|
||||
public static final CipherSuite TLS_RSA_WITH_AES_256_CCM =
|
||||
new CipherSuite((short) 0xC09D, "TLS_RSA_WITH_AES_256_CCM");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_AES_128_CCM =
|
||||
new CipherSuite((short) 0xC09E, "TLS_DHE_RSA_WITH_AES_128_CCM");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_AES_256_CCM =
|
||||
new CipherSuite((short) 0xC09F, "TLS_DHE_RSA_WITH_AES_256_CCM");
|
||||
public static final CipherSuite TLS_RSA_WITH_AES_128_CCM_8 =
|
||||
new CipherSuite((short) 0xC0A0, "TLS_RSA_WITH_AES_128_CCM_8");
|
||||
public static final CipherSuite TLS_RSA_WITH_AES_256_CCM_8 =
|
||||
new CipherSuite((short) 0xC0A1, "TLS_RSA_WITH_AES_256_CCM_8");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_AES_128_CCM_8 =
|
||||
new CipherSuite((short) 0xC0A2, "TLS_DHE_RSA_WITH_AES_128_CCM_8");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_AES_256_CCM_8 =
|
||||
new CipherSuite((short) 0xC0A3, "TLS_DHE_RSA_WITH_AES_256_CCM_8");
|
||||
public static final CipherSuite TLS_PSK_WITH_AES_128_CCM =
|
||||
new CipherSuite((short) 0xC0A4, "TLS_PSK_WITH_AES_128_CCM");
|
||||
public static final CipherSuite TLS_PSK_WITH_AES_256_CCM =
|
||||
new CipherSuite((short) 0xC0A5, "TLS_PSK_WITH_AES_256_CCM");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_AES_128_CCM =
|
||||
new CipherSuite((short) 0xC0A6, "TLS_DHE_PSK_WITH_AES_128_CCM");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_AES_256_CCM =
|
||||
new CipherSuite((short) 0xC0A7, "TLS_DHE_PSK_WITH_AES_256_CCM");
|
||||
public static final CipherSuite TLS_PSK_WITH_AES_128_CCM_8 =
|
||||
new CipherSuite((short) 0xC0A8, "TLS_PSK_WITH_AES_128_CCM_8");
|
||||
public static final CipherSuite TLS_PSK_WITH_AES_256_CCM_8 =
|
||||
new CipherSuite((short) 0xC0A9, "TLS_PSK_WITH_AES_256_CCM_8");
|
||||
public static final CipherSuite TLS_PSK_DHE_WITH_AES_128_CCM_8 =
|
||||
new CipherSuite((short) 0xC0AA, "TLS_PSK_DHE_WITH_AES_128_CCM_8");
|
||||
public static final CipherSuite TLS_PSK_DHE_WITH_AES_256_CCM_8 =
|
||||
new CipherSuite((short) 0xC0AB, "TLS_PSK_DHE_WITH_AES_256_CCM_8");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_128_CCM =
|
||||
new CipherSuite((short) 0xC0AC, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_256_CCM =
|
||||
new CipherSuite((short) 0xC0AD, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 =
|
||||
new CipherSuite((short) 0xC0AE, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 =
|
||||
new CipherSuite((short) 0xC0AF, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8");
|
||||
public static final CipherSuite TLS_ECCPWD_WITH_AES_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xC0B0, "TLS_ECCPWD_WITH_AES_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_ECCPWD_WITH_AES_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xC0B1, "TLS_ECCPWD_WITH_AES_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_ECCPWD_WITH_AES_128_CCM_SHA256 =
|
||||
new CipherSuite((short) 0xC0B2, "TLS_ECCPWD_WITH_AES_128_CCM_SHA256");
|
||||
public static final CipherSuite TLS_ECCPWD_WITH_AES_256_CCM_SHA384 =
|
||||
new CipherSuite((short) 0xC0B3, "TLS_ECCPWD_WITH_AES_256_CCM_SHA384");
|
||||
public static final CipherSuite RESERVED_GREASE_0xCACA =
|
||||
new CipherSuite((short) 0xCACA, "Reserved (GREASE)");
|
||||
public static final CipherSuite TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 =
|
||||
new CipherSuite((short) 0xCCA8, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 =
|
||||
new CipherSuite((short) 0xCCA9, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256");
|
||||
public static final CipherSuite TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 =
|
||||
new CipherSuite((short) 0xCCAA, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256");
|
||||
public static final CipherSuite TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 =
|
||||
new CipherSuite((short) 0xCCAB, "TLS_PSK_WITH_CHACHA20_POLY1305_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 =
|
||||
new CipherSuite((short) 0xCCAC, "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256");
|
||||
public static final CipherSuite TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256 =
|
||||
new CipherSuite((short) 0xCCAD, "TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256");
|
||||
public static final CipherSuite TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256 =
|
||||
new CipherSuite((short) 0xCCAE, "TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256 =
|
||||
new CipherSuite((short) 0xD001, "TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384 =
|
||||
new CipherSuite((short) 0xD002, "TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_AES_128_CCM_8_SHA256 =
|
||||
new CipherSuite((short) 0xD003, "TLS_ECDHE_PSK_WITH_AES_128_CCM_8_SHA256");
|
||||
public static final CipherSuite TLS_ECDHE_PSK_WITH_AES_128_CCM_SHA256 =
|
||||
new CipherSuite((short) 0xD005, "TLS_ECDHE_PSK_WITH_AES_128_CCM_SHA256");
|
||||
public static final CipherSuite RESERVED_GREASE_0xDADA =
|
||||
new CipherSuite((short) 0xDADA, "Reserved (GREASE)");
|
||||
public static final CipherSuite RESERVED_GREASE_0xEAEA =
|
||||
new CipherSuite((short) 0xEAEA, "Reserved (GREASE)");
|
||||
public static final CipherSuite RESERVED_GREASE_0xFAFA =
|
||||
new CipherSuite((short) 0xFAFA, "Reserved (GREASE)");
|
||||
|
||||
public CipherSuite(Short value, String name) {
|
||||
super(value, name);
|
||||
registry.put(value, this);
|
||||
}
|
||||
|
||||
public static CipherSuite getInstance(Short value) {
|
||||
if (registry.containsKey(value)) {
|
||||
return registry.get(value);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Неизвестный набор шифров TLS: " + value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(CipherSuite o) {
|
||||
return value().compareTo(o.value());
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.numbers;
|
||||
|
||||
import org.pcap4j.packet.namednumber.NamedNumber;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CompressionMethod extends NamedNumber<Byte, CompressionMethod> {
|
||||
|
||||
// https://www.iana.org/assignments/comp-meth-ids/comp-meth-ids.xhtml
|
||||
|
||||
public static final CompressionMethod NULL = new CompressionMethod((byte) 0, "null");
|
||||
public static final CompressionMethod DEFLATE = new CompressionMethod((byte) 1, "Deflate");
|
||||
public static final CompressionMethod LZS = new CompressionMethod((byte) 64, "LZS");
|
||||
|
||||
private static final Map<Byte, CompressionMethod> registry = new HashMap<>();
|
||||
|
||||
static {
|
||||
registry.put(NULL.value(), NULL);
|
||||
}
|
||||
|
||||
public CompressionMethod(Byte value, String name) {
|
||||
super(value, name);
|
||||
}
|
||||
|
||||
public static CompressionMethod getInstance(Byte value) {
|
||||
if (registry.containsKey(value)) {
|
||||
return registry.get(value);
|
||||
} else {
|
||||
return new CompressionMethod(value, "Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(CompressionMethod o) {
|
||||
return value().compareTo(o.value());
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.numbers;
|
||||
|
||||
import org.pcap4j.packet.namednumber.NamedNumber;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ContentType extends NamedNumber<Byte, ContentType> {
|
||||
|
||||
// https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml
|
||||
|
||||
public static final ContentType CHANGE_CIPHER_SPEC = new ContentType((byte) 20, "Change Cipher Spec");
|
||||
public static final ContentType ALERT = new ContentType((byte) 21, "Alert");
|
||||
public static final ContentType HANDSHAKE = new ContentType((byte) 22, "Handshake");
|
||||
public static final ContentType APPLICATION_DATA = new ContentType((byte) 23, "Application Data");
|
||||
public static final ContentType HEARTBEAT = new ContentType((byte) 24, "Heartbeat");
|
||||
|
||||
private static final Map<Byte, ContentType> registry = new HashMap<>();
|
||||
|
||||
static {
|
||||
registry.put(CHANGE_CIPHER_SPEC.value(), CHANGE_CIPHER_SPEC);
|
||||
registry.put(ALERT.value(), ALERT);
|
||||
registry.put(HANDSHAKE.value(), HANDSHAKE);
|
||||
registry.put(APPLICATION_DATA.value(), APPLICATION_DATA);
|
||||
registry.put(HEARTBEAT.value(), HEARTBEAT);
|
||||
}
|
||||
|
||||
public ContentType(Byte value, String name) {
|
||||
super(value, name);
|
||||
}
|
||||
|
||||
public static ContentType getInstance(Byte value) {
|
||||
if (registry.containsKey(value)) {
|
||||
return registry.get(value);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Неизвестный тип записи TLS: " + value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ContentType o) {
|
||||
return value().compareTo(o.value());
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.numbers;
|
||||
|
||||
import org.pcap4j.packet.namednumber.NamedNumber;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ExtensionType extends NamedNumber<Short, ExtensionType> {
|
||||
|
||||
private static final Map<Short, ExtensionType> registry = new HashMap<>();
|
||||
|
||||
public static final ExtensionType SERVER_NAME = new ExtensionType((short) 0, "server_name");
|
||||
public static final ExtensionType MAX_FRAGMENT_LENGTH = new ExtensionType((short) 1, "max_fragment_length");
|
||||
public static final ExtensionType CLIENT_CERTIFICATE_URL = new ExtensionType((short) 2, "client_certificate_url");
|
||||
public static final ExtensionType TRUSTED_CA_KEYS = new ExtensionType((short) 3, "trusted_ca_keys");
|
||||
public static final ExtensionType TRUNCATED_HMAC = new ExtensionType((short) 4, "truncated_hmac");
|
||||
public static final ExtensionType STATUS_REQUEST = new ExtensionType((short) 5, "status_request");
|
||||
public static final ExtensionType USER_MAPPING = new ExtensionType((short) 6, "user_mapping");
|
||||
public static final ExtensionType CLIENT_AUTHZ = new ExtensionType((short) 7, "client_authz");
|
||||
public static final ExtensionType SERVER_AUTHZ = new ExtensionType((short) 8, "server_authz");
|
||||
public static final ExtensionType CERT_TYPE = new ExtensionType((short) 9, "cert_type");
|
||||
public static final ExtensionType SUPPORTED_GROUPS = new ExtensionType((short) 10, "supported_groups");
|
||||
public static final ExtensionType EC_POINT_FORMATS = new ExtensionType((short) 11, "ec_point_formats");
|
||||
public static final ExtensionType SRP = new ExtensionType((short) 12, "srp");
|
||||
public static final ExtensionType SIGNATURE_ALGORITHMS = new ExtensionType((short) 13, "signature_algorithms");
|
||||
public static final ExtensionType USE_SRTP = new ExtensionType((short) 14, "use_srtp");
|
||||
public static final ExtensionType HEARTBEAT = new ExtensionType((short) 15, "heartbeat");
|
||||
public static final ExtensionType APPLICATION_LAYER_PROTOCOL_NEGOTIATION = new ExtensionType((short) 16, "application_layer_protocol_negotiation");
|
||||
public static final ExtensionType STATUS_REQUEST_V2 = new ExtensionType((short) 17, "status_request_v2");
|
||||
public static final ExtensionType SIGNED_CERTIFICATE_TIMESTAMP = new ExtensionType((short) 18, "signed_certificate_timestamp");
|
||||
public static final ExtensionType CLIENT_CERTIFICATE_TYPE = new ExtensionType((short) 19, "client_certificate_type");
|
||||
public static final ExtensionType SERVER_CERTIFICATE_TYPE = new ExtensionType((short) 20, "server_certificate_type");
|
||||
public static final ExtensionType PADDING = new ExtensionType((short) 21, "padding");
|
||||
public static final ExtensionType ENCRYPT_THEN_MAC = new ExtensionType((short) 22, "encrypt_then_mac");
|
||||
public static final ExtensionType EXTENDED_MASTER_SECRET = new ExtensionType((short) 23, "extended_master_secret");
|
||||
public static final ExtensionType TOKEN_BINDING = new ExtensionType((short) 24, "token_binding");
|
||||
public static final ExtensionType CACHED_INFO = new ExtensionType((short) 25, "cached_info");
|
||||
public static final ExtensionType TLS_LTS = new ExtensionType((short) 26, "tls_lts");
|
||||
public static final ExtensionType COMPRESS_CERTIFICATE = new ExtensionType((short) 27, "compress_certificate");
|
||||
public static final ExtensionType RECORD_SIZE_LIMIT = new ExtensionType((short) 28, "record_size_limit");
|
||||
public static final ExtensionType PWD_PROTECT = new ExtensionType((short) 29, "pwd_protect");
|
||||
public static final ExtensionType PWD_CLEAR = new ExtensionType((short) 30, "pwd_clear");
|
||||
public static final ExtensionType PASSWORD_SALT = new ExtensionType((short) 31, "password_salt");
|
||||
public static final ExtensionType TICKET_PINNING = new ExtensionType((short) 32, "ticket_pinning");
|
||||
public static final ExtensionType TLS_CERT_WITH_EXTERN_PSK = new ExtensionType((short) 33, "tls_cert_with_extern_psk");
|
||||
public static final ExtensionType DELEGATED_CREDENTIALS = new ExtensionType((short) 34, "delegated_credentials");
|
||||
public static final ExtensionType SESSION_TICKET = new ExtensionType((short) 35, "session_ticket");
|
||||
public static final ExtensionType PRE_SHARED_KEY = new ExtensionType((short) 41, "pre_shared_key");
|
||||
public static final ExtensionType EARLY_DATA = new ExtensionType((short) 42, "early_data");
|
||||
public static final ExtensionType SUPPORTED_VERSIONS = new ExtensionType((short) 43, "supported_versions");
|
||||
public static final ExtensionType COOKIE = new ExtensionType((short) 44, "cookie");
|
||||
public static final ExtensionType PSK_KEY_EXCHANGE_MODES = new ExtensionType((short) 45, "psk_key_exchange_modes");
|
||||
public static final ExtensionType CERTIFICATE_AUTHORITIES = new ExtensionType((short) 47, "certificate_authorities");
|
||||
public static final ExtensionType OID_FILTERS = new ExtensionType((short) 48, "oid_filters");
|
||||
public static final ExtensionType POST_HANDSHAKE_AUTH = new ExtensionType((short) 49, "post_handshake_auth");
|
||||
public static final ExtensionType SIGNATURE_ALGORITHMS_CERT = new ExtensionType((short) 50, "signature_algorithms_cert");
|
||||
public static final ExtensionType KEY_SHARE = new ExtensionType((short) 51, "key_share");
|
||||
public static final ExtensionType TRANSPARENCY_INFO = new ExtensionType((short) 52, "transparency_info");
|
||||
public static final ExtensionType CONNECTION_ID = new ExtensionType((short) 53, "connection_id");
|
||||
public static final ExtensionType EXTERNAL_ID_HASH = new ExtensionType((short) 55, "external_id_hash");
|
||||
public static final ExtensionType EXTERNAL_SESSION_ID = new ExtensionType((short) 56, "external_session_id");
|
||||
public static final ExtensionType RESERVED_GREASE_2570 = new ExtensionType((short) 2570, "Reserved (GREASE)");
|
||||
public static final ExtensionType RESERVED_GREASE_6682 = new ExtensionType((short) 6682, "Reserved (GREASE)");
|
||||
public static final ExtensionType RESERVED_GREASE_10794 = new ExtensionType((short) 10794, "Reserved (GREASE)");
|
||||
public static final ExtensionType RESERVED_GREASE_14906 = new ExtensionType((short) 14906, "Reserved (GREASE)");
|
||||
public static final ExtensionType RESERVED_GREASE_19018 = new ExtensionType((short) 19018, "Reserved (GREASE)");
|
||||
public static final ExtensionType RESERVED_GREASE_23130 = new ExtensionType((short) 23130, "Reserved (GREASE)");
|
||||
public static final ExtensionType RESERVED_GREASE_27242 = new ExtensionType((short) 27242, "Reserved (GREASE)");
|
||||
public static final ExtensionType RESERVED_GREASE_31354 = new ExtensionType((short) 31354, "Reserved (GREASE)");
|
||||
public static final ExtensionType RESERVED_GREASE_35466 = new ExtensionType((short) 35466, "Reserved (GREASE)");
|
||||
public static final ExtensionType RESERVED_GREASE_39578 = new ExtensionType((short) 39578, "Reserved (GREASE)");
|
||||
public static final ExtensionType RESERVED_GREASE_43690 = new ExtensionType((short) 43690, "Reserved (GREASE)");
|
||||
public static final ExtensionType RESERVED_GREASE_47802 = new ExtensionType((short) 47802, "Reserved (GREASE)");
|
||||
public static final ExtensionType RESERVED_GREASE_51914 = new ExtensionType((short) 51914, "Reserved (GREASE)");
|
||||
public static final ExtensionType RESERVED_GREASE_56026 = new ExtensionType((short) 56026, "Reserved (GREASE)");
|
||||
public static final ExtensionType RESERVED_GREASE_60138 = new ExtensionType((short) 60138, "Reserved (GREASE)");
|
||||
public static final ExtensionType RESERVED_GREASE_64250 = new ExtensionType((short) 64250, "Reserved (GREASE)");
|
||||
public static final ExtensionType RENEGOTIATION_INFO = new ExtensionType((short) 65281, "renegotiation_info");
|
||||
|
||||
public ExtensionType(Short value, String name) {
|
||||
super(value, name);
|
||||
registry.put(value, this);
|
||||
}
|
||||
|
||||
public static ExtensionType getInstance(Short value) {
|
||||
if (registry.containsKey(value)) {
|
||||
return registry.get(value);
|
||||
} else {
|
||||
return new ExtensionType(value, "Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ExtensionType o) {
|
||||
return value().compareTo(o.value());
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.numbers;
|
||||
|
||||
import org.pcap4j.packet.namednumber.NamedNumber;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class HandshakeType extends NamedNumber<Byte, HandshakeType> {
|
||||
|
||||
private static final Map<Byte, HandshakeType> registry = new HashMap<>();
|
||||
|
||||
// https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml
|
||||
|
||||
public static final HandshakeType HELLO_REQUEST = new HandshakeType((byte) 0, "Hello Request");
|
||||
public static final HandshakeType CLIENT_HELLO = new HandshakeType((byte) 1, "Client Hello");
|
||||
public static final HandshakeType SERVER_HELLO = new HandshakeType((byte) 2, "Server Hello");
|
||||
public static final HandshakeType HELLO_VERIFY_REQUEST = new HandshakeType((byte) 3, "Hello Verify Request");
|
||||
public static final HandshakeType NEW_SESSION_TICKET = new HandshakeType((byte) 4, "New Session Ticket");
|
||||
public static final HandshakeType END_OF_EARLY_DATA = new HandshakeType((byte) 5, "End Of Early Data");
|
||||
public static final HandshakeType HELLO_RETRY_REQUEST = new HandshakeType((byte) 6, "Hello Retry Request");
|
||||
public static final HandshakeType ENCRYPTED_EXTENSIONS = new HandshakeType((byte) 8, "Encrypted Extensions");
|
||||
public static final HandshakeType CERTIFICATE = new HandshakeType((byte) 11, "Certificate");
|
||||
public static final HandshakeType SERVER_KEY_EXCHANGE = new HandshakeType((byte) 12, "Server Key Excange");
|
||||
public static final HandshakeType CERTIFICATE_REQUEST = new HandshakeType((byte) 13, "Certificate Request");
|
||||
public static final HandshakeType SERVER_HELLO_DONE = new HandshakeType((byte) 14, "Server Hello Done");
|
||||
public static final HandshakeType CERTIFICATE_VERIFY = new HandshakeType((byte) 15, "Certificate Verify");
|
||||
public static final HandshakeType CLIENT_KEY_EXCHANGE = new HandshakeType((byte) 16, "Client Key Exchange");
|
||||
public static final HandshakeType FINISHED = new HandshakeType((byte) 20, "Finished");
|
||||
public static final HandshakeType CERTIFICATE_URL = new HandshakeType((byte) 21, "Certificate URL");
|
||||
public static final HandshakeType CERTIFICATE_STATUS = new HandshakeType((byte) 22, "Certificate Status");
|
||||
public static final HandshakeType SUPPLEMENTAL_DATA = new HandshakeType((byte) 23, "Supplemental Data");
|
||||
public static final HandshakeType KEY_UPDATE = new HandshakeType((byte) 24, "Key Update");
|
||||
public static final HandshakeType COMPRESSED_CERTIFICATE = new HandshakeType((byte) 25, "Compressed Certificate");
|
||||
public static final HandshakeType MESSAGE_HASH = new HandshakeType((byte) 254, "Message Hash");
|
||||
|
||||
public static final HandshakeType ENCRYPTED_HANDSHAKE_MESSAGE = new HandshakeType((byte) 255, "Encrypted Handshake Message");
|
||||
|
||||
public HandshakeType(Byte value, String name) {
|
||||
super(value, name);
|
||||
registry.put(value, this);
|
||||
}
|
||||
|
||||
public static HandshakeType getInstance(Byte value) {
|
||||
return registry.getOrDefault(value, ENCRYPTED_HANDSHAKE_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(HandshakeType o) {
|
||||
return value().compareTo(o.value());
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.numbers;
|
||||
|
||||
import org.pcap4j.packet.namednumber.NamedNumber;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class HeartbeatMessageType extends NamedNumber<Byte, HeartbeatMessageType> {
|
||||
|
||||
private static final Map<Byte, HeartbeatMessageType> registry = new HashMap<>();
|
||||
|
||||
public static final HeartbeatMessageType HEARTBEAT_REQUEST = new HeartbeatMessageType((byte) 1, "heartbeat_request");
|
||||
public static final HeartbeatMessageType HEARTBEAT_RESPONSE = new HeartbeatMessageType((byte) 2, "heartbeat_response");
|
||||
|
||||
public HeartbeatMessageType(Byte value, String name) {
|
||||
super(value, name);
|
||||
registry.put(value, this);
|
||||
}
|
||||
|
||||
public static HeartbeatMessageType getInstance(Byte value) {
|
||||
if (registry.containsKey(value)) {
|
||||
return registry.get(value);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Неизвестный тип сообщения Heartbeat: " + value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(HeartbeatMessageType o) {
|
||||
return value().compareTo(o.value());
|
||||
}
|
||||
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.numbers;
|
||||
|
||||
import org.pcap4j.packet.namednumber.NamedNumber;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class KeyGroup extends NamedNumber<Short, KeyGroup> {
|
||||
|
||||
// https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml
|
||||
|
||||
private static final Map<Short, KeyGroup> registry = new HashMap<>();
|
||||
|
||||
public static final KeyGroup RESERVED_GREASE_0 = new KeyGroup((short) 0, "Reserved (GREASE)");
|
||||
public static final KeyGroup SECT163K1 = new KeyGroup((short) 1, "sect163k1");
|
||||
public static final KeyGroup SECT163R1 = new KeyGroup((short) 2, "sect163r1");
|
||||
public static final KeyGroup SECT163R2 = new KeyGroup((short) 3, "sect163r2");
|
||||
public static final KeyGroup SECT193R1 = new KeyGroup((short) 4, "sect193r1");
|
||||
public static final KeyGroup SECT193R2 = new KeyGroup((short) 5, "sect193r2");
|
||||
public static final KeyGroup SECT233K1 = new KeyGroup((short) 6, "sect233k1");
|
||||
public static final KeyGroup SECT233R1 = new KeyGroup((short) 7, "sect233r1");
|
||||
public static final KeyGroup SECT239K1 = new KeyGroup((short) 8, "sect239k1");
|
||||
public static final KeyGroup SECT283K1 = new KeyGroup((short) 9, "sect283k1");
|
||||
public static final KeyGroup SECT283R1 = new KeyGroup((short) 10, "sect283r1");
|
||||
public static final KeyGroup SECT409K1 = new KeyGroup((short) 11, "sect409k1");
|
||||
public static final KeyGroup SECT409R1 = new KeyGroup((short) 12, "sect409r1");
|
||||
public static final KeyGroup SECT571K1 = new KeyGroup((short) 13, "sect571k1");
|
||||
public static final KeyGroup SECT571R1 = new KeyGroup((short) 14, "sect571r1");
|
||||
public static final KeyGroup SECP160K1 = new KeyGroup((short) 15, "secp160k1");
|
||||
public static final KeyGroup SECP160R1 = new KeyGroup((short) 16, "secp160r1");
|
||||
public static final KeyGroup SECP160R2 = new KeyGroup((short) 17, "secp160r2");
|
||||
public static final KeyGroup SECP192K1 = new KeyGroup((short) 18, "secp192k1");
|
||||
public static final KeyGroup SECP192R1 = new KeyGroup((short) 19, "secp192r1");
|
||||
public static final KeyGroup SECP224K1 = new KeyGroup((short) 20, "secp224k1");
|
||||
public static final KeyGroup SECP224R1 = new KeyGroup((short) 21, "secp224r1");
|
||||
public static final KeyGroup SECP256K1 = new KeyGroup((short) 22, "secp256k1");
|
||||
public static final KeyGroup SECP256R1 = new KeyGroup((short) 23, "secp256r1");
|
||||
public static final KeyGroup SECP384R1 = new KeyGroup((short) 24, "secp384r1");
|
||||
public static final KeyGroup SECP521R1 = new KeyGroup((short) 25, "secp521r1");
|
||||
public static final KeyGroup BRAINPOOLP256R1 = new KeyGroup((short) 26, "brainpoolP256r1");
|
||||
public static final KeyGroup BRAINPOOLP384R1 = new KeyGroup((short) 27, "brainpoolP384r1");
|
||||
public static final KeyGroup BRAINPOOLP512R1 = new KeyGroup((short) 28, "brainpoolP512r1");
|
||||
public static final KeyGroup X25519 = new KeyGroup((short) 29, "x25519");
|
||||
public static final KeyGroup X448 = new KeyGroup((short) 30, "x448");
|
||||
public static final KeyGroup BRAINPOOLP256R1TLS13 = new KeyGroup((short) 31, "brainpoolP256r1tls13");
|
||||
public static final KeyGroup BRAINPOOLP384R1TLS13 = new KeyGroup((short) 32, "brainpoolP384r1tls13");
|
||||
public static final KeyGroup BRAINPOOLP512R1TLS13 = new KeyGroup((short) 33, "brainpoolP512r1tls13");
|
||||
public static final KeyGroup GC256A = new KeyGroup((short) 34, "GC256A");
|
||||
public static final KeyGroup GC256B = new KeyGroup((short) 35, "GC256B");
|
||||
public static final KeyGroup GC256C = new KeyGroup((short) 36, "GC256C");
|
||||
public static final KeyGroup GC256D = new KeyGroup((short) 37, "GC256D");
|
||||
public static final KeyGroup GC512A = new KeyGroup((short) 38, "GC512A");
|
||||
public static final KeyGroup GC512B = new KeyGroup((short) 39, "GC512B");
|
||||
public static final KeyGroup GC512C = new KeyGroup((short) 40, "GC512C");
|
||||
public static final KeyGroup CURVESM2 = new KeyGroup((short) 41, "curveSM2");
|
||||
public static final KeyGroup FFDHE2048 = new KeyGroup((short) 256, "ffdhe2048");
|
||||
public static final KeyGroup FFDHE3072 = new KeyGroup((short) 257, "ffdhe3072");
|
||||
public static final KeyGroup FFDHE4096 = new KeyGroup((short) 258, "ffdhe4096");
|
||||
public static final KeyGroup FFDHE6144 = new KeyGroup((short) 259, "ffdhe6144");
|
||||
public static final KeyGroup FFDHE8192 = new KeyGroup((short) 260, "ffdhe8192");
|
||||
public static final KeyGroup RESERVED_GREASE_2570 = new KeyGroup((short) 2570, "Reserved (GREASE)");
|
||||
public static final KeyGroup RESERVED_GREASE_6682 = new KeyGroup((short) 6682, "Reserved (GREASE)");
|
||||
public static final KeyGroup RESERVED_GREASE_10794 = new KeyGroup((short) 10794, "Reserved (GREASE)");
|
||||
public static final KeyGroup RESERVED_GREASE_14906 = new KeyGroup((short) 14906, "Reserved (GREASE)");
|
||||
public static final KeyGroup RESERVED_GREASE_19018 = new KeyGroup((short) 19018, "Reserved (GREASE)");
|
||||
public static final KeyGroup RESERVED_GREASE_23130 = new KeyGroup((short) 23130, "Reserved (GREASE)");
|
||||
public static final KeyGroup RESERVED_GREASE_27242 = new KeyGroup((short) 27242, "Reserved (GREASE)");
|
||||
public static final KeyGroup RESERVED_GREASE_31354 = new KeyGroup((short) 31354, "Reserved (GREASE)");
|
||||
public static final KeyGroup RESERVED_GREASE_35466 = new KeyGroup((short) 35466, "Reserved (GREASE)");
|
||||
public static final KeyGroup RESERVED_GREASE_39578 = new KeyGroup((short) 39578, "Reserved (GREASE)");
|
||||
public static final KeyGroup RESERVED_GREASE_43690 = new KeyGroup((short) 43690, "Reserved (GREASE)");
|
||||
public static final KeyGroup RESERVED_GREASE_47802 = new KeyGroup((short) 47802, "Reserved (GREASE)");
|
||||
public static final KeyGroup RESERVED_GREASE_51914 = new KeyGroup((short) 51914, "Reserved (GREASE)");
|
||||
public static final KeyGroup RESERVED_GREASE_56026 = new KeyGroup((short) 56026, "Reserved (GREASE)");
|
||||
public static final KeyGroup RESERVED_GREASE_60138 = new KeyGroup((short) 60138, "Reserved (GREASE)");
|
||||
public static final KeyGroup RESERVED_GREASE_64250 = new KeyGroup((short) 64250, "Reserved (GREASE)");
|
||||
public static final KeyGroup ARBITRARY_EXPLICIT_PRIME_CURVES = new KeyGroup((short) 65281, "arbitrary_explicit_prime_curves");
|
||||
public static final KeyGroup ARBITRARY_EXPLICIT_CHAR2_CURVES = new KeyGroup((short) 65282, "arbitrary_explicit_char2_curves");
|
||||
|
||||
public KeyGroup(Short value, String name) {
|
||||
super(value, name);
|
||||
registry.put(value, this);
|
||||
}
|
||||
|
||||
public static KeyGroup getInstance(Short value) {
|
||||
if (registry.containsKey(value)) {
|
||||
return registry.get(value);
|
||||
} else {
|
||||
return new KeyGroup(value, "Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(KeyGroup o) {
|
||||
return value().compareTo(o.value());
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.numbers;
|
||||
|
||||
import org.pcap4j.packet.namednumber.NamedNumber;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class TlsVersion extends NamedNumber<Short, TlsVersion> {
|
||||
|
||||
public static final TlsVersion TLS_1_0 = new TlsVersion((short) 0x0301, "TLS 1.0");
|
||||
public static final TlsVersion TLS_1_1 = new TlsVersion((short) 0x0302, "TLS 1.1");
|
||||
public static final TlsVersion TLS_1_2 = new TlsVersion((short) 0x0303, "TLS 1.2");
|
||||
public static final TlsVersion TLS_1_3 = new TlsVersion((short) 0x0304, "TLS 1.3");
|
||||
|
||||
private static final Map<Short, TlsVersion> registry = new HashMap<>();
|
||||
|
||||
static {
|
||||
registry.put(TLS_1_0.value(), TLS_1_0);
|
||||
registry.put(TLS_1_1.value(), TLS_1_1);
|
||||
registry.put(TLS_1_2.value(), TLS_1_2);
|
||||
registry.put(TLS_1_3.value(), TLS_1_3);
|
||||
}
|
||||
|
||||
public TlsVersion(Short value, String name) {
|
||||
super(value, name);
|
||||
}
|
||||
|
||||
public static TlsVersion getInstance(Short value) {
|
||||
if (registry.containsKey(value)) {
|
||||
return registry.get(value);
|
||||
} else {
|
||||
return new TlsVersion(value, "unknown");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(TlsVersion o) {
|
||||
return value().compareTo(o.value());
|
||||
}
|
||||
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.records;
|
||||
|
||||
import org.pcap4j.util.ByteArrays;
|
||||
import ru.serega6531.packmate.service.optimization.tls.numbers.AlertDescription;
|
||||
import ru.serega6531.packmate.service.optimization.tls.numbers.AlertLevel;
|
||||
|
||||
import static org.pcap4j.util.ByteArrays.BYTE_SIZE_IN_BYTES;
|
||||
|
||||
public class AlertRecord implements TlsRecord {
|
||||
|
||||
private static final int LEVEL_OFFSET = 0;
|
||||
private static final int DESCRIPTION_OFFSET = LEVEL_OFFSET + BYTE_SIZE_IN_BYTES;
|
||||
|
||||
private int length;
|
||||
private AlertLevel level;
|
||||
private AlertDescription description;
|
||||
|
||||
public static AlertRecord newInstance(byte[] rawData, int offset, int length) {
|
||||
ByteArrays.validateBounds(rawData, offset, length);
|
||||
return new AlertRecord(rawData, offset, length);
|
||||
}
|
||||
|
||||
public AlertRecord(byte[] rawData, int offset, int length) {
|
||||
this.length = length;
|
||||
this.level = AlertLevel.getInstance(ByteArrays.getByte(rawData, LEVEL_OFFSET + offset));
|
||||
|
||||
if (level != AlertLevel.ENCRYPTED_ALERT) {
|
||||
this.description = AlertDescription.getInstance(ByteArrays.getByte(rawData, DESCRIPTION_OFFSET + offset));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (level != AlertLevel.ENCRYPTED_ALERT) {
|
||||
return " Alert [level: " + level.name() + ", description: " + description.name() + "]";
|
||||
} else {
|
||||
return " Encrypted Alert [" + length + " bytes]";
|
||||
}
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.records;
|
||||
|
||||
import org.pcap4j.util.ByteArrays;
|
||||
|
||||
public class ApplicationDataRecord implements TlsRecord {
|
||||
|
||||
/**
|
||||
* 0x0 - Зашифрованные данные приложения
|
||||
* 0x0 + length - Конец записи
|
||||
*/
|
||||
|
||||
private byte[] data;
|
||||
|
||||
public static ApplicationDataRecord newInstance(byte[] rawData, int offset, int length) {
|
||||
ByteArrays.validateBounds(rawData, offset, length);
|
||||
return new ApplicationDataRecord(rawData, offset, length);
|
||||
}
|
||||
|
||||
public ApplicationDataRecord(byte[] rawData, int offset, int length) {
|
||||
data = new byte[length];
|
||||
System.arraycopy(rawData, offset, data, 0, length);
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return " Зашифрованные данные: [" + data.length + " байт]";
|
||||
}
|
||||
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.records;
|
||||
|
||||
import org.pcap4j.util.ByteArrays;
|
||||
|
||||
public class ChangeCipherSpecRecord implements TlsRecord {
|
||||
|
||||
/**
|
||||
0x0 - Сообщение Change Cipher Spec
|
||||
0x1 - Конец записи
|
||||
*/
|
||||
|
||||
private byte changeCipherSpecMessage;
|
||||
|
||||
public static ChangeCipherSpecRecord newInstance(byte[] rawData, int offset, int length) {
|
||||
ByteArrays.validateBounds(rawData, offset, length);
|
||||
return new ChangeCipherSpecRecord(rawData, offset);
|
||||
}
|
||||
|
||||
private ChangeCipherSpecRecord(byte[] rawData, int offset) {
|
||||
this.changeCipherSpecMessage = ByteArrays.getByte(rawData, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return " Change Cipher Spec Message: " + changeCipherSpecMessage;
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.records;
|
||||
|
||||
import org.pcap4j.util.ByteArrays;
|
||||
import ru.serega6531.packmate.service.optimization.tls.numbers.HandshakeType;
|
||||
import ru.serega6531.packmate.service.optimization.tls.records.handshakes.*;
|
||||
import ru.serega6531.packmate.utils.BytesUtils;
|
||||
|
||||
import static org.pcap4j.util.ByteArrays.BYTE_SIZE_IN_BYTES;
|
||||
|
||||
public class HandshakeRecord implements TlsRecord {
|
||||
|
||||
/*
|
||||
0x0 - Тип рукопожатия
|
||||
0x1 - Длина рукопожатия
|
||||
0x4 - Версия рукопожатия
|
||||
0x6 - Содержимое рукопожатия
|
||||
*/
|
||||
|
||||
private static final int HANDSHAKE_TYPE_OFFSET = 0;
|
||||
private static final int LENGTH_OFFSET = HANDSHAKE_TYPE_OFFSET + BYTE_SIZE_IN_BYTES;
|
||||
private static final int CONTENT_OFFSET = LENGTH_OFFSET + 3;
|
||||
|
||||
private HandshakeType handshakeType;
|
||||
private int handshakeLength; // 3 байта.
|
||||
private HandshakeRecordContent content;
|
||||
|
||||
public static HandshakeRecord newInstance(byte[] rawData, int offset, int length) {
|
||||
ByteArrays.validateBounds(rawData, offset, length);
|
||||
return new HandshakeRecord(rawData, offset, length);
|
||||
}
|
||||
|
||||
private HandshakeRecord(byte[] rawData, int offset, int length) {
|
||||
this.handshakeType = HandshakeType.getInstance(ByteArrays.getByte(rawData, HANDSHAKE_TYPE_OFFSET + offset));
|
||||
|
||||
if (handshakeType == HandshakeType.ENCRYPTED_HANDSHAKE_MESSAGE) {
|
||||
this.handshakeLength = length;
|
||||
this.content = BasicHandshakeRecordContent.newInstance(
|
||||
rawData, offset, handshakeLength);
|
||||
return;
|
||||
}
|
||||
|
||||
this.handshakeLength = BytesUtils.getThreeBytesInt(rawData, LENGTH_OFFSET + offset);
|
||||
|
||||
if (handshakeType == HandshakeType.CLIENT_HELLO) {
|
||||
this.content = ClientHelloHandshakeRecordContent.newInstance(
|
||||
rawData, offset + CONTENT_OFFSET, handshakeLength);
|
||||
} else if (handshakeType == HandshakeType.SERVER_HELLO) {
|
||||
this.content = ServerHelloHandshakeRecordContent.newInstance(
|
||||
rawData, offset + CONTENT_OFFSET, handshakeLength);
|
||||
} else if (handshakeType == HandshakeType.CERTIFICATE) {
|
||||
this.content = CertificateHandshakeRecordContent.newInstance(
|
||||
rawData, offset + CONTENT_OFFSET, handshakeLength);
|
||||
} else {
|
||||
this.content = BasicHandshakeRecordContent.newInstance(
|
||||
rawData, offset + CONTENT_OFFSET, handshakeLength);
|
||||
}
|
||||
}
|
||||
|
||||
public HandshakeType getHandshakeType() {
|
||||
return handshakeType;
|
||||
}
|
||||
|
||||
public HandshakeRecordContent getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return " Длина рукопожатия: " + handshakeLength + "\n" +
|
||||
" Тип рукопожатия: " + handshakeType + "\n" +
|
||||
content.toString();
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.records;
|
||||
|
||||
import org.pcap4j.util.ByteArrays;
|
||||
import ru.serega6531.packmate.service.optimization.tls.numbers.HeartbeatMessageType;
|
||||
|
||||
import static org.pcap4j.util.ByteArrays.BYTE_SIZE_IN_BYTES;
|
||||
import static org.pcap4j.util.ByteArrays.SHORT_SIZE_IN_BYTES;
|
||||
|
||||
public class HeartbeatRecord implements TlsRecord {
|
||||
|
||||
// Формат записи задан в RFC 6520: https://tools.ietf.org/html/rfc6520
|
||||
|
||||
private static final int TYPE_OFFSET = 0;
|
||||
private static final int PAYLOAD_LENGTH_OFFSET = TYPE_OFFSET + BYTE_SIZE_IN_BYTES;
|
||||
private static final int PAYLOAD_OFFSET = PAYLOAD_LENGTH_OFFSET + SHORT_SIZE_IN_BYTES;
|
||||
|
||||
private HeartbeatMessageType type;
|
||||
private short payloadLength;
|
||||
private byte[] payload;
|
||||
private byte[] padding;
|
||||
|
||||
public static HeartbeatRecord newInstance(byte[] rawData, int offset, int length) {
|
||||
ByteArrays.validateBounds(rawData, offset, length);
|
||||
return new HeartbeatRecord(rawData, offset, length);
|
||||
}
|
||||
|
||||
public HeartbeatRecord(byte[] rawData, int offset, int length) {
|
||||
this.type = HeartbeatMessageType.getInstance(ByteArrays.getByte(rawData, TYPE_OFFSET + offset));
|
||||
this.payloadLength = ByteArrays.getShort(rawData, PAYLOAD_LENGTH_OFFSET + offset);
|
||||
this.payload = ByteArrays.getSubArray(rawData, PAYLOAD_OFFSET + offset, payloadLength);
|
||||
this.padding = ByteArrays.getSubArray(rawData, PAYLOAD_OFFSET + payloadLength + offset);
|
||||
}
|
||||
|
||||
public HeartbeatMessageType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public byte[] getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public byte[] getPadding() {
|
||||
return padding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return " Heartbeat (" + type.name() +
|
||||
") [данные: " + payloadLength + " байт, заполнение: " +
|
||||
padding.length + " байт]";
|
||||
}
|
||||
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.records;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface TlsRecord extends Serializable {
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package ru.serega6531.packmate.service.optimization.tls.records.handshakes;
|
||||
|
||||
import org.pcap4j.util.ByteArrays;
|
||||
|
||||
public class BasicHandshakeRecordContent implements HandshakeRecordContent {
|
||||
|
||||
/**
|
||||
* 0x0 - Содержимое
|
||||
* 0x0 + length - Конец записи
|
||||
*/
|
||||
|
||||
private byte[] content;
|
||||
|
||||
public static BasicHandshakeRecordContent newInstance(byte[] rawData, int offset, int length) {
|
||||
if(length > 0) {
|
||||
ByteArrays.validateBounds(rawData, offset, length);
|
||||
}
|
||||
return new BasicHandshakeRecordContent(rawData, offset, length);
|
||||
}
|
||||
|
||||
public BasicHandshakeRecordContent(byte[] rawData, int offset, int length) {
|
||||
content = new byte[length];
|
||||
if (length > 0) {
|
||||
System.arraycopy(rawData, offset, content, 0, length);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return " [" + content.length + " bytes]";
|
||||
}
|
||||
}
|
||||
Loaded 100 of 564 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user