44
55private import experimental.quantum.Language
66private 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
89
910// TODO: verification functions
1011class EVP_Signature_Initializer extends EVPInitialize {
@@ -44,14 +45,20 @@ class EVP_Signature_Initializer extends EVPInitialize {
4445
4546 /**
4647 * 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 .
4849 */
4950 override Expr getKeyArg ( ) {
5051 this .( Call ) .getTarget ( ) .getName ( ) = "EVP_DigestSignInit" and
5152 result = this .( Call ) .getArgument ( 4 )
5253 or
5354 this .( Call ) .getTarget ( ) .getName ( ) = "EVP_DigestSignInit_ex" and
5455 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+ )
5562 }
5663
5764 /**
@@ -123,8 +130,10 @@ abstract class EVP_Signature_Operation extends EVPOperation, Crypto::SignatureOp
123130 }
124131
125132 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 ( )
128137 }
129138
130139 override Crypto:: ArtifactOutputDataFlowNode getOutputArtifact ( ) {
@@ -139,7 +148,6 @@ abstract class EVP_Signature_Operation extends EVPOperation, Crypto::SignatureOp
139148 * TODO: only signing operations for now, change when verificaiton is added
140149 */
141150 override Crypto:: ConsumerInputDataFlowNode getSignatureConsumer ( ) { none ( ) }
142-
143151}
144152
145153class EVP_Signature_Call extends EVPOperation , EVP_Signature_Operation {
@@ -163,6 +171,12 @@ class EVP_Signature_Final_Call extends EVPFinal, EVP_Signature_Operation {
163171 ]
164172 }
165173
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+
166180 /**
167181 * Output is the signature.
168182 */
0 commit comments