Fix signature verification
Signed-off-by: Tiago Garcia <tiago.rgarcia@ua.pt>
This commit is contained in:
parent
44f40f2b55
commit
b156337e62
|
@ -78,6 +78,11 @@ def createSession(args):
|
||||||
try:
|
try:
|
||||||
req = requests.post(f'http://{state['REP_ADDRESS']}/user/login', json=json.dumps({'signature' : base64.b64encode(signature).decode('utf-8')}), headers={'Authorization': response['token']})
|
req = requests.post(f'http://{state['REP_ADDRESS']}/user/login', json=json.dumps({'signature' : base64.b64encode(signature).decode('utf-8')}), headers={'Authorization': response['token']})
|
||||||
req.raise_for_status()
|
req.raise_for_status()
|
||||||
|
|
||||||
|
except requests.exceptions.HTTPError:
|
||||||
|
logger.error("%d: %s", req.status_code, req.json()['error'])
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
except requests.exceptions.RequestException as errex:
|
except requests.exceptions.RequestException as errex:
|
||||||
logger.error("Failed to obtain response from server")
|
logger.error("Failed to obtain response from server")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import secrets
|
import secrets
|
||||||
|
|
||||||
|
from cryptography.exceptions import InvalidSignature
|
||||||
from cryptography.hazmat.primitives.serialization import load_pem_public_key
|
from cryptography.hazmat.primitives.serialization import load_pem_public_key
|
||||||
from cryptography.hazmat.primitives.asymmetric import padding
|
from cryptography.hazmat.primitives.asymmetric import padding
|
||||||
from cryptography.hazmat.primitives import hashes
|
from cryptography.hazmat.primitives import hashes
|
||||||
|
@ -37,12 +38,15 @@ class SessionService:
|
||||||
if not public_key_pem:
|
if not public_key_pem:
|
||||||
return jsonify({"error": "Public key not found"}), 404
|
return jsonify({"error": "Public key not found"}), 404
|
||||||
public_key = load_pem_public_key(public_key_pem.encode())
|
public_key = load_pem_public_key(public_key_pem.encode())
|
||||||
|
try:
|
||||||
public_key.verify(
|
public_key.verify(
|
||||||
signature,
|
signature,
|
||||||
session.challenge.encode(),
|
session.challenge.encode(),
|
||||||
padding.PKCS1v15(),
|
padding.PKCS1v15(),
|
||||||
hashes.SHA256()
|
hashes.SHA256()
|
||||||
)
|
)
|
||||||
|
except InvalidSignature:
|
||||||
|
return jsonify({"error": "Invalid signature"}), 403
|
||||||
session.challenge = None
|
session.challenge = None
|
||||||
session.verified = True
|
session.verified = True
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
Loading…
Reference in New Issue