-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathAllClassifications.ql
More file actions
119 lines (116 loc) · 3.9 KB
/
AllClassifications.ql
File metadata and controls
119 lines (116 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* @name All cryptographic classifications
* @description Reports every cryptographic element classified as quantum-vulnerable, insecure, or secure
* using all predicates in the QuantumCryptoClassification library.
* @id java/quantum/examples/demo/all-classifications
* @kind problem
* @problem.severity warning
* @tags quantum
* experimental
*/
import QuantumCryptoClassification
/**
* Gets a short label for logical grouping of each finding category.
*/
string categoryLabel(string cat) {
cat = "Algorithm" and result = "Algorithm"
or
cat = "KeyAgreement" and result = "KeyAgreement"
or
cat = "Curve" and result = "Curve"
or
cat = "Padding" and result = "Padding"
or
cat = "Mode" and result = "Mode"
or
cat = "Hash" and result = "Hash"
or
cat = "KeySize" and result = "KeySize"
}
from Crypto::NodeBase node, string category, string classification, string detail
where
// ---- Key-operation algorithms (quantum-vulnerable / insecure / secure) ----
exists(Crypto::KeyOperationAlgorithmNode alg |
node = alg and
category = "Algorithm" and
classification = classifyAlgorithmType(alg.getAlgorithmType()) and
classification != "other" and
detail = alg.getAlgorithmName()
)
or
// ---- Key-agreement algorithms (quantum-vulnerable) ----
exists(Crypto::KeyAgreementAlgorithmNode kaAlg |
node = kaAlg and
category = "KeyAgreement" and
classification = classifyKeyAgreementType(kaAlg.getKeyAgreementType()) and
classification != "other" and
detail = kaAlg.getAlgorithmName()
)
or
// ---- Elliptic curves (quantum-vulnerable) ----
exists(Crypto::EllipticCurveNode curve |
node = curve and
category = "Curve" and
isQuantumVulnerableCurveType(curve.getEllipticCurveType()) and
classification = "quantum-vulnerable" and
detail = curve.getAlgorithmName() + " (" + curve.getEllipticCurveType().toString() + ")"
)
or
// ---- Padding (quantum-vulnerable) ----
exists(Crypto::PaddingAlgorithmNode pad |
node = pad and
category = "Padding" and
isQuantumVulnerablePaddingType(pad.getPaddingType()) and
classification = "quantum-vulnerable" and
detail = pad.getPaddingType().toString()
)
or
// ---- Block modes (insecure) ----
exists(Crypto::ModeOfOperationAlgorithmNode mode |
node = mode and
category = "Mode" and
isInsecureModeType(mode.getModeType()) and
classification = "insecure" and
detail = mode.getModeType().toString()
)
or
// ---- Hash algorithms (insecure / secure) ----
exists(Crypto::HashAlgorithmNode hash |
node = hash and
category = "Hash" and
(
isInsecureHashType(hash.getHashType()) and
classification = "insecure" and
detail = hash.getHashType().toString()
or
isSecureHashType(hash.getHashType()) and
classification = "secure" and
detail =
hash.getHashType().toString() +
any(string s |
if exists(hash.getDigestLength())
then s = " (" + hash.getDigestLength().toString() + "-bit)"
else s = ""
)
)
)
or
// ---- Key sizes with quantum-vulnerable algorithms ----
exists(Crypto::KeyCreationOperationNode keygen, Crypto::AlgorithmNode alg, int keySize |
node = keygen and
category = "KeySize" and
classification = "quantum-vulnerable" and
alg = keygen.getAKnownAlgorithm() and
keygen.getAKeySizeSource().asElement().(Literal).getValue().toInt() = keySize and
(
exists(Crypto::KeyOperationAlgorithmNode keyAlg |
keyAlg = alg and isQuantumVulnerableAlgorithmType(keyAlg.getAlgorithmType())
)
or
exists(Crypto::KeyAgreementAlgorithmNode kaAlg |
kaAlg = alg and isQuantumVulnerableKeyAgreementType(kaAlg.getKeyAgreementType())
)
) and
detail = keySize.toString() + "-bit key for " + alg.getAlgorithmName()
)
select node, "[" + classification + "] " + categoryLabel(category) + ": " + detail