cryptoKits is now its own project.

pull/187/head
jMyles 2018-04-01 18:50:53 -07:00
parent 22ab9b69bf
commit 8d2bd2d77d
4 changed files with 15 additions and 41 deletions

View File

@ -1,28 +1,13 @@
from nkms.crypto.splitters import key_splitter, capsule_splitter
from constant_sorrow import constants, default_constant_splitter
from crypto_kits.kits import MessageKit
from umbral import pre
from nkms.crypto.splitters import key_splitter, capsule_splitter
class CryptoKit:
return_remainder_when_splitting = True
@classmethod
def split_bytes(cls, some_bytes):
return cls.splitter(some_bytes,
return_remainder=cls.return_remainder_when_splitting)
@classmethod
def from_bytes(cls, some_bytes):
constituents = cls.split_bytes(some_bytes)
return cls(*constituents)
class MessageKit(CryptoKit):
class UmbralMessageKit(MessageKit):
splitter = capsule_splitter + key_splitter
def __init__(self, capsule, alice_pubkey=None, ciphertext=None):
self.ciphertext = ciphertext
self.capsule = capsule
self.alice_pubkey = alice_pubkey
_capsule = None
_ciphertext = None
def decrypt(self, privkey):
return pre.decrypt(
@ -31,17 +16,9 @@ class MessageKit(CryptoKit):
self.alice_pubkey
)
def to_bytes(self, include_alice_pubkey=True):
as_bytes = bytes(self.capsule)
if include_alice_pubkey and self.alice_pubkey:
as_bytes += bytes(self.alice_pubkey)
as_bytes += self.ciphertext
return as_bytes
def __bytes__(self):
return self.ciphertext
class AdventureKit(UmbralMessageKit):
class MapKit(MessageKit):
def __init__(self, ciphertext, capsule, treasure_map, alice_pubkey=None):
def later__init__(self, ciphertext, capsule, treasure_map, alice_pubkey=None):
super().__init__(ciphertext, capsule, alice_pubkey)
self.treasure_map = treasure_map

View File

@ -5,7 +5,7 @@ from kademlia.utils import digest
from nkms.crypto.api import keccak_digest
from nkms.crypto.constants import PUBLIC_KEY_LENGTH, KECCAK_DIGEST_LENGTH
from nkms.crypto.signature import Signature
from nkms.crypto.utils import BytestringSplitter
from bytestring_splitter import BytestringSplitter
from nkms.network.constants import NODE_HAS_NO_STORAGE, BYTESTRING_IS_URSULA_IFACE_INFO, \
BYTESTRING_IS_TREASURE_MAP, DHT_VALUE_HEADER_LENGTH
from nkms.network.node import NuCypherNode

View File

@ -8,9 +8,9 @@ from kademlia.crawling import NodeSpiderCrawl
from kademlia.network import Server
from kademlia.utils import digest
from nkms.crypto.kits import MessageKit
from nkms.crypto.kits import UmbralMessageKit
from nkms.crypto.powers import EncryptingPower, SigningPower
from nkms.crypto.utils import BytestringSplitter
from bytestring_splitter import BytestringSplitter
from nkms.keystore.threading import ThreadedSession
from nkms.network.capabilities import SeedOnly, ServerCapability
from nkms.network.node import NuCypherNode
@ -24,7 +24,6 @@ from apistar.core import Route
from apistar.frameworks.wsgi import WSGIApp as App
class NuCypherDHTServer(Server):
protocol_class = NuCypherHashProtocol
capabilities = ()
@ -190,15 +189,13 @@ class ProxyRESTServer(object):
Policy (see #121).
"""
hrac = binascii.unhexlify(hrac_as_hex)
policy_message_kit = MessageKit.from_bytes(request.body)
policy_message_kit = UmbralMessageKit.from_bytes(request.body)
# group_payload_splitter = BytestringSplitter(PublicKey)
# policy_payload_splitter = BytestringSplitter((KFrag, KFRAG_LENGTH))
alice = self._alice_class.from_public_keys({SigningPower: policy_message_kit.alice_pubkey})
verified, cleartext = self.verify_from(
alice, policy_message_kit,
decrypt=True, signature_is_on_cleartext=True)
verified, cleartext = self.verify_from(alice, policy_message_kit, decrypt=True)
if not verified:
# TODO: What do we do if the Policy isn't signed properly?

View File

@ -6,7 +6,7 @@ import pytest
from kademlia.utils import digest
from nkms.characters import Ursula, Character
from nkms.crypto.api import keccak_digest
from nkms.crypto.kits import MessageKit
from nkms.crypto.kits import MessageKit, AdventureKit
from nkms.network import blockchain_client
from nkms.network.constants import BYTESTRING_IS_TREASURE_MAP, BYTESTRING_IS_URSULA_IFACE_INFO
@ -120,7 +120,7 @@ def test_treasure_map_stored_by_ursula_is_the_correct_one_for_bob(alice, bob, ur
assert header == BYTESTRING_IS_TREASURE_MAP
tmap_message_kit = MessageKit.from_bytes(encrypted_treasure_map)
tmap_message_kit = AdventureKit.from_bytes(encrypted_treasure_map)
verified, treasure_map_as_decrypted_by_bob = bob.verify_from(alice,
tmap_message_kit,
decrypt=True,