Three components, all bench-validated to varying depths: - applet/: CSA Aliro v1.0 Java Card applet for J3R180. AUTH0 + AUTH1 expedited-standard flow end-to-end green via PC/SC bench reader (aliro-bench-test). Userland AES-256-GCM and HMAC-SHA-256 layered on top of J3R180's primitives because the card lacks both natively. P-256 curve params seeded explicitly per J3R180's quirk. - harness/: Python orchestrator (aliro-trustgen, aliro-personalize, aliro-bench-test) for trust-bundle generation, card personalization via PersonalizationApplet, and PC/SC AUTH0+AUTH1 transactions. 126 pytest cases passing. - reader/STM32CubeExpansion_ALIRO_V1_0_0/: ST X-CUBE-ALIRO V1.0.0 with our NFC10A1 port (NUCLEO-U545RE-Q + X-NUCLEO-NFC10A1, ST25R200 shared with NFC09A1). nfc10-only/ project, NFC10A1 BSP shim, ALIRO_TRUST_OVERRIDE include into vendor's provisioning.c, and an ALIRO_APDU_TRACE wrapper around demoTransceiveBlocking. Boots, detects the J3R180, completes SELECT + AUTH0; AUTH1 currently fails with RFAL ERR_PROTO (0xB) — under investigation, see docs/plans/2026-04-20-nucleo-nfc10a1-port.md and bench-notes/. Excluded: x-cube-aliro.zip vendor archive, harness/.venv, build dirs, generated aliro_trust.h (contains private reader scalar), all PEMs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
"""Tests for PEM → fixed-width byte extraction."""
|
|
|
|
import pytest
|
|
from cryptography.hazmat.primitives.asymmetric import ec
|
|
|
|
from aliro_harness.personalizer.credentials import (
|
|
P256_COORD_LEN,
|
|
extract_priv_scalar,
|
|
extract_pub_xy,
|
|
)
|
|
|
|
|
|
def test_extract_priv_scalar_is_32_bytes():
|
|
key = ec.generate_private_key(ec.SECP256R1())
|
|
s = extract_priv_scalar(key)
|
|
assert len(s) == 32
|
|
|
|
|
|
def test_extract_priv_scalar_matches_private_value_be():
|
|
key = ec.generate_private_key(ec.SECP256R1())
|
|
expected = key.private_numbers().private_value.to_bytes(32, "big")
|
|
assert extract_priv_scalar(key) == expected
|
|
|
|
|
|
def test_extract_priv_scalar_pads_short_value():
|
|
"""A scalar small enough to need leading zeros must be left-padded."""
|
|
# Private value of 1 is the smallest possible; should pad with 31 zeros.
|
|
pem = ec.derive_private_key(1, ec.SECP256R1()).private_numbers()
|
|
key = ec.derive_private_key(1, ec.SECP256R1())
|
|
s = extract_priv_scalar(key)
|
|
assert s == bytes(31) + b"\x01"
|
|
assert len(s) == P256_COORD_LEN
|
|
|
|
|
|
def test_extract_pub_xy_is_64_bytes_no_prefix():
|
|
key = ec.generate_private_key(ec.SECP256R1())
|
|
xy = extract_pub_xy(key.public_key())
|
|
assert len(xy) == 64
|
|
# The 0x04 uncompressed-point tag must NOT appear; the applet's
|
|
# set_reader_pubk_apdu prepends nothing.
|
|
nums = key.public_key().public_numbers()
|
|
assert xy[:32] == nums.x.to_bytes(32, "big")
|
|
assert xy[32:] == nums.y.to_bytes(32, "big")
|
|
|
|
|
|
def test_non_p256_priv_rejected():
|
|
key = ec.generate_private_key(ec.SECP384R1())
|
|
with pytest.raises(ValueError, match="P-256"):
|
|
extract_priv_scalar(key)
|
|
|
|
|
|
def test_non_p256_pub_rejected():
|
|
key = ec.generate_private_key(ec.SECP384R1())
|
|
with pytest.raises(ValueError, match="P-256"):
|
|
extract_pub_xy(key.public_key())
|