Skip to content
Open
53 changes: 52 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
Expand Down Expand Up @@ -40,6 +41,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<!-- Existing execution for copying dependencies -->
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
Expand All @@ -53,11 +55,61 @@
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>

<!-- New execution for downloading and unpacking the ruleset ZIP file -->
<execution>
<id>unpack-ruleset</id>
<phase>generate-resources</phase> <!-- Changed phase to generate-resources -->
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>de.darmstadt.tu.crossing</groupId>
<artifactId>JavaCryptographicArchitecture</artifactId>
<version>3.1.1</version>
<type>zip</type>
<classifier>ruleset</classifier>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/generated-resources</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-ruleset-to-resources</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>src/main/resources/CrySLRules</outputDirectory> <!-- This is where the rules will be extracted -->
<resources>
<resource>
<directory>${project.build.directory}/generated-resources/JavaCryptographicArchitecture</directory>
<includes>
<include>**/*.crysl</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>



<dependencies>
<!-- https://mvnrepository.com/artifact/org.freemarker/freemarker -->
<dependency>
Expand All @@ -72,7 +124,6 @@
<version>3.1.1</version>
</dependency>


<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/de/upb/docgen/DocSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void parseSettingsFromCLI(String[] settings) {
case "--rulesdir":
setRulesetPathDir(settings[i + 1]);
i++;
mandatorySettings++;
// mandatorySettings++;
break;
case "--reportpath":
setReportDirectory(settings[i + 1]);
Expand All @@ -128,12 +128,12 @@ public void parseSettingsFromCLI(String[] settings) {
case "--ftltemplatespath":
setFTLTemplatesPath(settings[i + 1]);
i++;
mandatorySettings++;
// mandatorySettings++;
break;
case "--langtemplatespath":
setLangTemplatesPath(settings[i + 1]);
i++;
mandatorySettings++;
// mandatorySettings++;
break;
case "--booleana":
setBooleanA(false);
Expand Down Expand Up @@ -161,7 +161,7 @@ public void parseSettingsFromCLI(String[] settings) {
System.exit(255);
}
}
if (mandatorySettings != 4) {
if (mandatorySettings != 1) {
showErrorMessage();
System.exit(255);
}
Expand Down
57 changes: 50 additions & 7 deletions src/main/java/de/upb/docgen/DocumentGeneratorMain.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package de.upb.docgen;

import java.io.*;
import java.util.*;

import crypto.exceptions.CryptoAnalysisException;
import crypto.rules.CrySLPredicate;
import crypto.rules.CrySLRule;
import crypto.rules.CrySLRuleReader;
import de.upb.docgen.crysl.CrySLReader;
import de.upb.docgen.utils.PredicateTreeGenerator;
import de.upb.docgen.utils.TreeNode;
import de.upb.docgen.utils.Utils;
import de.upb.docgen.writer.FreeMarkerWriter;
import freemarker.template.*;
import freemarker.template.Configuration;
import freemarker.template.TemplateException;
import freemarker.template.Version;
import org.apache.commons.io.FileUtils;

import javax.print.Doc;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.*;

/**
* @author Ritika Singh
Expand All @@ -33,7 +37,14 @@ public static void main(String[] args) throws IOException, TemplateException, Cr

// read CryslRules from absolutePath provided by the user
System.out.println("Reading CrySL Rules");
List<CrySLRule> rules = ruleReader.readFromDirectory(new File(docSettings.getRulesetPathDir()));


List<CrySLRule> rules = null;
if (docSettings.getRulesetPathDir() != null) {
rules = ruleReader.readFromDirectory(new File(docSettings.getRulesetPathDir()));
} else {
rules = CrySLReader.readRulesFromJar();
}



Expand Down Expand Up @@ -146,12 +157,44 @@ public static void main(String[] args) throws IOException, TemplateException, Cr
// specifify this flag to distribute the documentation
System.out.println("CogniCryptDOC generated to: " + DocSettings.getInstance().getReportDirectory());
if (!docSettings.isBooleanF()) {
File source = new File(docSettings.getRulesetPathDir());
boolean readFromJar = false;
File source = null;
if (DocSettings.getInstance().getRulesetPathDir() != null) {
source = new File(docSettings.getRulesetPathDir());
} else {
readFromJar = true;
source = new File("tempRulesDir");
if (!source.exists()) {
source.mkdir();
}

// Read each rule and save it in the temporary directory
for (CrySLRule rule : rules) {
File ruleFile = CrySLReader.readRuleFromJarFile(rule.getClassName().substring(rule.getClassName().lastIndexOf(".") + 1));
if (ruleFile != null && ruleFile.exists()) {
try {
// Copy each rule file into the temporary directory
Files.copy(ruleFile.toPath(), new File(source, ruleFile.getName()).toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
File dest = new File(docSettings.getReportDirectory() + File.separator + "rules");
try {
FileUtils.copyDirectory(source, dest);
} catch (IOException e) {
e.printStackTrace();
} finally {
// Cleanup the temporary directory
if (readFromJar) {
try {
FileUtils.deleteDirectory(source);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

Expand Down
38 changes: 33 additions & 5 deletions src/main/java/de/upb/docgen/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import crypto.exceptions.CryptoAnalysisException;
import de.upb.docgen.crysl.CrySLReader;
import org.apache.commons.lang3.StringUtils;

import crypto.rules.CrySLRule;
Expand Down Expand Up @@ -66,7 +68,19 @@ private static Map<String, String> getSymValues() throws IOException {
Properties properties = new Properties();

try {
File fileone = new File(DocSettings.getInstance().getLangTemplatesPath() + "/symbol.properties");
File fileone = null;

if (DocSettings.getInstance().getRulesetPathDir() != null) {
fileone = new File(DocSettings.getInstance().getLangTemplatesPath() + "/symbol.properties");

} else {
fileone = CrySLReader.readSymbolPropertiesFromJar();
}





FileInputStream fileInput = new FileInputStream(fileone);
properties.load(fileInput);
fileInput.close();
Expand Down Expand Up @@ -314,10 +328,24 @@ private static void getProcessedMap(List<Event> eventList) {
}


public List<String> runOrder(CrySLRule file) throws IOException {
String filePath = DocSettings.getInstance().getRulesetPathDir();
filePath += File.separator + file.getClassName().substring(file.getClassName().lastIndexOf(".") + 1) + ".crysl";
Map<String, List<String>> fileContent = readCryslFile(filePath);
public List<String> runOrder(CrySLRule file) throws IOException, CryptoAnalysisException {


File rule = null;
Map<String, List<String>> fileContent = null;

if (DocSettings.getInstance().getRulesetPathDir() != null) {
String filePath = DocSettings.getInstance().getRulesetPathDir();
filePath += File.separator + file.getClassName().substring(file.getClassName().lastIndexOf(".") + 1) + ".crysl";
fileContent = readCryslFile(filePath);

} else {
rule = CrySLReader.readRuleFromJarFile(file.getClassName().substring(file.getClassName().lastIndexOf(".") + 1));
fileContent = readCryslFile(rule.getPath());
}
//String filePath = DocSettings.getInstance().getRulesetPathDir();
//filePath += File.separator + file.getClassName().substring(file.getClassName().lastIndexOf(".") + 1) + ".crysl";
//Map<String, List<String>> fileContent = readCryslFile(filePath);
List<String> objectList = fileContent.get("OBJECTS");

for (String pair : objectList) {
Expand Down
Loading