3
3
*/
4
4
5
5
import codeql.util.Location
6
- import codeql.util.Either
7
6
8
7
signature module InputSig< LocationSig Location> {
9
8
class LocatableElement {
@@ -36,10 +35,20 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
36
35
37
36
final class DataFlowNode = Input:: DataFlowNode ;
38
37
38
+ /**
39
+ * A `ConsumerInputDataFlowNode` is a `DataFlowNode` that represents a consumer of data.
40
+ *
41
+ * This class is equivalent to `DataFlowNode` but facilitates binding to a `ConsumerElement`.
42
+ */
39
43
class ConsumerInputDataFlowNode extends DataFlowNode {
40
44
ConsumerElement getConsumer ( ) { result .getInputNode ( ) = this }
41
45
}
42
46
47
+ /**
48
+ * An `ArtifactOutputDataFlowNode` is a `DataFlowNode` that represents the source of a created artifact.
49
+ *
50
+ * This class is equivalent to `DataFlowNode` but facilitates binding to an `OutputArtifactInstance`.
51
+ */
43
52
class ArtifactOutputDataFlowNode extends DataFlowNode {
44
53
OutputArtifactInstance getArtifact ( ) { result .getOutputNode ( ) = this }
45
54
}
@@ -51,19 +60,17 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
51
60
bindingset [ root]
52
61
private string getPropertyAsGraphString ( NodeBase node , string key , Location root ) {
53
62
result =
54
- strictconcat ( any ( string value , Location location , string parsed |
55
- node .properties ( key , value , location ) and
56
- (
57
- if location = root or location instanceof UnknownLocation
58
- then parsed = value
59
- else
60
- parsed =
61
- "(" + value + "," + Input:: locationToFileBaseNameAndLineNumberString ( location ) +
62
- ")"
63
- )
64
- |
65
- parsed
66
- ) , ","
63
+ strictconcat ( string value , Location location , string parsed |
64
+ node .properties ( key , value , location ) and
65
+ (
66
+ if location = root or location instanceof UnknownLocation
67
+ then parsed = value
68
+ else
69
+ parsed =
70
+ "(" + value + "," + Input:: locationToFileBaseNameAndLineNumberString ( location ) + ")"
71
+ )
72
+ |
73
+ parsed , ","
67
74
)
68
75
}
69
76
@@ -154,7 +161,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
154
161
* CROSS PRODUCT WARNING: Modeling any *other* element that is a `FlowAwareElement` to the same
155
162
* instance in the database will result in every `FlowAwareElement` sharing the output flow.
156
163
*/
157
- abstract class KnownElement extends LocatableElement {
164
+ abstract private class KnownElement extends LocatableElement {
158
165
final ConsumerElement getAConsumer ( ) { result .getAKnownSource ( ) = this }
159
166
}
160
167
@@ -297,6 +304,23 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
297
304
final override ConsumerInputDataFlowNode getInputNode ( ) { result = input }
298
305
}
299
306
307
+ /**
308
+ * An `AlgorithmValueConsumer` (_AVC_) is an element that consumes a value specifying an algorithm.
309
+ *
310
+ * Example 1:
311
+ * `arg0` of `set_algorithm` (`x`) is the AVC for the `ctx.encrypt()` operation.
312
+ * ```cpp
313
+ * x = "RSA";
314
+ * ctx.set_algorithm(x);
315
+ * ctx.encrypt();
316
+ * ```
317
+ *
318
+ * Example 2:
319
+ * `encrypt_with_rsa` is concurrently an an operation, an AVC, and an algorithm.
320
+ * ```cpp
321
+ * `encrypt_with_rsa();`
322
+ * ```
323
+ */
300
324
abstract class AlgorithmValueConsumer extends ConsumerElement {
301
325
/**
302
326
* DO NOT USE.
@@ -324,8 +348,8 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
324
348
* to the artifact it receives, thereby becoming the definitive contextual source for that artifact.
325
349
*
326
350
* Architectural Implications:
327
- * * By directly coupling a consumer with the node that receives an artifact,
328
- * the data flow is fully transparent with the consumer itself serving only as a transparent node .
351
+ * * By directly coupling a consumer with the node that receives an artifact, no modeling considerations have to be made
352
+ * to provide an interface for identifying the source via the consumer data-flow mechanisms .
329
353
* * An artifact's properties (such as being a nonce) are not necessarily inherent; they are determined by the context in which the artifact is consumed.
330
354
* The consumer node is therefore essential in defining these properties for inputs.
331
355
* * This approach reduces ambiguity by avoiding separate notions of "artifact source" and "consumer", as the node itself encapsulates both roles.
@@ -347,7 +371,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
347
371
* A `NonceArtifactConsumer` is always the `NonceArtifactInstance` itself, since data only becomes (i.e., is determined to be)
348
372
* a `NonceArtifactInstance` when it is consumed in a context that expects a nonce (e.g., an argument expecting nonce data).
349
373
*
350
- * In this case, the artifact (nonce) is fully defined by the context in which it is consumed, and the consumer embodies
374
+ * In this case, the artifact (nonce) is fully defined by the context in which it is consumed, and the consumer embodies
351
375
* that identity without the need for additional differentiation. Without the context a consumer provides, that data could
352
376
* otherwise be any other type of artifact or even simply random data.
353
377
*
@@ -604,7 +628,6 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
604
628
type = TSymmetricCipher ( SEED ( ) ) and size = 128
605
629
}
606
630
607
- bindingset [ type]
608
631
predicate symmetric_cipher_to_name_and_structure (
609
632
TSymmetricCipherType type , string name , CipherStructureType s
610
633
) {
@@ -651,7 +674,6 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
651
674
s = UnknownCipherStructureType ( )
652
675
}
653
676
654
- bindingset [ type]
655
677
predicate type_to_name ( Algorithm type , string name ) {
656
678
// Symmetric cipher algorithm
657
679
symmetric_cipher_to_name_and_structure ( type .( SymmetricCipherAlgorithm ) .getType ( ) , name , _)
@@ -1551,6 +1573,20 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
1551
1573
string toString ( ) { result = super .getAlgorithmName ( ) }
1552
1574
}
1553
1575
1576
+ /**
1577
+ * The subset of algorithm nodes that are known asymmetric algorithm.
1578
+ *
1579
+ * Note: This is not an independent top-level node type.
1580
+ */
1581
+ class AsymmetricAlgorithmNode extends TKeyCreationCandidateAlgorithm instanceof AlgorithmNode {
1582
+ AsymmetricAlgorithmNode ( ) {
1583
+ this instanceof EllipticCurveNode or
1584
+ this .( KeyOperationAlgorithmNode ) .isAsymmetric ( )
1585
+ }
1586
+
1587
+ string toString ( ) { result = super .getAlgorithmName ( ) }
1588
+ }
1589
+
1554
1590
/**
1555
1591
* A cryptographic key, such as a symmetric key or asymmetric key pair.
1556
1592
*/
@@ -1709,7 +1745,6 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
1709
1745
1710
1746
TMACType getMACType ( ) { result = instance .asAlg ( ) .getMACType ( ) }
1711
1747
1712
- bindingset [ type]
1713
1748
final private predicate macToNameMapping ( TMACType type , string name ) {
1714
1749
type instanceof THMAC and
1715
1750
name = "HMAC"
@@ -2102,7 +2137,6 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
2102
2137
*/
2103
2138
TBlockCipherModeOfOperationType getModeType ( ) { result = instance .getModeType ( ) }
2104
2139
2105
- bindingset [ type]
2106
2140
final private predicate modeToNameMapping ( TBlockCipherModeOfOperationType type , string name ) {
2107
2141
type = ECB ( ) and name = "ECB"
2108
2142
or
@@ -2148,7 +2182,6 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
2148
2182
2149
2183
TPaddingType getPaddingType ( ) { result = instance .getPaddingType ( ) }
2150
2184
2151
- bindingset [ type]
2152
2185
final private predicate paddingToNameMapping ( TPaddingType type , string name ) {
2153
2186
type = ANSI_X9_23 ( ) and name = "ANSI_X9_23"
2154
2187
or
@@ -2454,18 +2487,18 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
2454
2487
// ALL BRAINPOOL CURVES
2455
2488
keySize in [ 160 , 192 , 224 , 256 , 320 , 384 , 512 ] and
2456
2489
(
2457
- curveName = "BRAINPOOLP" + keySize . toString ( ) + "R1"
2490
+ curveName = "BRAINPOOLP" + keySize + "R1"
2458
2491
or
2459
- curveName = "BRAINPOOLP" + keySize . toString ( ) + "T1"
2492
+ curveName = "BRAINPOOLP" + keySize + "T1"
2460
2493
)
2461
2494
}
2462
2495
2463
2496
private predicate isSecCurve ( string curveName , int keySize ) {
2464
2497
// ALL SEC CURVES
2465
2498
keySize in [ 112 , 113 , 128 , 131 , 160 , 163 , 192 , 193 , 224 , 233 , 239 , 256 , 283 , 384 , 409 , 521 , 571 ] and
2466
2499
exists ( string suff | suff in [ "R1" , "R2" , "K1" ] |
2467
- curveName = "SECT" + keySize . toString ( ) + suff or
2468
- curveName = "SECP" + keySize . toString ( ) + suff
2500
+ curveName = "SECT" + keySize + suff or
2501
+ curveName = "SECP" + keySize + suff
2469
2502
)
2470
2503
}
2471
2504
@@ -2475,22 +2508,20 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
2475
2508
exists ( string pre , string suff |
2476
2509
pre in [ "PNB" , "ONB" , "TNB" ] and suff in [ "V1" , "V2" , "V3" , "V4" , "V5" , "W1" , "R1" ]
2477
2510
|
2478
- curveName = "C2" + pre + keySize . toString ( ) + suff
2511
+ curveName = "C2" + pre + keySize + suff
2479
2512
)
2480
2513
}
2481
2514
2482
2515
private predicate isPrimeCurve ( string curveName , int keySize ) {
2483
2516
// ALL PRIME CURVES
2484
2517
keySize in [ 192 , 239 , 256 ] and
2485
- exists ( string suff | suff in [ "V1" , "V2" , "V3" ] |
2486
- curveName = "PRIME" + keySize .toString ( ) + suff
2487
- )
2518
+ exists ( string suff | suff in [ "V1" , "V2" , "V3" ] | curveName = "PRIME" + keySize + suff )
2488
2519
}
2489
2520
2490
2521
private predicate isNumsCurve ( string curveName , int keySize ) {
2491
2522
// ALL NUMS CURVES
2492
2523
keySize in [ 256 , 384 , 512 ] and
2493
- exists ( string suff | suff = "T1" | curveName = "NUMSP" + keySize . toString ( ) + suff )
2524
+ exists ( string suff | suff = "T1" | curveName = "NUMSP" + keySize + suff )
2494
2525
}
2495
2526
2496
2527
/**
@@ -2587,10 +2618,4 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
2587
2618
location = this .getLocation ( )
2588
2619
}
2589
2620
}
2590
-
2591
- predicate isKnownAsymmetricAlgorithm ( AlgorithmNode node ) {
2592
- node instanceof EllipticCurveNode
2593
- or
2594
- node instanceof KeyOperationAlgorithmNode and node .( KeyOperationAlgorithmNode ) .isAsymmetric ( )
2595
- }
2596
2621
}
0 commit comments