Skip to content

Commit 30e2c44

Browse files
authored
Merge pull request #19509 from bdrodes/openssl_cipher_update
Quantum: Expand OpenSSL cipher modeling and fix JCA false reporting of intermediate calls
2 parents 5db797e + dbd66e6 commit 30e2c44

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

cpp/ql/lib/experimental/quantum/OpenSSL/Operations/EVPCipherOperation.qll

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,37 +67,42 @@ abstract class EVP_Cipher_Operation extends OpenSSLOperation, Crypto::KeyOperati
6767
}
6868
}
6969

70-
// abstract class EVP_Update_Call extends EVP_Cipher_Operation { }
71-
abstract class EVP_Final_Call extends EVP_Cipher_Operation {
72-
override Expr getInputArg() { none() }
73-
}
74-
75-
// TODO: only model Final (model final as operation and model update but not as an operation)
76-
// Updates are multiple input consumers (most important)
77-
// TODO: assuming update doesn't ouput, otherwise it outputs artifacts, but is not an operation
7870
class EVP_Cipher_Call extends EVP_Cipher_Operation {
7971
EVP_Cipher_Call() { this.(Call).getTarget().getName() = "EVP_Cipher" }
8072

8173
override Expr getInputArg() { result = this.(Call).getArgument(2) }
8274
}
8375

84-
// ******* TODO: model UPDATE but not as the core operation, rather a step towards final
85-
// see the JCA
86-
// class EVP_Encrypt_Decrypt_or_Cipher_Update_Call extends EVP_Update_Call {
87-
// EVP_Encrypt_Decrypt_or_Cipher_Update_Call() {
88-
// this.(Call).getTarget().getName() in [
89-
// "EVP_EncryptUpdate", "EVP_DecryptUpdate", "EVP_CipherUpdate"
90-
// ]
91-
// }
92-
// override Expr getInputArg() { result = this.(Call).getArgument(3) }
93-
// }
94-
class EVP_Encrypt_Decrypt_or_Cipher_Final_Call extends EVP_Final_Call {
95-
EVP_Encrypt_Decrypt_or_Cipher_Final_Call() {
76+
// NOTE: not modeled as cipher operations, these are intermediate calls
77+
class EVP_Update_Call extends Call {
78+
EVP_Update_Call() {
79+
this.(Call).getTarget().getName() in [
80+
"EVP_EncryptUpdate", "EVP_DecryptUpdate", "EVP_CipherUpdate"
81+
]
82+
}
83+
84+
Expr getInputArg() { result = this.(Call).getArgument(3) }
85+
86+
DataFlow::Node getInputNode() { result.asExpr() = this.getInputArg() }
87+
88+
Expr getContextArg() { result = this.(Call).getArgument(0) }
89+
}
90+
91+
class EVP_Final_Call extends EVP_Cipher_Operation {
92+
EVP_Final_Call() {
9693
this.(Call).getTarget().getName() in [
9794
"EVP_EncryptFinal_ex", "EVP_DecryptFinal_ex", "EVP_CipherFinal_ex", "EVP_EncryptFinal",
9895
"EVP_DecryptFinal", "EVP_CipherFinal"
9996
]
10097
}
98+
99+
EVP_Update_Call getUpdateCalls() {
100+
CTXFlow::ctxArgFlowsToCtxArg(result.getContextArg(), this.getContextArg())
101+
}
102+
103+
override Expr getInputArg() { result = this.getUpdateCalls().getInputArg() }
104+
105+
override Crypto::ConsumerInputDataFlowNode getInputConsumer() { result = this.getInputNode() }
101106
}
102107

103108
class EVP_PKEY_Operation extends EVP_Cipher_Operation {

java/ql/lib/experimental/quantum/JCA.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,8 @@ module JCAModel {
611611
}
612612

613613
class CipherOperationInstance extends Crypto::KeyOperationInstance instanceof CipherOperationCall {
614+
CipherOperationInstance() { not this.isIntermediate() }
615+
614616
override Crypto::KeyOperationSubtype getKeyOperationSubtype() {
615617
if CipherFlowAnalysisImpl::hasInit(this)
616618
then result = CipherFlowAnalysisImpl::getInitFromUse(this, _, _).getCipherOperationModeType()

0 commit comments

Comments
 (0)