Skip to content

Commit

Permalink
Bugfixes and refacoting
Browse files Browse the repository at this point in the history
  • Loading branch information
ic0ns committed Sep 27, 2017
1 parent 0e3bbe3 commit 2d38726
Show file tree
Hide file tree
Showing 112 changed files with 411 additions and 453 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static Config createEmptyConfig() {
try {
field.set(c, null);
} catch (IllegalAccessException e) {
e.printStackTrace();
LOGGER.warn("Could not set field in Config!",e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@
*/
public class SessionResumptionDelegate extends Delegate {

@Parameter(names = "-session_id", description = "The sessionID to resume in hex", converter = ByteArrayConverter.class)
private byte[] sessionID = null;
@Parameter(names = "-session_id", description = "The session ID to resume in hex", converter = ByteArrayConverter.class)
private byte[] sessionId = null;

public SessionResumptionDelegate() {
}

public byte[] getSessionID() {
return sessionID;
public byte[] getSessionId() {
return sessionId;
}

public void setSessionID(byte[] sessionID) {
this.sessionID = sessionID;
public void setSessionId(byte[] sessionId) {
this.sessionId = sessionId;
}

@Override
public void applyDelegate(Config config) {
if (sessionID != null) {
config.setDefaultClientSessionId(sessionID);
config.setDefaultServerSessionId(sessionID);
if (sessionId != null) {
config.setDefaultClientSessionId(sessionId);
config.setDefaultServerSessionId(sessionId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public short getShortValue() {

public static byte[] pointFormatsToByteArray(List<ECPointFormat> pointFormats) throws IOException {
if (pointFormats == null || pointFormats.isEmpty()) {
return null;
return new byte[0];
}

ByteArrayOutputStream bytes = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public int getIntValue() {

public static byte[] namedCurvesToByteArray(List<NamedCurve> curves) throws IOException {
if (curves == null || curves.isEmpty()) {
return null;
return new byte[0];
}

ByteArrayOutputStream bytes = new ByteArrayOutputStream();
Expand All @@ -160,7 +160,7 @@ public static byte[] namedCurvesToByteArray(List<NamedCurve> curves) throws IOEx

public static NamedCurve[] namedCurvesFromByteArray(byte[] sourceBytes) throws IOException, ClassNotFoundException {
if (sourceBytes == null || sourceBytes.length == 0) {
return null;
return new NamedCurve[0];
}

if (sourceBytes.length % NamedCurve.LENGTH != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class RecordByteLength {
* protocol version byte length
*/
public static final int PROTOCOL_VERSION = 2;
public static int EPOCH = 2;
public static int SEQUENCE_NUMBER = 8;
public static final int EPOCH = 2;
public static final int SEQUENCE_NUMBER = 8;

private RecordByteLength() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static ECPublicKeyParameters readECParametersWithPublicKey(InputStream in
*/
public static int[] convertNamedCurves(NamedCurve[] namedCurves) {
if (namedCurves == null || namedCurves.length == 0) {
return null;
return new int[0];
}
int[] nc = new int[namedCurves.length];
for (int i = 0; i < namedCurves.length; i++) {
Expand All @@ -102,7 +102,7 @@ public static int[] convertNamedCurves(NamedCurve[] namedCurves) {
*/
public static short[] convertPointFormats(ECPointFormat[] pointFormats) {
if (pointFormats == null || pointFormats.length == 0) {
return null;
return new short[0];
}
short[] pf = new short[pointFormats.length];
for (int i = 0; i < pointFormats.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void append(byte[] bytes) {

public byte[] digest(ProtocolVersion version, CipherSuite suite) {
try {
MessageDigest hash1 = null;
MessageDigest hash1;
MessageDigest hash2 = null;
DigestAlgorithm algorithm = AlgorithmResolver.getDigestAlgorithm(version, suite);
if (algorithm == DigestAlgorithm.LEGACY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import de.rub.nds.tlsattacker.core.constants.PRFAlgorithm;
import de.rub.nds.tlsattacker.core.exceptions.CryptoException;
import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
Expand Down Expand Up @@ -94,7 +95,7 @@ public static byte[] compute(PRFAlgorithm prfAlgorithm, byte[] secret, String la
*/
private static byte[] computeTls12(byte[] secret, String label, byte[] seed, int size, String macAlgorithm) {
try {
byte[] labelSeed = ArrayConverter.concatenate(label.getBytes(), seed);
byte[] labelSeed = ArrayConverter.concatenate(label.getBytes(Charset.forName("ASCII")), seed);
SecretKeySpec keySpec = null;

if (secret == null || secret.length == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package de.rub.nds.tlsattacker.core.crypto.ec;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Objects;
Expand All @@ -16,7 +17,7 @@
*
* @author Robert Merget <[email protected]>
*/
public class CustomECPoint {
public class CustomECPoint implements Serializable {

private BigInteger x;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
*/
public class CustomECPrivateKey implements ECPrivateKey {

private BigInteger privatekey;
private final BigInteger privatekey;

private NamedCurve curve;
private final NamedCurve curve;

public CustomECPrivateKey(BigInteger privatekey, NamedCurve curve) {
this.privatekey = privatekey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
public class CustomRSAPrivateKey implements RSAPrivateKey {

private BigInteger modulus;
private BigInteger privateExponent;
private final BigInteger modulus;
private final BigInteger privateExponent;

public CustomRSAPrivateKey(BigInteger modulus, BigInteger privateExponent) {
this.modulus = modulus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import de.rub.nds.tlsattacker.core.https.header.HttpsHeader;
import de.rub.nds.tlsattacker.core.https.header.parser.HttpsHeaderParser;
import de.rub.nds.tlsattacker.core.protocol.parser.ProtocolMessageParser;
import java.nio.charset.Charset;

/**
*
Expand Down Expand Up @@ -43,7 +44,7 @@ protected HttpsRequestMessage parseMessageContent() {
message.getHeader().add(header);
pointer = parser.getPointer();
}
LOGGER.info(new String(getAlreadyParsed()));
LOGGER.info(new String(getAlreadyParsed(),Charset.forName("ASCII")));
return message;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import de.rub.nds.tlsattacker.core.https.header.HttpsHeader;
import de.rub.nds.tlsattacker.core.https.header.parser.HttpsHeaderParser;
import de.rub.nds.tlsattacker.core.protocol.parser.ProtocolMessageParser;
import java.nio.charset.Charset;

/**
*
Expand All @@ -36,13 +37,13 @@ protected HttpsResponseMessage parseMessageContent() {
message.setResponseStatusCode(request.replaceFirst(split[0] + " ", ""));
String line = parseStringTill((byte) 0x0A);
while (!line.equals("\r\n")) {
HttpsHeaderParser parser = new HttpsHeaderParser(0, line.getBytes());
HttpsHeaderParser parser = new HttpsHeaderParser(0, line.getBytes(Charset.forName("ASCII")));
HttpsHeader header = parser.parse();
message.getHeader().add(header);
line = parseStringTill((byte) 0x0A);
}
byte[] content = parseArrayOrTillEnd(getBytesLeft());
message.setResponseContent(new String(content));
message.setResponseContent(new String(content, Charset.forName("ASCII")));
LOGGER.info(new String(getAlreadyParsed()));
return message;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
public abstract class HttpsHeaderHandler extends Handler<HttpsHeader> {

private HttpContext context;
private final HttpContext context;

public HttpsHeaderHandler(HttpContext context) {
this.context = context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
public class LocationHeaderPreparator extends Preparator<LocationHeader> {

private LocationHeader header;
private final LocationHeader header;

public LocationHeaderPreparator(Chooser chooser, LocationHeader header) {
super(chooser, header);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ private List<SignatureAndHashAlgorithm> convertSignatureAndHashAlgorithms(byte[]
copied[0] = bytesToConvert[i];
copied[1] = bytesToConvert[i + 1];
SignatureAndHashAlgorithm algo = SignatureAndHashAlgorithm.getSignatureAndHashAlgorithm(copied);
if (algo == null) {
LOGGER.warn("Cannot convert:" + ArrayConverter.bytesToHexString(copied)
+ " to a SignatureAndHashAlgorithm");
} else {
list.add(algo);
}
list.add(algo);
}
return list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public ECPointFormatExtensionParser getParser(byte[] message, int pointer) {
return new ECPointFormatExtensionParser(pointer, message);
}

@Override
public ECPointFormatExtensionPreparator getPreparator(ECPointFormatExtensionMessage message) {
return new ECPointFormatExtensionPreparator(context.getChooser(), message, getSerializer(message));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void adjustTLSExtensionContext(SignatureAndHashAlgorithmsExtensionMessage
byte[] algoBytes = Arrays.copyOfRange(signatureAndHashBytes, i, i
+ HandshakeByteLength.SIGNATURE_HASH_ALGORITHM);
SignatureAndHashAlgorithm algo = SignatureAndHashAlgorithm.getSignatureAndHashAlgorithm(algoBytes);
if (algo == null || algo.getSignatureAlgorithm() == null || algo.getHashAlgorithm() == null) {
if (algo.getSignatureAlgorithm() == null || algo.getHashAlgorithm() == null) {
LOGGER.warn("Unknown SignatureAndHashAlgorithm:" + ArrayConverter.bytesToHexString(algoBytes));
} else {
algoList.add(algo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ public boolean equals(Object obj) {
return false;
}
final ApplicationMessage other = (ApplicationMessage) obj;
if (!Arrays.equals(this.dataConfig, other.dataConfig)) {
return false;
}
return true;
return Arrays.equals(this.dataConfig, other.dataConfig);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ public void setCcsProtocolType(byte value) {
@Override
public String toString() {
StringBuilder sb = new StringBuilder(super.toString());
sb.append("\n CCS ProtocolType:");
sb.append(String.format("%02X ", ccsProtocolType.getValue()));
if (ccsProtocolType != null && ccsProtocolType.getValue() != null) {
sb.append("\n CCS ProtocolType:");
sb.append(String.format("%02X ", ccsProtocolType.getValue()));
}
return sb.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import de.rub.nds.tlsattacker.core.protocol.message.extension.TruncatedHmacExtensionMessage;
import de.rub.nds.tlsattacker.core.protocol.message.extension.TrustedCaIndicationExtensionMessage;
import de.rub.nds.tlsattacker.core.state.TlsContext;
import java.nio.charset.Charset;
import java.util.Date;
import javax.xml.bind.annotation.XmlRootElement;

Expand Down Expand Up @@ -113,7 +114,7 @@ public ClientHelloMessage(Config tlsConfig) {
if (tlsConfig.isAddServerNameIndicationExtension()) {
ServerNameIndicationExtensionMessage extension = new ServerNameIndicationExtensionMessage();
ServerNamePair pair = new ServerNamePair();
pair.setServerNameConfig(tlsConfig.getSniHostname().getBytes());
pair.setServerNameConfig(tlsConfig.getSniHostname().getBytes(Charset.forName("ASCII")));
pair.setServerNameTypeConfig(tlsConfig.getSniType().getValue());
extension.getServerNameList().add(pair);
addExtension(extension);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ public HandshakeMessage(Config tlsConfig, HandshakeMessageType handshakeMessageT
this.handshakeMessageType = handshakeMessageType;
}

public List<ExtensionMessage> getExtensions() {
public final List<ExtensionMessage> getExtensions() {
return extensions;
}

public void setExtensions(List<ExtensionMessage> extensions) {
public final void setExtensions(List<ExtensionMessage> extensions) {
this.extensions = extensions;
}

public void addExtension(ExtensionMessage extension) {
public final void addExtension(ExtensionMessage extension) {
if (this.extensions == null) {
extensions = new LinkedList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ public void setPadding(byte[] padding) {
@Override
public String toString() {
StringBuilder sb = new StringBuilder(super.toString());
sb.append("\nHeartbeat message:\n Type: ");
sb.append(HeartbeatMessageType.getHeartbeatMessageType(heartbeatMessageType.getValue()));
if (heartbeatMessageType != null && heartbeatMessageType.getValue() != null) {
sb.append("\nHeartbeat message:\n Type: ");
sb.append(HeartbeatMessageType.getHeartbeatMessageType(heartbeatMessageType.getValue()));
}
sb.append("\n Payload Length: ");
if (payloadLength != null) {
sb.append(payloadLength.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import de.rub.nds.modifiablevariable.bytearray.ModifiableByteArray;
import de.rub.nds.modifiablevariable.ModifiableVariableProperty;
import de.rub.nds.modifiablevariable.ModifiableVariableFactory;
import de.rub.nds.modifiablevariable.integer.ModifiableInteger;
import de.rub.nds.modifiablevariable.util.ArrayConverter;

/**
Expand All @@ -36,7 +37,7 @@ public class PSKClientKeyExchangeMessage extends ClientKeyExchangeMessage {
@ModifiableVariableProperty(format = ModifiableVariableProperty.Format.PKCS1, type = ModifiableVariableProperty.Type.PUBLIC_KEY)
private ModifiableByteArray identity;
@ModifiableVariableProperty(type = ModifiableVariableProperty.Type.LENGTH)
private ModifiableByteArray identityLength;
private ModifiableInteger identityLength;

public PSKClientKeyExchangeMessage(Config tlsConfig) {
super(tlsConfig);
Expand Down Expand Up @@ -77,16 +78,16 @@ public void setIdentity(byte[] identity) {
this.identity = ModifiableVariableFactory.safelySetValue(this.identity, identity);
}

public ModifiableByteArray getIdentityLength() {
public ModifiableInteger getIdentityLength() {
return identityLength;
}

public void setIdentityLength(ModifiableByteArray identity_length) {
this.identityLength = identity_length;
public void setIdentityLength(ModifiableInteger identityLength) {
this.identityLength = identityLength;
}

public void setIdentityLength(byte[] identity_length) {
this.identityLength = ModifiableVariableFactory.safelySetValue(this.identityLength, identity_length);
public void setIdentityLength(int identityLength) {
this.identityLength = ModifiableVariableFactory.safelySetValue(this.identityLength, identityLength);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @author Philip Riese <[email protected]>
*/
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class ProtocolMessage extends ModifiableVariableHolder implements Serializable {
public abstract class ProtocolMessage extends ModifiableVariableHolder {

/**
* content type
Expand Down
Loading

0 comments on commit 2d38726

Please sign in to comment.