diff --git a/rules/swift/security/hkdf-hardcoded-secret-swift.yml b/rules/swift/security/hkdf-hardcoded-secret-swift.yml new file mode 100644 index 00000000..6e626a49 --- /dev/null +++ b/rules/swift/security/hkdf-hardcoded-secret-swift.yml @@ -0,0 +1,291 @@ +id: hkdf-hardcoded-secret-swift +severity: warning +language: swift +message: >- + A secret is hard-coded in the application. Secrets stored in source + code, such as credentials, identifiers, and other types of sensitive data, + can be leaked and used by internal or external malicious actors. Use + environment variables to securely provide credentials and other secrets or + retrieve them from a secure vault or Hardware Security Module (HSM). +note: >- + [CWE-798] Use of Hard-coded Credentials. + [REFERENCES] + - https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html +utils: + match_pattern_try_expression_directly: + kind: try_expression + has: + stopBy: end + kind: call_expression + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^HKDF$" + - has: + stopBy: end + kind: call_suffix + has: + stopBy: end + kind: value_arguments + has: + stopBy: end + kind: value_argument + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^password$" + - has: + stopBy: end + kind: line_string_literal + has: + stopBy: end + kind: line_str_text + + match_pattern_HKDF_statement_directly: + kind: call_expression + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^HKDF$" + - has: + stopBy: end + kind: call_suffix + has: + stopBy: end + kind: value_arguments + has: + stopBy: end + kind: value_argument + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^password$" + - has: + stopBy: end + kind: line_string_literal + has: + stopBy: end + kind: line_str_text + - not: + inside: + stopBy: neighbor + kind: try_expression + + match_pattern_HKDF_expression_with_instance: + kind: call_expression + all: + - has: + stopBy: neighbor + kind: simple_identifier + regex: "^HKDF$" + - has: + stopBy: neighbor + kind: call_suffix + has: + stopBy: neighbor + kind: value_arguments + has: + stopBy: neighbor + kind: value_argument + all: + - has: + stopBy: neighbor + kind: simple_identifier + regex: "^password$" + - has: + stopBy: end + kind: simple_identifier + nthChild: 2 + pattern: $R + - not: + inside: + stopBy: neighbor + kind: try_expression + - inside: + stopBy: end + kind: property_declaration + follows: + stopBy: end + kind: property_declaration + all: + - has: + stopBy: end + kind: pattern + has: + stopBy: end + kind: simple_identifier + pattern: $R + - has: + stopBy: neighbor + kind: call_expression + pattern: Array("$$$".utf8) + + match_pattern_try_expression_with_instance: + kind: try_expression + all: + - has: + stopBy: neighbor + kind: call_expression + all: + - has: + stopBy: neighbor + kind: simple_identifier + regex: "^HKDF$" + - has: + stopBy: neighbor + kind: call_suffix + has: + stopBy: neighbor + kind: value_arguments + has: + stopBy: neighbor + kind: value_argument + all: + - has: + stopBy: neighbor + kind: simple_identifier + regex: "^password$" + - has: + stopBy: end + kind: simple_identifier + nthChild: 2 + pattern: $R + - inside: + stopBy: end + kind: property_declaration + follows: + stopBy: end + kind: property_declaration + all: + - has: + stopBy: end + kind: pattern + has: + stopBy: end + kind: simple_identifier + pattern: $R + - has: + stopBy: neighbor + kind: call_expression + pattern: Array("$$$".utf8) + + match_pattern_HKDF_expression_with_utf8: + kind: call_expression + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^HKDF$" + - has: + stopBy: end + kind: call_suffix + has: + stopBy: end + kind: value_argument + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^password$" + - has: + stopBy: end + kind: call_expression + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^Array$" + - has: + stopBy: end + kind: call_suffix + has: + stopBy: end + kind: value_argument + has: + stopBy: end + kind: navigation_expression + all: + - has: + stopBy: end + kind: line_string_literal + has: + stopBy: end + kind: line_str_text + - has: + stopBy: end + kind: navigation_suffix + has: + stopBy: end + kind: simple_identifier + regex: "^utf8$" + + match_pattern_try_expression_with_utf8: + kind: try_expression + has: + stopBy: neighbor + kind: call_expression + all: + - has: + stopBy: neighbor + kind: simple_identifier + regex: "^HKDF$" + - has: + stopBy: neighbor + kind: call_suffix + has: + stopBy: end + kind: value_argument + all: + - has: + stopBy: neighbor + kind: simple_identifier + regex: "^password$" + - has: + stopBy: neighbor + kind: call_expression + all: + - has: + stopBy: neighbor + kind: simple_identifier + regex: "^Array$" + - has: + stopBy: neighbor + kind: call_suffix + has: + stopBy: end + kind: value_argument + has: + stopBy: neighbor + kind: navigation_expression + all: + - has: + stopBy: neighbor + kind: line_string_literal + has: + stopBy: neighbor + kind: line_str_text + - has: + stopBy: neighbor + kind: navigation_suffix + has: + stopBy: neighbor + kind: simple_identifier + regex: "^utf8$" + +rule: + any: + - kind: try_expression + any: + - matches: match_pattern_try_expression_directly + - matches: match_pattern_try_expression_with_instance + - matches: match_pattern_try_expression_with_utf8 + + - kind: call_expression + any: + - matches: match_pattern_HKDF_statement_directly + - matches: match_pattern_HKDF_expression_with_instance + - matches: match_pattern_HKDF_expression_with_utf8 diff --git a/rules/swift/security/rabbit-hardcoded-secret-swift.yml b/rules/swift/security/rabbit-hardcoded-secret-swift.yml new file mode 100644 index 00000000..9356fdfb --- /dev/null +++ b/rules/swift/security/rabbit-hardcoded-secret-swift.yml @@ -0,0 +1,285 @@ +id: rabbit-hardcoded-secret-swift +severity: warning +language: swift +message: >- + A secret is hard-coded in the application. Secrets stored in source + code, such as credentials, identifiers, and other types of sensitive data, + can be leaked and used by internal or external malicious actors. Use + environment variables to securely provide credentials and other secrets or + retrieve them from a secure vault or Hardware Security Module (HSM). +note: >- + [CWE-798] Use of Hard-coded Credentials. + [REFERENCES] + - https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html +utils: + match_pattern_try_expression_directly: + kind: try_expression + has: + stopBy: neighbor + kind: call_expression + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^Rabbit$" + - has: + stopBy: end + kind: call_suffix + has: + stopBy: end + kind: value_arguments + has: + stopBy: end + kind: value_argument + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^key$" + - has: + stopBy: neighbor + kind: line_string_literal + has: + stopBy: end + kind: line_str_text + + match_pattern_Rabbit_statement_directly: + kind: call_expression + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^Rabbit$" + - has: + stopBy: end + kind: call_suffix + has: + stopBy: end + kind: value_arguments + has: + stopBy: end + kind: value_argument + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^key$" + - has: + stopBy: end + kind: line_string_literal + has: + stopBy: neighbor + kind: line_str_text + - not: + inside: + stopBy: end + kind: try_expression + + match_pattern_Rabbit_expression_with_instance: + kind: call_expression + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^Rabbit$" + - has: + stopBy: end + kind: call_suffix + has: + stopBy: end + kind: value_arguments + has: + stopBy: end + kind: value_argument + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^key$" + - has: + stopBy: end + kind: simple_identifier + nthChild: 2 + pattern: $R + - not: + inside: + stopBy: neighbor + kind: try_expression + - follows: + stopBy: end + kind: property_declaration + all: + - has: + stopBy: end + kind: pattern + has: + stopBy: end + kind: simple_identifier + pattern: $R + - has: + stopBy: neighbor + kind: call_expression + pattern: Array("$$$".utf8) + + match_pattern_try_expression_with_instance: + kind: try_expression + all: + - has: + stopBy: neighbor + kind: call_expression + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^Rabbit$" + - has: + stopBy: end + kind: call_suffix + has: + stopBy: end + kind: value_arguments + has: + stopBy: end + kind: value_argument + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^key$" + - has: + stopBy: end + kind: simple_identifier + nthChild: 2 + pattern: $R + - follows: + stopBy: end + kind: property_declaration + all: + - has: + stopBy: end + kind: pattern + has: + stopBy: end + kind: simple_identifier + pattern: $R + - has: + stopBy: end + kind: call_expression + pattern: Array("$$$".utf8) + + match_pattern_Rabbit_expression_with_utf8: + kind: call_expression + all: + - has: + stopBy: neighbor + kind: simple_identifier + regex: "^Rabbit$" + - has: + stopBy: neighbor + kind: call_suffix + has: + stopBy: end + kind: value_argument + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^key$" + - has: + stopBy: end + kind: call_expression + all: + - has: + stopBy: neighbor + kind: simple_identifier + regex: "^Array$" + - has: + stopBy: neighbor + kind: call_suffix + has: + stopBy: end + kind: value_argument + has: + stopBy: neighbor + kind: navigation_expression + all: + - has: + stopBy: neighbor + kind: line_string_literal + has: + stopBy: neighbor + kind: line_str_text + - has: + stopBy: neighbor + kind: navigation_suffix + has: + stopBy: neighbor + kind: simple_identifier + regex: "^utf8$" + + match_pattern_try_expression_with_utf8: + kind: try_expression + has: + stopBy: end + kind: call_expression + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^Rabbit$" + - has: + stopBy: end + kind: call_suffix + has: + stopBy: end + kind: value_argument + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^key$" + - has: + stopBy: end + kind: call_expression + all: + - has: + stopBy: end + kind: simple_identifier + regex: "^Array$" + - has: + stopBy: end + kind: call_suffix + has: + stopBy: end + kind: value_argument + has: + stopBy: end + kind: navigation_expression + all: + - has: + stopBy: end + kind: line_string_literal + has: + stopBy: end + kind: line_str_text + - has: + stopBy: end + kind: navigation_suffix + has: + stopBy: end + kind: simple_identifier + regex: "^utf8$" + +rule: + any: + - kind: try_expression + any: + - matches: match_pattern_try_expression_directly + - matches: match_pattern_try_expression_with_instance + - matches: match_pattern_try_expression_with_utf8 + + - kind: call_expression + any: + - matches: match_pattern_Rabbit_statement_directly + - matches: match_pattern_Rabbit_expression_with_instance + - matches: match_pattern_Rabbit_expression_with_utf8 diff --git a/tests/__snapshots__/hkdf-hardcoded-secret-swift-snapshot.yml b/tests/__snapshots__/hkdf-hardcoded-secret-swift-snapshot.yml new file mode 100644 index 00000000..a0af9d3a --- /dev/null +++ b/tests/__snapshots__/hkdf-hardcoded-secret-swift-snapshot.yml @@ -0,0 +1,250 @@ +id: hkdf-hardcoded-secret-swift +snapshots: + ? | + HKDF(password: "123", salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate() + : labels: + - source: 'HKDF(password: "123", salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate()' + style: primary + start: 0 + end: 78 + - source: HKDF + style: secondary + start: 0 + end: 4 + - source: password + style: secondary + start: 5 + end: 13 + - source: '123' + style: secondary + start: 16 + end: 19 + - source: '"123"' + style: secondary + start: 15 + end: 20 + - source: 'password: "123"' + style: secondary + start: 5 + end: 20 + - source: '(password: "123", salt: salt, dkLen: 64, N: 16384, r: 8, p: 1)' + style: secondary + start: 4 + end: 66 + - source: '(password: "123", salt: salt, dkLen: 64, N: 16384, r: 8, p: 1)' + style: secondary + start: 4 + end: 66 + ? | + HKDF(password: Array("hello".utf8), salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate() + : labels: + - source: 'HKDF(password: Array("hello".utf8), salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate()' + style: primary + start: 0 + end: 92 + - source: HKDF + style: secondary + start: 0 + end: 4 + - source: password + style: secondary + start: 5 + end: 13 + - source: hello + style: secondary + start: 22 + end: 27 + - source: '"hello"' + style: secondary + start: 21 + end: 28 + - source: 'password: Array("hello".utf8)' + style: secondary + start: 5 + end: 34 + - source: '(password: Array("hello".utf8), salt: salt, dkLen: 64, N: 16384, r: 8, p: 1)' + style: secondary + start: 4 + end: 80 + - source: '(password: Array("hello".utf8), salt: salt, dkLen: 64, N: 16384, r: 8, p: 1)' + style: secondary + start: 4 + end: 80 + ? | + let password = Array("s33krit".utf8) + let key = HKDF(password: password, salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate() + : labels: + - source: 'HKDF(password: password, salt: salt, dkLen: 64, N: 16384, r: 8, p: 1)' + style: primary + start: 47 + end: 116 + - source: HKDF + style: secondary + start: 47 + end: 51 + - source: password + style: secondary + start: 62 + end: 70 + - source: password + style: secondary + start: 62 + end: 70 + - source: 'password: password' + style: secondary + start: 52 + end: 70 + - source: '(password: password, salt: salt, dkLen: 64, N: 16384, r: 8, p: 1)' + style: secondary + start: 51 + end: 116 + - source: '(password: password, salt: salt, dkLen: 64, N: 16384, r: 8, p: 1)' + style: secondary + start: 51 + end: 116 + - source: password + style: secondary + start: 4 + end: 12 + - source: password + style: secondary + start: 4 + end: 12 + - source: Array("s33krit".utf8) + style: secondary + start: 15 + end: 36 + - source: let password = Array("s33krit".utf8) + style: secondary + start: 0 + end: 36 + - source: 'let key = HKDF(password: password, salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate()' + style: secondary + start: 37 + end: 128 + ? | + let password: Array = Array("s33krit".utf8) + let key = try HKDF(password: password, salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate() + : labels: + - source: 'try HKDF(password: password, salt: salt, dkLen: 64, N: 16384, r: 8, p: 1)' + style: primary + start: 61 + end: 134 + - source: HKDF + style: secondary + start: 65 + end: 69 + - source: password + style: secondary + start: 80 + end: 88 + - source: password + style: secondary + start: 80 + end: 88 + - source: 'password: password' + style: secondary + start: 70 + end: 88 + - source: '(password: password, salt: salt, dkLen: 64, N: 16384, r: 8, p: 1)' + style: secondary + start: 69 + end: 134 + - source: '(password: password, salt: salt, dkLen: 64, N: 16384, r: 8, p: 1)' + style: secondary + start: 69 + end: 134 + - source: 'HKDF(password: password, salt: salt, dkLen: 64, N: 16384, r: 8, p: 1)' + style: secondary + start: 65 + end: 134 + - source: password + style: secondary + start: 4 + end: 12 + - source: password + style: secondary + start: 4 + end: 12 + - source: Array("s33krit".utf8) + style: secondary + start: 29 + end: 50 + - source: 'let password: Array = Array("s33krit".utf8)' + style: secondary + start: 0 + end: 50 + - source: 'let key = try HKDF(password: password, salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate()' + style: secondary + start: 51 + end: 146 + ? | + try HKDF(password: "123", salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate() + : labels: + - source: 'try HKDF(password: "123", salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate()' + style: primary + start: 0 + end: 82 + - source: HKDF + style: secondary + start: 4 + end: 8 + - source: password + style: secondary + start: 9 + end: 17 + - source: '123' + style: secondary + start: 20 + end: 23 + - source: '"123"' + style: secondary + start: 19 + end: 24 + - source: 'password: "123"' + style: secondary + start: 9 + end: 24 + - source: '(password: "123", salt: salt, dkLen: 64, N: 16384, r: 8, p: 1)' + style: secondary + start: 8 + end: 70 + - source: '(password: "123", salt: salt, dkLen: 64, N: 16384, r: 8, p: 1)' + style: secondary + start: 8 + end: 70 + ? | + try HKDF(password: Array("hello".utf8), salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate() + : labels: + - source: 'try HKDF(password: Array("hello".utf8), salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate()' + style: primary + start: 0 + end: 96 + - source: HKDF + style: secondary + start: 4 + end: 8 + - source: password + style: secondary + start: 9 + end: 17 + - source: hello + style: secondary + start: 26 + end: 31 + - source: '"hello"' + style: secondary + start: 25 + end: 32 + - source: 'password: Array("hello".utf8)' + style: secondary + start: 9 + end: 38 + - source: '(password: Array("hello".utf8), salt: salt, dkLen: 64, N: 16384, r: 8, p: 1)' + style: secondary + start: 8 + end: 84 + - source: '(password: Array("hello".utf8), salt: salt, dkLen: 64, N: 16384, r: 8, p: 1)' + style: secondary + start: 8 + end: 84 diff --git a/tests/__snapshots__/rabbit-hardcoded-secret-swift-snapshot.yml b/tests/__snapshots__/rabbit-hardcoded-secret-swift-snapshot.yml new file mode 100644 index 00000000..9d450832 --- /dev/null +++ b/tests/__snapshots__/rabbit-hardcoded-secret-swift-snapshot.yml @@ -0,0 +1,274 @@ +id: rabbit-hardcoded-secret-swift +snapshots: + ? | + Rabbit(key: "hello", iv: "123") + : labels: + - source: 'Rabbit(key: "hello", iv: "123")' + style: primary + start: 0 + end: 31 + - source: Rabbit + style: secondary + start: 0 + end: 6 + - source: key + style: secondary + start: 7 + end: 10 + - source: hello + style: secondary + start: 13 + end: 18 + - source: '"hello"' + style: secondary + start: 12 + end: 19 + - source: 'key: "hello"' + style: secondary + start: 7 + end: 19 + - source: '(key: "hello", iv: "123")' + style: secondary + start: 6 + end: 31 + - source: '(key: "hello", iv: "123")' + style: secondary + start: 6 + end: 31 + ? | + Rabbit(key: Array("hello".utf8)); + : labels: + - source: 'Rabbit(key: Array("hello".utf8))' + style: primary + start: 0 + end: 32 + - source: Rabbit + style: secondary + start: 0 + end: 6 + - source: key + style: secondary + start: 7 + end: 10 + - source: hello + style: secondary + start: 19 + end: 24 + - source: '"hello"' + style: secondary + start: 18 + end: 25 + - source: 'key: Array("hello".utf8)' + style: secondary + start: 7 + end: 31 + - source: '(key: Array("hello".utf8))' + style: secondary + start: 6 + end: 32 + - source: '(key: Array("hello".utf8))' + style: secondary + start: 6 + end: 32 + ? | + let password = Array("s33krit".utf8) + Rabbit(key: password, iv: "123") + : labels: + - source: 'Rabbit(key: password, iv: "123")' + style: primary + start: 37 + end: 69 + - source: Rabbit + style: secondary + start: 37 + end: 43 + - source: key + style: secondary + start: 44 + end: 47 + - source: password + style: secondary + start: 49 + end: 57 + - source: 'key: password' + style: secondary + start: 44 + end: 57 + - source: '(key: password, iv: "123")' + style: secondary + start: 43 + end: 69 + - source: '(key: password, iv: "123")' + style: secondary + start: 43 + end: 69 + - source: password + style: secondary + start: 4 + end: 12 + - source: password + style: secondary + start: 4 + end: 12 + - source: Array("s33krit".utf8) + style: secondary + start: 15 + end: 36 + - source: let password = Array("s33krit".utf8) + style: secondary + start: 0 + end: 36 + ? | + let password: Array = Array("s33krit".utf8) + try Rabbit(key: password, iv: "123") + : labels: + - source: 'try Rabbit(key: password, iv: "123")' + style: primary + start: 51 + end: 87 + - source: Rabbit + style: secondary + start: 55 + end: 61 + - source: key + style: secondary + start: 62 + end: 65 + - source: password + style: secondary + start: 67 + end: 75 + - source: 'key: password' + style: secondary + start: 62 + end: 75 + - source: '(key: password, iv: "123")' + style: secondary + start: 61 + end: 87 + - source: '(key: password, iv: "123")' + style: secondary + start: 61 + end: 87 + - source: 'Rabbit(key: password, iv: "123")' + style: secondary + start: 55 + end: 87 + - source: password + style: secondary + start: 4 + end: 12 + - source: password + style: secondary + start: 4 + end: 12 + - source: Array("s33krit".utf8) + style: secondary + start: 29 + end: 50 + - source: 'let password: Array = Array("s33krit".utf8)' + style: secondary + start: 0 + end: 50 + ? | + try Rabbit(key: "hello", iv: "123") + : labels: + - source: 'try Rabbit(key: "hello", iv: "123")' + style: primary + start: 0 + end: 35 + - source: Rabbit + style: secondary + start: 4 + end: 10 + - source: key + style: secondary + start: 11 + end: 14 + - source: hello + style: secondary + start: 17 + end: 22 + - source: '"hello"' + style: secondary + start: 16 + end: 23 + - source: 'key: "hello"' + style: secondary + start: 11 + end: 23 + - source: '(key: "hello", iv: "123")' + style: secondary + start: 10 + end: 35 + - source: '(key: "hello", iv: "123")' + style: secondary + start: 10 + end: 35 + - source: 'Rabbit(key: "hello", iv: "123")' + style: secondary + start: 4 + end: 35 + ? | + try Rabbit(key: Array("hello".utf8)); + : labels: + - source: 'try Rabbit(key: Array("hello".utf8))' + style: primary + start: 0 + end: 36 + - source: Rabbit + style: secondary + start: 4 + end: 10 + - source: key + style: secondary + start: 11 + end: 14 + - source: Array + style: secondary + start: 16 + end: 21 + - source: hello + style: secondary + start: 23 + end: 28 + - source: '"hello"' + style: secondary + start: 22 + end: 29 + - source: utf8 + style: secondary + start: 30 + end: 34 + - source: .utf8 + style: secondary + start: 29 + end: 34 + - source: '"hello".utf8' + style: secondary + start: 22 + end: 34 + - source: '"hello".utf8' + style: secondary + start: 22 + end: 34 + - source: ("hello".utf8) + style: secondary + start: 21 + end: 35 + - source: Array("hello".utf8) + style: secondary + start: 16 + end: 35 + - source: 'key: Array("hello".utf8)' + style: secondary + start: 11 + end: 35 + - source: '(key: Array("hello".utf8))' + style: secondary + start: 10 + end: 36 + - source: 'Rabbit(key: Array("hello".utf8))' + style: secondary + start: 4 + end: 36 diff --git a/tests/swift/hkdf-hardcoded-secret-swift-test.yml b/tests/swift/hkdf-hardcoded-secret-swift-test.yml new file mode 100644 index 00000000..4eefa938 --- /dev/null +++ b/tests/swift/hkdf-hardcoded-secret-swift-test.yml @@ -0,0 +1,19 @@ +id: hkdf-hardcoded-secret-swift +valid: + - | + let key = try HKDF(password: password, salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate() +invalid: + - | + let password: Array = Array("s33krit".utf8) + let key = try HKDF(password: password, salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate() + - | + try HKDF(password: "123", salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate() + - | + let password = Array("s33krit".utf8) + let key = HKDF(password: password, salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate() + - | + HKDF(password: Array("hello".utf8), salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate() + - | + try HKDF(password: Array("hello".utf8), salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate() + - | + HKDF(password: "123", salt: salt, dkLen: 64, N: 16384, r: 8, p: 1).calculate() diff --git a/tests/swift/rabbit-hardcoded-secret-swift-test.yml b/tests/swift/rabbit-hardcoded-secret-swift-test.yml new file mode 100644 index 00000000..8eca3b6a --- /dev/null +++ b/tests/swift/rabbit-hardcoded-secret-swift-test.yml @@ -0,0 +1,19 @@ +id: rabbit-hardcoded-secret-swift +valid: + - | + +invalid: + - | + let password: Array = Array("s33krit".utf8) + try Rabbit(key: password, iv: "123") + - | + try Rabbit(key: "hello", iv: "123") + - | + let password = Array("s33krit".utf8) + Rabbit(key: password, iv: "123") + - | + Rabbit(key: Array("hello".utf8)); + - | + try Rabbit(key: Array("hello".utf8)); + - | + Rabbit(key: "hello", iv: "123")