mirror of https://github.com/nucypher/nucypher.git
Successful grant using a bob card, interactivity, and default policy configuration values.
parent
4ade2d7aa8
commit
8339078506
|
@ -18,11 +18,11 @@
|
|||
|
||||
import click
|
||||
from marshmallow import validates_schema
|
||||
from nucypher.cli import options, types
|
||||
|
||||
from nucypher.characters.control.specifications import fields
|
||||
from nucypher.characters.control.specifications.base import BaseSchema
|
||||
from nucypher.characters.control.specifications.exceptions import InvalidArgumentCombo
|
||||
from nucypher.cli import options, types
|
||||
|
||||
|
||||
class PolicyBaseSchema(BaseSchema):
|
||||
|
@ -33,14 +33,14 @@ class PolicyBaseSchema(BaseSchema):
|
|||
'--bob-encrypting-key',
|
||||
'-bek',
|
||||
help="Bob's encrypting key as a hexadecimal string",
|
||||
type=click.STRING, required=True,))
|
||||
type=click.STRING, required=False))
|
||||
bob_verifying_key = fields.Key(
|
||||
required=True, load_only=True,
|
||||
click=click.option(
|
||||
'--bob-verifying-key',
|
||||
'-bvk',
|
||||
help="Bob's verifying key as a hexadecimal string",
|
||||
type=click.STRING, required=True))
|
||||
type=click.STRING, required=False))
|
||||
m = fields.M(
|
||||
required=True, load_only=True,
|
||||
click=options.option_m)
|
||||
|
|
|
@ -127,6 +127,10 @@ class Alice(Character, BlockchainPolicyAuthor):
|
|||
rate: int = None,
|
||||
duration_periods: int = None,
|
||||
|
||||
# Policy Storage
|
||||
store_policy_credentials: bool = None,
|
||||
store_character_cards: bool = None,
|
||||
|
||||
# Middleware
|
||||
timeout: int = 10, # seconds # TODO: configure NRN
|
||||
network_middleware: RestMiddleware = None,
|
||||
|
@ -180,6 +184,8 @@ class Alice(Character, BlockchainPolicyAuthor):
|
|||
|
||||
self.active_policies = dict()
|
||||
self.revocation_kits = dict()
|
||||
self.store_policy_credentials = store_policy_credentials
|
||||
self.store_character_cards = store_character_cards
|
||||
|
||||
def get_card(self) -> 'Card':
|
||||
from nucypher.policy.identity import Card
|
||||
|
|
|
@ -448,6 +448,7 @@ def derive_policy_pubkey(general_config, label, character_options, config_file):
|
|||
@group_character_options
|
||||
@option_force
|
||||
@click.option('--bob', type=click.STRING)
|
||||
@option_force
|
||||
def grant(general_config,
|
||||
bob,
|
||||
bob_encrypting_key,
|
||||
|
@ -463,19 +464,13 @@ def grant(general_config,
|
|||
"""Create and enact an access policy for some Bob. """
|
||||
|
||||
if bob and any((bob_encrypting_key, bob_verifying_key)):
|
||||
raise click.BadOptionUsage()
|
||||
message = '--bob canot be used with --bob-encrypting-key or --bob-veryfying key'
|
||||
raise click.BadOptionUsage(option_name='--bob', message=message)
|
||||
|
||||
# Setup
|
||||
emitter = setup_emitter(general_config)
|
||||
ALICE = character_options.create_character(emitter, config_file, general_config.json_ipc)
|
||||
|
||||
# Grantee validation
|
||||
if bob:
|
||||
card = Card.load(identifier=bob)
|
||||
bob_verifying_key = card.verifying_key
|
||||
bob_encrypting_key = card.encrypting_key
|
||||
emitter.message(f'Loaded card from storage {card.id}')
|
||||
|
||||
# Policy validation
|
||||
if ALICE.federated_only:
|
||||
if any((value, rate)):
|
||||
|
@ -484,6 +479,19 @@ def grant(general_config,
|
|||
elif bool(value) and bool(rate):
|
||||
raise click.BadOptionUsage(option_name="--rate", message="Can't use --value if using --rate")
|
||||
|
||||
# Grantee validation
|
||||
if bob:
|
||||
card = Card.load(identifier=bob)
|
||||
bob_verifying_key = card.verifying_key.hex()
|
||||
bob_encrypting_key = card.encrypting_key.hex()
|
||||
emitter.message(f'Loaded card from storage\n'
|
||||
f'*{card.nickname or card.id.hex()}*\n'
|
||||
f'Encrypting Key | {card.encrypting_key.hex()}\n'
|
||||
f'Verifying Key | {card.verifying_key.hex()}',
|
||||
color='green')
|
||||
if not force:
|
||||
click.confirm('Is this the correct grantee (Bob)?', abort=True)
|
||||
|
||||
# Interactive collection follows:
|
||||
# TODO: Extricate to support modules
|
||||
# - Disclaimer
|
||||
|
|
|
@ -41,7 +41,7 @@ def lookup(card_identifier, card_nickname, qrcode):
|
|||
""""Manage character cards"""
|
||||
emitter = StdoutEmitter()
|
||||
if card_nickname and card_identifier:
|
||||
|
||||
|
||||
raise click.Abort
|
||||
card = select_card(emitter=emitter, card_identifier=card_identifier or card_nickname)
|
||||
paint_single_card(emitter=emitter, card=card, qrcode=qrcode)
|
||||
|
|
Loading…
Reference in New Issue