3
3
import java
4
4
import semmle.code.xml.AndroidManifest
5
5
import semmle.code.java.dataflow.TaintTracking
6
+ import semmle.code.java.frameworks.Networking
7
+ import semmle.code.java.security.Encryption
6
8
import HttpsUrls
7
9
8
10
/** An Android Network Security Configuration XML file. */
@@ -58,21 +60,17 @@ predicate trustedDomain(string domainName) {
58
60
* `default` is true if the default SSL socket factory for all URLs is being set.
59
61
*/
60
62
private predicate trustedSocketFactory ( MethodAccess setSocketFactory , boolean default ) {
61
- exists ( MethodAccess getSocketFactory , MethodAccess initSslContext , string methodName |
62
- setSocketFactory
63
- .getMethod ( )
64
- .getASourceOverriddenMethod * ( )
65
- .hasQualifiedName ( "javax.net.ssl" , "HttpsURLConnection" , methodName ) and
66
- (
67
- default = true and methodName = "setDefaultSSLSocketFactory"
63
+ exists ( MethodAccess getSocketFactory , MethodAccess initSslContext |
64
+ exists ( Method m | setSocketFactory .getMethod ( ) .getASourceOverriddenMethod * ( ) = m |
65
+ default = true and
66
+ m .getDeclaringType ( ) instanceof HttpsUrlConnection and
67
+ m .hasName ( "setDefaultSSLSocketFactory" )
68
68
or
69
- default = false and methodName = "setSSLSocketFactory"
69
+ default = false and m instanceof SetConnectionFactoryMethod
70
70
) and
71
- initSslContext .getMethod ( ) .hasQualifiedName ( "javax.net.ssl" , "SSLContext" , "init" ) and
72
- getSocketFactory
73
- .getMethod ( )
74
- .getASourceOverriddenMethod * ( )
75
- .hasQualifiedName ( "javax.net.ssl" , "SSLContext" , "getSocketFactory" ) and
71
+ initSslContext .getMethod ( ) .getDeclaringType ( ) instanceof SslContext and
72
+ initSslContext .getMethod ( ) .hasName ( "init" ) and
73
+ getSocketFactory .getMethod ( ) .getASourceOverriddenMethod * ( ) instanceof GetSocketFactory and
76
74
not initSslContext .getArgument ( 1 ) instanceof NullLiteral and
77
75
DataFlow:: localExprFlow ( initSslContext .getQualifier ( ) , getSocketFactory .getQualifier ( ) ) and
78
76
DataFlow:: localExprFlow ( getSocketFactory , setSocketFactory .getArgument ( 0 ) )
@@ -85,10 +83,7 @@ private predicate trustedSocketFactory(MethodAccess setSocketFactory, boolean de
85
83
*/
86
84
private predicate trustedUrlConnection ( Expr url ) {
87
85
exists ( MethodAccess openCon |
88
- openCon
89
- .getMethod ( )
90
- .getASourceOverriddenMethod * ( )
91
- .hasQualifiedName ( "java.net" , "URL" , "openConnection" ) and
86
+ openCon .getMethod ( ) .getASourceOverriddenMethod * ( ) instanceof UrlOpenConnectionMethod and
92
87
url = openCon .getQualifier ( ) and
93
88
exists ( MethodAccess setSocketFactory |
94
89
trustedSocketFactory ( setSocketFactory , false ) and
@@ -97,10 +92,10 @@ private predicate trustedUrlConnection(Expr url) {
97
92
)
98
93
or
99
94
trustedSocketFactory ( _, true ) and
100
- exists ( MethodAccess open |
101
- open . getMethod ( )
102
- . getASourceOverriddenMethod * ( )
103
- . hasQualifiedName ( "java.net" , "URL" , [ "openConnection" , "openStream" ] ) and
95
+ exists ( MethodAccess open , Method m |
96
+ m instanceof UrlOpenConnectionMethod or m instanceof UrlOpenStreamMethod
97
+ |
98
+ open . getMethod ( ) . getASourceOverriddenMethod * ( ) = m and
104
99
url = open .getQualifier ( )
105
100
)
106
101
}
0 commit comments