orangecheck 2.7.0__tar.gz → 2.8.0__tar.gz
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.
- {orangecheck-2.7.0 → orangecheck-2.8.0}/CHANGELOG.md +21 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/PKG-INFO +4 -2
- {orangecheck-2.7.0 → orangecheck-2.8.0}/README.md +3 -1
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/__init__.py +1 -1
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/integrator.py +76 -41
- {orangecheck-2.7.0 → orangecheck-2.8.0}/pyproject.toml +1 -1
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/test_integrator_vectors.py +61 -24
- {orangecheck-2.7.0 → orangecheck-2.8.0}/.gitignore +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/__main__.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/address.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/bond.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/canonical.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/client.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/errors.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/pledge/__init__.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/pledge/bond.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/pledge/canonical.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/pledge/delegation.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/pledge/envelopes.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/pledge/resolution.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/pledge/state.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/py.typed +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/top_level.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/types.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/orangecheck/verify_sig.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/fixtures/bip137-parity.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/fixtures/bip322-js-6.1.8.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/fixtures/bip322-official-basic.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/fixtures/bip322-official-generated.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/pledge/__init__.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/pledge/test_authority.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/pledge/test_delegation.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/pledge/test_vectors.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/pledge/test_wrap.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/test_address.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/test_bip322_official.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/test_client.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/test_client_failure_modes.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/test_conformance.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/test_ripemd160.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/test_signature_parity.py +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/index.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv01.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv02.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv03.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv04.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv05.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv06.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv07.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv08.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv09.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv10.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv11.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv12.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv13.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv14.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv15.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv16.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv17.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv18.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv19.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv20.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv21.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv22.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv23.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv24.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv25.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv26.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv27.json +0 -0
- {orangecheck-2.7.0 → orangecheck-2.8.0}/tests/vectors/tv28.json +0 -0
|
@@ -4,6 +4,27 @@ All notable changes to the **`orangecheck`** Python package. Follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [2.8.0] — 2026-10-22
|
|
8
|
+
|
|
9
|
+
### Changed — revocation by per-audience handle
|
|
10
|
+
|
|
11
|
+
As `@orangecheck/auth-core` 2.12.0. A sign-in token carries `rh`, its revocation
|
|
12
|
+
handle for its own audience; `RevocationList` looks it up in me.ochk.io's list of
|
|
13
|
+
ended handles for that audience, one list per audience, fetched at most once a
|
|
14
|
+
minute with a request signed over method, path and audience
|
|
15
|
+
(`<t>.GET /api/integrator/revocations?project_key=…&aud=…`). The handles name
|
|
16
|
+
nobody, and two sites' handles for one person never match.
|
|
17
|
+
- `RevocationList.status(rh, aud, iat)` replaces `status(sub, iat)`. A token
|
|
18
|
+
without `rh` is `"live"`: checked by its signature alone.
|
|
19
|
+
- A list's age is measured from its own `at`; one older than ten minutes, or dated
|
|
20
|
+
more than 60 s ahead, cannot vouch for a write.
|
|
21
|
+
- The first failed fetch logs one warning (`orangecheck` logger).
|
|
22
|
+
|
|
23
|
+
### Deprecated
|
|
24
|
+
|
|
25
|
+
- 2.7.0. me.ochk.io answers its request with an empty list, which it reads as
|
|
26
|
+
"nothing ended". Use 2.8.0 or later.
|
|
27
|
+
|
|
7
28
|
## [2.7.0] — 2026-10-22
|
|
8
29
|
|
|
9
30
|
### Added — refuse a session the person ended everywhere
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: orangecheck
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.8.0
|
|
4
4
|
Summary: Python SDK for OrangeCheck — proof of Bitcoin stake, the OC Pledge primitive, and ochk.app sign-in for your backend.
|
|
5
5
|
Project-URL: Homepage, https://ochk.io
|
|
6
6
|
Project-URL: Documentation, https://ochk.io/docs
|
|
@@ -225,7 +225,7 @@ event = verify_webhook(request.headers, raw_body) # raises InvalidWebhook
|
|
|
225
225
|
|
|
226
226
|
A token verifies until it expires, up to 30 days. To refuse one the person
|
|
227
227
|
ended everywhere (signed out everywhere, removed a passkey, deleted the
|
|
228
|
-
account), keep one `RevocationList` per process and pass it with the request's
|
|
228
|
+
account), keep one `RevocationList` (2.8.0 or later) per process and pass it with the request's
|
|
229
229
|
method. It reads those account cutoffs from me.ochk.io at most once a minute,
|
|
230
230
|
signed with your secret:
|
|
231
231
|
|
|
@@ -238,6 +238,8 @@ session = verify_session(token, audience="https://your-site.example",
|
|
|
238
238
|
revocations=REVOCATIONS, method=request.method)
|
|
239
239
|
# SessionEnded (an InvalidSession) when the person ended it. While the list
|
|
240
240
|
# can't be read, reads go on and writes raise reason "revocations_unavailable".
|
|
241
|
+
# If your own session replaces the token, keep its rh, aud and iat with that
|
|
242
|
+
# session and ask REVOCATIONS.status(rh, aud, iat): "revoked" ends it.
|
|
241
243
|
```
|
|
242
244
|
|
|
243
245
|
The full guide is at [ochk.io/docs/sdk/python](https://ochk.io/docs/sdk/python).
|
|
@@ -188,7 +188,7 @@ event = verify_webhook(request.headers, raw_body) # raises InvalidWebhook
|
|
|
188
188
|
|
|
189
189
|
A token verifies until it expires, up to 30 days. To refuse one the person
|
|
190
190
|
ended everywhere (signed out everywhere, removed a passkey, deleted the
|
|
191
|
-
account), keep one `RevocationList` per process and pass it with the request's
|
|
191
|
+
account), keep one `RevocationList` (2.8.0 or later) per process and pass it with the request's
|
|
192
192
|
method. It reads those account cutoffs from me.ochk.io at most once a minute,
|
|
193
193
|
signed with your secret:
|
|
194
194
|
|
|
@@ -201,6 +201,8 @@ session = verify_session(token, audience="https://your-site.example",
|
|
|
201
201
|
revocations=REVOCATIONS, method=request.method)
|
|
202
202
|
# SessionEnded (an InvalidSession) when the person ended it. While the list
|
|
203
203
|
# can't be read, reads go on and writes raise reason "revocations_unavailable".
|
|
204
|
+
# If your own session replaces the token, keep its rh, aud and iat with that
|
|
205
|
+
# session and ask REVOCATIONS.status(rh, aud, iat): "revoked" ends it.
|
|
204
206
|
```
|
|
205
207
|
|
|
206
208
|
The full guide is at [ochk.io/docs/sdk/python](https://ochk.io/docs/sdk/python).
|
|
@@ -145,7 +145,7 @@ __all__ = [
|
|
|
145
145
|
"VerificationError",
|
|
146
146
|
]
|
|
147
147
|
|
|
148
|
-
__version__ = "2.
|
|
148
|
+
__version__ = "2.8.0"
|
|
149
149
|
|
|
150
150
|
# OC Pledge submodule — sibling primitive for forward-looking commitments
|
|
151
151
|
# bound to a Bitcoin address. Imported here so consumers can write:
|
|
@@ -25,6 +25,7 @@ import binascii
|
|
|
25
25
|
import hashlib
|
|
26
26
|
import hmac
|
|
27
27
|
import json
|
|
28
|
+
import logging
|
|
28
29
|
import threading
|
|
29
30
|
import time
|
|
30
31
|
from collections.abc import Mapping
|
|
@@ -165,41 +166,36 @@ def _import_jwks(doc: Any) -> dict[str, Ed25519PublicKey]:
|
|
|
165
166
|
return keys
|
|
166
167
|
|
|
167
168
|
|
|
168
|
-
# ───
|
|
169
|
+
# ─── revocation handles ──────────────────────────────────────────────────
|
|
169
170
|
|
|
170
171
|
REVOCATIONS_URL = "https://me.ochk.io/api/integrator/revocations"
|
|
171
172
|
_REVOCATIONS_TTL_SECONDS = 60
|
|
172
173
|
_REVOCATIONS_MAX_STALE_SECONDS = 600
|
|
174
|
+
_REVOCATIONS_SKEW_SECONDS = 60
|
|
173
175
|
_REVOCATIONS_RETRY_SECONDS = 10
|
|
174
176
|
_SAFE_METHODS = frozenset({"GET", "HEAD", "OPTIONS"})
|
|
177
|
+
_log = logging.getLogger("orangecheck")
|
|
175
178
|
|
|
176
179
|
|
|
177
180
|
def revocation_key(kind: str, value: str) -> str:
|
|
178
|
-
"""The
|
|
181
|
+
"""The revocation store's key for a token (``"jti"``) or an account (``"sub"``), as auth-core derives it."""
|
|
179
182
|
digest = hashlib.sha256(f"ocrev1:{kind}:{value}".encode("utf-8")).digest()[:16]
|
|
180
183
|
return base64.urlsafe_b64encode(digest).decode("ascii").rstrip("=")
|
|
181
184
|
|
|
182
185
|
|
|
183
|
-
class
|
|
184
|
-
"""
|
|
185
|
-
The account cutoffs (sign out everywhere, a passkey removed, an account
|
|
186
|
-
deleted) from me.ochk.io, fetched at most once a minute with a request
|
|
187
|
-
signed by your project secret, as ``@orangecheck/auth-core``'s
|
|
188
|
-
``integratorRevocationCheck`` does. Make one per process and pass it to
|
|
189
|
-
:func:`verify_session`.
|
|
190
|
-
|
|
191
|
-
``status`` is ``"revoked"``, ``"live"``, or ``"unverified"`` when no copy
|
|
192
|
-
younger than ten minutes could be read: then reads may go on, but a write
|
|
193
|
-
should not.
|
|
194
|
-
"""
|
|
186
|
+
class _AudienceList:
|
|
187
|
+
"""me.ochk.io's ended handles for one audience, fetched at most once a minute."""
|
|
195
188
|
|
|
196
|
-
def __init__(self,
|
|
197
|
-
|
|
198
|
-
self.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
189
|
+
def __init__(self, owner: "RevocationList", aud: str):
|
|
190
|
+
self._owner = owner
|
|
191
|
+
self._path = (
|
|
192
|
+
"/api/integrator/revocations?project_key="
|
|
193
|
+
+ quote(owner._project_key, safe="-_.!~*'()")
|
|
194
|
+
+ "&aud="
|
|
195
|
+
+ quote(aud, safe="-_.!~*'()")
|
|
196
|
+
)
|
|
197
|
+
self._handles: dict[str, float] = {}
|
|
198
|
+
self._at: Optional[float] = None
|
|
203
199
|
self._fetched_at: Optional[float] = None
|
|
204
200
|
self._failed_at = float("-inf")
|
|
205
201
|
self._lock = threading.Lock()
|
|
@@ -207,34 +203,31 @@ class RevocationList:
|
|
|
207
203
|
def _fetch(self) -> None:
|
|
208
204
|
try:
|
|
209
205
|
r = httpx.get(
|
|
210
|
-
self.
|
|
206
|
+
self._owner._base + self._path,
|
|
211
207
|
headers={
|
|
212
208
|
"Accept": "application/json",
|
|
213
|
-
"X-OC-Signature": sign_event(self._secret, self.
|
|
209
|
+
"X-OC-Signature": sign_event(self._owner._secret, f"GET {self._path}"),
|
|
214
210
|
},
|
|
215
211
|
timeout=3.0,
|
|
216
212
|
)
|
|
217
213
|
r.raise_for_status()
|
|
218
214
|
doc = r.json()
|
|
219
|
-
if (
|
|
220
|
-
not isinstance(doc, dict)
|
|
221
|
-
or doc.get("v") != 1
|
|
222
|
-
or not isinstance(doc.get("tokens"), list)
|
|
223
|
-
or not isinstance(doc.get("accounts"), dict)
|
|
224
|
-
):
|
|
215
|
+
if not isinstance(doc, dict) or doc.get("v") != 1:
|
|
225
216
|
raise ValueError("revocations: unexpected body")
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
for k, v in
|
|
230
|
-
if isinstance(v, (int, float)) and not isinstance(v, bool)
|
|
217
|
+
raw = doc.get("handles")
|
|
218
|
+
handles: dict[str, Any] = raw if isinstance(raw, dict) else {}
|
|
219
|
+
self._handles = {
|
|
220
|
+
k: float(v) for k, v in handles.items() if isinstance(v, (int, float)) and not isinstance(v, bool)
|
|
231
221
|
}
|
|
222
|
+
at = doc.get("at")
|
|
223
|
+
self._at = float(at) if isinstance(at, (int, float)) and not isinstance(at, bool) else None
|
|
232
224
|
self._fetched_at = time.time()
|
|
233
|
-
except (httpx.HTTPError, ValueError):
|
|
225
|
+
except (httpx.HTTPError, ValueError) as err:
|
|
234
226
|
# Keep the last copy; try again after a short wait.
|
|
235
227
|
self._failed_at = time.time()
|
|
228
|
+
self._owner._warn_once(err)
|
|
236
229
|
|
|
237
|
-
def status(self,
|
|
230
|
+
def status(self, rh: str, iat: Optional[float]) -> str:
|
|
238
231
|
with self._lock:
|
|
239
232
|
now = time.time()
|
|
240
233
|
fresh = self._fetched_at is not None and now - self._fetched_at < _REVOCATIONS_TTL_SECONDS
|
|
@@ -242,12 +235,53 @@ class RevocationList:
|
|
|
242
235
|
self._fetch()
|
|
243
236
|
if self._fetched_at is None:
|
|
244
237
|
return "unverified"
|
|
245
|
-
|
|
246
|
-
return "revoked"
|
|
247
|
-
cutoff = self._accounts.get(revocation_key("sub", sub))
|
|
238
|
+
cutoff = self._handles.get(rh)
|
|
248
239
|
if cutoff is not None and not (iat is not None and iat >= cutoff):
|
|
249
240
|
return "revoked"
|
|
250
|
-
|
|
241
|
+
# The list's age is its own: an old copy served fresh is still old.
|
|
242
|
+
if self._at is None or self._at > now + _REVOCATIONS_SKEW_SECONDS:
|
|
243
|
+
return "unverified"
|
|
244
|
+
return "unverified" if now - self._at > _REVOCATIONS_MAX_STALE_SECONDS else "live"
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
class RevocationList:
|
|
248
|
+
"""
|
|
249
|
+
Sessions the person ended everywhere (sign out everywhere, a passkey removed,
|
|
250
|
+
an account deleted), as ``@orangecheck/auth-core``'s ``integratorRevocationCheck``
|
|
251
|
+
sees them. A sign-in token carries ``rh``, its revocation handle for its own
|
|
252
|
+
audience; this looks it up in me.ochk.io's list of ended handles for that
|
|
253
|
+
audience, fetched at most once a minute per audience with a request signed by
|
|
254
|
+
your project secret over method, path and audience. Make one per process and
|
|
255
|
+
pass it to :func:`verify_session`.
|
|
256
|
+
|
|
257
|
+
``status(rh, aud, iat)`` is ``"revoked"``, ``"live"``, or ``"unverified"`` when
|
|
258
|
+
no list younger than ten minutes (by its own ``at``) could be read: then reads
|
|
259
|
+
may go on, but a write should not. A token without ``rh`` is ``"live"``: it is
|
|
260
|
+
checked by its signature alone.
|
|
261
|
+
"""
|
|
262
|
+
|
|
263
|
+
def __init__(self, project_key: str, signing_secret: str, *, url: str = REVOCATIONS_URL):
|
|
264
|
+
self._project_key = project_key
|
|
265
|
+
self._secret = signing_secret
|
|
266
|
+
self._base = url[: -len("/api/integrator/revocations")] if url.endswith("/api/integrator/revocations") else url
|
|
267
|
+
self._lists: dict[str, _AudienceList] = {}
|
|
268
|
+
self._lists_lock = threading.Lock()
|
|
269
|
+
self._warned = False
|
|
270
|
+
|
|
271
|
+
def _warn_once(self, err: Exception) -> None:
|
|
272
|
+
if self._warned:
|
|
273
|
+
return
|
|
274
|
+
self._warned = True
|
|
275
|
+
_log.warning("orangecheck: the revocation list could not be read (%s); reads go on, writes are refused until it can", err)
|
|
276
|
+
|
|
277
|
+
def status(self, rh: Optional[str], aud: Optional[str], iat: Optional[float]) -> str:
|
|
278
|
+
if not isinstance(rh, str) or not rh or not isinstance(aud, str) or not aud:
|
|
279
|
+
return "live"
|
|
280
|
+
with self._lists_lock:
|
|
281
|
+
lst = self._lists.get(aud)
|
|
282
|
+
if lst is None:
|
|
283
|
+
lst = self._lists[aud] = _AudienceList(self, aud)
|
|
284
|
+
return lst.status(rh, iat)
|
|
251
285
|
|
|
252
286
|
|
|
253
287
|
# ─── sign-in tokens ──────────────────────────────────────────────────────
|
|
@@ -346,7 +380,8 @@ def verify_session(
|
|
|
346
380
|
raise InvalidSession("audience")
|
|
347
381
|
|
|
348
382
|
if revocations is not None:
|
|
349
|
-
|
|
383
|
+
token_aud = aud if isinstance(aud, str) else None
|
|
384
|
+
state = revocations.status(payload.get("rh"), token_aud, iat)
|
|
350
385
|
if state == "revoked":
|
|
351
386
|
raise SessionEnded()
|
|
352
387
|
if state == "unverified" and (method or "").upper() not in _SAFE_METHODS:
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "orangecheck"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.8.0"
|
|
8
8
|
description = "Python SDK for OrangeCheck — proof of Bitcoin stake, the OC Pledge primitive, and ochk.app sign-in for your backend."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { text = "MIT" }
|
|
@@ -15,6 +15,7 @@ from pathlib import Path
|
|
|
15
15
|
from typing import Any
|
|
16
16
|
|
|
17
17
|
import httpx
|
|
18
|
+
from urllib.parse import quote
|
|
18
19
|
import pytest
|
|
19
20
|
import respx
|
|
20
21
|
|
|
@@ -180,7 +181,7 @@ def test_webhook_fetches_me_ochk_io_dev_jwks(fresh_key_sets: None) -> None:
|
|
|
180
181
|
assert route.call_count == 1
|
|
181
182
|
|
|
182
183
|
|
|
183
|
-
# ───
|
|
184
|
+
# ─── revocation handles ──────────────────────────────────────────────────
|
|
184
185
|
|
|
185
186
|
R = V["revocation"]
|
|
186
187
|
|
|
@@ -189,10 +190,16 @@ def _revocations() -> RevocationList:
|
|
|
189
190
|
return RevocationList(R["request"]["project_key"], R["request"]["secret"])
|
|
190
191
|
|
|
191
192
|
|
|
193
|
+
def _serve_lists() -> None:
|
|
194
|
+
for aud, body in R["lists"].items():
|
|
195
|
+
url = f"https://me.ochk.io/api/integrator/revocations?project_key={R['request']['project_key']}&aud={quote(aud, safe='')}"
|
|
196
|
+
respx.get(url).mock(return_value=httpx.Response(200, json=body))
|
|
197
|
+
|
|
198
|
+
|
|
192
199
|
@respx.mock
|
|
193
200
|
def test_revocations_request_is_signed_as_the_node_sdk_signs_it() -> None:
|
|
194
|
-
route = respx.get(R["request"]["url"]).mock(return_value=httpx.Response(200, json=R["
|
|
195
|
-
_revocations().status("
|
|
201
|
+
route = respx.get(R["request"]["url"]).mock(return_value=httpx.Response(200, json=R["lists"][R["request"]["aud"]]))
|
|
202
|
+
_revocations().status("any", R["request"]["aud"], 0)
|
|
196
203
|
assert route.call_count == 1
|
|
197
204
|
sent = route.calls[0].request
|
|
198
205
|
assert str(sent.url) == R["request"]["url"]
|
|
@@ -207,29 +214,54 @@ def test_revocation_key_matches_the_node_sdk(v: dict[str, Any]) -> None:
|
|
|
207
214
|
@respx.mock
|
|
208
215
|
@pytest.mark.parametrize("v", R["sessions"], ids=lambda v: v["name"])
|
|
209
216
|
def test_revocations_decide_as_the_node_sdk_does(v: dict[str, Any]) -> None:
|
|
210
|
-
|
|
211
|
-
assert _revocations().status(v["
|
|
217
|
+
_serve_lists()
|
|
218
|
+
assert _revocations().status(v["rh"], v["aud"], v["iat"]) == v["status"]
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
@respx.mock
|
|
222
|
+
def test_a_token_with_no_handle_is_never_looked_up() -> None:
|
|
223
|
+
route = respx.get(url__startswith="https://me.ochk.io/api/integrator/revocations").mock(
|
|
224
|
+
return_value=httpx.Response(200, json={})
|
|
225
|
+
)
|
|
226
|
+
assert _revocations().status(None, R["request"]["aud"], 0) == "live"
|
|
227
|
+
assert route.call_count == 0
|
|
212
228
|
|
|
213
229
|
|
|
214
230
|
@respx.mock
|
|
215
|
-
def
|
|
216
|
-
route = respx.get(R["request"]["url"]).mock(return_value=httpx.Response(200, json=R["
|
|
231
|
+
def test_revocations_are_fetched_at_most_once_a_minute_per_audience(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
232
|
+
route = respx.get(R["request"]["url"]).mock(return_value=httpx.Response(200, json=R["lists"][R["request"]["aud"]]))
|
|
217
233
|
rl = _revocations()
|
|
218
|
-
rl.status("
|
|
219
|
-
rl.status("
|
|
234
|
+
rl.status("x", R["request"]["aud"], 0)
|
|
235
|
+
rl.status("x", R["request"]["aud"], 0)
|
|
220
236
|
assert route.call_count == 1
|
|
221
237
|
monkeypatch.setattr(integrator.time, "time", lambda: float(V["now"] + 61))
|
|
222
|
-
rl.status("
|
|
238
|
+
rl.status("x", R["request"]["aud"], 0)
|
|
223
239
|
assert route.call_count == 2
|
|
224
240
|
|
|
225
241
|
|
|
226
242
|
@respx.mock
|
|
227
|
-
def
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
243
|
+
def test_a_list_dated_too_old_or_too_far_ahead_cannot_vouch(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
244
|
+
body = dict(R["lists"][R["request"]["aud"]])
|
|
245
|
+
respx.get(R["request"]["url"]).mock(return_value=httpx.Response(200, json=body))
|
|
246
|
+
monkeypatch.setattr(integrator.time, "time", lambda: float(V["now"] + 11 * 60))
|
|
247
|
+
assert _revocations().status("x", R["request"]["aud"], 0) == "unverified"
|
|
248
|
+
monkeypatch.setattr(integrator.time, "time", lambda: float(V["now"] - 5 * 60))
|
|
249
|
+
assert _revocations().status("x", R["request"]["aud"], 0) == "unverified"
|
|
250
|
+
monkeypatch.setattr(integrator.time, "time", lambda: float(V["now"] - 30))
|
|
251
|
+
assert _revocations().status("x", R["request"]["aud"], 0) == "live"
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _rh_vector() -> dict[str, Any]:
|
|
255
|
+
return next(v for v in V["session"]["valid"] if v["claims"].get("rh"))
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
@respx.mock
|
|
259
|
+
def test_verify_session_refuses_a_session_whose_handle_is_ended() -> None:
|
|
260
|
+
v = _rh_vector()
|
|
261
|
+
url = f"https://me.ochk.io/api/integrator/revocations?project_key={R['request']['project_key']}&aud={quote(v['audience'], safe='')}"
|
|
262
|
+
respx.get(url).mock(return_value=httpx.Response(200, json={
|
|
263
|
+
"v": 1, "at": V["now"], "tokens": [], "accounts": {}, "handles": {v["claims"]["rh"]: v["claims"]["iat"] + 1},
|
|
264
|
+
}))
|
|
233
265
|
with pytest.raises(SessionEnded) as err:
|
|
234
266
|
verify_session(v["token"], v["audience"], jwks=V["session"]["jwks"], revocations=_revocations())
|
|
235
267
|
assert isinstance(err.value, InvalidSession)
|
|
@@ -237,12 +269,17 @@ def test_verify_session_refuses_a_session_its_account_cutoff_ends() -> None:
|
|
|
237
269
|
|
|
238
270
|
|
|
239
271
|
@respx.mock
|
|
240
|
-
def
|
|
241
|
-
|
|
242
|
-
|
|
272
|
+
def test_verify_session_keeps_reads_refuses_writes_and_warns_once_while_the_list_cannot_be_read(
|
|
273
|
+
caplog: pytest.LogCaptureFixture,
|
|
274
|
+
) -> None:
|
|
275
|
+
respx.get(url__startswith="https://me.ochk.io/api/integrator/revocations").mock(return_value=httpx.Response(503))
|
|
276
|
+
v = _rh_vector()
|
|
243
277
|
rl = _revocations()
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
278
|
+
with caplog.at_level("WARNING", logger="orangecheck"):
|
|
279
|
+
s = verify_session(v["token"], v["audience"], jwks=V["session"]["jwks"], revocations=rl, method="GET")
|
|
280
|
+
assert s.sub == v["claims"]["sub"]
|
|
281
|
+
with pytest.raises(InvalidSession) as err:
|
|
282
|
+
verify_session(v["token"], v["audience"], jwks=V["session"]["jwks"], revocations=rl, method="POST")
|
|
283
|
+
assert err.value.reason == "revocations_unavailable"
|
|
284
|
+
warnings = [r for r in caplog.records if r.name == "orangecheck" and r.levelname == "WARNING"]
|
|
285
|
+
assert len(warnings) == 1
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|