Skip to content

Commit dca9c56

Browse files
authored
Merge pull request #52 from tls-attacker/fuzzer
Introduces IllegalStringAdapter
2 parents ae4bbd2 + 3b57e7e commit dca9c56

File tree

4 files changed

+113
-1
lines changed

4 files changed

+113
-1
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@
8989
<artifactId>jaxb-runtime</artifactId>
9090
<version>2.3.3</version>
9191
</dependency>
92+
<dependency>
93+
<groupId>commons-lang</groupId>
94+
<artifactId>commons-lang</artifactId>
95+
<version>2.6</version>
96+
<type>jar</type>
97+
</dependency>
9298
</dependencies>
9399
<build>
94100
<plugins>

src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111

1212
import de.rub.nds.modifiablevariable.ModifiableVariable;
1313
import de.rub.nds.modifiablevariable.VariableModification;
14+
import de.rub.nds.modifiablevariable.util.IllegalStringAdapter;
1415
import java.io.Serializable;
16+
import java.nio.charset.StandardCharsets;
1517
import javax.xml.bind.annotation.XmlAccessType;
1618
import javax.xml.bind.annotation.XmlAccessorType;
1719
import javax.xml.bind.annotation.XmlRootElement;
20+
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
1821

1922
/**
2023
*
@@ -23,6 +26,7 @@
2326
@XmlAccessorType(XmlAccessType.FIELD)
2427
public class ModifiableString extends ModifiableVariable<String> implements Serializable {
2528

29+
@XmlJavaTypeAdapter(IllegalStringAdapter.class)
2630
private String originalValue;
2731

2832
public ModifiableString() {
@@ -48,7 +52,7 @@ public boolean isOriginalValueModified() {
4852
}
4953

5054
public byte[] getByteArray(int size) {
51-
return getValue().getBytes();
55+
return getValue().getBytes(StandardCharsets.ISO_8859_1);
5256
}
5357

5458
@Override
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* ModifiableVariable - A Variable Concept for Runtime Modifications
3+
*
4+
* Copyright 2014-2017 Ruhr University Bochum / Hackmanit GmbH
5+
*
6+
* Licensed under Apache License 2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*/
9+
10+
package de.rub.nds.modifiablevariable.util;
11+
12+
import javax.xml.bind.annotation.adapters.XmlAdapter;
13+
import org.apache.commons.lang.StringEscapeUtils;
14+
15+
/**
16+
*
17+
*/
18+
public class IllegalStringAdapter extends XmlAdapter<String, String> {
19+
20+
@Override
21+
public String unmarshal(String value) {
22+
return StringEscapeUtils.unescapeJava(value);
23+
}
24+
25+
@Override
26+
public String marshal(String value) {
27+
return StringEscapeUtils.escapeJava(value);
28+
}
29+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2021 ic0ns.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package de.rub.nds.modifiablevariable.util;
18+
19+
import java.nio.charset.StandardCharsets;
20+
import java.util.Arrays;
21+
import org.apache.commons.lang.StringEscapeUtils;
22+
import org.apache.logging.log4j.LogManager;
23+
import org.apache.logging.log4j.Logger;
24+
import org.junit.After;
25+
import org.junit.AfterClass;
26+
import org.junit.Before;
27+
import org.junit.BeforeClass;
28+
import org.junit.Test;
29+
import static org.junit.Assert.*;
30+
31+
public class IllegalStringAdapterTest {
32+
33+
private Logger LOGGER = LogManager.getLogger();
34+
35+
public IllegalStringAdapterTest() {
36+
}
37+
38+
@BeforeClass
39+
public static void setUpClass() {
40+
}
41+
42+
@AfterClass
43+
public static void tearDownClass() {
44+
}
45+
46+
@Before
47+
public void setUp() {
48+
}
49+
50+
@After
51+
public void tearDown() {
52+
}
53+
54+
/**
55+
* Test of unmarshal method, of class IllegalStringAdapter.
56+
*/
57+
@Test
58+
public void testUnmarshal() {
59+
IllegalStringAdapter instance = new IllegalStringAdapter();
60+
byte[] data = new byte[256];
61+
for (int i = 0; i < data.length; i++) {
62+
data[i] = (byte) i;
63+
}
64+
LOGGER.info("Bytes :"
65+
+ Arrays.toString(new String(data, StandardCharsets.ISO_8859_1).getBytes(StandardCharsets.ISO_8859_1)));
66+
String marshal = instance.marshal(new String(data, StandardCharsets.ISO_8859_1));
67+
LOGGER.info("Marshal: " + marshal);
68+
String unmarshal = instance.unmarshal(marshal);
69+
LOGGER.info("Unescaped:" + StringEscapeUtils.unescapeXml(unmarshal));
70+
LOGGER.info("Unmarshal: " + unmarshal);
71+
assertArrayEquals(data, unmarshal.getBytes(StandardCharsets.ISO_8859_1));
72+
}
73+
}

0 commit comments

Comments
 (0)