Skip to content

Commit f789433

Browse files
authored
[Confidential Ledger] [Data Plane] Make application claims parameter keyword-only in verify_receipt (Azure#30231)
* Make application claims keyword only argument for verify_receipt * Update tests after SDK change * Update samples * Update README * Update changelog * Update docstring * Address review comments
1 parent ebcfffd commit f789433

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

sdk/confidentialledger/azure-confidentialledger/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
### Features Added
66
- Add `azure.confidentialledger.receipt` module for Azure Confidential Ledger write transaction receipt verification.
7-
- Add `verify_receipt` function to verify write transaction receipts from a receipt JSON object. The function accepts an optional list of application claims, which can be used to compute the claims digest. The computed claims digest is then compared to the `claimsDigest` value present in the receipt.
7+
- Add `verify_receipt` function to verify write transaction receipts from a receipt JSON object. The function accepts an optional, keyword-only, list of application claims parameter, which can be used to compute the claims digest from the given claims: the verification would fail if the computed digest value does not match the `claimsDigest` value present in the receipt.
88
- Add `compute_claims_digest` function to compute the claims digest from a list of application claims JSON objects.
99
- Add sample code to get and verify a write receipt from a running Confidential Ledger instance.
10-
- Update README with examples and documentation for receipt verification.
10+
- Update README with examples and documentation for receipt verification and application claims.
1111

1212
### Other Changes
1313
- Add dependency on Python `cryptography` library (`>= 2.1.4`)

sdk/confidentialledger/azure-confidentialledger/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ Azure Confidential Ledger applications can attach arbitrary data, called applica
112112

113113
Later, application claims can be revealed in their un-digested form in the receipt payload corresponding to the same transaction where they were added. This allows users to leverage the information in the receipt to re-compute the same claims digest that was attached and signed in place by the Azure Confidential Ledger instance during the transaction. The claims digest can be used as part of the write transaction receipt verification process, providing an offline way for users to fully verify the authenticity of the recorded claims.
114114

115+
More details on the application claims format and the digest computation algorithm can be found at the following links:
116+
117+
- [Azure Confidential Ledger application claims](https://learn.microsoft.com/azure/confidential-ledger/write-transaction-receipts#application-claims)
118+
- [Azure Confidential Ledger application claims digest verification](https://learn.microsoft.com/azure/confidential-ledger/verify-write-transaction-receipts#verify-application-claims-digest)
119+
115120
Please refer to the following CCF documentation pages for more information about CCF Application claims:
116121

117122
- [Application Claims](https://microsoft.github.io/CCF/main/use_apps/verify_tx.html#application-claims)
@@ -437,7 +442,7 @@ application_claims = get_receipt_result.get("applicationClaims", None)
437442

438443
try:
439444
# Verify the contents of the receipt.
440-
verify_receipt(get_receipt_result["receipt"], service_cert_content, application_claims)
445+
verify_receipt(get_receipt_result["receipt"], service_cert_content, application_claims=application_claims)
441446
print(f"Receipt for transaction id {transaction_id} successfully verified")
442447
except ValueError:
443448
print(f"Receipt verification for transaction id {transaction_id} failed")

sdk/confidentialledger/azure-confidentialledger/azure/confidentialledger/receipt/_receipt_verification.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
def verify_receipt(
3333
receipt: Dict[str, Any],
3434
service_cert: str,
35+
*,
3536
application_claims: Optional[List[Dict[str, Any]]] = None,
3637
) -> None:
3738
"""Verify that a given Azure Confidential Ledger write transaction receipt
@@ -46,8 +47,8 @@ def verify_receipt(
4647
certificate of the Confidential Ledger service identity.
4748
:type service_cert: str
4849
49-
:param application_claims: List of application claims to be verified against the receipt.
50-
:type application_claims: Optional[List[Dict[str, Any]]], optional
50+
:keyword application_claims: List of application claims to be verified against the receipt.
51+
:paramtype application_claims: Optional[List[Dict[str, Any]]]
5152
5253
:raises ValueError: If the receipt verification has failed.
5354
"""

sdk/confidentialledger/azure-confidentialledger/samples/get_and_verify_receipt.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,15 @@ def main():
124124
service_cert_content = service_cert_file.read()
125125

126126
# Optionally read application claims, if any
127-
application_claims = get_receipt_result.get("applicationClaims", None)
127+
application_claims = get_receipt_result.get("applicationClaims", None)
128128

129129
try:
130130
# Verify the contents of the receipt.
131-
verify_receipt(get_receipt_result["receipt"], service_cert_content, application_claims)
131+
verify_receipt(
132+
get_receipt_result["receipt"],
133+
service_cert_content,
134+
application_claims=application_claims,
135+
)
132136
print(f"Receipt for transaction id {transaction_id} successfully verified")
133137
except ValueError:
134138
print(f"Receipt verification for transaction id {transaction_id} failed")

sdk/confidentialledger/azure-confidentialledger/tests/receipt/test_receipt_verification.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,9 @@ def test_receipt_verification_with_valid_application_claims_returns_successfully
362362
# Check that verify_receipt does not throw any exception
363363
# with a valid receipt, service certificate, and application claims
364364
try:
365-
verify_receipt(input_receipt, input_service_cert, input_claims)
365+
verify_receipt(
366+
input_receipt, input_service_cert, application_claims=input_claims
367+
)
366368
except Exception as e:
367369
pytest.fail(
368370
f"verify_receipt threw an exception with a valid receipt, service certificate, and application claims {e}"
@@ -391,4 +393,6 @@ def test_receipt_verification_with_invalid_application_claims_throws_exception(
391393
with pytest.raises(
392394
ValueError,
393395
):
394-
verify_receipt(input_receipt, input_service_cert, input_claims)
396+
verify_receipt(
397+
input_receipt, input_service_cert, application_claims=input_claims
398+
)

0 commit comments

Comments
 (0)