@@ -19,6 +19,13 @@ class ProtocolVersion extends string {
1919 or
2020 this = [ "TLSv1" , "TLSv1_1" , "TLSv1_2" ] and version = "TLSv1_3"
2121 }
22+
23+ predicate isInsecure ( ) { this in [ "SSLv2" , "SSLv3" , "TLSv1" , "TLSv1_1" ] }
24+ }
25+
26+ /** An unspecific protocol version */
27+ class ProtocolFamily extends string {
28+ ProtocolFamily ( ) { this in [ "SSLv23" , "TLS" ] }
2229}
2330
2431/** The creation of a context. */
@@ -42,14 +49,42 @@ abstract class ProtocolRestriction extends DataFlow::CfgNode {
4249 abstract ProtocolVersion getRestriction ( ) ;
4350}
4451
52+ /** A context is being relaxed on which protocols it can accepts. */
53+ abstract class ProtocolUnrestriction extends DataFlow:: CfgNode {
54+ /** Gets the context being relaxed. */
55+ abstract DataFlow:: CfgNode getContext ( ) ;
56+
57+ /** Gets the protocol version being allowed. */
58+ abstract ProtocolVersion getUnrestriction ( ) ;
59+ }
60+
61+ abstract class UnspecificContextCreation extends ContextCreation , ProtocolUnrestriction {
62+ TlsLibrary library ;
63+ ProtocolFamily family ;
64+
65+ UnspecificContextCreation ( ) { this .getProtocol ( ) = library .unspecific_version ( family ) }
66+
67+ override DataFlow:: CfgNode getContext ( ) { result = this }
68+
69+ override ProtocolVersion getUnrestriction ( ) {
70+ family = "TLS" and
71+ result in [ "TLSv1" , "TLSv1_1" , "TLSv1_2" , "TLSv1_3" ]
72+ or
73+ // This can negotiate a TLS 1.3 connection (!)
74+ // see https://docs.python.org/3/library/ssl.html#ssl-contexts
75+ family = "SSLv23" and
76+ result in [ "SSLv2" , "SSLv3" , "TLSv1" , "TLSv1_1" , "TLSv1_2" , "TLSv1_3" ]
77+ }
78+ }
79+
4580abstract class TlsLibrary extends string {
4681 TlsLibrary ( ) { this in [ "ssl" , "pyOpenSSL" ] }
4782
4883 /** The name of a specific protocol version, known to be insecure. */
4984 abstract string specific_insecure_version_name ( ProtocolVersion version ) ;
5085
5186 /** The name of an unspecific protocol version, say TLS, known to have insecure instances. */
52- abstract string unspecific_version_name ( ) ;
87+ abstract string unspecific_version_name ( ProtocolFamily family ) ;
5388
5489 /** The module or class holding the version constants. */
5590 abstract API:: Node version_constants ( ) ;
@@ -60,8 +95,8 @@ abstract class TlsLibrary extends string {
6095 }
6196
6297 /** A dataflow node representing an unspecific protocol version, say TLS, known to have insecure instances. */
63- DataFlow:: Node unspecific_version ( ) {
64- result = version_constants ( ) .getMember ( unspecific_version_name ( ) ) .getAUse ( )
98+ DataFlow:: Node unspecific_version ( ProtocolFamily family ) {
99+ result = version_constants ( ) .getMember ( unspecific_version_name ( family ) ) .getAUse ( )
65100 }
66101
67102 /** The creation of a context with a deafult protocol. */
@@ -77,11 +112,11 @@ abstract class TlsLibrary extends string {
77112 }
78113
79114 /** The creation of a context with an unspecific protocol version, say TLS, known to have insecure instances. */
80- DataFlow:: CfgNode unspecific_context_creation ( ) {
115+ DataFlow:: CfgNode unspecific_context_creation ( ProtocolFamily family ) {
81116 result = default_context_creation ( )
82117 or
83118 result = specific_context_creation ( ) and
84- result .( ContextCreation ) .getProtocol ( ) = unspecific_version ( )
119+ result .( ContextCreation ) .getProtocol ( ) = unspecific_version ( family )
85120 }
86121
87122 /** A connection is created in an insecure manner, not from a context. */
@@ -92,4 +127,7 @@ abstract class TlsLibrary extends string {
92127
93128 /** A context is being restricted on which protocols it can accepts. */
94129 abstract ProtocolRestriction protocol_restriction ( ) ;
130+
131+ /** A context is being relaxed on which protocols it can accepts. */
132+ abstract ProtocolUnrestriction protocol_unrestriction ( ) ;
95133}
0 commit comments