4
4
5
5
private import experimental.quantum.Language
6
6
private import OpenSSLOperationBase
7
- private import experimental.quantum.OpenSSL.CtxFlow as CTXFlow
7
+ private import experimental.quantum.OpenSSL.CtxFlow
8
+ private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.PKeyAlgorithmValueConsumer
8
9
9
10
// TODO: verification functions
10
11
class EVP_Signature_Initializer extends EVPInitialize {
@@ -44,14 +45,20 @@ class EVP_Signature_Initializer extends EVPInitialize {
44
45
45
46
/**
46
47
* Returns the key argument if there is one.
47
- * They key could be provided in the context or in a later call (final or one-shot) .
48
+ * If the key was provided via the context, we track it to the context .
48
49
*/
49
50
override Expr getKeyArg ( ) {
50
51
this .( Call ) .getTarget ( ) .getName ( ) = "EVP_DigestSignInit" and
51
52
result = this .( Call ) .getArgument ( 4 )
52
53
or
53
54
this .( Call ) .getTarget ( ) .getName ( ) = "EVP_DigestSignInit_ex" and
54
55
result = this .( Call ) .getArgument ( 5 )
56
+ or
57
+ this .( Call ) .getTarget ( ) .getName ( ) .matches ( "EVP_PKEY_%" ) and
58
+ exists ( EVPPKeyAlgorithmConsumer source |
59
+ result = source .getValueArgExpr ( ) and
60
+ ctxFlowsToCtxArg ( source .getResultNode ( ) .asExpr ( ) , this .getContextArg ( ) )
61
+ )
55
62
}
56
63
57
64
/**
@@ -123,8 +130,10 @@ abstract class EVP_Signature_Operation extends EVPOperation, Crypto::SignatureOp
123
130
}
124
131
125
132
override Crypto:: ConsumerInputDataFlowNode getKeyConsumer ( ) {
126
- result = DataFlow:: exprNode ( this .getInitCall ( ) .getKeyArg ( ) )
127
- // TODO: or track to the EVP_PKEY_CTX_new
133
+ // TODO: move to EVPOperation similarly to getAlgorithmArg
134
+ if exists ( this .getInitCall ( ) .getKeyArg ( ) )
135
+ then result = DataFlow:: exprNode ( this .getInitCall ( ) .getKeyArg ( ) )
136
+ else none ( )
128
137
}
129
138
130
139
override Crypto:: ArtifactOutputDataFlowNode getOutputArtifact ( ) {
@@ -139,7 +148,6 @@ abstract class EVP_Signature_Operation extends EVPOperation, Crypto::SignatureOp
139
148
* TODO: only signing operations for now, change when verificaiton is added
140
149
*/
141
150
override Crypto:: ConsumerInputDataFlowNode getSignatureConsumer ( ) { none ( ) }
142
-
143
151
}
144
152
145
153
class EVP_Signature_Call extends EVPOperation , EVP_Signature_Operation {
@@ -163,6 +171,12 @@ class EVP_Signature_Final_Call extends EVPFinal, EVP_Signature_Operation {
163
171
]
164
172
}
165
173
174
+ override Crypto:: ConsumerInputDataFlowNode getKeyConsumer ( ) {
175
+ if this .( Call ) .getTarget ( ) .getName ( ) in [ "EVP_SignFinal" , "EVP_SignFinal_ex" ]
176
+ then result = DataFlow:: exprNode ( this .( Call ) .getArgument ( 3 ) )
177
+ else none ( )
178
+ }
179
+
166
180
/**
167
181
* Output is the signature.
168
182
*/
0 commit comments