diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f9da31c8b..59bff77ce 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,7 +6,3 @@ updates: interval: weekly time: "04:00" open-pull-requests-limit: 10 - ignore: - - dependency-name: com.google.crypto.tink:tink - versions: - - 1.5.0 diff --git a/.github/workflows/approve_dependabotifications.yml b/.github/workflows/approve_dependabotifications.yml index 0da7c00e5..aeec9ab12 100644 --- a/.github/workflows/approve_dependabotifications.yml +++ b/.github/workflows/approve_dependabotifications.yml @@ -1,7 +1,10 @@ name: Dependabot auto-approve -on: - pull_request_target: - paths: ["**/pom.xml"] + +# Currently disabled because the action is not compatible with merge queues +on: [workflow_dispatch] + # pull_request_target: + # paths: ["**/pom.xml"] + permissions: contents: write diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 8327ec53a..4efc3ade8 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -10,7 +10,7 @@ on: types: [opened, reopened] env: - JAVA_VERSION: 11 + JAVA_VERSION: 17 jobs: # Build the CryptoAnalysis module and run its tests diff --git a/.github/workflows/deploy_and_release.yml b/.github/workflows/deploy_and_release.yml index beffcd7d8..cc5e0835f 100644 --- a/.github/workflows/deploy_and_release.yml +++ b/.github/workflows/deploy_and_release.yml @@ -6,8 +6,6 @@ jobs: deployment: runs-on: ubuntu-latest environment: Deploy - name: CryptoAnalysis Deployment - steps: - name: Checkout source code uses: actions/checkout@v4 @@ -19,18 +17,13 @@ jobs: with: distribution: 'adopt' java-package: 'jdk' - java-version: '11' + java-version: '17' server-id: 'ossrh' # must match the serverId configured for the nexus-staging-maven-plugin server-username: OSSRH_USERNAME # Env var that holds your OSSRH user name server-password: OSSRH_PASSWORD # Env var that holds your OSSRH user pw gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} # Substituted with the value stored in the referenced secret gpg-passphrase: SIGN_KEY_PASS # Env var that holds the key's passphrase - - name: Set up Maven - uses: stCarolas/setup-maven@v4.5 - with: - maven-version: 3.6.3 - - name: Build & Deploy CryptoAnalysis run: mvn -B -U clean deploy -Pdeployment -DskipTests env: @@ -38,6 +31,13 @@ jobs: OSSRH_USERNAME: ${{ secrets.SONATYPE_USER }} OSSRH_PASSWORD: ${{ secrets.SONATYPE_PW }} + release: + runs-on: ubuntu-latest + needs: deployment + steps: + - name: Checkout source code + uses: actions/checkout@v4 + - name: Fetch all tags run: git fetch --tags diff --git a/.github/workflows/merge_queue_mac.yml b/.github/workflows/merge_queue_mac.yml index bb5576de9..b996b44a2 100644 --- a/.github/workflows/merge_queue_mac.yml +++ b/.github/workflows/merge_queue_mac.yml @@ -4,7 +4,7 @@ on: merge_group: env: - JAVA_VERSION: 11 + JAVA_VERSION: 17 jobs: # This name must be equal to the corresponding build_and_test action diff --git a/.github/workflows/merge_queue_ubuntu.yml b/.github/workflows/merge_queue_ubuntu.yml index bad7f9d72..6545e342d 100644 --- a/.github/workflows/merge_queue_ubuntu.yml +++ b/.github/workflows/merge_queue_ubuntu.yml @@ -4,7 +4,7 @@ on: merge_group: env: - JAVA_VERSION: 11 + JAVA_VERSION: 17 jobs: # This name must be equal to the corresponding build_and_test job diff --git a/.github/workflows/merge_queue_windows.yml b/.github/workflows/merge_queue_windows.yml index fdfde8255..fd75bf93a 100644 --- a/.github/workflows/merge_queue_windows.yml +++ b/.github/workflows/merge_queue_windows.yml @@ -4,7 +4,7 @@ on: merge_group: env: - JAVA_VERSION: 11 + JAVA_VERSION: 17 jobs: # This name must be equal to the corresponding build_and_test job diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml index a2ec7193e..ebb129d8f 100644 --- a/.github/workflows/version.yml +++ b/.github/workflows/version.yml @@ -23,12 +23,7 @@ jobs: with: distribution: 'adopt' java-package: jdk - java-version: '11' - # Sets up Maven version - - name: Set up Maven - uses: stCarolas/setup-maven@v4.5 - with: - maven-version: 3.6.3 + java-version: '17' # Semantic versioning - name: Semantic versioning id: versioning diff --git a/CryptoAnalysis/pom.xml b/CryptoAnalysis/pom.xml index 7f8b22a5f..d2e809fc9 100644 --- a/CryptoAnalysis/pom.xml +++ b/CryptoAnalysis/pom.xml @@ -54,29 +54,16 @@ de.fraunhofer.iem testCore + + de.darmstadt.tu.crossing.CrySL + CrySLParser + org.json json 20240303 - - org.eclipse.xtext - org.eclipse.xtext.xbase - 2.36.0 - - - - org.eclipse.emf - org.eclipse.emf.common - 2.31.0 - - - - org.eclipse.emf - org.eclipse.emf.ecore - 2.37.0 - com.fasterxml.jackson.core @@ -91,31 +78,6 @@ - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.apache.maven.plugins - maven-dependency-plugin - 3.3.0 - - unpack - - - - - - - - - org.apache.maven.plugins diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/AlternativeReqPredicate.java b/CryptoAnalysis/src/main/java/crypto/analysis/AlternativeReqPredicate.java index 428009a14..ec51d68ef 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/AlternativeReqPredicate.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/AlternativeReqPredicate.java @@ -1,8 +1,8 @@ package crypto.analysis; import boomerang.scene.Statement; -import crypto.rules.CrySLPredicate; -import crypto.rules.ISLConstraint; +import crysl.rule.CrySLPredicate; +import crysl.rule.ISLConstraint; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/AnalysisSeedWithEnsuredPredicate.java b/CryptoAnalysis/src/main/java/crypto/analysis/AnalysisSeedWithEnsuredPredicate.java index c3cc3f4c2..eee9d5c3b 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/AnalysisSeedWithEnsuredPredicate.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/AnalysisSeedWithEnsuredPredicate.java @@ -7,7 +7,7 @@ import boomerang.scene.Val; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; -import crypto.rules.CrySLPredicate; +import crysl.rule.CrySLPredicate; import java.util.Collection; import typestate.TransitionFunction; diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/AnalysisSeedWithSpecification.java b/CryptoAnalysis/src/main/java/crypto/analysis/AnalysisSeedWithSpecification.java index 95747d328..bea8f9bd2 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/AnalysisSeedWithSpecification.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/AnalysisSeedWithSpecification.java @@ -19,19 +19,19 @@ import crypto.constraints.ConstraintSolver; import crypto.constraints.EvaluableConstraint; import crypto.extractparameter.CallSiteWithExtractedValue; -import crypto.rules.CrySLCondPredicate; -import crypto.rules.CrySLForbiddenMethod; -import crypto.rules.CrySLMethod; -import crypto.rules.CrySLObject; -import crypto.rules.CrySLPredicate; -import crypto.rules.CrySLRule; -import crypto.rules.ICrySLPredicateParameter; -import crypto.rules.ISLConstraint; -import crypto.rules.StateNode; -import crypto.rules.TransitionEdge; import crypto.typestate.ReportingErrorStateNode; import crypto.typestate.WrappedState; import crypto.utils.MatcherUtils; +import crysl.rule.CrySLCondPredicate; +import crysl.rule.CrySLForbiddenMethod; +import crysl.rule.CrySLMethod; +import crysl.rule.CrySLObject; +import crysl.rule.CrySLPredicate; +import crysl.rule.CrySLRule; +import crysl.rule.ICrySLPredicateParameter; +import crysl.rule.ISLConstraint; +import crysl.rule.StateNode; +import crysl.rule.TransitionEdge; import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/CryptoAnalysisDataFlowScope.java b/CryptoAnalysis/src/main/java/crypto/analysis/CryptoAnalysisDataFlowScope.java index d7f36024a..4090e1af8 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/CryptoAnalysisDataFlowScope.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/CryptoAnalysisDataFlowScope.java @@ -3,7 +3,7 @@ import boomerang.scene.DataFlowScope; import boomerang.scene.DeclaredMethod; import boomerang.scene.Method; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.util.Collection; import java.util.HashSet; import org.slf4j.Logger; diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/CryptoScanner.java b/CryptoAnalysis/src/main/java/crypto/analysis/CryptoScanner.java index 354a60584..4195b8e40 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/CryptoScanner.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/CryptoScanner.java @@ -9,7 +9,6 @@ import boomerang.scene.sparse.SparseCFGCache; import com.google.common.collect.Table; import crypto.analysis.errors.AbstractError; -import crypto.cryslhandler.RulesetReader; import crypto.exceptions.CryptoAnalysisException; import crypto.listener.AnalysisPrinter; import crypto.listener.AnalysisReporter; @@ -18,7 +17,8 @@ import crypto.listener.IAnalysisListener; import crypto.listener.IErrorListener; import crypto.listener.IResultsListener; -import crypto.rules.CrySLRule; +import crysl.CrySLParser; +import crysl.rule.CrySLRule; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -58,8 +58,8 @@ protected final void initialize() { // Read the ruleset analysisReporter.beforeReadingRuleset(getRulesetPath()); try { - RulesetReader reader = new RulesetReader(); - ruleset = reader.readRulesFromPath(getRulesetPath()); + CrySLParser parser = new CrySLParser(); + ruleset = parser.parseRulesFromDirectory(getRulesetPath()); } catch (IOException e) { throw new CryptoAnalysisException("Could not read rules: " + e.getMessage()); } diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/EnsuredCrySLPredicate.java b/CryptoAnalysis/src/main/java/crypto/analysis/EnsuredCrySLPredicate.java index a7da4bafc..6c33d3bba 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/EnsuredCrySLPredicate.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/EnsuredCrySLPredicate.java @@ -1,7 +1,7 @@ package crypto.analysis; import crypto.extractparameter.CallSiteWithExtractedValue; -import crypto.rules.CrySLPredicate; +import crysl.rule.CrySLPredicate; import java.util.Collection; public class EnsuredCrySLPredicate { diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/HiddenPredicate.java b/CryptoAnalysis/src/main/java/crypto/analysis/HiddenPredicate.java index 61b14788a..6ecc4cb97 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/HiddenPredicate.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/HiddenPredicate.java @@ -11,7 +11,7 @@ import crypto.analysis.errors.RequiredPredicateError; import crypto.analysis.errors.TypestateError; import crypto.extractparameter.CallSiteWithExtractedValue; -import crypto.rules.CrySLPredicate; +import crysl.rule.CrySLPredicate; import java.util.Collection; import java.util.stream.Collectors; diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/IAnalysisSeed.java b/CryptoAnalysis/src/main/java/crypto/analysis/IAnalysisSeed.java index 1ff2fa957..9e6626d2b 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/IAnalysisSeed.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/IAnalysisSeed.java @@ -8,7 +8,7 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import crypto.analysis.errors.AbstractError; -import crypto.rules.CrySLPredicate; +import crysl.rule.CrySLPredicate; import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -110,20 +110,6 @@ protected Collection expectedPredicatesAtStatement(Statement sta return predicates; } - public Collection getDependantSeeds() { - Collection seeds = new HashSet<>(); - - for (ExpectedPredicateOnSeed seed : expectedPredicates.values()) { - if (this.equals(seed.getSeed())) { - continue; - } - - seeds.add(seed.getSeed()); - } - - return seeds; - } - public Method getMethod() { return origin.getMethod(); } diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/PredicateHandler.java b/CryptoAnalysis/src/main/java/crypto/analysis/PredicateHandler.java index 57ce256ff..98068b080 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/PredicateHandler.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/PredicateHandler.java @@ -2,7 +2,7 @@ import crypto.analysis.errors.PredicateContradictionError; import crypto.analysis.errors.RequiredPredicateError; -import crypto.rules.ISLConstraint; +import crysl.rule.ISLConstraint; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/RequiredCrySLPredicate.java b/CryptoAnalysis/src/main/java/crypto/analysis/RequiredCrySLPredicate.java index 4754e43a8..d5d84d2d3 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/RequiredCrySLPredicate.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/RequiredCrySLPredicate.java @@ -1,8 +1,8 @@ package crypto.analysis; import boomerang.scene.Statement; -import crypto.rules.CrySLPredicate; -import crypto.rules.ISLConstraint; +import crysl.rule.CrySLPredicate; +import crysl.rule.ISLConstraint; import java.util.List; public class RequiredCrySLPredicate implements ISLConstraint { diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/SeedGenerator.java b/CryptoAnalysis/src/main/java/crypto/analysis/SeedGenerator.java index cc1841219..e14f4ef1f 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/SeedGenerator.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/SeedGenerator.java @@ -6,10 +6,10 @@ import boomerang.scene.DataFlowScope; import boomerang.scene.Statement; import boomerang.scene.Val; -import crypto.rules.CrySLRule; import crypto.typestate.ForwardSeedQuery; import crypto.typestate.TypestateAnalysis; import crypto.typestate.TypestateDefinition; +import crysl.rule.CrySLRule; import ideal.IDEALSeedSolver; import java.util.Collection; import java.util.Collections; diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/errors/AbstractError.java b/CryptoAnalysis/src/main/java/crypto/analysis/errors/AbstractError.java index 1e30f0d29..a48aafb39 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/errors/AbstractError.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/errors/AbstractError.java @@ -3,8 +3,8 @@ import boomerang.scene.Method; import boomerang.scene.Statement; import crypto.analysis.IAnalysisSeed; -import crypto.rules.CrySLMethod; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLMethod; +import crysl.rule.CrySLRule; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/errors/CallToError.java b/CryptoAnalysis/src/main/java/crypto/analysis/errors/CallToError.java index f3483608a..58818d6fe 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/errors/CallToError.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/errors/CallToError.java @@ -1,8 +1,8 @@ package crypto.analysis.errors; import crypto.analysis.IAnalysisSeed; -import crypto.rules.CrySLMethod; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLMethod; +import crysl.rule.CrySLRule; import java.util.Arrays; import java.util.Collection; diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/errors/ConstraintError.java b/CryptoAnalysis/src/main/java/crypto/analysis/errors/ConstraintError.java index 6a1ef86bc..2017362cb 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/errors/ConstraintError.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/errors/ConstraintError.java @@ -6,14 +6,13 @@ import com.google.common.base.CharMatcher; import crypto.analysis.IAnalysisSeed; import crypto.extractparameter.CallSiteWithExtractedValue; -import crypto.rules.CrySLArithmeticConstraint; -import crypto.rules.CrySLComparisonConstraint; -import crypto.rules.CrySLComparisonConstraint.CompOp; -import crypto.rules.CrySLConstraint; -import crypto.rules.CrySLRule; -import crypto.rules.CrySLSplitter; -import crypto.rules.CrySLValueConstraint; -import crypto.rules.ISLConstraint; +import crysl.rule.CrySLArithmeticConstraint; +import crysl.rule.CrySLComparisonConstraint; +import crysl.rule.CrySLConstraint; +import crysl.rule.CrySLRule; +import crysl.rule.CrySLSplitter; +import crysl.rule.CrySLValueConstraint; +import crysl.rule.ISLConstraint; import java.util.Arrays; import java.util.Collection; @@ -91,7 +90,7 @@ private String evaluateBrokenConstraint(final ISLConstraint constraint) { return msg.toString(); } - private String evaluateCompOp(CompOp operator) { + private String evaluateCompOp(CrySLComparisonConstraint.CompOp operator) { switch (operator) { case ge: return "at least"; diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/errors/ForbiddenMethodError.java b/CryptoAnalysis/src/main/java/crypto/analysis/errors/ForbiddenMethodError.java index 8ba3c9f4e..6b497c807 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/errors/ForbiddenMethodError.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/errors/ForbiddenMethodError.java @@ -3,8 +3,8 @@ import boomerang.scene.DeclaredMethod; import boomerang.scene.Statement; import crypto.analysis.IAnalysisSeed; -import crypto.rules.CrySLMethod; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLMethod; +import crysl.rule.CrySLRule; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/errors/HardCodedError.java b/CryptoAnalysis/src/main/java/crypto/analysis/errors/HardCodedError.java index bb938c0ba..452978b1d 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/errors/HardCodedError.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/errors/HardCodedError.java @@ -2,8 +2,8 @@ import crypto.analysis.IAnalysisSeed; import crypto.extractparameter.CallSiteWithExtractedValue; -import crypto.rules.CrySLRule; -import crypto.rules.ISLConstraint; +import crysl.rule.CrySLRule; +import crysl.rule.ISLConstraint; import java.util.Arrays; public class HardCodedError extends AbstractError { diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/errors/ImpreciseValueExtractionError.java b/CryptoAnalysis/src/main/java/crypto/analysis/errors/ImpreciseValueExtractionError.java index 9e15671c4..1dbc26a87 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/errors/ImpreciseValueExtractionError.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/errors/ImpreciseValueExtractionError.java @@ -2,8 +2,8 @@ import boomerang.scene.Statement; import crypto.analysis.IAnalysisSeed; -import crypto.rules.CrySLRule; -import crypto.rules.ISLConstraint; +import crysl.rule.CrySLRule; +import crysl.rule.ISLConstraint; import java.util.Arrays; public class ImpreciseValueExtractionError extends AbstractError { diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/errors/IncompleteOperationError.java b/CryptoAnalysis/src/main/java/crypto/analysis/errors/IncompleteOperationError.java index e960d5aec..4d59f9ecd 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/errors/IncompleteOperationError.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/errors/IncompleteOperationError.java @@ -3,8 +3,8 @@ import boomerang.scene.InvokeExpr; import boomerang.scene.Statement; import crypto.analysis.IAnalysisSeed; -import crypto.rules.CrySLMethod; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLMethod; +import crysl.rule.CrySLRule; import java.util.Arrays; import java.util.Collection; diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/errors/InstanceOfError.java b/CryptoAnalysis/src/main/java/crypto/analysis/errors/InstanceOfError.java index 75d2b1027..a558a5ec9 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/errors/InstanceOfError.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/errors/InstanceOfError.java @@ -2,10 +2,10 @@ import crypto.analysis.IAnalysisSeed; import crypto.extractparameter.CallSiteWithExtractedValue; -import crypto.rules.CrySLObject; -import crypto.rules.CrySLPredicate; -import crypto.rules.CrySLRule; -import crypto.rules.ISLConstraint; +import crysl.rule.CrySLObject; +import crysl.rule.CrySLPredicate; +import crysl.rule.CrySLRule; +import crysl.rule.ISLConstraint; import java.util.Arrays; public class InstanceOfError extends AbstractError { diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/errors/NeverTypeOfError.java b/CryptoAnalysis/src/main/java/crypto/analysis/errors/NeverTypeOfError.java index 091c25cdf..e1bc9b033 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/errors/NeverTypeOfError.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/errors/NeverTypeOfError.java @@ -2,10 +2,10 @@ import crypto.analysis.IAnalysisSeed; import crypto.extractparameter.CallSiteWithExtractedValue; -import crypto.rules.CrySLObject; -import crypto.rules.CrySLPredicate; -import crypto.rules.CrySLRule; -import crypto.rules.ISLConstraint; +import crysl.rule.CrySLObject; +import crysl.rule.CrySLPredicate; +import crysl.rule.CrySLRule; +import crysl.rule.ISLConstraint; import java.util.Arrays; public class NeverTypeOfError extends AbstractError { diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/errors/NoCallToError.java b/CryptoAnalysis/src/main/java/crypto/analysis/errors/NoCallToError.java index 9664cea72..5db72f317 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/errors/NoCallToError.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/errors/NoCallToError.java @@ -2,7 +2,7 @@ import boomerang.scene.Statement; import crypto.analysis.IAnalysisSeed; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; public class NoCallToError extends AbstractError { diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/errors/PredicateContradictionError.java b/CryptoAnalysis/src/main/java/crypto/analysis/errors/PredicateContradictionError.java index 942900846..5cf2f60f7 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/errors/PredicateContradictionError.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/errors/PredicateContradictionError.java @@ -2,8 +2,8 @@ import boomerang.scene.Statement; import crypto.analysis.IAnalysisSeed; -import crypto.rules.CrySLPredicate; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLPredicate; +import crysl.rule.CrySLRule; import java.util.Arrays; public class PredicateContradictionError extends AbstractError { diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/errors/RequiredPredicateError.java b/CryptoAnalysis/src/main/java/crypto/analysis/errors/RequiredPredicateError.java index e752ef9ea..5cee34c21 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/errors/RequiredPredicateError.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/errors/RequiredPredicateError.java @@ -4,7 +4,7 @@ import crypto.analysis.AnalysisSeedWithSpecification; import crypto.analysis.HiddenPredicate; import crypto.analysis.RequiredCrySLPredicate; -import crypto.rules.CrySLPredicate; +import crysl.rule.CrySLPredicate; import java.util.Arrays; import java.util.Collection; import java.util.Collections; diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/errors/TypestateError.java b/CryptoAnalysis/src/main/java/crypto/analysis/errors/TypestateError.java index ac3cc8e6e..632a0bd33 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/errors/TypestateError.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/errors/TypestateError.java @@ -2,8 +2,8 @@ import boomerang.scene.Statement; import crypto.analysis.IAnalysisSeed; -import crypto.rules.CrySLMethod; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLMethod; +import crysl.rule.CrySLRule; import java.util.Arrays; import java.util.Collection; diff --git a/CryptoAnalysis/src/main/java/crypto/analysis/errors/UncaughtExceptionError.java b/CryptoAnalysis/src/main/java/crypto/analysis/errors/UncaughtExceptionError.java index 9ab9d0242..31b57b360 100644 --- a/CryptoAnalysis/src/main/java/crypto/analysis/errors/UncaughtExceptionError.java +++ b/CryptoAnalysis/src/main/java/crypto/analysis/errors/UncaughtExceptionError.java @@ -3,7 +3,7 @@ import boomerang.scene.Statement; import boomerang.scene.WrappedClass; import crypto.analysis.IAnalysisSeed; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.util.Arrays; public class UncaughtExceptionError extends AbstractError { diff --git a/CryptoAnalysis/src/main/java/crypto/constraints/BinaryConstraint.java b/CryptoAnalysis/src/main/java/crypto/constraints/BinaryConstraint.java index 3c8ce421e..339c277d6 100644 --- a/CryptoAnalysis/src/main/java/crypto/constraints/BinaryConstraint.java +++ b/CryptoAnalysis/src/main/java/crypto/constraints/BinaryConstraint.java @@ -1,7 +1,6 @@ package crypto.constraints; -import crypto.rules.CrySLConstraint; -import crypto.rules.CrySLConstraint.LogOps; +import crysl.rule.CrySLConstraint; class BinaryConstraint extends EvaluableConstraint { @@ -17,9 +16,9 @@ public void evaluate() { EvaluableConstraint right = EvaluableConstraint.getInstance(binaryConstraint.getRight(), context); left.evaluate(); - LogOps ops = binaryConstraint.getOperator(); + CrySLConstraint.LogOps ops = binaryConstraint.getOperator(); - if (ops.equals(LogOps.implies)) { + if (ops.equals(CrySLConstraint.LogOps.implies)) { // Left side of implication is not satisfied => Right side does not need to be satisfied if (left.hasErrors()) { return; @@ -27,12 +26,12 @@ public void evaluate() { right.evaluate(); errors.addAll(right.getErrors()); - } else if (ops.equals(LogOps.or)) { + } else if (ops.equals(CrySLConstraint.LogOps.or)) { // Constraint is violated if left and right is not satisfied right.evaluate(); errors.addAll(left.getErrors()); errors.addAll(right.getErrors()); - } else if (ops.equals(LogOps.and)) { + } else if (ops.equals(CrySLConstraint.LogOps.and)) { // Left is not satisfied => AND cannot be satisfied if (left.hasErrors()) { errors.addAll(left.getErrors()); @@ -41,7 +40,7 @@ public void evaluate() { right.evaluate(); errors.addAll(right.getErrors()); - } else if (ops.equals(LogOps.eq)) { + } else if (ops.equals(CrySLConstraint.LogOps.eq)) { right.evaluate(); // Simple <=> evaluation diff --git a/CryptoAnalysis/src/main/java/crypto/constraints/ComparisonConstraint.java b/CryptoAnalysis/src/main/java/crypto/constraints/ComparisonConstraint.java index 0276e109e..95d137ecc 100644 --- a/CryptoAnalysis/src/main/java/crypto/constraints/ComparisonConstraint.java +++ b/CryptoAnalysis/src/main/java/crypto/constraints/ComparisonConstraint.java @@ -6,11 +6,11 @@ import crypto.analysis.errors.ImpreciseValueExtractionError; import crypto.extractparameter.CallSiteWithExtractedValue; import crypto.extractparameter.ExtractedValue; -import crypto.rules.CrySLArithmeticConstraint; -import crypto.rules.CrySLComparisonConstraint; -import crypto.rules.CrySLPredicate; -import crypto.rules.ICrySLPredicateParameter; -import crypto.rules.ISLConstraint; +import crysl.rule.CrySLArithmeticConstraint; +import crysl.rule.CrySLComparisonConstraint; +import crysl.rule.CrySLPredicate; +import crysl.rule.ICrySLPredicateParameter; +import crysl.rule.ISLConstraint; import java.util.HashMap; import java.util.Map; diff --git a/CryptoAnalysis/src/main/java/crypto/constraints/ConstraintSolver.java b/CryptoAnalysis/src/main/java/crypto/constraints/ConstraintSolver.java index 2a6c9837d..226ecaa03 100644 --- a/CryptoAnalysis/src/main/java/crypto/constraints/ConstraintSolver.java +++ b/CryptoAnalysis/src/main/java/crypto/constraints/ConstraintSolver.java @@ -15,11 +15,11 @@ import crypto.extractparameter.ExtractParameterAnalysis; import crypto.extractparameter.ExtractParameterDefinition; import crypto.listener.AnalysisReporter; -import crypto.rules.CrySLConstraint; -import crypto.rules.CrySLPredicate; -import crypto.rules.CrySLRule; -import crypto.rules.ICrySLPredicateParameter; -import crypto.rules.ISLConstraint; +import crysl.rule.CrySLConstraint; +import crysl.rule.CrySLPredicate; +import crysl.rule.CrySLRule; +import crysl.rule.ICrySLPredicateParameter; +import crysl.rule.ISLConstraint; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; diff --git a/CryptoAnalysis/src/main/java/crypto/constraints/EvaluableConstraint.java b/CryptoAnalysis/src/main/java/crypto/constraints/EvaluableConstraint.java index 102a72db0..9cf077312 100644 --- a/CryptoAnalysis/src/main/java/crypto/constraints/EvaluableConstraint.java +++ b/CryptoAnalysis/src/main/java/crypto/constraints/EvaluableConstraint.java @@ -20,12 +20,12 @@ import crypto.extractparameter.CallSiteWithExtractedValue; import crypto.extractparameter.CallSiteWithParamIndex; import crypto.extractparameter.ExtractedValue; -import crypto.rules.CrySLComparisonConstraint; -import crypto.rules.CrySLConstraint; -import crypto.rules.CrySLExceptionConstraint; -import crypto.rules.CrySLPredicate; -import crypto.rules.CrySLValueConstraint; -import crypto.rules.ISLConstraint; +import crysl.rule.CrySLComparisonConstraint; +import crysl.rule.CrySLConstraint; +import crysl.rule.CrySLExceptionConstraint; +import crysl.rule.CrySLPredicate; +import crysl.rule.CrySLValueConstraint; +import crysl.rule.ISLConstraint; import java.util.Collection; import java.util.HashMap; import java.util.Map; diff --git a/CryptoAnalysis/src/main/java/crypto/constraints/ExceptionConstraint.java b/CryptoAnalysis/src/main/java/crypto/constraints/ExceptionConstraint.java index b1d8df106..a2bc6712b 100644 --- a/CryptoAnalysis/src/main/java/crypto/constraints/ExceptionConstraint.java +++ b/CryptoAnalysis/src/main/java/crypto/constraints/ExceptionConstraint.java @@ -8,7 +8,7 @@ import boomerang.scene.jimple.JimpleStatement; import boomerang.scene.jimple.JimpleWrappedClass; import crypto.analysis.errors.UncaughtExceptionError; -import crypto.rules.CrySLExceptionConstraint; +import crysl.rule.CrySLExceptionConstraint; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; diff --git a/CryptoAnalysis/src/main/java/crypto/constraints/PredicateConstraint.java b/CryptoAnalysis/src/main/java/crypto/constraints/PredicateConstraint.java index be9c3ffb4..a5e4e8c3f 100644 --- a/CryptoAnalysis/src/main/java/crypto/constraints/PredicateConstraint.java +++ b/CryptoAnalysis/src/main/java/crypto/constraints/PredicateConstraint.java @@ -13,12 +13,12 @@ import crypto.extractparameter.CallSiteWithExtractedValue; import crypto.extractparameter.CallSiteWithParamIndex; import crypto.extractparameter.ExtractedValue; -import crypto.rules.CrySLMethod; -import crypto.rules.CrySLObject; -import crypto.rules.CrySLPredicate; -import crypto.rules.ICrySLPredicateParameter; -import crypto.rules.ISLConstraint; import crypto.utils.MatcherUtils; +import crysl.rule.CrySLMethod; +import crysl.rule.CrySLObject; +import crysl.rule.CrySLPredicate; +import crysl.rule.ICrySLPredicateParameter; +import crysl.rule.ISLConstraint; import java.util.ArrayList; import java.util.Collection; import java.util.List; diff --git a/CryptoAnalysis/src/main/java/crypto/constraints/ValueConstraint.java b/CryptoAnalysis/src/main/java/crypto/constraints/ValueConstraint.java index 6c23b2112..cac54f0de 100644 --- a/CryptoAnalysis/src/main/java/crypto/constraints/ValueConstraint.java +++ b/CryptoAnalysis/src/main/java/crypto/constraints/ValueConstraint.java @@ -2,10 +2,10 @@ import crypto.analysis.errors.ConstraintError; import crypto.extractparameter.CallSiteWithExtractedValue; -import crypto.rules.CrySLObject; -import crypto.rules.CrySLSplitter; -import crypto.rules.CrySLValueConstraint; -import crypto.rules.ISLConstraint; +import crysl.rule.CrySLObject; +import crysl.rule.CrySLSplitter; +import crysl.rule.CrySLValueConstraint; +import crysl.rule.ISLConstraint; import java.util.AbstractMap; import java.util.ArrayList; import java.util.List; diff --git a/CryptoAnalysis/src/main/java/crypto/cryslhandler/CrySLModelReader.java b/CryptoAnalysis/src/main/java/crypto/cryslhandler/CrySLModelReader.java deleted file mode 100644 index 74f38245e..000000000 --- a/CryptoAnalysis/src/main/java/crypto/cryslhandler/CrySLModelReader.java +++ /dev/null @@ -1,698 +0,0 @@ -package crypto.cryslhandler; - -import com.google.common.base.CharMatcher; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.google.inject.Injector; -import crypto.exceptions.CryptoAnalysisException; -import crypto.rules.CrySLArithmeticConstraint; -import crypto.rules.CrySLArithmeticConstraint.ArithOp; -import crypto.rules.CrySLComparisonConstraint; -import crypto.rules.CrySLComparisonConstraint.CompOp; -import crypto.rules.CrySLCondPredicate; -import crypto.rules.CrySLConstraint; -import crypto.rules.CrySLConstraint.LogOps; -import crypto.rules.CrySLForbiddenMethod; -import crypto.rules.CrySLMethod; -import crypto.rules.CrySLObject; -import crypto.rules.CrySLPredicate; -import crypto.rules.CrySLRule; -import crypto.rules.CrySLSplitter; -import crypto.rules.CrySLValueConstraint; -import crypto.rules.ICrySLPredicateParameter; -import crypto.rules.ISLConstraint; -import crypto.rules.StateMachineGraph; -import crypto.rules.StateNode; -import crypto.rules.TransitionEdge; -import de.darmstadt.tu.crossing.CrySLStandaloneSetup; -import de.darmstadt.tu.crossing.crySL.AlternativeRequiredPredicates; -import de.darmstadt.tu.crossing.crySL.BuiltinPredicate; -import de.darmstadt.tu.crossing.crySL.ConditionalPredicate; -import de.darmstadt.tu.crossing.crySL.Constraint; -import de.darmstadt.tu.crossing.crySL.ConstraintsBlock; -import de.darmstadt.tu.crossing.crySL.Domainmodel; -import de.darmstadt.tu.crossing.crySL.EnsuresBlock; -import de.darmstadt.tu.crossing.crySL.Event; -import de.darmstadt.tu.crossing.crySL.EventsBlock; -import de.darmstadt.tu.crossing.crySL.ForbiddenBlock; -import de.darmstadt.tu.crossing.crySL.ForbiddenMethod; -import de.darmstadt.tu.crossing.crySL.LabeledMethodCall; -import de.darmstadt.tu.crossing.crySL.Literal; -import de.darmstadt.tu.crossing.crySL.LiteralExpression; -import de.darmstadt.tu.crossing.crySL.LiteralList; -import de.darmstadt.tu.crossing.crySL.NegatesBlock; -import de.darmstadt.tu.crossing.crySL.ObjectExpression; -import de.darmstadt.tu.crossing.crySL.ObjectOperation; -import de.darmstadt.tu.crossing.crySL.ObjectReference; -import de.darmstadt.tu.crossing.crySL.ObjectsBlock; -import de.darmstadt.tu.crossing.crySL.Operator; -import de.darmstadt.tu.crossing.crySL.Order; -import de.darmstadt.tu.crossing.crySL.OrderBlock; -import de.darmstadt.tu.crossing.crySL.Predicate; -import de.darmstadt.tu.crossing.crySL.PredicateParameter; -import de.darmstadt.tu.crossing.crySL.RequiredPredicate; -import de.darmstadt.tu.crossing.crySL.RequiresBlock; -import de.darmstadt.tu.crossing.crySL.ThisPredicateParameter; -import de.darmstadt.tu.crossing.crySL.TimedPredicate; -import de.darmstadt.tu.crossing.crySL.WildcardPredicateParameter; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.xtext.common.types.JvmDeclaredType; -import org.eclipse.xtext.common.types.JvmTypeReference; -import org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider; -import org.eclipse.xtext.diagnostics.Severity; -import org.eclipse.xtext.linking.lazy.LazyLinkingResource; -import org.eclipse.xtext.resource.XtextResourceSet; -import org.eclipse.xtext.util.CancelIndicator; -import org.eclipse.xtext.validation.CheckMode; -import org.eclipse.xtext.validation.IResourceValidator; -import org.eclipse.xtext.validation.Issue; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class CrySLModelReader { - - private static final Logger LOGGER = LoggerFactory.getLogger(CrySLModelReader.class); - - private StateMachineGraph smg = null; - private JvmTypeReference currentClass; - private final XtextResourceSet resourceSet; - private final Injector injector; - public static final String cryslFileEnding = ".crysl"; - - private static final String THIS = "this"; - private static final String NULL = "null"; - private static final String UNDERSCORE = "_"; - - /** Creates a CrySLModelReader which creates rules from classes on the runtime's classpath. */ - public CrySLModelReader() { - this(CrySLModelReaderClassPath.JAVA_CLASS_PATH); - } - - /** - * Creates a CrySLModelReader which creates rules from classes on the runtime's classpath and a - * given virtual classpath. - * - * @param classPath Contains additional classpath elements which are not present on the current - * runtime's classpath. - */ - public CrySLModelReader(CrySLModelReaderClassPath classPath) { - CrySLStandaloneSetup crySLStandaloneSetup = new CrySLStandaloneSetup(); - this.injector = crySLStandaloneSetup.createInjectorAndDoEMFRegistration(); - this.resourceSet = injector.getInstance(XtextResourceSet.class); - URL[] classpath = classPath.getClassPath(); - URLClassLoader ucl = new URLClassLoader(classpath); - this.resourceSet.setClasspathURIContext(new URLClassLoader(classpath)); - new ClasspathTypeProvider(ucl, this.resourceSet, null, null); - } - - /** - * Read the crysl rules from all given files. - * - * @param files a list of files to read from - * @return the list with the parsed CrySLRules - */ - public Collection readRulesFromFiles(Collection files) { - Map ruleMap = new HashMap(); - - for (File file : files) { - resourceSet.getResource(URI.createFileURI(file.getAbsolutePath()), true); - } - - EcoreUtil.resolveAll(resourceSet); - - for (Resource resource : resourceSet.getResources()) { - if (resource == null) { - continue; - } - - if (!(resource instanceof LazyLinkingResource)) { - continue; - } - - try { - CrySLRule rule = createRuleFromResource(resource); - - if (!ruleMap.containsKey(rule.getClassName())) { - ruleMap.put(rule.getClassName(), rule); - } - } catch (CryptoAnalysisException e) { - LOGGER.error(e.toString()); - } - } - - return new HashSet<>(ruleMap.values()); - } - - /** - * Reads the content of a CrySL file from an {@link InputStream}, afterwards the {@link - * CrySLRule} will be created. - * - * @param stream the {@link InputStream} holds the CrySL file content - * @param virtualFileName the name needs following structure - * [HexHashedAbsoluteZipFilePath][SystemFileSeparator][ZipEntryName] - * @return the {@link CrySLRule} - * @throws IllegalArgumentException If the file for the rule cannot be found - * @throws IOException If there is a problem with reading the file - * @throws CryptoAnalysisException If the file is not a .crysl file - */ - public CrySLRule readRule(InputStream stream, String virtualFileName) - throws IOException, CryptoAnalysisException { - if (!virtualFileName.endsWith(cryslFileEnding)) { - throw new CryptoAnalysisException( - "The extension of " + virtualFileName + " does not match " + cryslFileEnding); - } - - URI uri = URI.createURI(virtualFileName); - Resource resource = resourceSet.getURIResourceMap().get(uri); - - if (resource == null) { - resource = resourceSet.createResource(uri); - resource.load(stream, Collections.EMPTY_MAP); - } - - return createRuleFromResource(resource); - } - - /** - * Reads the content of a CrySL file and returns a {@link CrySLRule} object. - * - * @param ruleFile the CrySL file - * @return the {@link CrySLRule} object - * @throws CryptoAnalysisException If the file is not a .crysl file - */ - public CrySLRule readRule(File ruleFile) throws CryptoAnalysisException { - Resource resource = - resourceSet.getResource(URI.createFileURI(ruleFile.getAbsolutePath()), true); - - return createRuleFromResource(resource); - } - - private boolean runValidator(Resource resource, Severity report) { - IResourceValidator validator = injector.getInstance(IResourceValidator.class); - Collection issues = - validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl); - boolean errorFound = false; - - for (Issue issue : issues) { - switch (issue.getSeverity()) { - case ERROR: - if (report.compareTo(issue.getSeverity()) >= 0) - LOGGER.error( - "{}:{}: {}", - resource.getURI(), - issue.getLineNumber(), - issue.getMessage()); - errorFound = true; - break; - case WARNING: - if (report.compareTo(issue.getSeverity()) >= 0) - LOGGER.warn( - "{}:{}: {}", - resource.getURI(), - issue.getLineNumber(), - issue.getMessage()); - errorFound = true; - break; - case INFO: - if (report.compareTo(issue.getSeverity()) >= 0) - LOGGER.info( - "{}:{}: {}", - resource.getURI(), - issue.getLineNumber(), - issue.getMessage()); - break; - case IGNORE: - break; - } - } - return errorFound; - } - - private CrySLRule createRuleFromResource(Resource resource) throws CryptoAnalysisException { - if (resource == null) { - throw new CryptoAnalysisException( - "Internal error creating a CrySL rule: 'resource parameter was null'."); - } - - if (runValidator(resource, Severity.WARNING)) { - throw new CryptoAnalysisException( - "Skipping rule since it contains errors: " + resource.getURI()); - } - - try { - return createRuleFromDomainmodel((Domainmodel) resource.getContents().get(0)); - } catch (Exception e) { - throw new CryptoAnalysisException( - "An error occurred while reading the rule " + resource.getURI(), e); - } - } - - private CrySLRule createRuleFromDomainmodel(Domainmodel model) throws CryptoAnalysisException { - this.currentClass = model.getJavaType(); - String currentClass = this.currentClass.getQualifiedName(); - - if (currentClass.equals("void")) { - throw new CryptoAnalysisException("Class for the rule is not on the classpath."); - } - - final Collection> objects = getObjects(model.getObjects()); - - Collection forbiddenMethods = - getForbiddenMethods(model.getForbidden()); - - final EventsBlock eventsBlock = model.getEvents(); - final OrderBlock orderBlock = model.getOrder(); - final Collection events = changeDeclaringClass(this.currentClass, eventsBlock); - final Order order = orderBlock == null ? null : orderBlock.getOrder(); - this.smg = StateMachineGraphBuilder.buildSMG(order, events); - - final Collection constraints = Lists.newArrayList(); - constraints.addAll(getConstraints(model.getConstraints())); - constraints.addAll(getRequiredPredicates(model.getRequires())); - - // Since 3.0.0: All sections are optional - final Collection eventMethods = new HashSet<>(); - if (eventsBlock != null) { - eventMethods.addAll(CrySLReaderUtils.resolveEventsToCryslMethods(events)); - constraints.addAll(ExceptionsReader.getExceptionConstraints(eventsBlock)); - } - - final EnsuresBlock ensuresBlock = model.getEnsures(); - final NegatesBlock negatesBlock = model.getNegates(); - - final Collection predicates = Lists.newArrayList(); - final Collection negatedPredicates = Lists.newArrayList(); - predicates.addAll(getEnsuredPredicates(ensuresBlock)); - negatedPredicates.addAll(getNegatedPredicates(negatesBlock)); - - return new CrySLRule( - currentClass, - objects, - forbiddenMethods, - eventMethods, - this.smg, - constraints, - predicates, - negatedPredicates); - } - - private Collection changeDeclaringClass( - JvmTypeReference currentClass, EventsBlock eventsBlock) { - if (eventsBlock == null) { - return Collections.emptyList(); - } - - return eventsBlock.getEvents().stream() - .map( - event -> - event instanceof LabeledMethodCall - ? changeDeclaringClass( - currentClass, (LabeledMethodCall) event) - : event) - .collect(Collectors.toList()); - } - - private Event changeDeclaringClass(JvmTypeReference currentClass, LabeledMethodCall event) { - event.getMethod().getMethod().setDeclaringType((JvmDeclaredType) currentClass.getType()); - return event; - } - - private Collection> getObjects(final ObjectsBlock objects) { - if (objects == null) { - return Collections.emptyList(); - } - return objects.getDeclarations().parallelStream() - .map(CrySLReaderUtils::resolveObject) - .collect(Collectors.toList()); - } - - private Collection getForbiddenMethods(final ForbiddenBlock forbidden) { - if (forbidden == null) { - return Collections.emptyList(); - } - - Collection forbiddenMethods = Lists.newArrayList(); - - for (final ForbiddenMethod method : forbidden.getForbiddenMethods()) { - CrySLMethod cryslMethod = CrySLReaderUtils.toCrySLMethod(method); - Collection alternatives = - CrySLReaderUtils.resolveEventToCryslMethods(method.getReplacement()); - forbiddenMethods.add(new CrySLForbiddenMethod(cryslMethod, alternatives)); - } - return forbiddenMethods; - } - - private Collection getEnsuredPredicates(final EnsuresBlock ensures) { - if (ensures == null) { - return Collections.emptyList(); - } - - return getTimedPredicates(ensures.getEnsuredPredicates(), false); - } - - private Collection getNegatedPredicates(final NegatesBlock negates) { - if (negates == null) { - return Collections.emptyList(); - } - return getTimedPredicates(negates.getNegatedPredicates(), true); - } - - private Collection getTimedPredicates( - final Collection timedPredicates, boolean negate) { - Collection predicates = new ArrayList<>(timedPredicates.size()); - - for (final TimedPredicate timed : timedPredicates) { - Predicate predicate = timed.getPredicate(); - ISLConstraint constraint = - timed instanceof ConditionalPredicate - ? getPredicateCondition((ConditionalPredicate) timed) - : null; - List parameters = resolvePredicateParameters(predicate); - String name = predicate.getName(); - - if (timed.getAfter() == null) { - predicates.add(new CrySLPredicate(null, name, parameters, negate, constraint)); - } else { - Collection nodes = - getStatesForMethods( - CrySLReaderUtils.resolveEventToCryslMethods(timed.getAfter())); - predicates.add( - new CrySLCondPredicate(null, name, parameters, negate, nodes, constraint)); - } - } - return predicates; - } - - private List resolvePredicateParameters(Predicate predicate) { - final List parameters = - new ArrayList<>(predicate.getParameters().size()); - - for (PredicateParameter parameter : predicate.getParameters()) { - if (parameter instanceof WildcardPredicateParameter) { - parameters.add(new CrySLObject(UNDERSCORE, NULL)); - } else if (parameter instanceof ThisPredicateParameter) { - parameters.add(new CrySLObject(THIS, this.currentClass.getQualifiedName())); - } else { - parameters.add(getObjectExpressionValue(parameter.getValue())); - } - } - return parameters; - } - - private CrySLObject getObjectExpressionValue(ObjectExpression expression) { - if (expression instanceof ObjectReference) { - return getObjectExpressionValue((ObjectReference) expression); - } - if (expression instanceof ObjectOperation) { - return getObjectExpressionValue((ObjectOperation) expression); - } - return null; - } - - private CrySLObject getObjectExpressionValue(ObjectReference reference) { - return CrySLReaderUtils.toCrySLObject(reference.getObject()); - } - - private CrySLObject getObjectExpressionValue(ObjectOperation operation) { - String type = operation.getObject().getType().getQualifiedName(); - String name = operation.getObject().getName(); - switch (operation.getFn()) { - case ALG: - return new CrySLObject(name, type, new CrySLSplitter(0, "/")); - case MODE: - return new CrySLObject(name, type, new CrySLSplitter(1, "/")); - case PAD: - return new CrySLObject(name, type, new CrySLSplitter(2, "/")); - case PART: - int index = Integer.parseInt(operation.getIndex()); - String split = operation.getSplit(); - return new CrySLObject(name, type, new CrySLSplitter(index, split)); - case ELEMENTS: // It does basically nothing - return CrySLReaderUtils.toCrySLObject(operation.getObject()); - default: - return null; - } - } - - private ISLConstraint getPredicateCondition(ConditionalPredicate predicate) { - EObject condition = predicate.getCondition(); - if (condition instanceof Constraint) { - return getConstraint((Constraint) condition); - } - if (condition instanceof Predicate) { - return getPredicate((Predicate) condition); - } - return null; - } - - private CrySLPredicate getPredicate(Predicate predicate) { - return getPredicate(predicate, false, null); - } - - private CrySLPredicate getPredicate( - Predicate predicate, boolean negate, ISLConstraint constraint) { - final List variables = resolvePredicateParameters(predicate); - return new CrySLPredicate(null, predicate.getName(), variables, negate, constraint); - } - - private Collection getRequiredPredicates(RequiresBlock requiresBlock) { - if (requiresBlock == null) { - return Collections.emptyList(); - } - - final Collection predicates = new ArrayList<>(); - final Collection requiredPredicates = - requiresBlock.getRequiredPredicates(); - - for (AlternativeRequiredPredicates alternativePredicates : requiredPredicates) { - List alternatives = - alternativePredicates.getAlternatives().parallelStream() - .map(this::getRequiredPredicate) - .collect(Collectors.toList()); - ISLConstraint predicate = alternatives.get(0); - - for (int i = 1; i < alternatives.size(); i++) - predicate = new CrySLConstraint(alternatives.get(i), predicate, LogOps.or); - predicates.add(predicate); - } - return predicates; - } - - private CrySLPredicate getRequiredPredicate(RequiredPredicate predicate) { - ISLConstraint constraint = getPredicateCondition(predicate); - boolean negate = predicate.isNegated(); - return getPredicate(predicate.getPredicate(), negate, constraint); - } - - private Collection getConstraints(ConstraintsBlock constraintsBlock) { - if (constraintsBlock == null) { - return Collections.emptyList(); - } - return constraintsBlock.getConstraints().parallelStream() - .map(this::getConstraint) - .collect(Collectors.toList()); - } - - private ISLConstraint getConstraint(final Constraint constraint) { - - if (constraint instanceof LiteralExpression) { - return getLiteralExpression((LiteralExpression) constraint); - } - - switch (constraint.getOp()) { - /* Logical Expressions */ - case NOT: - // NOT operator was only implemented for Predicates, which were - // not reachable from the Constraint rule. - // Add it to LogOps? - throw new UnsupportedOperationException("The NOT operator is not implemented."); - case IMPLY: - case OR: - case AND: - { - ISLConstraint left = getConstraint(constraint.getLeft()); - ISLConstraint right = getConstraint(constraint.getRight()); - LogOps logOp = CrySLReaderUtils.logOpFromOperator(constraint.getOp()).get(); - return new CrySLConstraint(left, right, logOp); - } - /* Comparison Expressions */ - case EQUAL: // LogOps specifies eq aswell, but it was not used - case UNEQUAL: - case GREATER: - case GREATER_OR_EQUAL: - case LESS: - case LESS_OR_EQUAL: - { - CompOp compOp = CrySLReaderUtils.compOpFromOperator(constraint.getOp()).get(); - CrySLArithmeticConstraint left = - coerceConstraintToArithmeticConstraint( - getConstraint(constraint.getLeft())); - CrySLArithmeticConstraint right = - coerceConstraintToArithmeticConstraint( - getConstraint(constraint.getRight())); - return new CrySLComparisonConstraint(left, right, compOp); - } - /* Arithmetic Expressions */ - case TIMES: - case DIVIDE: - // These were specified in Syntax, but not implemented here. - // Add it to ArithOp? - throw new UnsupportedOperationException( - "The multiplication operators are not implemented."); - case PLUS: - case MINUS: - case MODULO: - { - ISLConstraint left = getConstraint(constraint.getLeft()); - ISLConstraint right = getConstraint((Constraint) constraint.getRight()); - ArithOp arithOp = - CrySLReaderUtils.arithOpFromOperator(constraint.getOp()).get(); - return new CrySLArithmeticConstraint(left, right, arithOp); - } - /* In Expression */ - case IN: - { - CrySLObject left = - constraint.getLeft() instanceof ObjectExpression - ? getObjectExpressionValue( - (ObjectExpression) constraint.getLeft()) - : constraint.getLeft() instanceof Literal - ? CrySLReaderUtils.toCrySLObject((Literal) constraint) - : null; - if (left == null) - throw new IllegalArgumentException( - "lhs of an IN expression must be an Object or an Operation thereon."); - LiteralList right = (LiteralList) constraint.getRight(); - List values = - right.getElements().stream() - .map(Literal::getValue) - .collect(Collectors.toList()); - return new CrySLValueConstraint(left, values); - } - } - return null; - } - - private CrySLArithmeticConstraint coerceConstraintToArithmeticConstraint( - ISLConstraint constraint) { - if (constraint instanceof CrySLArithmeticConstraint) { - return (CrySLArithmeticConstraint) constraint; - } - if (constraint instanceof CrySLPredicate) { - return makeArithmeticConstraint((CrySLPredicate) constraint); - } - throw new ClassCastException( - "Cant coerce `" + constraint.toString() + "` into ArithmeticExpression"); - } - - private ISLConstraint getLiteralExpression(LiteralExpression expression) { - if (expression instanceof BuiltinPredicate) { - return getBuiltinPredicate((BuiltinPredicate) expression); - } - if (expression instanceof Literal) { - return makeConstraintFromObject(CrySLReaderUtils.toCrySLObject((Literal) expression)); - } - if (expression instanceof ObjectExpression) { - return makeConstraintFromObject( - getObjectExpressionValue((ObjectExpression) expression)); - } - return null; - } - - /** This is weird, but is taken from the original implementation. */ - private ISLConstraint makeConstraintFromObject(ICrySLPredicateParameter object) { - return makeArithmeticConstraint(object); - } - - private CrySLArithmeticConstraint makeArithmeticConstraint(ICrySLPredicateParameter object) { - CrySLObject zero = new CrySLObject("0", "int"); - ArithOp plus = CrySLReaderUtils.arithOpFromOperator(Operator.PLUS).get(); - return new CrySLArithmeticConstraint(object, zero, plus); - } - - private Collection getStatesForMethods(final Collection condition) { - final Collection predicateGenerationNodes = new HashSet<>(); - if (condition.size() == 0) { - return predicateGenerationNodes; - } - - for (final TransitionEdge transition : this.smg.getAllTransitions()) { - if (transition.getLabel().containsAll(condition)) { - Collection reachableNodes = - getAllReachableNodes(transition.getRight(), Sets.newHashSet()); - - predicateGenerationNodes.addAll(reachableNodes); - } - } - return predicateGenerationNodes; - } - - private Collection getAllReachableNodes( - final StateNode startNode, Collection visited) { - if (visited.contains(startNode)) { - return visited; - } - - visited.add(startNode); - - for (TransitionEdge edge : this.smg.getAllOutgoingEdges(startNode)) { - Collection reachableNodes = getAllReachableNodes(edge.getRight(), visited); - - visited.addAll(reachableNodes); - } - return visited; - } - - private ISLConstraint getBuiltinPredicate(BuiltinPredicate builtinPredicate) { - String name = builtinPredicate.getPredicate().getLiteral(); - List parameters; - boolean negated = false; - - switch (builtinPredicate.getPredicate()) { - case NO_CALL_TO: - case CALL_TO: - parameters = - CrySLReaderUtils.resolveEventToPredicateParameters( - builtinPredicate.getEvent()); - break; - - case INSTANCE_OF: - case NEVER_TYPE_OF: - parameters = - Lists.newArrayList( - CrySLReaderUtils.toCrySLObject(builtinPredicate.getObject()), - new CrySLObject( - NULL, builtinPredicate.getType().getQualifiedName())); - break; - - case NOT_HARD_CODED: - case LENGTH: - CrySLObject object = CrySLReaderUtils.toCrySLObject(builtinPredicate.getObject()); - parameters = Collections.singletonList(object); - break; - default: - parameters = Collections.emptyList(); - } - return new CrySLPredicate(null, name, parameters, negated); - } - - public static String filterQuotes(final String dirty) { - return CharMatcher.anyOf("\"").removeFrom(dirty); - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/cryslhandler/CrySLModelReaderClassPath.java b/CryptoAnalysis/src/main/java/crypto/cryslhandler/CrySLModelReaderClassPath.java deleted file mode 100644 index ddaa06e8a..000000000 --- a/CryptoAnalysis/src/main/java/crypto/cryslhandler/CrySLModelReaderClassPath.java +++ /dev/null @@ -1,135 +0,0 @@ -package crypto.cryslhandler; - -import com.google.common.base.Splitter; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Objects; -import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Appendable, virtual classpath extension, allowing to add custom elements, even after the actual - * classpath was already set. - */ -public class CrySLModelReaderClassPath { - - private static final Logger LOGGER = LoggerFactory.getLogger(CrySLModelReaderClassPath.class); - - private static final URL[] javaRuntimeClassPath; - private final Collection virtualClassPath; - - public static final CrySLModelReaderClassPath JAVA_CLASS_PATH = new CrySLModelReaderClassPath(); - - static { - Collection runtimeClassPath = - Splitter.on(File.pathSeparatorChar) - .splitToList(System.getProperty("java.class.path")); - javaRuntimeClassPath = - runtimeClassPath.stream() - .map( - (it) -> { - try { - return new File(it).toURI().toURL(); - } catch (MalformedURLException e) { - LOGGER.warn( - "Unable to get URL from java classpath element '" - + it - + "'.", - e); - return null; - } - }) - .filter(Objects::nonNull) - .toArray(URL[]::new); - } - - /** Initializes a new instance with the current runtime's classpath. */ - private CrySLModelReaderClassPath() { - virtualClassPath = Collections.emptySet(); - } - - /** - * Initializes a new instance with the current runtime's classpath and the elements the given - * set. - * - * @param virtualClassPath the virtual class path - */ - public CrySLModelReaderClassPath(Collection virtualClassPath) { - this.virtualClassPath = virtualClassPath; - } - - /** - * Creates a new instance with the current runtime's classpath and the elements the given set. - * - * @param virtualClassPath the virtual class path - * @return the model reader class path instance for the given virtual class path - */ - public static CrySLModelReaderClassPath createFromPaths(Collection virtualClassPath) { - Collection urlClassPath = - virtualClassPath.stream() - .map( - (it) -> { - try { - return it.toAbsolutePath().toUri().toURL(); - } catch (MalformedURLException e) { - LOGGER.warn( - "Unable to get URL from virtual classpath element '" - + it.toAbsolutePath() - + "'.", - e); - return null; - } - }) - .filter(Objects::nonNull) - .collect(Collectors.toSet()); - return new CrySLModelReaderClassPath(urlClassPath); - } - - /** - * Creates a new instance with the current runtime's classpath and the elements the given set. - * - * @param virtualClassPath the virtual class path - * @return the model reader class path instance for the given virtual class path - */ - public static CrySLModelReaderClassPath createFromURIs(Collection virtualClassPath) { - Collection urlClassPath = - virtualClassPath.stream() - .map( - (it) -> { - try { - return it.toURL(); - } catch (MalformedURLException e) { - LOGGER.warn( - "Unable to get URL from virtual classpath element '" - + it - + "'.", - e); - return null; - } - }) - .filter(Objects::nonNull) - .collect(Collectors.toSet()); - return new CrySLModelReaderClassPath(urlClassPath); - } - - /** - * Get the class path. - * - * @return A copy of the current state of the classpath. - */ - public URL[] getClassPath() { - if (virtualClassPath.isEmpty()) return javaRuntimeClassPath.clone(); - Collection classPath = new HashSet<>(); - classPath.addAll(Arrays.asList(javaRuntimeClassPath)); - classPath.addAll(virtualClassPath); - return classPath.toArray(new URL[0]); - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/cryslhandler/CrySLReaderUtils.java b/CryptoAnalysis/src/main/java/crypto/cryslhandler/CrySLReaderUtils.java deleted file mode 100644 index 821229e5e..000000000 --- a/CryptoAnalysis/src/main/java/crypto/cryslhandler/CrySLReaderUtils.java +++ /dev/null @@ -1,225 +0,0 @@ -package crypto.cryslhandler; - -import crypto.rules.CrySLArithmeticConstraint.ArithOp; -import crypto.rules.CrySLComparisonConstraint.CompOp; -import crypto.rules.CrySLConstraint.LogOps; -import crypto.rules.CrySLException; -import crypto.rules.CrySLMethod; -import crypto.rules.CrySLObject; -import crypto.rules.ICrySLPredicateParameter; -import de.darmstadt.tu.crossing.crySL.Aggregate; -import de.darmstadt.tu.crossing.crySL.AnyParameterType; -import de.darmstadt.tu.crossing.crySL.BooleanLiteral; -import de.darmstadt.tu.crossing.crySL.Constraint; -import de.darmstadt.tu.crossing.crySL.Event; -import de.darmstadt.tu.crossing.crySL.Exception; -import de.darmstadt.tu.crossing.crySL.ExceptionAggregate; -import de.darmstadt.tu.crossing.crySL.ExceptionDeclaration; -import de.darmstadt.tu.crossing.crySL.ForbiddenMethod; -import de.darmstadt.tu.crossing.crySL.IntLiteral; -import de.darmstadt.tu.crossing.crySL.LabeledMethodCall; -import de.darmstadt.tu.crossing.crySL.Literal; -import de.darmstadt.tu.crossing.crySL.Method; -import de.darmstadt.tu.crossing.crySL.Object; -import de.darmstadt.tu.crossing.crySL.Operator; -import de.darmstadt.tu.crossing.crySL.StringLiteral; -import java.io.File; -import java.util.AbstractMap.SimpleEntry; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.eclipse.xtext.common.types.JvmTypeParameter; - -public class CrySLReaderUtils { - - public static Collection resolveEventToCryslMethods(final Event event) { - return resolveEventToCryslMethodsStream(event).collect(Collectors.toList()); - } - - public static List resolveEventToPredicateParameters( - final Event event) { - return resolveEventToCryslMethodsStream(event).collect(Collectors.toList()); - } - - public static Collection resolveEventsToCryslMethods( - final Collection events) { - return resolveEventsToCryslMethodsStream(events).collect(Collectors.toList()); - } - - public static Stream resolveEventsToCryslMethodsStream( - final Collection events) { - return events.parallelStream().flatMap(CrySLReaderUtils::resolveEventToCryslMethodsStream); - } - - public static Stream resolveEventToCryslMethodsStream(final Event event) { - if (event instanceof Aggregate) return resolveEventToCryslMethodsStream((Aggregate) event); - if (event instanceof LabeledMethodCall) - return resolveEventToCryslMethodsStream((LabeledMethodCall) event); - return Stream.empty(); - } - - protected static Stream resolveEventToCryslMethodsStream( - final Aggregate aggregate) { - return aggregate.getEvents().parallelStream() - .flatMap(CrySLReaderUtils::resolveEventToCryslMethodsStream); - } - - protected static Stream resolveEventToCryslMethodsStream( - final LabeledMethodCall event) { - return Stream.of(toCrySLMethod((event.getMethod()))); - } - - public static CrySLMethod toCrySLMethod(final ForbiddenMethod method) { - String name = method.getMethod().getQualifiedName(); - String declaringClassType = method.getMethod().getDeclaringType().getQualifiedName(); - List> parameters = - method.getParameters().stream() - .map( - parameter -> - new SimpleEntry<>( - parameter.getSimpleName(), - parameter.getType().getQualifiedName())) - .collect(Collectors.toList()); - return new CrySLMethod(name, declaringClassType, parameters, resolveObject(null)); - } - - public static CrySLMethod toCrySLMethod(final Method method) { - String name = method.getMethod().getQualifiedName(); - String declaringClassType = method.getMethod().getDeclaringType().getQualifiedName(); - List> parameters = - method.getParameters().stream() - .map( - parameter -> - parameter instanceof AnyParameterType - ? new SimpleEntry<>( - CrySLMethod.NO_NAME, CrySLMethod.ANY_TYPE) - : resolveObject((parameter.getValue()))) - .collect(Collectors.toList()); - return new CrySLMethod( - name, declaringClassType, parameters, resolveObject(method.getReturn())); - } - - public static CrySLObject toCrySLObject(Object object) { - return new CrySLObject(object.getName(), object.getType().getQualifiedName()); - } - - public static CrySLObject toCrySLObject(Literal literal) { - String value = literal.getValue(); - String type = - literal instanceof IntLiteral - ? "int" - : literal instanceof BooleanLiteral - ? "boolean" - : literal instanceof StringLiteral - ? String.class.getName() - : "void"; - return new CrySLObject(value, type); - } - - public static Collection resolveExceptions(final Exception exception) { - return resolveExceptionsStream(exception).collect(Collectors.toList()); - } - - public static Stream resolveExceptionsStream(final Exception exception) { - if (exception instanceof ExceptionDeclaration) - return resolveExceptionsStream((ExceptionDeclaration) exception); - if (exception instanceof ExceptionAggregate) - return resolveExceptionsStream((ExceptionAggregate) exception); - return Stream.empty(); - } - - protected static Stream resolveExceptionsStream( - final ExceptionAggregate exception) { - return exception.getExceptions().stream() - .flatMap(CrySLReaderUtils::resolveExceptionsStream); - } - - protected static Stream resolveExceptionsStream( - final ExceptionDeclaration exception) { - return Stream.of(toCrySLException(exception)); - } - - public static CrySLException toCrySLException(final ExceptionDeclaration exception) { - return new CrySLException(exception.getException().getIdentifier()); - } - - public static Map.Entry resolveObject(final Object o) { - if (o == null) { - return new SimpleEntry<>(CrySLMethod.NO_NAME, CrySLMethod.VOID); - } - - if (o.getType().getType() instanceof JvmTypeParameter) { - return new SimpleEntry<>(o.getName(), "java.lang.Object"); - } else { - return new SimpleEntry<>(o.getName(), o.getType().getQualifiedName()); - } - } - - public static File getResourceFromWithin(final String inputPath) { - return new File(inputPath); - } - - public static Optional arithOpFromOperator(Operator operator) { - switch (operator) { - case PLUS: - return Optional.of(ArithOp.p); - // case TIMES: return Optional.of(ArithOp.t); /* Only in Syntax yet */ - // case DIVIDE: return Optional.of(ArithOp.g); /* Only in Syntax yet */ - case MINUS: - return Optional.of(ArithOp.n); - case MODULO: - return Optional.of(ArithOp.m); - default: - return Optional.empty(); - } - } - - public static Optional logOpFromOperator(Operator operator) { - switch (operator) { - case AND: - return Optional.of(LogOps.and); - case OR: - return Optional.of(LogOps.or); - case IMPLY: - return Optional.of(LogOps.implies); - // case NOT: return Optional.of(LogOps.not); /* Only in Syntax yet */ - // case EQUAL: return Optional.of(LogOps.eq); /* unused enum item */ - default: - return Optional.empty(); - } - } - - public static Optional compOpFromOperator(Operator operator) { - switch (operator) { - case EQUAL: - return Optional.of(CompOp.eq); - case UNEQUAL: - return Optional.of(CompOp.neq); - case LESS: - return Optional.of(CompOp.l); - case LESS_OR_EQUAL: - return Optional.of(CompOp.le); - case GREATER: - return Optional.of(CompOp.g); - case GREATER_OR_EQUAL: - return Optional.of(CompOp.ge); - default: - return Optional.empty(); - } - } - - public static boolean isArithmeticExpression(Constraint constraint) { - return arithOpFromOperator(constraint.getOp()).isPresent(); - } - - public static boolean isLogicExpression(Constraint constraint) { - return logOpFromOperator(constraint.getOp()).isPresent(); - } - - public static boolean isComparisonExpression(Constraint constraint) { - return compOpFromOperator(constraint.getOp()).isPresent(); - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/cryslhandler/ExceptionsReader.java b/CryptoAnalysis/src/main/java/crypto/cryslhandler/ExceptionsReader.java deleted file mode 100644 index 5138ee4ed..000000000 --- a/CryptoAnalysis/src/main/java/crypto/cryslhandler/ExceptionsReader.java +++ /dev/null @@ -1,30 +0,0 @@ -package crypto.cryslhandler; - -import crypto.rules.CrySLExceptionConstraint; -import crypto.rules.CrySLMethod; -import de.darmstadt.tu.crossing.crySL.EventsBlock; -import de.darmstadt.tu.crossing.crySL.LabeledMethodCall; -import java.util.Collection; -import java.util.stream.Collectors; - -/** Helper class to derive {@link CrySLExceptionConstraint}'s from the events. */ -public abstract class ExceptionsReader { - public static Collection getExceptionConstraints( - EventsBlock eventsBlock) { - return eventsBlock.getEvents().stream() - .filter(event -> event instanceof LabeledMethodCall) - .map(event -> (LabeledMethodCall) event) - .flatMap( - meth -> - CrySLReaderUtils.resolveExceptionsStream(meth.getException()) - .map( - exception -> { - CrySLMethod method = - CrySLReaderUtils.toCrySLMethod( - meth.getMethod()); - return new CrySLExceptionConstraint( - method, exception); - })) - .collect(Collectors.toList()); - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/cryslhandler/RulesetReader.java b/CryptoAnalysis/src/main/java/crypto/cryslhandler/RulesetReader.java deleted file mode 100644 index 1d2a5e08d..000000000 --- a/CryptoAnalysis/src/main/java/crypto/cryslhandler/RulesetReader.java +++ /dev/null @@ -1,183 +0,0 @@ -package crypto.cryslhandler; - -import crypto.exceptions.CryptoAnalysisException; -import crypto.rules.CrySLRule; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.RandomAccessFile; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class RulesetReader { - - private static final Logger LOGGER = LoggerFactory.getLogger(RulesetReader.class); - private static final String CRYSL_FILE_ENDING = ".crysl"; - - public Collection readRulesFromPath(String path) throws IOException { - if (isZipFile(path)) { - return readRulesFromZipArchive(path); - } - - return readRulesFromDirectory(path); - } - - public Collection readRulesFromDirectory(String path) throws IOException { - File directory = new File(path); - if (!directory.exists()) { - throw new FileNotFoundException("Directory " + path + " does not exist"); - } - - if (!directory.isDirectory()) { - throw new IOException(path + " is not a directory"); - } - - Collection files = Arrays.asList(directory.listFiles()); - return readRulesFromFiles(files); - } - - public Collection readRulesFromFiles(Collection files) { - Collection result = new HashSet<>(); - - for (File file : files) { - try { - CrySLRule rule = readRuleFromFile(file); - - if (result.contains(rule)) { - LOGGER.warn("Rule for class {} appears multiple times", rule.getClassName()); - continue; - } - - result.add(rule); - } catch (CryptoAnalysisException e) { - LOGGER.error(e.getMessage()); - } - } - return result; - } - - public CrySLRule readRuleFromFile(File file) throws CryptoAnalysisException { - String fileName = file.getName(); - if (!fileName.endsWith(CRYSL_FILE_ENDING)) { - throw new CryptoAnalysisException( - "The extension of " + fileName + " does not match " + CRYSL_FILE_ENDING); - } - - CrySLModelReader modelReader = new CrySLModelReader(); - return modelReader.readRule(file); - } - - private boolean isZipFile(String path) { - File file = new File(path); - - // Copied from - // https://stackoverflow.com/questions/33934178/how-to-identify-a-zip-file-in-java - int fileSignature; - - try (RandomAccessFile raf = new RandomAccessFile(file, "r")) { - fileSignature = raf.readInt(); - } catch (IOException e) { - return false; - } - return fileSignature == 0x504B0304 - || fileSignature == 0x504B0506 - || fileSignature == 0x504B0708; - } - - public Collection readRulesFromZipArchive(String path) throws IOException { - Collection result = new HashSet<>(); - File file = new File(path); - - try (ZipFile zipFile = new ZipFile(file)) { - Enumeration entries = zipFile.entries(); - - while (entries.hasMoreElements()) { - ZipEntry entry = entries.nextElement(); - - if (entry.isDirectory()) { - continue; - } - - try { - CrySLRule rule = readRuleFromZipEntry(entry, zipFile, file); - result.add(rule); - } catch (CryptoAnalysisException e) { - LOGGER.error(e.getMessage()); - } - } - } - return result; - } - - private CrySLRule readRuleFromZipEntry(ZipEntry entry, ZipFile zipFile, File file) - throws CryptoAnalysisException { - String entryName = entry.getName(); - if (entry.isDirectory() || !entryName.endsWith(CRYSL_FILE_ENDING)) { - throw new CryptoAnalysisException("ZIP entry " + entryName + " not a CrySL file"); - } - - try { - String name = createUniqueZipEntryName(file, entry); - CrySLModelReader reader = new CrySLModelReader(); - - InputStream inputStream = zipFile.getInputStream(entry); - CrySLRule rule = reader.readRule(inputStream, name); - inputStream.close(); - - return rule; - } catch (IOException ex) { - throw new CryptoAnalysisException( - "Could not read file " - + entry.getName() - + " from Zip archive " - + ex.getMessage()); - } - } - - /** - * For zip file entries there is no real URI. Using the raw absolute path of the zip file will - * cause an exception when trying to resolve/create the resource in the {@link - * CrySLModelReader#readRule(File)} methods. Solution: Create a custom URI with the following - * scheme: uri := [HexHashedAbsoluteZipFilePath][SystemFileSeparator][ZipEntryName] This scheme - * has the properties that it still is unique system-wide, The hash will be the same for the - * same file, so you could know if two rules come from the same ruleset file, and you still can - * get the information of the zipped file. - * - * @param zipFile the File that holds the zip archive - * @param zipEntry the Zip entry to create the name for - * @return the unique name - */ - private static String createUniqueZipEntryName(File zipFile, ZipEntry zipEntry) { - StringBuilder sb = new StringBuilder(); - - MessageDigest messageDigest; - try { - messageDigest = MessageDigest.getInstance("SHA-256"); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } - messageDigest.update(zipFile.getAbsolutePath().getBytes()); - byte[] updatedFileName = messageDigest.digest(zipFile.getAbsolutePath().getBytes()); - - String partFileName = bytesToHex(updatedFileName); - sb.append(partFileName); - sb.append(File.separator); - sb.append(zipEntry.getName()); - return sb.toString(); - } - - private static String bytesToHex(byte[] bytes) { - StringBuilder sb = new StringBuilder(); - for (byte b : bytes) sb.append(String.format("%02x", b)); - return sb.toString(); - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/cryslhandler/StateMachineGraphBuilder.java b/CryptoAnalysis/src/main/java/crypto/cryslhandler/StateMachineGraphBuilder.java deleted file mode 100644 index ae9efc8c6..000000000 --- a/CryptoAnalysis/src/main/java/crypto/cryslhandler/StateMachineGraphBuilder.java +++ /dev/null @@ -1,252 +0,0 @@ -package crypto.cryslhandler; - -import com.google.common.collect.Sets; -import crypto.rules.CrySLMethod; -import crypto.rules.FiniteStateMachine; -import crypto.rules.StateMachineGraph; -import crypto.rules.StateNode; -import de.darmstadt.tu.crossing.crySL.Event; -import de.darmstadt.tu.crossing.crySL.Order; -import de.darmstadt.tu.crossing.crySL.OrderOperator; -import de.darmstadt.tu.crossing.crySL.Primary; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; - -/** - * This class will build a {@link FiniteStateMachine} for a given ORDER expression from crysl rules. - * - * @author marvinvogel - */ -public class StateMachineGraphBuilder { - - private final Order order; - private final StateMachineGraph result; - private final Collection events; - private final Collection allMethods = Sets.newHashSet(); - - public static StateMachineGraph buildSMG(final Order order, final Collection events) { - return (new StateMachineGraphBuilder(order, events)).buildSMG(); - } - - protected StateMachineGraphBuilder(final Order order, final Collection events) { - this.order = order; - this.events = events; - this.result = new StateMachineGraph(); - } - - protected StateMachineGraph buildSMG() { - StateNode initialNode = new StateNode("-1", true, false); - this.result.addNode(initialNode); - SubStateMachine subSmg = buildSubSMG(this.order, Collections.singleton(initialNode)); - subSmg.getEndNodes().parallelStream().forEach(StateNode::makeAccepting); - return this.result; - } - - /** Helper class to store a {@link Collection} of endNodes and startNodes. */ - private static class SubStateMachine { - - private final Collection startNodes; - private final Collection endNodes; - - public SubStateMachine(final StateNode startNode, final StateNode endNode) { - this(Collections.singleton(startNode), Collections.singleton(endNode)); - } - - public SubStateMachine( - final Collection startNodes, final Collection endNodes) { - this.startNodes = startNodes; - this.endNodes = endNodes; - } - - public Collection getStartNodes() { - return this.startNodes; - } - - public Collection getEndNodes() { - return this.endNodes; - } - } - - /** - * This method builds a {@link SubStateMachine} equivalent to the given {@link Order}. - * - *

