|
| 1 | +import ssl |
| 2 | +import sys |
| 3 | +import traceback |
| 4 | + |
| 5 | +# --- WARNING: THIS SCRIPT DISABLES SSL VERIFICATION --- # |
| 6 | +# --- USE ONLY IF YOU TRUST YOUR NETWORK --- # |
| 7 | +# --- AND `camoufox fetch` FAILS DUE TO SSL --- # |
| 8 | + |
| 9 | +print("="*60) |
| 10 | +print("WARNING: This script will temporarily disable SSL certificate verification") |
| 11 | +print(" globally for this Python process to attempt fetching Camoufox data.") |
| 12 | +print(" This can expose you to security risks like man-in-the-middle attacks.") |
| 13 | +print("="*60) |
| 14 | + |
| 15 | +confirm = input("Do you understand the risks and want to proceed? (yes/NO): ").strip().lower() |
| 16 | + |
| 17 | +if confirm != 'yes': |
| 18 | + print("Operation cancelled by user.") |
| 19 | + sys.exit(0) |
| 20 | + |
| 21 | +print("\nAttempting to disable SSL verification...") |
| 22 | +original_ssl_context = None |
| 23 | +try: |
| 24 | + # Store the original context creation function |
| 25 | + if hasattr(ssl, '_create_default_https_context'): |
| 26 | + original_ssl_context = ssl._create_default_https_context |
| 27 | + |
| 28 | + # Get the unverified context creation function |
| 29 | + _create_unverified_https_context = ssl._create_unverified_context |
| 30 | + |
| 31 | + # Monkey patch the default context creation |
| 32 | + ssl._create_default_https_context = _create_unverified_https_context |
| 33 | + print("SSL verification temporarily disabled for this process.") |
| 34 | +except AttributeError: |
| 35 | + print("ERROR: Cannot disable SSL verification on this Python version (missing necessary SSL functions).") |
| 36 | + sys.exit(1) |
| 37 | +except Exception as e: |
| 38 | + print(f"ERROR: An unexpected error occurred while trying to disable SSL verification: {e}") |
| 39 | + traceback.print_exc() |
| 40 | + sys.exit(1) |
| 41 | + |
| 42 | +# Now, try to import and run the fetch command logic from camoufox |
| 43 | +print("\nAttempting to run Camoufox fetch logic...") |
| 44 | +fetch_success = False |
| 45 | +try: |
| 46 | + # The exact way to trigger fetch programmatically might differ. |
| 47 | + # This tries to import the CLI module and run the fetch command. |
| 48 | + from camoufox import cli |
| 49 | + # Simulate command line arguments: ['fetch'] |
| 50 | + # Note: cli.cli() might exit the process directly on completion or error. |
| 51 | + # We assume it might raise an exception or return normally. |
| 52 | + cli.cli(['fetch']) |
| 53 | + print("Camoufox fetch process seems to have completed.") |
| 54 | + # We assume success if no exception was raised and the process didn't exit. |
| 55 | + # A more robust check would involve verifying the downloaded files, |
| 56 | + # but that's beyond the scope of this simple script. |
| 57 | + fetch_success = True |
| 58 | +except ImportError: |
| 59 | + print("\nERROR: Could not import camoufox.cli. Make sure camoufox package is installed.") |
| 60 | + print(" Try running: pip show camoufox") |
| 61 | +except FileNotFoundError as e: |
| 62 | + print(f"\nERROR during fetch (FileNotFoundError): {e}") |
| 63 | + print(" This might indicate issues with file paths or permissions during download/extraction.") |
| 64 | + print(" Please check network connectivity and directory write permissions.") |
| 65 | +except SystemExit as e: |
| 66 | + # The CLI might use sys.exit(). We interpret non-zero exit codes as failure. |
| 67 | + if e.code == 0: |
| 68 | + print("Camoufox fetch process exited successfully (code 0).") |
| 69 | + fetch_success = True |
| 70 | + else: |
| 71 | + print(f"\nERROR: Camoufox fetch process exited with error code: {e.code}") |
| 72 | +except Exception as e: |
| 73 | + print(f"\nERROR: An unexpected error occurred while running camoufox fetch: {e}") |
| 74 | + traceback.print_exc() |
| 75 | +finally: |
| 76 | + # Attempt to restore the original SSL context |
| 77 | + if original_ssl_context: |
| 78 | + try: |
| 79 | + ssl._create_default_https_context = original_ssl_context |
| 80 | + print("\nOriginal SSL context restored.") |
| 81 | + except Exception as restore_e: |
| 82 | + print(f"\nWarning: Failed to restore original SSL context: {restore_e}") |
| 83 | + else: |
| 84 | + # If we couldn't store the original, we can't restore it. |
| 85 | + # The effect was process-local anyway. |
| 86 | + pass |
| 87 | + |
| 88 | +if fetch_success: |
| 89 | + print("\nFetch attempt finished. Please verify if Camoufox browser files were downloaded successfully.") |
| 90 | +else: |
| 91 | + print("\nFetch attempt failed or exited with an error.") |
| 92 | + |
| 93 | +print("Script finished.") |
0 commit comments