fix(chrome-ledger): enforce implant ownership
This commit is contained in:
1 parent
a4eba116db
commit
48c7ab4618
3 files changed
+6
-6
No files matched your search
@@ -46,4 +46,4 @@ def check_certificate(implant_id):
|
||||
@bp.post("/reissue/<implant_id>")
|
||||
@owner_session
|
||||
def reissue_certificate(implant_id):
|
||||
return implants.reissue(database(), ledger(), implant_id, json_object()), 200
|
||||
return implants.reissue(database(), ledger(), implant_id, g.user["id"], json_object()), 200
|
||||
@@ -20,7 +20,7 @@ def implant(connection, implant_id, owner_id=None):
|
||||
def challenge(connection, ledger, implant_id, owner_id):
|
||||
with connection:
|
||||
connection.execute("BEGIN IMMEDIATE")
|
||||
implant(connection, implant_id)
|
||||
implant(connection, implant_id, owner_id)
|
||||
current = repositories.get_current_certificate(connection, implant_id)
|
||||
if current is None or not certificates.valid(certificates.load_certificate(current["cert_pem"]), ledger.ca):
|
||||
raise LedgerError(409, "Implant has no valid certificate")
|
||||
@@ -44,7 +44,7 @@ def read_details(connection, ledger, implant_id, owner_id, payload):
|
||||
raise LedgerError(401, invalid) from None
|
||||
with connection:
|
||||
connection.execute("BEGIN IMMEDIATE")
|
||||
row = implant(connection, implant_id)
|
||||
row = implant(connection, implant_id, owner_id)
|
||||
if not compare_digest(certificates.subject_implant_id(certificate), implant_id):
|
||||
raise LedgerError(401, invalid)
|
||||
stored = repositories.get_certificate(connection, implant_id, format(certificate.serial_number, "x"))
|
||||
|
||||
@@ -68,11 +68,11 @@ def check_certificate(connection, ledger, implant_id, owner_id, payload=None):
|
||||
return result
|
||||
|
||||
|
||||
def reissue(connection, ledger, implant_id, payload):
|
||||
def reissue(connection, ledger, implant_id, owner_id, payload):
|
||||
key, digest = certificates.signing_request(payload)
|
||||
with connection:
|
||||
connection.execute("BEGIN IMMEDIATE")
|
||||
row = access.implant(connection, implant_id)
|
||||
row = access.implant(connection, implant_id, owner_id)
|
||||
current = repositories.get_current_certificate(connection, implant_id)
|
||||
if current is None:
|
||||
raise LedgerError(409, "Implant has no valid certificate")
|
||||
@@ -86,7 +86,7 @@ def reissue(connection, ledger, implant_id, payload):
|
||||
if not isinstance(signature, str):
|
||||
raise LedgerError(401, "Invalid signature for the current key")
|
||||
current_key_authorized = keys.verify_implant_signature(previous.public_key(), signature, message)
|
||||
if not current_key_authorized and not keys.verify_implant_signature(key, signature, message):
|
||||
if not current_key_authorized:
|
||||
raise LedgerError(401, "Invalid signature for the current key")
|
||||
now = utc_now()
|
||||
details = json.loads(envelopes.decode_envelope(ledger.master_key, row["details"], implant_id))
|
||||
|
||||
Reference in new issue
Block a user