1+ /**
2+ * Provides predicates and classes relating to encryption in Java.
3+ */
4+
15import java
26
37class SSLClass extends RefType {
@@ -85,41 +89,51 @@ private string algorithmRegex(string algorithmString) {
8589 "((^|.*[A-Z]{2}|.*[^a-zA-Z])(" + algorithmString .toLowerCase ( ) + ")([^a-z].*|$))"
8690}
8791
88- /** Gets a blacklist of algorithms that are known to be insecure. */
89- private string algorithmBlacklist ( ) {
92+ /**
93+ * Gets the name of an algorithm that is known to be insecure.
94+ */
95+ string getAnInsecureAlgorithmName ( ) {
9096 result = "DES" or
9197 result = "RC2" or
9298 result = "RC4" or
9399 result = "RC5" or
94100 result = "ARCFOUR" // a variant of RC4
95101}
96102
97- // These are only bad if they're being used for encryption.
98- private string hashAlgorithmBlacklist ( ) {
103+ /**
104+ * Gets the name of a hash algorithm that is insecure if it is being used for
105+ * encryption.
106+ */
107+ string getAnInsecureHashAlgorithmName ( ) {
99108 result = "SHA1" or
100109 result = "MD5"
101110}
102111
103- private string rankedAlgorithmBlacklist ( int i ) {
112+ private string rankedInsecureAlgorithm ( int i ) {
104113 // In this case we know these are being used for encryption, so we want to match
105114 // weak hash algorithms too.
106- result = rank [ i ] ( string s | s = algorithmBlacklist ( ) or s = hashAlgorithmBlacklist ( ) )
115+ result =
116+ rank [ i ] ( string s | s = getAnInsecureAlgorithmName ( ) or s = getAnInsecureHashAlgorithmName ( ) )
107117}
108118
109- private string algorithmBlacklistString ( int i ) {
110- i = 1 and result = rankedAlgorithmBlacklist ( i )
119+ private string insecureAlgorithmString ( int i ) {
120+ i = 1 and result = rankedInsecureAlgorithm ( i )
111121 or
112- result = rankedAlgorithmBlacklist ( i ) + "|" + algorithmBlacklistString ( i - 1 )
122+ result = rankedInsecureAlgorithm ( i ) + "|" + insecureAlgorithmString ( i - 1 )
113123}
114124
115- /** Gets a regex for matching strings that look like they contain a blacklisted algorithm. */
116- string algorithmBlacklistRegex ( ) {
117- result =
118- algorithmRegex ( algorithmBlacklistString ( max ( int i | exists ( rankedAlgorithmBlacklist ( i ) ) ) ) )
125+ /**
126+ * Gets the regular expression used for matching strings that look like they
127+ * contain an algorithm that is known to be insecure.
128+ */
129+ string getInsecureAlgorithmRegex ( ) {
130+ result = algorithmRegex ( insecureAlgorithmString ( max ( int i | exists ( rankedInsecureAlgorithm ( i ) ) ) ) )
119131}
120132
121- /** Gets a whitelist of algorithms that are known to be secure. */
122- private string algorithmWhitelist ( ) {
133+ /**
134+ * Gets the name of an algorithm that is known to be secure.
135+ */
136+ string getASecureAlgorithmName ( ) {
123137 result = "RSA" or
124138 result = "SHA256" or
125139 result = "SHA512" or
@@ -130,20 +144,50 @@ private string algorithmWhitelist() {
130144 result = "ECIES"
131145}
132146
133- private string rankedAlgorithmWhitelist ( int i ) { result = rank [ i ] ( algorithmWhitelist ( ) ) }
147+ private string rankedSecureAlgorithm ( int i ) { result = rank [ i ] ( getASecureAlgorithmName ( ) ) }
134148
135- private string algorithmWhitelistString ( int i ) {
136- i = 1 and result = rankedAlgorithmWhitelist ( i )
149+ private string secureAlgorithmString ( int i ) {
150+ i = 1 and result = rankedSecureAlgorithm ( i )
137151 or
138- result = rankedAlgorithmWhitelist ( i ) + "|" + algorithmWhitelistString ( i - 1 )
152+ result = rankedSecureAlgorithm ( i ) + "|" + secureAlgorithmString ( i - 1 )
139153}
140154
141- /** Gets a regex for matching strings that look like they contain a whitelisted algorithm. */
142- string algorithmWhitelistRegex ( ) {
143- result =
144- algorithmRegex ( algorithmWhitelistString ( max ( int i | exists ( rankedAlgorithmWhitelist ( i ) ) ) ) )
155+ /**
156+ * Gets a regular expression for matching strings that look like they
157+ * contain an algorithm that is known to be secure.
158+ */
159+ string getSecureAlgorithmRegex ( ) {
160+ result = algorithmRegex ( secureAlgorithmString ( max ( int i | exists ( rankedSecureAlgorithm ( i ) ) ) ) )
145161}
146162
163+ /**
164+ * DEPRECATED: Terminology has been updated. Use `getAnInsecureAlgorithmName()`
165+ * instead.
166+ */
167+ deprecated string algorithmBlacklist ( ) { result = getAnInsecureAlgorithmName ( ) }
168+
169+ /**
170+ * DEPRECATED: Terminology has been updated. Use
171+ * `getAnInsecureHashAlgorithmName()` instead.
172+ */
173+ deprecated string hashAlgorithmBlacklist ( ) { result = getAnInsecureHashAlgorithmName ( ) }
174+
175+ /**
176+ * DEPRECATED: Terminology has been updated. Use `getInsecureAlgorithmRegex()` instead.
177+ */
178+ deprecated string algorithmBlacklistRegex ( ) { result = getInsecureAlgorithmRegex ( ) }
179+
180+ /**
181+ * DEPRECATED: Terminology has been updated. Use `getASecureAlgorithmName()`
182+ * instead.
183+ */
184+ deprecated string algorithmWhitelist ( ) { result = getASecureAlgorithmName ( ) }
185+
186+ /**
187+ * DEPRECATED: Terminology has been updated. Use `getSecureAlgorithmRegex()` instead.
188+ */
189+ deprecated string algorithmWhitelistRegex ( ) { result = getSecureAlgorithmRegex ( ) }
190+
147191/**
148192 * Any use of a cryptographic element that specifies an encryption
149193 * algorithm. For example, methods returning ciphers, decryption methods,
0 commit comments