Добавлена структура блоков

This commit is contained in:
serega6531
2020-04-20 16:38:51 +03:00
parent c72e7b1da9
commit 4b6711ea72
9 changed files with 64 additions and 4 deletions

View File

@@ -78,6 +78,13 @@ public class TlsPacket extends AbstractPacket {
public static final class TlsHeader extends AbstractHeader { public static final class TlsHeader extends AbstractHeader {
/*
0x0 - Content Type
0x1 - Version
0x3 - Length
0x5 - Record content
*/
private static final int CONTENT_TYPE_OFFSET = 0; 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 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 LENGTH_OFFSET = VERSION_OFFSET + SHORT_SIZE_IN_BYTES;

View File

@@ -6,6 +6,13 @@ import ru.serega6531.packmate.service.optimization.tls.numbers.ExtensionType;
public abstract class TlsExtension { public abstract class TlsExtension {
/*
0x0 - Type
0x2 - Length
0x4 - Content
0x4+length - End
*/
protected ExtensionType type; protected ExtensionType type;
protected short extensionLength; protected short extensionLength;

View File

@@ -2,7 +2,12 @@ package ru.serega6531.packmate.service.optimization.tls.records;
import org.pcap4j.util.ByteArrays; import org.pcap4j.util.ByteArrays;
public class ApplicationDataRecord extends TlsRecord { public class ApplicationDataRecord implements TlsRecord {
/**
* 0x0 - Encrypted Application Data
* 0x0 + length - End
*/
private byte[] data; private byte[] data;

View File

@@ -2,7 +2,12 @@ package ru.serega6531.packmate.service.optimization.tls.records;
import org.pcap4j.util.ByteArrays; import org.pcap4j.util.ByteArrays;
public class ChangeCipherSpecRecord extends TlsRecord { public class ChangeCipherSpecRecord implements TlsRecord {
/*
0x0 - Change Cipher Spec Message
0x1 - End
*/
private byte changeCipherSpecMessage; private byte changeCipherSpecMessage;

View File

@@ -10,7 +10,14 @@ import ru.serega6531.packmate.utils.BytesUtils;
import static org.pcap4j.util.ByteArrays.BYTE_SIZE_IN_BYTES; import static org.pcap4j.util.ByteArrays.BYTE_SIZE_IN_BYTES;
public class HandshakeRecord extends TlsRecord { public class HandshakeRecord implements TlsRecord {
/*
0x0 - Handshake type
0x1 - Handshake length
0x4 - Handshake version
0x6 - Handshake content
*/
private static final int HANDSHAKE_TYPE_OFFSET = 0; 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 LENGTH_OFFSET = HANDSHAKE_TYPE_OFFSET + BYTE_SIZE_IN_BYTES;

View File

@@ -2,6 +2,6 @@ package ru.serega6531.packmate.service.optimization.tls.records;
import java.io.Serializable; import java.io.Serializable;
public class TlsRecord implements Serializable { public interface TlsRecord extends Serializable {
} }

View File

@@ -12,6 +12,19 @@ import static org.pcap4j.util.ByteArrays.SHORT_SIZE_IN_BYTES;
public class ClientHelloHandshakeRecordContent extends HelloHandshakeRecordContent { public class ClientHelloHandshakeRecordContent extends HelloHandshakeRecordContent {
/*
0x0 - Client random
0x20 - Session id length (sidl)
0x21 - Session id
0x21+sidl - Cipher suites length (csl)
0x23+sidl - Cipher suite 1..(csl/2)
0x23+sidl+csl - Compression methods length (cml)
0x24+sidl+csl - Compression method 1..cml
0x24+sidl+csl+cml - Extensions Length (el)
0x26+sidl+csl+cml - Extension 1..N
0x26+sidl+csl+cml+el - End
*/
private static final int CIPHER_SUITES_LENGTH_OFFSET = HelloHandshakeRecordContent.SESSION_ID_OFFSET; // + sessionIdLength private static final int CIPHER_SUITES_LENGTH_OFFSET = HelloHandshakeRecordContent.SESSION_ID_OFFSET; // + sessionIdLength
private static final int CIPHER_SUITE_OFFSET = private static final int CIPHER_SUITE_OFFSET =
CIPHER_SUITES_LENGTH_OFFSET + SHORT_SIZE_IN_BYTES; // + sessionIdLength + SHORT_SIZE_IN_BYTES*i CIPHER_SUITES_LENGTH_OFFSET + SHORT_SIZE_IN_BYTES; // + sessionIdLength + SHORT_SIZE_IN_BYTES*i

View File

@@ -9,6 +9,17 @@ import static org.pcap4j.util.ByteArrays.SHORT_SIZE_IN_BYTES;
public class ServerHelloHandshakeRecordContent extends HelloHandshakeRecordContent { public class ServerHelloHandshakeRecordContent extends HelloHandshakeRecordContent {
/*
0x0 - Server random
0x20 - Session id length (sidl)
0x21 - Session id
0x21+si - Cipher suite
0x23+sidl - Compression method
0x24+sidl - Extensions Length (el)
0x26+sidl - Extension 1..N
0x26+sidl+el - End
*/
private static final int CIPHER_SUITE_OFFSET = HelloHandshakeRecordContent.SESSION_ID_OFFSET; // + sessionIdLength private static final int CIPHER_SUITE_OFFSET = HelloHandshakeRecordContent.SESSION_ID_OFFSET; // + sessionIdLength
private static final int COMPRESSION_METHOD_OFFSET = CIPHER_SUITE_OFFSET + SHORT_SIZE_IN_BYTES; // + sessionIdLength private static final int COMPRESSION_METHOD_OFFSET = CIPHER_SUITE_OFFSET + SHORT_SIZE_IN_BYTES; // + sessionIdLength
private static final int EXTENSIONS_LENGTH_OFFSET = COMPRESSION_METHOD_OFFSET + BYTE_SIZE_IN_BYTES; // + sessionIdLength private static final int EXTENSIONS_LENGTH_OFFSET = COMPRESSION_METHOD_OFFSET + BYTE_SIZE_IN_BYTES; // + sessionIdLength

View File

@@ -4,6 +4,11 @@ import org.pcap4j.util.ByteArrays;
public class UnknownRecordContent implements HandshakeRecordContent { public class UnknownRecordContent implements HandshakeRecordContent {
/**
* 0x0 - Content
* 0x0 + length - End
*/
private byte[] content; private byte[] content;
public static UnknownRecordContent newInstance(byte[] rawData, int offset, int length) { public static UnknownRecordContent newInstance(byte[] rawData, int offset, int length) {