pisa -> teos

This commit is contained in:
Sergi Delgado Segura
2020-03-17 13:05:55 +01:00
parent 15126618d5
commit 7c7ff909d7
56 changed files with 373 additions and 372 deletions

View File

@@ -1,10 +1,10 @@
# Dependencies
`wt_cli` has both system-wide and Python dependencies. This document walks you through how to satisfy them.
`teos_cli` has both system-wide and Python dependencies. This document walks you through how to satisfy them.
## System-wide dependencies
`wt_cli` has the following system-wide dependencies:
`teos_cli` has the following system-wide dependencies:
- `python3`
- `pip3`
@@ -27,7 +27,7 @@ It is also likely that, if `python3` is installed in our system, the `python` al
python3 --version
If `python3` is installed but the `python` alias is not set to it, we should either set it, or use `python3` to run `wt_cli`.
If `python3` is installed but the `python` alias is not set to it, we should either set it, or use `python3` to run `teos_cli`.
Regarding `pip`, we can check what version is installed in our system (if any) by running:
@@ -74,7 +74,7 @@ and for `pip3`:
## Python dependencies
`wt_cli` has the following dependencies (which can be satisfied by using `pip install -r requirements.txt`):
`teos_cli` has the following dependencies (which can be satisfied by using `pip install -r requirements.txt`):
- `cryptography`
- `requests`

View File

@@ -1,11 +1,11 @@
# Install
`wt_cli` has some dependencies that can be satisfied by following [DEPENDENCIES.md](DEPENDENCIES.md). If your system already satisfies the dependencies, you can skip that part.
`teos_cli` has some dependencies that can be satisfied by following [DEPENDENCIES.md](DEPENDENCIES.md). If your system already satisfies the dependencies, you can skip that part.
There are two ways of running `wt_cli`: adding the library to the `PYTHONPATH` env variable, or running it as a module.
There are two ways of running `teos_cli`: adding the library to the `PYTHONPATH` env variable, or running it as a module.
## Modifying `PYTHONPATH`
In order to run `wt_cli`, you should set your `PYTHONPATH` env variable to include the folder that contains the `apps` folder. You can do so by running:
In order to run `teos_cli`, you should set your `PYTHONPATH` env variable to include the folder that contains the `apps` folder. You can do so by running:
export PYTHONPATH=$PYTHONPATH:<absolute_path_to_apps>
@@ -17,17 +17,17 @@ You should also include the command in your `.bashrc` to avoid having to run it
echo 'export PYTHONPATH=$PYTHONPATH:<absolute_path_to_apps>' >> ~/.bashrc
Once the `PYTHONPATH` is set, you should be able to run `wt_cli` straightaway. Try it by running:
Once the `PYTHONPATH` is set, you should be able to run `teos_cli` straightaway. Try it by running:
cd <absolute_path_to_apps>/apps/cli
python wt_cli.py -h
python teos_cli.py -h
## Running `wt_cli` as a module
## Running `teos_cli` as a module
Python code can be also run as a module, to do so you need to use `python -m`. From `apps` **parent** directory run:
python -m apps.cli.wt_cli -h
python -m apps.cli.teos_cli -h
Notice that if you run `wt_cli` as a module, you'll need to replace all the calls from `python wt_cli.py <argument>` to `python -m apps.cli.wt_cli <argument>`
Notice that if you run `teos_cli` as a module, you'll need to replace all the calls from `python teos_cli.py <argument>` to `python -m apps.cli.teos_cli <argument>`
## Modify configuration parameters
If you'd like to modify some of the configuration defaults (such as the user directory, where the logs and appointment receipts will be stored) you can do so in the config file located at:

View File

