-
Notifications
You must be signed in to change notification settings - Fork 3
UNG 2711 #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
UNG 2711 #14
Changes from 34 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
8f67a1f
move pack example and extend it
UBOK19 653c5cd
add script to dump keystore contents
UBOK19 a770691
move verification example and extend it
UBOK19 95dd8f7
add script to send data and key registration upps
UBOK19 3f92456
move unpacker
UBOK19 670d7fa
add script to request anchoring status of an UPP
UBOK19 c783b00
distinguish between v1/v2 upps when splitting off the signature
UBOK19 0e6d2d2
fix tests
UBOK19 b8a614b
add a script to send data to the uBirch Simple Data Service
UBOK19 5b90291
fix old comment
UBOK19 caed463
only print anchoring information if the UPP is anchored
UBOK19 53bab4f
move and extend data verifier script
UBOK19 b960adc
fix result displaying
UBOK19 f0ec062
add ability to serialize json before creating the hash for the UPP
UBOK19 5fc0190
fix invalid indentation
UBOK19 3775c12
fix parameter description
UBOK19 25a15fb
add documentation for some examples
UBOK19 4636086
remove old comment
UBOK19 c47c537
fix typo
UBOK19 2bec84b
add documentation for keystore dumper script
UBOK19 887a82a
Reviewed and corrected EXAMPLES.md
4b58c55
.
UBOK19 e7812ab
fix incomplete toc
UBOK19 44d64a2
test-identity try to solve broken reference
5c6debc
solve broken reference links
6b48d13
add option to only generate data hash without verifying it
UBOK19 76c7ce8
fix typo in usage info
UBOK19 701a60c
add hashlink functionality to data verifier and upp creator scripts
UBOK19 d0d510c
print used hashing method to prevent confusion
UBOK19 06b1b44
update the readme to have some info about hashlink
UBOK19 ec56fad
add ability to read hex encoded upps as input to the upp verifier
UBOK19 f0d94e8
add hex-input support for the anchoring status script
UBOK19 ede1d65
add a script to check chains of upps (upp-chaining)
UBOK19 b33e3a6
add docs for the chain-checker script
UBOK19 56bff97
adapt changes from review to the readme
UBOK19 71a6a1c
include changes from review
UBOK19 2c59f53
[from review] replace old print statement with logger.x
UBOK19 9c3027e
initialize ishex and ishex_str in __init__ before using it in setup_a…
UBOK19 f4cb6e1
adapt changes from review
UBOK19 725ec4b
adapt changes from review
UBOK19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| ) | ||
| 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()) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.