Skip to content

Commit

Permalink
Merge pull request #43 from valefar-on-discord/connectivity-warning
Browse files Browse the repository at this point in the history
Adding connectivity check and warning warning
  • Loading branch information
remyroy authored May 7, 2024
2 parents 2a22142 + 4080a18 commit ecd202a
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 6 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [Step 2. Create keys and `deposit_data-*.json`](#step-2-create-keys-and-deposit_data-json)
- [`language` Argument](#language-argument)
- [`--non_interactive` flag](#--non_interactive-flag)
- [`--ignore_connectivity` flag](#--ignore_connectivity-flag)
- [Commands](#commands)
- [`new-mnemonic` Arguments](#new-mnemonic-arguments)
- [`existing-mnemonic` Arguments](#existing-mnemonic-arguments)
Expand Down Expand Up @@ -67,6 +68,7 @@
- [Install basic requirements](#install-basic-requirements)
- [Install testing requirements](#install-testing-requirements)
- [Run tests](#run-tests)
- [Run the app](#run-the-app)
- [Building Binaries](#building-binaries)
- [Mac M1 Binaries](#mac-m1-binaries)

Expand Down Expand Up @@ -126,12 +128,20 @@ The Launchpad offers many language/internationalization options. If you wish to

###### `--non_interactive` flag

**Warning: with this flag, there will be no confirmation step(s) to verify the input value(s). Please use it carefully.**
**Warning: With this flag, there will be no confirmation step(s) to verify the input value(s). This will also ignore the connectivity check. Please use it carefully.**

| Argument | Type | Description |
| -------- | -------- | -------- |
| `--non_interactive` | Flag | Run CLI in non-interactive mode. |

###### `--ignore_connectivity` flag

**Warning: It is strongly recommended not to use this tool with internet access. Ignoring this check can further the risk of theft and compromise of your generated key material.**

| Argument | Type | Description |
| -------- | -------- | -------- |
| `--ignore_connectivity` | Flag | Skip internet connectivity check and warning. |

###### Commands

The CLI offers different commands depending on what you want to do with the tool.
Expand Down
35 changes: 31 additions & 4 deletions staking_deposit/deposit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import click
import socket
import sys

from staking_deposit.cli.existing_mnemonic import existing_mnemonic
Expand All @@ -24,11 +25,23 @@ def check_python_version() -> None:
'''
Checks that the python version running is sufficient and exits if not.
'''
if sys.version_info < (3, 7):
if sys.version_info < (3, 9):
click.pause(load_text(['err_python_version']))
sys.exit()


def check_connectivity() -> None:
'''
Checks if there is an internet connection and warns the user if so.
'''
try:
socket.setdefaulttimeout(2)
socket.getaddrinfo('icann.org', 80)
click.pause(load_text(['connectivity_warning']))
except OSError:
return None


@click.group()
@click.pass_context
@jit_option(
Expand All @@ -47,10 +60,25 @@ def check_python_version() -> None:
'--non_interactive',
default=False,
is_flag=True,
help='Disables interactive prompts. Warning: with this flag, there will be no confirmation step(s) to verify the input value(s). Please use it carefully.', # noqa: E501
help=(
'Disables interactive prompts. Warning: With this flag, there will be no confirmation step(s) to verify the '
'input value(s). This will also ignore the connectivity check. Please use it carefully.'
),
hidden=False,
)
@click.option(
'--ignore_connectivity',
default=False,
is_flag=True,
help=(
'Disables internet connectivity check. Warning: It is strongly recommended not to use this tool with internet '
'access. Ignoring this check can further the risk of theft and compromise of your generated key material.'
),
hidden=False,
)
def cli(ctx: click.Context, language: str, non_interactive: bool) -> None:
def cli(ctx: click.Context, language: str, non_interactive: bool, ignore_connectivity: bool) -> None:
if not ignore_connectivity and not non_interactive:
check_connectivity()
config.language = language
config.non_interactive = non_interactive # Remove interactive commands

Expand All @@ -64,7 +92,6 @@ def cli(ctx: click.Context, language: str, non_interactive: bool) -> None:

def run() -> None:
check_python_version()
print('\n***Using the tool on an offline and secure device is highly recommended to keep your mnemonic safe.***\n')
cli()


Expand Down
5 changes: 4 additions & 1 deletion staking_deposit/intl/en/deposit.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"check_python_version": {
"err_python_version": "Your python version is insufficient, please install version 3.12 or greater."
},
"check_connectivity": {
"connectivity_warning": "\n*** Internet connectivity detected ***\n\nTo mitigate the risk of unauthorized access and safeguard generated key material, it is strongly advised to run this tool in an offline, airgapped environment. Operating online increases susceptibility to potential theft or compromise.\n\nBy continuing, you are accepting responsibility for the risk.\n\nPress any key to continue..."
}
}
}
1 change: 1 addition & 0 deletions staking_deposit/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

language = 'en' # The CLI language selected by the user
non_interactive = False # Whether or not to interactively prompt the user for input. (Useful for tests and debugging)
ignore_connectivity = False # Whether or not the check for an active internet connection will be skipped
3 changes: 3 additions & 0 deletions tests/test_cli/test_existing_mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_existing_mnemonic_bls_withdrawal() -> None:
data = '\n'.join(inputs)
arguments = [
'--language', 'english',
'--ignore_connectivity',
'existing-mnemonic',
'--eth1_withdrawal_address', '',
'--folder', my_folder_path,
Expand Down Expand Up @@ -71,6 +72,7 @@ def test_existing_mnemonic_eth1_address_withdrawal() -> None:
data = '\n'.join(inputs)
arguments = [
'--language', 'english',
'--ignore_connectivity',
'existing-mnemonic',
'--folder', my_folder_path,
'--mnemonic_password', 'TREZOR',
Expand Down Expand Up @@ -129,6 +131,7 @@ def test_existing_mnemonic_eth1_address_withdrawal_bad_checksum() -> None:
data = '\n'.join(inputs)
arguments = [
'--language', 'english',
'--ignore_connectivity',
'existing-mnemonic',
'--folder', my_folder_path,
'--mnemonic_password', 'TREZOR',
Expand Down
1 change: 1 addition & 0 deletions tests/test_cli/test_generate_bls_to_execution_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def test_existing_mnemonic_bls_withdrawal_interactive() -> None:
data = '\n'.join(inputs)
arguments = [
'--language', 'english',
'--ignore_connectivity',
'generate-bls-to-execution-change',
'--bls_to_execution_changes_folder', my_folder_path,
]
Expand Down
5 changes: 5 additions & 0 deletions tests/test_cli/test_new_mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def mock_get_mnemonic(language, words_path, entropy=None) -> str:
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about']
data = '\n'.join(inputs)
arguments = [
'--ignore_connectivity',
'new-mnemonic',
'--eth1_withdrawal_address', '',
'--folder', my_folder_path,
Expand Down Expand Up @@ -84,6 +85,7 @@ def mock_get_mnemonic(language, words_path, entropy=None) -> str:
data = '\n'.join(inputs)
arguments = [
'--language', 'english',
'--ignore_connectivity',
'new-mnemonic',
'--folder', my_folder_path,
]
Expand Down Expand Up @@ -144,6 +146,7 @@ def mock_get_mnemonic(language, words_path, entropy=None) -> str:
data = '\n'.join(inputs)
arguments = [
'--language', 'english',
'--ignore_connectivity',
'new-mnemonic',
'--folder', my_folder_path,
]
Expand Down Expand Up @@ -199,6 +202,7 @@ def mock_get_mnemonic(language, words_path, entropy=None) -> str:
data = '\n'.join(inputs)
arguments = [
'--language', 'english',
'--ignore_connectivity',
'new-mnemonic',
'--folder', my_folder_path,
'--execution_address', execution_address, # execution_address and eth1_withdrawal_address are aliases
Expand Down Expand Up @@ -255,6 +259,7 @@ def mock_get_mnemonic(language, words_path, entropy=None) -> str:
data = '\n'.join(inputs)
arguments = [
'--language', 'english',
'--ignore_connectivity',
'new-mnemonic',
'--folder', my_folder_path,
'--execution_address', execution_address,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cli/test_regeneration.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def mock_get_mnemonic(language, words_path, entropy=None) -> str:
inputs = ['english', 'english', '2', 'mainnet', my_password, my_password, mock_mnemonic]
data = '\n'.join(inputs)
arguments = [
'--ignore_connectivity',
'new-mnemonic',
'--eth1_withdrawal_address', '',
'--folder', folder_path_1,
Expand Down Expand Up @@ -66,6 +67,7 @@ def mock_get_mnemonic(language, words_path, entropy=None) -> str:
'1', '1', '2', 'mainnet', 'MyPassword', 'MyPassword']
data = '\n'.join(inputs)
arguments = [
'--ignore_connectivity',
'existing-mnemonic',
'--eth1_withdrawal_address', '',
'--folder', folder_path_2,
Expand Down
Loading

0 comments on commit ecd202a

Please sign in to comment.