@@ -1,6 +1,6 @@
# wt_cli
# teos_cli
`wt_cli` is a command line interface to interact with the Eye of Satoshi watchtower server, written in Python3.
`teos_cli` is a command line interface to interact with the Eye of Satoshi watchtower server, written in Python3.
## Dependencies
Refer to [DEPENDENCIES.md](DEPENDENCIES.md)
@@ -11,7 +11,7 @@ Refer to [INSTALL.md](INSTALL.md)
## Usage
python wt_cli.py [global options] command [command options] [arguments]
python teos_cli.py [global options] command [command options] [arguments]
#### Global options
@@ -59,7 +59,7 @@ The alpha release does not have authentication, payments nor rate limiting, ther
#### Usage
python wt_cli.py add_appointment [command options] <appointment>/<path_to_appointment_file>
python teos_cli.py add_appointment [command options] <appointment>/<path_to_appointment_file>
if `-f, --file` **is** specified, then the command expects a path to a json file instead of a json encoded string as parameter.
@@ -103,7 +103,7 @@ if `-f, --file` **is** specified, then the command expects a path to a json file
#### Usage
python wt_cli.py get_appointment <appointment_locator>
python teos_cli.py get_appointment <appointment_locator>
@@ -112,11 +112,11 @@ if `-f, --file` **is** specified, then the command expects a path to a json file
Shows the list of commands or help about how to run a specific command.
#### Usage
python wt_cli.py help
python teos_cli.py help
or
python wt_cli.py help command
python teos_cli.py help command
## Example
@@ -131,7 +131,7 @@ or
2. Send the appointment to the tower API. Which will then start monitoring for matching transactions.
```
python wt_cli.py add_appointment -f dummy_appointment_data.json
python teos_cli.py add_appointment -f dummy_appointment_data.json
```
This returns a appointment locator that can be used to get updates about this appointment from the tower.
@@ -139,20 +139,20 @@ or
3. Test that the tower is still watching the appointment by replacing the appointment locator received into the following command:
```
python wt_cli.py get_appointment <appointment_locator>
python teos_cli.py get_appointment <appointment_locator>
```
## the Eye of Satoshi's API
If you wish to read about the underlying API, and how to write your own tool to interact with it, refer to [tEOS-API.md](tEOS-API.md).
If you wish to read about the underlying API, and how to write your own tool to interact with it, refer to [tEOS-API.md](TEOS-API.md).
## Are you reckless? Try me on mainnet
Would you like to try me on `mainnet` instead of `testnet`? Add `-s https://mainnet.teos.pisa.watch` to your calls, for example:
```
python wt_cli.py -s https://teosmainnet.pisa.watch add_appointment -f dummy_appointment_data.json
python teos_cli.py -s https://teosmainnet.pisa.watch add_appointment -f dummy_appointment_data.json
```
You can also change the config file to avoid specifying the server every time:
`DEFAULT_PISA_API_SERVER = "https://teosmainnet.pisa.watch"`
`DEFAULT_TEOS_API_SERVER = "https://teosmainnet.pisa.watch"`

View File

@@ -6,14 +6,14 @@ LOG_PREFIX = "cli"
# Load config fields
conf_fields = {
"DEFAULT_PISA_API_SERVER": {"value": conf.DEFAULT_PISA_API_SERVER, "type": str},
"DEFAULT_PISA_API_PORT": {"value": conf.DEFAULT_PISA_API_PORT, "type": int},
"DEFAULT_TEOS_API_SERVER": {"value": conf.DEFAULT_TEOS_API_SERVER, "type": str},
"DEFAULT_TEOS_API_PORT": {"value": conf.DEFAULT_TEOS_API_PORT, "type": int},
"DATA_FOLDER": {"value": conf.DATA_FOLDER, "type": str},
"CLIENT_LOG_FILE": {"value": conf.CLIENT_LOG_FILE, "type": str, "path": True},
"APPOINTMENTS_FOLDER_NAME": {"value": conf.APPOINTMENTS_FOLDER_NAME, "type": str, "path": True},
# "CLI_PUBLIC_KEY": {"value": conf.CLI_PUBLIC_KEY, "type": str, "path": True},
# "CLI_PRIVATE_KEY": {"value": conf.CLI_PRIVATE_KEY, "type": str, "path": True},
# "PISA_PUBLIC_KEY": {"value": conf.PISA_PUBLIC_KEY, "type": str, "path": True},
# "TEOS_PUBLIC_KEY": {"value": conf.TEOS_PUBLIC_KEY, "type": str, "path": True},
}
# Expand user (~) if found and check fields are correct

View File