It is called recursively For a collection of start nodes, which must already be added to - * the {@link StateMachineGraph} result. - * - * @param order The CrySL {@link Order} Expression to build the {@link SubStateMachine} for. - * @param startNodes Set of nodes used as the startNodes of this {@link SubStateMachine}. - * @return the {@link SubStateMachine} representing this {@link Order} Expression - *

Having a look at the Crysl Xtext definition for the Order section, we have ----------- - * - * Sequence returns Order: - * Alternative ({Order.left=current} op=SequenceOperator right=Alternative)* - * ; - * - * enum SequenceOperator returns OrderOperator: - * SEQUENCE = ',' - * ; - * - * Alternative returns Order: - * Cardinality ({Order.left=current} op=AlternativeOperator right=Cardinality)* - * ; - * - * enum AlternativeOperator returns OrderOperator: - * ALTERNATIVE = '|' - * ; - * - * Cardinality returns Order: - * Primary ({Order.left=current} op = CardinalityOperator)? - * ; - * - * enum CardinalityOperator returns OrderOperator: - * ZERO_OR_MORE = '*' | ONE_OR_MORE = '+' | ZERO_OR_ONE = '?' - * ; - * - * Primary returns Order: - * {Primary} event = [Event] - * | '(' Order ')' - * ; - * ----------- - *

