From 9d2dc7cc3b2f43eea418d26146713b0692e741fe Mon Sep 17 00:00:00 2001 From: Helder Eijs Date: Sun, 29 Sep 2024 21:46:22 +0200 Subject: [PATCH] Debug --- .github/workflows/wheels.yml | 2 +- lib/Crypto/PublicKey/ECC.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 3c541d8b..487a1e26 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -78,7 +78,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ ubuntu-20.04, windows-latest, macos-12 ] + os: [ ubuntu-20.04, macos-12 ] arch: [ multi-arch ] # Python 2 on Windows requires manual toolchain setup (per-arch) due to newer MSVC used here exclude: diff --git a/lib/Crypto/PublicKey/ECC.py b/lib/Crypto/PublicKey/ECC.py index cd674f83..3d64a5a3 100644 --- a/lib/Crypto/PublicKey/ECC.py +++ b/lib/Crypto/PublicKey/ECC.py @@ -826,18 +826,25 @@ def _import_rfc5915_der(encoded, passphrase, curve_oid=None): # publicKey [1] BIT STRING OPTIONAL # } + print("************************************************") + print("Processing %d bytes" % len(encoded)) + ec_private_key = DerSequence().decode(encoded, nr_elements=(2, 3, 4)) if ec_private_key[0] != 1: + print("Incorrect version") raise ValueError("Incorrect ECC private key version") scalar_bytes = DerOctetString().decode(ec_private_key[1]).payload + print("Payload is %d bytes" % len(scalar_bytes)) next_element = 2 # Try to decode 'parameters' if next_element < len(ec_private_key): + print("Decoding parameters") try: parameters = DerObjectId(explicit=0).decode(ec_private_key[next_element]).value + print("Parameters is", parameters) if curve_oid is not None and parameters != curve_oid: raise ValueError("Curve mismatch") curve_oid = parameters @@ -846,23 +853,28 @@ def _import_rfc5915_der(encoded, passphrase, curve_oid=None): pass if curve_oid is None: + print("No curve_oid") raise ValueError("No curve found") for curve_name, curve in _curves.items(): if curve.oid == curve_oid: break else: + print("Unknown curve_oid", curve_oid) raise UnsupportedEccFeature("Unsupported ECC curve (OID: %s)" % curve_oid) modulus_bytes = curve.p.size_in_bytes() if len(scalar_bytes) != modulus_bytes: + print("Small modulus %d bytes", len(modulus_bytes)) raise ValueError("Private key is too small") # Try to decode 'publicKey' point_x = point_y = None if next_element < len(ec_private_key): try: + print("Decode public key I") public_key_enc = DerBitString(explicit=1).decode(ec_private_key[next_element]).value + print("Decode public key II") public_key = _import_public_der(public_key_enc, curve_oid=curve_oid) point_x = public_key.pointQ.x point_y = public_key.pointQ.y @@ -870,6 +882,7 @@ def _import_rfc5915_der(encoded, passphrase, curve_oid=None): except ValueError: pass + print("Build private key") d = Integer.from_bytes(scalar_bytes) return construct(curve=curve_name, d=d, point_x=point_x, point_y=point_y)