mirror of https://github.com/nucypher/nucypher.git
Using pyUmbral Signer as SignatureStamp's signing function.
parent
e2d1a019cc
commit
fa6a4f6f57
|
@ -19,7 +19,7 @@ from nucypher.crypto.api import secure_random, keccak_digest, encrypt_and_sign
|
|||
from nucypher.crypto.constants import PUBLIC_KEY_LENGTH
|
||||
from nucypher.crypto.kits import UmbralMessageKit
|
||||
from nucypher.crypto.powers import CryptoPower, SigningPower, EncryptingPower, DelegatingPower, NoSigningPower
|
||||
from nucypher.crypto.signature import Signature, signature_splitter, SignatureStamp, StrangerStamp
|
||||
from nucypher.crypto.signing import Signature, signature_splitter, SignatureStamp, StrangerStamp
|
||||
from nucypher.network import blockchain_client
|
||||
from nucypher.network.protocols import dht_value_splitter, dht_with_hrac_splitter
|
||||
from nucypher.network.server import NucypherDHTServer, NucypherSeedOnlyDHTServer, ProxyRESTServer
|
||||
|
@ -79,7 +79,8 @@ class Character(object):
|
|||
if is_me:
|
||||
self.network_middleware = network_middleware or NetworkyStuff()
|
||||
try:
|
||||
self._stamp = SignatureStamp(self._crypto_power.power_ups(SigningPower).keypair)
|
||||
signing_power = self._crypto_power.power_ups(SigningPower)
|
||||
self._stamp = signing_power.get_signature_stamp()
|
||||
except NoSigningPower:
|
||||
self._stamp = constants.NO_SIGNING_POWER
|
||||
|
||||
|
@ -89,7 +90,7 @@ class Character(object):
|
|||
if network_middleware is not None:
|
||||
raise TypeError(
|
||||
"Can't attach network middleware to a Character who isn't me. What are you even trying to do?")
|
||||
self._stamp = StrangerStamp(self._crypto_power.power_ups(SigningPower).keypair)
|
||||
self._stamp = StrangerStamp(self.public_key(SigningPower))
|
||||
|
||||
def __eq__(self, other):
|
||||
return bytes(self.stamp) == bytes(other.stamp)
|
||||
|
|
|
@ -117,7 +117,7 @@ class DerivedKeyBasedPower(CryptoPowerUp):
|
|||
class SigningPower(KeyPairBasedPower):
|
||||
_keypair_class = SigningKeypair
|
||||
not_found_error = NoSigningPower
|
||||
provides = ("sign", "generate_self_signed_cert")
|
||||
provides = ("sign", "generate_self_signed_cert", "get_signature_stamp")
|
||||
|
||||
|
||||
class EncryptingPower(KeyPairBasedPower):
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from nucypher.crypto.api import keccak_digest
|
||||
from bytestring_splitter import BytestringSplitter
|
||||
from umbral.signing import Signature
|
||||
from umbral.signing import Signature, Signer
|
||||
|
||||
signature_splitter = BytestringSplitter(Signature)
|
||||
|
||||
|
@ -11,16 +11,16 @@ class SignatureStamp(object):
|
|||
key as bytes.
|
||||
"""
|
||||
|
||||
def __init__(self, signing_keypair):
|
||||
self._sign = signing_keypair.sign
|
||||
self._as_bytes = bytes(signing_keypair.pubkey)
|
||||
self._as_umbral_pubkey = signing_keypair.pubkey
|
||||
def __init__(self, signing_key, signer: Signer=None):
|
||||
self.__signer = signer
|
||||
self._as_bytes = bytes(signing_key)
|
||||
self._as_umbral_pubkey = signing_key
|
||||
|
||||
def __bytes__(self):
|
||||
return self._as_bytes
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self._sign(*args, **kwargs)
|
||||
return self.__signer(*args, **kwargs)
|
||||
|
||||
def __hash__(self):
|
||||
return int.from_bytes(self, byteorder="big")
|
||||
|
@ -56,7 +56,6 @@ class StrangerStamp(SignatureStamp):
|
|||
"""
|
||||
SignatureStamp of a stranger (ie, can only be used to glean public key, not to sign)
|
||||
"""
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
message = "This isn't your SignatureStamp; it belongs to (a Stranger). You can't sign with it."
|
||||
raise TypeError(message)
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
from nucypher.crypto.api import encrypt_and_sign
|
||||
from nucypher.crypto.signature import SignatureStamp
|
||||
from nucypher.crypto.powers import SigningPower
|
||||
from nucypher.crypto.signing import SignatureStamp
|
||||
from nucypher.keystore.keypairs import SigningKeypair
|
||||
from constant_sorrow.constants import NO_SIGNING_POWER
|
||||
from umbral.keys import UmbralPublicKey
|
||||
from umbral.signing import Signer
|
||||
|
||||
|
||||
class DataSource:
|
||||
|
||||
def __init__(self, policy_pubkey_enc, signer=NO_SIGNING_POWER, label=None):
|
||||
def __init__(self, policy_pubkey_enc, signing_keypair=NO_SIGNING_POWER, label=None):
|
||||
self.policy_pubkey = policy_pubkey_enc
|
||||
if signer is NO_SIGNING_POWER:
|
||||
signer = SignatureStamp(SigningKeypair()) # TODO: Generate signing key properly. #241
|
||||
self.stamp = signer
|
||||
if signing_keypair is NO_SIGNING_POWER:
|
||||
signing_keypair = SigningKeypair() # TODO: Generate signing key properly. #241
|
||||
signing_power = SigningPower(keypair=signing_keypair)
|
||||
self.stamp = signing_power.get_signature_stamp()
|
||||
self.label = label
|
||||
|
||||
def encapsulate_single_message(self, message):
|
||||
|
|
|
@ -7,8 +7,8 @@ from umbral.keys import UmbralPrivateKey, UmbralPublicKey
|
|||
from umbral import pre
|
||||
from umbral.config import default_curve
|
||||
from nucypher.crypto.kits import MessageKit
|
||||
from nucypher.crypto.signature import SignatureStamp
|
||||
from umbral.signing import Signature
|
||||
from nucypher.crypto.signing import SignatureStamp
|
||||
from umbral.signing import Signature, Signer
|
||||
|
||||
|
||||
class Keypair(object):
|
||||
|
@ -106,3 +106,7 @@ class SigningKeypair(Keypair):
|
|||
def generate_self_signed_cert(self, common_name):
|
||||
cryptography_key = self._privkey.to_cryptography_privkey()
|
||||
return generate_self_signed_certificate(common_name, default_curve(), cryptography_key)
|
||||
|
||||
def get_signature_stamp(self):
|
||||
signer = Signer(self._privkey)
|
||||
return SignatureStamp(signing_key=self.pubkey, signer=signer)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Union
|
||||
|
||||
from nucypher.crypto.signature import Signature
|
||||
from nucypher.crypto.signing import Signature
|
||||
from bytestring_splitter import BytestringSplitter
|
||||
from nucypher.keystore.db.models import Key, PolicyArrangement, Workorder
|
||||
from umbral.fragments import KFrag
|
||||
|
|
|
@ -5,7 +5,7 @@ from kademlia.utils import digest
|
|||
from constant_sorrow import default_constant_splitter, constants
|
||||
from nucypher.crypto.api import keccak_digest
|
||||
from nucypher.crypto.constants import PUBLIC_KEY_LENGTH, KECCAK_DIGEST_LENGTH
|
||||
from nucypher.crypto.signature import Signature
|
||||
from nucypher.crypto.signing import Signature
|
||||
from bytestring_splitter import BytestringSplitter
|
||||
from nucypher.network.node import NucypherNode
|
||||
from nucypher.network.routing import NucypherRoutingTable
|
||||
|
|
|
@ -12,7 +12,7 @@ from nucypher.characters import Bob, Ursula
|
|||
from nucypher.crypto.api import keccak_digest
|
||||
from nucypher.crypto.constants import KECCAK_DIGEST_LENGTH
|
||||
from nucypher.crypto.powers import SigningPower, DelegatingPower
|
||||
from nucypher.crypto.signature import Signature
|
||||
from nucypher.crypto.signing import Signature
|
||||
from nucypher.crypto.splitters import key_splitter
|
||||
from bytestring_splitter import BytestringSplitter
|
||||
from nucypher.blockchain.eth.policies import BlockchainArrangement
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
from nucypher.crypto.api import secure_random
|
||||
from nucypher.crypto.signature import Signature
|
||||
from nucypher.crypto.signing import Signature
|
||||
from bytestring_splitter import BytestringSplitter
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from nucypher.crypto.api import ecdsa_sign
|
||||
from umbral.keys import UmbralPrivateKey
|
||||
from nucypher.crypto.signature import Signature
|
||||
from nucypher.crypto.signing import Signature
|
||||
|
||||
|
||||
def test_signature_can_verify():
|
||||
|
|
|
@ -11,7 +11,7 @@ from nucypher.characters import Alice, Bob
|
|||
from nucypher.keystore import keystore
|
||||
from nucypher.keystore.db import Base
|
||||
|
||||
from nucypher.crypto.signature import SignatureStamp
|
||||
from nucypher.crypto.signing import SignatureStamp
|
||||
from nucypher.data_sources import DataSource
|
||||
from nucypher.keystore import keystore
|
||||
from nucypher.keystore.db import Base
|
||||
|
@ -97,7 +97,7 @@ def test_keystore():
|
|||
def capsule_side_channel(enacted_policy):
|
||||
signing_keypair = SigningKeypair()
|
||||
data_source = DataSource(policy_pubkey_enc=enacted_policy.public_key,
|
||||
signer=SignatureStamp(signing_keypair))
|
||||
signing_keypair=signing_keypair)
|
||||
message_kit, _signature = data_source.encapsulate_single_message(b"Welcome to the flippering.")
|
||||
return message_kit, data_source
|
||||
|
||||
|
|
Loading…
Reference in New Issue