| #!/bin/bash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| set -e
|
|
|
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
| REPO_ROOT="$(dirname "$SCRIPT_DIR")"
|
| SOVEREIGN_DIR="$REPO_ROOT/sovereign"
|
|
|
|
|
|
|
|
|
|
|
| echo "[1/5] Locating authorization record..."
|
|
|
| if [ ! -f "$SOVEREIGN_DIR/authorization.json" ]; then
|
| echo "ERROR: Authorization record not found"
|
| echo "Expected: $SOVEREIGN_DIR/authorization.json"
|
| exit 2
|
| fi
|
|
|
| echo " β Authorization record found"
|
|
|
|
|
|
|
|
|
|
|
| echo "[2/5] Locating node identity..."
|
|
|
| if [ ! -f "$SOVEREIGN_DIR/node.json" ]; then
|
| echo "ERROR: Node identity not found"
|
| exit 2
|
| fi
|
|
|
| echo " β Node identity found"
|
|
|
|
|
|
|
|
|
|
|
| echo "[3/5] Parsing authorization record..."
|
|
|
|
|
| AUTH_ID=$(grep 'authorization_id' "$SOVEREIGN_DIR/authorization.json" | head -1 | sed 's/.*"authorization_id": "\([^"]*\)".*/\1/' || echo "")
|
| NODE_ID=$(grep 'node_id' "$SOVEREIGN_DIR/authorization.json" | head -1 | sed 's/.*"node_id": "\([^"]*\)".*/\1/' || echo "")
|
| STATUS=$(grep 'authorization_status' "$SOVEREIGN_DIR/authorization.json" | head -1 | sed 's/.*"authorization_status": "\([^"]*\)".*/\1/' || echo "")
|
| SCOPE=$(grep 'authorization_scope' "$SOVEREIGN_DIR/authorization.json" | head -1 | sed 's/.*"authorization_scope": "\([^"]*\)".*/\1/' || echo "")
|
| EXPIRES=$(grep 'expires_at_utc' "$SOVEREIGN_DIR/authorization.json" | head -1 | sed 's/.*"expires_at_utc": \(null\|"[^"]*"\).*/\1/' | tr -d '"' || echo "null")
|
| REVOKED=$(grep 'revocation_status' "$SOVEREIGN_DIR/authorization.json" | head -1 | sed 's/.*"revocation_status": "\([^"]*\)".*/\1/' || echo "")
|
|
|
| if [ -z "$AUTH_ID" ] || [ -z "$NODE_ID" ] || [ -z "$STATUS" ]; then
|
| echo "ERROR: Authorization record malformed"
|
| exit 2
|
| fi
|
|
|
| echo " Authorization ID: $AUTH_ID"
|
| echo " Node ID: $NODE_ID"
|
| echo " Status: $STATUS"
|
| echo " Scope: $SCOPE"
|
|
|
|
|
|
|
|
|
|
|
| echo "[4/5] Validating authorization status..."
|
|
|
|
|
| case "$STATUS" in
|
| ACTIVE)
|
| echo " β Status is ACTIVE"
|
| ;;
|
| REQUESTED)
|
| echo " β Status is REQUESTED (not yet authorized)"
|
| exit 1
|
| ;;
|
| SUSPENDED)
|
| echo " β Status is SUSPENDED"
|
| exit 1
|
| ;;
|
| REVOKED)
|
| echo " β Status is REVOKED"
|
| exit 1
|
| ;;
|
| EXPIRED)
|
| echo " β Status is EXPIRED"
|
| exit 1
|
| ;;
|
| *)
|
| echo " β Unknown authorization status: $STATUS"
|
| exit 2
|
| ;;
|
| esac
|
|
|
|
|
| case "$REVOKED" in
|
| ACTIVE)
|
| echo " β Revocation status is ACTIVE (not revoked)"
|
| ;;
|
| REVOKED)
|
| echo " β Revocation status is REVOKED"
|
| exit 1
|
| ;;
|
| *)
|
| echo " β Unknown revocation status: $REVOKED"
|
| exit 2
|
| ;;
|
| esac
|
|
|
|
|
| if [ "$EXPIRES" != "null" ]; then
|
| CURRENT_TIME=$(date +%s 2>/dev/null || echo "0")
|
| EXPIRATION_TIME=$(date -d "$EXPIRES" +%s 2>/dev/null || date -j -f "%Y-%m-%dT%H:%M:%SZ" "$EXPIRES" +%s 2>/dev/null || echo "0")
|
|
|
| if [ "$CURRENT_TIME" -gt "$EXPIRATION_TIME" ]; then
|
| echo " β Authorization has expired ($EXPIRES)"
|
| exit 1
|
| fi
|
| echo " β Authorization not expired (expires $EXPIRES)"
|
| fi
|
|
|
|
|
|
|
|
|
|
|
| echo "[5/5] Verifying node identity consistency..."
|
|
|
| LOCAL_NODE_ID=$(grep 'node_id' "$SOVEREIGN_DIR/node.json" | head -1 | sed 's/.*"node_id": "\([^"]*\)".*/\1/' || echo "")
|
|
|
| if [ "$LOCAL_NODE_ID" != "$NODE_ID" ]; then
|
| echo " β Node ID mismatch"
|
| echo " Authorization: $NODE_ID"
|
| echo " Local node: $LOCAL_NODE_ID"
|
| exit 2
|
| fi
|
|
|
| echo " β Node identity matches"
|
|
|
|
|
|
|
|
|
|
|
| echo ""
|
| echo "=========================================="
|
| echo "AUTHORIZATION_STATUS: VALID"
|
| echo "=========================================="
|
| echo ""
|
| echo "Node $NODE_ID is authorized for:"
|
| echo " Scope: $SCOPE"
|
| echo " Authorization: $AUTH_ID"
|
| echo " Status: $STATUS"
|
| echo ""
|
|
|
| exit 0
|
|
|