--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Security/Checks/awsHardcodedPassword.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Security/Checks/awsHardcodedPassword.py Wed Jul 13 14:55:47 2022 +0200 @@ -25,7 +25,7 @@ def getChecks(): """ Public method to get a dictionary with checks handled by this module. - + @return dictionary containing checker lists containing checker function and list of codes @rtype dict @@ -36,26 +36,23 @@ ], } + AWS_ACCESS_KEY_ID_SYMBOLS = string.ascii_uppercase + string.digits -AWS_ACCESS_KEY_ID_REGEX = re.compile( - '[' + AWS_ACCESS_KEY_ID_SYMBOLS + ']{20}' -) +AWS_ACCESS_KEY_ID_REGEX = re.compile("[" + AWS_ACCESS_KEY_ID_SYMBOLS + "]{20}") AWS_ACCESS_KEY_ID_MAX_ENTROPY = 3 -AWS_SECRET_ACCESS_KEY_SYMBOLS = string.ascii_letters + string.digits + '/+=' -AWS_SECRET_ACCESS_KEY_REGEX = re.compile( - '[' + AWS_SECRET_ACCESS_KEY_SYMBOLS + ']{40}' -) +AWS_SECRET_ACCESS_KEY_SYMBOLS = string.ascii_letters + string.digits + "/+=" +AWS_SECRET_ACCESS_KEY_REGEX = re.compile("[" + AWS_SECRET_ACCESS_KEY_SYMBOLS + "]{40}") AWS_SECRET_ACCESS_KEY_MAX_ENTROPY = 4.5 def shannonEntropy(data, symbols): """ Function to caclculate the Shannon entropy of some given data. - + Source: http://blog.dkbza.org/2007/05/scanning-data-for-entropy-anomalies.html - + @param data data to calculate the entropy for @type str @param symbols allowed symbols @@ -70,14 +67,14 @@ for x in symbols: p_x = float(counts[x]) / len(data) if p_x > 0: - entropy += - p_x * math.log(p_x, 2) + entropy += -p_x * math.log(p_x, 2) return entropy def checkHardcodedAwsKey(reportError, context, config): """ Function to check for potentially hardcoded AWS passwords. - + @param reportError function to be used to report errors @type func @param context security context object @@ -95,9 +92,9 @@ "S801", "L", "M", - node.s + node.s, ) - + elif AWS_SECRET_ACCESS_KEY_REGEX.fullmatch(node.s): entropy = shannonEntropy(node.s, AWS_SECRET_ACCESS_KEY_SYMBOLS) if entropy > AWS_SECRET_ACCESS_KEY_MAX_ENTROPY: @@ -107,5 +104,5 @@ "S802", "M", "M", - node.s + node.s, )