diff --git a/nucypher/characters/lawful.py b/nucypher/characters/lawful.py index 0107f75f8..36b703d29 100644 --- a/nucypher/characters/lawful.py +++ b/nucypher/characters/lawful.py @@ -82,7 +82,8 @@ from nucypher.crypto.powers import ( DelegatingPower, PowerUpError, SigningPower, - TransactingPower + TransactingPower, + TLSHostingPower, ) from nucypher.crypto.signing import InvalidSignature from nucypher.crypto.splitters import key_splitter, signature_splitter, cfrag_splitter @@ -103,7 +104,7 @@ from nucypher.network.exceptions import NodeSeemsToBeDown from nucypher.network.middleware import RestMiddleware from nucypher.network.nodes import NodeSprout, TEACHER_NODES, Teacher from nucypher.network.protocols import InterfaceInfo, parse_node_uri -from nucypher.network.server import ProxyRESTServer, TLSHostingPower, make_rest_app +from nucypher.network.server import ProxyRESTServer, make_rest_app from nucypher.network.trackers import AvailabilityTracker from nucypher.policy.hrac import HRAC from nucypher.policy.maps import TreasureMap, EncryptedTreasureMap, AuthorizedKeyFrag diff --git a/nucypher/crypto/keystore.py b/nucypher/crypto/keystore.py index b1718149c..7ad18e932 100644 --- a/nucypher/crypto/keystore.py +++ b/nucypher/crypto/keystore.py @@ -46,7 +46,8 @@ from nucypher.crypto.powers import ( KeyPairBasedPower, SigningPower, CryptoPowerUp, - DelegatingPower + DelegatingPower, + TLSHostingPower, ) from nucypher.crypto.tls import generate_self_signed_certificate from nucypher.crypto.umbral_adapter import ( @@ -54,7 +55,6 @@ from nucypher.crypto.umbral_adapter import ( secret_key_factory_from_seed, secret_key_factory_from_secret_key_factory ) -from nucypher.network.server import TLSHostingPower # HKDF __INFO_BASE = b'NuCypher/' diff --git a/nucypher/crypto/powers.py b/nucypher/crypto/powers.py index 7e4e25716..ec180681c 100644 --- a/nucypher/crypto/powers.py +++ b/nucypher/crypto/powers.py @@ -25,7 +25,7 @@ from hexbytes import HexBytes from nucypher.blockchain.eth.decorators import validate_checksum_address from nucypher.blockchain.eth.signers.base import Signer from nucypher.crypto import keypairs -from nucypher.crypto.keypairs import DecryptingKeypair, SigningKeypair +from nucypher.crypto.keypairs import DecryptingKeypair, SigningKeypair, HostingKeypair from nucypher.crypto.umbral_adapter import generate_kfrags, SecretKeyFactory, SecretKey, PublicKey @@ -290,3 +290,29 @@ class DelegatingPower(DerivedKeyBasedPower): label_keypair = keypairs.DecryptingKeypair(private_key=label_privkey) decrypting_power = DecryptingPower(keypair=label_keypair) return decrypting_power + + +class TLSHostingPower(KeyPairBasedPower): + _keypair_class = HostingKeypair + provides = ("get_deployer",) + + class NoHostingPower(PowerUpError): + pass + + not_found_error = NoHostingPower + + def __init__(self, + host: str, + public_certificate=None, + public_certificate_filepath=None, + *args, **kwargs) -> None: + + if public_certificate and public_certificate_filepath: + # TODO: Design decision here: if they do pass both, and they're identical, do we let that slide? NRN + raise ValueError("Pass either a public_certificate or a public_certificate_filepath, not both.") + + if public_certificate: + kwargs['keypair'] = HostingKeypair(certificate=public_certificate, host=host) + elif public_certificate_filepath: + kwargs['keypair'] = HostingKeypair(certificate_filepath=public_certificate_filepath, host=host) + super().__init__(*args, **kwargs) diff --git a/nucypher/network/server.py b/nucypher/network/server.py index 176f4df02..2f51ad9e0 100644 --- a/nucypher/network/server.py +++ b/nucypher/network/server.py @@ -29,7 +29,7 @@ from mako.template import Template from nucypher.blockchain.eth.utils import period_to_epoch from nucypher.config.constants import MAX_UPLOAD_CONTENT_LENGTH -from nucypher.crypto.keypairs import HostingKeypair, DecryptingKeypair +from nucypher.crypto.keypairs import DecryptingKeypair from nucypher.crypto.kits import PolicyMessageKit from nucypher.crypto.powers import KeyPairBasedPower, PowerUpError from nucypher.crypto.signing import InvalidSignature @@ -345,29 +345,3 @@ def _make_rest_app(datastore: Datastore, this_node, domain: str, log: Logger) -> return Response(response=content, headers=headers) return rest_app - - -class TLSHostingPower(KeyPairBasedPower): - _keypair_class = HostingKeypair - provides = ("get_deployer",) - - class NoHostingPower(PowerUpError): - pass - - not_found_error = NoHostingPower - - def __init__(self, - host: str, - public_certificate=None, - public_certificate_filepath=None, - *args, **kwargs) -> None: - - if public_certificate and public_certificate_filepath: - # TODO: Design decision here: if they do pass both, and they're identical, do we let that slide? NRN - raise ValueError("Pass either a public_certificate or a public_certificate_filepath, not both.") - - if public_certificate: - kwargs['keypair'] = HostingKeypair(certificate=public_certificate, host=host) - elif public_certificate_filepath: - kwargs['keypair'] = HostingKeypair(certificate_filepath=public_certificate_filepath, host=host) - super().__init__(*args, **kwargs) diff --git a/tests/integration/config/test_keystore_integration.py b/tests/integration/config/test_keystore_integration.py index 5e88c56fd..7587411df 100644 --- a/tests/integration/config/test_keystore_integration.py +++ b/tests/integration/config/test_keystore_integration.py @@ -27,10 +27,10 @@ from flask import Flask from nucypher.characters.lawful import Alice, Bob, Ursula from nucypher.config.constants import TEMPORARY_DOMAIN from nucypher.crypto.keystore import Keystore -from nucypher.crypto.powers import DecryptingPower, DelegatingPower +from nucypher.crypto.powers import DecryptingPower, DelegatingPower, TLSHostingPower from nucypher.crypto.umbral_adapter import SecretKey, Signer from nucypher.datastore.datastore import Datastore -from nucypher.network.server import TLSHostingPower, ProxyRESTServer +from nucypher.network.server import ProxyRESTServer from nucypher.utilities.networking import LOOPBACK_ADDRESS from tests.constants import INSECURE_DEVELOPMENT_PASSWORD from tests.utils.matchers import IsType diff --git a/tests/unit/crypto/test_keystore.py b/tests/unit/crypto/test_keystore.py index 2030b105e..1a4f4e097 100644 --- a/tests/unit/crypto/test_keystore.py +++ b/tests/unit/crypto/test_keystore.py @@ -40,13 +40,12 @@ from nucypher.crypto.keystore import ( _write_keystore, _read_keystore ) -from nucypher.crypto.powers import DecryptingPower, SigningPower, DelegatingPower +from nucypher.crypto.powers import DecryptingPower, SigningPower, DelegatingPower, TLSHostingPower from nucypher.crypto.umbral_adapter import SecretKey from nucypher.crypto.umbral_adapter import ( secret_key_factory_from_seed, secret_key_factory_from_secret_key_factory ) -from nucypher.network.server import TLSHostingPower from nucypher.utilities.networking import LOOPBACK_ADDRESS from tests.constants import INSECURE_DEVELOPMENT_PASSWORD