Skip to content

Commit

Permalink
Merge pull request #106 from ubirch/dev
Browse files Browse the repository at this point in the history
v3.0.0 release
  • Loading branch information
leroxyl authored Dec 1, 2022
2 parents 22afead + 3d969d2 commit e84faab
Show file tree
Hide file tree
Showing 54 changed files with 5,476 additions and 1,572 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ main/main
/main/protocol.json
/main/identities.json
/load-test/config.json
/integration-test/config.json
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ IMAGE_TAG := $(VERSION)
IMAGE_ARCHS := amd64 arm arm64 386 # supported architectures

GO = go
GO_VERSION := 1.16
GO_VERSION := 1.19
LDFLAGS = -ldflags "-buildid= -s -w -X main.Version=$(VERSION) -X main.Revision=$(REVISION)"
GO_BUILD = $(GO) build -tags="netgo" -trimpath $(LDFLAGS)
UPX=upx --quiet --quiet
Expand All @@ -50,7 +50,7 @@ THISDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
.PHONY: lint
lint:
@# we supress echoing the command, so every output line
@# can be considered a linting error.
@# can be considered a linting error.
@$(DOCKER) run --rm -v $(THISDIR):/app:ro -w /app $(GO_LINTER_IMAGE) golangci-lint run

.PHONY: build
Expand All @@ -66,9 +66,10 @@ test:
$(DOCKER) run -t --rm -v $(THISDIR):/app -w /app golang:$(GO_VERSION) \
go test ./...

.PHONY: image
.PHONY: image
image:
$(DOCKER) build -t $(IMAGE_REPO):$(IMAGE_TAG) \
$(DOCKER) build -t $(IMAGE_REPO):$(IMAGE_TAG)-arm \
--build-arg="GOARCH=arm" \
--build-arg="VERSION=$(VERSION)" \
--build-arg="REVISION=$(REVISION)" \
--build-arg="GOVERSION=$(GO_VERSION)" \
Expand Down
693 changes: 500 additions & 193 deletions README.md

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions integration-test/README.md
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
```
70 changes: 70 additions & 0 deletions integration-test/helpers.py
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", "-", "=",
"[", "]", ";", "'", "#", ",", ".", "/", "\\",
"¬", "!", '''"''', "£", "$", "%", "^", "*", "(", ")", "_", "+",
"{", "}", ":", "@", "~", "?", " |",
"&", "<", ">", "&#8482",
"®", "™", "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
4 changes: 4 additions & 0 deletions integration-test/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ecdsa
msgpack
pytest
requests
Loading

0 comments on commit e84faab

Please sign in to comment.