Skip to content

Commit 21d5e41

Browse files
add interprocedural cases to the tests
1 parent 9576e4c commit 21d5e41

File tree

4 files changed

+98
-103
lines changed

4 files changed

+98
-103
lines changed
Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
edges
2-
| testAES.swift:32:12:32:16 | call to init() : | testAES.swift:36:36:36:36 | ecb |
3-
| testAES.swift:32:12:32:16 | call to init() : | testAES.swift:37:36:37:36 | ecb |
4-
| testBlowfish.swift:32:12:32:16 | call to init() : | testBlowfish.swift:36:41:36:41 | ecb |
2+
| test.swift:34:9:34:13 | call to init() : | test.swift:54:37:54:53 | call to getECBBlockMode() |
3+
| test.swift:34:9:34:13 | call to init() : | test.swift:55:37:55:53 | call to getECBBlockMode() |
4+
| test.swift:34:9:34:13 | call to init() : | test.swift:67:42:67:58 | call to getECBBlockMode() |
5+
| test.swift:45:12:45:16 | call to init() : | test.swift:50:37:50:37 | ecb |
6+
| test.swift:45:12:45:16 | call to init() : | test.swift:51:37:51:37 | ecb |
7+
| test.swift:45:12:45:16 | call to init() : | test.swift:65:42:65:42 | ecb |
58
nodes
6-
| testAES.swift:32:12:32:16 | call to init() : | semmle.label | call to init() : |
7-
| testAES.swift:36:36:36:36 | ecb | semmle.label | ecb |
8-
| testAES.swift:37:36:37:36 | ecb | semmle.label | ecb |
9-
| testAES.swift:38:36:38:40 | call to init() | semmle.label | call to init() |
10-
| testAES.swift:39:36:39:40 | call to init() | semmle.label | call to init() |
11-
| testBlowfish.swift:32:12:32:16 | call to init() : | semmle.label | call to init() : |
12-
| testBlowfish.swift:36:41:36:41 | ecb | semmle.label | ecb |
13-
| testBlowfish.swift:37:41:37:45 | call to init() | semmle.label | call to init() |
9+
| test.swift:34:9:34:13 | call to init() : | semmle.label | call to init() : |
10+
| test.swift:45:12:45:16 | call to init() : | semmle.label | call to init() : |
11+
| test.swift:50:37:50:37 | ecb | semmle.label | ecb |
12+
| test.swift:51:37:51:37 | ecb | semmle.label | ecb |
13+
| test.swift:52:37:52:41 | call to init() | semmle.label | call to init() |
14+
| test.swift:53:37:53:41 | call to init() | semmle.label | call to init() |
15+
| test.swift:54:37:54:53 | call to getECBBlockMode() | semmle.label | call to getECBBlockMode() |
16+
| test.swift:55:37:55:53 | call to getECBBlockMode() | semmle.label | call to getECBBlockMode() |
17+
| test.swift:65:42:65:42 | ecb | semmle.label | ecb |
18+
| test.swift:66:42:66:46 | call to init() | semmle.label | call to init() |
19+
| test.swift:67:42:67:58 | call to getECBBlockMode() | semmle.label | call to getECBBlockMode() |
1420
subpaths
1521
#select
16-
| testAES.swift:36:36:36:36 | ecb | testAES.swift:32:12:32:16 | call to init() : | testAES.swift:36:36:36:36 | ecb | The initialization of the cipher 'ecb' uses the insecure ECB block mode from $@ | testAES.swift:32:12:32:16 | call to init() : | call to init() |
17-
| testAES.swift:37:36:37:36 | ecb | testAES.swift:32:12:32:16 | call to init() : | testAES.swift:37:36:37:36 | ecb | The initialization of the cipher 'ecb' uses the insecure ECB block mode from $@ | testAES.swift:32:12:32:16 | call to init() : | call to init() |
18-
| testAES.swift:38:36:38:40 | call to init() | testAES.swift:38:36:38:40 | call to init() | testAES.swift:38:36:38:40 | call to init() | The initialization of the cipher 'call to init()' uses the insecure ECB block mode from $@ | testAES.swift:38:36:38:40 | call to init() | call to init() |
19-
| testAES.swift:39:36:39:40 | call to init() | testAES.swift:39:36:39:40 | call to init() | testAES.swift:39:36:39:40 | call to init() | The initialization of the cipher 'call to init()' uses the insecure ECB block mode from $@ | testAES.swift:39:36:39:40 | call to init() | call to init() |
20-
| testBlowfish.swift:36:41:36:41 | ecb | testBlowfish.swift:32:12:32:16 | call to init() : | testBlowfish.swift:36:41:36:41 | ecb | The initialization of the cipher 'ecb' uses the insecure ECB block mode from $@ | testBlowfish.swift:32:12:32:16 | call to init() : | call to init() |
21-
| testBlowfish.swift:37:41:37:45 | call to init() | testBlowfish.swift:37:41:37:45 | call to init() | testBlowfish.swift:37:41:37:45 | call to init() | The initialization of the cipher 'call to init()' uses the insecure ECB block mode from $@ | testBlowfish.swift:37:41:37:45 | call to init() | call to init() |
22+
| test.swift:50:37:50:37 | ecb | test.swift:45:12:45:16 | call to init() : | test.swift:50:37:50:37 | ecb | The initialization of the cipher 'ecb' uses the insecure ECB block mode from $@ | test.swift:45:12:45:16 | call to init() : | call to init() |
23+
| test.swift:51:37:51:37 | ecb | test.swift:45:12:45:16 | call to init() : | test.swift:51:37:51:37 | ecb | The initialization of the cipher 'ecb' uses the insecure ECB block mode from $@ | test.swift:45:12:45:16 | call to init() : | call to init() |
24+
| test.swift:52:37:52:41 | call to init() | test.swift:52:37:52:41 | call to init() | test.swift:52:37:52:41 | call to init() | The initialization of the cipher 'call to init()' uses the insecure ECB block mode from $@ | test.swift:52:37:52:41 | call to init() | call to init() |
25+
| test.swift:53:37:53:41 | call to init() | test.swift:53:37:53:41 | call to init() | test.swift:53:37:53:41 | call to init() | The initialization of the cipher 'call to init()' uses the insecure ECB block mode from $@ | test.swift:53:37:53:41 | call to init() | call to init() |
26+
| test.swift:54:37:54:53 | call to getECBBlockMode() | test.swift:34:9:34:13 | call to init() : | test.swift:54:37:54:53 | call to getECBBlockMode() | The initialization of the cipher 'call to getECBBlockMode()' uses the insecure ECB block mode from $@ | test.swift:34:9:34:13 | call to init() : | call to init() |
27+
| test.swift:55:37:55:53 | call to getECBBlockMode() | test.swift:34:9:34:13 | call to init() : | test.swift:55:37:55:53 | call to getECBBlockMode() | The initialization of the cipher 'call to getECBBlockMode()' uses the insecure ECB block mode from $@ | test.swift:34:9:34:13 | call to init() : | call to init() |
28+
| test.swift:65:42:65:42 | ecb | test.swift:45:12:45:16 | call to init() : | test.swift:65:42:65:42 | ecb | The initialization of the cipher 'ecb' uses the insecure ECB block mode from $@ | test.swift:45:12:45:16 | call to init() : | call to init() |
29+
| test.swift:66:42:66:46 | call to init() | test.swift:66:42:66:46 | call to init() | test.swift:66:42:66:46 | call to init() | The initialization of the cipher 'call to init()' uses the insecure ECB block mode from $@ | test.swift:66:42:66:46 | call to init() | call to init() |
30+
| test.swift:67:42:67:58 | call to getECBBlockMode() | test.swift:34:9:34:13 | call to init() : | test.swift:67:42:67:58 | call to getECBBlockMode() | The initialization of the cipher 'call to getECBBlockMode()' uses the insecure ECB block mode from $@ | test.swift:34:9:34:13 | call to init() : | call to init() |
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2+
// --- stubs ---
3+
4+
// These stubs roughly follows the same structure as classes from CryptoSwift
5+
class AES
6+
{
7+
init(key: Array<UInt8>, blockMode: BlockMode, padding: Padding) { }
8+
init(key: Array<UInt8>, blockMode: BlockMode) { }
9+
}
10+
11+
class Blowfish
12+
{
13+
init(key: Array<UInt8>, blockMode: BlockMode, padding: Padding) { }
14+
}
15+
16+
protocol BlockMode { }
17+
18+
struct ECB: BlockMode {
19+
init() { }
20+
}
21+
22+
struct CBC: BlockMode {
23+
init() { }
24+
}
25+
26+
protocol PaddingProtocol { }
27+
28+
enum Padding: PaddingProtocol {
29+
case noPadding, zeroPadding, pkcs7, pkcs5, eme_pkcs1v15, emsa_pkcs1v15, iso78164, iso10126
30+
}
31+
32+
// Create some inter-procedural dependencies
33+
func getECBBlockMode() -> BlockMode {
34+
return ECB()
35+
}
36+
37+
func getCBCBlockMode() -> BlockMode {
38+
return CBC()
39+
}
40+
41+
// --- tests ---
42+
43+
func test1() {
44+
let key: Array<UInt8> = [0x2a, 0x3a, 0x80, 0x05, 0xaf, 0x46, 0x58, 0x2d, 0x66, 0x52, 0x10, 0xae, 0x86, 0xd3, 0x8e, 0x8f]
45+
let ecb = ECB()
46+
let cbc = CBC()
47+
let padding = Padding.noPadding
48+
49+
// AES test cases
50+
let ab1 = AES(key: key, blockMode: ecb, padding: padding) // BAD
51+
let ab2 = AES(key: key, blockMode: ecb) // BAD
52+
let ab3 = AES(key: key, blockMode: ECB(), padding: padding) // BAD
53+
let ab4 = AES(key: key, blockMode: ECB()) // BAD
54+
let ab5 = AES(key: key, blockMode: getECBBlockMode(), padding: padding) // BAD
55+
let ab6 = AES(key: key, blockMode: getECBBlockMode()) // BAD
56+
57+
let ag1 = AES(key: key, blockMode: cbc, padding: padding) // GOOD
58+
let ag2 = AES(key: key, blockMode: cbc) // GOOD
59+
let ag3 = AES(key: key, blockMode: CBC(), padding: padding) // GOOD
60+
let ag4 = AES(key: key, blockMode: CBC()) // GOOD
61+
let ag5 = AES(key: key, blockMode: getCBCBlockMode(), padding: padding) // GOOD
62+
let ag6 = AES(key: key, blockMode: getCBCBlockMode()) // GOOD
63+
64+
// Blowfish test cases
65+
let bb1 = Blowfish(key: key, blockMode: ecb, padding: padding) // BAD
66+
let bb2 = Blowfish(key: key, blockMode: ECB(), padding: padding) // BAD
67+
let bb3 = Blowfish(key: key, blockMode: getECBBlockMode(), padding: padding) // BAD
68+
69+
let bg1 = Blowfish(key: key, blockMode: cbc, padding: padding) // GOOD
70+
let bg2 = Blowfish(key: key, blockMode: CBC(), padding: padding) // GOOD
71+
let bg3 = Blowfish(key: key, blockMode: getCBCBlockMode(), padding: padding) // GOOD
72+
}

swift/ql/test/query-tests/Security/ECB-Encryption/testAES.swift

Lines changed: 0 additions & 45 deletions
This file was deleted.

swift/ql/test/query-tests/Security/ECB-Encryption/testBlowfish.swift

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)