diff --git a/unified/ql/lib/ext/legacy-swift.model.json b/unified/ql/lib/ext/legacy-swift.model.json index c8260c926b96..aeeaaba6bb9b 100644 --- a/unified/ql/lib/ext/legacy-swift.model.json +++ b/unified/ql/lib/ext/legacy-swift.model.json @@ -261,10 +261,10 @@ ["", "SHA384.Type", true, "hash(data:)", "", "", "Argument[data:]", "weak-password-hash-input-SHA384", "manual"], ["", "SHA384", true, "update(bufferPointer:)", "", "", "Argument[bufferPointer:]", "weak-password-hash-input-SHA384", "manual"], ["", "SHA384", true, "update(data:)", "", "", "Argument[data:]", "weak-password-hash-input-SHA384", "manual"], - ["", "SHA3", true, "callAsFunction(_:)", "", "", "Argument[0]", "weak-password-hash-input-SHA2", "manual"], - ["", "SHA3", true, "calculate(for:)", "", "", "Argument[for:]", "weak-password-hash-input-SHA2", "manual"], - ["", "SHA3", true, "process(block:currentHash:)", "", "", "Argument[block:]", "weak-password-hash-input-SHA2", "manual"], - ["", "SHA3", true, "update(withBytes:isLast?:)", "", "", "Argument[withBytes:]", "weak-password-hash-input-SHA2", "manual"], + ["", "SHA3", true, "callAsFunction(_:)", "", "", "Argument[0]", "weak-password-hash-input-SHA3", "manual"], + ["", "SHA3", true, "calculate(for:)", "", "", "Argument[for:]", "weak-password-hash-input-SHA3", "manual"], + ["", "SHA3", true, "process(block:currentHash:)", "", "", "Argument[block:]", "weak-password-hash-input-SHA3", "manual"], + ["", "SHA3", true, "update(withBytes:isLast?:)", "", "", "Argument[withBytes:]", "weak-password-hash-input-SHA3", "manual"], ["", "SHA512.Type", true, "hash(bufferPointer:)", "", "", "Argument[bufferPointer:]", "weak-password-hash-input-SHA512", "manual"], ["", "SHA512.Type", true, "hash(data:)", "", "", "Argument[data:]", "weak-password-hash-input-SHA512", "manual"], ["", "SHA512", true, "update(bufferPointer:)", "", "", "Argument[bufferPointer:]", "weak-password-hash-input-SHA512", "manual"], diff --git a/unified/ql/src/queries/security/CWE-328/WeakPasswordHashing.qhelp b/unified/ql/src/queries/security/CWE-328/WeakPasswordHashing.qhelp new file mode 100644 index 000000000000..390c5b12fa64 --- /dev/null +++ b/unified/ql/src/queries/security/CWE-328/WeakPasswordHashing.qhelp @@ -0,0 +1,95 @@ + + + +

+ Hash functions that are not sufficiently computationally hard can leave data vulnerable. You should not use such functions for password hashing. +

+ +

+ A strong cryptographic hash function should be resistant to: +

+ + +

+ All of MD5, SHA-1, SHA-2 and SHA-3 are weak against offline brute forcing, since they are not sufficiently computationally hard. This includes SHA-224, SHA-256, SHA-384 and SHA-512, which are in the SHA-2 family. +

+ +

+ Password hashing algorithms should be slow and/or memory intensive to compute, to make brute force attacks more difficult. +

+ +
+ + +

+ For password storage, you should use a sufficiently computationally hard cryptographic hash function, such as one of the following: +

+ + + +
+ + +

+ The following examples show two versions of the same function. In both cases, a password is hashed using a cryptographic hashing algorithm. + + In the first case, the SHA-512 hashing algorithm is used. It is vulnerable to offline brute force attacks: +

+ +

+ + Here is the same function using Argon2, which is suitable for password hashing: +

