authorization: attempt to resolve cryptography import issues
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
d7c367f095
commit
5f7cff9af8
|
@ -19,13 +19,8 @@ import logging
|
||||||
from jose import jwt
|
from jose import jwt
|
||||||
from tornado.ioloop import IOLoop, PeriodicCallback
|
from tornado.ioloop import IOLoop, PeriodicCallback
|
||||||
from tornado.web import HTTPError
|
from tornado.web import HTTPError
|
||||||
from cryptography.hazmat.primitives.asymmetric import ec
|
import cryptography.hazmat.primitives.asymmetric.ec as ec
|
||||||
from cryptography.hazmat.primitives.serialization import (
|
import cryptography.hazmat.primitives.serialization as serialization
|
||||||
PrivateFormat,
|
|
||||||
Encoding,
|
|
||||||
NoEncryption,
|
|
||||||
load_pem_private_key,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Annotation imports
|
# Annotation imports
|
||||||
from typing import (
|
from typing import (
|
||||||
|
@ -338,7 +333,8 @@ class Authorization:
|
||||||
if jwt_secret_hex is None:
|
if jwt_secret_hex is None:
|
||||||
private_key = ec.generate_private_key(ec.SECP256R1())
|
private_key = ec.generate_private_key(ec.SECP256R1())
|
||||||
serialized: bytes = cast(ECPrivateKey, private_key).private_bytes(
|
serialized: bytes = cast(ECPrivateKey, private_key).private_bytes(
|
||||||
Encoding.PEM, PrivateFormat.PKCS8, NoEncryption())
|
serialization.Encoding.PEM, serialization.PrivateFormat.PKCS8,
|
||||||
|
serialization.NoEncryption())
|
||||||
user_info['jwt_secret'] = serialized.hex()
|
user_info['jwt_secret'] = serialized.hex()
|
||||||
self.users[username] = user_info
|
self.users[username] = user_info
|
||||||
else:
|
else:
|
||||||
|
@ -431,7 +427,8 @@ class Authorization:
|
||||||
|
|
||||||
def _load_private_key(self, secret: str) -> ec.EllipticCurvePrivateKey:
|
def _load_private_key(self, secret: str) -> ec.EllipticCurvePrivateKey:
|
||||||
try:
|
try:
|
||||||
key = load_pem_private_key(bytes.fromhex(secret), None)
|
key = serialization.load_pem_private_key(
|
||||||
|
bytes.fromhex(secret), None)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise self.server.error(
|
raise self.server.error(
|
||||||
"Error decoding private key, user data may"
|
"Error decoding private key, user data may"
|
||||||
|
|
Loading…
Reference in New Issue