diff --git a/.changes/remove-python-compatibility-shims.removed.md b/.changes/remove-python-compatibility-shims.removed.md new file mode 100644 index 00000000000..abeb68a00ea --- /dev/null +++ b/.changes/remove-python-compatibility-shims.removed.md @@ -0,0 +1,2 @@ +Removed the deprecated `ccf.cose.verify_receipt` function and `ccf.ledger` signature compatibility re-exports. +Use [`ccf.receipt.verify_cose`](doc/use_apps/verify_tx.rst#cose-receipt-verification) and `ccf.signatures` for the replacements; see the [7.x to 8.x migration guide](doc/releases/migration_7_x_to_8_x.rst#removed-deprecated-python-sdk-compatibility-apis). diff --git a/doc/audit/python_library.rst b/doc/audit/python_library.rst index 59a146eea40..a5918b382fa 100644 --- a/doc/audit/python_library.rst +++ b/doc/audit/python_library.rst @@ -201,6 +201,4 @@ API :members: .. automodule:: ccf.receipt - :members: - -.. autofunction:: ccf.cose.verify_receipt \ No newline at end of file + :members: \ No newline at end of file diff --git a/doc/releases/migration_7_x_to_8_x.rst b/doc/releases/migration_7_x_to_8_x.rst index 6bd4d10d7c1..9e742e51824 100644 --- a/doc/releases/migration_7_x_to_8_x.rst +++ b/doc/releases/migration_7_x_to_8_x.rst @@ -147,6 +147,15 @@ The following public C++ headers and compatibility APIs, deprecated in 7.x or ea * - Unused legacy aliases ``ccf::historical::CheckAvailability``, ``ccf::OpenIDJWKMetadataLegacy``, and ``ccf::JwtPublicSigningKeysMetadataLegacy`` - ``ccf::historical::CheckHistoricalTxStatus``, ``ccf::OpenIDJWKMetadata``, and ``ccf::JwtPublicSigningKeysMetadata`` +Removed Deprecated Python SDK Compatibility APIs +------------------------------------------------ + +The deprecated ``ccf.cose.verify_receipt`` function has been removed. +Use :py:func:`ccf.receipt.verify_cose` instead. + +The deprecated compatibility re-exports on ``ccf.ledger`` (``COSE_SIGNATURE_TX_TABLE_NAME``, ``SIGNATURE_TX_TABLE_NAME``, ``WELL_KNOWN_SINGLETON_TABLE_KEY``, ``InvalidRootException``, ``InvalidRootSignatureException``, ``InvalidRootCoseSignatureException``, ``UntrustedNodeException``, and ``spki_from_cert``) have also been removed. +Import them from :py:mod:`ccf.signatures` instead. + ML-DSA Service Identity ----------------------- diff --git a/doc/use_apps/verify_tx.rst b/doc/use_apps/verify_tx.rst index 6b44d3cf05f..c4807c7565c 100644 --- a/doc/use_apps/verify_tx.rst +++ b/doc/use_apps/verify_tx.rst @@ -126,8 +126,6 @@ The Python :py:func:`ccf.receipt.verify_cose` API verifies inclusion receipts ag It validates the receipt and proof structures according to `CCF Profile for COSE Receipts, draft -06 `_, rejects duplicate map keys and trailing CBOR data, and accepts an empty inclusion path for a single-entry tree. Every inclusion proof must cover the supplied digest, and all supplied inclusion and consistency proofs must reconstruct the same signed root. Checking accompanying consistency proofs against that root does not establish consistency with a previously trusted checkpoint; this inclusion API does not take an older root. -The deprecated :py:func:`ccf.cose.verify_receipt` entry point retains its existing behavior and does not apply these additional checks. -Callers should migrate to :py:func:`ccf.receipt.verify_cose` to use the stricter verification. A service with an ML-DSA identity signs each signature transaction with its classical and its ML-DSA service keys (see :ref:`releases/migration_7_x_to_8_x:ML-DSA Service Identity`). ``GET /node/receipt/cose`` returns the receipt signed with the classical key, and with ``identity_type=PQ`` the one signed with the ML-DSA key, for example ``/node/receipt/cose?transaction_id=2.643&identity_type=PQ``. diff --git a/python/src/ccf/cose.py b/python/src/ccf/cose.py index b0ccf6412bf..6c4debc9877 100644 --- a/python/src/ccf/cose.py +++ b/python/src/ccf/cose.py @@ -6,7 +6,6 @@ import hashlib import json import sys -import warnings from collections.abc import Mapping from datetime import datetime from io import BytesIO @@ -444,69 +443,6 @@ def verify_cose_sign1_with_key( return cose_ctx.decode_with_headers(cose_sign1, cose_key, detached_payload=payload) -def verify_receipt( - receipt_bytes: bytes, key: CertificatePublicKeyTypes, claim_digest: bytes -): - """ - Verify a COSE Sign1 receipt as defined in https://datatracker.ietf.org/doc/draft-ietf-cose-merkle-tree-proofs/, - using the CCF tree algorithm defined in https://datatracker.ietf.org/doc/draft-birkholz-cose-receipts-ccf-profile/ - - Deprecated: use ccf.receipt.verify_cose instead. - """ - warnings.warn( - "ccf.cose.verify_receipt is deprecated; use ccf.receipt.verify_cose instead.", - DeprecationWarning, - stacklevel=2, - ) - key_pem = key.public_bytes(Encoding.PEM, PublicFormat.SubjectPublicKeyInfo).decode( - "ascii" - ) - expected_kid = key_fingerprint_from_key(key_pem) - cose_key = cwt.COSEKey.from_pem(key_pem, kid=expected_kid) - cose_ctx = cwt.COSE.new() - - receipt = cbor2.loads(receipt_bytes) - assert receipt.tag == cwt.const.COSE_TYPE_TO_TAG[cwt.COSETypes.SIGN1] - phdr, uhdr, _payload, _sig = receipt.value - phdr = cbor2.loads(phdr) - - assert phdr[4] == expected_kid.encode("utf-8") - - assert COSE_PHDR_VDS_LABEL in phdr, "Verifiable data structure type is required" - assert ( - phdr[COSE_PHDR_VDS_LABEL] == COSE_PHDR_VDS_CCF_LEDGER_SHA256 - ), "vds(395) protected header must be CCF_LEDGER_SHA256(2)" - - assert COSE_PHDR_VDP_LABEL in uhdr, "Verifiable data proof is required" - proof = uhdr[COSE_PHDR_VDP_LABEL] - assert COSE_RECEIPT_INCLUSION_PROOF_LABEL in proof, "Inclusion proof is required" - inclusion_proofs = proof[COSE_RECEIPT_INCLUSION_PROOF_LABEL] - assert inclusion_proofs, "At least one inclusion proof is required" - - ic_phdr = None - for inclusion_proof in inclusion_proofs: - assert isinstance(inclusion_proof, bytes), "Inclusion proof must be bstr" - proof = cbor2.loads(inclusion_proof) - assert CCF_PROOF_LEAF_LABEL in proof, "Leaf must be present" - leaf = proof[CCF_PROOF_LEAF_LABEL] - if claim_digest != leaf[2]: - raise ValueError(f"Claim digest mismatch: {leaf[2]!r} != {claim_digest!r}") - accumulator = hashlib.sha256( - leaf[0] + hashlib.sha256(leaf[1].encode()).digest() + leaf[2] - ).digest() - assert CCF_PROOF_PATH_LABEL in proof, "Path must be present" - path = proof[CCF_PROOF_PATH_LABEL] - for left, digest in path: - if left: - accumulator = hashlib.sha256(digest + accumulator).digest() - else: - accumulator = hashlib.sha256(accumulator + digest).digest() - ic_phdr, _, _ = cose_ctx.decode_with_headers( - receipt_bytes, cose_key, detached_payload=accumulator - ) - return ic_phdr - - _SIGN_DESCRIPTION = """Create and sign a COSE Sign1 message for CCF governance Note that this tool writes binary COSE Sign1 to standard output. diff --git a/python/src/ccf/ledger.py b/python/src/ccf/ledger.py index 98908d03628..182c13c74ea 100644 --- a/python/src/ccf/ledger.py +++ b/python/src/ccf/ledger.py @@ -5,7 +5,6 @@ import os import re import struct -import warnings from collections.abc import Iterator from dataclasses import dataclass from enum import Enum, Flag, IntEnum, auto @@ -21,35 +20,6 @@ from ccf.merkletree import MerkleTree from ccf.tx_id import TxID -# Names that used to live in ``ccf.ledger`` and now live in ``ccf.signatures``. -# Accessing them through ``ccf.ledger`` emits a DeprecationWarning; import -# directly from ``ccf.signatures`` instead. -_DEPRECATED_SIGNATURE_REEXPORTS = frozenset( - { - "COSE_SIGNATURE_TX_TABLE_NAME", - "InvalidRootCoseSignatureException", - "InvalidRootException", - "InvalidRootSignatureException", - "SIGNATURE_TX_TABLE_NAME", - "UntrustedNodeException", - "WELL_KNOWN_SINGLETON_TABLE_KEY", - "spki_from_cert", - } -) - - -def __getattr__(name: str): - if name in _DEPRECATED_SIGNATURE_REEXPORTS: - warnings.warn( - f"ccf.ledger.{name} is deprecated; " - f"import {name} from ccf.signatures instead.", - DeprecationWarning, - stacklevel=2, - ) - return getattr(signatures, name) - raise AttributeError(f"module {__name__!r} has no attribute {name!r}") - - GCM_SIZE_TAG = 16 GCM_SIZE_IV = 12 LEDGER_DOMAIN_SIZE = 8 diff --git a/python/tests/test_ledger.py b/python/tests/test_ledger.py index 1711f196c5a..3b5e3439b19 100644 --- a/python/tests/test_ledger.py +++ b/python/tests/test_ledger.py @@ -7,6 +7,23 @@ import pytest +@pytest.mark.parametrize( + "name", + [ + "COSE_SIGNATURE_TX_TABLE_NAME", + "InvalidRootCoseSignatureException", + "InvalidRootException", + "InvalidRootSignatureException", + "SIGNATURE_TX_TABLE_NAME", + "UntrustedNodeException", + "WELL_KNOWN_SINGLETON_TABLE_KEY", + "spki_from_cert", + ], +) +def test_deprecated_signature_reexports_are_removed(name): + assert not hasattr(ccf.ledger, name) + + def test_committed_prefix_filename_range(): """Committed-prefix names expose their closed sequence-number range.""" assert ccf.ledger.range_from_filename("ledger_42-100.committed_prefix") == (42, 100) diff --git a/python/tests/test_receipt.py b/python/tests/test_receipt.py index 75cc584fb6c..0c32349d797 100644 --- a/python/tests/test_receipt.py +++ b/python/tests/test_receipt.py @@ -24,6 +24,10 @@ UNSET = object() +def test_deprecated_cose_verify_receipt_is_removed(): + assert not hasattr(ccf.cose, "verify_receipt") + + @pytest.fixture(scope="module") def identity(): return ec.generate_private_key(ec.SECP384R1())