From abca07bfcf4172a42379a797855ed15a3bcb876e Mon Sep 17 00:00:00 2001 From: Sven Meyer Date: Thu, 4 Jul 2024 17:20:51 +0200 Subject: [PATCH] Add test case from #208 --- .../tests/headless/ReportedIssueTest.java | 3 +++ .../Issue208WithMultipleEntryPoints.java | 19 ++++++++++++++ .../Issue208WithSingleEntryPoint.java | 25 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 CryptoAnalysisTargets/ReportedIssues/src/main/java/issue208/Issue208WithMultipleEntryPoints.java create mode 100644 CryptoAnalysisTargets/ReportedIssues/src/main/java/issue208/Issue208WithSingleEntryPoint.java diff --git a/CryptoAnalysis/src/test/java/tests/headless/ReportedIssueTest.java b/CryptoAnalysis/src/test/java/tests/headless/ReportedIssueTest.java index e90c5bc9e..720dfbdc3 100644 --- a/CryptoAnalysis/src/test/java/tests/headless/ReportedIssueTest.java +++ b/CryptoAnalysis/src/test/java/tests/headless/ReportedIssueTest.java @@ -20,6 +20,9 @@ public void reportedIssues() { HeadlessCryptoScanner scanner = createScanner(mavenProject); setErrorsCount("", RequiredPredicateError.class, 1); + + setErrorsCount("", RequiredPredicateError.class, 0); + setErrorsCount("", RequiredPredicateError.class, 1); setErrorsCount("", ConstraintError.class, 1); setErrorsCount("", RequiredPredicateError.class, 1); diff --git a/CryptoAnalysisTargets/ReportedIssues/src/main/java/issue208/Issue208WithMultipleEntryPoints.java b/CryptoAnalysisTargets/ReportedIssues/src/main/java/issue208/Issue208WithMultipleEntryPoints.java new file mode 100644 index 000000000..f851d8e84 --- /dev/null +++ b/CryptoAnalysisTargets/ReportedIssues/src/main/java/issue208/Issue208WithMultipleEntryPoints.java @@ -0,0 +1,19 @@ +package issue208; + +import javax.crypto.spec.IvParameterSpec; +import java.security.SecureRandom; + +public class Issue208WithMultipleEntryPoints { + + private final SecureRandom secureRandom = new SecureRandom(); + + private static final int IV_LENGTH = 32; + + private void encryptImpl() { + byte[] iv = new byte[IV_LENGTH]; + secureRandom.nextBytes(iv); + + // iv has to ensure 'randomized' + IvParameterSpec ivParameterSpec = new IvParameterSpec(iv); + } +} diff --git a/CryptoAnalysisTargets/ReportedIssues/src/main/java/issue208/Issue208WithSingleEntryPoint.java b/CryptoAnalysisTargets/ReportedIssues/src/main/java/issue208/Issue208WithSingleEntryPoint.java new file mode 100644 index 000000000..290a28121 --- /dev/null +++ b/CryptoAnalysisTargets/ReportedIssues/src/main/java/issue208/Issue208WithSingleEntryPoint.java @@ -0,0 +1,25 @@ +package issue208; + +import javax.crypto.spec.IvParameterSpec; +import java.security.SecureRandom; + +public class Issue208WithSingleEntryPoint { + + private final SecureRandom secureRandom = new SecureRandom(); + + private static final int IV_LENGTH = 32; + + private void encryptImpl() { + byte[] iv = new byte[IV_LENGTH]; + secureRandom.nextBytes(iv); + + IvParameterSpec ivParameterSpec = new IvParameterSpec(iv); + } + + public static void main(String[] args) { + // Method 'main' is the single entry point -> Instantiate SecureRandom seed and + // use it in 'encryptImpl' + Issue208WithSingleEntryPoint issue208 = new Issue208WithSingleEntryPoint(); + issue208.encryptImpl(); + } +}