Use a signature field for enrico and represent as base64

pull/2098/head
Kieran R. Prasch 2020-06-16 20:18:08 -07:00
parent a71ecc8454
commit 28567b7561
7 changed files with 56 additions and 7 deletions

View File

@ -141,7 +141,8 @@ class CLIController(CharacterControlServer):
def handle_request(self, method_name, request):
start = maya.now()
response = self._perform_action(action=method_name, request=request)
return self.emitter.ipc(response=response, request_id=start.epoch, duration=maya.now() - start)
self.emitter.ipc(response=response, request_id=start.epoch, duration=maya.now() - start)
return response
class JSONRPCController(CharacterControlServer):

View File

@ -62,7 +62,6 @@ class EncryptMessage(BaseSchema):
return {"plaintext": data}
# output
message_kit = fields.UmbralMessageKit(dump_only=True)
signature = fields.String(dump_only=True) # maybe we need a signature field?
signature = fields.UmbralSignature(dump_only=True) # maybe we need a signature field?

View File

@ -23,3 +23,4 @@ from nucypher.characters.control.specifications.fields.label import *
from nucypher.characters.control.specifications.fields.cleartext import *
from nucypher.characters.control.specifications.fields.misc import *
from nucypher.characters.control.specifications.fields.file import *
from nucypher.characters.control.specifications.fields.signature import *

View File

@ -0,0 +1,44 @@
"""
This file is part of nucypher.
nucypher is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
nucypher is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
from base64 import b64decode, b64encode
from marshmallow import fields
from umbral.signing import Signature
from nucypher.characters.control.specifications.exceptions import InvalidInputData, InvalidNativeDataTypes
from nucypher.characters.control.specifications.fields.base import BaseField
class UmbralSignature(BaseField, fields.Field):
def _serialize(self, value: Signature, attr, obj, **kwargs):
return b64encode(bytes(value)).decode()
def _deserialize(self, value, attr, data, **kwargs):
if isinstance(value, bytes):
return value
try:
return b64decode(value)
except InvalidNativeDataTypes as e:
raise InvalidInputData(f"Could not parse {self.name}: {e}")
def _validate(self, value):
try:
Signature.from_bytes(value)
except InvalidNativeDataTypes as e:
raise InvalidInputData(f"Could not parse {self.name}: {e}")

View File

@ -792,15 +792,15 @@ class Bob(Character):
self.get_reencrypted_cfrags(work_order, retain_cfrags=retain_cfrags)
except NodeSeemsToBeDown as e:
# TODO: What to do here? Ursula isn't supposed to be down. NRN
self.log.info(
f"Ursula ({work_order.ursula}) seems to be down while trying to complete WorkOrder: {work_order}")
self.log.info(f"Ursula ({work_order.ursula}) seems to be down while trying to complete WorkOrder: {work_order}")
continue
except self.network_middleware.NotFound:
# This Ursula claims not to have a matching KFrag. Maybe this has been revoked?
# TODO: What's the thing to do here? Do we want to track these Ursulas in some way in case they're lying? 567
self.log.warn(
f"Ursula ({work_order.ursula}) claims not to have the KFrag to complete WorkOrder: {work_order}. Has accessed been revoked?")
self.log.warn(f"Ursula ({work_order.ursula}) claims not to have the KFrag to complete WorkOrder: {work_order}. Has accessed been revoked?")
continue
except self.network_middleware.UnexpectedResponse:
raise # TODO: Handle this
for capsule, pre_task in work_order.tasks.items():
try:

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU Affero General Public License
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
import base64
import click

View File

@ -61,12 +61,15 @@ def run(general_config, policy_encrypting_key, dry_run, http_port):
@group_general_config
def encrypt(general_config, policy_encrypting_key, message, file):
"""Encrypt a message under a given policy public key."""
# Setup
emitter = setup_emitter(general_config=general_config, banner=policy_encrypting_key)
ENRICO = _create_enrico(emitter, policy_encrypting_key)
if not (bool(message) ^ bool(file)):
emitter.error(f'Pass either --message or --file. Got {message}, {file}.')
raise click.Abort
# Encryption Request
encryption_request = {'policy_encrypting_key': policy_encrypting_key, 'message': message, 'filepath': file}
response = ENRICO.controller.encrypt_message(request=encryption_request)
return response