Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8f67a1f
move pack example and extend it
UBOK19 Jun 28, 2021
653c5cd
add script to dump keystore contents
UBOK19 Jun 28, 2021
a770691
move verification example and extend it
UBOK19 Jun 28, 2021
95dd8f7
add script to send data and key registration upps
UBOK19 Jun 28, 2021
3f92456
move unpacker
UBOK19 Jun 28, 2021
670d7fa
add script to request anchoring status of an UPP
UBOK19 Jun 28, 2021
c783b00
distinguish between v1/v2 upps when splitting off the signature
UBOK19 Jun 28, 2021
0e6d2d2
fix tests
UBOK19 Jun 28, 2021
b8a614b
add a script to send data to the uBirch Simple Data Service
UBOK19 Jul 1, 2021
5b90291
fix old comment
UBOK19 Jul 1, 2021
caed463
only print anchoring information if the UPP is anchored
UBOK19 Jul 1, 2021
53bab4f
move and extend data verifier script
UBOK19 Jul 1, 2021
b960adc
fix result displaying
UBOK19 Jul 1, 2021
f0ec062
add ability to serialize json before creating the hash for the UPP
UBOK19 Jul 1, 2021
5fc0190
fix invalid indentation
UBOK19 Jul 2, 2021
3775c12
fix parameter description
UBOK19 Jul 2, 2021
25a15fb
add documentation for some examples
UBOK19 Jul 2, 2021
4636086
remove old comment
UBOK19 Jul 2, 2021
c47c537
fix typo
UBOK19 Jul 2, 2021
2bec84b
add documentation for keystore dumper script
UBOK19 Jul 2, 2021
887a82a
Reviewed and corrected EXAMPLES.md
Jul 5, 2021
4b58c55
.
UBOK19 Jul 6, 2021
e7812ab
fix incomplete toc
UBOK19 Jul 7, 2021
44d64a2
test-identity try to solve broken reference
Jul 8, 2021
5c6debc
solve broken reference links
Jul 8, 2021
6b48d13
add option to only generate data hash without verifying it
UBOK19 Sep 4, 2021
76c7ce8
fix typo in usage info
UBOK19 Oct 12, 2021
701a60c
add hashlink functionality to data verifier and upp creator scripts
UBOK19 Oct 12, 2021
d0d510c
print used hashing method to prevent confusion
UBOK19 Oct 15, 2021
06b1b44
update the readme to have some info about hashlink
UBOK19 Oct 15, 2021
ec56fad
add ability to read hex encoded upps as input to the upp verifier
UBOK19 Oct 21, 2021
f0d94e8
add hex-input support for the anchoring status script
UBOK19 Nov 7, 2021
ede1d65
add a script to check chains of upps (upp-chaining)
UBOK19 Nov 7, 2021
b33e3a6
add docs for the chain-checker script
UBOK19 Nov 7, 2021
56bff97
adapt changes from review to the readme
UBOK19 Nov 16, 2021
71a6a1c
include changes from review
UBOK19 Nov 16, 2021
2c59f53
[from review] replace old print statement with logger.x
UBOK19 Nov 16, 2021
9c3027e
initialize ishex and ishex_str in __init__ before using it in setup_a…
UBOK19 Nov 16, 2021
f4cb6e1
adapt changes from review
UBOK19 Nov 16, 2021
725ec4b
adapt changes from review
UBOK19 Nov 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
455 changes: 455 additions & 0 deletions examples/EXAMPLES.md

Large diffs are not rendered by default.

145 changes: 145 additions & 0 deletions examples/data-sender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import sys
import logging
import argparse
import msgpack
import requests
import binascii
import uuid

import ubirch


DEFAULT_ENV = "dev"


logging.basicConfig(format='%(asctime)s %(name)20.20s %(funcName)20.20s() %(levelname)-8.8s %(message)s', level=logging.INFO)
logger = logging.getLogger()


class Main:
def __init__(self):
self.argparser : argparse.ArgumentParser = None
self.args : argparse.Namespace = None

self.uuid_str : str = None
self.uuid : uuid.UUID = None
self.auth : str = None
self.env : str = None
self.input : str = None

self.api : ubirch.API = None

# initialize the argument parser
self.setup_argparse()

return

def setup_argparse(self):
self.argparser = argparse.ArgumentParser(
description="Send some data to the uBirch Simple Data Service",
epilog="Note that the input data should follow this pattern: "
"{\"timestamp\": TIMESTAMP, \"uuid\": \"UUID\", \"msg_type\": 0, \"data\": DATA, \"hash\": \"UPP_HASH\"}. "
"For more information take a look at the EXAMPLES.md file."
)

self.argparser.add_argument("uuid", metavar="UUID", type=str,
help="UUID to work with; e.g.: 56bd9b85-6c6e-4a24-bf71-f2ac2de10183"
)
self.argparser.add_argument("auth", metavar="AUTH", type=str,
help="uBirch device authentication token, e.g.: 12345678-1234-1234-1234-123456789abc (this is NOT the UUID)"
)
self.argparser.add_argument("--env", "-e", metavar="ENV", type=str, default=DEFAULT_ENV,
help="environment to operate in; dev, demo or prod (default: %s)" % DEFAULT_ENV
)
self.argparser.add_argument("input", metavar="INPUT", type=str,
help="data to be sent to the simple data service"
)

return

def process_args(self) -> bool:
# parse cli arguments (exists on err)
self.args = self.argparser.parse_args()

# get all needed args
self.uuid_str = self.args.uuid
self.auth = self.args.auth
self.env = self.args.env
self.input = self.args.input

# process the uuid
try:
self.uuid = uuid.UUID(hex=self.uuid_str)
except Exception as e:
logger.error("Invalid UUID: \"%s\"" % self.uuid_str)
logger.exception(e)

return False

# validate env
if self.env.lower() not in ["dev", "demo", "prod"]:
logger.error("Invalid value for --env: \"%s\"!" % self.env)

return False

return True

def init_api(self) -> bool:
try:
# initialize the uBirch api
self.api = ubirch.API(env=self.env, debug=True)
self.api.set_authentication(self.uuid, self.auth)
except Exception as e:
logger.exception(e)

return False

return True

def send_data(self) -> bool:
try:
r = self.api.send_data(self.uuid, self.input.encode())

# check the response
if r.status_code == 200:
logger.info("Successfully sent all data to the Simple Data Service! (%d)" % r.status_code)
else:
logger.error("Failed to send data to the Simple Data Service! (%d)" % r.status_code)
logger.error(r.content)
except Exception as e:
logger.exception(e)

return False

return True

def run(self):
# process all args
if self.process_args() != True:
logger.error("Errors occured during argument processing - exiting!\n")

self.argparser.print_usage()

return 1

# initialize the api
if self.init_api() != True:
logger.error("Errors occured while initializing the uBirch API - exiting!\n")

self.argparser.print_usage()

return 1

# send data
if self.send_data() != True:
logger.error("Errors occured while sending data to the simple data service - exiting!\n")

self.argparser.print_usage()

return 1

return 0


if __name__ == "__main__":
sys.exit(Main().run())
Loading