Skip to content

Commit

Permalink
Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Legrandin committed Sep 29, 2024
1 parent 19494e0 commit 5f7551c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
echo 'CIBW_ARCHS=x86_64 universal2' >> $GITHUB_ENV
if: runner.os == 'macOS'

- uses: pypa/cibuildwheel@v2.15.0
- uses: pypa/cibuildwheel@v2.16.5
name: Build wheels
env:
# cibuildwheel will build wheel once and test it for each CPython version
Expand Down Expand Up @@ -78,17 +78,17 @@ 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:
- os: windows-latest
arch: multi-arch
include:
- os: windows-latest
arch: x86
- os: windows-latest
arch: x64
#include:
# - os: windows-latest
# arch: x86
# - os: windows-latest
# arch: x64

if: github.actor == 'Legrandin'

Expand Down
20 changes: 19 additions & 1 deletion lib/Crypto/PublicKey/ECC.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -846,32 +853,43 @@ 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
next_element += 1
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)
try:
key = construct(curve=curve_name, d=d, point_x=point_x, point_y=point_y)
except ValueError as e:
print("Failed to build", str(e))
raise e
return key


def _import_pkcs8(encoded, passphrase):
Expand Down

0 comments on commit 5f7551c

Please sign in to comment.