Skip to content

Commit feb508b

Browse files
authored
Create check_encryption.sh
1 parent 3e05301 commit feb508b

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

FreeRadius/check_encryption.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
#Color
4+
YELLOW='\033[1;33m'
5+
RED='\033[1;31m'
6+
BLUE='\033[1;34m'
7+
NOCOLOR='\033[0m'
8+
9+
# List of specific files to check (Modify as needed)
10+
FILES_TO_CHECK=(
11+
"clients.conf"
12+
"mods-available/ldap"
13+
)
14+
UNENCRYPTED_FOUND=0 # Flag to track unencrypted secrets
15+
16+
# Loop through the specified files
17+
for file in "${FILES_TO_CHECK[@]}"; do
18+
if [ ! -f "$file" ]; then
19+
echo "⚠️ Skipping $file (File not found)"
20+
continue
21+
fi
22+
23+
echo "🔎 Checking $file..."
24+
line_number=0 # Line Number counter
25+
while IFS= read -r line || [[ -n "$line" ]]; do
26+
line_number=$((line_number +1)) # +1 line the number
27+
28+
# Trim leading and trailing whitespace from the line
29+
trimmed_line=$(echo "$line" | awk '{$1=$1};1')
30+
31+
# Extract the key and value, trimming any extra spaces around them
32+
key=$(echo "$trimmed_line" | cut -d '=' -f 1 | awk '{$1=$1};1')
33+
value=$(echo "$trimmed_line" | cut -d '=' -f 2 | awk '{$1=$1};1')
34+
35+
# Check if the key is "secret" or "password" and the value does NOT start with "ENC:"
36+
if [[ "$key" == "secret" || "$key" == "password" ]] && [[ "$value" != ENC:* ]]; then
37+
echo -e ${YELLOW}"WARNING:${NOCOLOR} Unencrypted secret found in $file"
38+
echo -e ${YELLOW}"WARNING:${NOCOLOR} Line Number: $line_number"
39+
echo "⚠️ $line" >&2
40+
UNENCRYPTED_FOUND=1
41+
fi
42+
done < "$file"
43+
44+
45+
46+
done
47+
48+
# Final check: If no unencrypted secrets were found, exit successfully
49+
if [ "$UNENCRYPTED_FOUND" -eq 0 ]; then
50+
echo "✅ All secrets are encrypted."
51+
exit 0
52+
else
53+
echo -e ${RED}""ERROR:${NOCOLOR}" Some secret(s) are not encrypted!"
54+
echo -e ${BLUE}""INFO:${NOCOLOR}" All secrets and passwords must be encrypted before this file can be merged into main branch."
55+
exit 1
56+
fi
57+

0 commit comments

Comments
 (0)