+ + +
+ +
  • + OWASP: + Password Storage + Cheat Sheet + +
  • +
  • + GitHub: CryptoSwift README - Password-Based Key Derivation Function +
  • +
  • + libsodium: libsodium bindings for other languages +
  • +
  • + GitHub: Argon2Swift +
  • +
    + +
    diff --git a/unified/ql/src/queries/security/CWE-328/WeakPasswordHashing.ql b/unified/ql/src/queries/security/CWE-328/WeakPasswordHashing.ql new file mode 100644 index 000000000000..295708c0c794 --- /dev/null +++ b/unified/ql/src/queries/security/CWE-328/WeakPasswordHashing.ql @@ -0,0 +1,79 @@ +/** + * @name Use of an inappropriate cryptographic hashing algorithm on passwords + * @description Using inappropriate cryptographic hashing algorithms with passwords can compromise security. + * @kind path-problem + * @problem.severity warning + * @security-severity 7.5 + * @precision high + * @id unified/swift/weak-password-hashing + * @tags security + * external/cwe/cwe-327 + * external/cwe/cwe-328 + * external/cwe/cwe-916 + */ + +import unified +import codeql.unified.security.SensitiveData + +/** + * Holds if `node` is a sink for weak password hashing using `algorithm`. + */ +private predicate isWeakPasswordHashingSink(DataFlow::Node node, string algorithm) { + exists(string kind | Models::isSink(node, kind) | + // match the following sinks: + // - `weak-hash-input-` (sinks that apply to both this query and `unified/swift/weak-sensitive-data-hashing`) + // - `weak-password-hash-input-` (sinks that apply to just this query) + algorithm = kind.regexpCapture("weak-(?:password-)?hash-input-(.+)", 1) + ) +} + +/** + * A taint tracking configuration from password expressions to inappropriate + * hashing sinks. + */ +module WeakPasswordHashingConfig implements DataFlow::ConfigSig { + predicate isSource(DataFlow::Node node) { + node.(SensitiveData).getClassification() = SensitiveDataClassification::password() + } + + predicate isSink(DataFlow::Node node) { isWeakPasswordHashingSink(node, _) } + + predicate isBarrier(DataFlow::Node node) { + // A barrier for weak password hashing, when it occurs inside of + // certain cryptographic algorithms as part of their design. + exists(ClassLikeDeclaration cls, string name | + node.asExpr().getParent+() = cls and + ( + name = cls.resolve().getName() + or + name = cls.getExtensionTarget().(Identifier).getValue() + ) and + name = ["HMAC", "PBKDF1", "PBKDF2"] + ) + } + + predicate isBarrierIn(DataFlow::Node node) { + // make sources barriers so that we only report the closest instance + isSource(node) + } + + predicate isBarrierOut(DataFlow::Node node) { + // make sinks barriers so that we only report the closest instance + isSink(node) + } + + predicate observeDiffInformedIncrementalMode() { any() } +} + +module WeakPasswordHashingFlow = TaintTracking::Global; + +import WeakPasswordHashingFlow::PathGraph + +from + WeakPasswordHashingFlow::PathNode source, WeakPasswordHashingFlow::PathNode sink, string algorithm +where + WeakPasswordHashingFlow::flowPath(source, sink) and + isWeakPasswordHashingSink(sink.getNode(), algorithm) +select sink.getNode(), source, sink, + "Insecure hashing algorithm (" + algorithm + ") depends on $@.", source.getNode(), + "password (" + source.getNode().toString() + ")" diff --git a/unified/ql/src/queries/security/CWE-328/WeakPasswordHashingBad.swift b/unified/ql/src/queries/security/CWE-328/WeakPasswordHashingBad.swift new file mode 100644 index 000000000000..572fe9fa3605 --- /dev/null +++ b/unified/ql/src/queries/security/CWE-328/WeakPasswordHashingBad.swift @@ -0,0 +1,8 @@ +let passwordData = Data(passwordString.utf8) +let passwordHash = Crypto.SHA512.hash(data: passwordData) // BAD: SHA-512 is not suitable for password hashing. + +// ... + +if Crypto.SHA512.hash(data: Data(passwordString.utf8)) == passwordHash { + // ... +} diff --git a/unified/ql/src/queries/security/CWE-328/WeakPasswordHashingGood.swift b/unified/ql/src/queries/security/CWE-328/WeakPasswordHashingGood.swift new file mode 100644 index 000000000000..ed2c8758674c --- /dev/null +++ b/unified/ql/src/queries/security/CWE-328/WeakPasswordHashingGood.swift @@ -0,0 +1,11 @@ +import Argon2Swift + +let salt = Salt.newSalt() +let result = try! Argon2Swift.hashPasswordString(password: passwordString, salt: salt) // GOOD: Argon2 is suitable for password hashing. +let passwordHash = result.encodedString() + +// ... + +if try! Argon2Swift.verifyHashString(password: passwordString, hash: passwordHash) { + // ... +} diff --git a/unified/ql/test/query-tests/security/CWE-328/WeakPasswordHashing.expected b/unified/ql/test/query-tests/security/CWE-328/WeakPasswordHashing.expected new file mode 100644 index 000000000000..b0483b35d6ee --- /dev/null +++ b/unified/ql/test/query-tests/security/CWE-328/WeakPasswordHashing.expected @@ -0,0 +1,262 @@ +#select +| testCryptoKit.swift:84:47:84:52 | passwd | testCryptoKit.swift:84:47:84:52 | passwd | testCryptoKit.swift:84:47:84:52 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:84:47:84:52 | passwd | password (passwd) | +| testCryptoKit.swift:84:47:84:52 | passwd | testCryptoKit.swift:84:47:84:52 | passwd | testCryptoKit.swift:84:47:84:52 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:84:47:84:52 | passwd | password (passwd) | +| testCryptoKit.swift:84:47:84:52 | passwd | testCryptoKit.swift:84:47:84:52 | passwd | testCryptoKit.swift:84:47:84:52 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:84:47:84:52 | passwd | password (passwd) | +| testCryptoKit.swift:84:47:84:52 | passwd | testCryptoKit.swift:84:47:84:52 | passwd | testCryptoKit.swift:84:47:84:52 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:84:47:84:52 | passwd | password (passwd) | +| testCryptoKit.swift:84:47:84:52 | passwd | testCryptoKit.swift:84:47:84:52 | passwd | testCryptoKit.swift:84:47:84:52 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:84:47:84:52 | passwd | password (passwd) | +| testCryptoKit.swift:85:52:85:57 | passwd | testCryptoKit.swift:85:52:85:57 | passwd | testCryptoKit.swift:85:52:85:57 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:85:52:85:57 | passwd | password (passwd) | +| testCryptoKit.swift:85:52:85:57 | passwd | testCryptoKit.swift:85:52:85:57 | passwd | testCryptoKit.swift:85:52:85:57 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:85:52:85:57 | passwd | password (passwd) | +| testCryptoKit.swift:85:52:85:57 | passwd | testCryptoKit.swift:85:52:85:57 | passwd | testCryptoKit.swift:85:52:85:57 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:85:52:85:57 | passwd | password (passwd) | +| testCryptoKit.swift:85:52:85:57 | passwd | testCryptoKit.swift:85:52:85:57 | passwd | testCryptoKit.swift:85:52:85:57 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:85:52:85:57 | passwd | password (passwd) | +| testCryptoKit.swift:85:52:85:57 | passwd | testCryptoKit.swift:85:52:85:57 | passwd | testCryptoKit.swift:85:52:85:57 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:85:52:85:57 | passwd | password (passwd) | +| testCryptoKit.swift:91:36:91:41 | passwd | testCryptoKit.swift:91:36:91:41 | passwd | testCryptoKit.swift:91:36:91:41 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:91:36:91:41 | passwd | password (passwd) | +| testCryptoKit.swift:91:36:91:41 | passwd | testCryptoKit.swift:91:36:91:41 | passwd | testCryptoKit.swift:91:36:91:41 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:91:36:91:41 | passwd | password (passwd) | +| testCryptoKit.swift:91:36:91:41 | passwd | testCryptoKit.swift:91:36:91:41 | passwd | testCryptoKit.swift:91:36:91:41 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:91:36:91:41 | passwd | password (passwd) | +| testCryptoKit.swift:91:36:91:41 | passwd | testCryptoKit.swift:91:36:91:41 | passwd | testCryptoKit.swift:91:36:91:41 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:91:36:91:41 | passwd | password (passwd) | +| testCryptoKit.swift:91:36:91:41 | passwd | testCryptoKit.swift:91:36:91:41 | passwd | testCryptoKit.swift:91:36:91:41 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:91:36:91:41 | passwd | password (passwd) | +| testCryptoKit.swift:92:45:92:50 | passwd | testCryptoKit.swift:92:45:92:50 | passwd | testCryptoKit.swift:92:45:92:50 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:92:45:92:50 | passwd | password (passwd) | +| testCryptoKit.swift:92:45:92:50 | passwd | testCryptoKit.swift:92:45:92:50 | passwd | testCryptoKit.swift:92:45:92:50 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:92:45:92:50 | passwd | password (passwd) | +| testCryptoKit.swift:92:45:92:50 | passwd | testCryptoKit.swift:92:45:92:50 | passwd | testCryptoKit.swift:92:45:92:50 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:92:45:92:50 | passwd | password (passwd) | +| testCryptoKit.swift:92:45:92:50 | passwd | testCryptoKit.swift:92:45:92:50 | passwd | testCryptoKit.swift:92:45:92:50 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:92:45:92:50 | passwd | password (passwd) | +| testCryptoKit.swift:92:45:92:50 | passwd | testCryptoKit.swift:92:45:92:50 | passwd | testCryptoKit.swift:92:45:92:50 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:92:45:92:50 | passwd | password (passwd) | +| testCryptoKit.swift:98:44:98:49 | passwd | testCryptoKit.swift:98:44:98:49 | passwd | testCryptoKit.swift:98:44:98:49 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:98:44:98:49 | passwd | password (passwd) | +| testCryptoKit.swift:98:44:98:49 | passwd | testCryptoKit.swift:98:44:98:49 | passwd | testCryptoKit.swift:98:44:98:49 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:98:44:98:49 | passwd | password (passwd) | +| testCryptoKit.swift:98:44:98:49 | passwd | testCryptoKit.swift:98:44:98:49 | passwd | testCryptoKit.swift:98:44:98:49 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:98:44:98:49 | passwd | password (passwd) | +| testCryptoKit.swift:98:44:98:49 | passwd | testCryptoKit.swift:98:44:98:49 | passwd | testCryptoKit.swift:98:44:98:49 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:98:44:98:49 | passwd | password (passwd) | +| testCryptoKit.swift:98:44:98:49 | passwd | testCryptoKit.swift:98:44:98:49 | passwd | testCryptoKit.swift:98:44:98:49 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:98:44:98:49 | passwd | password (passwd) | +| testCryptoKit.swift:99:53:99:58 | passwd | testCryptoKit.swift:99:53:99:58 | passwd | testCryptoKit.swift:99:53:99:58 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:99:53:99:58 | passwd | password (passwd) | +| testCryptoKit.swift:99:53:99:58 | passwd | testCryptoKit.swift:99:53:99:58 | passwd | testCryptoKit.swift:99:53:99:58 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:99:53:99:58 | passwd | password (passwd) | +| testCryptoKit.swift:99:53:99:58 | passwd | testCryptoKit.swift:99:53:99:58 | passwd | testCryptoKit.swift:99:53:99:58 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:99:53:99:58 | passwd | password (passwd) | +| testCryptoKit.swift:99:53:99:58 | passwd | testCryptoKit.swift:99:53:99:58 | passwd | testCryptoKit.swift:99:53:99:58 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:99:53:99:58 | passwd | password (passwd) | +| testCryptoKit.swift:99:53:99:58 | passwd | testCryptoKit.swift:99:53:99:58 | passwd | testCryptoKit.swift:99:53:99:58 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:99:53:99:58 | passwd | password (passwd) | +| testCryptoKit.swift:105:37:105:42 | passwd | testCryptoKit.swift:105:37:105:42 | passwd | testCryptoKit.swift:105:37:105:42 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:105:37:105:42 | passwd | password (passwd) | +| testCryptoKit.swift:105:37:105:42 | passwd | testCryptoKit.swift:105:37:105:42 | passwd | testCryptoKit.swift:105:37:105:42 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:105:37:105:42 | passwd | password (passwd) | +| testCryptoKit.swift:105:37:105:42 | passwd | testCryptoKit.swift:105:37:105:42 | passwd | testCryptoKit.swift:105:37:105:42 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:105:37:105:42 | passwd | password (passwd) | +| testCryptoKit.swift:105:37:105:42 | passwd | testCryptoKit.swift:105:37:105:42 | passwd | testCryptoKit.swift:105:37:105:42 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:105:37:105:42 | passwd | password (passwd) | +| testCryptoKit.swift:105:37:105:42 | passwd | testCryptoKit.swift:105:37:105:42 | passwd | testCryptoKit.swift:105:37:105:42 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:105:37:105:42 | passwd | password (passwd) | +| testCryptoKit.swift:106:46:106:51 | passwd | testCryptoKit.swift:106:46:106:51 | passwd | testCryptoKit.swift:106:46:106:51 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:106:46:106:51 | passwd | password (passwd) | +| testCryptoKit.swift:106:46:106:51 | passwd | testCryptoKit.swift:106:46:106:51 | passwd | testCryptoKit.swift:106:46:106:51 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:106:46:106:51 | passwd | password (passwd) | +| testCryptoKit.swift:106:46:106:51 | passwd | testCryptoKit.swift:106:46:106:51 | passwd | testCryptoKit.swift:106:46:106:51 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:106:46:106:51 | passwd | password (passwd) | +| testCryptoKit.swift:106:46:106:51 | passwd | testCryptoKit.swift:106:46:106:51 | passwd | testCryptoKit.swift:106:46:106:51 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:106:46:106:51 | passwd | password (passwd) | +| testCryptoKit.swift:106:46:106:51 | passwd | testCryptoKit.swift:106:46:106:51 | passwd | testCryptoKit.swift:106:46:106:51 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:106:46:106:51 | passwd | password (passwd) | +| testCryptoKit.swift:112:37:112:42 | passwd | testCryptoKit.swift:112:37:112:42 | passwd | testCryptoKit.swift:112:37:112:42 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:112:37:112:42 | passwd | password (passwd) | +| testCryptoKit.swift:112:37:112:42 | passwd | testCryptoKit.swift:112:37:112:42 | passwd | testCryptoKit.swift:112:37:112:42 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:112:37:112:42 | passwd | password (passwd) | +| testCryptoKit.swift:112:37:112:42 | passwd | testCryptoKit.swift:112:37:112:42 | passwd | testCryptoKit.swift:112:37:112:42 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:112:37:112:42 | passwd | password (passwd) | +| testCryptoKit.swift:112:37:112:42 | passwd | testCryptoKit.swift:112:37:112:42 | passwd | testCryptoKit.swift:112:37:112:42 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:112:37:112:42 | passwd | password (passwd) | +| testCryptoKit.swift:112:37:112:42 | passwd | testCryptoKit.swift:112:37:112:42 | passwd | testCryptoKit.swift:112:37:112:42 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:112:37:112:42 | passwd | password (passwd) | +| testCryptoKit.swift:113:46:113:51 | passwd | testCryptoKit.swift:113:46:113:51 | passwd | testCryptoKit.swift:113:46:113:51 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:113:46:113:51 | passwd | password (passwd) | +| testCryptoKit.swift:113:46:113:51 | passwd | testCryptoKit.swift:113:46:113:51 | passwd | testCryptoKit.swift:113:46:113:51 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:113:46:113:51 | passwd | password (passwd) | +| testCryptoKit.swift:113:46:113:51 | passwd | testCryptoKit.swift:113:46:113:51 | passwd | testCryptoKit.swift:113:46:113:51 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:113:46:113:51 | passwd | password (passwd) | +| testCryptoKit.swift:113:46:113:51 | passwd | testCryptoKit.swift:113:46:113:51 | passwd | testCryptoKit.swift:113:46:113:51 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:113:46:113:51 | passwd | password (passwd) | +| testCryptoKit.swift:113:46:113:51 | passwd | testCryptoKit.swift:113:46:113:51 | passwd | testCryptoKit.swift:113:46:113:51 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:113:46:113:51 | passwd | password (passwd) | +| testCryptoKit.swift:119:37:119:42 | passwd | testCryptoKit.swift:119:37:119:42 | passwd | testCryptoKit.swift:119:37:119:42 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:119:37:119:42 | passwd | password (passwd) | +| testCryptoKit.swift:119:37:119:42 | passwd | testCryptoKit.swift:119:37:119:42 | passwd | testCryptoKit.swift:119:37:119:42 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:119:37:119:42 | passwd | password (passwd) | +| testCryptoKit.swift:119:37:119:42 | passwd | testCryptoKit.swift:119:37:119:42 | passwd | testCryptoKit.swift:119:37:119:42 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:119:37:119:42 | passwd | password (passwd) | +| testCryptoKit.swift:119:37:119:42 | passwd | testCryptoKit.swift:119:37:119:42 | passwd | testCryptoKit.swift:119:37:119:42 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:119:37:119:42 | passwd | password (passwd) | +| testCryptoKit.swift:119:37:119:42 | passwd | testCryptoKit.swift:119:37:119:42 | passwd | testCryptoKit.swift:119:37:119:42 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:119:37:119:42 | passwd | password (passwd) | +| testCryptoKit.swift:120:46:120:51 | passwd | testCryptoKit.swift:120:46:120:51 | passwd | testCryptoKit.swift:120:46:120:51 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:120:46:120:51 | passwd | password (passwd) | +| testCryptoKit.swift:120:46:120:51 | passwd | testCryptoKit.swift:120:46:120:51 | passwd | testCryptoKit.swift:120:46:120:51 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:120:46:120:51 | passwd | password (passwd) | +| testCryptoKit.swift:120:46:120:51 | passwd | testCryptoKit.swift:120:46:120:51 | passwd | testCryptoKit.swift:120:46:120:51 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:120:46:120:51 | passwd | password (passwd) | +| testCryptoKit.swift:120:46:120:51 | passwd | testCryptoKit.swift:120:46:120:51 | passwd | testCryptoKit.swift:120:46:120:51 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:120:46:120:51 | passwd | password (passwd) | +| testCryptoKit.swift:120:46:120:51 | passwd | testCryptoKit.swift:120:46:120:51 | passwd | testCryptoKit.swift:120:46:120:51 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:120:46:120:51 | passwd | password (passwd) | +| testCryptoKit.swift:129:23:129:28 | passwd | testCryptoKit.swift:129:23:129:28 | passwd | testCryptoKit.swift:129:23:129:28 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:129:23:129:28 | passwd | password (passwd) | +| testCryptoKit.swift:129:23:129:28 | passwd | testCryptoKit.swift:129:23:129:28 | passwd | testCryptoKit.swift:129:23:129:28 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:129:23:129:28 | passwd | password (passwd) | +| testCryptoKit.swift:129:23:129:28 | passwd | testCryptoKit.swift:129:23:129:28 | passwd | testCryptoKit.swift:129:23:129:28 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:129:23:129:28 | passwd | password (passwd) | +| testCryptoKit.swift:129:23:129:28 | passwd | testCryptoKit.swift:129:23:129:28 | passwd | testCryptoKit.swift:129:23:129:28 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:129:23:129:28 | passwd | password (passwd) | +| testCryptoKit.swift:129:23:129:28 | passwd | testCryptoKit.swift:129:23:129:28 | passwd | testCryptoKit.swift:129:23:129:28 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:129:23:129:28 | passwd | password (passwd) | +| testCryptoKit.swift:138:23:138:28 | passwd | testCryptoKit.swift:138:23:138:28 | passwd | testCryptoKit.swift:138:23:138:28 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:138:23:138:28 | passwd | password (passwd) | +| testCryptoKit.swift:138:23:138:28 | passwd | testCryptoKit.swift:138:23:138:28 | passwd | testCryptoKit.swift:138:23:138:28 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:138:23:138:28 | passwd | password (passwd) | +| testCryptoKit.swift:138:23:138:28 | passwd | testCryptoKit.swift:138:23:138:28 | passwd | testCryptoKit.swift:138:23:138:28 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:138:23:138:28 | passwd | password (passwd) | +| testCryptoKit.swift:138:23:138:28 | passwd | testCryptoKit.swift:138:23:138:28 | passwd | testCryptoKit.swift:138:23:138:28 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:138:23:138:28 | passwd | password (passwd) | +| testCryptoKit.swift:138:23:138:28 | passwd | testCryptoKit.swift:138:23:138:28 | passwd | testCryptoKit.swift:138:23:138:28 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:138:23:138:28 | passwd | password (passwd) | +| testCryptoKit.swift:147:23:147:28 | passwd | testCryptoKit.swift:147:23:147:28 | passwd | testCryptoKit.swift:147:23:147:28 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:147:23:147:28 | passwd | password (passwd) | +| testCryptoKit.swift:147:23:147:28 | passwd | testCryptoKit.swift:147:23:147:28 | passwd | testCryptoKit.swift:147:23:147:28 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:147:23:147:28 | passwd | password (passwd) | +| testCryptoKit.swift:147:23:147:28 | passwd | testCryptoKit.swift:147:23:147:28 | passwd | testCryptoKit.swift:147:23:147:28 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:147:23:147:28 | passwd | password (passwd) | +| testCryptoKit.swift:147:23:147:28 | passwd | testCryptoKit.swift:147:23:147:28 | passwd | testCryptoKit.swift:147:23:147:28 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:147:23:147:28 | passwd | password (passwd) | +| testCryptoKit.swift:147:23:147:28 | passwd | testCryptoKit.swift:147:23:147:28 | passwd | testCryptoKit.swift:147:23:147:28 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:147:23:147:28 | passwd | password (passwd) | +| testCryptoKit.swift:156:23:156:28 | passwd | testCryptoKit.swift:156:23:156:28 | passwd | testCryptoKit.swift:156:23:156:28 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:156:23:156:28 | passwd | password (passwd) | +| testCryptoKit.swift:156:23:156:28 | passwd | testCryptoKit.swift:156:23:156:28 | passwd | testCryptoKit.swift:156:23:156:28 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:156:23:156:28 | passwd | password (passwd) | +| testCryptoKit.swift:156:23:156:28 | passwd | testCryptoKit.swift:156:23:156:28 | passwd | testCryptoKit.swift:156:23:156:28 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:156:23:156:28 | passwd | password (passwd) | +| testCryptoKit.swift:156:23:156:28 | passwd | testCryptoKit.swift:156:23:156:28 | passwd | testCryptoKit.swift:156:23:156:28 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:156:23:156:28 | passwd | password (passwd) | +| testCryptoKit.swift:156:23:156:28 | passwd | testCryptoKit.swift:156:23:156:28 | passwd | testCryptoKit.swift:156:23:156:28 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:156:23:156:28 | passwd | password (passwd) | +| testCryptoKit.swift:165:23:165:28 | passwd | testCryptoKit.swift:165:23:165:28 | passwd | testCryptoKit.swift:165:23:165:28 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:165:23:165:28 | passwd | password (passwd) | +| testCryptoKit.swift:165:23:165:28 | passwd | testCryptoKit.swift:165:23:165:28 | passwd | testCryptoKit.swift:165:23:165:28 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:165:23:165:28 | passwd | password (passwd) | +| testCryptoKit.swift:165:23:165:28 | passwd | testCryptoKit.swift:165:23:165:28 | passwd | testCryptoKit.swift:165:23:165:28 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:165:23:165:28 | passwd | password (passwd) | +| testCryptoKit.swift:165:23:165:28 | passwd | testCryptoKit.swift:165:23:165:28 | passwd | testCryptoKit.swift:165:23:165:28 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:165:23:165:28 | passwd | password (passwd) | +| testCryptoKit.swift:165:23:165:28 | passwd | testCryptoKit.swift:165:23:165:28 | passwd | testCryptoKit.swift:165:23:165:28 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:165:23:165:28 | passwd | password (passwd) | +| testCryptoKit.swift:174:32:174:37 | passwd | testCryptoKit.swift:174:32:174:37 | passwd | testCryptoKit.swift:174:32:174:37 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:174:32:174:37 | passwd | password (passwd) | +| testCryptoKit.swift:174:32:174:37 | passwd | testCryptoKit.swift:174:32:174:37 | passwd | testCryptoKit.swift:174:32:174:37 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:174:32:174:37 | passwd | password (passwd) | +| testCryptoKit.swift:174:32:174:37 | passwd | testCryptoKit.swift:174:32:174:37 | passwd | testCryptoKit.swift:174:32:174:37 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:174:32:174:37 | passwd | password (passwd) | +| testCryptoKit.swift:174:32:174:37 | passwd | testCryptoKit.swift:174:32:174:37 | passwd | testCryptoKit.swift:174:32:174:37 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:174:32:174:37 | passwd | password (passwd) | +| testCryptoKit.swift:174:32:174:37 | passwd | testCryptoKit.swift:174:32:174:37 | passwd | testCryptoKit.swift:174:32:174:37 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:174:32:174:37 | passwd | password (passwd) | +| testCryptoKit.swift:183:32:183:37 | passwd | testCryptoKit.swift:183:32:183:37 | passwd | testCryptoKit.swift:183:32:183:37 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:183:32:183:37 | passwd | password (passwd) | +| testCryptoKit.swift:183:32:183:37 | passwd | testCryptoKit.swift:183:32:183:37 | passwd | testCryptoKit.swift:183:32:183:37 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:183:32:183:37 | passwd | password (passwd) | +| testCryptoKit.swift:183:32:183:37 | passwd | testCryptoKit.swift:183:32:183:37 | passwd | testCryptoKit.swift:183:32:183:37 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:183:32:183:37 | passwd | password (passwd) | +| testCryptoKit.swift:183:32:183:37 | passwd | testCryptoKit.swift:183:32:183:37 | passwd | testCryptoKit.swift:183:32:183:37 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:183:32:183:37 | passwd | password (passwd) | +| testCryptoKit.swift:183:32:183:37 | passwd | testCryptoKit.swift:183:32:183:37 | passwd | testCryptoKit.swift:183:32:183:37 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:183:32:183:37 | passwd | password (passwd) | +| testCryptoKit.swift:192:32:192:37 | passwd | testCryptoKit.swift:192:32:192:37 | passwd | testCryptoKit.swift:192:32:192:37 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:192:32:192:37 | passwd | password (passwd) | +| testCryptoKit.swift:192:32:192:37 | passwd | testCryptoKit.swift:192:32:192:37 | passwd | testCryptoKit.swift:192:32:192:37 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:192:32:192:37 | passwd | password (passwd) | +| testCryptoKit.swift:192:32:192:37 | passwd | testCryptoKit.swift:192:32:192:37 | passwd | testCryptoKit.swift:192:32:192:37 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:192:32:192:37 | passwd | password (passwd) | +| testCryptoKit.swift:192:32:192:37 | passwd | testCryptoKit.swift:192:32:192:37 | passwd | testCryptoKit.swift:192:32:192:37 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:192:32:192:37 | passwd | password (passwd) | +| testCryptoKit.swift:192:32:192:37 | passwd | testCryptoKit.swift:192:32:192:37 | passwd | testCryptoKit.swift:192:32:192:37 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:192:32:192:37 | passwd | password (passwd) | +| testCryptoKit.swift:201:32:201:37 | passwd | testCryptoKit.swift:201:32:201:37 | passwd | testCryptoKit.swift:201:32:201:37 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:201:32:201:37 | passwd | password (passwd) | +| testCryptoKit.swift:201:32:201:37 | passwd | testCryptoKit.swift:201:32:201:37 | passwd | testCryptoKit.swift:201:32:201:37 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:201:32:201:37 | passwd | password (passwd) | +| testCryptoKit.swift:201:32:201:37 | passwd | testCryptoKit.swift:201:32:201:37 | passwd | testCryptoKit.swift:201:32:201:37 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:201:32:201:37 | passwd | password (passwd) | +| testCryptoKit.swift:201:32:201:37 | passwd | testCryptoKit.swift:201:32:201:37 | passwd | testCryptoKit.swift:201:32:201:37 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:201:32:201:37 | passwd | password (passwd) | +| testCryptoKit.swift:201:32:201:37 | passwd | testCryptoKit.swift:201:32:201:37 | passwd | testCryptoKit.swift:201:32:201:37 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:201:32:201:37 | passwd | password (passwd) | +| testCryptoKit.swift:210:32:210:37 | passwd | testCryptoKit.swift:210:32:210:37 | passwd | testCryptoKit.swift:210:32:210:37 | passwd | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:210:32:210:37 | passwd | password (passwd) | +| testCryptoKit.swift:210:32:210:37 | passwd | testCryptoKit.swift:210:32:210:37 | passwd | testCryptoKit.swift:210:32:210:37 | passwd | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:210:32:210:37 | passwd | password (passwd) | +| testCryptoKit.swift:210:32:210:37 | passwd | testCryptoKit.swift:210:32:210:37 | passwd | testCryptoKit.swift:210:32:210:37 | passwd | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:210:32:210:37 | passwd | password (passwd) | +| testCryptoKit.swift:210:32:210:37 | passwd | testCryptoKit.swift:210:32:210:37 | passwd | testCryptoKit.swift:210:32:210:37 | passwd | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:210:32:210:37 | passwd | password (passwd) | +| testCryptoKit.swift:210:32:210:37 | passwd | testCryptoKit.swift:210:32:210:37 | passwd | testCryptoKit.swift:210:32:210:37 | passwd | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:210:32:210:37 | passwd | password (passwd) | +| testCryptoKit.swift:220:49:220:60 | passwordData | testCryptoKit.swift:220:49:220:60 | passwordData | testCryptoKit.swift:220:49:220:60 | passwordData | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:220:49:220:60 | passwordData | password (passwordData) | +| testCryptoKit.swift:220:49:220:60 | passwordData | testCryptoKit.swift:220:49:220:60 | passwordData | testCryptoKit.swift:220:49:220:60 | passwordData | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:220:49:220:60 | passwordData | password (passwordData) | +| testCryptoKit.swift:220:49:220:60 | passwordData | testCryptoKit.swift:220:49:220:60 | passwordData | testCryptoKit.swift:220:49:220:60 | passwordData | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:220:49:220:60 | passwordData | password (passwordData) | +| testCryptoKit.swift:220:49:220:60 | passwordData | testCryptoKit.swift:220:49:220:60 | passwordData | testCryptoKit.swift:220:49:220:60 | passwordData | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:220:49:220:60 | passwordData | password (passwordData) | +| testCryptoKit.swift:220:49:220:60 | passwordData | testCryptoKit.swift:220:49:220:60 | passwordData | testCryptoKit.swift:220:49:220:60 | passwordData | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:220:49:220:60 | passwordData | password (passwordData) | +| testCryptoKit.swift:224:33:224:57 | Data(...) | testCryptoKit.swift:224:38:224:51 | passwordString | testCryptoKit.swift:224:33:224:57 | Data(...) | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:224:38:224:51 | passwordString | password (passwordString) | +| testCryptoKit.swift:224:33:224:57 | Data(...) | testCryptoKit.swift:224:38:224:51 | passwordString | testCryptoKit.swift:224:33:224:57 | Data(...) | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:224:38:224:51 | passwordString | password (passwordString) | +| testCryptoKit.swift:224:33:224:57 | Data(...) | testCryptoKit.swift:224:38:224:51 | passwordString | testCryptoKit.swift:224:33:224:57 | Data(...) | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:224:38:224:51 | passwordString | password (passwordString) | +| testCryptoKit.swift:224:33:224:57 | Data(...) | testCryptoKit.swift:224:38:224:51 | passwordString | testCryptoKit.swift:224:33:224:57 | Data(...) | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:224:38:224:51 | passwordString | password (passwordString) | +| testCryptoKit.swift:224:33:224:57 | Data(...) | testCryptoKit.swift:224:38:224:51 | passwordString | testCryptoKit.swift:224:33:224:57 | Data(...) | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:224:38:224:51 | passwordString | password (passwordString) | +| testCryptoKit.swift:251:39:251:44 | value7 | testCryptoKit.swift:249:23:249:36 | passwordString | testCryptoKit.swift:251:39:251:44 | value7 | Insecure hashing algorithm (MD5) depends on $@. | testCryptoKit.swift:249:23:249:36 | passwordString | password (passwordString) | +| testCryptoKit.swift:251:39:251:44 | value7 | testCryptoKit.swift:249:23:249:36 | passwordString | testCryptoKit.swift:251:39:251:44 | value7 | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoKit.swift:249:23:249:36 | passwordString | password (passwordString) | +| testCryptoKit.swift:251:39:251:44 | value7 | testCryptoKit.swift:249:23:249:36 | passwordString | testCryptoKit.swift:251:39:251:44 | value7 | Insecure hashing algorithm (SHA256) depends on $@. | testCryptoKit.swift:249:23:249:36 | passwordString | password (passwordString) | +| testCryptoKit.swift:251:39:251:44 | value7 | testCryptoKit.swift:249:23:249:36 | passwordString | testCryptoKit.swift:251:39:251:44 | value7 | Insecure hashing algorithm (SHA384) depends on $@. | testCryptoKit.swift:249:23:249:36 | passwordString | password (passwordString) | +| testCryptoKit.swift:251:39:251:44 | value7 | testCryptoKit.swift:249:23:249:36 | passwordString | testCryptoKit.swift:251:39:251:44 | value7 | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoKit.swift:249:23:249:36 | passwordString | password (passwordString) | +| testCryptoSwift.swift:154:30:154:40 | passwdArray | testCryptoSwift.swift:154:30:154:40 | passwdArray | testCryptoSwift.swift:154:30:154:40 | passwdArray | Insecure hashing algorithm (MD5) depends on $@. | testCryptoSwift.swift:154:30:154:40 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:154:30:154:40 | passwdArray | testCryptoSwift.swift:154:30:154:40 | passwdArray | testCryptoSwift.swift:154:30:154:40 | passwdArray | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoSwift.swift:154:30:154:40 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:154:30:154:40 | passwdArray | testCryptoSwift.swift:154:30:154:40 | passwdArray | testCryptoSwift.swift:154:30:154:40 | passwdArray | Insecure hashing algorithm (SHA2) depends on $@. | testCryptoSwift.swift:154:30:154:40 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:154:30:154:40 | passwdArray | testCryptoSwift.swift:154:30:154:40 | passwdArray | testCryptoSwift.swift:154:30:154:40 | passwdArray | Insecure hashing algorithm (SHA3) depends on $@. | testCryptoSwift.swift:154:30:154:40 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:157:31:157:41 | passwdArray | testCryptoSwift.swift:157:31:157:41 | passwdArray | testCryptoSwift.swift:157:31:157:41 | passwdArray | Insecure hashing algorithm (MD5) depends on $@. | testCryptoSwift.swift:157:31:157:41 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:157:31:157:41 | passwdArray | testCryptoSwift.swift:157:31:157:41 | passwdArray | testCryptoSwift.swift:157:31:157:41 | passwdArray | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoSwift.swift:157:31:157:41 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:157:31:157:41 | passwdArray | testCryptoSwift.swift:157:31:157:41 | passwdArray | testCryptoSwift.swift:157:31:157:41 | passwdArray | Insecure hashing algorithm (SHA2) depends on $@. | testCryptoSwift.swift:157:31:157:41 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:157:31:157:41 | passwdArray | testCryptoSwift.swift:157:31:157:41 | passwdArray | testCryptoSwift.swift:157:31:157:41 | passwdArray | Insecure hashing algorithm (SHA3) depends on $@. | testCryptoSwift.swift:157:31:157:41 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:160:47:160:57 | passwdArray | testCryptoSwift.swift:160:47:160:57 | passwdArray | testCryptoSwift.swift:160:47:160:57 | passwdArray | Insecure hashing algorithm (MD5) depends on $@. | testCryptoSwift.swift:160:47:160:57 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:160:47:160:57 | passwdArray | testCryptoSwift.swift:160:47:160:57 | passwdArray | testCryptoSwift.swift:160:47:160:57 | passwdArray | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoSwift.swift:160:47:160:57 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:160:47:160:57 | passwdArray | testCryptoSwift.swift:160:47:160:57 | passwdArray | testCryptoSwift.swift:160:47:160:57 | passwdArray | Insecure hashing algorithm (SHA2) depends on $@. | testCryptoSwift.swift:160:47:160:57 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:160:47:160:57 | passwdArray | testCryptoSwift.swift:160:47:160:57 | passwdArray | testCryptoSwift.swift:160:47:160:57 | passwdArray | Insecure hashing algorithm (SHA3) depends on $@. | testCryptoSwift.swift:160:47:160:57 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:163:47:163:57 | passwdArray | testCryptoSwift.swift:163:47:163:57 | passwdArray | testCryptoSwift.swift:163:47:163:57 | passwdArray | Insecure hashing algorithm (MD5) depends on $@. | testCryptoSwift.swift:163:47:163:57 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:163:47:163:57 | passwdArray | testCryptoSwift.swift:163:47:163:57 | passwdArray | testCryptoSwift.swift:163:47:163:57 | passwdArray | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoSwift.swift:163:47:163:57 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:163:47:163:57 | passwdArray | testCryptoSwift.swift:163:47:163:57 | passwdArray | testCryptoSwift.swift:163:47:163:57 | passwdArray | Insecure hashing algorithm (SHA2) depends on $@. | testCryptoSwift.swift:163:47:163:57 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:163:47:163:57 | passwdArray | testCryptoSwift.swift:163:47:163:57 | passwdArray | testCryptoSwift.swift:163:47:163:57 | passwdArray | Insecure hashing algorithm (SHA3) depends on $@. | testCryptoSwift.swift:163:47:163:57 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:167:20:167:30 | passwdArray | testCryptoSwift.swift:167:20:167:30 | passwdArray | testCryptoSwift.swift:167:20:167:30 | passwdArray | Insecure hashing algorithm (MD5) depends on $@. | testCryptoSwift.swift:167:20:167:30 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:170:21:170:31 | passwdArray | testCryptoSwift.swift:170:21:170:31 | passwdArray | testCryptoSwift.swift:170:21:170:31 | passwdArray | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoSwift.swift:170:21:170:31 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:173:23:173:33 | passwdArray | testCryptoSwift.swift:173:23:173:33 | passwdArray | testCryptoSwift.swift:173:23:173:33 | passwdArray | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoSwift.swift:173:23:173:33 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:176:21:176:31 | passwdArray | testCryptoSwift.swift:176:21:176:31 | passwdArray | testCryptoSwift.swift:176:21:176:31 | passwdArray | Insecure hashing algorithm (SHA2) depends on $@. | testCryptoSwift.swift:176:21:176:31 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:179:21:179:31 | passwdArray | testCryptoSwift.swift:179:21:179:31 | passwdArray | testCryptoSwift.swift:179:21:179:31 | passwdArray | Insecure hashing algorithm (SHA3) depends on $@. | testCryptoSwift.swift:179:21:179:31 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:183:9:183:25 | [self arg] ... .md5(...) | testCryptoSwift.swift:183:9:183:19 | passwdArray | testCryptoSwift.swift:183:9:183:25 | [self arg] ... .md5(...) | Insecure hashing algorithm (MD5) depends on $@. | testCryptoSwift.swift:183:9:183:19 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:186:9:186:26 | [self arg] ... .sha1(...) | testCryptoSwift.swift:186:9:186:19 | passwdArray | testCryptoSwift.swift:186:9:186:26 | [self arg] ... .sha1(...) | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoSwift.swift:186:9:186:19 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:189:9:189:28 | [self arg] ... .sha512(...) | testCryptoSwift.swift:189:9:189:19 | passwdArray | testCryptoSwift.swift:189:9:189:28 | [self arg] ... .sha512(...) | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoSwift.swift:189:9:189:19 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:192:9:192:33 | [self arg] ... .sha2(...) | testCryptoSwift.swift:192:9:192:19 | passwdArray | testCryptoSwift.swift:192:9:192:33 | [self arg] ... .sha2(...) | Insecure hashing algorithm (SHA2) depends on $@. | testCryptoSwift.swift:192:9:192:19 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:195:9:195:33 | [self arg] ... .sha3(...) | testCryptoSwift.swift:195:9:195:19 | passwdArray | testCryptoSwift.swift:195:9:195:33 | [self arg] ... .sha3(...) | Insecure hashing algorithm (SHA3) depends on $@. | testCryptoSwift.swift:195:9:195:19 | passwdArray | password (passwdArray) | +| testCryptoSwift.swift:201:9:201:24 | [self arg] ... .md5(...) | testCryptoSwift.swift:201:9:201:18 | passwdData | testCryptoSwift.swift:201:9:201:24 | [self arg] ... .md5(...) | Insecure hashing algorithm (MD5) depends on $@. | testCryptoSwift.swift:201:9:201:18 | passwdData | password (passwdData) | +| testCryptoSwift.swift:204:9:204:25 | [self arg] ... .sha1(...) | testCryptoSwift.swift:204:9:204:18 | passwdData | testCryptoSwift.swift:204:9:204:25 | [self arg] ... .sha1(...) | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoSwift.swift:204:9:204:18 | passwdData | password (passwdData) | +| testCryptoSwift.swift:207:9:207:27 | [self arg] ... .sha512(...) | testCryptoSwift.swift:207:9:207:18 | passwdData | testCryptoSwift.swift:207:9:207:27 | [self arg] ... .sha512(...) | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoSwift.swift:207:9:207:18 | passwdData | password (passwdData) | +| testCryptoSwift.swift:210:9:210:32 | [self arg] ... .sha2(...) | testCryptoSwift.swift:210:9:210:18 | passwdData | testCryptoSwift.swift:210:9:210:32 | [self arg] ... .sha2(...) | Insecure hashing algorithm (SHA2) depends on $@. | testCryptoSwift.swift:210:9:210:18 | passwdData | password (passwdData) | +| testCryptoSwift.swift:213:9:213:32 | [self arg] ... .sha3(...) | testCryptoSwift.swift:213:9:213:18 | passwdData | testCryptoSwift.swift:213:9:213:32 | [self arg] ... .sha3(...) | Insecure hashing algorithm (SHA3) depends on $@. | testCryptoSwift.swift:213:9:213:18 | passwdData | password (passwdData) | +| testCryptoSwift.swift:219:9:219:20 | [self arg] ... .md5(...) | testCryptoSwift.swift:219:9:219:14 | passwd | testCryptoSwift.swift:219:9:219:20 | [self arg] ... .md5(...) | Insecure hashing algorithm (MD5) depends on $@. | testCryptoSwift.swift:219:9:219:14 | passwd | password (passwd) | +| testCryptoSwift.swift:222:9:222:21 | [self arg] ... .sha1(...) | testCryptoSwift.swift:222:9:222:14 | passwd | testCryptoSwift.swift:222:9:222:21 | [self arg] ... .sha1(...) | Insecure hashing algorithm (SHA1) depends on $@. | testCryptoSwift.swift:222:9:222:14 | passwd | password (passwd) | +| testCryptoSwift.swift:225:9:225:23 | [self arg] ... .sha512(...) | testCryptoSwift.swift:225:9:225:14 | passwd | testCryptoSwift.swift:225:9:225:23 | [self arg] ... .sha512(...) | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoSwift.swift:225:9:225:14 | passwd | password (passwd) | +| testCryptoSwift.swift:228:9:228:28 | [self arg] ... .sha2(...) | testCryptoSwift.swift:228:9:228:14 | passwd | testCryptoSwift.swift:228:9:228:28 | [self arg] ... .sha2(...) | Insecure hashing algorithm (SHA2) depends on $@. | testCryptoSwift.swift:228:9:228:14 | passwd | password (passwd) | +| testCryptoSwift.swift:231:9:231:28 | [self arg] ... .sha3(...) | testCryptoSwift.swift:231:9:231:14 | passwd | testCryptoSwift.swift:231:9:231:28 | [self arg] ... .sha3(...) | Insecure hashing algorithm (SHA3) depends on $@. | testCryptoSwift.swift:231:9:231:14 | passwd | password (passwd) | +| testCryptoSwift.swift:248:30:248:34 | bytes | testCryptoSwift.swift:255:36:255:46 | passwdArray | testCryptoSwift.swift:248:30:248:34 | bytes | Insecure hashing algorithm (SHA512) depends on $@. | testCryptoSwift.swift:255:36:255:46 | passwdArray | password (passwdArray) | +edges +| testCryptoKit.swift:224:38:224:51 | passwordString | testCryptoKit.swift:224:38:224:56 | ... .utf8 | provenance | | +| testCryptoKit.swift:224:38:224:56 | ... .utf8 | testCryptoKit.swift:224:33:224:57 | Data(...) | provenance | | +| testCryptoKit.swift:249:9:249:14 | value7 | testCryptoKit.swift:251:39:251:44 | value7 | provenance | | +| testCryptoKit.swift:249:18:249:42 | Data(...) | testCryptoKit.swift:249:9:249:14 | value7 | provenance | | +| testCryptoKit.swift:249:23:249:36 | passwordString | testCryptoKit.swift:249:23:249:41 | ... .utf8 | provenance | | +| testCryptoKit.swift:249:23:249:41 | ... .utf8 | testCryptoKit.swift:249:18:249:42 | Data(...) | provenance | | +| testCryptoSwift.swift:183:9:183:19 | passwdArray | testCryptoSwift.swift:183:9:183:25 | [self arg] ... .md5(...) | provenance | | +| testCryptoSwift.swift:186:9:186:19 | passwdArray | testCryptoSwift.swift:186:9:186:26 | [self arg] ... .sha1(...) | provenance | | +| testCryptoSwift.swift:189:9:189:19 | passwdArray | testCryptoSwift.swift:189:9:189:28 | [self arg] ... .sha512(...) | provenance | | +| testCryptoSwift.swift:192:9:192:19 | passwdArray | testCryptoSwift.swift:192:9:192:33 | [self arg] ... .sha2(...) | provenance | | +| testCryptoSwift.swift:195:9:195:19 | passwdArray | testCryptoSwift.swift:195:9:195:33 | [self arg] ... .sha3(...) | provenance | | +| testCryptoSwift.swift:201:9:201:18 | passwdData | testCryptoSwift.swift:201:9:201:24 | [self arg] ... .md5(...) | provenance | | +| testCryptoSwift.swift:204:9:204:18 | passwdData | testCryptoSwift.swift:204:9:204:25 | [self arg] ... .sha1(...) | provenance | | +| testCryptoSwift.swift:207:9:207:18 | passwdData | testCryptoSwift.swift:207:9:207:27 | [self arg] ... .sha512(...) | provenance | | +| testCryptoSwift.swift:210:9:210:18 | passwdData | testCryptoSwift.swift:210:9:210:32 | [self arg] ... .sha2(...) | provenance | | +| testCryptoSwift.swift:213:9:213:18 | passwdData | testCryptoSwift.swift:213:9:213:32 | [self arg] ... .sha3(...) | provenance | | +| testCryptoSwift.swift:219:9:219:14 | passwd | testCryptoSwift.swift:219:9:219:20 | [self arg] ... .md5(...) | provenance | | +| testCryptoSwift.swift:222:9:222:14 | passwd | testCryptoSwift.swift:222:9:222:21 | [self arg] ... .sha1(...) | provenance | | +| testCryptoSwift.swift:225:9:225:14 | passwd | testCryptoSwift.swift:225:9:225:23 | [self arg] ... .sha512(...) | provenance | | +| testCryptoSwift.swift:228:9:228:14 | passwd | testCryptoSwift.swift:228:9:228:28 | [self arg] ... .sha2(...) | provenance | | +| testCryptoSwift.swift:231:9:231:14 | passwd | testCryptoSwift.swift:231:9:231:28 | [self arg] ... .sha3(...) | provenance | | +| testCryptoSwift.swift:247:24:247:28 | bytes | testCryptoSwift.swift:248:30:248:34 | bytes | provenance | | +| testCryptoSwift.swift:255:36:255:46 | passwdArray | testCryptoSwift.swift:247:24:247:28 | bytes | provenance | | +nodes +| testCryptoKit.swift:84:47:84:52 | passwd | semmle.label | passwd | +| testCryptoKit.swift:85:52:85:57 | passwd | semmle.label | passwd | +| testCryptoKit.swift:91:36:91:41 | passwd | semmle.label | passwd | +| testCryptoKit.swift:92:45:92:50 | passwd | semmle.label | passwd | +| testCryptoKit.swift:98:44:98:49 | passwd | semmle.label | passwd | +| testCryptoKit.swift:99:53:99:58 | passwd | semmle.label | passwd | +| testCryptoKit.swift:105:37:105:42 | passwd | semmle.label | passwd | +| testCryptoKit.swift:106:46:106:51 | passwd | semmle.label | passwd | +| testCryptoKit.swift:112:37:112:42 | passwd | semmle.label | passwd | +| testCryptoKit.swift:113:46:113:51 | passwd | semmle.label | passwd | +| testCryptoKit.swift:119:37:119:42 | passwd | semmle.label | passwd | +| testCryptoKit.swift:120:46:120:51 | passwd | semmle.label | passwd | +| testCryptoKit.swift:129:23:129:28 | passwd | semmle.label | passwd | +| testCryptoKit.swift:138:23:138:28 | passwd | semmle.label | passwd | +| testCryptoKit.swift:147:23:147:28 | passwd | semmle.label | passwd | +| testCryptoKit.swift:156:23:156:28 | passwd | semmle.label | passwd | +| testCryptoKit.swift:165:23:165:28 | passwd | semmle.label | passwd | +| testCryptoKit.swift:174:32:174:37 | passwd | semmle.label | passwd | +| testCryptoKit.swift:183:32:183:37 | passwd | semmle.label | passwd | +| testCryptoKit.swift:192:32:192:37 | passwd | semmle.label | passwd | +| testCryptoKit.swift:201:32:201:37 | passwd | semmle.label | passwd | +| testCryptoKit.swift:210:32:210:37 | passwd | semmle.label | passwd | +| testCryptoKit.swift:220:49:220:60 | passwordData | semmle.label | passwordData | +| testCryptoKit.swift:224:33:224:57 | Data(...) | semmle.label | Data(...) | +| testCryptoKit.swift:224:38:224:51 | passwordString | semmle.label | passwordString | +| testCryptoKit.swift:224:38:224:56 | ... .utf8 | semmle.label | ... .utf8 | +| testCryptoKit.swift:249:9:249:14 | value7 | semmle.label | value7 | +| testCryptoKit.swift:249:18:249:42 | Data(...) | semmle.label | Data(...) | +| testCryptoKit.swift:249:23:249:36 | passwordString | semmle.label | passwordString | +| testCryptoKit.swift:249:23:249:41 | ... .utf8 | semmle.label | ... .utf8 | +| testCryptoKit.swift:251:39:251:44 | value7 | semmle.label | value7 | +| testCryptoSwift.swift:154:30:154:40 | passwdArray | semmle.label | passwdArray | +| testCryptoSwift.swift:157:31:157:41 | passwdArray | semmle.label | passwdArray | +| testCryptoSwift.swift:160:47:160:57 | passwdArray | semmle.label | passwdArray | +| testCryptoSwift.swift:163:47:163:57 | passwdArray | semmle.label | passwdArray | +| testCryptoSwift.swift:167:20:167:30 | passwdArray | semmle.label | passwdArray | +| testCryptoSwift.swift:170:21:170:31 | passwdArray | semmle.label | passwdArray | +| testCryptoSwift.swift:173:23:173:33 | passwdArray | semmle.label | passwdArray | +| testCryptoSwift.swift:176:21:176:31 | passwdArray | semmle.label | passwdArray | +| testCryptoSwift.swift:179:21:179:31 | passwdArray | semmle.label | passwdArray | +| testCryptoSwift.swift:183:9:183:19 | passwdArray | semmle.label | passwdArray | +| testCryptoSwift.swift:183:9:183:25 | [self arg] ... .md5(...) | semmle.label | [self arg] ... .md5(...) | +| testCryptoSwift.swift:186:9:186:19 | passwdArray | semmle.label | passwdArray | +| testCryptoSwift.swift:186:9:186:26 | [self arg] ... .sha1(...) | semmle.label | [self arg] ... .sha1(...) | +| testCryptoSwift.swift:189:9:189:19 | passwdArray | semmle.label | passwdArray | +| testCryptoSwift.swift:189:9:189:28 | [self arg] ... .sha512(...) | semmle.label | [self arg] ... .sha512(...) | +| testCryptoSwift.swift:192:9:192:19 | passwdArray | semmle.label | passwdArray | +| testCryptoSwift.swift:192:9:192:33 | [self arg] ... .sha2(...) | semmle.label | [self arg] ... .sha2(...) | +| testCryptoSwift.swift:195:9:195:19 | passwdArray | semmle.label | passwdArray | +| testCryptoSwift.swift:195:9:195:33 | [self arg] ... .sha3(...) | semmle.label | [self arg] ... .sha3(...) | +| testCryptoSwift.swift:201:9:201:18 | passwdData | semmle.label | passwdData | +| testCryptoSwift.swift:201:9:201:24 | [self arg] ... .md5(...) | semmle.label | [self arg] ... .md5(...) | +| testCryptoSwift.swift:204:9:204:18 | passwdData | semmle.label | passwdData | +| testCryptoSwift.swift:204:9:204:25 | [self arg] ... .sha1(...) | semmle.label | [self arg] ... .sha1(...) | +| testCryptoSwift.swift:207:9:207:18 | passwdData | semmle.label | passwdData | +| testCryptoSwift.swift:207:9:207:27 | [self arg] ... .sha512(...) | semmle.label | [self arg] ... .sha512(...) | +| testCryptoSwift.swift:210:9:210:18 | passwdData | semmle.label | passwdData | +| testCryptoSwift.swift:210:9:210:32 | [self arg] ... .sha2(...) | semmle.label | [self arg] ... .sha2(...) | +| testCryptoSwift.swift:213:9:213:18 | passwdData | semmle.label | passwdData | +| testCryptoSwift.swift:213:9:213:32 | [self arg] ... .sha3(...) | semmle.label | [self arg] ... .sha3(...) | +| testCryptoSwift.swift:219:9:219:14 | passwd | semmle.label | passwd | +| testCryptoSwift.swift:219:9:219:20 | [self arg] ... .md5(...) | semmle.label | [self arg] ... .md5(...) | +| testCryptoSwift.swift:222:9:222:14 | passwd | semmle.label | passwd | +| testCryptoSwift.swift:222:9:222:21 | [self arg] ... .sha1(...) | semmle.label | [self arg] ... .sha1(...) | +| testCryptoSwift.swift:225:9:225:14 | passwd | semmle.label | passwd | +| testCryptoSwift.swift:225:9:225:23 | [self arg] ... .sha512(...) | semmle.label | [self arg] ... .sha512(...) | +| testCryptoSwift.swift:228:9:228:14 | passwd | semmle.label | passwd | +| testCryptoSwift.swift:228:9:228:28 | [self arg] ... .sha2(...) | semmle.label | [self arg] ... .sha2(...) | +| testCryptoSwift.swift:231:9:231:14 | passwd | semmle.label | passwd | +| testCryptoSwift.swift:231:9:231:28 | [self arg] ... .sha3(...) | semmle.label | [self arg] ... .sha3(...) | +| testCryptoSwift.swift:247:24:247:28 | bytes | semmle.label | bytes | +| testCryptoSwift.swift:248:30:248:34 | bytes | semmle.label | bytes | +| testCryptoSwift.swift:255:36:255:46 | passwdArray | semmle.label | passwdArray | +subpaths diff --git a/unified/ql/test/query-tests/security/CWE-328/WeakPasswordHashing.qlref b/unified/ql/test/query-tests/security/CWE-328/WeakPasswordHashing.qlref new file mode 100644 index 000000000000..8648f309dcfb --- /dev/null +++ b/unified/ql/test/query-tests/security/CWE-328/WeakPasswordHashing.qlref @@ -0,0 +1,3 @@ +query: queries/security/CWE-328/WeakPasswordHashing.ql +postprocess: + - utils/test/InlineExpectationsTestQuery.ql diff --git a/unified/ql/test/query-tests/security/CWE-328/testArgon2Swift.swift b/unified/ql/test/query-tests/security/CWE-328/testArgon2Swift.swift new file mode 100644 index 000000000000..c0a02ef8b4e1 --- /dev/null +++ b/unified/ql/test/query-tests/security/CWE-328/testArgon2Swift.swift @@ -0,0 +1,49 @@ + +// --- stubs --- + +class Data +{ + init(_ elements: S) {} +} + +class Salt { + init(bytes: Data) { } + + static func newSalt(length: Int = 16) -> Salt { + return Salt(bytes: Data(0)) + } +} + +class Argon2SwiftResult { + init(hashBytes: [Int8], encodedBytes: [Int8]) { } + + func encodedString() -> String { + return "" + } +} + +class Argon2Swift { + // slightly simplified (type and version changed to Int) + static func hashPasswordString(password: String, salt: Salt, iterations: Int = 32, memory: Int = 256, parallelism: Int = 2, length: Int = 32, type: Int = 1, version: Int = 13) throws -> Argon2SwiftResult { + return Argon2SwiftResult(hashBytes: [], encodedBytes: []) + } + + static func verifyHashString(password: String, hash: String, type: Int = 1) throws -> Bool { + return false + } +} + +// --- tests --- + +func testGoodExample(passwordString: String) { + // this is the "good" example from the `.qhelp` + let salt = Salt.newSalt() + let result = try! Argon2Swift.hashPasswordString(password: passwordString, salt: salt) // GOOD (suitable password hash) + let passwordHash = result.encodedString() + + // ... + + if try! Argon2Swift.verifyHashString(password: passwordString, hash: passwordHash) { + // ... + } +} diff --git a/unified/ql/test/query-tests/security/CWE-328/testCryptoKit.swift b/unified/ql/test/query-tests/security/CWE-328/testCryptoKit.swift new file mode 100644 index 000000000000..9a52810b4496 --- /dev/null +++ b/unified/ql/test/query-tests/security/CWE-328/testCryptoKit.swift @@ -0,0 +1,264 @@ +//codeql-extractor-options: -module-name Crypto + +// --- stubs --- + +class Data +{ + init(_ elements: S) {} +} + +public protocol HashFunction { + associatedtype Digest + + init() + mutating func update(bufferPointer: UnsafeRawBufferPointer) + func finalize() -> Digest +} + +extension HashFunction { + @inlinable + public static func hash(bufferPointer: UnsafeRawBufferPointer) -> Digest { + var hasher = Self() + hasher.update(bufferPointer: bufferPointer) + return hasher.finalize() + } + + @inlinable + public static func hash(data: D) -> Self.Digest { + var hasher = Self() + hasher.update(data: data) + return hasher.finalize() + } + + @inlinable + public mutating func update(data: D) { + // ... + } +} + +public struct SHA256: HashFunction { + public typealias Digest = [UInt8] + + public init() {} + public mutating func update(bufferPointer: UnsafeRawBufferPointer) {} + public func finalize() -> Digest { return [] } +} + +public struct SHA384: HashFunction { + public typealias Digest = [UInt8] + + public init() {} + public mutating func update(bufferPointer: UnsafeRawBufferPointer) {} + public func finalize() -> Digest { return [] } +} + +public struct SHA512: HashFunction { + public typealias Digest = [UInt8] + + public init() {} + public mutating func update(bufferPointer: UnsafeRawBufferPointer) {} + public func finalize() -> Digest { return [] } +} + +enum Insecure { + public struct MD5: HashFunction { + public typealias Digest = [UInt8] + + public init() {} + public mutating func update(bufferPointer: UnsafeRawBufferPointer) {} + public func finalize() -> Digest { return [] } + } + + public struct SHA1: HashFunction { + public typealias Digest = [UInt8] + + public init() {} + public mutating func update(bufferPointer: UnsafeRawBufferPointer) {} + public func finalize() -> Digest { return [] } + } +} + +// --- tests --- + +func testHashMethods(passwd : UnsafeRawBufferPointer, cert: String, encrypted_passwd : String, account_no : String, credit_card_no : String) { + var hash = Crypto.Insecure.MD5.hash(data: passwd) // $ Alert[unified/swift/weak-password-hashing] + hash = Crypto.Insecure.MD5.hash(bufferPointer: passwd) // $ Alert[unified/swift/weak-password-hashing] + hash = Crypto.Insecure.MD5.hash(data: cert) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + hash = Crypto.Insecure.MD5.hash(data: encrypted_passwd) // GOOD (not sensitive) + hash = Crypto.Insecure.MD5.hash(data: account_no) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + hash = Crypto.Insecure.MD5.hash(data: credit_card_no) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + + hash = Insecure.MD5.hash(data: passwd) // $ Alert[unified/swift/weak-password-hashing] + hash = Insecure.MD5.hash(bufferPointer: passwd) // $ Alert[unified/swift/weak-password-hashing] + hash = Insecure.MD5.hash(data: cert) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + hash = Insecure.MD5.hash(data: encrypted_passwd) // GOOD (not sensitive) + hash = Insecure.MD5.hash(data: account_no) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + hash = Insecure.MD5.hash(data: credit_card_no) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + + hash = Crypto.Insecure.SHA1.hash(data: passwd) // $ Alert[unified/swift/weak-password-hashing] + hash = Crypto.Insecure.SHA1.hash(bufferPointer: passwd) // $ Alert[unified/swift/weak-password-hashing] + hash = Crypto.Insecure.SHA1.hash(data: cert) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + hash = Crypto.Insecure.SHA1.hash(data: encrypted_passwd) // GOOD (not sensitive) + hash = Crypto.Insecure.SHA1.hash(data: account_no) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + hash = Crypto.Insecure.SHA1.hash(data: credit_card_no) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + + hash = Crypto.SHA256.hash(data: passwd) // $ Alert[unified/swift/weak-password-hashing] (not a computationally expensive hash) + hash = Crypto.SHA256.hash(bufferPointer: passwd) // $ Alert[unified/swift/weak-password-hashing] (not a computationally expensive hash) + hash = Crypto.SHA256.hash(data: cert) // GOOD, computationally expensive hash not required + hash = Crypto.SHA256.hash(data: encrypted_passwd) // GOOD, not sensitive + hash = Crypto.SHA256.hash(data: account_no) // GOOD, computationally expensive hash not required + hash = Crypto.SHA256.hash(data: credit_card_no) // GOOD, computationally expensive hash not required + + hash = Crypto.SHA384.hash(data: passwd) // $ Alert[unified/swift/weak-password-hashing] (not a computationally expensive hash) + hash = Crypto.SHA384.hash(bufferPointer: passwd) // $ Alert[unified/swift/weak-password-hashing] (not a computationally expensive hash) + hash = Crypto.SHA384.hash(data: cert) // GOOD, computationally expensive hash not required + hash = Crypto.SHA384.hash(data: encrypted_passwd) // GOOD, not sensitive + hash = Crypto.SHA384.hash(data: account_no) // GOOD, computationally expensive hash not required + hash = Crypto.SHA384.hash(data: credit_card_no) // GOOD, computationally expensive hash not required + + hash = Crypto.SHA512.hash(data: passwd) // $ Alert[unified/swift/weak-password-hashing] (not a computationally expensive hash) + hash = Crypto.SHA512.hash(bufferPointer: passwd) // $ Alert[unified/swift/weak-password-hashing] (not a computationally expensive hash) + hash = Crypto.SHA512.hash(data: cert) // GOOD, computationally expensive hash not required + hash = Crypto.SHA512.hash(data: encrypted_passwd) // GOOD, not sensitive + hash = Crypto.SHA512.hash(data: account_no) // GOOD, computationally expensive hash not required + hash = Crypto.SHA512.hash(data: credit_card_no) // GOOD, computationally expensive hash not required +} + +func testMD5UpdateWithData(passwd : String, cert: String, encrypted_passwd : String, account_no : String, credit_card_no : String) { + var hash = Crypto.Insecure.MD5() + hash.update(data: passwd) // $ Alert[unified/swift/weak-password-hashing] + hash.update(data: cert) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + hash.update(data: encrypted_passwd) // GOOD (not sensitive) + hash.update(data: account_no) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + hash.update(data: credit_card_no) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] +} + +func testSHA1UpdateWithData(passwd : String, cert: String, encrypted_passwd : String, account_no : String, credit_card_no : String) { + var hash = Crypto.Insecure.SHA1() + hash.update(data: passwd) // $ Alert[unified/swift/weak-password-hashing] + hash.update(data: cert) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + hash.update(data: encrypted_passwd) // GOOD (not sensitive) + hash.update(data: account_no) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + hash.update(data: credit_card_no) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] +} + +func testSHA256UpdateWithData(passwd : String, cert: String, encrypted_passwd : String, account_no : String, credit_card_no : String) { + var hash = Crypto.SHA256() + hash.update(data: passwd) // $ Alert[unified/swift/weak-password-hashing] (not a computationally expensive hash) + hash.update(data: cert) // GOOD + hash.update(data: encrypted_passwd) // GOOD (not sensitive) + hash.update(data: account_no) // GOOD + hash.update(data: credit_card_no) // GOOD +} + +func testSHA384UpdateWithData(passwd : String, cert: String, encrypted_passwd : String, account_no : String, credit_card_no : String) { + var hash = Crypto.SHA384() + hash.update(data: passwd) // $ Alert[unified/swift/weak-password-hashing] (not a computationally expensive hash) + hash.update(data: cert) // GOOD + hash.update(data: encrypted_passwd) // GOOD (not sensitive) + hash.update(data: account_no) // GOOD + hash.update(data: credit_card_no) // GOOD +} + +func testSHA512UpdateWithData(passwd : String, cert: String, encrypted_passwd : String, account_no : String, credit_card_no : String) { + var hash = Crypto.SHA512() + hash.update(data: passwd) // $ Alert[unified/swift/weak-password-hashing] (not a computationally expensive hash) + hash.update(data: cert) // GOOD + hash.update(data: encrypted_passwd) // GOOD (not sensitive) + hash.update(data: account_no) // GOOD + hash.update(data: credit_card_no) // GOOD +} + +func testMD5UpdateWithUnsafeRawBufferPointer(passwd : UnsafeRawBufferPointer, cert: UnsafeRawBufferPointer, encrypted_passwd : UnsafeRawBufferPointer, account_no : UnsafeRawBufferPointer, credit_card_no : UnsafeRawBufferPointer) { + var hash = Crypto.Insecure.MD5() + hash.update(bufferPointer: passwd) // $ Alert[unified/swift/weak-password-hashing] + hash.update(bufferPointer: cert) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + hash.update(bufferPointer: encrypted_passwd) // GOOD (not sensitive) + hash.update(bufferPointer: account_no) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + hash.update(bufferPointer: credit_card_no) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] +} + +func testSHA1UpdateWithUnsafeRawBufferPointer(passwd : UnsafeRawBufferPointer, cert: UnsafeRawBufferPointer, encrypted_passwd : UnsafeRawBufferPointer, account_no : UnsafeRawBufferPointer, credit_card_no : UnsafeRawBufferPointer) { + var hash = Crypto.Insecure.SHA1() + hash.update(bufferPointer: passwd) // $ Alert[unified/swift/weak-password-hashing] + hash.update(bufferPointer: cert) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + hash.update(bufferPointer: encrypted_passwd) // GOOD (not sensitive) + hash.update(bufferPointer: account_no) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + hash.update(bufferPointer: credit_card_no) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] +} + +func testSHA256UpdateWithUnsafeRawBufferPointer(passwd : UnsafeRawBufferPointer, cert: UnsafeRawBufferPointer, encrypted_passwd : UnsafeRawBufferPointer, account_no : UnsafeRawBufferPointer, credit_card_no : UnsafeRawBufferPointer) { + var hash = Crypto.SHA256() + hash.update(bufferPointer: passwd) // $ Alert[unified/swift/weak-password-hashing] (not a computationally expensive hash) + hash.update(bufferPointer: cert) // GOOD + hash.update(bufferPointer: encrypted_passwd) // GOOD (not sensitive) + hash.update(bufferPointer: account_no) // GOOD + hash.update(bufferPointer: credit_card_no) // GOOD +} + +func testSHA384UpdateWithUnsafeRawBufferPointer(passwd : UnsafeRawBufferPointer, cert: UnsafeRawBufferPointer, encrypted_passwd : UnsafeRawBufferPointer, account_no : UnsafeRawBufferPointer, credit_card_no : UnsafeRawBufferPointer) { + var hash = Crypto.SHA384() + hash.update(bufferPointer: passwd) // $ Alert[unified/swift/weak-password-hashing] (not a computationally expensive hash) + hash.update(bufferPointer: cert) // GOOD + hash.update(bufferPointer: encrypted_passwd) // GOOD (not sensitive) + hash.update(bufferPointer: account_no) // GOOD + hash.update(bufferPointer: credit_card_no) // GOOD +} + +func testSHA512UpdateWithUnsafeRawBufferPointer(passwd : UnsafeRawBufferPointer, cert: UnsafeRawBufferPointer, encrypted_passwd : UnsafeRawBufferPointer, account_no : UnsafeRawBufferPointer, credit_card_no : UnsafeRawBufferPointer) { + var hash = Crypto.SHA512() + hash.update(bufferPointer: passwd) // $ Alert[unified/swift/weak-password-hashing] (not a computationally expensive hash) + hash.update(bufferPointer: cert) // GOOD + hash.update(bufferPointer: encrypted_passwd) // GOOD (not sensitive) + hash.update(bufferPointer: account_no) // GOOD + hash.update(bufferPointer: credit_card_no) // GOOD +} + +func testBadExample(passwordString: String) { + // this is the "bad" example from the `.qhelp` + let passwordData = Data(passwordString.utf8) + let passwordHash = Crypto.SHA512.hash(data: passwordData) // $ Alert[unified/swift/weak-password-hashing] (not a computationally expensive hash) + + // ... + + if Crypto.SHA512.hash(data: Data(passwordString.utf8)) == passwordHash { // $ Alert[unified/swift/weak-password-hashing] (not a computationally expensive hash) + // ... + } +} + +func testWithFlowAndMetatypes(cardNumber: String, passwordString: String) { + let value1 = Data(cardNumber.utf8); // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + let _digest1 = Insecure.MD5.hash(data: value1); // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + + let value2 = Data(cardNumber.utf8); // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + let hasher2 = Insecure.MD5.self; // metatype + let _digest2 = hasher2.hash(data: value2); // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + + let value3 = Data(cardNumber.utf8); // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + let _digest3 = (Insecure.MD5.self).hash(data: value3); // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + + let value4 = Data(cardNumber.utf8); // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + testReceiver1(value: value4); + + let value5 = Data(cardNumber.utf8); // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + testReceiver2(hasher: Insecure.MD5.self, value: value5); + + let value6 = Data(cardNumber.utf8); + testReceiver3(hasher: Insecure.MD5.self, value: value6); + + let value7 = Data(passwordString.utf8); // $ Source[unified/swift/weak-password-hashing] + let hasher7 = SHA256.self; // metatype + let _digest7 = hasher7.hash(data: value7); // $ Alert[unified/swift/weak-password-hashing] +} + +func testReceiver1(value: Data) { + let _digest = Insecure.MD5.hash(data: value); // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] +} + +func testReceiver2(hasher: Insecure.MD5.Type, value: Data) { + let _digest = hasher.hash(data: value); // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] +} + +func testReceiver3(hasher: H.Type, value: Data) { + let _digest = hasher.hash(data: value); // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] +} diff --git a/unified/ql/test/query-tests/security/CWE-328/testCryptoSwift.swift b/unified/ql/test/query-tests/security/CWE-328/testCryptoSwift.swift new file mode 100644 index 000000000000..aae91aa07f0b --- /dev/null +++ b/unified/ql/test/query-tests/security/CWE-328/testCryptoSwift.swift @@ -0,0 +1,256 @@ + +// --- stubs --- + +class Data +{ + init(_ elements: S) {} +} + +protocol DigestType { + func calculate(for bytes: Array) -> Array +} + +class MD5 : DigestType { + public func calculate(for bytes: Array) -> Array { + return Array() + } +} + +class SHA1 : DigestType { + public func calculate(for bytes: Array) -> Array { + return Array() + } +} + +class SHA2 : DigestType { + public enum Variant { + case sha512 + } + + public init(variant: SHA2.Variant) {} + + public func calculate(for bytes: Array) -> Array { + return Array() + } +} + +class SHA3 : DigestType { + public enum Variant { + case sha512 + } + + public init(variant: SHA3.Variant) {} + + public func calculate(for bytes: Array) -> Array { + return Array() + } +} + +struct Digest { + static func md5(_ bytes: Array) -> Array { + return MD5().calculate(for: bytes) + } + + static func sha1(_ bytes: Array) -> Array { + return SHA1().calculate(for: bytes) + } + + static func sha512(_ bytes: Array) -> Array { + return self.sha2(bytes, variant: .sha512) + } + + static func sha2(_ bytes: Array, variant: SHA2.Variant) -> Array { + return SHA2(variant: variant).calculate(for: bytes) + } + + static func sha3(_ bytes: Array, variant: SHA3.Variant) -> Array { + return SHA3(variant: variant).calculate(for: bytes) + } +} + +extension Array where Element == UInt8 { + func toHexString() -> String { + return "" + } + + func md5() -> [Element] { + return Digest.md5(self) + } + + func sha1() -> [Element] { + return Digest.sha1(self) + } + + func sha512() -> [Element] { + return Digest.sha512(self) + } + + func sha2(_ variant: SHA2.Variant) -> [Element] { + return Digest.sha2(self, variant: variant) + } + + func sha3(_ variant: SHA3.Variant) -> [Element] { + return Digest.sha3(self, variant: variant) + } +} + +extension Data { + var bytes: Array { + return Array() + } + + func md5() -> Data { + return Data(Digest.md5(bytes)) + } + + func sha1() -> Data { + return Data(Digest.sha1(bytes)) + } + + func sha512() -> Data { + return Data(Digest.sha512(bytes)) + } + + func sha2(_ variant: SHA2.Variant) -> Data { + return Data(Digest.sha2(bytes, variant: variant)) + } + + func sha3(_ variant: SHA3.Variant) -> Data { + return Data(Digest.sha3(bytes, variant: variant)) + } +} + +extension String { + var bytes: Array { + return Array() + } + + func md5() -> String { + return self.bytes.md5().toHexString() + } + + func sha1() -> String { + return self.bytes.sha1().toHexString() + } + + func sha512() -> String { + return self.bytes.sha512().toHexString() + } + + func sha2(_ variant: SHA2.Variant) -> String { + return self.bytes.sha2(variant).toHexString() + } + + func sha3(_ variant: SHA3.Variant) -> String { + return self.bytes.sha3(variant).toHexString() + } +} + +// --- tests --- + +func testArrays(harmlessArray: Array, phoneNumberArray: Array, passwdArray: Array) { + _ = MD5().calculate(for: harmlessArray) // GOOD (not sensitive) + _ = MD5().calculate(for: phoneNumberArray) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + _ = MD5().calculate(for: passwdArray) // $ Alert[unified/swift/weak-password-hashing] + _ = SHA1().calculate(for: harmlessArray) // GOOD (not sensitive) + _ = SHA1().calculate(for: phoneNumberArray) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + _ = SHA1().calculate(for: passwdArray) // $ Alert[unified/swift/weak-password-hashing] + _ = SHA2(variant: .sha512).calculate(for: harmlessArray) // GOOD + _ = SHA2(variant: .sha512).calculate(for: phoneNumberArray) // GOOD + _ = SHA2(variant: .sha512).calculate(for: passwdArray) // $ Alert[unified/swift/weak-password-hashing] + _ = SHA3(variant: .sha512).calculate(for: harmlessArray) // GOOD + _ = SHA3(variant: .sha512).calculate(for: phoneNumberArray) // GOOD + _ = SHA3(variant: .sha512).calculate(for: passwdArray) // $ Alert[unified/swift/weak-password-hashing] + + _ = Digest.md5(harmlessArray) // GOOD (not sensitive) + _ = Digest.md5(phoneNumberArray) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + _ = Digest.md5(passwdArray) // $ Alert[unified/swift/weak-password-hashing] + _ = Digest.sha1(harmlessArray) // GOOD (not sensitive) + _ = Digest.sha1(phoneNumberArray) // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + _ = Digest.sha1(passwdArray) // $ Alert[unified/swift/weak-password-hashing] + _ = Digest.sha512(harmlessArray) // GOOD (not sensitive) + _ = Digest.sha512(phoneNumberArray) // GOOD + _ = Digest.sha512(passwdArray) // $ Alert[unified/swift/weak-password-hashing] + _ = Digest.sha2(harmlessArray, variant: .sha512) // GOOD (not sensitive) + _ = Digest.sha2(phoneNumberArray, variant: .sha512) // GOOD + _ = Digest.sha2(passwdArray, variant: .sha512) // $ Alert[unified/swift/weak-password-hashing] + _ = Digest.sha3(harmlessArray, variant: .sha512) // GOOD (not sensitive) + _ = Digest.sha3(phoneNumberArray, variant: .sha512) // GOOD + _ = Digest.sha3(passwdArray, variant: .sha512) // $ Alert[unified/swift/weak-password-hashing] + + _ = harmlessArray.md5() // GOOD (not sensitive) + _ = phoneNumberArray.md5() // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + _ = passwdArray.md5() // $ Alert[unified/swift/weak-password-hashing] + _ = harmlessArray.sha1() // GOOD (not sensitive) + _ = phoneNumberArray.sha1() // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + _ = passwdArray.sha1() // $ Alert[unified/swift/weak-password-hashing] + _ = harmlessArray.sha512() // GOOD + _ = phoneNumberArray.sha512() // GOOD + _ = passwdArray.sha512() // $ Alert[unified/swift/weak-password-hashing] + _ = harmlessArray.sha2(.sha512) // GOOD + _ = phoneNumberArray.sha2(.sha512) // GOOD + _ = passwdArray.sha2(.sha512) // $ Alert[unified/swift/weak-password-hashing] + _ = harmlessArray.sha3(.sha512) // GOOD + _ = phoneNumberArray.sha3(.sha512) // GOOD + _ = passwdArray.sha3(.sha512) // $ Alert[unified/swift/weak-password-hashing] +} + +func testData(harmlessData: Data, medicalData: Data, passwdData: Data) { + _ = harmlessData.md5() // GOOD (not sensitive) + _ = medicalData.md5() // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + _ = passwdData.md5() // $ Alert[unified/swift/weak-password-hashing] + _ = harmlessData.sha1() // GOOD (not sensitive) + _ = medicalData.sha1() // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + _ = passwdData.sha1() // $ Alert[unified/swift/weak-password-hashing] + _ = harmlessData.sha512() // GOOD + _ = medicalData.sha512() // GOOD + _ = passwdData.sha512() // $ Alert[unified/swift/weak-password-hashing] + _ = harmlessData.sha2(.sha512) // GOOD + _ = medicalData.sha2(.sha512) // GOOD + _ = passwdData.sha2(.sha512) // $ Alert[unified/swift/weak-password-hashing] + _ = harmlessData.sha3(.sha512) // GOOD + _ = medicalData.sha3(.sha512) // GOOD + _ = passwdData.sha3(.sha512) // $ Alert[unified/swift/weak-password-hashing] +} + +func testStrings(creditCardNumber: String, passwd: String) { + _ = "harmless".md5() // GOOD (not sensitive) + _ = creditCardNumber.md5() // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + _ = passwd.md5() // $ Alert[unified/swift/weak-password-hashing] + _ = "harmless".sha1() // GOOD (not sensitive) + _ = creditCardNumber.sha1() // $ MISSING: Alert[unified/swift/weak-sensitive-data-hashing] + _ = passwd.sha1() // $ Alert[unified/swift/weak-password-hashing] + _ = "harmless".sha512() // GOOD + _ = creditCardNumber.sha512() // GOOD + _ = passwd.sha512() // $ Alert[unified/swift/weak-password-hashing] + _ = "harmless".sha2(.sha512) // GOOD + _ = creditCardNumber.sha2(.sha512) // GOOD + _ = passwd.sha2(.sha512) // $ Alert[unified/swift/weak-password-hashing] + _ = "harmless".sha3(.sha512) // GOOD + _ = creditCardNumber.sha3(.sha512) // GOOD + _ = passwd.sha3(.sha512) // $ Alert[unified/swift/weak-password-hashing] +} + +struct PBKDF2 { + static func derive(bytes: Array) -> Array { + return Digest.sha512(bytes) // GOOD (inside PBKDF2 implementation) + } +} + +extension PBKDF2 { + static func deriveInExtension(bytes: Array) -> Array { + return Digest.sha512(bytes) // GOOD (inside PBKDF2 extension) + } +} + +struct CustomHasher { + static func derive(bytes: Array) -> Array { + return Digest.sha512(bytes) // $ Alert[unified/swift/weak-password-hashing] + } +} + +func testImplementationBarrier(passwdArray: Array) { + _ = PBKDF2.derive(bytes: passwdArray) + _ = PBKDF2.deriveInExtension(bytes: passwdArray) + _ = CustomHasher.derive(bytes: passwdArray) // $ Source[unified/swift/weak-password-hashing] +}