70 if p_x > 0: |
70 if p_x > 0: |
71 entropy += -p_x * math.log(p_x, 2) |
71 entropy += -p_x * math.log(p_x, 2) |
72 return entropy |
72 return entropy |
73 |
73 |
74 |
74 |
75 def checkHardcodedAwsKey(reportError, context, config): # noqa: U100 |
75 def checkHardcodedAwsKey(reportError, context, _config): |
76 """ |
76 """ |
77 Function to check for potentially hardcoded AWS passwords. |
77 Function to check for potentially hardcoded AWS passwords. |
78 |
78 |
79 @param reportError function to be used to report errors |
79 @param reportError function to be used to report errors |
80 @type func |
80 @type func |
81 @param context security context object |
81 @param context security context object |
82 @type SecurityContext |
82 @type SecurityContext |
83 @param config dictionary with configuration data |
83 @param _config dictionary with configuration data (unused) |
84 @type dict |
84 @type dict |
85 """ |
85 """ |
86 node = context.node |
86 node = context.node |
87 if AWS_ACCESS_KEY_ID_REGEX.fullmatch(node.value): |
87 if AWS_ACCESS_KEY_ID_REGEX.fullmatch(node.value): |
88 entropy = shannonEntropy(node.value, AWS_ACCESS_KEY_ID_SYMBOLS) |
88 entropy = shannonEntropy(node.value, AWS_ACCESS_KEY_ID_SYMBOLS) |