@@ -6,9 +6,26 @@ private import AlgToAVCFlow
66private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.DirectAlgorithmValueConsumer
77private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumerBase
88
9+ /**
10+ * A class to define padding specific integer values.
11+ * from rsa.h in openssl:
12+ * # define RSA_PKCS1_PADDING 1
13+ * # define RSA_NO_PADDING 3
14+ * # define RSA_PKCS1_OAEP_PADDING 4
15+ * # define RSA_X931_PADDING 5
16+ * # define RSA_PKCS1_PSS_PADDING 6
17+ * # define RSA_PKCS1_WITH_TLS_PADDING 7
18+ * # define RSA_PKCS1_NO_IMPLICIT_REJECT_PADDING 8
19+ */
20+ class OpenSSLPaddingLiteral extends Literal {
21+ // TODO: we can be more specific about where the literal is in a larger expression
22+ // to avoid literals that are clealy not representing an algorithm, e.g., array indices.
23+ OpenSSLPaddingLiteral ( ) { this .getValue ( ) .toInt ( ) in [ 0 , 1 , 3 , 4 , 5 , 6 , 7 , 8 ] }
24+ }
25+
926/**
1027 * Given a `KnownOpenSSLPaddingAlgorithmConstant`, converts this to a padding family type.
11- * Does not bind if there is know mapping (no mapping to 'unknown' or 'other').
28+ * Does not bind if there is no mapping (no mapping to 'unknown' or 'other').
1229 */
1330predicate knownOpenSSLConstantToPaddingFamilyType (
1431 KnownOpenSSLPaddingAlgorithmConstant e , Crypto:: TPaddingType type
@@ -60,19 +77,8 @@ class KnownOpenSSLPaddingConstantAlgorithmInstance extends OpenSSLAlgorithmInsta
6077 this instanceof KnownOpenSSLPaddingAlgorithmConstant and
6178 isPaddingSpecificConsumer = false
6279 or
63- // Possibility 3:
64- // from rsa.h in openssl:
65- // # define RSA_PKCS1_PADDING 1
66- // # define RSA_NO_PADDING 3
67- // # define RSA_PKCS1_OAEP_PADDING 4
68- // # define RSA_X931_PADDING 5
69- // /* EVP_PKEY_ only */
70- // # define RSA_PKCS1_PSS_PADDING 6
71- // # define RSA_PKCS1_WITH_TLS_PADDING 7
72- // /* internal RSA_ only */
73- // # define RSA_PKCS1_NO_IMPLICIT_REJECT_PADDING 8
74- this instanceof Literal and
75- this .getValue ( ) .toInt ( ) in [ 0 , 1 , 3 , 4 , 5 , 6 , 7 , 8 ] and
80+ // Possibility 3: padding-specific literal
81+ this instanceof OpenSSLPaddingLiteral and
7682 exists ( DataFlow:: Node src , DataFlow:: Node sink |
7783 // Sink is an argument to a CipherGetterCall
7884 sink = getterCall .( OpenSSLAlgorithmValueConsumer ) .getInputNode ( ) and
@@ -88,24 +94,24 @@ class KnownOpenSSLPaddingConstantAlgorithmInstance extends OpenSSLAlgorithmInsta
8894
8995 override OpenSSLAlgorithmValueConsumer getAVC ( ) { result = getterCall }
9096
97+ Crypto:: TPaddingType getKnownPaddingType ( ) {
98+ this .( Literal ) .getValue ( ) .toInt ( ) in [ 1 , 7 , 8 ] and result = Crypto:: PKCS1_v1_5 ( )
99+ or
100+ this .( Literal ) .getValue ( ) .toInt ( ) = 3 and result = Crypto:: NoPadding ( )
101+ or
102+ this .( Literal ) .getValue ( ) .toInt ( ) = 4 and result = Crypto:: OAEP ( )
103+ or
104+ this .( Literal ) .getValue ( ) .toInt ( ) = 5 and result = Crypto:: ANSI_X9_23 ( )
105+ or
106+ this .( Literal ) .getValue ( ) .toInt ( ) = 6 and result = Crypto:: PSS ( )
107+ }
108+
91109 override Crypto:: TPaddingType getPaddingType ( ) {
92110 isPaddingSpecificConsumer = true and
93111 (
94- if this .( Literal ) .getValue ( ) .toInt ( ) in [ 1 , 7 , 8 ]
95- then result = Crypto:: PKCS1_v1_5 ( )
96- else
97- if this .( Literal ) .getValue ( ) .toInt ( ) = 3
98- then result = Crypto:: NoPadding ( )
99- else
100- if this .( Literal ) .getValue ( ) .toInt ( ) = 4
101- then result = Crypto:: OAEP ( )
102- else
103- if this .( Literal ) .getValue ( ) .toInt ( ) = 5
104- then result = Crypto:: ANSI_X9_23 ( )
105- else
106- if this .( Literal ) .getValue ( ) .toInt ( ) = 6
107- then result = Crypto:: PSS ( )
108- else result = Crypto:: OtherPadding ( )
112+ result = getKnownPaddingType ( )
113+ or
114+ not exists ( getKnownPaddingType ( ) ) and result = Crypto:: OtherPadding ( )
109115 )
110116 or
111117 isPaddingSpecificConsumer = false and
0 commit comments