Багфиксы
This commit is contained in:
@@ -16,7 +16,7 @@ public class ClientKeyShareExtension extends KeyShareExtension {
|
|||||||
super(type, extensionLength);
|
super(type, extensionLength);
|
||||||
this.keyShareLength = ByteArrays.getShort(rawData, KEY_SHARE_LENGTH_OFFSET + offset); // the field is not always there
|
this.keyShareLength = ByteArrays.getShort(rawData, KEY_SHARE_LENGTH_OFFSET + offset); // the field is not always there
|
||||||
int cursor = KEY_SHARE_ENTRY_OFFSET + offset;
|
int cursor = KEY_SHARE_ENTRY_OFFSET + offset;
|
||||||
ByteArrays.validateBounds(rawData, cursor + offset, keyShareLength);
|
ByteArrays.validateBounds(rawData, cursor, keyShareLength);
|
||||||
readEntries(rawData, KEY_SHARE_ENTRY_OFFSET + offset, offset + keyShareLength);
|
readEntries(rawData, KEY_SHARE_ENTRY_OFFSET + offset, offset + keyShareLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,17 +34,15 @@ public class HandshakeType extends NamedNumber<Byte, HandshakeType> {
|
|||||||
public static final HandshakeType COMPRESSED_CERTIFICATE = new HandshakeType((byte) 25, "Compressed Certificate");
|
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 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) {
|
public HandshakeType(Byte value, String name) {
|
||||||
super(value, name);
|
super(value, name);
|
||||||
registry.put(value, this);
|
registry.put(value, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandshakeType getInstance(Byte value) {
|
public static HandshakeType getInstance(Byte value) {
|
||||||
if (registry.containsKey(value)) {
|
return registry.getOrDefault(value, ENCRYPTED_HANDSHAKE_MESSAGE);
|
||||||
return registry.get(value);
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Unknown handshake type " + value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package ru.serega6531.packmate.service.optimization.tls.records;
|
|||||||
|
|
||||||
import org.pcap4j.util.ByteArrays;
|
import org.pcap4j.util.ByteArrays;
|
||||||
import ru.serega6531.packmate.service.optimization.tls.numbers.HandshakeType;
|
import ru.serega6531.packmate.service.optimization.tls.numbers.HandshakeType;
|
||||||
|
import ru.serega6531.packmate.service.optimization.tls.records.handshakes.BasicRecordContent;
|
||||||
import ru.serega6531.packmate.service.optimization.tls.records.handshakes.ClientHelloHandshakeRecordContent;
|
import ru.serega6531.packmate.service.optimization.tls.records.handshakes.ClientHelloHandshakeRecordContent;
|
||||||
import ru.serega6531.packmate.service.optimization.tls.records.handshakes.HandshakeRecordContent;
|
import ru.serega6531.packmate.service.optimization.tls.records.handshakes.HandshakeRecordContent;
|
||||||
import ru.serega6531.packmate.service.optimization.tls.records.handshakes.ServerHelloHandshakeRecordContent;
|
import ru.serega6531.packmate.service.optimization.tls.records.handshakes.ServerHelloHandshakeRecordContent;
|
||||||
import ru.serega6531.packmate.service.optimization.tls.records.handshakes.UnknownRecordContent;
|
|
||||||
import ru.serega6531.packmate.utils.BytesUtils;
|
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;
|
||||||
@@ -29,11 +29,19 @@ public class HandshakeRecord implements TlsRecord {
|
|||||||
|
|
||||||
public static HandshakeRecord newInstance(byte[] rawData, int offset, int length) {
|
public static HandshakeRecord newInstance(byte[] rawData, int offset, int length) {
|
||||||
ByteArrays.validateBounds(rawData, offset, length);
|
ByteArrays.validateBounds(rawData, offset, length);
|
||||||
return new HandshakeRecord(rawData, offset);
|
return new HandshakeRecord(rawData, offset, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
private HandshakeRecord(byte[] rawData, int offset) {
|
private HandshakeRecord(byte[] rawData, int offset, int length) {
|
||||||
this.handshakeType = HandshakeType.getInstance(ByteArrays.getByte(rawData, HANDSHAKE_TYPE_OFFSET + offset));
|
this.handshakeType = HandshakeType.getInstance(ByteArrays.getByte(rawData, HANDSHAKE_TYPE_OFFSET + offset));
|
||||||
|
|
||||||
|
if (handshakeType == HandshakeType.ENCRYPTED_HANDSHAKE_MESSAGE) {
|
||||||
|
this.content = BasicRecordContent.newInstance(
|
||||||
|
rawData, offset, handshakeLength);
|
||||||
|
this.handshakeLength = length;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.handshakeLength = BytesUtils.getThreeBytesInt(rawData, LENGTH_OFFSET + offset);
|
this.handshakeLength = BytesUtils.getThreeBytesInt(rawData, LENGTH_OFFSET + offset);
|
||||||
|
|
||||||
if (handshakeType == HandshakeType.CLIENT_HELLO) {
|
if (handshakeType == HandshakeType.CLIENT_HELLO) {
|
||||||
@@ -43,7 +51,7 @@ public class HandshakeRecord implements TlsRecord {
|
|||||||
this.content = ServerHelloHandshakeRecordContent.newInstance(
|
this.content = ServerHelloHandshakeRecordContent.newInstance(
|
||||||
rawData, offset + CONTENT_OFFSET, handshakeLength);
|
rawData, offset + CONTENT_OFFSET, handshakeLength);
|
||||||
} else {
|
} else {
|
||||||
this.content = UnknownRecordContent.newInstance(
|
this.content = BasicRecordContent.newInstance(
|
||||||
rawData, offset + CONTENT_OFFSET, handshakeLength);
|
rawData, offset + CONTENT_OFFSET, handshakeLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package ru.serega6531.packmate.service.optimization.tls.records.handshakes;
|
||||||
|
|
||||||
|
import org.pcap4j.util.ByteArrays;
|
||||||
|
|
||||||
|
public class BasicRecordContent implements HandshakeRecordContent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0x0 - Content
|
||||||
|
* 0x0 + length - End
|
||||||
|
*/
|
||||||
|
|
||||||
|
private byte[] content;
|
||||||
|
|
||||||
|
public static BasicRecordContent newInstance(byte[] rawData, int offset, int length) {
|
||||||
|
if(length > 0) {
|
||||||
|
ByteArrays.validateBounds(rawData, offset, length);
|
||||||
|
}
|
||||||
|
return new BasicRecordContent(rawData, offset, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BasicRecordContent(byte[] rawData, int offset, int length) {
|
||||||
|
content = new byte[length];
|
||||||
|
if (length > 0) {
|
||||||
|
System.arraycopy(rawData, offset, content, 0, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return " [" + content.length + " bytes]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -58,7 +58,7 @@ public abstract class HelloHandshakeRecordContent implements HandshakeRecordCont
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return " TLS version: " + version + "\n" +
|
return " TLS version: " + version + "\n" +
|
||||||
" Client random: " + ByteArrays.toHexString(random, "") + "\n" +
|
" Random: " + ByteArrays.toHexString(random, "") + "\n" +
|
||||||
" Session id: " + (sessionIdLength > 0 ? ByteArrays.toHexString(sessionId, "") : "null") + "\n" +
|
" Session id: " + (sessionIdLength > 0 ? ByteArrays.toHexString(sessionId, "") : "null") + "\n" +
|
||||||
" Extensions: " + extensions.toString();
|
" Extensions: " + extensions.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package ru.serega6531.packmate.service.optimization.tls.records.handshakes;
|
|
||||||
|
|
||||||
import org.pcap4j.util.ByteArrays;
|
|
||||||
|
|
||||||
public class UnknownRecordContent implements HandshakeRecordContent {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 0x0 - Content
|
|
||||||
* 0x0 + length - End
|
|
||||||
*/
|
|
||||||
|
|
||||||
private byte[] content;
|
|
||||||
|
|
||||||
public static UnknownRecordContent newInstance(byte[] rawData, int offset, int length) {
|
|
||||||
ByteArrays.validateBounds(rawData, offset, length);
|
|
||||||
return new UnknownRecordContent(rawData, offset, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public UnknownRecordContent(byte[] rawData, int offset, int length) {
|
|
||||||
System.arraycopy(rawData, offset, content, 0, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return " [" + content.length + " bytes]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,7 @@ public class TlsPacketTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandshake() throws IOException, IllegalRawDataException {
|
public void testHandshake() throws IOException, IllegalRawDataException {
|
||||||
List<Packet> packets = new PackmateDumpFileLoader("tls.pkmt").getPackets();
|
List<Packet> packets = new PackmateDumpFileLoader("tls-wolfram.pkmt").getPackets();
|
||||||
|
|
||||||
for (int i = 0; i < packets.size(); i++) {
|
for (int i = 0; i < packets.size(); i++) {
|
||||||
Packet packet = packets.get(i);
|
Packet packet = packets.get(i);
|
||||||
|
|||||||
12
src/test/resources/tls-wolfram.pkmt
Normal file
12
src/test/resources/tls-wolfram.pkmt
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user