-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARJAVA-4883 S4423: Support detection of TLS Protocol Downgrades fo…
…r Spring programmatically (#4749)
- Loading branch information
1 parent
f68bf12
commit f7286e5
Showing
5 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
its/autoscan/src/test/resources/autoscan/diffs/diff_S4423.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"ruleKey": "S4423", | ||
"hasTruePositives": true, | ||
"falseNegatives": 7, | ||
"falseNegatives": 10, | ||
"falsePositives": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
java-checks-test-sources/spring-3.2/src/main/java/checks/WeakSSLContextCheckSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package checks; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.ssl.PropertiesSslBundle; | ||
import org.springframework.boot.autoconfigure.ssl.SslProperties; | ||
import org.springframework.boot.ssl.DefaultSslBundleRegistry; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class WeakSSLContextCheckSample { | ||
|
||
public static final String TLSV_1_0 = "TLSv1.0"; | ||
|
||
@Autowired | ||
public WeakSSLContextCheckSample(SslProperties props, DefaultSslBundleRegistry registry, Set<String> propsSet) { | ||
props.getBundle().getJks().get("").getOptions().setEnabledProtocols(Set.of("TLSv1.1", // Noncompliant [[sc=53;ec=72;secondary=18,20]] {{Change this code to use a stronger protocol.}} | ||
"test", | ||
"TLSv1.0")); | ||
props.getBundle().getJks().get("").getOptions().setEnabledProtocols(Set.of("TLSv1.0")); // Noncompliant | ||
|
||
props.getBundle().getJks().get("").getOptions().setEnabledProtocols(Set.of(TLSV_1_0)); // Noncompliant [[sc=53;ec=72;secondary=23]] {{Change this code to use a stronger protocol.}} | ||
props.getBundle().getJks().get("").getOptions().setEnabledProtocols(Set.of(null)); // coverage | ||
|
||
props.getBundle().getJks().get("").getOptions().setEnabledProtocols(Set.of("TLSv1")); // Compliant | ||
props.getBundle().getJks().get("").getOptions().setEnabledProtocols(getSet()); // Compliant - FN | ||
props.getBundle().getJks().get("").getOptions().setEnabledProtocols(propsSet); // Compliant | ||
props.getBundle().getJks().get("").getOptions().getCiphers(); // coverage | ||
|
||
registry.updateBundle("", PropertiesSslBundle.get(props.getBundle().getJks().get(""))); | ||
} | ||
|
||
Set<String> getSet() { | ||
Set<String> set = new HashSet<>(); | ||
set.add("TLSv1.1"); | ||
return set; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters