From b3460f6951ad9dca8daf116af27f65d310041255 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Mon, 21 May 2018 12:53:01 +0200 Subject: [PATCH] whitespaces, javadoc --- .../rule/security/InsecureCryptoIvRule.java | 12 +- .../main/resources/category/java/security.xml | 4 +- .../rule/security/xml/InsecureCryptoIv.xml | 240 ++++++++---------- 3 files changed, 121 insertions(+), 135 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/security/InsecureCryptoIvRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/security/InsecureCryptoIvRule.java index 5f9a0aae10..0a6e6e1476 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/security/InsecureCryptoIvRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/security/InsecureCryptoIvRule.java @@ -21,12 +21,14 @@ import net.sourceforge.pmd.lang.java.typeresolution.TypeHelper; /** * Finds hardcoded static Initialization Vectors vectors used with cryptographic * operations. - * + * + * * //bad: byte[] ivBytes = new byte[] {32, 87, -14, 25, 78, -104, 98, 40}; - * //bad: byte[] ivBytes = "hardcoded".getBytes(); //bad: byte[] ivBytes = - * someString.getBytes(); - * - * javax.crypto.spec.IvParameterSpec must not be created from a static sources + * //bad: byte[] ivBytes = "hardcoded".getBytes(); + * //bad: byte[] ivBytes = someString.getBytes(); + * + * + *

{@link javax.crypto.spec.IvParameterSpec} must not be created from a static sources * * @author sergeygorbaty * @since 6.3.0 diff --git a/pmd-java/src/main/resources/category/java/security.xml b/pmd-java/src/main/resources/category/java/security.xml index 73fae75838..6710b64490 100644 --- a/pmd-java/src/main/resources/category/java/security.xml +++ b/pmd-java/src/main/resources/category/java/security.xml @@ -8,7 +8,8 @@ Rules that flag potential security flaws. - @@ -56,7 +57,6 @@ public class Foo { void alsoBad() { byte[] iv = "secret iv in here".getBytes(); } - } ]]> diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/security/xml/InsecureCryptoIv.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/security/xml/InsecureCryptoIv.xml index 6482224bef..222b42f0d5 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/security/xml/InsecureCryptoIv.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/security/xml/InsecureCryptoIv.xml @@ -1,140 +1,124 @@ - - - 1 - + + Hard coded inline IvSpec, bad + 1 + - - - - 0 - + + + Randomly generated IV, good + 0 + - - - - 1 - + + + Hard coded Iv from string, bad + 1 + - - - - 1 - - - - - 1 - - - - - 0 - - - - - 0 - - + void encrypt() { + byte[] staticIv = "ALL_ZEROS_HERE".getBytes(); + IvParameterSpec iv = new IvParameterSpec(staticIv); + } +} + ]]> + + + Hard coded Iv field, bad + 1 + + + + Hard coded Iv local var, bad + 1 + + + + Random IV, good + 0 + + + + Inline IvSpec Random IV, good + 0 + +