-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from ubirch/dev
v3.0.0 release
- Loading branch information
Showing
54 changed files
with
5,476 additions
and
1,572 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -40,3 +40,4 @@ main/main | |
/main/protocol.json | ||
/main/identities.json | ||
/load-test/config.json | ||
/integration-test/config.json |
This file contains 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
This file contains 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,30 @@ | ||
# Integration test (python) | ||
|
||
The integration test is written in python, using the `pytest` module. | ||
|
||
## Configuration | ||
|
||
The test identity must be registered at the ubirch console / thing API in advance. | ||
|
||
`config.json`: | ||
|
||
```json | ||
{ | ||
"host": "<base URL of the UPP-signer instance under test>", | ||
"staticAuth": "<static auth token>", | ||
"testDevice": { | ||
"uuid": "<test identity UUID>", | ||
"password": "<test identity password>" | ||
}, | ||
"env": "<ubirch backend environment>" | ||
} | ||
``` | ||
|
||
## Run integration test | ||
|
||
```shell | ||
python3 -m venv venv && \ | ||
. venv/bin/activate && \ | ||
pip install -r requirements.txt && \ | ||
pytest -v | ||
``` |
This file contains 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,70 @@ | ||
import hashlib | ||
import json | ||
import random | ||
import time | ||
import uuid | ||
from binascii import b2a_base64, a2b_base64 | ||
|
||
import ecdsa | ||
|
||
symbols = ("a", "b", "c", "d", "e", "f", "A", "B", "C", "D", "E", "F", | ||
"ä", "ë", "ï", "ö", "ü", "ÿ", "Ä", "Ë", "Ï", "Ö", "Ü", "Ÿ", | ||
"`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", | ||
"[", "]", ";", "'", "#", ",", ".", "/", "\\", | ||
"¬", "!", '''"''', "£", "$", "%", "^", "*", "(", ")", "_", "+", | ||
"{", "}", ":", "@", "~", "?", " |", | ||
"&", "<", ">", "™", | ||
"®", "™", "U+2122", "%20", "\\n", "", "\ | ||
") | ||
|
||
|
||
def get_random_json() -> dict: | ||
"""generates a random JSON message""" | ||
return { | ||
"id": str(uuid.uuid4()), | ||
"ts": int(time.time()), | ||
"big": random.getrandbits(53), | ||
"tpl": (random.getrandbits(32), "".join(random.choices(symbols, k=4)), | ||
random.getrandbits(8), "".join(random.choices(symbols, k=8)), | ||
random.getrandbits(16), "".join(random.choices(symbols, k=2)), | ||
random.getrandbits(4), "".join(random.choices(symbols, k=16)) | ||
), | ||
"lst": random.choices(symbols, k=8), | ||
"map": { | ||
random.choice(symbols): random.getrandbits(4), | ||
random.choice(symbols): random.getrandbits(16), | ||
random.choice(symbols): random.getrandbits(8), | ||
random.choice(symbols): random.getrandbits(32) | ||
}, | ||
"str": "".join(random.choices(symbols, k=128)) | ||
} | ||
|
||
|
||
def serialize(msg: dict) -> bytes: | ||
return json.dumps(msg, separators=(',', ':'), sort_keys=True, ensure_ascii=False).encode() | ||
|
||
|
||
def get_hash(serialized: bytes) -> bytes: | ||
return hashlib.sha256(serialized).digest() | ||
|
||
|
||
def to_base64(hash_bytes: bytes) -> str: | ||
return b2a_base64(hash_bytes, newline=False).decode() | ||
|
||
|
||
def get_random_hash_base64(): | ||
"""return 32 random bytes in base64 encoding""" | ||
# return to_base64(random.randbytes(32)) # randbytes() is new in version 3.9 | ||
return to_base64(bytearray(random.getrandbits(8) for _ in range(32))) | ||
|
||
|
||
def verify_upp_signature(upp_bytes: bytes, pubkey_bas64: bytes) -> bool: | ||
pubkey_bytes = a2b_base64(pubkey_bas64) | ||
|
||
vk = ecdsa.VerifyingKey.from_string(pubkey_bytes, curve=ecdsa.NIST256p, hashfunc=hashlib.sha256) | ||
|
||
try: | ||
vk.verify(upp_bytes[-64:], upp_bytes[:-66]) | ||
return True | ||
except ecdsa.BadSignatureError: | ||
return False |
This file contains 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,4 @@ | ||
ecdsa | ||
msgpack | ||
pytest | ||
requests |
Oops, something went wrong.