2022-09-16 01:03:29 +00:00
|
|
|
import traceback
|
|
|
|
|
|
|
|
from nacl.signing import VerifyKey
|
|
|
|
|
2022-09-27 17:21:00 +00:00
|
|
|
from logger import log as logging
|
2022-09-16 01:03:29 +00:00
|
|
|
|
2022-09-17 05:02:49 +00:00
|
|
|
from wot.getbykey import get_identity_by_key
|
2022-10-01 04:25:46 +00:00
|
|
|
from wot.wotcommand import WotCommand
|
|
|
|
|
|
|
|
from utils import identifyhome
|
2022-09-16 01:03:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
def process_revoke_signature(revoke_signature_payload):
|
|
|
|
if len(revoke_signature_payload) != 129:
|
2022-09-27 17:21:00 +00:00
|
|
|
logging.warn(
|
2022-09-16 01:03:29 +00:00
|
|
|
f'Signature size is invalid for revoking an identity',
|
2022-09-27 17:21:00 +00:00
|
|
|
)
|
2022-09-16 01:03:29 +00:00
|
|
|
|
|
|
|
# verify that this is a signature for a trust command
|
|
|
|
if revoke_signature_payload[0] != WotCommand.REVOKE_TRUST:
|
2022-09-27 17:21:00 +00:00
|
|
|
logging.warn(
|
|
|
|
f'Invalid command in signature' )
|
2022-09-16 01:03:29 +00:00
|
|
|
return
|
|
|
|
# signer is first 32 bytes
|
|
|
|
signer = VerifyKey(revoke_signature_payload[1:33])
|
|
|
|
# revoked is next 32 bytes
|
|
|
|
revoked = revoke_signature_payload[33:65]
|
|
|
|
# signature is last 64 bytes
|
|
|
|
signature = revoke_signature_payload[65:]
|
|
|
|
|
|
|
|
# If bad signature, it raises nacl.exceptions.BadSignatureError
|
|
|
|
signer.verify(
|
|
|
|
int.to_bytes(revoke_signature_payload[0], 1, 'big') + \
|
|
|
|
revoked, signature)
|
|
|
|
|
|
|
|
# if good signature
|
|
|
|
try:
|
|
|
|
|
|
|
|
signer_identity = get_identity_by_key(bytes(signer))
|
|
|
|
# noop if already revoked
|
|
|
|
signer_identity.trusted.remove(get_identity_by_key(revoked))
|
|
|
|
except KeyError:
|
|
|
|
# if signer or revoked identity are not in the identity set
|
|
|
|
# this means they have not been announced yet
|
|
|
|
traceback.print_exc()
|
|
|
|
pass
|