feat: 🥳 initial version

This commit is contained in:
Alberto Lerda 2023-02-09 18:27:12 +01:00
commit ee81c95b32
8 changed files with 122 additions and 0 deletions

4
.env.example Normal file
View File

@ -0,0 +1,4 @@
FAB_HOST=localhost
FAB_PORT=59661
FAB_USER=Testuser
FAB_PASS=secret

6
.gitmodules vendored Normal file
View File

@ -0,0 +1,6 @@
[submodule "pyfabapi"]
path = pyfabapi
url = https://gitlab.com/fabinfra/fabaccess/pyfabapi.git
[submodule "zenflows-crypto"]
path = zenflows-crypto
url = git@github.com:interfacerproject/zenflows-crypto.git

3
example/new_session.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
curl -X POST -H 'Content-Type:application/json' -d "@session.json" http://localhost:8000/new-session

6
example/session.json Normal file
View File

@ -0,0 +1,6 @@
{
"command": "OPEN",
"eddsa_public_key": "EdDja2UdyPPEduFhXLEzzRHuW9TdaG7g16oVFAXWYvHt",
"eddsa_signature": "4YApLBq9KMytJZmcRUdU2Ltn6QqLiDCPWshziBJymeP88vRg63VNWL19PM8TxZjcQvkBU6g7ABmwXdCyPnzWsNjM",
"timestamp": "1234567"
}

93
main.py Normal file
View File

@ -0,0 +1,93 @@
import asyncio
from pyfabapi import fabapi
import pyfabapi.fabapi.user_system
from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel
from zenroom import zencode_exec
import json
import os
from dotenv import load_dotenv
load_dotenv()
class Config:
fab_host: string
fab_port: int
fab_user: string
fab_pass: string
def __init__(self):
self.fab_host = os.getenv("FAB_HOST")
self.fab_port = int(os.getenv("FAB_PORT"))
self.fab_user = os.getenv("FAB_USER")
self.fab_pass = os.getenv("FAB_PASS")
with open('zenflows-crypto/src/verify_fabaccess_open.zen','r') as file:
zen_verify_open = file.read()
with open('zenflows-crypto/src/verify_fabaccess_cmd.zen','r') as file:
zen_verify_cmd = file.read()
class NewSession(BaseModel):
timestamp: str
command: str
eddsa_public_key: str
eddsa_signature: str
class Command(BaseModel):
timestamp: str
token: str
service: str
command: str
eddsa_public_key: str
eddsa_signature: str
app = FastAPI()
conf = Config()
# Maybe the session is useless
@app.post("/new-session")
async def new_session(cmd: NewSession):
zen_result = zencode_exec(zen_verify_open, keys=cmd.json())
if zen_result.output == '':
raise HTTPException(status_code=500, detail="Invalid signature")
res = json.loads(zen_result.output)
if res["output"][0] != 'ok':
raise HTTPException(status_code=500, detail="Invalid signature")
return {"token": "todo"}
@app.get("/command")
async def read_root(cmd: Command):
zen_result = zencode_exec(zen_verify_cmd, keys=cmd.json())
if zen_result.output == '':
raise HTTPException(status_code=500, detail="Invalid signature")
res = json.loads(zen_result.output)
if res["output"][0] != 'ok':
raise HTTPException(status_code=500, detail="Invalid signature")
# a service "urn:fabaccess:resource:Another"
session = await fabapi.connect(conf.fab_host, conf.fab_port, conf.fab_user, conf.fab_pass)
info = session.machineSystem.info
ma = await info.getMachineURN(cmd.service).a_wait()
if ma.just:
print(ma)
print(ma.just)
await ma.just.use.use().a_wait()
else:
raise HTTPException(status_code=500, detail="No such resource")

1
pyfabapi Submodule

@ -0,0 +1 @@
Subproject commit 2383a6cc0dd3c49a677e05e5cedd6854d89f4237

8
requirements.txt Normal file
View File

@ -0,0 +1,8 @@
fastapi==0.90.0
meson==1.0.0
ninja==1.11.1
pycapnp==1.3.0
pydantic==1.10.4
python-dotenv==0.21.1
uvicorn==0.20.0
zenroom==2.16.4

1
zenflows-crypto Submodule

@ -0,0 +1 @@
Subproject commit 49c4f42c667d53101efaec52617b19b0abc96089