Based on this definition, the method will build the StateMachine from the Order - * section. - *

This is done by recursively building a sub-StateMachine and connecting it with given - * start Nodes and returned end Nodes according to the specific OrderOperator. - *

Therefore, consider the following cases - *

1. Order instanceof Primary: In this case, we create a new Node and add an Transistion - * for the Event from each start Node to the newly created Node. Finally, we return a - * SubStateMachine where the newly created node is the start and end Node. - *

2. OrderOperator == SEQUENCE: The left-side should occur before the right-side. We - * therefore recursively build the sub-StateMachine of the left-side with the given start - * Nodes saving the returned end Nodes. We then build the sub-StateMachine of the right-side - * giving it the left-side's end Nodes as start Nodes. Finally, we return the startNodes of - * the left-side's start Nodes as our start Nodes and the end Nodes of the right-side's - * sub-StateMachine as our end Nodes. - *

3. OrderOperator == ALTERNATIVE: Either the left-side or the right-side should occur. - * We therefore build both sub-StateMachines with our start Nodes as start Nodes. Finally, - * we return the aggregate of both start Nodes as our startNodes and the aggregates of both - * end Nodes as our end Nodes. - *

4. OrderOperator == ZERO_OR_ONE: The Event can occur or be skipped. We therefore build - * the sub-StateMachine (only the left-side is present) with our start Nodes as start Nodes. - * Finally, we return the returned start Nodes as our start Nodes and the returned Nodes end - * Nodes (event occurs) and our start nodes (event skipped) as end Nodes. - *

