feat(lab7): implement secure messenger infrastructure with TLS, OpenBao and observability
Skeleton contracts / contracts (pull_request) Blocked by required conditions
Skeleton contracts / contracts (pull_request) Blocked by required conditions
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
PKI_DIR="${LAB7_PKI_DIR:-$HOME/.local/share/mtusi2026lab7/pki}"
|
||||
|
||||
if [[ ! -f "$PKI_DIR/ca.crt" || ! -f "$PKI_DIR/ca.key" ]]; then
|
||||
echo "FAIL: existing CA certificate or key is missing"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -e "$PKI_DIR/openbao.crt" || -e "$PKI_DIR/openbao.key" ]]; then
|
||||
echo "FAIL: OpenBao TLS files already exist; refusing to overwrite"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
umask 077
|
||||
|
||||
WORK_DIR="$(mktemp -d)"
|
||||
trap 'rm -rf "$WORK_DIR"' EXIT
|
||||
|
||||
openssl genpkey \
|
||||
-algorithm RSA \
|
||||
-pkeyopt rsa_keygen_bits:3072 \
|
||||
-out "$WORK_DIR/openbao.key" 2>/dev/null
|
||||
|
||||
openssl req -new -sha256 \
|
||||
-key "$WORK_DIR/openbao.key" \
|
||||
-subj "/CN=openbao" \
|
||||
-out "$WORK_DIR/openbao.csr"
|
||||
|
||||
cat > "$WORK_DIR/openbao.ext" <<'EOF'
|
||||
basicConstraints=critical,CA:FALSE
|
||||
keyUsage=critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage=serverAuth
|
||||
subjectAltName=DNS:openbao,DNS:localhost,IP:127.0.0.1
|
||||
EOF
|
||||
|
||||
openssl x509 -req -sha256 \
|
||||
-in "$WORK_DIR/openbao.csr" \
|
||||
-CA "$PKI_DIR/ca.crt" \
|
||||
-CAkey "$PKI_DIR/ca.key" \
|
||||
-CAserial "$PKI_DIR/ca.srl" \
|
||||
-CAcreateserial \
|
||||
-out "$WORK_DIR/openbao.crt" \
|
||||
-days 365 \
|
||||
-extfile "$WORK_DIR/openbao.ext"
|
||||
|
||||
openssl verify \
|
||||
-CAfile "$PKI_DIR/ca.crt" \
|
||||
-purpose sslserver \
|
||||
-verify_hostname openbao \
|
||||
"$WORK_DIR/openbao.crt"
|
||||
|
||||
openssl verify \
|
||||
-CAfile "$PKI_DIR/ca.crt" \
|
||||
-purpose sslserver \
|
||||
-verify_hostname localhost \
|
||||
"$WORK_DIR/openbao.crt"
|
||||
|
||||
install -m 644 \
|
||||
"$WORK_DIR/openbao.crt" \
|
||||
"$PKI_DIR/openbao.crt"
|
||||
|
||||
# The OpenBao container runs with UID=100 and GID=1000.
|
||||
sudo install -o 100 -g 1000 -m 600 \
|
||||
"$WORK_DIR/openbao.key" \
|
||||
"$PKI_DIR/openbao.key"
|
||||
|
||||
echo "PASS: OpenBao TLS certificate issued"
|
||||
echo "PASS: existing CA trusted"
|
||||
echo "PASS: SAN contains openbao and localhost"
|
||||
echo "PASS: private key owned by UID=100 GID=1000"
|
||||
echo "PASS: private key permissions are 600"
|
||||
Reference in New Issue
Block a user