@7h3/protocol 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1317
- package/agentAdapter.d.ts +26 -0
- package/auditLog.d.ts +54 -0
- package/capability.d.ts +67 -0
- package/cborCodec.d.ts +34 -0
- package/conformanceVectors.d.ts +20 -0
- package/encryption.d.ts +85 -0
- package/envelopeCbor.d.ts +33 -0
- package/frameworkAdapters.d.ts +72 -0
- package/gateway.d.ts +53 -0
- package/grpcBinding.d.ts +29 -0
- package/httpBinding.d.ts +50 -0
- package/index.d.ts +39 -0
- package/index.js +3662 -0
- package/keyInfra.d.ts +64 -0
- package/keyRegistry.d.ts +9 -0
- package/keyRotation.d.ts +20 -0
- package/mcpGateway.d.ts +37 -0
- package/mcpTransports.d.ts +62 -0
- package/mcpWrapper.d.ts +83 -0
- package/otel.d.ts +65 -0
- package/package.json +13 -121
- package/policyEnforcer.d.ts +50 -0
- package/policyTelemetryFeedback.d.ts +11 -0
- package/{src/protocol.d.ts → protocol.d.ts} +1 -2
- package/protocolAgent.d.ts +58 -0
- package/protocolBinary.d.ts +8 -0
- package/protocolCapabilities.d.ts +24 -0
- package/protocolReplay.d.ts +35 -0
- package/protocolTransport.d.ts +73 -0
- package/queueBinding.d.ts +43 -0
- package/rateLimiter.d.ts +18 -0
- package/{src/redisClient.ts → redisClient.d.ts} +25 -75
- package/replayStores.d.ts +98 -0
- package/revocation.d.ts +71 -0
- package/routePolicy.d.ts +30 -0
- package/runtimePolicy.d.ts +24 -0
- package/runtimePolicyManager.d.ts +15 -0
- package/runtimePolicyPresets.d.ts +11 -0
- package/signedResponse.d.ts +21 -0
- package/stream.d.ts +59 -0
- package/telemetry.d.ts +79 -0
- package/webhookBinding.d.ts +30 -0
- package/wsBinding.d.ts +52 -0
- package/.dockerignore +0 -19
- package/.github/dependabot.yml +0 -32
- package/.github/workflows/ci.yml +0 -31
- package/.github/workflows/publish.yml +0 -59
- package/.github/workflows/scorecard.yml +0 -37
- package/7h3.example.yaml +0 -125
- package/CHANGELOG.md +0 -152
- package/CONTRIBUTING.md +0 -82
- package/Dockerfile +0 -73
- package/GOVERNANCE.md +0 -62
- package/SECURITY.md +0 -70
- package/bench-results/replay-cache-full-1777891033256.json +0 -10
- package/bench-results/replay-cache-full-1777896317488.json +0 -10
- package/bench-results/replay-cache-full-1777900993184.json +0 -10
- package/bench-results/replay-cache-full-1777901019285.json +0 -10
- package/bench-results/replay-cache-quick-1777870170126.json +0 -10
- package/bench-results/signature-profiles-quick-1775875160079.json +0 -85
- package/bench-results/signature-profiles-quick-1775983539716.json +0 -85
- package/bench-results/signature-profiles-quick-1776237913190.json +0 -85
- package/bench-results/wire-codecs-full-1777891019803.json +0 -93
- package/bench-results/wire-codecs-full-1777896260964.json +0 -93
- package/bench-results/wire-codecs-full-1777901004247.json +0 -93
- package/bench-results/wire-codecs-quick-1775972879056.json +0 -93
- package/bench-results/wire-codecs-quick-1775983541111.json +0 -93
- package/bench-results/wire-codecs-quick-1776237914299.json +0 -93
- package/bench-results/wire-codecs-quick-1777841285236.json +0 -93
- package/bench-results/wire-codecs-quick-1777841321772.json +0 -93
- package/bench-results/wire-codecs-quick-1777841330408.json +0 -93
- package/bench-results/wire-codecs-quick-1777852886082.json +0 -93
- package/bench-results/wire-codecs-quick-1777852988773.json +0 -93
- package/bench-results/wire-codecs-quick-1777870188095.json +0 -93
- package/bench-results/wire-codecs-quick-1777870263918.json +0 -93
- package/bench-results/wire-codecs-quick-1777870455034.json +0 -93
- package/bench-results/wire-codecs-quick-1778816163081.json +0 -93
- package/bench-results/wire-codecs-quick-1778843936130.json +0 -93
- package/bin/7h3.ts +0 -406
- package/conformance/7h3_v0_1.json +0 -77
- package/conformance/7h3_v0_1_binary.json +0 -20
- package/conformance/aip_v0_1_binary.json +0 -20
- package/docker-compose.yaml +0 -77
- package/docs/ADOPTION_PLAN.md +0 -120
- package/docs/AGENTS.md +0 -77
- package/docs/AIP_RFC_v0.1.md +0 -97
- package/docs/AI_DECISION_CARD.md +0 -122
- package/docs/AI_RUNTIME_POLICY.json +0 -126
- package/docs/AI_RUNTIME_POLICY.yaml +0 -110
- package/docs/BACKPRESSURE_TUNING.md +0 -65
- package/docs/BENCHMARK_CLAIM_MATRIX.md +0 -42
- package/docs/BENCHMARK_REPORT_TEMPLATE.md +0 -169
- package/docs/BINARY_CODEC_BENCH.md +0 -23
- package/docs/CLEAN_CLONE_RUNBOOK.md +0 -36
- package/docs/CLOCK_SKEW_POLICY.md +0 -30
- package/docs/DISTRIBUTED_REPLAY.md +0 -142
- package/docs/FUZZ_CAMPAIGN.md +0 -121
- package/docs/GATEWAY.md +0 -195
- package/docs/KEY_MANAGEMENT_POLICY.md +0 -53
- package/docs/KEY_REVOCATION.md +0 -69
- package/docs/MCP_WRAPPER.md +0 -159
- package/docs/MIGRATION_GUIDE.md +0 -40
- package/docs/OPERATORS.md +0 -184
- package/docs/PERF_REGRESSION_POLICY.md +0 -34
- package/docs/PROJECT_EXAMINATION_2026-05-31.md +0 -219
- package/docs/RELEASE_BENCHMARK_REPORT_2026-05-15.md +0 -135
- package/docs/RELEASE_GATE.md +0 -25
- package/docs/RELEASE_NOTES_v0.1.0.md +0 -54
- package/docs/SECURITY_REVIEW_2026-06-05.md +0 -165
- package/docs/TELEMETRY.md +0 -41
- package/docs/THREAT_MODEL.md +0 -89
- package/docs/VERSIONING_POLICY.md +0 -30
- package/docs/assets/banner-github.png +0 -0
- package/docs/assets/banner.png +0 -0
- package/docs/assets/banner.svg +0 -123
- package/eslint.config.js +0 -15
- package/fuzz/ts/harness-decode.ts +0 -136
- package/fuzz/ts/harness-verify.ts +0 -121
- package/fuzz/ts/run.ts +0 -35
- package/mcp-server/README.md +0 -38
- package/mcp-server/package-lock.json +0 -1187
- package/mcp-server/package.json +0 -35
- package/mcp-server/src/index.ts +0 -236
- package/mcp-server/tsconfig.json +0 -14
- package/scripts/aip-framework-quickstart.ts +0 -110
- package/scripts/aip-mcp-gateway.ts +0 -38
- package/scripts/aip-mcp-wrap-demo.ts +0 -72
- package/scripts/aip-quickstart.ts +0 -60
- package/scripts/bench-diff.ts +0 -118
- package/scripts/bench-protocol-e2e.ts +0 -937
- package/scripts/bench-protocol-openloop.ts +0 -1397
- package/scripts/bench-replay-cache.ts +0 -76
- package/scripts/bench-signature-profiles.ts +0 -180
- package/scripts/bench-wire-codecs.ts +0 -161
- package/scripts/build-binary-conformance.ts +0 -36
- package/scripts/build-release-dashboard.ts +0 -175
- package/scripts/canary-rollout.ts +0 -38
- package/scripts/mcpGatewayCli.test.ts +0 -116
- package/scripts/prepare-aip-package.ts +0 -88
- package/scripts/regen-conformance-sigs.ts +0 -18
- package/scripts/release-gate.ts +0 -19
- package/scripts/validate-runtime-policy.ts +0 -18
- package/sdk/browser/index.test.ts +0 -162
- package/sdk/browser/index.ts +0 -257
- package/sdk/browser/package.json +0 -13
- package/sdk/go/cbor.go +0 -551
- package/sdk/go/cbor_test.go +0 -232
- package/sdk/go/encryption.go +0 -280
- package/sdk/go/encryption_test.go +0 -318
- package/sdk/go/go.mod +0 -7
- package/sdk/go/go.sum +0 -4
- package/sdk/go/http.go +0 -135
- package/sdk/go/protocol.go +0 -324
- package/sdk/go/protocol_test.go +0 -334
- package/sdk/go/replay.go +0 -121
- package/sdk/go/replay_test.go +0 -149
- package/sdk/go/webhook.go +0 -136
- package/sdk/pq/package-lock.json +0 -1358
- package/sdk/pq/package.json +0 -42
- package/sdk/pq/src/index.test.ts +0 -143
- package/sdk/pq/src/index.ts +0 -166
- package/sdk/pq/tsconfig.json +0 -14
- package/sdk/pq/vitest.config.ts +0 -7
- package/sdk/python/README.md +0 -18
- package/sdk/python/protocol_7h3/__init__.py +0 -46
- package/sdk/python/protocol_7h3/encryption.py +0 -252
- package/sdk/python/protocol_7h3/http.py +0 -212
- package/sdk/python/protocol_7h3/keys.py +0 -149
- package/sdk/python/protocol_7h3/pq.py +0 -244
- package/sdk/python/protocol_7h3/protocol.py +0 -525
- package/sdk/python/protocol_7h3/queue.py +0 -118
- package/sdk/python/protocol_7h3/replay.py +0 -98
- package/sdk/python/protocol_7h3/webhook.py +0 -116
- package/sdk/python/pyproject.toml +0 -40
- package/sdk/python/tests/test_conformance.py +0 -110
- package/sdk/python/tests/test_encryption.py +0 -206
- package/sdk/python/tests/test_http.py +0 -305
- package/sdk/python/tests/test_keys.py +0 -417
- package/sdk/python/tests/test_queue.py +0 -120
- package/sdk/python/tests/test_webhook.py +0 -345
- package/sdk/rust/Cargo.lock +0 -371
- package/sdk/rust/Cargo.toml +0 -25
- package/sdk/rust/README.md +0 -31
- package/sdk/rust/fuzz/Cargo.toml +0 -29
- package/sdk/rust/fuzz/fuzz_targets/fuzz_canonicalize.rs +0 -46
- package/sdk/rust/fuzz/fuzz_targets/fuzz_decode.rs +0 -11
- package/sdk/rust/src/bin/aip_mcp_gateway.rs +0 -59
- package/sdk/rust/src/http.rs +0 -145
- package/sdk/rust/src/keys.rs +0 -161
- package/sdk/rust/src/lib.rs +0 -688
- package/sdk/rust/src/queue.rs +0 -79
- package/sdk/rust/src/webhook.rs +0 -86
- package/sdk/rust/tests/conformance.rs +0 -148
- package/sdk/rust/tests/gateway.rs +0 -130
- package/sdk/rust/tests/http_webhook_queue.rs +0 -201
- package/sdk/rust/tests/keys.rs +0 -189
- package/sdk/threshold/index.d.ts +0 -68
- package/sdk/threshold/index.d.ts.map +0 -1
- package/sdk/threshold/index.js +0 -254
- package/sdk/threshold/package-lock.json +0 -1361
- package/sdk/threshold/package.json +0 -39
- package/sdk/threshold/src/index.d.ts +0 -68
- package/sdk/threshold/src/index.d.ts.map +0 -1
- package/sdk/threshold/src/index.js +0 -254
- package/sdk/threshold/src/index.test.ts +0 -238
- package/sdk/threshold/src/index.ts +0 -355
- package/sdk/threshold/tsconfig.json +0 -19
- package/sdk/threshold/vitest.config.ts +0 -12
- package/src/agentAdapter.test.ts +0 -48
- package/src/agentAdapter.ts +0 -56
- package/src/auditLog.test.ts +0 -145
- package/src/auditLog.ts +0 -147
- package/src/capability.test.ts +0 -504
- package/src/capability.ts +0 -380
- package/src/cborCodec.test.ts +0 -263
- package/src/cborCodec.ts +0 -339
- package/src/conformance.test.ts +0 -136
- package/src/conformanceVectors.ts +0 -99
- package/src/encryption.test.ts +0 -206
- package/src/encryption.ts +0 -245
- package/src/envelopeCbor.ts +0 -140
- package/src/frameworkAdapters.test.ts +0 -290
- package/src/frameworkAdapters.ts +0 -261
- package/src/gateway.test.ts +0 -343
- package/src/gateway.ts +0 -246
- package/src/grpcBinding.test.ts +0 -211
- package/src/grpcBinding.ts +0 -103
- package/src/httpBinding.test.ts +0 -376
- package/src/httpBinding.ts +0 -189
- package/src/index.ts +0 -39
- package/src/keyInfra.test.ts +0 -278
- package/src/keyInfra.ts +0 -228
- package/src/keyRegistry.ts +0 -59
- package/src/keyRotation.test.ts +0 -78
- package/src/keyRotation.ts +0 -72
- package/src/mcpGateway.test.ts +0 -129
- package/src/mcpGateway.ts +0 -250
- package/src/mcpTransports.test.ts +0 -92
- package/src/mcpTransports.ts +0 -169
- package/src/mcpWrapper.test.ts +0 -179
- package/src/mcpWrapper.ts +0 -206
- package/src/otel.ts +0 -136
- package/src/policyEnforcer.test.ts +0 -99
- package/src/policyEnforcer.ts +0 -169
- package/src/policyTelemetryFeedback.test.ts +0 -25
- package/src/policyTelemetryFeedback.ts +0 -38
- package/src/protocol.bench.ts +0 -37
- package/src/protocol.d.ts.map +0 -1
- package/src/protocol.js +0 -294
- package/src/protocol.test.ts +0 -155
- package/src/protocol.ts +0 -414
- package/src/protocolAgent.test.ts +0 -105
- package/src/protocolAgent.ts +0 -169
- package/src/protocolBinary.test.ts +0 -165
- package/src/protocolBinary.ts +0 -312
- package/src/protocolCapabilities.ts +0 -70
- package/src/protocolFuzz.advanced.test.ts +0 -235
- package/src/protocolFuzz.test.ts +0 -111
- package/src/protocolNegative.test.ts +0 -97
- package/src/protocolReplay.test.ts +0 -71
- package/src/protocolReplay.ts +0 -194
- package/src/protocolTransport.test.ts +0 -556
- package/src/protocolTransport.ts +0 -483
- package/src/queueBinding.test.ts +0 -130
- package/src/queueBinding.ts +0 -102
- package/src/rateLimiter.test.ts +0 -96
- package/src/rateLimiter.ts +0 -46
- package/src/redisIntegration.test.ts +0 -134
- package/src/replayStores.test.ts +0 -273
- package/src/replayStores.ts +0 -215
- package/src/revocation.test.ts +0 -98
- package/src/revocation.ts +0 -0
- package/src/routePolicy.test.ts +0 -87
- package/src/routePolicy.ts +0 -72
- package/src/runtimePolicy.test.ts +0 -49
- package/src/runtimePolicy.ts +0 -81
- package/src/runtimePolicyManager.test.ts +0 -29
- package/src/runtimePolicyManager.ts +0 -50
- package/src/runtimePolicyPresets.ts +0 -43
- package/src/signedResponse.test.ts +0 -111
- package/src/signedResponse.ts +0 -83
- package/src/stream.test.ts +0 -254
- package/src/stream.ts +0 -417
- package/src/telemetry.test.ts +0 -251
- package/src/telemetry.ts +0 -299
- package/src/webhookBinding.test.ts +0 -144
- package/src/webhookBinding.ts +0 -115
- package/src/wsBinding.test.ts +0 -221
- package/src/wsBinding.ts +0 -200
- package/tsconfig.json +0 -15
- package/tsconfig.lib.json +0 -23
- package/vite.lib.config.ts +0 -16
- package/vitest.config.ts +0 -11
|
@@ -1,417 +0,0 @@
|
|
|
1
|
-
"""Tests for protocol_7h3.keys — key infrastructure."""
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
|
|
4
|
-
import json
|
|
5
|
-
import time
|
|
6
|
-
import unittest
|
|
7
|
-
|
|
8
|
-
from protocol_7h3.keys import (
|
|
9
|
-
KeyEntry,
|
|
10
|
-
KeyRotationManager,
|
|
11
|
-
ManagedKeyPair,
|
|
12
|
-
RevocationRegistry,
|
|
13
|
-
WellKnownKeysDocument,
|
|
14
|
-
)
|
|
15
|
-
from protocol_7h3.http import StaticKeyRegistry
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class TestWellKnownKeysDocumentRoundTrip(unittest.TestCase):
|
|
19
|
-
"""Test 1: WellKnownKeysDocument.to_json / from_json round trip."""
|
|
20
|
-
|
|
21
|
-
def test_round_trip_basic(self):
|
|
22
|
-
now = int(time.time() * 1000)
|
|
23
|
-
original = WellKnownKeysDocument(
|
|
24
|
-
version="7h3/0.1",
|
|
25
|
-
updated=now,
|
|
26
|
-
keys=[
|
|
27
|
-
KeyEntry(
|
|
28
|
-
id="key-abc",
|
|
29
|
-
algorithm="Ed25519",
|
|
30
|
-
public_key="MCowBQYDK2VwAyEAAABBBBCCDDEEFF==",
|
|
31
|
-
created=now - 1000,
|
|
32
|
-
),
|
|
33
|
-
KeyEntry(
|
|
34
|
-
id="key-def",
|
|
35
|
-
algorithm="Ed25519",
|
|
36
|
-
public_key="MCowBQYDK2VwAyEA11223344==",
|
|
37
|
-
created=now - 500,
|
|
38
|
-
expires=now + 3600000,
|
|
39
|
-
),
|
|
40
|
-
],
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
serialized = original.to_json()
|
|
44
|
-
parsed = json.loads(serialized)
|
|
45
|
-
|
|
46
|
-
# Check top-level structure
|
|
47
|
-
self.assertEqual(parsed["version"], "7h3/0.1")
|
|
48
|
-
self.assertEqual(parsed["updated"], now)
|
|
49
|
-
self.assertEqual(len(parsed["keys"]), 2)
|
|
50
|
-
|
|
51
|
-
# Deserialize
|
|
52
|
-
restored = WellKnownKeysDocument.from_json(serialized)
|
|
53
|
-
self.assertEqual(restored.version, original.version)
|
|
54
|
-
self.assertEqual(restored.updated, original.updated)
|
|
55
|
-
self.assertEqual(len(restored.keys), 2)
|
|
56
|
-
|
|
57
|
-
k0 = restored.keys[0]
|
|
58
|
-
self.assertEqual(k0.id, "key-abc")
|
|
59
|
-
self.assertEqual(k0.algorithm, "Ed25519")
|
|
60
|
-
self.assertEqual(k0.public_key, "MCowBQYDK2VwAyEAAABBBBCCDDEEFF==")
|
|
61
|
-
self.assertEqual(k0.created, now - 1000)
|
|
62
|
-
self.assertIsNone(k0.expires)
|
|
63
|
-
self.assertFalse(k0.revoked)
|
|
64
|
-
|
|
65
|
-
k1 = restored.keys[1]
|
|
66
|
-
self.assertEqual(k1.id, "key-def")
|
|
67
|
-
self.assertEqual(k1.expires, now + 3600000)
|
|
68
|
-
|
|
69
|
-
def test_round_trip_with_revoked_key(self):
|
|
70
|
-
now = int(time.time() * 1000)
|
|
71
|
-
original = WellKnownKeysDocument(
|
|
72
|
-
version="7h3/0.1",
|
|
73
|
-
updated=now,
|
|
74
|
-
keys=[
|
|
75
|
-
KeyEntry(
|
|
76
|
-
id="key-revoked",
|
|
77
|
-
algorithm="Ed25519",
|
|
78
|
-
public_key="MCowBQYDK2VwAyEA==",
|
|
79
|
-
created=now - 10000,
|
|
80
|
-
revoked=True,
|
|
81
|
-
revoked_at=now - 5000,
|
|
82
|
-
),
|
|
83
|
-
],
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
serialized = original.to_json()
|
|
87
|
-
restored = WellKnownKeysDocument.from_json(serialized)
|
|
88
|
-
|
|
89
|
-
k = restored.keys[0]
|
|
90
|
-
self.assertTrue(k.revoked)
|
|
91
|
-
self.assertEqual(k.revoked_at, now - 5000)
|
|
92
|
-
|
|
93
|
-
def test_to_json_omits_optional_fields_when_absent(self):
|
|
94
|
-
now = int(time.time() * 1000)
|
|
95
|
-
doc = WellKnownKeysDocument(
|
|
96
|
-
version="7h3/0.1",
|
|
97
|
-
updated=now,
|
|
98
|
-
keys=[
|
|
99
|
-
KeyEntry(
|
|
100
|
-
id="key-minimal",
|
|
101
|
-
algorithm="Ed25519",
|
|
102
|
-
public_key="abc123==",
|
|
103
|
-
created=now,
|
|
104
|
-
),
|
|
105
|
-
],
|
|
106
|
-
)
|
|
107
|
-
serialized = doc.to_json()
|
|
108
|
-
parsed = json.loads(serialized)
|
|
109
|
-
k = parsed["keys"][0]
|
|
110
|
-
self.assertNotIn("expires", k)
|
|
111
|
-
self.assertNotIn("revoked", k)
|
|
112
|
-
self.assertNotIn("revokedAt", k)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
class TestStaticKeyRegistry(unittest.TestCase):
|
|
116
|
-
"""Test 2: StaticKeyRegistry (from http.py) get_public_key."""
|
|
117
|
-
|
|
118
|
-
def test_get_public_key_returns_registered_key(self):
|
|
119
|
-
registry = StaticKeyRegistry({"agent-alice": "MCowBQYDK2VwAyEAAlice=="})
|
|
120
|
-
result = registry.get_public_key("agent-alice")
|
|
121
|
-
self.assertEqual(result, "MCowBQYDK2VwAyEAAlice==")
|
|
122
|
-
|
|
123
|
-
def test_get_public_key_returns_none_for_unknown(self):
|
|
124
|
-
registry = StaticKeyRegistry({"agent-alice": "MCowBQYDK2VwAyEAAlice=="})
|
|
125
|
-
result = registry.get_public_key("agent-unknown")
|
|
126
|
-
self.assertIsNone(result)
|
|
127
|
-
|
|
128
|
-
def test_get_public_key_empty_registry(self):
|
|
129
|
-
registry = StaticKeyRegistry({})
|
|
130
|
-
self.assertIsNone(registry.get_public_key("any-id"))
|
|
131
|
-
|
|
132
|
-
def test_get_public_key_multiple_keys(self):
|
|
133
|
-
keys = {
|
|
134
|
-
"alice": "pub-alice",
|
|
135
|
-
"bob": "pub-bob",
|
|
136
|
-
"carol": "pub-carol",
|
|
137
|
-
}
|
|
138
|
-
registry = StaticKeyRegistry(keys)
|
|
139
|
-
self.assertEqual(registry.get_public_key("alice"), "pub-alice")
|
|
140
|
-
self.assertEqual(registry.get_public_key("bob"), "pub-bob")
|
|
141
|
-
self.assertEqual(registry.get_public_key("carol"), "pub-carol")
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
class TestRevocationRegistryRevokeAndIsRevoked(unittest.TestCase):
|
|
145
|
-
"""Test 3: RevocationRegistry: revoke + is_revoked."""
|
|
146
|
-
|
|
147
|
-
def test_revoke_marks_key_as_revoked(self):
|
|
148
|
-
reg = RevocationRegistry()
|
|
149
|
-
reg.revoke("key-abc")
|
|
150
|
-
self.assertTrue(reg.is_revoked("key-abc"))
|
|
151
|
-
|
|
152
|
-
def test_is_revoked_returns_false_for_unrevo_key(self):
|
|
153
|
-
reg = RevocationRegistry()
|
|
154
|
-
reg.revoke("key-abc")
|
|
155
|
-
self.assertFalse(reg.is_revoked("key-xyz"))
|
|
156
|
-
|
|
157
|
-
def test_revoke_with_reason(self):
|
|
158
|
-
reg = RevocationRegistry()
|
|
159
|
-
reg.revoke("key-compromised", reason="private key leak")
|
|
160
|
-
self.assertTrue(reg.is_revoked("key-compromised"))
|
|
161
|
-
|
|
162
|
-
def test_revoke_multiple_keys(self):
|
|
163
|
-
reg = RevocationRegistry()
|
|
164
|
-
reg.revoke("key-1")
|
|
165
|
-
reg.revoke("key-2")
|
|
166
|
-
self.assertTrue(reg.is_revoked("key-1"))
|
|
167
|
-
self.assertTrue(reg.is_revoked("key-2"))
|
|
168
|
-
self.assertFalse(reg.is_revoked("key-3"))
|
|
169
|
-
|
|
170
|
-
def test_empty_registry_returns_false(self):
|
|
171
|
-
reg = RevocationRegistry()
|
|
172
|
-
self.assertFalse(reg.is_revoked("key-anything"))
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
class TestRevocationRegistryGetList(unittest.TestCase):
|
|
176
|
-
"""Test 4: RevocationRegistry: get_list returns correct structure."""
|
|
177
|
-
|
|
178
|
-
def test_get_list_structure_when_empty(self):
|
|
179
|
-
reg = RevocationRegistry()
|
|
180
|
-
result = reg.get_list()
|
|
181
|
-
self.assertEqual(result["version"], "7h3/0.1")
|
|
182
|
-
self.assertIn("updated", result)
|
|
183
|
-
self.assertIsInstance(result["updated"], int)
|
|
184
|
-
self.assertEqual(result["revokedKeys"], [])
|
|
185
|
-
|
|
186
|
-
def test_get_list_contains_revoked_key(self):
|
|
187
|
-
reg = RevocationRegistry()
|
|
188
|
-
before = int(time.time() * 1000)
|
|
189
|
-
reg.revoke("key-foo", reason="expired")
|
|
190
|
-
after = int(time.time() * 1000)
|
|
191
|
-
|
|
192
|
-
result = reg.get_list()
|
|
193
|
-
self.assertEqual(result["version"], "7h3/0.1")
|
|
194
|
-
self.assertEqual(len(result["revokedKeys"]), 1)
|
|
195
|
-
|
|
196
|
-
entry = result["revokedKeys"][0]
|
|
197
|
-
self.assertEqual(entry["id"], "key-foo")
|
|
198
|
-
self.assertGreaterEqual(entry["revokedAt"], before)
|
|
199
|
-
self.assertLessEqual(entry["revokedAt"], after)
|
|
200
|
-
self.assertEqual(entry["reason"], "expired")
|
|
201
|
-
|
|
202
|
-
def test_get_list_omits_reason_when_none(self):
|
|
203
|
-
reg = RevocationRegistry()
|
|
204
|
-
reg.revoke("key-noreaso")
|
|
205
|
-
result = reg.get_list()
|
|
206
|
-
entry = result["revokedKeys"][0]
|
|
207
|
-
self.assertNotIn("reason", entry)
|
|
208
|
-
|
|
209
|
-
def test_get_list_multiple_revoked(self):
|
|
210
|
-
reg = RevocationRegistry()
|
|
211
|
-
reg.revoke("key-a")
|
|
212
|
-
reg.revoke("key-b")
|
|
213
|
-
result = reg.get_list()
|
|
214
|
-
ids = {e["id"] for e in result["revokedKeys"]}
|
|
215
|
-
self.assertIn("key-a", ids)
|
|
216
|
-
self.assertIn("key-b", ids)
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
class TestRevocationRegistryImportList(unittest.TestCase):
|
|
220
|
-
"""Test 5: RevocationRegistry: import_list merges entries."""
|
|
221
|
-
|
|
222
|
-
def test_import_list_adds_entries(self):
|
|
223
|
-
reg = RevocationRegistry()
|
|
224
|
-
revocation_list = {
|
|
225
|
-
"version": "7h3/0.1",
|
|
226
|
-
"updated": int(time.time() * 1000),
|
|
227
|
-
"revokedKeys": [
|
|
228
|
-
{"id": "key-remote-1", "revokedAt": 1700000000000},
|
|
229
|
-
{"id": "key-remote-2", "revokedAt": 1700000001000, "reason": "compromised"},
|
|
230
|
-
],
|
|
231
|
-
}
|
|
232
|
-
reg.import_list(revocation_list)
|
|
233
|
-
|
|
234
|
-
self.assertTrue(reg.is_revoked("key-remote-1"))
|
|
235
|
-
self.assertTrue(reg.is_revoked("key-remote-2"))
|
|
236
|
-
|
|
237
|
-
def test_import_list_does_not_overwrite_existing(self):
|
|
238
|
-
reg = RevocationRegistry()
|
|
239
|
-
local_revoked_at = int(time.time() * 1000)
|
|
240
|
-
reg.revoke("key-shared")
|
|
241
|
-
|
|
242
|
-
revocation_list = {
|
|
243
|
-
"revokedKeys": [
|
|
244
|
-
{"id": "key-shared", "revokedAt": 1000000000000, "reason": "remote"},
|
|
245
|
-
]
|
|
246
|
-
}
|
|
247
|
-
reg.import_list(revocation_list)
|
|
248
|
-
|
|
249
|
-
# Should still be revoked; original entry should be kept (not overwritten)
|
|
250
|
-
self.assertTrue(reg.is_revoked("key-shared"))
|
|
251
|
-
# Check that the local timestamp is preserved (not overwritten by remote)
|
|
252
|
-
result = reg.get_list()
|
|
253
|
-
entry = next(e for e in result["revokedKeys"] if e["id"] == "key-shared")
|
|
254
|
-
self.assertGreaterEqual(entry["revokedAt"], local_revoked_at - 100)
|
|
255
|
-
|
|
256
|
-
def test_import_list_merges_new_and_existing(self):
|
|
257
|
-
reg = RevocationRegistry()
|
|
258
|
-
reg.revoke("key-existing")
|
|
259
|
-
|
|
260
|
-
revocation_list = {
|
|
261
|
-
"revokedKeys": [
|
|
262
|
-
{"id": "key-new-from-remote", "revokedAt": 1700000000000},
|
|
263
|
-
]
|
|
264
|
-
}
|
|
265
|
-
reg.import_list(revocation_list)
|
|
266
|
-
|
|
267
|
-
self.assertTrue(reg.is_revoked("key-existing"))
|
|
268
|
-
self.assertTrue(reg.is_revoked("key-new-from-remote"))
|
|
269
|
-
|
|
270
|
-
def test_import_empty_list(self):
|
|
271
|
-
reg = RevocationRegistry()
|
|
272
|
-
reg.import_list({"revokedKeys": []})
|
|
273
|
-
result = reg.get_list()
|
|
274
|
-
self.assertEqual(result["revokedKeys"], [])
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
class TestKeyRotationManagerAddKeyGetCurrentKey(unittest.TestCase):
|
|
278
|
-
"""Test 6: KeyRotationManager: add_key + get_current_key returns newest."""
|
|
279
|
-
|
|
280
|
-
def test_get_current_key_returns_none_when_empty(self):
|
|
281
|
-
mgr = KeyRotationManager()
|
|
282
|
-
self.assertIsNone(mgr.get_current_key())
|
|
283
|
-
|
|
284
|
-
def test_get_current_key_returns_added_key(self):
|
|
285
|
-
mgr = KeyRotationManager()
|
|
286
|
-
now = int(time.time() * 1000)
|
|
287
|
-
pair = ManagedKeyPair(
|
|
288
|
-
id="key-1", public_key="pub-1", private_key="priv-1", created=now
|
|
289
|
-
)
|
|
290
|
-
mgr.add_key(pair)
|
|
291
|
-
result = mgr.get_current_key()
|
|
292
|
-
self.assertIsNotNone(result)
|
|
293
|
-
self.assertEqual(result.id, "key-1")
|
|
294
|
-
|
|
295
|
-
def test_get_current_key_returns_newest_of_multiple(self):
|
|
296
|
-
mgr = KeyRotationManager()
|
|
297
|
-
now = int(time.time() * 1000)
|
|
298
|
-
old_pair = ManagedKeyPair(
|
|
299
|
-
id="key-old", public_key="pub-old", private_key="priv-old",
|
|
300
|
-
created=now - 10000
|
|
301
|
-
)
|
|
302
|
-
new_pair = ManagedKeyPair(
|
|
303
|
-
id="key-new", public_key="pub-new", private_key="priv-new",
|
|
304
|
-
created=now
|
|
305
|
-
)
|
|
306
|
-
mgr.add_key(old_pair)
|
|
307
|
-
mgr.add_key(new_pair)
|
|
308
|
-
|
|
309
|
-
result = mgr.get_current_key()
|
|
310
|
-
self.assertEqual(result.id, "key-new")
|
|
311
|
-
|
|
312
|
-
def test_get_current_key_excludes_expired(self):
|
|
313
|
-
mgr = KeyRotationManager()
|
|
314
|
-
now = int(time.time() * 1000)
|
|
315
|
-
expired_pair = ManagedKeyPair(
|
|
316
|
-
id="key-expired", public_key="pub-exp", private_key="priv-exp",
|
|
317
|
-
created=now - 10000,
|
|
318
|
-
expires_at=now - 1000, # already expired
|
|
319
|
-
)
|
|
320
|
-
active_pair = ManagedKeyPair(
|
|
321
|
-
id="key-active", public_key="pub-act", private_key="priv-act",
|
|
322
|
-
created=now - 5000,
|
|
323
|
-
expires_at=now + 3600000,
|
|
324
|
-
)
|
|
325
|
-
mgr.add_key(expired_pair)
|
|
326
|
-
mgr.add_key(active_pair)
|
|
327
|
-
|
|
328
|
-
result = mgr.get_current_key()
|
|
329
|
-
self.assertEqual(result.id, "key-active")
|
|
330
|
-
|
|
331
|
-
def test_get_current_key_none_when_all_expired(self):
|
|
332
|
-
mgr = KeyRotationManager()
|
|
333
|
-
now = int(time.time() * 1000)
|
|
334
|
-
expired = ManagedKeyPair(
|
|
335
|
-
id="key-exp", public_key="pub", private_key="priv",
|
|
336
|
-
created=now - 10000,
|
|
337
|
-
expires_at=now - 1000,
|
|
338
|
-
)
|
|
339
|
-
mgr.add_key(expired)
|
|
340
|
-
self.assertIsNone(mgr.get_current_key())
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
class TestKeyRotationManagerGetWellKnownDocument(unittest.TestCase):
|
|
344
|
-
"""Test 7: KeyRotationManager: get_well_known_document returns correct format."""
|
|
345
|
-
|
|
346
|
-
def test_well_known_document_empty(self):
|
|
347
|
-
mgr = KeyRotationManager()
|
|
348
|
-
doc = mgr.get_well_known_document()
|
|
349
|
-
self.assertEqual(doc.version, "7h3/0.1")
|
|
350
|
-
self.assertIsInstance(doc.updated, int)
|
|
351
|
-
self.assertEqual(doc.keys, [])
|
|
352
|
-
|
|
353
|
-
def test_well_known_document_with_keys(self):
|
|
354
|
-
mgr = KeyRotationManager()
|
|
355
|
-
now = int(time.time() * 1000)
|
|
356
|
-
pair1 = ManagedKeyPair(
|
|
357
|
-
id="key-1", public_key="pub-spki-1==", private_key="priv-pkcs8-1==",
|
|
358
|
-
created=now - 1000,
|
|
359
|
-
)
|
|
360
|
-
pair2 = ManagedKeyPair(
|
|
361
|
-
id="key-2", public_key="pub-spki-2==", private_key="priv-pkcs8-2==",
|
|
362
|
-
created=now,
|
|
363
|
-
expires_at=now + 3600000,
|
|
364
|
-
)
|
|
365
|
-
mgr.add_key(pair1)
|
|
366
|
-
mgr.add_key(pair2)
|
|
367
|
-
|
|
368
|
-
doc = mgr.get_well_known_document()
|
|
369
|
-
self.assertEqual(doc.version, "7h3/0.1")
|
|
370
|
-
self.assertEqual(len(doc.keys), 2)
|
|
371
|
-
|
|
372
|
-
ids = {k.id for k in doc.keys}
|
|
373
|
-
self.assertIn("key-1", ids)
|
|
374
|
-
self.assertIn("key-2", ids)
|
|
375
|
-
|
|
376
|
-
for k in doc.keys:
|
|
377
|
-
self.assertEqual(k.algorithm, "Ed25519")
|
|
378
|
-
self.assertIsNotNone(k.public_key)
|
|
379
|
-
|
|
380
|
-
def test_well_known_document_is_serializable(self):
|
|
381
|
-
mgr = KeyRotationManager()
|
|
382
|
-
now = int(time.time() * 1000)
|
|
383
|
-
mgr.add_key(ManagedKeyPair(
|
|
384
|
-
id="key-serial", public_key="pub-spki==", private_key="priv==",
|
|
385
|
-
created=now,
|
|
386
|
-
))
|
|
387
|
-
|
|
388
|
-
doc = mgr.get_well_known_document()
|
|
389
|
-
serialized = doc.to_json()
|
|
390
|
-
parsed = json.loads(serialized)
|
|
391
|
-
|
|
392
|
-
self.assertEqual(parsed["version"], "7h3/0.1")
|
|
393
|
-
self.assertIn("updated", parsed)
|
|
394
|
-
self.assertEqual(len(parsed["keys"]), 1)
|
|
395
|
-
self.assertEqual(parsed["keys"][0]["id"], "key-serial")
|
|
396
|
-
self.assertEqual(parsed["keys"][0]["algorithm"], "Ed25519")
|
|
397
|
-
self.assertEqual(parsed["keys"][0]["publicKey"], "pub-spki==")
|
|
398
|
-
|
|
399
|
-
def test_expired_key_marked_revoked_in_document(self):
|
|
400
|
-
mgr = KeyRotationManager()
|
|
401
|
-
now = int(time.time() * 1000)
|
|
402
|
-
# A key that has already expired
|
|
403
|
-
expired_pair = ManagedKeyPair(
|
|
404
|
-
id="key-expired", public_key="pub==", private_key="priv==",
|
|
405
|
-
created=now - 10000,
|
|
406
|
-
expires_at=now - 1000,
|
|
407
|
-
)
|
|
408
|
-
mgr.add_key(expired_pair)
|
|
409
|
-
|
|
410
|
-
doc = mgr.get_well_known_document()
|
|
411
|
-
self.assertEqual(len(doc.keys), 1)
|
|
412
|
-
entry = doc.keys[0]
|
|
413
|
-
self.assertTrue(entry.revoked)
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
if __name__ == "__main__":
|
|
417
|
-
unittest.main()
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"""Tests for protocol_7h3.queue — Queue message binding."""
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
|
|
4
|
-
import json
|
|
5
|
-
import unittest
|
|
6
|
-
|
|
7
|
-
from protocol_7h3.queue import (
|
|
8
|
-
sign_queue_message,
|
|
9
|
-
verify_queue_message,
|
|
10
|
-
verify_queue_batch,
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
# Keys from conformance vectors (PKCS8/SPKI DER, base64url-encoded)
|
|
14
|
-
PRIVATE_KEY = "MC4CAQAwBQYDK2VwBCIEICheZbQGuDVb6hezIlcs0QnCHGxz6IhiLkC9M0qr8OOZ"
|
|
15
|
-
PUBLIC_KEY = "MCowBQYDK2VwAyEA-mUFiTQtcKN4nnD19V_-Wyy4q19OivnAutRUPhOcC78"
|
|
16
|
-
|
|
17
|
-
# A different public key to test wrong-key rejection (second key from test vectors or generated)
|
|
18
|
-
OTHER_PUBLIC_KEY = "MCowBQYDK2VwAyEAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def _make_signed(payload: object) -> str:
|
|
22
|
-
return sign_queue_message(payload, PRIVATE_KEY, sender="test.sender")
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class TestSignVerifyRoundTrip(unittest.TestCase):
|
|
26
|
-
def test_string_payload_roundtrip(self):
|
|
27
|
-
"""sign_queue_message + verify_queue_message round trip (string payload)."""
|
|
28
|
-
payload = "hello queue"
|
|
29
|
-
signed = _make_signed(payload)
|
|
30
|
-
result = verify_queue_message(signed, PUBLIC_KEY)
|
|
31
|
-
self.assertEqual(result["payload"], payload)
|
|
32
|
-
self.assertIn("envelope", result)
|
|
33
|
-
self.assertIn("header", result["envelope"])
|
|
34
|
-
self.assertIn("signature", result["envelope"])
|
|
35
|
-
|
|
36
|
-
def test_dict_payload_roundtrip(self):
|
|
37
|
-
"""Round trip with dict payload."""
|
|
38
|
-
payload = {"task": "process", "items": [1, 2, 3], "meta": {"retry": True}}
|
|
39
|
-
signed = _make_signed(payload)
|
|
40
|
-
result = verify_queue_message(signed, PUBLIC_KEY)
|
|
41
|
-
self.assertEqual(result["payload"], payload)
|
|
42
|
-
self.assertIn("signature", result["envelope"])
|
|
43
|
-
|
|
44
|
-
def test_verify_raises_on_tampered_envelope(self):
|
|
45
|
-
"""verify_queue_message raises on tampered envelope."""
|
|
46
|
-
signed = _make_signed("important data")
|
|
47
|
-
wrapper = json.loads(signed)
|
|
48
|
-
# Tamper with the sender field inside the envelope
|
|
49
|
-
wrapper["envelope"]["header"]["sender"] = "evil.actor"
|
|
50
|
-
tampered = json.dumps(wrapper)
|
|
51
|
-
with self.assertRaises(ValueError) as ctx:
|
|
52
|
-
verify_queue_message(tampered, PUBLIC_KEY)
|
|
53
|
-
self.assertIn("7h3:", str(ctx.exception))
|
|
54
|
-
|
|
55
|
-
def test_verify_raises_on_wrong_public_key(self):
|
|
56
|
-
"""verify_queue_message raises on wrong public key."""
|
|
57
|
-
# Generate a different key pair by using a known different key from a second vector
|
|
58
|
-
# We use a second private/public pair
|
|
59
|
-
alt_private = "MC4CAQAwBQYDK2VwBCIEIBcJSnDN3_g3o_0K5VJHOO_HqFcBCUt1tnGbqiVoaWyb"
|
|
60
|
-
alt_public = "MCowBQYDK2VwAyEAiFt0vBZq_X5sMCbR5_LhkRKU2ueD80_bqFMhqfYP5TA"
|
|
61
|
-
signed = sign_queue_message("payload", alt_private, sender="test.sender")
|
|
62
|
-
with self.assertRaises(ValueError) as ctx:
|
|
63
|
-
verify_queue_message(signed, PUBLIC_KEY)
|
|
64
|
-
self.assertIn("7h3:", str(ctx.exception))
|
|
65
|
-
|
|
66
|
-
def test_verify_raises_on_malformed_json(self):
|
|
67
|
-
"""verify_queue_message raises on malformed JSON."""
|
|
68
|
-
with self.assertRaises(ValueError) as ctx:
|
|
69
|
-
verify_queue_message("{not valid json}", PUBLIC_KEY)
|
|
70
|
-
self.assertIn("7h3: malformed queue message", str(ctx.exception))
|
|
71
|
-
|
|
72
|
-
def test_verify_raises_on_missing_envelope(self):
|
|
73
|
-
"""verify_queue_message raises when envelope key is missing."""
|
|
74
|
-
msg = json.dumps({"payload": "data"})
|
|
75
|
-
with self.assertRaises(ValueError) as ctx:
|
|
76
|
-
verify_queue_message(msg, PUBLIC_KEY)
|
|
77
|
-
self.assertIn("7h3: missing envelope", str(ctx.exception))
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
class TestVerifyQueueBatch(unittest.TestCase):
|
|
81
|
-
def test_batch_mixed_ok_and_fail(self):
|
|
82
|
-
"""verify_queue_batch: returns correct ok/false mix."""
|
|
83
|
-
valid_msg = _make_signed("valid payload")
|
|
84
|
-
invalid_msg = "not json at all"
|
|
85
|
-
results = verify_queue_batch([valid_msg, invalid_msg], PUBLIC_KEY)
|
|
86
|
-
self.assertEqual(len(results), 2)
|
|
87
|
-
self.assertTrue(results[0]["ok"])
|
|
88
|
-
self.assertEqual(results[0]["payload"], "valid payload")
|
|
89
|
-
self.assertFalse(results[1]["ok"])
|
|
90
|
-
self.assertIn("error", results[1])
|
|
91
|
-
self.assertEqual(results[1]["raw"], invalid_msg)
|
|
92
|
-
|
|
93
|
-
def test_batch_all_valid(self):
|
|
94
|
-
"""verify_queue_batch: all valid messages."""
|
|
95
|
-
messages = [_make_signed(f"msg-{i}") for i in range(3)]
|
|
96
|
-
results = verify_queue_batch(messages, PUBLIC_KEY)
|
|
97
|
-
self.assertEqual(len(results), 3)
|
|
98
|
-
for i, r in enumerate(results):
|
|
99
|
-
self.assertTrue(r["ok"], f"message {i} should be ok")
|
|
100
|
-
self.assertEqual(r["payload"], f"msg-{i}")
|
|
101
|
-
self.assertIn("envelope", r)
|
|
102
|
-
|
|
103
|
-
def test_batch_all_invalid_never_throws(self):
|
|
104
|
-
"""verify_queue_batch: all invalid messages (never throws)."""
|
|
105
|
-
bad_messages = [
|
|
106
|
-
"not json",
|
|
107
|
-
json.dumps({"no": "envelope"}),
|
|
108
|
-
"",
|
|
109
|
-
"{}",
|
|
110
|
-
]
|
|
111
|
-
# Must not raise
|
|
112
|
-
results = verify_queue_batch(bad_messages, PUBLIC_KEY)
|
|
113
|
-
self.assertEqual(len(results), len(bad_messages))
|
|
114
|
-
for r in results:
|
|
115
|
-
self.assertFalse(r["ok"])
|
|
116
|
-
self.assertIn("error", r)
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if __name__ == "__main__":
|
|
120
|
-
unittest.main()
|