Encode JWT
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
import requests
|
||||
from src.args import args
|
||||
import src.constants as constants
|
||||
from cryptography.x509 import load_pem_x509_certificate
|
||||
from cryptography import utils
|
||||
import jwt
|
||||
|
||||
|
||||
def get_secure_origin() -> str:
|
||||
@ -70,3 +73,21 @@ def device_certificate() -> str:
|
||||
print(res.text)
|
||||
raise Exception(f"Failed to check enrollment with status {res.status_code}")
|
||||
return res.text
|
||||
|
||||
|
||||
def sync_device(dev_id: str, privkey):
|
||||
"""
|
||||
Synchronize device with backend
|
||||
"""
|
||||
encoded = jwt.encode(
|
||||
{"info": device_info()}, privkey, algorithm="RS256", headers={"kid": dev_id}
|
||||
)
|
||||
|
||||
res = requests.post(
|
||||
f"{args.secure_origin}/devices_api/mgmt/sync",
|
||||
json={"payload": encoded},
|
||||
verify=args.root_ca_path,
|
||||
)
|
||||
|
||||
print(encoded)
|
||||
print(res)
|
||||
|
Reference in New Issue
Block a user