Skip to content

Commit bbfff7e

Browse files
committed
Remove duplicate copies of CryptoAlgorithms and CryptoAlgorithmNames
1 parent e81a5b7 commit bbfff7e

File tree

9 files changed

+4
-800
lines changed

9 files changed

+4
-800
lines changed

config/identical-files.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,6 @@
231231
"java/ql/src/experimental/Security/CWE/CWE-400/LocalThreadResourceAbuse.qhelp",
232232
"java/ql/src/experimental/Security/CWE/CWE-400/ThreadResourceAbuse.qhelp"
233233
],
234-
"CryptoAlgorithms Python/JS/Ruby": [
235-
"javascript/ql/lib/semmle/javascript/security/CryptoAlgorithms.qll",
236-
"python/ql/lib/semmle/python/concepts/CryptoAlgorithms.qll",
237-
"ruby/ql/lib/codeql/ruby/security/CryptoAlgorithms.qll",
238-
"rust/ql/lib/codeql/rust/security/CryptoAlgorithms.qll"
239-
],
240-
"CryptoAlgorithmNames Python/JS/Ruby": [
241-
"javascript/ql/lib/semmle/javascript/security/internal/CryptoAlgorithmNames.qll",
242-
"python/ql/lib/semmle/python/concepts/internal/CryptoAlgorithmNames.qll",
243-
"ruby/ql/lib/codeql/ruby/security/internal/CryptoAlgorithmNames.qll",
244-
"rust/ql/lib/codeql/rust/security/internal/CryptoAlgorithmNames.qll"
245-
],
246234
"IncompleteUrlSubstringSanitization": [
247235
"javascript/ql/src/Security/CWE-020/IncompleteUrlSubstringSanitization.qll",
248236
"ruby/ql/src/queries/security/cwe-020/IncompleteUrlSubstringSanitization.qll"
Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,5 @@
11
/**
22
* Provides classes modeling cryptographic algorithms, separated into strong and weak variants.
3-
*
4-
* The classification into strong and weak are based on Wikipedia, OWASP and Google (2021).
53
*/
64

7-
private import codeql.concepts.internal.CryptoAlgorithmNames
8-
9-
/**
10-
* A cryptographic algorithm.
11-
*/
12-
private newtype TCryptographicAlgorithm =
13-
MkHashingAlgorithm(string name, boolean isWeak) {
14-
isStrongHashingAlgorithm(name) and isWeak = false
15-
or
16-
isWeakHashingAlgorithm(name) and isWeak = true
17-
} or
18-
MkEncryptionAlgorithm(string name, boolean isWeak) {
19-
isStrongEncryptionAlgorithm(name) and isWeak = false
20-
or
21-
isWeakEncryptionAlgorithm(name) and isWeak = true
22-
} or
23-
MkPasswordHashingAlgorithm(string name, boolean isWeak) {
24-
isStrongPasswordHashingAlgorithm(name) and isWeak = false
25-
or
26-
isWeakPasswordHashingAlgorithm(name) and isWeak = true
27-
}
28-
29-
/**
30-
* Gets the most specific `CryptographicAlgorithm` that matches the given `name`.
31-
* A matching algorithm is one where the name of the algorithm matches the start of name, with allowances made for different name formats.
32-
* In the case that multiple `CryptographicAlgorithm`s match the given `name`, the algorithm(s) with the longest name will be selected. This is intended to select more specific versions of algorithms when multiple versions could match - for example "SHA3_224" matches against both "SHA3" and "SHA3224", but the latter is a more precise match.
33-
*/
34-
bindingset[name]
35-
private CryptographicAlgorithm getBestAlgorithmForName(string name) {
36-
result =
37-
max(CryptographicAlgorithm algorithm |
38-
algorithm.getName() =
39-
[
40-
name.toUpperCase(), // the full name
41-
name.toUpperCase().regexpCapture("^([\\w]+)(?:-.*)?$", 1), // the name prior to any dashes or spaces
42-
name.toUpperCase().regexpCapture("^([A-Z0-9]+)(?:(-|_).*)?$", 1) // the name prior to any dashes, spaces, or underscores
43-
].regexpReplaceAll("[-_ ]", "") // strip dashes, underscores, and spaces
44-
|
45-
algorithm order by algorithm.getName().length()
46-
)
47-
}
48-
49-
/**
50-
* A cryptographic algorithm.
51-
*/
52-
abstract class CryptographicAlgorithm extends TCryptographicAlgorithm {
53-
/** Gets a textual representation of this element. */
54-
string toString() { result = this.getName() }
55-
56-
/**
57-
* Gets the normalized name of this algorithm (upper-case, no spaces, dashes or underscores).
58-
*/
59-
abstract string getName();
60-
61-
/**
62-
* Holds if the name of this algorithm is the most specific match for `name`.
63-
* This predicate matches quite liberally to account for different ways of formatting algorithm names, e.g. using dashes, underscores, or spaces as separators, including or not including block modes of operation, etc.
64-
*/
65-
bindingset[name]
66-
predicate matchesName(string name) { this = getBestAlgorithmForName(name) }
67-
68-
/**
69-
* Holds if this algorithm is weak.
70-
*/
71-
abstract predicate isWeak();
72-
}
73-
74-
/**
75-
* A hashing algorithm such as `MD5` or `SHA512`.
76-
*/
77-
class HashingAlgorithm extends MkHashingAlgorithm, CryptographicAlgorithm {
78-
string name;
79-
boolean isWeak;
80-
81-
HashingAlgorithm() { this = MkHashingAlgorithm(name, isWeak) }
82-
83-
override string getName() { result = name }
84-
85-
override predicate isWeak() { isWeak = true }
86-
}
87-
88-
/**
89-
* An encryption algorithm such as `DES` or `AES512`.
90-
*/
91-
class EncryptionAlgorithm extends MkEncryptionAlgorithm, CryptographicAlgorithm {
92-
string name;
93-
boolean isWeak;
94-
95-
EncryptionAlgorithm() { this = MkEncryptionAlgorithm(name, isWeak) }
96-
97-
override string getName() { result = name }
98-
99-
override predicate isWeak() { isWeak = true }
100-
101-
/** Holds if this algorithm is a stream cipher. */
102-
predicate isStreamCipher() { isStreamCipher(name) }
103-
}
104-
105-
/**
106-
* A password hashing algorithm such as `PBKDF2` or `SCRYPT`.
107-
*/
108-
class PasswordHashingAlgorithm extends MkPasswordHashingAlgorithm, CryptographicAlgorithm {
109-
string name;
110-
boolean isWeak;
111-
112-
PasswordHashingAlgorithm() { this = MkPasswordHashingAlgorithm(name, isWeak) }
113-
114-
override string getName() { result = name }
115-
116-
override predicate isWeak() { isWeak = true }
117-
}
5+
private import codeql.concepts.CryptoAlgorithms

javascript/ql/lib/semmle/javascript/security/internal/CryptoAlgorithmNames.qll

Lines changed: 0 additions & 84 deletions
This file was deleted.
Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,5 @@
11
/**
22
* Provides classes modeling cryptographic algorithms, separated into strong and weak variants.
3-
*
4-
* The classification into strong and weak are based on Wikipedia, OWASP and Google (2021).
53
*/
64

7-
private import codeql.concepts.internal.CryptoAlgorithmNames
8-
9-
/**
10-
* A cryptographic algorithm.
11-
*/
12-
private newtype TCryptographicAlgorithm =
13-
MkHashingAlgorithm(string name, boolean isWeak) {
14-
isStrongHashingAlgorithm(name) and isWeak = false
15-
or
16-
isWeakHashingAlgorithm(name) and isWeak = true
17-
} or
18-
MkEncryptionAlgorithm(string name, boolean isWeak) {
19-
isStrongEncryptionAlgorithm(name) and isWeak = false
20-
or
21-
isWeakEncryptionAlgorithm(name) and isWeak = true
22-
} or
23-
MkPasswordHashingAlgorithm(string name, boolean isWeak) {
24-
isStrongPasswordHashingAlgorithm(name) and isWeak = false
25-
or
26-
isWeakPasswordHashingAlgorithm(name) and isWeak = true
27-
}
28-
29-
/**
30-
* Gets the most specific `CryptographicAlgorithm` that matches the given `name`.
31-
* A matching algorithm is one where the name of the algorithm matches the start of name, with allowances made for different name formats.
32-
* In the case that multiple `CryptographicAlgorithm`s match the given `name`, the algorithm(s) with the longest name will be selected. This is intended to select more specific versions of algorithms when multiple versions could match - for example "SHA3_224" matches against both "SHA3" and "SHA3224", but the latter is a more precise match.
33-
*/
34-
bindingset[name]
35-
private CryptographicAlgorithm getBestAlgorithmForName(string name) {
36-
result =
37-
max(CryptographicAlgorithm algorithm |
38-
algorithm.getName() =
39-
[
40-
name.toUpperCase(), // the full name
41-
name.toUpperCase().regexpCapture("^([\\w]+)(?:-.*)?$", 1), // the name prior to any dashes or spaces
42-
name.toUpperCase().regexpCapture("^([A-Z0-9]+)(?:(-|_).*)?$", 1) // the name prior to any dashes, spaces, or underscores
43-
].regexpReplaceAll("[-_ ]", "") // strip dashes, underscores, and spaces
44-
|
45-
algorithm order by algorithm.getName().length()
46-
)
47-
}
48-
49-
/**
50-
* A cryptographic algorithm.
51-
*/
52-
abstract class CryptographicAlgorithm extends TCryptographicAlgorithm {
53-
/** Gets a textual representation of this element. */
54-
string toString() { result = this.getName() }
55-
56-
/**
57-
* Gets the normalized name of this algorithm (upper-case, no spaces, dashes or underscores).
58-
*/
59-
abstract string getName();
60-
61-
/**
62-
* Holds if the name of this algorithm is the most specific match for `name`.
63-
* This predicate matches quite liberally to account for different ways of formatting algorithm names, e.g. using dashes, underscores, or spaces as separators, including or not including block modes of operation, etc.
64-
*/
65-
bindingset[name]
66-
predicate matchesName(string name) { this = getBestAlgorithmForName(name) }
67-
68-
/**
69-
* Holds if this algorithm is weak.
70-
*/
71-
abstract predicate isWeak();
72-
}
73-
74-
/**
75-
* A hashing algorithm such as `MD5` or `SHA512`.
76-
*/
77-
class HashingAlgorithm extends MkHashingAlgorithm, CryptographicAlgorithm {
78-
string name;
79-
boolean isWeak;
80-
81-
HashingAlgorithm() { this = MkHashingAlgorithm(name, isWeak) }
82-
83-
override string getName() { result = name }
84-
85-
override predicate isWeak() { isWeak = true }
86-
}
87-
88-
/**
89-
* An encryption algorithm such as `DES` or `AES512`.
90-
*/
91-
class EncryptionAlgorithm extends MkEncryptionAlgorithm, CryptographicAlgorithm {
92-
string name;
93-
boolean isWeak;
94-
95-
EncryptionAlgorithm() { this = MkEncryptionAlgorithm(name, isWeak) }
96-
97-
override string getName() { result = name }
98-
99-
override predicate isWeak() { isWeak = true }
100-
101-
/** Holds if this algorithm is a stream cipher. */
102-
predicate isStreamCipher() { isStreamCipher(name) }
103-
}
104-
105-
/**
106-
* A password hashing algorithm such as `PBKDF2` or `SCRYPT`.
107-
*/
108-
class PasswordHashingAlgorithm extends MkPasswordHashingAlgorithm, CryptographicAlgorithm {
109-
string name;
110-
boolean isWeak;
111-
112-
PasswordHashingAlgorithm() { this = MkPasswordHashingAlgorithm(name, isWeak) }
113-
114-
override string getName() { result = name }
115-
116-
override predicate isWeak() { isWeak = true }
117-
}
5+
import codeql.concepts.CryptoAlgorithms

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy