Skip to content

Commit 8981822

Browse files
committed
bring in changes from cryptsweeper
1 parent 7437860 commit 8981822

4 files changed

Lines changed: 407 additions & 105 deletions

File tree

python/ql/lib/experimental/cryptography/CryptoAlgorithmNames.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ predicate isSymmetricEncryptionAlgorithm(string name) {
104104
predicate isKeyDerivationAlgorithm(string name) {
105105
name =
106106
[
107-
"ARGON2", "ARGON2D", "ARGON2I", "ARGON2ID", "CONCATKDF", "CONCATKDFHASH", "CONCATKDFHMAC",
107+
// 'ARGON2' should only be used in cases where the specific variant in use cannot be discerned reliably
108+
"ARGON2", "ARGON2D", "ARGON2I", "ARGON2ID",
109+
"CONCATKDF", "CONCATKDFHASH", "CONCATKDFHMAC",
108110
"KBKDFCMAC", "BCRYPT", "HKDF", "HKDFEXPAND", "KBKDF", "KBKDFHMAC", "PBKDF1", "PBKDF2",
109111
"PBKDF2HMAC", "PKCS5", "SCRYPT", "X963KDF", "EVPKDF"
110112
]

python/ql/lib/experimental/cryptography/CryptoArtifact.qll

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ abstract class CryptographicArtifact extends DataFlow::Node { }
2020
abstract class SymmetricCipher extends CryptographicArtifact {
2121
abstract SymmetricEncryptionAlgorithm getEncryptionAlgorithm();
2222

23-
abstract BlockMode getBlockMode();
23+
abstract BlockModeInstance getBlockMode();
2424

2525
final predicate hasBlockMode() { exists(this.getBlockMode()) }
2626
}
@@ -55,9 +55,14 @@ abstract class CryptographicOperation extends CryptographicArtifact, API::CallNo
5555
not this.hasAlgorithm()
5656
}
5757

58+
/** Gets the data flow node where the cryptographic algorithm used in this operation is configured. */
59+
abstract DataFlow::Node getInitialisation();
5860
// TODO: this might have to be parameterized by a configuration source for
5961
// situations where an operation is passed an algorithm
62+
/** Gets the algorithm used, if it matches a known `CryptographicAlgorithm`. */
6063
abstract CryptographicAlgorithm getAlgorithm();
64+
/** Gets an input the algorithm is used on, for example the plain text input to be encrypted. */
65+
abstract DataFlow::Node getAnInput();
6166
}
6267

6368
/** A key generation operation for asymmetric keys */
@@ -129,10 +134,11 @@ abstract class KeyDerivationAlgorithm extends CryptographicAlgorithm {
129134
}
130135

131136
abstract class KeyDerivationOperation extends CryptographicOperation {
132-
DataFlow::Node getIterationSizeSrc() { none() }
133-
137+
DataFlow::Node getSaltConfigSink() { none() }
134138
DataFlow::Node getSaltConfigSrc() { none() }
135139

140+
DataFlow::Node getIterationSizeSrc() { none() }
141+
136142
DataFlow::Node getHashConfigSrc() { none() }
137143

138144
DataFlow::Node getLanesConfigSrc() { none() }
@@ -175,6 +181,8 @@ abstract class EncryptionAlgorithm extends CryptographicAlgorithm {
175181
// class does not have this common predicate.
176182
}
177183

184+
abstract class EncryptionOperation extends CryptographicOperation { }
185+
178186
/**
179187
* Algorithms directly or indirectly related to asymmetric encryption,
180188
* e.g., RSA, DSA, but also RSA padding algorithms
@@ -200,6 +208,8 @@ abstract class SymmetricEncryptionAlgorithm extends EncryptionAlgorithm {
200208
// TODO: add a stream cipher predicate?
201209
}
202210

211+
abstract class SymmetricEncryptionOperation extends EncryptionOperation { }
212+
203213
// Used only to categorize all padding into a single object,
204214
// DO_NOT add predicates here. Only for categorization purposes.
205215
abstract class PaddingAlgorithm extends CryptographicAlgorithm { }
@@ -230,7 +240,7 @@ abstract class EllipticCurveAlgorithm extends AsymmetricAlgorithm {
230240
final int getCurveBitSize() { isEllipticCurveAlgorithm(this.getCurveName(), result) }
231241
}
232242

233-
abstract class BlockMode extends CryptographicAlgorithm {
243+
abstract class BlockModeInstance extends CryptographicAlgorithm {
234244
final string getBlockModeName() {
235245
if exists(string n | n = this.getName() and isCipherBlockModeAlgorithm(n))
236246
then isCipherBlockModeAlgorithm(result) and result = this.getName()
@@ -240,21 +250,38 @@ abstract class BlockMode extends CryptographicAlgorithm {
240250
/**
241251
* Gets the source of the IV configuration.
242252
*/
243-
abstract DataFlow::Node getIVorNonce();
253+
abstract DataFlow::Node getIVOrNonceSrc();
254+
255+
/**
256+
* Gets the sink of the IV configuration.
257+
*/
258+
abstract DataFlow::Node getIVOrNonceSink();
244259

245-
final predicate hasIVorNonce() { exists(this.getIVorNonce()) }
260+
final predicate hasIVorNonce() { exists(this.getIVOrNonceSrc()) }
246261
}
247262

248263
abstract class KeyWrapOperation extends CryptographicOperation { }
249264

250265
abstract class AuthenticatedEncryptionAlgorithm extends SymmetricEncryptionAlgorithm {
251-
final string getAuthticatedEncryptionName() {
266+
final string getAuthenticatedEncryptionName() {
252267
if exists(string n | n = this.getName() and isSymmetricEncryptionAlgorithm(n))
253268
then isSymmetricEncryptionAlgorithm(result) and result = this.getName()
254269
else result = unknownAlgorithm()
255270
}
256271
}
257272

273+
abstract class AuthenticatedEncryptionOperation extends SymmetricEncryptionOperation {
274+
/**
275+
* Gets the source of the IV configuration.
276+
*/
277+
abstract DataFlow::Node getIVOrNonceSrc();
278+
279+
/**
280+
* Gets the sink of the IV configuration.
281+
*/
282+
abstract DataFlow::Node getIVOrNonceSink();
283+
}
284+
258285
abstract class KeyExchangeAlgorithm extends AsymmetricAlgorithm {
259286
final string getKeyExchangeName() {
260287
if exists(string n | n = this.getName() and isKeyExchangeAlgorithm(n))

0 commit comments

Comments
 (0)