5. OrderOperator == ONE_OR_MORE: The Event can occur once or multiple times. We - * therefore build the sub-StateMachine (only the left-side is present) with our start Nodes - * as start Nodes and save the returned end Nodes. We then duplicate the transitions from - * each given start Node to the start node of the Sub-StateMachine, but not with the given - * start Node as origin, but each end Node of the Sub-StateMachine, this creates the desired - * loop. Finally, we return the returned start and end Nodes. - *

5. OrderOperator == ZERO_OR_MORE: This can be seen as (Order)*?. We therefore proceed - * as in ONE_OR_MORE but additionally return the given start Nodes as end Nodes aswell as in - * ZERO_OR_ONE. - */ - private SubStateMachine buildSubSMG(final Order order, final Collection startNodes) { - - if (order == null) { - // This is the case if the ORDER section was omitted. - // It implies, that any method may be called in any sequence. - // We therefore create a Node and a transition from all startNodes - // to this node and a loop from the node to itself. - StateNode node = this.result.createNewNode(); - node.setAccepting(true); - Collection label = new HashSet<>(retrieveAllMethodsFromEvents()); - - for (StateNode startNode : startNodes) { - this.result.createNewEdge(label, startNode, node); - } - - this.result.createNewEdge(label, node, node); - return new SubStateMachine(Collections.singleton(node), startNodes); - } - - if (order instanceof Primary) { - Event event = ((Primary) order).getEvent(); - StateNode node = this.result.createNewNode(); - Collection label = CrySLReaderUtils.resolveEventToCryslMethods(event); - - for (StateNode startNode : startNodes) { - this.result.createNewEdge(label, startNode, node); - } - - return new SubStateMachine(node, node); - } - - Collection end = Sets.newHashSet(); - Collection start = Sets.newHashSet(); - - final SubStateMachine left; - final SubStateMachine right; - - switch (order.getOp()) { - case SEQUENCE: - left = buildSubSMG(order.getLeft(), startNodes); - right = buildSubSMG(order.getRight(), left.getEndNodes()); - start.addAll(left.getStartNodes()); - end.addAll(right.getEndNodes()); - - for (StateNode node : startNodes) { - if (left.getEndNodes().contains(node)) { - start.addAll(right.getStartNodes()); - } - } - - break; - case ALTERNATIVE: - left = buildSubSMG(order.getLeft(), startNodes); - right = buildSubSMG(order.getRight(), startNodes); - start.addAll(left.getStartNodes()); - start.addAll(right.getStartNodes()); - end.addAll(left.getEndNodes()); - end.addAll(right.getEndNodes()); - // TODO For some reason, this part removes loops in accepting states - // reduce all end nodes without outgoing edges to one end node - // Set endNodesWithOutgoingEdges = - // this.result.getEdges().parallelStream() - // .map(edge -> edge.from()).filter(node -> - // end.contains(node)).collect(Collectors.toSet()); - // if (endNodesWithOutgoingEdges.size() < end.size() - 1) { - // end.removeAll(endNodesWithOutgoingEdges); - // StateNode aggrNode = this.result.aggregateNodesToOneNode(end, - // end.iterator().next()); - // end.clear(); - // end.add(aggrNode); - // end.addAll(endNodesWithOutgoingEdges); - // } - break; - case ONE_OR_MORE: - case ZERO_OR_MORE: - case ZERO_OR_ONE: - left = buildSubSMG(order.getLeft(), startNodes); - start.addAll(left.getStartNodes()); - end.addAll(left.getEndNodes()); - if (order.getOp() == OrderOperator.ZERO_OR_MORE - || order.getOp() == OrderOperator.ONE_OR_MORE) { - startNodes.stream() - .map(this.result::getAllOutgoingEdges) - .flatMap(Collection::stream) - .filter(edge -> left.getStartNodes().contains(edge.getRight())) - .forEach( - edge -> - left.getEndNodes().stream() - .forEach( - endNode -> - this.result.createNewEdge( - edge.getLabel(), - endNode, - edge.getRight()))); - } - if (order.getOp() == OrderOperator.ZERO_OR_MORE - || order.getOp() == OrderOperator.ZERO_OR_ONE) { - end.addAll(startNodes); - } - break; - } - return new SubStateMachine(start, end); - } - - private Collection retrieveAllMethodsFromEvents() { - if (this.allMethods.isEmpty()) - this.allMethods.addAll(CrySLReaderUtils.resolveEventsToCryslMethods(this.events)); - return this.allMethods; - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/extractparameter/ExtractParameterAnalysis.java b/CryptoAnalysis/src/main/java/crypto/extractparameter/ExtractParameterAnalysis.java index f29c7c40a..3bb54bc2a 100644 --- a/CryptoAnalysis/src/main/java/crypto/extractparameter/ExtractParameterAnalysis.java +++ b/CryptoAnalysis/src/main/java/crypto/extractparameter/ExtractParameterAnalysis.java @@ -8,8 +8,8 @@ import boomerang.scene.Type; import boomerang.scene.Val; import crypto.extractparameter.transformation.TransformedAllocVal; -import crypto.rules.CrySLMethod; import crypto.utils.MatcherUtils; +import crysl.rule.CrySLMethod; import java.util.AbstractMap; import java.util.Collection; import java.util.HashSet; diff --git a/CryptoAnalysis/src/main/java/crypto/extractparameter/ExtractParameterDefinition.java b/CryptoAnalysis/src/main/java/crypto/extractparameter/ExtractParameterDefinition.java index f982f6c54..fadbbf7c6 100644 --- a/CryptoAnalysis/src/main/java/crypto/extractparameter/ExtractParameterDefinition.java +++ b/CryptoAnalysis/src/main/java/crypto/extractparameter/ExtractParameterDefinition.java @@ -5,7 +5,7 @@ import boomerang.scene.Statement; import boomerang.scene.sparse.SparseCFGCache; import crypto.listener.AnalysisReporter; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.util.Collection; public interface ExtractParameterDefinition { diff --git a/CryptoAnalysis/src/main/java/crypto/listener/AnalysisPrinter.java b/CryptoAnalysis/src/main/java/crypto/listener/AnalysisPrinter.java index 8f608a9a7..eb6ae369a 100644 --- a/CryptoAnalysis/src/main/java/crypto/listener/AnalysisPrinter.java +++ b/CryptoAnalysis/src/main/java/crypto/listener/AnalysisPrinter.java @@ -7,7 +7,7 @@ import crypto.analysis.IAnalysisSeed; import crypto.analysis.errors.AbstractError; import crypto.extractparameter.ExtractParameterQuery; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.util.Collection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/CryptoAnalysis/src/main/java/crypto/listener/AnalysisReporter.java b/CryptoAnalysis/src/main/java/crypto/listener/AnalysisReporter.java index aa74c3d18..049f8ffd5 100644 --- a/CryptoAnalysis/src/main/java/crypto/listener/AnalysisReporter.java +++ b/CryptoAnalysis/src/main/java/crypto/listener/AnalysisReporter.java @@ -24,8 +24,8 @@ import crypto.analysis.errors.UncaughtExceptionError; import crypto.extractparameter.CallSiteWithExtractedValue; import crypto.extractparameter.ExtractParameterQuery; -import crypto.rules.CrySLRule; -import crypto.rules.ISLConstraint; +import crysl.rule.CrySLRule; +import crysl.rule.ISLConstraint; import java.util.Collection; import java.util.HashSet; import java.util.Map; diff --git a/CryptoAnalysis/src/main/java/crypto/listener/IAnalysisListener.java b/CryptoAnalysis/src/main/java/crypto/listener/IAnalysisListener.java index cd00fff5b..794f26048 100644 --- a/CryptoAnalysis/src/main/java/crypto/listener/IAnalysisListener.java +++ b/CryptoAnalysis/src/main/java/crypto/listener/IAnalysisListener.java @@ -6,7 +6,7 @@ import crypto.analysis.IAnalysisSeed; import crypto.analysis.errors.AbstractError; import crypto.extractparameter.ExtractParameterQuery; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.util.Collection; public interface IAnalysisListener { diff --git a/CryptoAnalysis/src/main/java/crypto/listener/IResultsListener.java b/CryptoAnalysis/src/main/java/crypto/listener/IResultsListener.java index b327b296d..aaef32b58 100644 --- a/CryptoAnalysis/src/main/java/crypto/listener/IResultsListener.java +++ b/CryptoAnalysis/src/main/java/crypto/listener/IResultsListener.java @@ -10,7 +10,7 @@ import crypto.analysis.errors.AbstractError; import crypto.extractparameter.CallSiteWithExtractedValue; import crypto.extractparameter.ExtractParameterQuery; -import crypto.rules.ISLConstraint; +import crysl.rule.ISLConstraint; import java.util.Collection; import java.util.Map; import typestate.TransitionFunction; diff --git a/CryptoAnalysis/src/main/java/crypto/preanalysis/EmptyStatementTransformer.java b/CryptoAnalysis/src/main/java/crypto/preanalysis/EmptyStatementTransformer.java index 5e1f77e91..740749a89 100644 --- a/CryptoAnalysis/src/main/java/crypto/preanalysis/EmptyStatementTransformer.java +++ b/CryptoAnalysis/src/main/java/crypto/preanalysis/EmptyStatementTransformer.java @@ -1,6 +1,6 @@ package crypto.preanalysis; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.util.Collection; import java.util.HashSet; import java.util.Map; diff --git a/CryptoAnalysis/src/main/java/crypto/preanalysis/ExceptionAwareTransformer.java b/CryptoAnalysis/src/main/java/crypto/preanalysis/ExceptionAwareTransformer.java index fec272924..f65be1085 100644 --- a/CryptoAnalysis/src/main/java/crypto/preanalysis/ExceptionAwareTransformer.java +++ b/CryptoAnalysis/src/main/java/crypto/preanalysis/ExceptionAwareTransformer.java @@ -4,7 +4,7 @@ import boomerang.scene.jimple.JimpleMethod; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.util.HashMap; import java.util.Map; import java.util.Optional; diff --git a/CryptoAnalysis/src/main/java/crypto/preanalysis/TransformerSetup.java b/CryptoAnalysis/src/main/java/crypto/preanalysis/TransformerSetup.java index a706cb6c8..6cc374436 100644 --- a/CryptoAnalysis/src/main/java/crypto/preanalysis/TransformerSetup.java +++ b/CryptoAnalysis/src/main/java/crypto/preanalysis/TransformerSetup.java @@ -1,7 +1,7 @@ package crypto.preanalysis; import boomerang.scene.jimple.BoomerangPretransformer; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.util.Collection; public class TransformerSetup { diff --git a/CryptoAnalysis/src/main/java/crypto/reporting/CSVReporter.java b/CryptoAnalysis/src/main/java/crypto/reporting/CSVReporter.java index d7fe7b841..d6b5e4ce1 100644 --- a/CryptoAnalysis/src/main/java/crypto/reporting/CSVReporter.java +++ b/CryptoAnalysis/src/main/java/crypto/reporting/CSVReporter.java @@ -7,8 +7,8 @@ import crypto.analysis.IAnalysisSeed; import crypto.analysis.errors.AbstractError; import crypto.listener.AnalysisStatistics; -import crypto.rules.CrySLRule; import crypto.utils.ErrorUtils; +import crysl.rule.CrySLRule; import java.io.File; import java.io.FileWriter; import java.io.IOException; diff --git a/CryptoAnalysis/src/main/java/crypto/reporting/CSVSummaryReporter.java b/CryptoAnalysis/src/main/java/crypto/reporting/CSVSummaryReporter.java index e814d68e2..c3c0a073e 100644 --- a/CryptoAnalysis/src/main/java/crypto/reporting/CSVSummaryReporter.java +++ b/CryptoAnalysis/src/main/java/crypto/reporting/CSVSummaryReporter.java @@ -7,8 +7,8 @@ import crypto.analysis.IAnalysisSeed; import crypto.analysis.errors.AbstractError; import crypto.listener.AnalysisStatistics; -import crypto.rules.CrySLRule; import crypto.utils.ErrorUtils; +import crysl.rule.CrySLRule; import java.io.File; import java.io.FileWriter; import java.io.IOException; diff --git a/CryptoAnalysis/src/main/java/crypto/reporting/CommandLineReporter.java b/CryptoAnalysis/src/main/java/crypto/reporting/CommandLineReporter.java index 0a1d0da08..100d0dadf 100644 --- a/CryptoAnalysis/src/main/java/crypto/reporting/CommandLineReporter.java +++ b/CryptoAnalysis/src/main/java/crypto/reporting/CommandLineReporter.java @@ -6,7 +6,7 @@ import crypto.analysis.IAnalysisSeed; import crypto.analysis.errors.AbstractError; import crypto.listener.AnalysisStatistics; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.util.Collection; import java.util.Set; diff --git a/CryptoAnalysis/src/main/java/crypto/reporting/GitHubAnnotationReporter.java b/CryptoAnalysis/src/main/java/crypto/reporting/GitHubAnnotationReporter.java index be86a70e1..33de1aa57 100644 --- a/CryptoAnalysis/src/main/java/crypto/reporting/GitHubAnnotationReporter.java +++ b/CryptoAnalysis/src/main/java/crypto/reporting/GitHubAnnotationReporter.java @@ -6,8 +6,8 @@ import crypto.analysis.IAnalysisSeed; import crypto.analysis.errors.AbstractError; import crypto.listener.AnalysisStatistics; -import crypto.rules.CrySLRule; import crypto.utils.ErrorUtils; +import crysl.rule.CrySLRule; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; diff --git a/CryptoAnalysis/src/main/java/crypto/reporting/ReportGenerator.java b/CryptoAnalysis/src/main/java/crypto/reporting/ReportGenerator.java index 7af30e3ba..646d591d8 100644 --- a/CryptoAnalysis/src/main/java/crypto/reporting/ReportGenerator.java +++ b/CryptoAnalysis/src/main/java/crypto/reporting/ReportGenerator.java @@ -6,8 +6,8 @@ import crypto.analysis.IAnalysisSeed; import crypto.analysis.errors.AbstractError; import crypto.listener.AnalysisStatistics; -import crypto.rules.CrySLRule; import crypto.utils.ErrorUtils; +import crysl.rule.CrySLRule; import java.util.Collection; import java.util.List; import java.util.Map; diff --git a/CryptoAnalysis/src/main/java/crypto/reporting/Reporter.java b/CryptoAnalysis/src/main/java/crypto/reporting/Reporter.java index 05eba35d4..8fdd3d7ed 100644 --- a/CryptoAnalysis/src/main/java/crypto/reporting/Reporter.java +++ b/CryptoAnalysis/src/main/java/crypto/reporting/Reporter.java @@ -6,7 +6,7 @@ import crypto.analysis.IAnalysisSeed; import crypto.analysis.errors.AbstractError; import crypto.listener.AnalysisStatistics; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.io.File; import java.io.IOException; import java.util.Collection; diff --git a/CryptoAnalysis/src/main/java/crypto/reporting/ReporterFactory.java b/CryptoAnalysis/src/main/java/crypto/reporting/ReporterFactory.java index cd8be14c0..a1b09e933 100644 --- a/CryptoAnalysis/src/main/java/crypto/reporting/ReporterFactory.java +++ b/CryptoAnalysis/src/main/java/crypto/reporting/ReporterFactory.java @@ -1,6 +1,6 @@ package crypto.reporting; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.io.IOException; import java.util.Collection; import java.util.HashSet; diff --git a/CryptoAnalysis/src/main/java/crypto/reporting/SARIFReporter.java b/CryptoAnalysis/src/main/java/crypto/reporting/SARIFReporter.java index f4e865d7f..e16f14490 100644 --- a/CryptoAnalysis/src/main/java/crypto/reporting/SARIFReporter.java +++ b/CryptoAnalysis/src/main/java/crypto/reporting/SARIFReporter.java @@ -8,7 +8,7 @@ import crypto.analysis.IAnalysisSeed; import crypto.analysis.errors.AbstractError; import crypto.listener.AnalysisStatistics; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.io.File; import java.io.IOException; import java.nio.file.Paths; diff --git a/CryptoAnalysis/src/main/java/crypto/reporting/TXTReporter.java b/CryptoAnalysis/src/main/java/crypto/reporting/TXTReporter.java index 497538127..6b3f225cb 100644 --- a/CryptoAnalysis/src/main/java/crypto/reporting/TXTReporter.java +++ b/CryptoAnalysis/src/main/java/crypto/reporting/TXTReporter.java @@ -6,7 +6,7 @@ import crypto.analysis.IAnalysisSeed; import crypto.analysis.errors.AbstractError; import crypto.listener.AnalysisStatistics; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.io.File; import java.io.FileWriter; import java.io.IOException; diff --git a/CryptoAnalysis/src/main/java/crypto/rules/CrySLArithmeticConstraint.java b/CryptoAnalysis/src/main/java/crypto/rules/CrySLArithmeticConstraint.java deleted file mode 100644 index 424117ce5..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/CrySLArithmeticConstraint.java +++ /dev/null @@ -1,87 +0,0 @@ -package crypto.rules; - -import java.util.ArrayList; -import java.util.List; - -public class CrySLArithmeticConstraint extends CrySLLiteral { - - public enum ArithOp { - p, - n, - m - } - - /* p = + - * n = - - * m = % - */ - - private final ArithOp operator; - private final ICrySLPredicateParameter left; - private final ICrySLPredicateParameter right; - - public CrySLArithmeticConstraint( - ICrySLPredicateParameter l, ICrySLPredicateParameter r, ArithOp op) { - left = l; - right = r; - operator = op; - } - - /** - * @return the operator - */ - public ArithOp getOperator() { - return operator; - } - - /** - * @return the left - */ - public ICrySLPredicateParameter getLeft() { - return left; - } - - /** - * @return the right - */ - public ICrySLPredicateParameter getRight() { - return right; - } - - public String toString() { - return left - + " " - + (operator.equals(ArithOp.p) ? "+" : (operator.equals(ArithOp.m) ? "%" : "-")) - + " " - + right; - } - - @Override - public List getInvolvedVarNames() { - List varNames = new ArrayList<>(); - String name = left.getName(); - if (!isIntOrBoolean(name)) { - varNames.add(name); - } - - name = right.getName(); - if (!isIntOrBoolean(name)) { - varNames.add(name); - } - return varNames; - } - - private boolean isIntOrBoolean(String name) { - try { - Integer.parseInt(name); - return true; - } catch (NumberFormatException ex) { - return name.equalsIgnoreCase("false") || name.equalsIgnoreCase("true"); - } - } - - @Override - public String getName() { - return toString(); - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/CrySLComparisonConstraint.java b/CryptoAnalysis/src/main/java/crypto/rules/CrySLComparisonConstraint.java deleted file mode 100644 index f0aa1f791..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/CrySLComparisonConstraint.java +++ /dev/null @@ -1,80 +0,0 @@ -package crypto.rules; - -import java.util.List; - -public class CrySLComparisonConstraint extends CrySLLiteral { - - public enum CompOp { - l, - g, - le, - ge, - eq, - neq - } - - private final CompOp operator; - private final CrySLArithmeticConstraint left; - private final CrySLArithmeticConstraint right; - - public CrySLComparisonConstraint( - CrySLArithmeticConstraint l, CrySLArithmeticConstraint r, CompOp op) { - left = l; - right = r; - operator = op; - } - - public String toString() { - return left + " " + getOperatorString() + " " + right; - } - - private String getOperatorString() { - switch (operator) { - case l: - return "<"; - case le: - return "<="; - case g: - return ">"; - case ge: - return ">="; - case neq: - return "!="; - default: - return "="; - } - } - - /** - * @return the operator - */ - public CompOp getOperator() { - return operator; - } - - /** - * @return the left - */ - public CrySLArithmeticConstraint getLeft() { - return left; - } - - /** - * @return the right - */ - public CrySLArithmeticConstraint getRight() { - return right; - } - - @Override - public List getInvolvedVarNames() { - List varNames = left.getInvolvedVarNames(); - varNames.addAll(right.getInvolvedVarNames()); - return varNames; - } - - @Override - public String getName() { - return toString(); - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/CrySLCondPredicate.java b/CryptoAnalysis/src/main/java/crypto/rules/CrySLCondPredicate.java deleted file mode 100644 index 0f872ca15..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/CrySLCondPredicate.java +++ /dev/null @@ -1,52 +0,0 @@ -package crypto.rules; - -import java.util.Collection; -import java.util.List; - -public class CrySLCondPredicate extends CrySLPredicate { - - private final Collection conditionalNodes; - - public CrySLCondPredicate( - ICrySLPredicateParameter baseObj, - String name, - List parameters, - Boolean negated, - Collection nodes) { - this(baseObj, name, parameters, negated, nodes, null); - } - - public CrySLCondPredicate( - ICrySLPredicateParameter baseObj, - String name, - List parameters, - Boolean negated, - Collection nodes, - ISLConstraint constraint) { - super(baseObj, name, parameters, negated, constraint); - this.conditionalNodes = nodes; - } - - /** - * @return the conditionalMethods - */ - public Collection getConditionalMethods() { - return conditionalNodes; - } - - @Override - public boolean equals(Object obj) { - if (!super.equals(obj)) return false; - - if (!(obj instanceof CrySLCondPredicate)) return false; - - CrySLCondPredicate other = (CrySLCondPredicate) obj; - if (!getConditionalMethods().equals(other.getConditionalMethods())) return false; - - return true; - } - - public String toString() { - return super.toString() + " after " + conditionalNodes; - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/CrySLConstraint.java b/CryptoAnalysis/src/main/java/crypto/rules/CrySLConstraint.java deleted file mode 100644 index 4b91d938b..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/CrySLConstraint.java +++ /dev/null @@ -1,64 +0,0 @@ -package crypto.rules; - -import java.util.List; - -public class CrySLConstraint implements ISLConstraint { - - public enum LogOps { - and, - or, - implies, - eq - } - - private final LogOps operator; - private final ISLConstraint left; - private final ISLConstraint right; - - public CrySLConstraint(ISLConstraint l, ISLConstraint r, LogOps op) { - left = l; - right = r; - operator = op; - } - - /** - * @return the operator return operator; - */ - public LogOps getOperator() { - return operator; - } - - /** - * @return the left - */ - public ISLConstraint getLeft() { - return left; - } - - /** - * @return the right - */ - public ISLConstraint getRight() { - return right; - } - - public String toString() { - StringBuilder constraintSB = new StringBuilder(); - constraintSB.append(left.toString()); - constraintSB.append(operator); - constraintSB.append(right.toString()); - return constraintSB.toString(); - } - - @Override - public List getInvolvedVarNames() { - List varNames = left.getInvolvedVarNames(); - varNames.addAll(right.getInvolvedVarNames()); - return varNames; - } - - @Override - public String getName() { - return toString(); - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/CrySLException.java b/CryptoAnalysis/src/main/java/crypto/rules/CrySLException.java deleted file mode 100644 index 8408db512..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/CrySLException.java +++ /dev/null @@ -1,28 +0,0 @@ -package crypto.rules; - -/** Helper Class to store an {@link Exception} as a String. */ -public class CrySLException { - - private final String exception; - - /** - * Construct a {@link CrySLException} from the fully qualified classname of the {@link - * Exception} to store. - * - * @param exception the exception's name - */ - public CrySLException(String exception) { - this.exception = exception; - } - - /** - * @return The fully qualified classname of the stored {@link Exception}. - */ - public String getException() { - return exception; - } - - public String toString() { - return String.format("%s(%s)", this.getClass().getName(), this.exception); - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/CrySLExceptionConstraint.java b/CryptoAnalysis/src/main/java/crypto/rules/CrySLExceptionConstraint.java deleted file mode 100644 index 983b34d19..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/CrySLExceptionConstraint.java +++ /dev/null @@ -1,61 +0,0 @@ -package crypto.rules; - -import java.util.Collections; -import java.util.List; - -/** - * Constraint expressing, that a {@link CrySLMethod} throws an {@link CrySLException}, that must be - * caught. - */ -public class CrySLExceptionConstraint implements ISLConstraint { - - /** The Method throwing the Exception. */ - private final CrySLMethod method; - - /** The Exception thrown by the Method. */ - private final CrySLException exception; - - /** - * Construct the {@link CrySLExceptionConstraint} given the method and the exception thrown - * thereby. - * - * @param method Method that throws the Exception. - * @param exception Exception that thrown by the Method. - */ - public CrySLExceptionConstraint(CrySLMethod method, CrySLException exception) { - this.method = method; - this.exception = exception; - } - - /** - * Returns the Method throwing the Exception. - * - * @return The Method throwing the Exception. - */ - public CrySLMethod getMethod() { - return method; - } - - /** - * Returns the Exception thrown by the Exception. - * - * @return The Exception thrown by the Exception. - */ - public CrySLException getException() { - return exception; - } - - public String toString() { - return String.format("%s(%s, %s)", this.getClass().getName(), getMethod(), getException()); - } - - @Override - public List getInvolvedVarNames() { - return Collections.emptyList(); - } - - @Override - public String getName() { - return toString(); - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/CrySLForbiddenMethod.java b/CryptoAnalysis/src/main/java/crypto/rules/CrySLForbiddenMethod.java deleted file mode 100644 index 0e71568db..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/CrySLForbiddenMethod.java +++ /dev/null @@ -1,55 +0,0 @@ -package crypto.rules; - -import java.util.Collection; - -public class CrySLForbiddenMethod { - - private final CrySLMethod method; - private final Collection alternatives; - - public CrySLForbiddenMethod(CrySLMethod method, Collection alternatives) { - this.method = method; - this.alternatives = alternatives; - } - - public CrySLMethod getMethod() { - return method; - } - - public Collection getAlternatives() { - return alternatives; - } - - @Override - public String toString() { - final StringBuilder forbiddenMethod = new StringBuilder(); - forbiddenMethod.append(method.toString()); - if (!alternatives.isEmpty()) { - forbiddenMethod.append(" Alternatives: "); - } - - for (CrySLMethod meth : alternatives) { - forbiddenMethod.append(meth.toString()); - } - - return forbiddenMethod.toString(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (!(obj instanceof CrySLForbiddenMethod)) { - return false; - } - - CrySLForbiddenMethod other = (CrySLForbiddenMethod) obj; - if (!method.equals(other.getMethod())) { - return false; - } - - return alternatives.equals(other.getAlternatives()); - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/CrySLLiteral.java b/CryptoAnalysis/src/main/java/crypto/rules/CrySLLiteral.java deleted file mode 100644 index c2ca7ffd1..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/CrySLLiteral.java +++ /dev/null @@ -1,6 +0,0 @@ -package crypto.rules; - -public abstract class CrySLLiteral implements ISLConstraint { - - protected CrySLLiteral() {} -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/CrySLMethod.java b/CryptoAnalysis/src/main/java/crypto/rules/CrySLMethod.java deleted file mode 100644 index 8c0f5d4aa..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/CrySLMethod.java +++ /dev/null @@ -1,121 +0,0 @@ -package crypto.rules; - -import java.util.List; -import java.util.Map.Entry; -import java.util.stream.Collectors; - -public class CrySLMethod implements ICrySLPredicateParameter { - - public static final String VOID = "void"; - public static final String ANY_TYPE = "AnyType"; - public static final String NO_NAME = "_"; - - private final String methodName; - private final String declaringClassName; - private final Entry retObject; - - /** - * List of Parameters, where a Parameter is an {@link java.util.Map.Entry} of Name and Type, - * both as {@link String}. - */ - private final List> parameters; - - public CrySLMethod( - String methodName, - String declaringClassName, - List> parameters, - Entry retObject) { - this.methodName = methodName; - this.declaringClassName = declaringClassName; - this.parameters = parameters; - this.retObject = retObject; - } - - /** - * @return the FQ methodName - */ - public String getMethodName() { - return methodName; - } - - /** - * @return the short methodName - */ - public String getShortMethodName() { - return methodName.substring(methodName.lastIndexOf(".") + 1); - } - - public String getDeclaringClassName() { - return declaringClassName; - } - - /** - * @return the parameters - */ - public List> getParameters() { - return parameters; - } - - public Entry getRetObject() { - return retObject; - } - - public String toString() { - return getName(); - } - - public String getSignature() { - return getMethodName() - + "(" - + parameters.stream() - .map(param -> String.format("%s", param.getValue())) - .collect(Collectors.joining(", ")) - + ")"; - } - - @Override - public String getName() { - StringBuilder stmntBuilder = new StringBuilder(); - String returnValue = retObject.getKey(); - if (!"_".equals(returnValue)) { - stmntBuilder.append(returnValue); - stmntBuilder.append(" = "); - } - - stmntBuilder.append(this.methodName); - stmntBuilder.append("("); - - stmntBuilder.append( - parameters.stream() - .map(param -> String.format("%s %s", param.getValue(), param.getKey())) - .collect(Collectors.joining(", "))); - - stmntBuilder.append(");"); - return stmntBuilder.toString(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((methodName == null) ? 0 : methodName.hashCode()); - result = prime * result + ((parameters == null) ? 0 : parameters.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof CrySLMethod)) { - return false; - } - CrySLMethod other = (CrySLMethod) obj; - return this.getMethodName().equals(other.getMethodName()) - && parameters.equals(other.parameters); - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/CrySLObject.java b/CryptoAnalysis/src/main/java/crypto/rules/CrySLObject.java deleted file mode 100644 index 76b014489..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/CrySLObject.java +++ /dev/null @@ -1,64 +0,0 @@ -package crypto.rules; - -import java.util.Arrays; - -public class CrySLObject implements ICrySLPredicateParameter { - - private final String varName; - private final String javaType; - private final CrySLSplitter splitter; - - public CrySLObject(String name, String type) { - this(name, type, null); - } - - public CrySLObject(String name, String type, CrySLSplitter part) { - varName = name; - javaType = type; - splitter = part; - } - - /** - * @return the varName - */ - public String getVarName() { - return varName; - } - - /** - * @return the splitter - */ - public CrySLSplitter getSplitter() { - return splitter; - } - - @Override - public boolean equals(Object other) { - if (other == this) return true; - if (other == null) return false; - if (!(other instanceof CrySLObject)) return false; - CrySLObject object = (CrySLObject) other; - return this.getJavaType().equals(object.getJavaType()) - && this.getName().equals(object.getName()) - && (this.getSplitter() == null || this.getSplitter().equals(object.getSplitter())); - } - - @Override - public int hashCode() { - return Arrays.hashCode(new Object[] {varName, javaType, splitter}); - } - - @Override - public String toString() { - return javaType + " " + varName + ((splitter != null) ? splitter.toString() : ""); - } - - @Override - public String getName() { - return varName; - } - - public String getJavaType() { - return javaType; - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/CrySLPredicate.java b/CryptoAnalysis/src/main/java/crypto/rules/CrySLPredicate.java deleted file mode 100644 index b2747339d..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/CrySLPredicate.java +++ /dev/null @@ -1,156 +0,0 @@ -package crypto.rules; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -public class CrySLPredicate extends CrySLLiteral { - - protected final ICrySLPredicateParameter baseObject; - protected final String predName; - protected final List parameters; - protected final boolean negated; - protected final ISLConstraint constraint; - - public CrySLPredicate( - ICrySLPredicateParameter baseObject, - String name, - List parameters, - Boolean negated) { - this(baseObject, name, parameters, negated, null); - } - - public CrySLPredicate( - ICrySLPredicateParameter baseObject, - String name, - List parameters, - Boolean negated, - ISLConstraint constraint) { - this.baseObject = baseObject; - this.predName = name; - this.parameters = parameters; - this.negated = negated; - this.constraint = constraint; - } - - @Override - public int hashCode() { - return Arrays.hashCode(new Object[] {predName, parameters.size(), negated}); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (!(obj instanceof CrySLPredicate)) { - return false; - } - - CrySLPredicate other = (CrySLPredicate) obj; - if (baseObject == null) { - if (other.getBaseObject() != null) return false; - } else if (!baseObject.equals(other.getBaseObject())) { - return false; - } - - if (predName == null) { - if (other.getPredName() != null) return false; - } else if (!predName.equals(other.getPredName())) { - return false; - } - - if (parameters == null) { - if (other.getParameters() != null) return false; - } else if (parameters.size() != other.getParameters().size()) { - return false; - } - - return negated == other.isNegated(); - } - - /** - * @return the baseObject - */ - public ICrySLPredicateParameter getBaseObject() { - return baseObject; - } - - /** - * @return the predName - */ - public String getPredName() { - return predName; - } - - /** - * @return the optConstraint - */ - public Optional getConstraint() { - return Optional.ofNullable(constraint); - } - - /** - * @return the parameters - */ - public List getParameters() { - return parameters; - } - - /** - * @return the negated - */ - public Boolean isNegated() { - return negated; - } - - @Override - public String toString() { - StringBuilder predSB = new StringBuilder(); - if (negated) predSB.append("!"); - predSB.append(predName); - predSB.append("("); - predSB.append(parameters.stream().map(Object::toString).collect(Collectors.joining(", "))); - predSB.append(")"); - - return predSB.toString(); - } - - @Override - public List getInvolvedVarNames() { - List varNames = new ArrayList<>(); - if (Arrays.asList(new String[] {"neverTypeOf", "instanceOf"}).contains(predName)) { - varNames.add(parameters.get(0).getName()); - } else { - for (ICrySLPredicateParameter var : parameters) { - if (!("_".equals(var.getName()) - || "this".equals(var.getName()) - || var instanceof CrySLMethod)) { - varNames.add(var.getName()); - } - } - } - if (getBaseObject() != null) varNames.add(getBaseObject().getName()); - return varNames; - } - - public CrySLPredicate invertNegation() { - return new CrySLPredicate(baseObject, predName, parameters, !negated); - } - - public CrySLPredicate toNormalCrySLPredicate() { - return new CrySLPredicate(baseObject, predName, parameters, negated, constraint); - } - - @Override - public String getName() { - if (parameters.size() == 1) { - return parameters.get(0).getName(); - } else { - return ""; - } - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/CrySLRule.java b/CryptoAnalysis/src/main/java/crypto/rules/CrySLRule.java deleted file mode 100644 index 4d936ec25..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/CrySLRule.java +++ /dev/null @@ -1,171 +0,0 @@ -package crypto.rules; - -import java.util.Collection; -import java.util.LinkedList; -import java.util.Map; - -public class CrySLRule { - - private final String className; - - private final Collection> objects; - - private final Collection forbiddenMethods; - - private final Collection events; - - private final StateMachineGraph usagePattern; - - private final Collection constraints; - - private final Collection predicates; - - private final Collection negatedPredicates; - - public CrySLRule( - String className, - Collection> objects, - Collection forbiddenMethods, - Collection events, - StateMachineGraph usagePattern, - Collection constraints, - Collection predicates, - Collection negatedPredicates) { - this.className = className; - this.objects = objects; - this.forbiddenMethods = forbiddenMethods; - this.events = events; - this.usagePattern = usagePattern; - this.constraints = constraints; - this.predicates = predicates; - this.negatedPredicates = negatedPredicates; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof CrySLRule) { - return ((CrySLRule) obj).getClassName().equals(className); - } - return false; - } - - @Override - public int hashCode() { - return 31 * className.hashCode(); - } - - /** - * @return the className - */ - public String getClassName() { - return className; - } - - /** - * @return the objects - */ - public Collection> getObjects() { - return objects; - } - - /** - * @return the forbiddenMethods - */ - public Collection getForbiddenMethods() { - return forbiddenMethods; - } - - /** - * @return the events - */ - public Collection getEvents() { - return events; - } - - /** - * @return the usagePattern - */ - public StateMachineGraph getUsagePattern() { - return usagePattern; - } - - /** - * @return the constraints - */ - public Collection getConstraints() { - return constraints; - } - - /** - * @return the predicates - */ - public Collection getPredicates() { - return predicates; - } - - /** - * @return the negated predicates - */ - public Collection getNegatedPredicates() { - return negatedPredicates; - } - - /** - * @return the constraints - */ - public Collection getRequiredPredicates() { - Collection requires = new LinkedList<>(); - for (ISLConstraint con : constraints) { - if (con instanceof CrySLPredicate) { - requires.add((CrySLPredicate) con); - } - } - return requires; - } - - @Override - public String toString() { - StringBuilder outputSB = new StringBuilder(); - - outputSB.append(this.className); - - outputSB.append("\nforbiddenMethods:"); - for (CrySLForbiddenMethod forMethSig : this.forbiddenMethods) { - outputSB.append(forMethSig); - outputSB.append(", "); - } - - outputSB.append("\nEvents:"); - for (CrySLMethod method : events) { - outputSB.append(method); - outputSB.append(", "); - } - - outputSB.append("\nUsage Pattern:"); - outputSB.append(this.usagePattern); - - outputSB.append("\nConstraints:"); - for (ISLConstraint constraint : this.constraints) { - outputSB.append(constraint); - outputSB.append(", "); - } - - if (this.predicates != null) { - outputSB.append("\nPredicates:"); - for (CrySLPredicate predicate : this.predicates) { - outputSB.append(predicate); - outputSB.append(", "); - } - } - - if (this.negatedPredicates != null) { - outputSB.append("\nNegated predicates:"); - for (CrySLPredicate predicate : this.negatedPredicates) { - outputSB.append(predicate); - outputSB.append(", "); - } - } - - return outputSB.toString(); - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/CrySLSplitter.java b/CryptoAnalysis/src/main/java/crypto/rules/CrySLSplitter.java deleted file mode 100644 index 171ce4a0f..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/CrySLSplitter.java +++ /dev/null @@ -1,32 +0,0 @@ -package crypto.rules; - -public class CrySLSplitter { - - private final int index; - private final String split; - - public CrySLSplitter(int ind, String spl) { - this.index = ind; - this.split = spl; - } - - public int getIndex() { - return index; - } - - public String getSplitter() { - return split; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof CrySLSplitter)) return false; - - CrySLSplitter splitter = (CrySLSplitter) other; - return this.index == splitter.getIndex() && this.split.equals(splitter.getSplitter()); - } - - public String toString() { - return ".split(" + split + ")[" + index + "]"; - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/CrySLValueConstraint.java b/CryptoAnalysis/src/main/java/crypto/rules/CrySLValueConstraint.java deleted file mode 100644 index e42d23219..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/CrySLValueConstraint.java +++ /dev/null @@ -1,60 +0,0 @@ -package crypto.rules; - -import java.util.ArrayList; -import java.util.List; - -public class CrySLValueConstraint extends CrySLLiteral { - - CrySLObject var; - List valueRange; - - public CrySLValueConstraint(CrySLObject name, List values) { - var = name; - valueRange = values; - } - - /** - * @return the varName - */ - public String getVarName() { - return var.getVarName(); - } - - /** - * @return the varName - */ - public CrySLObject getVar() { - return var; - } - - /** - * @return the valueRange - */ - public List getValueRange() { - return valueRange; - } - - public String toString() { - StringBuilder vCSB = new StringBuilder(); - vCSB.append("VC:"); - vCSB.append(var); - vCSB.append(" - "); - for (String value : valueRange) { - vCSB.append(value); - vCSB.append(","); - } - return vCSB.toString(); - } - - @Override - public List getInvolvedVarNames() { - List varNames = new ArrayList<>(); - varNames.add(var.getVarName()); - return varNames; - } - - @Override - public String getName() { - return toString(); - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/FiniteStateMachine.java b/CryptoAnalysis/src/main/java/crypto/rules/FiniteStateMachine.java deleted file mode 100644 index 83cde1c51..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/FiniteStateMachine.java +++ /dev/null @@ -1,11 +0,0 @@ -package crypto.rules; - -import java.util.Collection; - -public interface FiniteStateMachine { - Transition getInitialTransition(); - - Collection getAcceptingStates(); - - Collection> getAllTransitions(); -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/ICrySLPredicateParameter.java b/CryptoAnalysis/src/main/java/crypto/rules/ICrySLPredicateParameter.java deleted file mode 100644 index bf378b46b..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/ICrySLPredicateParameter.java +++ /dev/null @@ -1,6 +0,0 @@ -package crypto.rules; - -public interface ICrySLPredicateParameter { - - String getName(); -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/ISLConstraint.java b/CryptoAnalysis/src/main/java/crypto/rules/ISLConstraint.java deleted file mode 100644 index f0c9a0264..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/ISLConstraint.java +++ /dev/null @@ -1,8 +0,0 @@ -package crypto.rules; - -import java.util.List; - -public interface ISLConstraint extends ICrySLPredicateParameter { - - List getInvolvedVarNames(); -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/StateMachineGraph.java b/CryptoAnalysis/src/main/java/crypto/rules/StateMachineGraph.java deleted file mode 100644 index c8c78b772..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/StateMachineGraph.java +++ /dev/null @@ -1,189 +0,0 @@ -package crypto.rules; - -import com.google.common.collect.Lists; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.stream.Collectors; - -public final class StateMachineGraph implements FiniteStateMachine { - - private StateNode startNode; - private final Collection nodes; - private final Collection edges; - private final Collection initialEdges; - private int nodeNameCounter = 0; - - public StateMachineGraph() { - nodes = new HashSet<>(); - edges = new ArrayList<>(); - initialEdges = new ArrayList<>(); - } - - public StateNode createNewNode() { - StateNode node = new StateNode(String.valueOf(this.nodeNameCounter++), false, false); - this.nodes.add(node); - return node; - } - - public boolean createNewEdge(Collection methods, StateNode left, StateNode right) { - return this.addEdge(new TransitionEdge(methods, left, right)); - } - - private Boolean addEdge(TransitionEdge edge) { - final StateNode right = edge.getRight(); - final StateNode left = edge.getLeft(); - if (!(nodes.parallelStream().anyMatch(e -> e.equals(left)) - || nodes.parallelStream().anyMatch(e -> e.equals(right)))) { - return false; - } - if (edges.contains(edge)) { - return false; - } - edges.add(edge); - - if (left.isInitialState()) { - initialEdges.add(edge); - } - - return true; - } - - public void wrapUpCreation() { - getAcceptingStates().parallelStream() - .forEach( - e -> { - e.setHopsToAccepting(0); - updateHops(e); - }); - } - - public Collection getAllOutgoingEdges(StateNode node) { - return edges.parallelStream() - .filter(edge -> edge.from().equals(node)) - .collect(Collectors.toSet()); - } - - public void addAllOutgoingEdgesFromOneNodeToOtherNodes( - StateNode node, Collection otherNodes) { - Collection edgesFromNode = - edges.parallelStream() - .filter(e -> node.equals(e.from())) - .collect(Collectors.toList()); - otherNodes.forEach( - otherNode -> - edgesFromNode.forEach( - edge -> - this.createNewEdge( - edge.getLabel(), otherNode, edge.getLeft()))); - } - - public StateNode aggregateNodesToOneNode(Collection endNodes, StateNode newNode) { - this.aggregateNodesToOtherNodes(endNodes, Lists.newArrayList(newNode)); - return newNode; - } - - public Collection aggregateNodesToOtherNodes( - Collection nodesToAggr, Collection startNodes) { - Collection edgesToAnyAggrNode = - edges.parallelStream() - .filter(e -> nodesToAggr.contains(e.to())) - .collect(Collectors.toList()); - // Add new edges to newNode instead of Aggr Node - startNodes.forEach( - node -> - edgesToAnyAggrNode.forEach( - edgeToAggrNode -> - this.createNewEdge( - edgeToAggrNode.getLabel(), - edgeToAggrNode.getLeft(), - node))); - nodesToAggr.removeAll(startNodes); - removeNodesWithAllEdges(nodesToAggr); - return startNodes; - } - - private void removeNodesWithAllEdges(Collection nodesToRemove) { - nodesToRemove.forEach(this::removeNodeWithAllEdges); - } - - private void removeNodeWithAllEdges(StateNode node) { - removeAllEdgesHavingNode(node); - nodes.remove(node); - } - - private void removeAllEdgesHavingNode(StateNode node) { - Collection filteredEdges = - edges.parallelStream() - .filter(e -> node.equals(e.to()) || node.equals(e.from())) - .collect(Collectors.toList()); - edges.removeAll(filteredEdges); - } - - private void updateHops(StateNode node) { - int newPath = node.getHopsToAccepting() + 1; - getAllTransitions().parallelStream() - .forEach( - e -> { - StateNode theNewRight = e.getLeft(); - if (e.getRight().equals(node) - && theNewRight.getHopsToAccepting() > newPath) { - theNewRight.setHopsToAccepting(newPath); - updateHops(theNewRight); - } - }); - } - - public Boolean addNode(StateNode node) { - if (node.isInitialState()) { - this.startNode = node; - } - return nodes.parallelStream().anyMatch(n -> n.getName().equals(node.getName())) - ? false - : nodes.add(node); - } - - public String toString() { - StringBuilder graphSB = new StringBuilder(); - for (StateNode node : nodes) { - graphSB.append(node.toString()); - graphSB.append(System.lineSeparator()); - } - - for (TransitionEdge te : edges) { - graphSB.append(te.toString()); - graphSB.append(System.lineSeparator()); - } - - return graphSB.toString(); - } - - public Collection getNodes() { - return nodes; - } - - public StateNode getStartNode() { - return startNode; - } - - public Collection getEdges() { - return edges; - } - - public TransitionEdge getInitialTransition() { - throw new UnsupportedOperationException( - "There is no single initial transition. Use getInitialTransitions()"); - } - - public Collection getInitialTransitions() { - return initialEdges; - } - - public Collection getAcceptingStates() { - return nodes.parallelStream().filter(StateNode::getAccepting).collect(Collectors.toList()); - } - - public Collection getAllTransitions() { - return getEdges(); - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/StateMachineGraphReader.java b/CryptoAnalysis/src/main/java/crypto/rules/StateMachineGraphReader.java deleted file mode 100644 index 89dbff309..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/StateMachineGraphReader.java +++ /dev/null @@ -1,23 +0,0 @@ -package crypto.rules; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; - -public class StateMachineGraphReader { - public static StateMachineGraph readFromFile(File file) { - StateMachineGraph smg = null; - try { - FileInputStream fileIn = new FileInputStream(file); - ObjectInputStream in = new ObjectInputStream(fileIn); - smg = (StateMachineGraph) in.readObject(); - System.err.println(smg); - in.close(); - fileIn.close(); - } catch (IOException | ClassNotFoundException e) { - e.printStackTrace(); - } - return smg; - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/StateNode.java b/CryptoAnalysis/src/main/java/crypto/rules/StateNode.java deleted file mode 100644 index 7655bb99f..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/StateNode.java +++ /dev/null @@ -1,100 +0,0 @@ -package crypto.rules; - -public class StateNode { - - private final String name; - - private final Boolean init; - private Boolean accepting; - private int hopsToAccepting = Integer.MAX_VALUE; - - public StateNode(String name) { - this(name, false, false); - } - - public StateNode(String name, Boolean init) { - this(name, init, false); - } - - public StateNode(String name, Boolean init, Boolean accepting) { - this.name = name; - this.init = init; - this.accepting = accepting; - } - - public String getName() { - return name; - } - - public Boolean getInit() { - return init; - } - - public Boolean getAccepting() { - return accepting; - } - - public void makeAccepting() { - this.accepting = true; - } - - public void setAccepting(Boolean accepting) { - this.accepting = accepting; - } - - public String toString() { - StringBuilder nodeSB = new StringBuilder(); - nodeSB.append("Name: "); - nodeSB.append(name); - nodeSB.append(" ("); - if (!accepting) { - nodeSB.append(hopsToAccepting + "hops to "); - } - nodeSB.append("accepting)"); - return nodeSB.toString(); - } - - public boolean isErrorState() { - return !accepting; - } - - public boolean isInitialState() { - return init; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((accepting == null) ? 0 : accepting.hashCode()); - result = prime * result + ((init == null) ? 0 : init.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - StateNode other = (StateNode) obj; - if (accepting == null) { - if (other.accepting != null) return false; - } else if (!accepting.equals(other.accepting)) return false; - if (init == null) { - if (other.init != null) return false; - } else if (!init.equals(other.init)) return false; - if (name == null) { - if (other.name != null) return false; - } else if (!name.equals(other.name)) return false; - return true; - } - - public void setHopsToAccepting(int hops) { - hopsToAccepting = hops; - } - - public int getHopsToAccepting() { - return hopsToAccepting; - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/Transition.java b/CryptoAnalysis/src/main/java/crypto/rules/Transition.java deleted file mode 100644 index c0ae332a4..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/Transition.java +++ /dev/null @@ -1,11 +0,0 @@ -package crypto.rules; - -import java.util.Collection; - -public interface Transition { - State from(); - - State to(); - - Collection getLabel(); -} diff --git a/CryptoAnalysis/src/main/java/crypto/rules/TransitionEdge.java b/CryptoAnalysis/src/main/java/crypto/rules/TransitionEdge.java deleted file mode 100644 index bd61ae494..000000000 --- a/CryptoAnalysis/src/main/java/crypto/rules/TransitionEdge.java +++ /dev/null @@ -1,74 +0,0 @@ -package crypto.rules; - -import java.util.Collection; - -public class TransitionEdge implements Transition { - - private final StateNode left; - private final StateNode right; - private final Collection methods; - - public TransitionEdge(Collection _methods, StateNode _left, StateNode _right) { - left = _left; - right = _right; - methods = _methods; - } - - public StateNode getLeft() { - return left; - } - - public StateNode getRight() { - return right; - } - - public Collection getLabel() { - return methods; - } - - @Override - public String toString() { - return "Left: " - + this.left.getName() - + " ====" - + methods - + "====> Right:" - + this.right.getName(); - } - - public StateNode from() { - return left; - } - - public StateNode to() { - return right; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((methods == null) ? 0 : methods.hashCode()); - result = prime * result + ((left == null) ? 0 : left.hashCode()); - result = prime * result + ((right == null) ? 0 : right.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - TransitionEdge other = (TransitionEdge) obj; - if (methods == null) { - if (other.methods != null) return false; - } else if (!methods.equals(other.methods)) return false; - if (left == null) { - if (other.left != null) return false; - } else if (!left.equals(other.left)) return false; - if (right == null) { - if (other.right != null) return false; - } else if (!right.equals(other.right)) return false; - return true; - } -} diff --git a/CryptoAnalysis/src/main/java/crypto/typestate/ForwardSeedQuery.java b/CryptoAnalysis/src/main/java/crypto/typestate/ForwardSeedQuery.java index 0e1284e85..f5100ac07 100644 --- a/CryptoAnalysis/src/main/java/crypto/typestate/ForwardSeedQuery.java +++ b/CryptoAnalysis/src/main/java/crypto/typestate/ForwardSeedQuery.java @@ -3,7 +3,7 @@ import boomerang.WeightedForwardQuery; import boomerang.scene.ControlFlowGraph; import boomerang.scene.Val; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.util.Collection; import typestate.TransitionFunction; diff --git a/CryptoAnalysis/src/main/java/crypto/typestate/LabeledMatcherTransition.java b/CryptoAnalysis/src/main/java/crypto/typestate/LabeledMatcherTransition.java index 8f4af9040..78cc40e39 100644 --- a/CryptoAnalysis/src/main/java/crypto/typestate/LabeledMatcherTransition.java +++ b/CryptoAnalysis/src/main/java/crypto/typestate/LabeledMatcherTransition.java @@ -1,8 +1,8 @@ package crypto.typestate; import boomerang.scene.DeclaredMethod; -import crypto.rules.CrySLMethod; import crypto.utils.MatcherUtils; +import crysl.rule.CrySLMethod; import java.util.Arrays; import java.util.Collection; import java.util.Optional; diff --git a/CryptoAnalysis/src/main/java/crypto/typestate/MatcherTransitionCollection.java b/CryptoAnalysis/src/main/java/crypto/typestate/MatcherTransitionCollection.java index ea0aeb6cf..0aa61cb1c 100644 --- a/CryptoAnalysis/src/main/java/crypto/typestate/MatcherTransitionCollection.java +++ b/CryptoAnalysis/src/main/java/crypto/typestate/MatcherTransitionCollection.java @@ -3,10 +3,10 @@ import boomerang.scene.ControlFlowGraph; import boomerang.scene.InvokeExpr; import boomerang.scene.Statement; -import crypto.rules.CrySLMethod; -import crypto.rules.StateMachineGraph; -import crypto.rules.StateNode; -import crypto.rules.TransitionEdge; +import crysl.rule.CrySLMethod; +import crysl.rule.StateMachineGraph; +import crysl.rule.StateNode; +import crysl.rule.TransitionEdge; import java.util.Collection; import java.util.Collections; import java.util.HashSet; diff --git a/CryptoAnalysis/src/main/java/crypto/typestate/ReportingErrorStateNode.java b/CryptoAnalysis/src/main/java/crypto/typestate/ReportingErrorStateNode.java index 635078948..9b090ee23 100644 --- a/CryptoAnalysis/src/main/java/crypto/typestate/ReportingErrorStateNode.java +++ b/CryptoAnalysis/src/main/java/crypto/typestate/ReportingErrorStateNode.java @@ -1,6 +1,6 @@ package crypto.typestate; -import crypto.rules.CrySLMethod; +import crysl.rule.CrySLMethod; import java.util.Collection; import typestate.finiteautomata.State; diff --git a/CryptoAnalysis/src/main/java/crypto/typestate/RuleTransitions.java b/CryptoAnalysis/src/main/java/crypto/typestate/RuleTransitions.java index 4b3bc7714..c7d20a1ea 100644 --- a/CryptoAnalysis/src/main/java/crypto/typestate/RuleTransitions.java +++ b/CryptoAnalysis/src/main/java/crypto/typestate/RuleTransitions.java @@ -1,7 +1,7 @@ package crypto.typestate; import boomerang.scene.ControlFlowGraph; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.util.Collection; import typestate.TransitionFunction; diff --git a/CryptoAnalysis/src/main/java/crypto/typestate/TypestateAnalysis.java b/CryptoAnalysis/src/main/java/crypto/typestate/TypestateAnalysis.java index 29760e236..bf041a297 100644 --- a/CryptoAnalysis/src/main/java/crypto/typestate/TypestateAnalysis.java +++ b/CryptoAnalysis/src/main/java/crypto/typestate/TypestateAnalysis.java @@ -9,7 +9,7 @@ import boomerang.scene.ControlFlowGraph; import boomerang.scene.DataFlowScope; import boomerang.scene.Val; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import ideal.IDEALAnalysis; import ideal.IDEALAnalysisDefinition; import ideal.IDEALResultHandler; diff --git a/CryptoAnalysis/src/main/java/crypto/typestate/TypestateAnalysisScope.java b/CryptoAnalysis/src/main/java/crypto/typestate/TypestateAnalysisScope.java index 1e44cad51..a9131d18e 100644 --- a/CryptoAnalysis/src/main/java/crypto/typestate/TypestateAnalysisScope.java +++ b/CryptoAnalysis/src/main/java/crypto/typestate/TypestateAnalysisScope.java @@ -16,11 +16,11 @@ import boomerang.scene.Method; import boomerang.scene.Statement; import boomerang.scene.Val; -import crypto.rules.CrySLMethod; -import crypto.rules.CrySLPredicate; -import crypto.rules.CrySLRule; -import crypto.rules.ICrySLPredicateParameter; import crypto.utils.MatcherUtils; +import crysl.rule.CrySLMethod; +import crysl.rule.CrySLPredicate; +import crysl.rule.CrySLRule; +import crysl.rule.ICrySLPredicateParameter; import java.util.Collection; import java.util.Collections; import java.util.HashSet; diff --git a/CryptoAnalysis/src/main/java/crypto/typestate/TypestateDefinition.java b/CryptoAnalysis/src/main/java/crypto/typestate/TypestateDefinition.java index eb3ee8848..ed39b3f1c 100644 --- a/CryptoAnalysis/src/main/java/crypto/typestate/TypestateDefinition.java +++ b/CryptoAnalysis/src/main/java/crypto/typestate/TypestateDefinition.java @@ -3,7 +3,7 @@ import boomerang.debugger.Debugger; import boomerang.scene.CallGraph; import boomerang.scene.DataFlowScope; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import ideal.IDEALSeedSolver; import java.util.Collection; import typestate.TransitionFunction; diff --git a/CryptoAnalysis/src/main/java/crypto/typestate/WrappedState.java b/CryptoAnalysis/src/main/java/crypto/typestate/WrappedState.java index b4c3f090b..74740fe84 100644 --- a/CryptoAnalysis/src/main/java/crypto/typestate/WrappedState.java +++ b/CryptoAnalysis/src/main/java/crypto/typestate/WrappedState.java @@ -1,6 +1,6 @@ package crypto.typestate; -import crypto.rules.StateNode; +import crysl.rule.StateNode; import typestate.finiteautomata.State; public class WrappedState implements State { diff --git a/CryptoAnalysis/src/main/java/crypto/utils/MatcherUtils.java b/CryptoAnalysis/src/main/java/crypto/utils/MatcherUtils.java index 829b93dce..a57e82bb3 100644 --- a/CryptoAnalysis/src/main/java/crypto/utils/MatcherUtils.java +++ b/CryptoAnalysis/src/main/java/crypto/utils/MatcherUtils.java @@ -2,8 +2,8 @@ import boomerang.scene.DeclaredMethod; import boomerang.scene.Type; -import crypto.rules.CrySLMethod; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLMethod; +import crysl.rule.CrySLRule; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; diff --git a/CryptoAnalysis/src/test/java/test/TestDataFlowScope.java b/CryptoAnalysis/src/test/java/test/TestDataFlowScope.java index c76261c83..57576abb3 100644 --- a/CryptoAnalysis/src/test/java/test/TestDataFlowScope.java +++ b/CryptoAnalysis/src/test/java/test/TestDataFlowScope.java @@ -6,7 +6,7 @@ import boomerang.scene.WrappedClass; import boomerang.scene.jimple.JimpleDeclaredMethod; import boomerang.scene.jimple.JimpleMethod; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.util.Collection; import java.util.HashSet; diff --git a/CryptoAnalysis/src/test/java/test/UsagePatternResultsListener.java b/CryptoAnalysis/src/test/java/test/UsagePatternResultsListener.java index 81b51c8ed..dbaa88eaa 100644 --- a/CryptoAnalysis/src/test/java/test/UsagePatternResultsListener.java +++ b/CryptoAnalysis/src/test/java/test/UsagePatternResultsListener.java @@ -15,7 +15,7 @@ import crypto.extractparameter.CallSiteWithExtractedValue; import crypto.extractparameter.ExtractParameterQuery; import crypto.listener.IResultsListener; -import crypto.rules.ISLConstraint; +import crysl.rule.ISLConstraint; import java.util.Collection; import java.util.Map; import test.assertions.ExtractedValueAssertion; diff --git a/CryptoAnalysis/src/test/java/test/finitestatemachine/BufferedBlockCipherTest.java b/CryptoAnalysis/src/test/java/test/finitestatemachine/BufferedBlockCipherTest.java deleted file mode 100644 index aee2b2317..000000000 --- a/CryptoAnalysis/src/test/java/test/finitestatemachine/BufferedBlockCipherTest.java +++ /dev/null @@ -1,15 +0,0 @@ -package test.finitestatemachine; - -public class BufferedBlockCipherTest extends FiniteStateMachineTestingFramework { - - public BufferedBlockCipherTest() { - super("BufferedBlockCipher"); - this.order = - new Simple( - new E("BufferedBlockCipher"), - new Plus( - new Simple(new E("init"), new E("processByte"), new E("doFinal")))); - } - // Cons, (Inits, Procs, DOFINALS)+ - -} diff --git a/CryptoAnalysis/src/test/java/test/finitestatemachine/CipherTest.java b/CryptoAnalysis/src/test/java/test/finitestatemachine/CipherTest.java deleted file mode 100644 index 613aadf20..000000000 --- a/CryptoAnalysis/src/test/java/test/finitestatemachine/CipherTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package test.finitestatemachine; - -public class CipherTest extends FiniteStateMachineTestingFramework { - - public CipherTest() { - super("Cipher"); - this.order = - new Simple( - new E("getInstance"), - new Plus(new E("init")), - new Or( - new Plus(new E("wrap")), - new Plus( - new Or( - new E("doFinal"), - new Simple( - new Plus(new E("update")), - new E("doFinal")))))); - } - // Gets, Inits+, WKB+ | (FINWOU | (Updates+, DOFINALS))+ - -} diff --git a/CryptoAnalysis/src/test/java/test/finitestatemachine/ECElGamalDecryptorTest.java b/CryptoAnalysis/src/test/java/test/finitestatemachine/ECElGamalDecryptorTest.java deleted file mode 100644 index 397e81c01..000000000 --- a/CryptoAnalysis/src/test/java/test/finitestatemachine/ECElGamalDecryptorTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package test.finitestatemachine; - -public class ECElGamalDecryptorTest extends FiniteStateMachineTestingFramework { - - public ECElGamalDecryptorTest() { - super("ECElGamalDecryptor"); - order = - new Simple( - new E("ECElGamalDecryptor"), - new Plus(new Simple(new E("init"), new Plus(new E("decrypt"))))); - } - // Cons, (Inits, Decrypts+)+ - -} diff --git a/CryptoAnalysis/src/test/java/test/finitestatemachine/FiniteStateMachineTestingFramework.java b/CryptoAnalysis/src/test/java/test/finitestatemachine/FiniteStateMachineTestingFramework.java deleted file mode 100644 index 0101a89b9..000000000 --- a/CryptoAnalysis/src/test/java/test/finitestatemachine/FiniteStateMachineTestingFramework.java +++ /dev/null @@ -1,260 +0,0 @@ -package test.finitestatemachine; - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import crypto.cryslhandler.RulesetReader; -import crypto.rules.CrySLRule; -import crypto.rules.StateMachineGraph; -import crypto.rules.StateNode; -import crypto.rules.TransitionEdge; -import java.io.IOException; -import java.util.Collection; -import java.util.List; -import java.util.Random; -import java.util.Set; -import java.util.stream.Collectors; -import org.junit.Before; -import test.TestConstants; - -public abstract class FiniteStateMachineTestingFramework { - - private StateMachineGraph smg; - private String crySLRule; - protected Order order; - protected static int maxRepeat; - - public FiniteStateMachineTestingFramework(String crySLRule) { - this.crySLRule = crySLRule; - } - - // uncomment "@Test" to test the StatemachineBuilder. - // These tests require a lot of memory and runtime and are thus excluded to not run each time. - // Further, the tests solely test the StatemachineBuilder and thereby only require to be - // executed when changing the Builder. - // @Test - public void simulate() { - if (order != null) { - benchmark(); - } - } - - public void benchmark() { - // valid paths - maxRepeat = 1; - List> allPossiblePathsMaxRepeat1 = order.get(); - maxRepeat = 3; - List> allPossiblePathsMaxRepeat3 = order.get(); - for (List path : allPossiblePathsMaxRepeat3) { - assertInSMG(path); - } - // invalid paths - assertRandomInvalidPaths(allPossiblePathsMaxRepeat1, allPossiblePathsMaxRepeat3); - } - - public void assertRandomInvalidPaths( - List> pathsWithSmallRepeat, List> pathsWithLargeRepeat) { - for (List path : pathsWithSmallRepeat) { - if (path.size() > 1) { - for (int i = 0; i < 10; i++) { - List events = Lists.newArrayList(path); - switch ((new Random()).nextInt(2)) { - case 0: - // delete an event - int rand = (new Random()).nextInt(events.size()); - events.remove(rand); - break; - case 1: - // switch two events - int rand1 = (new Random()).nextInt(events.size()); - String event = events.remove(rand1); - int rand2 = (new Random()).nextInt(events.size()); - events.add(rand2, event); - break; - } - if (!pathsWithLargeRepeat.contains(events)) { - assertNotInSMG(events); - } - } - } - } - } - - public void assertInSMG(List methodPath) { - if (!isPathOfMethodsInSMG(methodPath)) { - throw new AssertionError( - "Order of calls are not in SMG but should be: " + methodPath.toString()); - } - ; - } - - public void assertNotInSMG(List methodPath) { - if (!methodPath.isEmpty() && isPathOfMethodsInSMG(methodPath)) { - // the initial state is always accepting. - throw new AssertionError( - "Order of calls are in SMG but should probably not be: " - + methodPath.toString()); - } - ; - } - - private boolean isPathOfMethodsInSMG(List methodPath) { - final Set current = Sets.newHashSet(); - // current.add(smg.getInitialTransition().getLeft()); - for (String event : methodPath) { - List matchingEdges = - smg.getAllTransitions().stream() - .filter( - edge -> - current.contains(edge.getLeft()) - && edge.getLabel().stream() - .anyMatch( - label -> - label.getName() - .contains( - event))) - .collect(Collectors.toList()); - if (matchingEdges.size() == 0) { - // found no matching edge - return false; - } - current.clear(); - matchingEdges.forEach(edge -> current.add(edge.getRight())); - } - return current.stream().anyMatch(node -> node.getAccepting()); - } - - @Before - public void createSMG() { - RulesetReader reader = new RulesetReader(); - - try { - Collection rules = reader.readRulesFromPath(TestConstants.JCA_RULESET_PATH); - - for (CrySLRule rule : rules) { - if (rule.getClassName().equals(crySLRule)) { - smg = rule.getUsagePattern(); - } - } - } catch (IOException e) { - throw new RuntimeException(e.getMessage()); - } - } - - // - // Classes of type Order are able to generate all possible paths of events - // up to a certain recursion depth for * and + - // - - public interface Order { - List> get(); - } - - public class Simple implements Order { - private Order[] order; - - public Simple(Order... order) { - this.order = order; - } - - public List> get() { - List> result = Lists.newArrayList(); - result.add(Lists.newArrayList()); - for (Order o : order) { - List> possibleNextSteps = o.get(); - List> possiblePathesWithNextSteps = Lists.newArrayList(); - for (List possiblePathesUpToThisOrderIteration : result) { - for (List nextSteps : possibleNextSteps) { - List tmp = Lists.newArrayList(possiblePathesUpToThisOrderIteration); - tmp.addAll(nextSteps); - possiblePathesWithNextSteps.add(tmp); - } - } - result = possiblePathesWithNextSteps; - } - return result; - } - } - - public class Or implements Order { - private Order[] order; - - public Or(Order... order) { - this.order = order; - } - - public List> get() { - List> result = Lists.newArrayList(); - for (Order o : order) { - result.addAll(o.get()); - } - return result; - } - } - - public static class Plus implements Order { - private Order order; - - public Plus(Order order) { - this.order = order; - } - - public List> get() { - List> result = Lists.newArrayList(); - result.add(Lists.newArrayList()); - for (int i = 0; i < FiniteStateMachineTestingFramework.maxRepeat; i++) { - List> newPathes = Lists.newArrayList(); - for (List possibleStartPaths : result) { - for (List possibleRepeats : order.get()) { - List clone = Lists.newArrayList(possibleStartPaths); - clone.addAll(possibleRepeats); - newPathes.add(clone); - } - } - result.addAll(newPathes); - } - result.remove(0); // empty path should not be in result - return result; - } - } - - public class Opt implements Order { - private Order order; - - public Opt(Order order) { - this.order = order; - } - - public List> get() { - List> result = Lists.newArrayList(); - result.add(Lists.newArrayList()); - result.addAll(order.get()); - return result; - } - } - - public class Star implements Order { - private Order order; - - public Star(Order order) { - this.order = new Opt(new Plus(order)); - } - - public List> get() { - return order.get(); - } - } - - public class E implements Order { - private String event; - - public E(String event) { - this.event = event; - } - - public List> get() { - List> result = Lists.newArrayList(); - result.add(Lists.newArrayList(event)); - return result; - } - } -} diff --git a/CryptoAnalysis/src/test/java/test/finitestatemachine/HMacTest.java b/CryptoAnalysis/src/test/java/test/finitestatemachine/HMacTest.java deleted file mode 100644 index 412325ece..000000000 --- a/CryptoAnalysis/src/test/java/test/finitestatemachine/HMacTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package test.finitestatemachine; - -public class HMacTest extends FiniteStateMachineTestingFramework { - - public HMacTest() { - super("HMac"); - this.order = - new Simple( - new E("HMac"), - new Plus( - new Simple( - new E("init"), - new Plus(new E("update")), - new E("doFinal")))); - } - // Cons, (Init, Updates+, Finals)+ - -} diff --git a/CryptoAnalysis/src/test/java/test/finitestatemachine/KeyFactoryTest.java b/CryptoAnalysis/src/test/java/test/finitestatemachine/KeyFactoryTest.java deleted file mode 100644 index d1fbc0f31..000000000 --- a/CryptoAnalysis/src/test/java/test/finitestatemachine/KeyFactoryTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package test.finitestatemachine; - -public class KeyFactoryTest extends FiniteStateMachineTestingFramework { - - public KeyFactoryTest() { - super("KeyFactory"); - this.order = - new Simple( - new E("getInstance"), - new Star( - new Or( - new Star(new E("generatePrivate")), - new Star(new E("generatePublic"))))); - } - // Gets, (GenPriv* | GenPubl*)* - -} diff --git a/CryptoAnalysis/src/test/java/test/finitestatemachine/KeyStoreTest.java b/CryptoAnalysis/src/test/java/test/finitestatemachine/KeyStoreTest.java deleted file mode 100644 index 402937c67..000000000 --- a/CryptoAnalysis/src/test/java/test/finitestatemachine/KeyStoreTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package test.finitestatemachine; - -public class KeyStoreTest extends FiniteStateMachineTestingFramework { - - public KeyStoreTest() { - super("KeyStore"); - this.order = - new Simple( - new E("getInstance"), - new E("load"), - new Star( - new Or( - new Simple(new Opt(new E("getEntry")), new E("getKey")), - new Simple(new E("setEntry"), new E("store"))))); - } - // Gets, Loads, ((GetEntry?, GetKey) | (SetEntry, Stores))* - -} diff --git a/CryptoAnalysis/src/test/java/test/finitestatemachine/MessageDigestTest.java b/CryptoAnalysis/src/test/java/test/finitestatemachine/MessageDigestTest.java deleted file mode 100644 index 6c7881eeb..000000000 --- a/CryptoAnalysis/src/test/java/test/finitestatemachine/MessageDigestTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package test.finitestatemachine; - -public class MessageDigestTest extends FiniteStateMachineTestingFramework { - - public MessageDigestTest() { - super("MessageDigest"); - this.order = - new Simple( - new E("getInstance"), - new Plus( - new Or( - new E("digest"), - new Simple(new Plus(new E("update")), new E("digest"))))); - } - // Gets, (DWOU | (Updates+, Digests))+ - -} diff --git a/CryptoAnalysis/src/test/java/test/finitestatemachine/SHA256DigestTest.java b/CryptoAnalysis/src/test/java/test/finitestatemachine/SHA256DigestTest.java deleted file mode 100644 index 301021079..000000000 --- a/CryptoAnalysis/src/test/java/test/finitestatemachine/SHA256DigestTest.java +++ /dev/null @@ -1,15 +0,0 @@ -package test.finitestatemachine; - -public class SHA256DigestTest extends FiniteStateMachineTestingFramework { - - public SHA256DigestTest() { - super("SHA256Digest"); - - this.order = - new Simple( - new E("SHA256Digest"), - new Star(new Simple(new Plus(new E("update")), new E("doFinal")))); - } - // Cons, (Updates+, Finals)* - -} diff --git a/CryptoAnalysis/src/test/java/test/finitestatemachine/SSLEngineTest.java b/CryptoAnalysis/src/test/java/test/finitestatemachine/SSLEngineTest.java deleted file mode 100644 index af6203373..000000000 --- a/CryptoAnalysis/src/test/java/test/finitestatemachine/SSLEngineTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package test.finitestatemachine; - -public class SSLEngineTest extends FiniteStateMachineTestingFramework { - - public SSLEngineTest() { - super("SSLEngine"); - this.order = - new Or( - new Simple(new E("setEnabledCipherSuites"), new E("setEnabledProtocols")), - new Simple(new E("setEnabledProtocols"), new E("setEnabledCipherSuites"))); - } - // (EnableCipher, EnableProtocol) | (EnableProtocol, EnableCipher) - -} diff --git a/CryptoAnalysis/src/test/java/test/finitestatemachine/SecretKey.java b/CryptoAnalysis/src/test/java/test/finitestatemachine/SecretKey.java deleted file mode 100644 index 0e88463a5..000000000 --- a/CryptoAnalysis/src/test/java/test/finitestatemachine/SecretKey.java +++ /dev/null @@ -1,11 +0,0 @@ -package test.finitestatemachine; - -public class SecretKey extends FiniteStateMachineTestingFramework { - - public SecretKey() { - super("SecretKey"); - this.order = new Simple(new Star(new E("getEncoded")), new Opt(new E("destroy"))); - } - // GetEnc*, Destroy? - -} diff --git a/CryptoAnalysis/src/test/java/test/finitestatemachine/SecureRandom.java b/CryptoAnalysis/src/test/java/test/finitestatemachine/SecureRandom.java deleted file mode 100644 index aee117c70..000000000 --- a/CryptoAnalysis/src/test/java/test/finitestatemachine/SecureRandom.java +++ /dev/null @@ -1,18 +0,0 @@ -package test.finitestatemachine; - -public class SecureRandom extends FiniteStateMachineTestingFramework { - - public SecureRandom() { - super("SecureRandom"); - - this.order = - new Simple( - new E("getInstance"), - new Star( - new Simple( - new Opt(new E("setSeed")), - new Star(new E("generateSeed"))))); - } - // Ins, (Seeds?, Ends*)* - -} diff --git a/CryptoAnalysis/src/test/java/test/finitestatemachine/SignatureTest.java b/CryptoAnalysis/src/test/java/test/finitestatemachine/SignatureTest.java deleted file mode 100644 index df63d4ec4..000000000 --- a/CryptoAnalysis/src/test/java/test/finitestatemachine/SignatureTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package test.finitestatemachine; - -public class SignatureTest extends FiniteStateMachineTestingFramework { - - public SignatureTest() { - super("Signature"); - this.order = - new Simple( - new E("getInstance"), - new Or( - new Simple( - new Plus(new E("initSign")), - new Plus( - new Simple( - new Plus(new E("update")), - new Plus(new E("sign"))))), - new Simple( - new Plus(new E("initVerify")), - new Plus( - new Simple( - new Star(new E("update")), - new Plus(new E("verify"))))))); - } - // THIS HAS TO MANY REPEATITIONS - // The Test framework is not able to generate all possible paths for the following - // Gets, ((InitSigns+, (Updates+, Signs+)+ )+ | (InitVerifies+, (Updates*, Verifies+)+ )+ ) - - // We simplify it to - // Gets, ( InitSigns+, (Updates+, Signs+)+ | InitVerifies+, (Updates*, Verifies+)+ ) -} diff --git a/CryptoAnalysis/src/test/java/tests/crysl/RulesetReaderTest.java b/CryptoAnalysis/src/test/java/tests/crysl/RulesetReaderTest.java deleted file mode 100644 index b13941338..000000000 --- a/CryptoAnalysis/src/test/java/tests/crysl/RulesetReaderTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package tests.crysl; - -import crypto.cryslhandler.RulesetReader; -import crypto.rules.CrySLRule; -import java.io.IOException; -import java.util.Collection; -import org.apache.commons.lang3.time.StopWatch; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -public class RulesetReaderTest { - - private static final String emptyZipFilePath = "src/test/resources/crySL/empty.zip"; - private static final String jcaRulesetZipFilePath = - "src/test/resources/crySL/JavaCryptographicArchitecture-3.0.1-ruleset.zip"; - private static final String junkRuleSet = "src/test/resources/crySL/rulesetWithJunk.zip"; - - @Test - public void testJunkThrows() throws IOException { - RulesetReader reader = new RulesetReader(); - Collection rules = reader.readRulesFromPath(junkRuleSet); - - Assert.assertEquals(48, rules.size()); - } - - @Test - public void testNumberOfRules() throws IOException { - RulesetReader reader = new RulesetReader(); - Collection rules = reader.readRulesFromPath(jcaRulesetZipFilePath); - - Assert.assertEquals(49, rules.size()); - } - - @Test - public void testRulesZipFile() throws IOException { - RulesetReader reader = new RulesetReader(); - Collection rules = reader.readRulesFromZipArchive(jcaRulesetZipFilePath); - - Assert.assertEquals(49, rules.size()); - } - - @Test(expected = IOException.class) - public void testFileNotExists() throws IOException { - RulesetReader reader = new RulesetReader(); - Collection rules = reader.readRulesFromPath("notExist"); - Assert.assertEquals(0, rules.size()); - } - - @Test - public void testFileNoCrySLFiles() throws IOException { - RulesetReader reader = new RulesetReader(); - Collection rules = reader.readRulesFromPath(emptyZipFilePath); - - Assert.assertEquals(0, rules.size()); - } - - @Test - public void testRunTwiceSameResult() throws IOException { - RulesetReader reader = new RulesetReader(); - Collection rules = reader.readRulesFromPath(jcaRulesetZipFilePath); - Assert.assertEquals(49, rules.size()); - - rules = reader.readRulesFromPath(jcaRulesetZipFilePath); - Assert.assertEquals(49, rules.size()); - } - - @Test - @Ignore - public void TestPerformanceReducesSignificantlySecondTime() throws IOException { - StopWatch watch = new StopWatch(); - watch.start(); - RulesetReader reader = new RulesetReader(); - reader.readRulesFromZipArchive(jcaRulesetZipFilePath); - watch.stop(); - long firstRun = watch.getTime(); - watch.reset(); - watch.start(); - reader.readRulesFromZipArchive(jcaRulesetZipFilePath); - watch.stop(); - long secondRun = watch.getTime(); - Assert.assertTrue(secondRun * 100 < firstRun); - System.out.println("First: " + firstRun + "; Second: " + secondRun); - } -} diff --git a/CryptoAnalysis/src/test/resources/crySL/JavaCryptographicArchitecture-3.0.1-ruleset.zip b/CryptoAnalysis/src/test/resources/crySL/JavaCryptographicArchitecture-3.0.1-ruleset.zip deleted file mode 100644 index a9f61457b..000000000 Binary files a/CryptoAnalysis/src/test/resources/crySL/JavaCryptographicArchitecture-3.0.1-ruleset.zip and /dev/null differ diff --git a/CryptoAnalysis/src/test/resources/crySL/Multiple-rulesets.zip b/CryptoAnalysis/src/test/resources/crySL/Multiple-rulesets.zip deleted file mode 100644 index 1eb076c36..000000000 Binary files a/CryptoAnalysis/src/test/resources/crySL/Multiple-rulesets.zip and /dev/null differ diff --git a/CryptoAnalysis/src/test/resources/crySL/empty.zip b/CryptoAnalysis/src/test/resources/crySL/empty.zip deleted file mode 100644 index 15cb0ecb3..000000000 Binary files a/CryptoAnalysis/src/test/resources/crySL/empty.zip and /dev/null differ diff --git a/CryptoAnalysis/src/test/resources/crySL/rulesetWithJunk.zip b/CryptoAnalysis/src/test/resources/crySL/rulesetWithJunk.zip deleted file mode 100644 index 8bfa12533..000000000 Binary files a/CryptoAnalysis/src/test/resources/crySL/rulesetWithJunk.zip and /dev/null differ diff --git a/HeadlessAndroidScanner/src/main/java/de/fraunhofer/iem/android/AndroidDataFlowScope.java b/HeadlessAndroidScanner/src/main/java/de/fraunhofer/iem/android/AndroidDataFlowScope.java index ee047e4eb..65e4b07f9 100644 --- a/HeadlessAndroidScanner/src/main/java/de/fraunhofer/iem/android/AndroidDataFlowScope.java +++ b/HeadlessAndroidScanner/src/main/java/de/fraunhofer/iem/android/AndroidDataFlowScope.java @@ -3,7 +3,7 @@ import boomerang.scene.DeclaredMethod; import boomerang.scene.Method; import crypto.analysis.CryptoAnalysisDataFlowScope; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.util.Collection; public class AndroidDataFlowScope extends CryptoAnalysisDataFlowScope { diff --git a/HeadlessAndroidScanner/src/main/java/de/fraunhofer/iem/android/FlowDroidSetup.java b/HeadlessAndroidScanner/src/main/java/de/fraunhofer/iem/android/FlowDroidSetup.java index ce8b5ef3e..09c56e4e5 100644 --- a/HeadlessAndroidScanner/src/main/java/de/fraunhofer/iem/android/FlowDroidSetup.java +++ b/HeadlessAndroidScanner/src/main/java/de/fraunhofer/iem/android/FlowDroidSetup.java @@ -4,7 +4,7 @@ import boomerang.scene.jimple.SootCallGraph; import com.google.common.base.Stopwatch; import crypto.preanalysis.TransformerSetup; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import java.io.File; import java.util.ArrayList; import java.util.Collection; diff --git a/HeadlessJavaScanner/src/main/java/de/fraunhofer/iem/framework/FrameworkSetup.java b/HeadlessJavaScanner/src/main/java/de/fraunhofer/iem/framework/FrameworkSetup.java index 2df383617..25ca3e501 100644 --- a/HeadlessJavaScanner/src/main/java/de/fraunhofer/iem/framework/FrameworkSetup.java +++ b/HeadlessJavaScanner/src/main/java/de/fraunhofer/iem/framework/FrameworkSetup.java @@ -2,7 +2,7 @@ import boomerang.scene.CallGraph; import com.google.common.base.Stopwatch; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import de.fraunhofer.iem.scanner.ScannerSettings; import java.util.Collection; import org.slf4j.Logger; diff --git a/HeadlessJavaScanner/src/main/java/de/fraunhofer/iem/framework/OpalSetup.java b/HeadlessJavaScanner/src/main/java/de/fraunhofer/iem/framework/OpalSetup.java index 028a11f6d..c2caab662 100644 --- a/HeadlessJavaScanner/src/main/java/de/fraunhofer/iem/framework/OpalSetup.java +++ b/HeadlessJavaScanner/src/main/java/de/fraunhofer/iem/framework/OpalSetup.java @@ -1,7 +1,7 @@ package de.fraunhofer.iem.framework; import boomerang.scene.CallGraph; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import de.fraunhofer.iem.scanner.ScannerSettings; import java.util.Collection; diff --git a/HeadlessJavaScanner/src/main/java/de/fraunhofer/iem/framework/SootSetup.java b/HeadlessJavaScanner/src/main/java/de/fraunhofer/iem/framework/SootSetup.java index 146055a8c..e460fe3f9 100644 --- a/HeadlessJavaScanner/src/main/java/de/fraunhofer/iem/framework/SootSetup.java +++ b/HeadlessJavaScanner/src/main/java/de/fraunhofer/iem/framework/SootSetup.java @@ -5,7 +5,7 @@ import com.google.common.collect.Lists; import crypto.exceptions.CryptoAnalysisException; import crypto.preanalysis.TransformerSetup; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import de.fraunhofer.iem.scanner.ScannerSettings; import java.io.File; import java.util.ArrayList; diff --git a/HeadlessJavaScanner/src/main/java/de/fraunhofer/iem/framework/SootUpSetup.java b/HeadlessJavaScanner/src/main/java/de/fraunhofer/iem/framework/SootUpSetup.java index 0d370c95b..6b8304c74 100644 --- a/HeadlessJavaScanner/src/main/java/de/fraunhofer/iem/framework/SootUpSetup.java +++ b/HeadlessJavaScanner/src/main/java/de/fraunhofer/iem/framework/SootUpSetup.java @@ -1,7 +1,7 @@ package de.fraunhofer.iem.framework; import boomerang.scene.CallGraph; -import crypto.rules.CrySLRule; +import crysl.rule.CrySLRule; import de.fraunhofer.iem.scanner.ScannerSettings; import java.util.Collection; diff --git a/README.md b/README.md index 3e1de9547..dea79faf2 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ CogniCryptSAST uses Maven as build tool. You can compile and build th ```mvn clean package -DskipTests=true```. -The packaged `jar` artifacts including all dependencies can be found in `/apps`. Building requires at least Java 11. +The packaged `jar` artifacts including all dependencies can be found in `/apps`. Building requires at least Java 17. ## CogniCryptSAST for Java Applications diff --git a/action.yml b/action.yml index 1e2bbebf3..f45fe4b99 100644 --- a/action.yml +++ b/action.yml @@ -48,7 +48,7 @@ runs: with: distribution: 'adopt' java-package: jdk - java-version: '11' + java-version: '17' - name: Checkout rules uses: actions/checkout@v4 diff --git a/pom.xml b/pom.xml index be1d9bee8..52a346733 100644 --- a/pom.xml +++ b/pom.xml @@ -54,12 +54,12 @@ UTF-8 3.4.2 - 11 + 17 true 3.2.2 4.6.0 - 3.0.2 + 4.0.0 @@ -100,6 +100,11 @@ ${spdsVersion} test + + de.darmstadt.tu.crossing.CrySL + CrySLParser + ${cryslVersion} + @@ -126,11 +131,6 @@ 4.13.2 test - - de.darmstadt.tu.crossing.CrySL - de.darmstadt.tu.crossing.CrySL - ${cryslVersion} - org.bouncycastle bcprov-jdk18on @@ -174,13 +174,6 @@ commons-lang3 3.17.0 - - - com.google.inject - guice - 7.0.0 -