#!/bin/bash # Example Key Setup Script # Demonstrates how to use the key management tools set -e # Colors for output GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo -e "${GREEN}Emergency Access Key Management Example${NC}" echo "==========================================" # Check if we're in the right directory if [[ ! -f "add_key.py" || ! -f "manage_keys.py" ]]; then echo "Error: Please run this script from the emergency-access directory" exit 1 fi echo echo -e "${YELLOW}1. Generating passwords for default keys...${NC}" python3 generate_passwords.py --keys backup master recovery --hide-passwords echo echo -e "${YELLOW}2. Adding a backup key interactively...${NC}" echo " (This would normally be interactive - showing programmatic example instead)" # Example of adding a key programmatically python3 add_key.py --key-id example_backup \ --file /tmp/emergency-access-example/backup-key.txt \ --backends matrix_sec,email_emergency \ --message "🚨 EMERGENCY: Backup key accessed from server" \ --create-file \ --key-content "# Example backup key content\nBACKUP_KEY=example_key_content_here\n" \ --config config.json.example || echo "Key already exists or config not found" echo echo -e "${YELLOW}3. Listing all configured keys...${NC}" python3 add_key.py --list --config config.json.example || echo "Using example config" echo echo -e "${YELLOW}4. Checking key file status...${NC}" python3 manage_keys.py --list-files --config config.json.example || echo "Using example config" echo echo -e "${YELLOW}5. Generating different types of key content...${NC}" echo "SSH Key:" python3 manage_keys.py --generate-content ssh | head -3 echo echo "API Key:" python3 manage_keys.py --generate-content api echo echo "Password:" python3 manage_keys.py --generate-content password echo echo -e "${YELLOW}6. Example testing (requires running server)...${NC}" echo "To test key access when server is running:" echo " python3 manage_keys.py --test-key backup_key --password 'your_password'" echo " python3 manage_keys.py --test-health --password 'health_password'" echo echo -e "${GREEN}Key Management Commands Summary:${NC}" echo "================================" echo echo "Add keys:" echo " python3 add_key.py --interactive" echo " python3 add_key.py --key-id NAME --file /path --backends backend1,backend2" echo echo "Manage keys:" echo " python3 manage_keys.py --list-files" echo " python3 manage_keys.py --validate" echo " python3 manage_keys.py --rotate-key NAME --key-type ssh" echo echo "Generate passwords:" echo " python3 generate_passwords.py --keys key1 key2" echo " python3 generate_passwords.py --interactive" echo echo "Test access:" echo " python3 manage_keys.py --test-key NAME --password PASSWORD" echo " python3 manage_keys.py --test-health --password PASSWORD" echo echo -e "${GREEN}Example complete!${NC}" echo "See README.md for more detailed usage information."