Багфиксы

This commit is contained in:
serega6531
2020-04-20 19:43:47 +03:00
parent 4b6711ea72
commit d02fe5f60f
8 changed files with 62 additions and 39 deletions

View File

@@ -16,7 +16,7 @@ public class ClientKeyShareExtension extends KeyShareExtension {
super(type, extensionLength);
this.keyShareLength = ByteArrays.getShort(rawData, KEY_SHARE_LENGTH_OFFSET + offset); // the field is not always there
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);
}

View File

@@ -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 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) {
if (registry.containsKey(value)) {
return registry.get(value);
} else {
throw new IllegalArgumentException("Unknown handshake type " + value);
}
return registry.getOrDefault(value, ENCRYPTED_HANDSHAKE_MESSAGE);
}
@Override

View File

@@ -2,10 +2,10 @@ 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.BasicRecordContent;
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.ServerHelloHandshakeRecordContent;
import ru.serega6531.packmate.service.optimization.tls.records.handshakes.UnknownRecordContent;
import ru.serega6531.packmate.utils.BytesUtils;
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) {
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));
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);
if (handshakeType == HandshakeType.CLIENT_HELLO) {
@@ -43,7 +51,7 @@ public class HandshakeRecord implements TlsRecord {
this.content = ServerHelloHandshakeRecordContent.newInstance(
rawData, offset + CONTENT_OFFSET, handshakeLength);
} else {
this.content = UnknownRecordContent.newInstance(
this.content = BasicRecordContent.newInstance(
rawData, offset + CONTENT_OFFSET, handshakeLength);
}
}

View File

@@ -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]";
}
}

View File

@@ -58,7 +58,7 @@ public abstract class HelloHandshakeRecordContent implements HandshakeRecordCont
@Override
public String toString() {
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" +
" Extensions: " + extensions.toString();
}

View File

@@ -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]";
}
}

View File

@@ -12,7 +12,7 @@ public class TlsPacketTest {
@Test
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++) {
Packet packet = packets.get(i);

File diff suppressed because one or more lines are too long