Skip to content

Commit

Permalink
Merge pull request #448 from RUB-NDS/new_modvarversion
Browse files Browse the repository at this point in the history
Updated the Version of the ModifiableVariable Package
  • Loading branch information
ic0ns authored Jun 1, 2018
2 parents 2d00998 + b3078cc commit 6d4de77
Show file tree
Hide file tree
Showing 17 changed files with 292 additions and 296 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,38 @@
*/
package de.rub.nds.tlsattacker.core.config;

import de.rub.nds.modifiablevariable.util.XMLPrettyPrinter;
import de.rub.nds.tlsattacker.core.config.filter.ConfigDisplayFilter;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.JAXB;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactoryConfigurationException;
import org.xml.sax.SAXException;

public class ConfigIO {

public static void write(Config config, File f) {
JAXB.marshal(config, f);
try {
write(config, new FileOutputStream(f));
} catch (FileNotFoundException ex) {
throw new RuntimeException(ex);
}
}

public static void write(Config config, OutputStream os) {
JAXB.marshal(config, os);
ByteArrayOutputStream tempStream = new ByteArrayOutputStream();

JAXB.marshal(config, tempStream);
try {
os.write(XMLPrettyPrinter.prettyPrintXML(new String(tempStream.toByteArray())).getBytes());
} catch (IOException | TransformerException | XPathExpressionException | XPathFactoryConfigurationException
| ParserConfigurationException | SAXException ex) {
throw new RuntimeException("Could not format XML");
}
}

public static void write(Config config, File f, ConfigDisplayFilter filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import de.rub.nds.modifiablevariable.ModifiableVariable;
import de.rub.nds.modifiablevariable.ModificationFilter;
import de.rub.nds.modifiablevariable.VariableModification;
import de.rub.nds.modifiablevariable.util.XMLPrettyPrinter;
import de.rub.nds.tlsattacker.core.protocol.message.ProtocolMessage;
import de.rub.nds.tlsattacker.core.protocol.message.extension.ExtensionMessage;
import de.rub.nds.tlsattacker.core.workflow.action.ReceiveAction;
Expand All @@ -26,15 +27,22 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactoryConfigurationException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.xml.sax.SAXException;

public class WorkflowTraceSerializer {

Expand Down Expand Up @@ -107,8 +115,16 @@ public static void write(OutputStream outputStream, WorkflowTrace workflowTrace)
context = getJAXBContext();
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

m.marshal(workflowTrace, outputStream);
ByteArrayOutputStream tempStream = new ByteArrayOutputStream();

m.marshal(workflowTrace, tempStream);
try {
outputStream.write(XMLPrettyPrinter.prettyPrintXML(new String(tempStream.toByteArray())).getBytes());
} catch (TransformerException | XPathExpressionException | XPathFactoryConfigurationException
| ParserConfigurationException | SAXException ex) {
throw new RuntimeException("Could not format XML");
}
tempStream.close();
outputStream.close();
}

Expand Down
481 changes: 240 additions & 241 deletions TLS-Core/src/main/resources/default_config.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void serializeWithSingleConnectionTest() {
action = new SendAction(new ClientHelloMessage(config));
trace.addTlsAction(action);

StringBuilder sb = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
StringBuilder sb = new StringBuilder();
sb.append("<workflowTrace>\n");
sb.append(" <Send>\n");
sb.append(" <messages>\n");
Expand Down Expand Up @@ -164,7 +164,7 @@ public void serializeWithSingleCustomConnectionTest() {
action.setConnectionAlias(con.getAlias());
trace.addTlsAction(action);

StringBuilder sb = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
StringBuilder sb = new StringBuilder("");
sb.append("<workflowTrace>\n");
sb.append(" <OutboundConnection>\n");
sb.append(" <alias>theAlias</alias>\n");
Expand Down Expand Up @@ -214,7 +214,7 @@ public void serializeWithMultipleCustomConnectionTest() {
action = new SendAction(con3.getAlias(), new ClientHelloMessage(config));
trace.addTlsAction(action);

StringBuilder sb = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
StringBuilder sb = new StringBuilder("");
sb.append("<workflowTrace>\n");
sb.append(" <OutboundConnection>\n");
sb.append(" <alias>alias1</alias>\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static <T extends TlsAction> void marshalingEmptyActionYieldsMinimalOutpu
logger.warn("The action under test does not follow naming convention. " + xmlName
+ " does not end with string 'Action'");
}
StringBuilder sb = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
StringBuilder sb = new StringBuilder("");
sb.append("<workflowTrace>\n");
sb.append(" <").append(xmlName).append("/>\n");
sb.append("</workflowTrace>\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void marshalingEmptyActionYieldsMinimalOutput() {
try {
action = new ForwardAction(ctx1Alias, ctx2Alias);
trace.addTlsAction(action);
StringBuilder sb = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
StringBuilder sb = new StringBuilder("");
sb.append("<workflowTrace>\n");
sb.append(" <OutboundConnection>\n");
sb.append(" <alias>ctx1</alias>\n");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# Given this config:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config>
</config>

# And this input trace
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
</workflowTrace>

# We expect this normalized trace
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<OutboundConnection>
<alias>client</alias>
Expand All @@ -21,5 +18,4 @@
</workflowTrace>

# And this after default filter application:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace/>
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Given this config:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config>
</config>

# And this input trace
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<Send>
<messages>
Expand All @@ -14,7 +12,6 @@
</workflowTrace>

# We expect this normalized trace
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<OutboundConnection>
<alias>client</alias>
Expand All @@ -33,11 +30,10 @@
</workflowTrace>

# And this after default filter application:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<Send>
<messages>
<ClientHello/>
</messages>
</Send>
</workflowTrace>
</workflowTrace>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Given this config:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config>
<defaulRunningMode>CLIENT</defaulRunningMode>
<defaultClientConnection>
Expand All @@ -19,12 +18,10 @@
</config>

# And this input trace
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
</workflowTrace>

# We expect this normalized trace
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<OutboundConnection>
<alias>client</alias>
Expand All @@ -36,5 +33,4 @@
</workflowTrace>

# And this after default filter application:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace/>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Given this config:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config>
<defaultRunningMode>CLIENT</defaultRunningMode>
<defaultClientConnection>
Expand All @@ -19,7 +18,6 @@
</config>

# And this input trace
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<Send>
<messages>
Expand All @@ -29,7 +27,6 @@
</workflowTrace>

# We expect this normalized trace
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<OutboundConnection>
<alias>client</alias>
Expand All @@ -48,7 +45,6 @@
</workflowTrace>

# And this after default filter application:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<Send>
<messages>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ Test that user default connections that are explicitly overwritten in the
workflow trace are not overwritten by noramlizing and filtering.

# Given this config:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config>
</config>

# And this input trace
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<OutboundConnection>
<alias>client</alias>
Expand All @@ -16,7 +14,6 @@ workflow trace are not overwritten by noramlizing and filtering.
</workflowTrace>

# We expect this normalized trace
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<OutboundConnection>
<alias>client</alias>
Expand All @@ -28,7 +25,6 @@ workflow trace are not overwritten by noramlizing and filtering.
</workflowTrace>

# And this after default filter application:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<OutboundConnection>
<alias>client</alias>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
Test custom connection in workflow trace

# Given this config:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config>
</config>

# And this input trace
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<OutboundConnection>
<alias>custom</alias>
Expand All @@ -15,7 +13,6 @@ Test custom connection in workflow trace
</workflowTrace>

# We expect this normalized trace
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<OutboundConnection>
<alias>custom</alias>
Expand All @@ -27,7 +24,6 @@ Test custom connection in workflow trace
</workflowTrace>

# And this after default filter application:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<OutboundConnection>
<alias>custom</alias>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Given this config:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config>
</config>

# And this input trace
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<OutboundConnection>
<timeout>44</timeout>
Expand All @@ -17,7 +15,6 @@
</workflowTrace>

# We expect this normalized trace
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<OutboundConnection>
<alias>client</alias>
Expand All @@ -36,7 +33,6 @@
</workflowTrace>

# And this after default filter application:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<OutboundConnection>
<timeout>44</timeout>
Expand All @@ -46,4 +42,4 @@
<ClientHello/>
</messages>
</Send>
</workflowTrace>
</workflowTrace>
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ if there is only one connection defined in the workflow trace. This is
true for default and custom connections.

# Given this config:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config>
</config>

# And this input trace
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<OutboundConnection>
<alias>custom</alias>
Expand All @@ -22,7 +20,6 @@ true for default and custom connections.
</workflowTrace>

# We expect this normalized trace
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<OutboundConnection>
<alias>custom</alias>
Expand All @@ -41,7 +38,6 @@ true for default and custom connections.
</workflowTrace>

# And this after default filter application:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflowTrace>
<OutboundConnection>
<alias>custom</alias>
Expand All @@ -52,4 +48,4 @@ true for default and custom connections.
<ClientHello/>
</messages>
</Send>
</workflowTrace>
</workflowTrace>
Loading

0 comments on commit 6d4de77

Please sign in to comment.