@@ -1,9 +1,9 @@
def help_add_appointment():
return (
"NAME:"
"\tpython wt_cli add_appointment - Registers a json formatted appointment to the tower."
"\tpython teos_cli add_appointment - Registers a json formatted appointment to the tower."
"\n\nUSAGE:"
"\tpython wt_cli add_appointment [command options] appointment/path_to_appointment_file"
"\tpython teos_cli add_appointment [command options] appointment/path_to_appointment_file"
"\n\nDESCRIPTION:"
"\n\n\tRegisters a json formatted appointment to the tower."
"\n\tif -f, --file *is* specified, then the command expects a path to a json file instead of a json encoded "
@@ -17,9 +17,9 @@ def help_add_appointment():
def help_get_appointment():
return (
"NAME:"
"\tpython wt_cli get_appointment - Gets json formatted data about an appointment from the tower."
"\tpython teos_cli get_appointment - Gets json formatted data about an appointment from the tower."
"\n\nUSAGE:"
"\tpython wt_cli get_appointment appointment_locator"
"\tpython teos_cli get_appointment appointment_locator"
"\n\nDESCRIPTION:"
"\n\n\tGets json formatted data about an appointment from the tower.\n"
)

View File

@@ -1,9 +1,9 @@
# PISA-WT-SERVER
DEFAULT_PISA_API_SERVER = "https://teos.pisa.watch"
DEFAULT_PISA_API_PORT = 443
# TEOS-SERVER
DEFAULT_TEOS_API_SERVER = "https://teos.pisa.watch"
DEFAULT_TEOS_API_PORT = 443
# WT-CLI
DATA_FOLDER = "~/.wt_cli/"
DATA_FOLDER = "~/.teos_cli/"
CLIENT_LOG_FILE = "cli.log"
APPOINTMENTS_FOLDER_NAME = "appointment_receipts"

View File

@@ -1,4 +1,4 @@
## tEOS-API
## TEOS-API
### Disclaimer: Everything in here is experimental and subject to change.

View File

@@ -24,26 +24,26 @@ from common.tools import check_sha256_hex_format, check_locator_format, compute_
logger = Logger(actor="Client", log_name_prefix=LOG_PREFIX)
common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix=LOG_PREFIX)
# FIXME: creating a simpler load_keys for the alpha. Client keys will not be necessary. PISA key is hardcoded.
# def load_keys(pisa_pk_path, cli_sk_path, cli_pk_path):
# FIXME: creating a simpler load_keys for the alpha. Client keys will not be necessary. TEOS key is hardcoded.
# def load_keys(teos_pk_path, cli_sk_path, cli_pk_path):
# """
# Loads all the keys required so sign, send, and verify the appointment.
#
# Args:
# pisa_pk_path (:obj:`str`): path to the PISA public key file.
# teos_pk_path (:obj:`str`): path to the TEOS public key file.
# cli_sk_path (:obj:`str`): path to the client private key file.
# cli_pk_path (:obj:`str`): path to the client public key file.
#
# Returns:
# :obj:`tuple` or ``None``: a three item tuple containing a pisa_pk object, cli_sk object and the cli_sk_der
# :obj:`tuple` or ``None``: a three item tuple containing a teos_pk object, cli_sk object and the cli_sk_der
# encoded key if all keys can be loaded. ``None`` otherwise.
# """
#
# pisa_pk_der = Cryptographer.load_key_file(pisa_pk_path)
# pisa_pk = Cryptographer.load_public_key_der(pisa_pk_der)
# teos_pk_der = Cryptographer.load_key_file(teos_pk_path)
# teos_pk = Cryptographer.load_public_key_der(teos_pk_der)
#
# if pisa_pk is None:
# logger.error("PISA's public key file not found. Please check your settings")
# if teos_pk is None:
# logger.error("TEOS's public key file not found. Please check your settings")
# return None
#
# cli_sk_der = Cryptographer.load_key_file(cli_sk_path)
@@ -59,14 +59,14 @@ common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix=LOG_
# logger.error("Client's public key file not found. Please check your settings")
# return None
#
# return pisa_pk, cli_sk, cli_pk_der
# return teos_pk, cli_sk, cli_pk_der
def load_keys():
PISA_PUBLIC_KEY = "0230053e39c53b8bcb43354a4ed886b8082af1d1e8fc14956e60ad0592bfdfab51"
pisa_pk = PublicKey(binascii.unhexlify(PISA_PUBLIC_KEY))
TEOS_PUBLIC_KEY = "0230053e39c53b8bcb43354a4ed886b8082af1d1e8fc14956e60ad0592bfdfab51"
teos_pk = PublicKey(binascii.unhexlify(TEOS_PUBLIC_KEY))
return pisa_pk
return teos_pk
def add_appointment(args):
@@ -95,9 +95,9 @@ def add_appointment(args):
:obj:`bool`: True if the appointment is accepted by the tower and the receipt is properly stored, false if any
error occurs during the process.
"""
# FIXME: creating a simpler load_keys for the alpha. Client keys will not be necessary. PISA key is hardcoded.
# pisa_pk, cli_sk, cli_pk_der = load_keys(
# config.get("PISA_PUBLIC_KEY"), config.get("CLI_PRIVATE_KEY"), config.get("CLI_PUBLIC_KEY")
# FIXME: creating a simpler load_keys for the alpha. Client keys will not be necessary. TEOS key is hardcoded.
# teos_pk, cli_sk, cli_pk_der = load_keys(
# config.get("TEOS_PUBLIC_KEY"), config.get("CLI_PRIVATE_KEY"), config.get("CLI_PUBLIC_KEY")
# )
#
# try:
@@ -106,9 +106,9 @@ def add_appointment(args):
# except binascii.Error as e:
# logger.error("Could not successfully encode public key as hex", error=str(e))
# return False
pisa_pk = load_keys()
teos_pk = load_keys()
if pisa_pk is None:
if teos_pk is None:
return False
# Get appointment data from user.
@@ -163,7 +163,7 @@ def add_appointment(args):
return False
rpk = Cryptographer.recover_pk(appointment.serialize(), signature)
if not Cryptographer.verify_rpk(pisa_pk, rpk):
if not Cryptographer.verify_rpk(teos_pk, rpk):
logger.error("The returned appointment's signature is invalid")
return False
@@ -237,7 +237,7 @@ def post_appointment(data):
logger.info("Sending appointment to the Eye of Satoshi")
try:
add_appointment_endpoint = "{}:{}".format(pisa_api_server, pisa_api_port)
add_appointment_endpoint = "{}:{}".format(teos_api_server, teos_api_port)
return requests.post(url=add_appointment_endpoint, json=json.dumps(data), timeout=5)
except ConnectTimeout:
@@ -347,7 +347,7 @@ def get_appointment(locator):
logger.error("The provided locator is not valid", locator=locator)
return None
get_appointment_endpoint = "{}:{}/get_appointment".format(pisa_api_server, pisa_api_port)
get_appointment_endpoint = "{}:{}/get_appointment".format(teos_api_server, teos_api_port)
parameters = "?locator={}".format(locator)
try:
@@ -372,7 +372,7 @@ def get_appointment(locator):
def show_usage():
return (
"USAGE: "
"\n\tpython wt_cli.py [global options] command [command options] [arguments]"
"\n\tpython teos_cli.py [global options] command [command options] [arguments]"
"\n\nCOMMANDS:"
"\n\tadd_appointment \tRegisters a json formatted appointment with the tower."
"\n\tget_appointment \tGets json formatted data about an appointment from the tower."
@@ -381,14 +381,14 @@ def show_usage():
"\n\t-s, --server \tAPI server where to send the requests. Defaults to https://teos.pisa.watch (modifiable in "
"config.py)"
"\n\t-p, --port \tAPI port where to send the requests. Defaults to 443 (modifiable in conf.py)"
"\n\t-d, --debug \tshows debug information and stores it in wt_cli.log"
"\n\t-d, --debug \tshows debug information and stores it in teos_cli.log"
"\n\t-h --help \tshows this message."
)
if __name__ == "__main__":
pisa_api_server = config.get("DEFAULT_PISA_API_SERVER")
pisa_api_port = config.get("DEFAULT_PISA_API_PORT")
teos_api_server = config.get("DEFAULT_TEOS_API_SERVER")
teos_api_port = config.get("DEFAULT_TEOS_API_PORT")
commands = ["add_appointment", "get_appointment", "help"]
try:
@@ -397,11 +397,11 @@ if __name__ == "__main__":
for opt, arg in opts:
if opt in ["-s", "server"]:
if arg:
pisa_api_server = arg
teos_api_server = arg
if opt in ["-p", "--port"]:
if arg:
pisa_api_port = int(arg)
teos_api_port = int(arg)
if opt in ["-h", "--help"]:
sys.exit(show_usage())

View File

@@ -8,7 +8,7 @@ from cryptography.hazmat.primitives.asymmetric import ec
# Simple tool to generate an ECDSA private key using the secp256k1 curve and save private and public keys
# as 'pisa_sk.der' 'and pisa_pk.der', respectively.
# as 'teos_sk.der' 'and teos_pk.der', respectively.
def save_sk(sk, filename):
@@ -29,7 +29,7 @@ def save_pk(pk, filename):
if __name__ == "__main__":
name = "pisa"
name = "teos"
output_dir = "."
opts, _ = getopt(argv[1:], "n:d:", ["name", "dir"])