|
| 1 | +import java |
| 2 | +import semmle.code.java.security.Encryption |
| 3 | +import semmle.code.java.dataflow.TaintTracking |
| 4 | +import DataFlow |
| 5 | +import PathGraph |
| 6 | + |
| 7 | +/** |
| 8 | + * A taint-tracking configuration for unsafe SSL and TLS versions. |
| 9 | + */ |
| 10 | +class UnsafeTlsVersionConfig extends TaintTracking::Configuration { |
| 11 | + UnsafeTlsVersionConfig() { this = "UnsafeTlsVersion::UnsafeTlsVersionConfig" } |
| 12 | + |
| 13 | + override predicate isSource(DataFlow::Node source) { source.asExpr() instanceof UnsafeTlsVersion } |
| 14 | + |
| 15 | + override predicate isSink(DataFlow::Node sink) { |
| 16 | + sink instanceof SslContextGetInstanceSink or |
| 17 | + sink instanceof CreateSslParametersSink or |
| 18 | + sink instanceof SslParametersSetProtocolsSink or |
| 19 | + sink instanceof SetEnabledProtocolsSink |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +/** |
| 24 | + * A sink that sets protocol versions in `SSLContext`, |
| 25 | + * i.e `SSLContext.getInstance(protocol)`. |
| 26 | + */ |
| 27 | +class SslContextGetInstanceSink extends DataFlow::ExprNode { |
| 28 | + SslContextGetInstanceSink() { |
| 29 | + exists(StaticMethodAccess ma, Method m | m = ma.getMethod() | |
| 30 | + m.getDeclaringType() instanceof SSLContext and |
| 31 | + m.hasName("getInstance") and |
| 32 | + ma.getArgument(0) = asExpr() |
| 33 | + ) |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +/** |
| 38 | + * A sink that creates `SSLParameters` with specified protocols, |
| 39 | + * i.e. `new SSLParameters(ciphersuites, protocols)`. |
| 40 | + */ |
| 41 | +class CreateSslParametersSink extends DataFlow::ExprNode { |
| 42 | + CreateSslParametersSink() { |
| 43 | + exists(ConstructorCall cc | cc.getConstructedType() instanceof SSLParameters | |
| 44 | + cc.getArgument(1) = asExpr() |
| 45 | + ) |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +/** |
| 50 | + * A sink that sets protocol versions for `SSLParameters`, |
| 51 | + * i.e. `parameters.setProtocols(versions)`. |
| 52 | + */ |
| 53 | +class SslParametersSetProtocolsSink extends DataFlow::ExprNode { |
| 54 | + SslParametersSetProtocolsSink() { |
| 55 | + exists(MethodAccess ma, Method m | m = ma.getMethod() | |
| 56 | + m.getDeclaringType() instanceof SSLParameters and |
| 57 | + m.hasName("setProtocols") and |
| 58 | + ma.getArgument(0) = asExpr() |
| 59 | + ) |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +/** |
| 64 | + * A sink that sets protocol versions fro `SSLSocket`, `SSLServerSocket` and `SSLEngine`, |
| 65 | + * i.e. `socket.setEnabledProtocols(versions)` or `engine.setEnabledProtocols(versions)`. |
| 66 | + */ |
| 67 | +class SetEnabledProtocolsSink extends DataFlow::ExprNode { |
| 68 | + SetEnabledProtocolsSink() { |
| 69 | + exists(MethodAccess ma, Method m, RefType type | |
| 70 | + m = ma.getMethod() and type = m.getDeclaringType() |
| 71 | + | |
| 72 | + ( |
| 73 | + type instanceof SSLSocket or |
| 74 | + type instanceof SSLServerSocket or |
| 75 | + type instanceof SSLEngine |
| 76 | + ) and |
| 77 | + m.hasName("setEnabledProtocols") and |
| 78 | + ma.getArgument(0) = asExpr() |
| 79 | + ) |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +/** |
| 84 | + * Insecure SSL and TLS versions supported by JSSE. |
| 85 | + */ |
| 86 | +class UnsafeTlsVersion extends StringLiteral { |
| 87 | + UnsafeTlsVersion() { |
| 88 | + getValue() = "SSL" or |
| 89 | + getValue() = "SSLv2" or |
| 90 | + getValue() = "SSLv3" or |
| 91 | + getValue() = "TLS" or |
| 92 | + getValue() = "TLSv1" or |
| 93 | + getValue() = "TLSv1.1" |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +class SSLParameters extends RefType { |
| 98 | + SSLParameters() { hasQualifiedName("javax.net.ssl", "SSLParameters") } |
| 99 | +} |
| 100 | + |
| 101 | +class SSLSocket extends RefType { |
| 102 | + SSLSocket() { hasQualifiedName("javax.net.ssl", "SSLSocket") } |
| 103 | +} |
| 104 | + |
| 105 | +class SSLServerSocket extends RefType { |
| 106 | + SSLServerSocket() { hasQualifiedName("javax.net.ssl", "SSLServerSocket") } |
| 107 | +} |
| 108 | + |
| 109 | +class SSLEngine extends RefType { |
| 110 | + SSLEngine() { hasQualifiedName("javax.net.ssl", "SSLEngine") } |
| 111 | +} |
0 commit comments