diff --git a/data/.gitignore b/data/.gitignore new file mode 100644 index 0000000..3f82532 --- /dev/null +++ b/data/.gitignore @@ -0,0 +1,11 @@ +.DS_Store +.idea +*.log +tmp/ + +*.py[cod] +*.egg +build +htmlcov + +*.pem diff --git a/demo/config.py.simple b/demo/config.py.simple index 7d17154..9316321 100644 --- a/demo/config.py.simple +++ b/demo/config.py.simple @@ -1,4 +1,8 @@ "Store App settings" +from pathlib import Path + +_ROOT_DIR = Path().parent.resolve() +KEY_PATH = _ROOT_DIR / "data" / "key.pem" USER_AGENT = "COSCUP-demo" AP_CONTENT_TYPE = "application/activity+json" diff --git a/demo/utils/key.py b/demo/utils/key.py new file mode 100644 index 0000000..c04124b --- /dev/null +++ b/demo/utils/key.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +"""process Key.""" + +import sys + +from pathlib import Path +from Crypto.PublicKey import RSA +from demo.config import KEY_PATH + + +def get_pubkey_as_pem(key_path: Path) -> str: + """Exporting public key from private key file.""" + text = key_path.read_text() + return RSA.import_key(text).public_key().export_key("PEM").decode("utf-8") + + +def gen_key(): + """Generate key.""" + if KEY_PATH.exists(): + print("is existing!") + sys.exit(2) + else: + k = RSA.generate(2048) + privkey_pem = k.exportKey("PEM").decode("utf-8") + KEY_PATH.write_text(privkey_pem)