File tree Expand file tree Collapse file tree 4 files changed +45
-9
lines changed
src/semmle/code/cpp/security
test/library-tests/security/encryption Expand file tree Collapse file tree 4 files changed +45
-9
lines changed Original file line number Diff line number Diff line change @@ -59,15 +59,16 @@ string getASecureAlgorithmName() {
5959 * contain an algorithm that is known to be secure.
6060 */
6161string getSecureAlgorithmRegex ( ) {
62- // algorithms usually appear in names surrounded by characters that are not
63- // alphabetical characters in the same case. This handles the upper and lower
64- // case cases
65- result = "(^|.*[^A-Z])" + getASecureAlgorithmName ( ) + "([^A-Z].*|$)"
66- or
67- // for lowercase, we want to be careful to avoid being confused by camelCase
68- // hence we require two preceding uppercase letters to be sure of a case
69- // switch, or a preceding non-alphabetic character
70- result = "(^|.*[A-Z]{2}|.*[^a-zA-Z])" + getASecureAlgorithmName ( ) .toLowerCase ( ) + "([^a-z].*|$)"
62+ result =
63+ // algorithms usually appear in names surrounded by characters that are not
64+ // alphabetical characters in the same case. This handles the upper and lower
65+ // case cases
66+ "(^|.*[^A-Z])(" + strictconcat ( getASecureAlgorithmName ( ) , "|" ) + ")([^A-Z].*|$)" + "|" +
67+ // for lowercase, we want to be careful to avoid being confused by camelCase
68+ // hence we require two preceding uppercase letters to be sure of a case
69+ // switch, or a preceding non-alphabetic character
70+ "(^|.*[A-Z]{2}|.*[^a-zA-Z])(" + strictconcat ( getASecureAlgorithmName ( ) .toLowerCase ( ) , "|" ) +
71+ ")([^a-z].*|$)"
7172}
7273
7374/**
Original file line number Diff line number Diff line change 1+
2+ void des_function (); // insecure
3+ void function_using_des (); // insecure
4+ void EncryptWithDES (); // insecure
5+
6+ void aes_function (); // secure
7+ void function_using_aes (); // secure
8+ void EncryptionWithAES (); // secure
9+
10+ void abc_function ();
11+ void function_using_abc ();
12+ void EncryptionWithABC ();
Original file line number Diff line number Diff line change 1+ | test.cpp:2:6:2:17 | des_function | getInsecureAlgorithmRegex |
2+ | test.cpp:3:6:3:23 | function_using_des | getInsecureAlgorithmRegex |
3+ | test.cpp:4:6:4:19 | EncryptWithDES | getInsecureAlgorithmRegex |
4+ | test.cpp:6:6:6:17 | aes_function | getSecureAlgorithmRegex |
5+ | test.cpp:7:6:7:23 | function_using_aes | getSecureAlgorithmRegex |
6+ | test.cpp:8:6:8:22 | EncryptionWithAES | getSecureAlgorithmRegex |
7+ | test.cpp:10:6:10:17 | abc_function | |
8+ | test.cpp:11:6:11:23 | function_using_abc | |
9+ | test.cpp:12:6:12:22 | EncryptionWithABC | |
Original file line number Diff line number Diff line change 1+ import default
2+ import semmle.code.cpp.security.Encryption
3+
4+ string describe ( Function f ) {
5+ f .getName ( ) .regexpMatch ( getSecureAlgorithmRegex ( ) ) and
6+ result = "getSecureAlgorithmRegex"
7+ or
8+ f .getName ( ) .regexpMatch ( getInsecureAlgorithmRegex ( ) ) and
9+ result = "getInsecureAlgorithmRegex"
10+ }
11+
12+ from Function f
13+ where exists ( f .getLocation ( ) .getFile ( ) )
14+ select f , concat ( describe ( f ) , ", " )
You can’t perform that action at this time.
0 commit comments