Skip to content

Commit 494a8ec

Browse files
ogasurfproject-jpgHorizonIwaniukooo11
authored
test(signing): add cross-SDK signature vectors (a2aproject#1286)
Adds tests that pin what a change to `_canonicalize_agent_card` (a2aproject#1278) has to keep: a card signed by another SDK still verifies here. Test only; no library code changes. - `tests/utils/signing_interop_vectors.json`: the five `s0-control` vectors of the `a2a-card-sign-v01` corpus (a2aproject/a2a-tck#246), each lifted verbatim, the same way `jcs_vectors.json` was lifted from a2aproject/a2a-tck#228. One card with every REQUIRED field and no field at its default value, signed by this SDK, @a2a-js/sdk 1.3.0, a2a-go (main 534a60fc) and a reference signer, plus the reference signature on the card edited after signing. These expectations hold however a2aproject/A2A#2122 is settled. - `tests/utils/test_signing_interop.py`: - each of the four signed cards verifies; - each canonicalizes to the shared bytes; - the edited card raises `InvalidSignaturesError`; - the frozen JS-signed production card from a2aproject/a2a-go#445 verifies and keeps 6410 bytes / `c5d5384a…`, the anchors @kuangmi-bit set out in a2aproject#1278. Its file hashes are asserted too, so the fixture cannot drift. One caveat on that last test: the frozen card carries `securityRequirements: [{}]`, a nested empty value whose canonical form is part of #2122. So it pins today's bytes, the ones this SDK and @a2a-js/sdk agree on, as agreed in a2aproject#1278, and it needs updating if #2122 settles the other way. The docstring says so. The reading-dependent group (`s1-default-valued`: `description: ""`, `skills: []`, `tags: []`, `extensions: []`) is deliberately not lifted. Its expectations depend on #2122, and adding them now would lock in one answer before the spec does. All 11 tests pass on main (fad0482). `ruff check`, `ruff format --check` and `ty check` are clean. The production card is ours (HORIZON SHIELD publishes it). If you would rather not carry it in the repo, `test_frozen_js_signed_production_card` and its two files drop out cleanly. cc @aeoess @kuangmi-bit --------- Signed-off-by: Horizon <horizon@example.com> Co-authored-by: Horizon <horizon@example.com> Co-authored-by: Mateusz Iwaniuk <45974414+Iwaniukooo11@users.noreply.github.com>
1 parent 4f4101c commit 494a8ec

2 files changed

Lines changed: 330 additions & 0 deletions

File tree

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
{
2+
"_comment": "Cross-SDK Agent Card signature vectors: the five vectors of the s0-control group of the language-neutral a2a-card-sign-v01 corpus (Layer C of the corpus whose Layers A and B are a2a-tck#228 and #245), keeping only the fields these tests read. Every card carries every REQUIRED field and no field at its default value, so the canonical readings in use today agree on its bytes and these expectations hold however a2aproject/A2A#2122 is settled. The key is a published test key (derivation in `test_key`); it signs test vectors only. The jku in each protected header is a placeholder that is never fetched.",
3+
"corpus": "a2a-card-sign-v01",
4+
"specRef": "https://a2a-protocol.org/latest/specification/#841-canonicalization-requirements",
5+
"oracles": [
6+
"rfc8785 (PyPI, 0.1.4)",
7+
"gowebpki/jcs (Go, v1.0.1)"
8+
],
9+
"test_key": {
10+
"kid": "hs-interop-test-v1",
11+
"alg": "ES256",
12+
"jwk": {
13+
"kty": "EC",
14+
"crv": "P-256",
15+
"x": "khLaGq9LmIvsjFv8YF0N4IJwRGvldb36SwqntLYct04",
16+
"y": "XCMP49DgLRfdGJKDr5MacrOCNaDXIwSvoFjID8ORkmQ",
17+
"kid": "hs-interop-test-v1",
18+
"alg": "ES256",
19+
"use": "sig"
20+
},
21+
"derivation": "d = int.from_bytes(sha256(phrase), 'big') mod (n - 1) + 1 on P-256",
22+
"phrase": "HORIZON SHIELD A2A card-signing interop test key v1 (public, test vectors only)",
23+
"note": "Published test key, so anyone can re-create the private key and re-sign every reference vector byte for byte (RFC 6979). It signs test vectors only and is nobody's production key."
24+
},
25+
"counts": {
26+
"accept": 4,
27+
"reject": 1,
28+
"total": 5
29+
},
30+
"vectors": [
31+
{
32+
"id": "S0-001",
33+
"disposition": "MUST-ACCEPT",
34+
"signer": "reference (ES256, RFC 6979)",
35+
"canonical_utf8_hex": "7b226361706162696c6974696573223a7b22707573684e6f74696669636174696f6e73223a66616c73652c2273747265616d696e67223a747275657d2c2264656661756c74496e7075744d6f646573223a5b22746578742f706c61696e225d2c2264656661756c744f75747075744d6f646573223a5b22746578742f706c61696e225d2c226465736372697074696f6e223a2250726f6265206361726420666f722063726f73732d53444b207369676e617475726520636865636b73222c226e616d65223a22496e7465726f702050726f6265222c22736b696c6c73223a5b7b226465736372697074696f6e223a22416e737765727320612070726f6265222c226964223a2270726f6265222c226e616d65223a2250726f6265222c2274616773223a5b2270726f6265225d7d5d2c22737570706f72746564496e7465726661636573223a5b7b2270726f746f636f6c42696e64696e67223a224a534f4e525043222c2270726f746f636f6c56657273696f6e223a22312e30222c2275726c223a2268747470733a2f2f6578616d706c652e636f6d2f6132612f7631227d5d2c2276657273696f6e223a22312e302e30227d",
36+
"served_card": {
37+
"name": "Interop Probe",
38+
"description": "Probe card for cross-SDK signature checks",
39+
"version": "1.0.0",
40+
"supportedInterfaces": [
41+
{
42+
"url": "https://example.com/a2a/v1",
43+
"protocolBinding": "JSONRPC",
44+
"protocolVersion": "1.0"
45+
}
46+
],
47+
"capabilities": {
48+
"streaming": true,
49+
"pushNotifications": false
50+
},
51+
"defaultInputModes": [
52+
"text/plain"
53+
],
54+
"defaultOutputModes": [
55+
"text/plain"
56+
],
57+
"skills": [
58+
{
59+
"id": "probe",
60+
"name": "Probe",
61+
"description": "Answers a probe",
62+
"tags": [
63+
"probe"
64+
]
65+
}
66+
],
67+
"signatures": [
68+
{
69+
"protected": "eyJhbGciOiJFUzI1NiIsImprdSI6Imh0dHBzOi8vZXhhbXBsZS5jb20vYTJhLWNhcmQtc2lnbi12MDEvdGVzdGtleV9qd2tzLmpzb24iLCJraWQiOiJocy1pbnRlcm9wLXRlc3QtdjEiLCJ0eXAiOiJKT1NFIn0",
70+
"signature": "jkAX98oJc4IUm6400xBQWnk5_dN33PH6KSz3KYVh6mA6gvdaroVnSVxSkzT5NoNLVIN3IoAaxvHK4etXsDMelQ"
71+
}
72+
]
73+
}
74+
},
75+
{
76+
"id": "S0-002",
77+
"disposition": "MUST-ACCEPT",
78+
"signer": "a2a-sdk 1.2.1",
79+
"canonical_utf8_hex": "7b226361706162696c6974696573223a7b22707573684e6f74696669636174696f6e73223a66616c73652c2273747265616d696e67223a747275657d2c2264656661756c74496e7075744d6f646573223a5b22746578742f706c61696e225d2c2264656661756c744f75747075744d6f646573223a5b22746578742f706c61696e225d2c226465736372697074696f6e223a2250726f6265206361726420666f722063726f73732d53444b207369676e617475726520636865636b73222c226e616d65223a22496e7465726f702050726f6265222c22736b696c6c73223a5b7b226465736372697074696f6e223a22416e737765727320612070726f6265222c226964223a2270726f6265222c226e616d65223a2250726f6265222c2274616773223a5b2270726f6265225d7d5d2c22737570706f72746564496e7465726661636573223a5b7b2270726f746f636f6c42696e64696e67223a224a534f4e525043222c2270726f746f636f6c56657273696f6e223a22312e30222c2275726c223a2268747470733a2f2f6578616d706c652e636f6d2f6132612f7631227d5d2c2276657273696f6e223a22312e302e30227d",
80+
"served_card": {
81+
"name": "Interop Probe",
82+
"description": "Probe card for cross-SDK signature checks",
83+
"version": "1.0.0",
84+
"supportedInterfaces": [
85+
{
86+
"url": "https://example.com/a2a/v1",
87+
"protocolBinding": "JSONRPC",
88+
"protocolVersion": "1.0"
89+
}
90+
],
91+
"capabilities": {
92+
"streaming": true,
93+
"pushNotifications": false
94+
},
95+
"defaultInputModes": [
96+
"text/plain"
97+
],
98+
"defaultOutputModes": [
99+
"text/plain"
100+
],
101+
"skills": [
102+
{
103+
"id": "probe",
104+
"name": "Probe",
105+
"description": "Answers a probe",
106+
"tags": [
107+
"probe"
108+
]
109+
}
110+
],
111+
"signatures": [
112+
{
113+
"protected": "eyJhbGciOiJFUzI1NiIsImprdSI6Imh0dHBzOi8vZXhhbXBsZS5jb20vYTJhLWNhcmQtc2lnbi12MDEvdGVzdGtleV9qd2tzLmpzb24iLCJraWQiOiJocy1pbnRlcm9wLXRlc3QtdjEiLCJ0eXAiOiJKT1NFIn0",
114+
"signature": "nw-32J6gLi6LsENaVDE6Qjz1oiagGEGtY6hYEc-LLXD3hmMLSYZ6cIZH7U9YHja3Hkqk-Uh4CUq2EtZY_TnjDg"
115+
}
116+
]
117+
}
118+
},
119+
{
120+
"id": "S0-003",
121+
"disposition": "MUST-ACCEPT",
122+
"signer": "@a2a-js/sdk 1.3.0",
123+
"canonical_utf8_hex": "7b226361706162696c6974696573223a7b22707573684e6f74696669636174696f6e73223a66616c73652c2273747265616d696e67223a747275657d2c2264656661756c74496e7075744d6f646573223a5b22746578742f706c61696e225d2c2264656661756c744f75747075744d6f646573223a5b22746578742f706c61696e225d2c226465736372697074696f6e223a2250726f6265206361726420666f722063726f73732d53444b207369676e617475726520636865636b73222c226e616d65223a22496e7465726f702050726f6265222c22736b696c6c73223a5b7b226465736372697074696f6e223a22416e737765727320612070726f6265222c226964223a2270726f6265222c226e616d65223a2250726f6265222c2274616773223a5b2270726f6265225d7d5d2c22737570706f72746564496e7465726661636573223a5b7b2270726f746f636f6c42696e64696e67223a224a534f4e525043222c2270726f746f636f6c56657273696f6e223a22312e30222c2275726c223a2268747470733a2f2f6578616d706c652e636f6d2f6132612f7631227d5d2c2276657273696f6e223a22312e302e30227d",
124+
"served_card": {
125+
"name": "Interop Probe",
126+
"description": "Probe card for cross-SDK signature checks",
127+
"version": "1.0.0",
128+
"supportedInterfaces": [
129+
{
130+
"url": "https://example.com/a2a/v1",
131+
"protocolBinding": "JSONRPC",
132+
"protocolVersion": "1.0"
133+
}
134+
],
135+
"capabilities": {
136+
"streaming": true,
137+
"pushNotifications": false
138+
},
139+
"defaultInputModes": [
140+
"text/plain"
141+
],
142+
"defaultOutputModes": [
143+
"text/plain"
144+
],
145+
"skills": [
146+
{
147+
"id": "probe",
148+
"name": "Probe",
149+
"description": "Answers a probe",
150+
"tags": [
151+
"probe"
152+
]
153+
}
154+
],
155+
"signatures": [
156+
{
157+
"protected": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpPU0UiLCJraWQiOiJocy1pbnRlcm9wLXRlc3QtdjEiLCJqa3UiOiJodHRwczovL2V4YW1wbGUuY29tL2EyYS1jYXJkLXNpZ24tdjAxL3Rlc3RrZXlfandrcy5qc29uIn0",
158+
"signature": "aJbacfQKkE_YmVBGBCqwVtLZR9HOIPLlbzhVkF27T6ISnYiSJPeXX9xcVl9EhhRu-bk8P2iRQGtBmMd_eWR1oQ"
159+
}
160+
]
161+
}
162+
},
163+
{
164+
"id": "S0-004",
165+
"disposition": "MUST-ACCEPT",
166+
"signer": "a2a-go main 534a60fc",
167+
"canonical_utf8_hex": "7b226361706162696c6974696573223a7b22707573684e6f74696669636174696f6e73223a66616c73652c2273747265616d696e67223a747275657d2c2264656661756c74496e7075744d6f646573223a5b22746578742f706c61696e225d2c2264656661756c744f75747075744d6f646573223a5b22746578742f706c61696e225d2c226465736372697074696f6e223a2250726f6265206361726420666f722063726f73732d53444b207369676e617475726520636865636b73222c226e616d65223a22496e7465726f702050726f6265222c22736b696c6c73223a5b7b226465736372697074696f6e223a22416e737765727320612070726f6265222c226964223a2270726f6265222c226e616d65223a2250726f6265222c2274616773223a5b2270726f6265225d7d5d2c22737570706f72746564496e7465726661636573223a5b7b2270726f746f636f6c42696e64696e67223a224a534f4e525043222c2270726f746f636f6c56657273696f6e223a22312e30222c2275726c223a2268747470733a2f2f6578616d706c652e636f6d2f6132612f7631227d5d2c2276657273696f6e223a22312e302e30227d",
168+
"served_card": {
169+
"name": "Interop Probe",
170+
"description": "Probe card for cross-SDK signature checks",
171+
"version": "1.0.0",
172+
"supportedInterfaces": [
173+
{
174+
"url": "https://example.com/a2a/v1",
175+
"protocolBinding": "JSONRPC",
176+
"protocolVersion": "1.0"
177+
}
178+
],
179+
"capabilities": {
180+
"streaming": true,
181+
"pushNotifications": false
182+
},
183+
"defaultInputModes": [
184+
"text/plain"
185+
],
186+
"defaultOutputModes": [
187+
"text/plain"
188+
],
189+
"skills": [
190+
{
191+
"id": "probe",
192+
"name": "Probe",
193+
"description": "Answers a probe",
194+
"tags": [
195+
"probe"
196+
]
197+
}
198+
],
199+
"signatures": [
200+
{
201+
"protected": "eyJhbGciOiJFUzI1NiIsImprdSI6Imh0dHBzOi8vZXhhbXBsZS5jb20vYTJhLWNhcmQtc2lnbi12MDEvdGVzdGtleV9qd2tzLmpzb24iLCJraWQiOiJocy1pbnRlcm9wLXRlc3QtdjEiLCJ0eXAiOiJKT1NFIn0",
202+
"signature": "Sm8gkamh8mcy5OsA5q84-GHO_hL5hyGrkyB8k4qJ1gm_4M64eMB6Av_m3sZSVNzgvygKXTTpeWM_wL22COXTww"
203+
}
204+
]
205+
}
206+
},
207+
{
208+
"id": "S0-REJECT-005",
209+
"disposition": "MUST-REJECT",
210+
"signer": "reference (ES256, RFC 6979)",
211+
"canonical_utf8_hex": "7b226361706162696c6974696573223a7b22707573684e6f74696669636174696f6e73223a66616c73652c2273747265616d696e67223a747275657d2c2264656661756c74496e7075744d6f646573223a5b22746578742f706c61696e225d2c2264656661756c744f75747075744d6f646573223a5b22746578742f706c61696e225d2c226465736372697074696f6e223a2250726f6265206361726420666f722063726f73732d53444b207369676e617475726520636865636b732e222c226e616d65223a22496e7465726f702050726f6265222c22736b696c6c73223a5b7b226465736372697074696f6e223a22416e737765727320612070726f6265222c226964223a2270726f6265222c226e616d65223a2250726f6265222c2274616773223a5b2270726f6265225d7d5d2c22737570706f72746564496e7465726661636573223a5b7b2270726f746f636f6c42696e64696e67223a224a534f4e525043222c2270726f746f636f6c56657273696f6e223a22312e30222c2275726c223a2268747470733a2f2f6578616d706c652e636f6d2f6132612f7631227d5d2c2276657273696f6e223a22312e302e30227d",
212+
"served_card": {
213+
"name": "Interop Probe",
214+
"description": "Probe card for cross-SDK signature checks.",
215+
"version": "1.0.0",
216+
"supportedInterfaces": [
217+
{
218+
"url": "https://example.com/a2a/v1",
219+
"protocolBinding": "JSONRPC",
220+
"protocolVersion": "1.0"
221+
}
222+
],
223+
"capabilities": {
224+
"streaming": true,
225+
"pushNotifications": false
226+
},
227+
"defaultInputModes": [
228+
"text/plain"
229+
],
230+
"defaultOutputModes": [
231+
"text/plain"
232+
],
233+
"skills": [
234+
{
235+
"id": "probe",
236+
"name": "Probe",
237+
"description": "Answers a probe",
238+
"tags": [
239+
"probe"
240+
]
241+
}
242+
],
243+
"signatures": [
244+
{
245+
"protected": "eyJhbGciOiJFUzI1NiIsImprdSI6Imh0dHBzOi8vZXhhbXBsZS5jb20vYTJhLWNhcmQtc2lnbi12MDEvdGVzdGtleV9qd2tzLmpzb24iLCJraWQiOiJocy1pbnRlcm9wLXRlc3QtdjEiLCJ0eXAiOiJKT1NFIn0",
246+
"signature": "jkAX98oJc4IUm6400xBQWnk5_dN33PH6KSz3KYVh6mA6gvdaroVnSVxSkzT5NoNLVIN3IoAaxvHK4etXsDMelQ"
247+
}
248+
]
249+
}
250+
}
251+
]
252+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""Cross-SDK Agent Card signature tests.
2+
3+
`signing_interop_vectors.json` holds one card signed four ways: by this SDK,
4+
by @a2a-js/sdk, by a2a-go and by an independent reference signer. The card
5+
carries every REQUIRED field and no field at its default value, so the
6+
canonical readings in use today agree on its bytes, and those expectations
7+
hold however a2aproject/A2A#2122 is settled: a card another SDK signed still
8+
verifies here.
9+
"""
10+
11+
import json
12+
13+
from pathlib import Path
14+
15+
import pytest
16+
17+
from a2a.types import AgentCard
18+
from a2a.utils import signing
19+
from google.protobuf import json_format
20+
from jwt import PyJWK
21+
22+
23+
_HERE = Path(__file__).parent
24+
_VECTORS = json.loads(
25+
(_HERE / 'signing_interop_vectors.json').read_text(encoding='utf-8')
26+
)
27+
_ACCEPT = [v for v in _VECTORS['vectors'] if v['disposition'] == 'MUST-ACCEPT']
28+
_REJECT = [v for v in _VECTORS['vectors'] if v['disposition'] == 'MUST-REJECT']
29+
30+
31+
def _key_provider(jwks: dict):
32+
def provide(kid: str | None, jku: str | None) -> PyJWK:
33+
for key in jwks['keys']:
34+
if key['kid'] == kid:
35+
return PyJWK(key)
36+
raise ValueError(f'kid not in key set: {kid}')
37+
38+
return provide
39+
40+
41+
def _card(served: dict) -> AgentCard:
42+
return json_format.ParseDict(served, AgentCard())
43+
44+
45+
_VERIFY = signing.create_signature_verifier(
46+
_key_provider({'keys': [_VECTORS['test_key']['jwk']]}), ['ES256']
47+
)
48+
49+
50+
def test_vector_corpus_is_complete():
51+
"""The corpus must be whole; a partially loaded corpus passes vacuously."""
52+
assert len(_ACCEPT) == _VECTORS['counts']['accept'] == 4
53+
assert len(_REJECT) == _VECTORS['counts']['reject'] == 1
54+
assert {v['signer'] for v in _ACCEPT} >= {
55+
'a2a-sdk 1.2.1',
56+
'@a2a-js/sdk 1.3.0',
57+
'a2a-go main 534a60fc',
58+
}
59+
60+
61+
@pytest.mark.parametrize('vector', _ACCEPT, ids=lambda v: v['id'])
62+
def test_card_signed_by_any_sdk_verifies(vector):
63+
"""A card signed by any SDK verifies here."""
64+
_VERIFY(_card(vector['served_card']))
65+
66+
67+
@pytest.mark.parametrize('vector', _ACCEPT, ids=lambda v: v['id'])
68+
def test_card_canonical_bytes_are_the_shared_form(vector):
69+
"""The bytes every SDK and every reading agree on, byte for byte."""
70+
canonical = signing._canonicalize_agent_card(_card(vector['served_card']))
71+
assert canonical.encode('utf-8').hex() == vector['canonical_utf8_hex']
72+
73+
74+
@pytest.mark.parametrize('vector', _REJECT, ids=lambda v: v['id'])
75+
def test_card_edited_after_signing_is_rejected(vector):
76+
"""A signature over other bytes must not verify."""
77+
with pytest.raises(signing.InvalidSignaturesError):
78+
_VERIFY(_card(vector['served_card']))

0 commit comments

Comments
 (0)