From 3d16cecaa5e4a6aa0d83a89c4e30cf0205b11089 Mon Sep 17 00:00:00 2001 From: Kieran Prasch Date: Mon, 3 Apr 2023 10:02:09 -0700 Subject: [PATCH] updates nucypher-core and umbral usage --- nucypher/characters/lawful.py | 1 + nucypher/crypto/constants.py | 5 ++--- nucypher/crypto/keypairs.py | 9 +++------ nucypher/crypto/keystore.py | 18 +++++++----------- nucypher/crypto/signing.py | 2 -- nucypher/crypto/tls.py | 10 +++------- tests/unit/crypto/test_keypairs.py | 3 --- tests/unit/crypto/test_keystore.py | 4 +--- 8 files changed, 17 insertions(+), 35 deletions(-) diff --git a/nucypher/characters/lawful.py b/nucypher/characters/lawful.py index efb406a74..edf6796f3 100644 --- a/nucypher/characters/lawful.py +++ b/nucypher/characters/lawful.py @@ -458,6 +458,7 @@ class Bob(Character): if not publisher_verifying_key: publisher_verifying_key = alice_verifying_key + publisher_verifying_key = PublicKey.from_compressed_bytes(publisher_verifying_key.to_compressed_bytes()) # A small optimization to avoid multiple treasure map decryptions. map_hash = hash(bytes(encrypted_treasure_map)) diff --git a/nucypher/crypto/constants.py b/nucypher/crypto/constants.py index 9114449ab..020d4dda2 100644 --- a/nucypher/crypto/constants.py +++ b/nucypher/crypto/constants.py @@ -1,8 +1,7 @@ - - - from cryptography.hazmat.primitives import hashes +UMBRAL_SECRET_KEY_SIZE = 32 + # Policy component sizes SIGNATURE_SIZE = 64 diff --git a/nucypher/crypto/keypairs.py b/nucypher/crypto/keypairs.py index 95be3e11d..4cc992d39 100644 --- a/nucypher/crypto/keypairs.py +++ b/nucypher/crypto/keypairs.py @@ -1,7 +1,3 @@ - -from pathlib import Path -from typing import Optional, Union - import sha3 from OpenSSL.SSL import TLSv1_2_METHOD from OpenSSL.crypto import X509 @@ -9,14 +5,13 @@ from constant_sorrow import constants from cryptography.hazmat.primitives.asymmetric import ec from hendrix.deploy.tls import HendrixDeployTLS from hendrix.facilities.services import ExistingKeyTLSContextFactory - from nucypher_core import ( MessageKit, EncryptedTreasureMap, EncryptedKeyFrag, HRAC, TreasureMap, - ) +) from nucypher_core.umbral import ( SecretKey, PublicKey, @@ -24,6 +19,8 @@ from nucypher_core.umbral import ( Signer, VerifiedKeyFrag, ) +from pathlib import Path +from typing import Optional, Union from nucypher.config.constants import MAX_UPLOAD_CONTENT_LENGTH from nucypher.crypto.signing import SignatureStamp, StrangerStamp diff --git a/nucypher/crypto/keystore.py b/nucypher/crypto/keystore.py index 762eab2ca..b24c92575 100644 --- a/nucypher/crypto/keystore.py +++ b/nucypher/crypto/keystore.py @@ -1,25 +1,20 @@ +from json import JSONDecodeError +from os.path import abspath - - +import click import json import os import stat import string import time -from json import JSONDecodeError -from os.path import abspath +from constant_sorrow.constants import KEYSTORE_LOCKED +from mnemonic.mnemonic import Mnemonic +from nucypher_core.umbral import SecretKeyFactory from pathlib import Path from secrets import token_bytes from typing import Callable, ClassVar, Dict, List, Union, Optional, Tuple -import click -from constant_sorrow.constants import KEYSTORE_LOCKED -from mnemonic.mnemonic import Mnemonic - -from nucypher_core.umbral import SecretKey, SecretKeyFactory - from nucypher.config.constants import DEFAULT_CONFIG_ROOT -from nucypher.utilities.emitters import StdoutEmitter from nucypher.crypto.keypairs import HostingKeypair from nucypher.crypto.passwords import ( secret_box_decrypt, @@ -37,6 +32,7 @@ from nucypher.crypto.powers import ( TLSHostingPower, ) from nucypher.crypto.tls import generate_self_signed_certificate +from nucypher.utilities.emitters import StdoutEmitter # HKDF __INFO_BASE = b'NuCypher/' diff --git a/nucypher/crypto/signing.py b/nucypher/crypto/signing.py index fec303059..5e118eb0f 100644 --- a/nucypher/crypto/signing.py +++ b/nucypher/crypto/signing.py @@ -1,5 +1,3 @@ - - from nucypher_core.umbral import Signer diff --git a/nucypher/crypto/tls.py b/nucypher/crypto/tls.py index 59c98ea9a..75f2f33f5 100644 --- a/nucypher/crypto/tls.py +++ b/nucypher/crypto/tls.py @@ -1,10 +1,4 @@ - - import datetime -from ipaddress import IPv4Address -from pathlib import Path -from typing import ClassVar, Optional, Tuple - from cryptography import x509 from cryptography.hazmat.backends import default_backend from cryptography.hazmat.backends.openssl.ec import _EllipticCurvePrivateKey @@ -14,7 +8,9 @@ from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurve from cryptography.hazmat.primitives.serialization import Encoding from cryptography.x509 import Certificate from cryptography.x509.oid import NameOID -from nucypher_core.umbral import SecretKey +from ipaddress import IPv4Address +from pathlib import Path +from typing import ClassVar, Optional, Tuple _TLS_CERTIFICATE_ENCODING = Encoding.PEM _TLS_CURVE = ec.SECP384R1 diff --git a/tests/unit/crypto/test_keypairs.py b/tests/unit/crypto/test_keypairs.py index 8a3b410df..9217da131 100644 --- a/tests/unit/crypto/test_keypairs.py +++ b/tests/unit/crypto/test_keypairs.py @@ -1,8 +1,5 @@ - - import sha3 from constant_sorrow.constants import PUBLIC_ONLY - from nucypher_core.umbral import SecretKey from nucypher.crypto import keypairs diff --git a/tests/unit/crypto/test_keystore.py b/tests/unit/crypto/test_keystore.py index 35fec2518..5fff1ac46 100644 --- a/tests/unit/crypto/test_keystore.py +++ b/tests/unit/crypto/test_keystore.py @@ -1,6 +1,3 @@ - - - import os import random import string @@ -13,6 +10,7 @@ from mnemonic.mnemonic import Mnemonic from nucypher_core.umbral import SecretKey, SecretKeyFactory +from nucypher.crypto.constants import UMBRAL_SECRET_KEY_SIZE from nucypher.crypto.keystore import ( Keystore, InvalidPassword,