-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_clients.sh
More file actions
32 lines (24 loc) · 843 Bytes
/
Copy pathgenerate_clients.sh
File metadata and controls
32 lines (24 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
NUM_CLIENTS=$1
if [[ -z "$NUM_CLIENTS" ]]; then
echo "Usage: ./generate_clients.sh <number_of_clients>"
exit 1
fi
mkdir -p certs
# Check if CA files exist
if [[ ! -f certs/ca.crt || ! -f certs/ca.key ]]; then
echo "❌ Missing certs/ca.crt or certs/ca.key. Make sure the CA is set up."
exit 1
fi
for ((i = 1; i <= NUM_CLIENTS; i++)); do
CN="Client$i"
KEY="certs/client$i.key"
CSR="certs/client$i.csr"
CRT="certs/client$i.crt"
echo "🔐 Generating certificate for $CN..."
openssl genrsa -out "$KEY" 2048
openssl req -new -key "$KEY" -out "$CSR" -subj "/CN=$CN"
openssl x509 -req -in "$CSR" -CA certs/ca.crt -CAkey certs/ca.key -CAcreateserial -out "$CRT" -days 365 -sha256
rm "$CSR" # cleanup
done
echo "✅ Generated $NUM_CLIENTS client certificate(s) in certs/"