Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changes/remove-python-compatibility-shims.removed.md
Original file line number Diff line number Diff line change
@@ -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).
4 changes: 1 addition & 3 deletions doc/audit/python_library.rst
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,4 @@ API
:members:

.. automodule:: ccf.receipt
:members:

.. autofunction:: ccf.cose.verify_receipt
:members:
9 changes: 9 additions & 0 deletions doc/releases/migration_7_x_to_8_x.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------------

Expand Down
2 changes: 0 additions & 2 deletions doc/use_apps/verify_tx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.ietf.org/archive/id/draft-ietf-scitt-receipts-ccf-profile-06.html>`_, 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``.
Expand Down
64 changes: 0 additions & 64 deletions python/src/ccf/cose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
30 changes: 0 additions & 30 deletions python/src/ccf/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions python/tests/test_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions python/tests/test_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down