supso-project 1.0.0__py3-none-any.whl
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.
- supso/__init__.py +363 -0
- supso/certificate.py +152 -0
- supso/errors.py +45 -0
- supso/keys.py +69 -0
- supso/license.py +128 -0
- supso/verify.py +259 -0
- supso_project-1.0.0.dist-info/METADATA +110 -0
- supso_project-1.0.0.dist-info/RECORD +10 -0
- supso_project-1.0.0.dist-info/WHEEL +4 -0
- supso_project-1.0.0.dist-info/licenses/LICENSE-APACHE +201 -0
supso/__init__.py
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
"""``supso`` — Supported Source license verification.
|
|
2
|
+
|
|
3
|
+
Assert at startup that the downstream user holds a valid Supso license
|
|
4
|
+
certificate for your project. Verification is **100% offline**: it checks a
|
|
5
|
+
hybrid Ed25519 + ML-DSA-44 signature against Supso's baked-in public keys and
|
|
6
|
+
never touches the network. The library never terminates the host process — it
|
|
7
|
+
reports; the host decides.
|
|
8
|
+
|
|
9
|
+
.. code-block:: python
|
|
10
|
+
|
|
11
|
+
import supso
|
|
12
|
+
|
|
13
|
+
# Hard enforcement — raises SupsoError your app decides how to act on.
|
|
14
|
+
license = supso.require_license("acme-db")
|
|
15
|
+
|
|
16
|
+
# Soft enforcement — never raises; logs a notice on grace/failure.
|
|
17
|
+
status = supso.check_license("acme-db")
|
|
18
|
+
if supso.is_licensed(status):
|
|
19
|
+
... # run normally
|
|
20
|
+
|
|
21
|
+
Or configure once and call the no-argument forms (SPEC §9):
|
|
22
|
+
|
|
23
|
+
.. code-block:: python
|
|
24
|
+
|
|
25
|
+
supso.initialize_project("acme-db", grace_period_days=30)
|
|
26
|
+
license = supso.require_license()
|
|
27
|
+
status = supso.check_license()
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
from __future__ import annotations
|
|
31
|
+
|
|
32
|
+
import os
|
|
33
|
+
import sys
|
|
34
|
+
from dataclasses import dataclass, field
|
|
35
|
+
from datetime import datetime, timedelta, timezone
|
|
36
|
+
from typing import Optional
|
|
37
|
+
|
|
38
|
+
from .certificate import GraceValidity, Located, locate
|
|
39
|
+
from .errors import ErrorCode, SupsoError
|
|
40
|
+
from .keys import (
|
|
41
|
+
TRUSTED_ED25519_KEYS_HEX,
|
|
42
|
+
TRUSTED_MLDSA44_KEYS_HEX,
|
|
43
|
+
IssuerKeys,
|
|
44
|
+
)
|
|
45
|
+
from .license import (
|
|
46
|
+
Grace,
|
|
47
|
+
License,
|
|
48
|
+
Order,
|
|
49
|
+
Organization,
|
|
50
|
+
Project,
|
|
51
|
+
Status,
|
|
52
|
+
Unlicensed,
|
|
53
|
+
Valid,
|
|
54
|
+
is_licensed,
|
|
55
|
+
license_of,
|
|
56
|
+
)
|
|
57
|
+
from .verify import inspect_token, verify_token_internal, verify_token_strict
|
|
58
|
+
|
|
59
|
+
#: Default grace window: a lapsed certificate is honored this many days.
|
|
60
|
+
DEFAULT_GRACE_PERIOD_DAYS = 21
|
|
61
|
+
|
|
62
|
+
#: Logging policy for :meth:`Supso.check` (logging only — never aborts).
|
|
63
|
+
Enforcement = str # one of "silent" | "warn" | "error"
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _now() -> datetime:
|
|
67
|
+
return datetime.now(timezone.utc)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@dataclass
|
|
71
|
+
class _Requirements:
|
|
72
|
+
min_seats: Optional[int] = None
|
|
73
|
+
tier: Optional[str] = None
|
|
74
|
+
features: list[str] = field(default_factory=list)
|
|
75
|
+
min_days_remaining: Optional[int] = None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class Supso:
|
|
79
|
+
"""A configured license check. Build with :meth:`Supso.project` (or the
|
|
80
|
+
module-level :func:`initialize_project`).
|
|
81
|
+
|
|
82
|
+
Setter methods return ``self`` so they can be chained, mirroring the Rust and
|
|
83
|
+
TypeScript builders.
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
def __init__(self, project: str) -> None:
|
|
87
|
+
self._project = project
|
|
88
|
+
self._enforcement: Enforcement = "warn"
|
|
89
|
+
self._grace_period_days: int = DEFAULT_GRACE_PERIOD_DAYS
|
|
90
|
+
self._certificate_path: Optional[str] = None
|
|
91
|
+
self._issuer_keys: Optional[IssuerKeys] = None
|
|
92
|
+
self._req = _Requirements()
|
|
93
|
+
|
|
94
|
+
@classmethod
|
|
95
|
+
def project(cls, name: str) -> "Supso":
|
|
96
|
+
"""Start a check for ``project``. The license's product slug must equal this."""
|
|
97
|
+
return cls(name)
|
|
98
|
+
|
|
99
|
+
# ---- configuration ----
|
|
100
|
+
|
|
101
|
+
def enforcement(self, policy: Enforcement) -> "Supso":
|
|
102
|
+
self._enforcement = policy
|
|
103
|
+
return self
|
|
104
|
+
|
|
105
|
+
def grace_period_days(self, days: int) -> "Supso":
|
|
106
|
+
self._grace_period_days = days
|
|
107
|
+
return self
|
|
108
|
+
|
|
109
|
+
def certificate_path(self, path: str) -> "Supso":
|
|
110
|
+
self._certificate_path = path
|
|
111
|
+
return self
|
|
112
|
+
|
|
113
|
+
def issuer_keys(self, keys: IssuerKeys) -> "Supso":
|
|
114
|
+
self._issuer_keys = keys
|
|
115
|
+
return self
|
|
116
|
+
|
|
117
|
+
def require_seats(self, n: int) -> "Supso":
|
|
118
|
+
self._req.min_seats = n
|
|
119
|
+
return self
|
|
120
|
+
|
|
121
|
+
def require_tier(self, tier: str) -> "Supso":
|
|
122
|
+
self._req.tier = tier
|
|
123
|
+
return self
|
|
124
|
+
|
|
125
|
+
def require_feature(self, feature: str) -> "Supso":
|
|
126
|
+
self._req.features.append(feature)
|
|
127
|
+
return self
|
|
128
|
+
|
|
129
|
+
def require_days_remaining(self, days: int) -> "Supso":
|
|
130
|
+
self._req.min_days_remaining = days
|
|
131
|
+
return self
|
|
132
|
+
|
|
133
|
+
# ---- verification ----
|
|
134
|
+
|
|
135
|
+
def verify(self) -> License:
|
|
136
|
+
"""Verify against the system clock, returning the license or raising."""
|
|
137
|
+
return self.verify_at(_now())
|
|
138
|
+
|
|
139
|
+
def verify_at(self, now: datetime) -> License:
|
|
140
|
+
""":meth:`verify` against a supplied clock (for tests)."""
|
|
141
|
+
located = self._locate(now)
|
|
142
|
+
self._enforce_requirements(located.license, now)
|
|
143
|
+
return located.license
|
|
144
|
+
|
|
145
|
+
def check(self) -> Status:
|
|
146
|
+
"""Verify against the system clock, returning a :data:`Status` (never raises)."""
|
|
147
|
+
return self.check_at(_now())
|
|
148
|
+
|
|
149
|
+
def check_at(self, now: datetime) -> Status:
|
|
150
|
+
""":meth:`check` against a supplied clock (for tests)."""
|
|
151
|
+
status: Status
|
|
152
|
+
try:
|
|
153
|
+
located = self._locate(now)
|
|
154
|
+
try:
|
|
155
|
+
self._enforce_requirements(located.license, now)
|
|
156
|
+
if isinstance(located.validity, GraceValidity):
|
|
157
|
+
status = Grace(
|
|
158
|
+
license=located.license,
|
|
159
|
+
expired_at=located.validity.expired_at,
|
|
160
|
+
grace_until=located.validity.grace_until,
|
|
161
|
+
)
|
|
162
|
+
else:
|
|
163
|
+
status = Valid(license=located.license)
|
|
164
|
+
except SupsoError as e:
|
|
165
|
+
status = Unlicensed(error=e)
|
|
166
|
+
except SupsoError as e:
|
|
167
|
+
status = Unlicensed(error=e)
|
|
168
|
+
self._log(status, now)
|
|
169
|
+
return status
|
|
170
|
+
|
|
171
|
+
# ---- internals ----
|
|
172
|
+
|
|
173
|
+
def _keys(self) -> IssuerKeys:
|
|
174
|
+
return self._issuer_keys if self._issuer_keys is not None else IssuerKeys.supso()
|
|
175
|
+
|
|
176
|
+
def _locate(self, now: datetime) -> Located:
|
|
177
|
+
explicit = self._certificate_path or os.environ.get("SUPSO_LICENSE_PATH")
|
|
178
|
+
return locate(
|
|
179
|
+
explicit,
|
|
180
|
+
self._project,
|
|
181
|
+
self._keys(),
|
|
182
|
+
timedelta(days=self._grace_period_days),
|
|
183
|
+
now,
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
def _enforce_requirements(self, license: License, now: datetime) -> None:
|
|
187
|
+
r = self._req
|
|
188
|
+
if r.min_seats is not None:
|
|
189
|
+
have = license.seats() or 0
|
|
190
|
+
if have < r.min_seats:
|
|
191
|
+
raise SupsoError(
|
|
192
|
+
"requirement_not_met",
|
|
193
|
+
f"requires {r.min_seats} seats, license has {have}",
|
|
194
|
+
)
|
|
195
|
+
if r.tier is not None:
|
|
196
|
+
have_tier = license.tier() or ""
|
|
197
|
+
if have_tier != r.tier:
|
|
198
|
+
raise SupsoError(
|
|
199
|
+
"requirement_not_met",
|
|
200
|
+
f'requires tier "{r.tier}", license has "{have_tier}"',
|
|
201
|
+
)
|
|
202
|
+
for feature in r.features:
|
|
203
|
+
if not license.has_feature(feature):
|
|
204
|
+
raise SupsoError("requirement_not_met", f'requires feature "{feature}"')
|
|
205
|
+
if r.min_days_remaining is not None:
|
|
206
|
+
have_days = license.days_remaining(now)
|
|
207
|
+
if have_days < r.min_days_remaining:
|
|
208
|
+
raise SupsoError(
|
|
209
|
+
"requirement_not_met",
|
|
210
|
+
f"requires {r.min_days_remaining} days remaining, license has {have_days}",
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
def _log(self, status: Status, now: datetime) -> None:
|
|
214
|
+
if isinstance(status, Valid) or self._enforcement == "silent":
|
|
215
|
+
return
|
|
216
|
+
line = status_message(status, now)
|
|
217
|
+
prefix = "supso:" if self._enforcement == "warn" else "supso [error]:"
|
|
218
|
+
print(f"{prefix} {line}", file=sys.stderr)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
# ---- status messaging ----
|
|
222
|
+
|
|
223
|
+
_DAY = timedelta(days=1)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def grace_message(status: Status, now: datetime) -> Optional[str]:
|
|
227
|
+
"""A renewal notice for a grace status, else ``None``."""
|
|
228
|
+
if not isinstance(status, Grace):
|
|
229
|
+
return None
|
|
230
|
+
days_ago = max(0, int((now - status.expired_at) / _DAY))
|
|
231
|
+
days_left = max(0, int((status.grace_until - now) / _DAY))
|
|
232
|
+
return (
|
|
233
|
+
f"Your {status.license.project.name} license expired {days_ago} day{_plural(days_ago)} "
|
|
234
|
+
f"ago — you're in a grace period, but it will stop being accepted in {days_left} "
|
|
235
|
+
f"day{_plural(days_left)}. Renew the license certificate to avoid an interruption."
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def status_message(status: Status, now: datetime) -> str:
|
|
240
|
+
"""One line safe to print or log, whatever the status."""
|
|
241
|
+
if isinstance(status, Valid):
|
|
242
|
+
lic = status.license
|
|
243
|
+
return (
|
|
244
|
+
f"{lic.project.name} licensed to {lic.organization.name} "
|
|
245
|
+
f"(order {lic.order.id})"
|
|
246
|
+
)
|
|
247
|
+
if isinstance(status, Grace):
|
|
248
|
+
return grace_message(status, now) or "license in grace period"
|
|
249
|
+
return status.error.message
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def _plural(n: int) -> str:
|
|
253
|
+
return "" if n == 1 else "s"
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
# ---- module-level convenience functions (SPEC §9) ----
|
|
257
|
+
|
|
258
|
+
_configured: Optional[Supso] = None
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def initialize_project(
|
|
262
|
+
name: str,
|
|
263
|
+
*,
|
|
264
|
+
enforcement: Optional[Enforcement] = None,
|
|
265
|
+
grace_period_days: Optional[int] = None,
|
|
266
|
+
certificate_path: Optional[str] = None,
|
|
267
|
+
issuer_keys: Optional[IssuerKeys] = None,
|
|
268
|
+
) -> Supso:
|
|
269
|
+
"""Configure the default project for the no-argument :func:`require_license`
|
|
270
|
+
and :func:`check_license` calls, and return the configured :class:`Supso`.
|
|
271
|
+
"""
|
|
272
|
+
global _configured
|
|
273
|
+
s = Supso.project(name)
|
|
274
|
+
if enforcement is not None:
|
|
275
|
+
s.enforcement(enforcement)
|
|
276
|
+
if grace_period_days is not None:
|
|
277
|
+
s.grace_period_days(grace_period_days)
|
|
278
|
+
if certificate_path is not None:
|
|
279
|
+
s.certificate_path(certificate_path)
|
|
280
|
+
if issuer_keys is not None:
|
|
281
|
+
s.issuer_keys(issuer_keys)
|
|
282
|
+
_configured = s
|
|
283
|
+
return s
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def _for(project: Optional[str]) -> Supso:
|
|
287
|
+
if project is not None:
|
|
288
|
+
return Supso.project(project)
|
|
289
|
+
if _configured is None:
|
|
290
|
+
raise SupsoError(
|
|
291
|
+
"no_certificate",
|
|
292
|
+
"no project configured — pass one or call initialize_project() first",
|
|
293
|
+
)
|
|
294
|
+
return _configured
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def require_license(project: Optional[str] = None) -> License:
|
|
298
|
+
"""Verify a certificate for ``project`` against the system clock (raises).
|
|
299
|
+
|
|
300
|
+
With no argument, uses the project set by :func:`initialize_project`.
|
|
301
|
+
"""
|
|
302
|
+
return _for(project).verify()
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def check_license(project: Optional[str] = None) -> Status:
|
|
306
|
+
"""Verify a certificate for ``project``, returning a :data:`Status` (never raises).
|
|
307
|
+
|
|
308
|
+
With no argument, uses the project set by :func:`initialize_project`.
|
|
309
|
+
"""
|
|
310
|
+
return _for(project).check()
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def verify_token(token: str, project: str) -> License:
|
|
314
|
+
"""Verify a raw token for ``project`` (no on-disk search, no grace)."""
|
|
315
|
+
return verify_token_with(token, project, IssuerKeys.supso(), _now())
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def verify_token_with(
|
|
319
|
+
token: str, project: str, keys: IssuerKeys, now: datetime
|
|
320
|
+
) -> License:
|
|
321
|
+
""":func:`verify_token` with a caller-supplied clock and trust anchor."""
|
|
322
|
+
return verify_token_strict(token, project, keys, now)
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def inspect(token: str) -> License:
|
|
326
|
+
"""Verify a token without binding to a project, returning it even if expired."""
|
|
327
|
+
return inspect_with(token, IssuerKeys.supso(), _now())
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def inspect_with(token: str, keys: IssuerKeys, now: datetime) -> License:
|
|
331
|
+
""":func:`inspect` with a caller-supplied clock and trust anchor."""
|
|
332
|
+
return inspect_token(token, keys, now)
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
__all__ = [
|
|
336
|
+
"Supso",
|
|
337
|
+
"SupsoError",
|
|
338
|
+
"ErrorCode",
|
|
339
|
+
"IssuerKeys",
|
|
340
|
+
"TRUSTED_ED25519_KEYS_HEX",
|
|
341
|
+
"TRUSTED_MLDSA44_KEYS_HEX",
|
|
342
|
+
"License",
|
|
343
|
+
"Organization",
|
|
344
|
+
"Project",
|
|
345
|
+
"Order",
|
|
346
|
+
"Status",
|
|
347
|
+
"Valid",
|
|
348
|
+
"Grace",
|
|
349
|
+
"Unlicensed",
|
|
350
|
+
"is_licensed",
|
|
351
|
+
"license_of",
|
|
352
|
+
"Enforcement",
|
|
353
|
+
"DEFAULT_GRACE_PERIOD_DAYS",
|
|
354
|
+
"initialize_project",
|
|
355
|
+
"require_license",
|
|
356
|
+
"check_license",
|
|
357
|
+
"verify_token",
|
|
358
|
+
"verify_token_with",
|
|
359
|
+
"inspect",
|
|
360
|
+
"inspect_with",
|
|
361
|
+
"grace_message",
|
|
362
|
+
"status_message",
|
|
363
|
+
]
|
supso/certificate.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""Locating and verifying license certificates on disk (SPEC §6–§7).
|
|
2
|
+
|
|
3
|
+
A *certificate file* is a single token (whitespace trimmed). The search order is
|
|
4
|
+
an explicit path, then ``$HOME/.supso/license_certificates/``, then
|
|
5
|
+
``./.supso/license_certificates/``. A live certificate always wins; failing
|
|
6
|
+
that, the most-recently-expired otherwise-valid one is honored if it lapsed
|
|
7
|
+
within the grace window.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
from dataclasses import dataclass
|
|
14
|
+
from datetime import datetime, timedelta
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import NamedTuple, Optional, Union
|
|
17
|
+
|
|
18
|
+
from .errors import SupsoError
|
|
19
|
+
from .keys import IssuerKeys
|
|
20
|
+
from .license import License
|
|
21
|
+
from .verify import verify_token_internal, _iso
|
|
22
|
+
|
|
23
|
+
#: The subdirectory under each ``.supso/`` base that holds certificates.
|
|
24
|
+
CERTIFICATE_SUBDIR = "license_certificates"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass(frozen=True)
|
|
28
|
+
class ValidValidity:
|
|
29
|
+
kind: str = "valid"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass(frozen=True)
|
|
33
|
+
class GraceValidity:
|
|
34
|
+
expired_at: datetime
|
|
35
|
+
grace_until: datetime
|
|
36
|
+
kind: str = "grace"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
Validity = Union[ValidValidity, GraceValidity]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class Located(NamedTuple):
|
|
43
|
+
license: License
|
|
44
|
+
validity: Validity
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class _GraceCandidate(NamedTuple):
|
|
48
|
+
license: License
|
|
49
|
+
expires_at: datetime
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def locate(
|
|
53
|
+
explicit: Optional[str],
|
|
54
|
+
project: str,
|
|
55
|
+
keys: IssuerKeys,
|
|
56
|
+
grace_period: timedelta,
|
|
57
|
+
now: datetime,
|
|
58
|
+
) -> Located:
|
|
59
|
+
"""Locate and verify a certificate for ``project``.
|
|
60
|
+
|
|
61
|
+
When ``explicit`` is set, only that path is consulted (no fallback).
|
|
62
|
+
``grace_period`` is the grace window.
|
|
63
|
+
"""
|
|
64
|
+
tried: list[tuple[str, str]] = []
|
|
65
|
+
grace: Optional[_GraceCandidate] = None
|
|
66
|
+
|
|
67
|
+
def verify_file(path: Path) -> Optional[License]:
|
|
68
|
+
nonlocal grace
|
|
69
|
+
try:
|
|
70
|
+
raw = path.read_text(encoding="utf-8")
|
|
71
|
+
except OSError as e:
|
|
72
|
+
tried.append((str(path), f"could not read certificate: {e}"))
|
|
73
|
+
return None
|
|
74
|
+
try:
|
|
75
|
+
result = verify_token_internal(raw.strip(), project, keys, now)
|
|
76
|
+
except SupsoError as e:
|
|
77
|
+
tried.append((str(path), e.message))
|
|
78
|
+
return None
|
|
79
|
+
if not result.expired:
|
|
80
|
+
return result.license
|
|
81
|
+
expires_at = result.license.order.expires_at
|
|
82
|
+
tried.append((str(path), f"license expired at {_iso(expires_at)} (now: {_iso(now)})"))
|
|
83
|
+
if grace is None or expires_at > grace.expires_at:
|
|
84
|
+
grace = _GraceCandidate(license=result.license, expires_at=expires_at)
|
|
85
|
+
return None
|
|
86
|
+
|
|
87
|
+
def scan_dir(directory: Path) -> Optional[License]:
|
|
88
|
+
try:
|
|
89
|
+
entries = sorted(p for p in directory.iterdir() if not p.name.startswith("."))
|
|
90
|
+
except OSError:
|
|
91
|
+
return None
|
|
92
|
+
for path in entries:
|
|
93
|
+
if not path.is_file():
|
|
94
|
+
continue
|
|
95
|
+
lic = verify_file(path)
|
|
96
|
+
if lic is not None:
|
|
97
|
+
return lic
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
found: Optional[License] = None
|
|
101
|
+
if explicit is not None:
|
|
102
|
+
ep = Path(explicit)
|
|
103
|
+
if not ep.exists():
|
|
104
|
+
raise SupsoError(
|
|
105
|
+
"no_certificate", f"no license certificate found (searched: {explicit})"
|
|
106
|
+
)
|
|
107
|
+
found = scan_dir(ep) if ep.is_dir() else verify_file(ep)
|
|
108
|
+
searched = [explicit]
|
|
109
|
+
else:
|
|
110
|
+
searched = _default_dirs()
|
|
111
|
+
for directory in searched:
|
|
112
|
+
found = scan_dir(Path(directory))
|
|
113
|
+
if found is not None:
|
|
114
|
+
break
|
|
115
|
+
|
|
116
|
+
return _finalize(found, grace, tried, searched, grace_period, now)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _finalize(
|
|
120
|
+
found: Optional[License],
|
|
121
|
+
grace: Optional[_GraceCandidate],
|
|
122
|
+
tried: list[tuple[str, str]],
|
|
123
|
+
searched: list[str],
|
|
124
|
+
grace_period: timedelta,
|
|
125
|
+
now: datetime,
|
|
126
|
+
) -> Located:
|
|
127
|
+
if found is not None:
|
|
128
|
+
return Located(license=found, validity=ValidValidity())
|
|
129
|
+
if grace is not None:
|
|
130
|
+
grace_until = grace.expires_at + grace_period
|
|
131
|
+
if now <= grace_until:
|
|
132
|
+
return Located(
|
|
133
|
+
license=grace.license,
|
|
134
|
+
validity=GraceValidity(expired_at=grace.expires_at, grace_until=grace_until),
|
|
135
|
+
)
|
|
136
|
+
if not tried:
|
|
137
|
+
raise SupsoError(
|
|
138
|
+
"no_certificate",
|
|
139
|
+
f"no license certificate found (searched: {', '.join(searched)})",
|
|
140
|
+
)
|
|
141
|
+
detail = "; ".join(f"{p}: {why}" for p, why in tried)
|
|
142
|
+
raise SupsoError("none_valid", f"no valid license certificate ({len(tried)} tried): {detail}")
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _default_dirs() -> list[str]:
|
|
146
|
+
"""Per-user ``$HOME`` first, then the project-local ``./.supso``."""
|
|
147
|
+
dirs: list[str] = []
|
|
148
|
+
home = os.environ.get("HOME") or os.environ.get("USERPROFILE")
|
|
149
|
+
if home:
|
|
150
|
+
dirs.append(str(Path(home) / ".supso" / CERTIFICATE_SUBDIR))
|
|
151
|
+
dirs.append(str(Path(".supso") / CERTIFICATE_SUBDIR))
|
|
152
|
+
return dirs
|
supso/errors.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""The single error type the API raises, tagged with the canonical error
|
|
2
|
+
``code`` from the cross-language spec (``spec/SPEC.md`` §4).
|
|
3
|
+
|
|
4
|
+
Hosts switch on ``code`` to render an actionable message — ``"expired"`` reads
|
|
5
|
+
differently from ``"wrong_project"`` reads differently from ``"no_certificate"``.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Literal
|
|
11
|
+
|
|
12
|
+
#: Canonical error names shared by every implementation (SPEC §4).
|
|
13
|
+
ErrorCode = Literal[
|
|
14
|
+
"malformed",
|
|
15
|
+
"base64",
|
|
16
|
+
"bad_ed25519_signature",
|
|
17
|
+
"bad_mldsa_signature",
|
|
18
|
+
"invalid_json",
|
|
19
|
+
"unsupported_schema",
|
|
20
|
+
"bad_timestamp",
|
|
21
|
+
"expired",
|
|
22
|
+
"wrong_project",
|
|
23
|
+
"requirement_not_met",
|
|
24
|
+
"no_certificate",
|
|
25
|
+
"none_valid",
|
|
26
|
+
"bad_trusted_key",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class SupsoError(Exception):
|
|
31
|
+
"""Why a license could not be accepted.
|
|
32
|
+
|
|
33
|
+
Carries the canonical :data:`ErrorCode` in :attr:`code` so callers can
|
|
34
|
+
branch on the reason without parsing the human-readable message.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
code: ErrorCode
|
|
38
|
+
|
|
39
|
+
def __init__(self, code: ErrorCode, message: str) -> None:
|
|
40
|
+
super().__init__(message)
|
|
41
|
+
self.code = code
|
|
42
|
+
self.message = message
|
|
43
|
+
|
|
44
|
+
def __str__(self) -> str: # pragma: no cover - trivial
|
|
45
|
+
return self.message
|
supso/keys.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Trusted issuer keys — Supso's production anchor, baked into the published
|
|
2
|
+
package so a downstream user cannot substitute their own.
|
|
3
|
+
|
|
4
|
+
Each scheme is a list so a key can be rotated (ship a release with old + new,
|
|
5
|
+
re-issue, then drop the old entry). Mirrors the Rust crate's ``keys.rs`` and the
|
|
6
|
+
TypeScript package's ``keys.ts``.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import re
|
|
12
|
+
from dataclasses import dataclass
|
|
13
|
+
|
|
14
|
+
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
|
|
15
|
+
|
|
16
|
+
from .errors import SupsoError
|
|
17
|
+
|
|
18
|
+
#: Supso's production Ed25519 public keys, 64-char lowercase hex (32 bytes).
|
|
19
|
+
TRUSTED_ED25519_KEYS_HEX: tuple[str, ...] = (
|
|
20
|
+
"b1ef6d78434daaf5dae5e3df7996a3edc155198c71c92b91f539ce2fe649e9d4",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
#: Supso's production ML-DSA-44 public keys, 2624-char lowercase hex (1312 bytes).
|
|
24
|
+
TRUSTED_MLDSA44_KEYS_HEX: tuple[str, ...] = (
|
|
25
|
+
"1be0e29d77a9998bb7661228a79e1d8118aa9ad88535720563d1aef9b8abc0d3d037cd984f3f652fc5512c935593dcd9f470540e125f0e9bcdc17c0bad721386bb3e3cd28cf895cbd0168cfcaee5131e581e2916abc7a1c25022f016c81781d16cd8b4cd8c36a7ced2a1753e4c01f69a05e9acb6f1926867a028f0a5ae6c1f22873c3df3d562f2ec844d422c8c68b2deba9257a13013bd009a227d7c40a3aa81129b6ed1f950a0cf75f3cfb9fc0e405d7fc929ecc9bf59dc566b075b3b80ad914fd150749b9022638e99a7d64b68ff82e295609dc2f6bd291463c417a1e69e7e145164fb3787c5bc90fe1dc4268bbd4d4e44c13d50120cf161466fbb53ea2a5f724ace3afef42eeeb0d631ad2b815b5442caddb509ed9d1cc8ab79ba4042fa168245d1446294677503eed33410a979a0646da3393e7c2a6e450c63c55ecc5bd92771ef7b278b3cef2d80fa306733fb2ecee4b2f4bb07c3b14ad29da4607b97e04cfefb76258000185c6d795ff91e9af4a0acf54a25ddbf14814540461474d67d6b9503d7e07e97907ef483593f97b9d039c4e548b25917d722c1c3e5ae7f81a1c232faf5a6978641230408cc01d70724f64e150836388dcadf60ae5be134ab5413228e5ab13402aa4331d144b586e1cb05d7a4034a9a5f71513d6029615197212b4a68684d05fedfe92bb05f24eccb6a9be9c1fa1003ba106718db9d39d4a08c5b6ae014d0086a957ed033e74af13d9a94d549524316d6aa544487eab716878a4a07ca3285724af050fccc8c3f8c3c82e2cd271133ca9562e71238e23baca5ec297ff50ebee8b2461607054d8f18d60b012b6eee2240adfa38b05f10ca679c271922907819974b5481d0aa7cab37c215123a6b6d7067856dfc475a8c2e3e54b658deb0709c8cb77b0a8508519d44b784f7584966d978d65b78e11e059c1e4b5441fd1625af92b2d647c5f0805343243b2225882b3c9beda4c1102aff1c084dac105da2d37813881fad33a860cc655bb45fac59d73ac2d92fb4fde59cbf10bdd07541e605d008467ea4c20e0c2796683499b19adb394dea4c8260c7438fb9efe2db2d65b9f7f4f2a8068a1010f70b7b2ae83c92dac6af023fe7f41eccba36d702b1bd73c88147f3ebc4f9e5416573321567b224a255e3edaf6afce2bce7b1d33955bb3288bf1da61709488c84e9321385e6ac71d120b752698f60eed6f1e75b12c04b30f998450cedecf91c6e611e7f23d5ca1252f89b699196f726931078f7e93d5a81b32613f7fe42563b907dae17822757bd66a0b1d3aecce3b5a01d317f085322c2df01cea971b0e3b58ec7cd80d681dafbc6ed2eeadcef36e8168336aa8954fd1cf6426702679d8e3f57a8e0b9cda12dd0ccf0aeb5a6f84ac5e2e0d4e43093063f1b8e1103359bc92d5a1891d8e34ec44a97469941d5b2665c5cfb910019840a8b8efd7e59e3bb727dbd09d3d68cf9b4f4c42687b762da645233bfb55b5fa523eca0241e4a6649e12aa41b5d52a2a6cdd043e1bcd500c6c99ba7fe33bd39a5f380be88c14ebaf01c24034b4b57b04a290336240ee06c0feaa495aee10f15006cff5750061bc93091660dd945efda00ddbd50cff8f69b85c18493ae21f70e1d9b29c6b90457177f9313764d505738b5474550b1e6969fac1aac7a3f25b6bef5d0be43eab4b464a8a86be08417935a8f5d097cc237a0f57e4330c18ef54d376e42a2b8d17a1c3e18a6a84c123cff67ea4f2e86284a34862f81c0c65cf79cb5c972de88a98e5c0ce89530739729610b39ac1f03f5158e26b81e364219ead057d43b222bbd93c39d3507c127ca78a7c6a85511ba92195b125f8ff70cb2d5c7b2",
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
_HEX_RE = re.compile(r"^[0-9a-fA-F]+$")
|
|
29
|
+
_ED25519_KEY_LEN = 32
|
|
30
|
+
_MLDSA44_KEY_LEN = 1312
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass(frozen=True)
|
|
34
|
+
class IssuerKeys:
|
|
35
|
+
"""A set of trusted issuer verifying keys, one list per scheme.
|
|
36
|
+
|
|
37
|
+
A token is accepted iff its signature verifies under **at least one** key in
|
|
38
|
+
each list (SPEC §4 "Key rotation").
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
#: Parsed Ed25519 public keys.
|
|
42
|
+
ed25519: tuple[Ed25519PublicKey, ...]
|
|
43
|
+
#: Raw ML-DSA-44 public-key bytes (1312 each), passed to the verifier as-is.
|
|
44
|
+
mldsa44: tuple[bytes, ...]
|
|
45
|
+
|
|
46
|
+
@classmethod
|
|
47
|
+
def from_hex(
|
|
48
|
+
cls,
|
|
49
|
+
ed25519_hex: "list[str] | tuple[str, ...]",
|
|
50
|
+
mldsa44_hex: "list[str] | tuple[str, ...]",
|
|
51
|
+
) -> "IssuerKeys":
|
|
52
|
+
"""Build a trust anchor from hex key lists (self-hosting issuers and tests)."""
|
|
53
|
+
ed = tuple(
|
|
54
|
+
Ed25519PublicKey.from_public_bytes(_decode_key(h, _ED25519_KEY_LEN, "Ed25519"))
|
|
55
|
+
for h in ed25519_hex
|
|
56
|
+
)
|
|
57
|
+
pq = tuple(_decode_key(h, _MLDSA44_KEY_LEN, "ML-DSA-44") for h in mldsa44_hex)
|
|
58
|
+
return cls(ed25519=ed, mldsa44=pq)
|
|
59
|
+
|
|
60
|
+
@classmethod
|
|
61
|
+
def supso(cls) -> "IssuerKeys":
|
|
62
|
+
"""The baked-in Supso production anchor."""
|
|
63
|
+
return cls.from_hex(TRUSTED_ED25519_KEYS_HEX, TRUSTED_MLDSA44_KEYS_HEX)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _decode_key(hex_str: str, byte_len: int, scheme: str) -> bytes:
|
|
67
|
+
if len(hex_str) != byte_len * 2 or not _HEX_RE.match(hex_str):
|
|
68
|
+
raise SupsoError("bad_trusted_key", f"{scheme} key hex is malformed")
|
|
69
|
+
return bytes.fromhex(hex_str)
|
supso/license.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""The data a verified license carries, and the outcome types the API returns."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from typing import Any, Mapping, Optional, Union
|
|
8
|
+
|
|
9
|
+
from .errors import SupsoError
|
|
10
|
+
|
|
11
|
+
_DAY_SECONDS = 86_400
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass(frozen=True)
|
|
15
|
+
class Organization:
|
|
16
|
+
"""The buyer the license was issued to."""
|
|
17
|
+
|
|
18
|
+
id: str
|
|
19
|
+
name: str
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True)
|
|
23
|
+
class Project:
|
|
24
|
+
"""The product the license is for, read from ``metadata.project``.
|
|
25
|
+
|
|
26
|
+
Verification requires :attr:`slug` to equal the project slug the maintainer
|
|
27
|
+
asked about.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
id: str
|
|
31
|
+
#: The stable, URL-safe handle a maintainer integrates against (e.g. ``"acme-db"``).
|
|
32
|
+
slug: str
|
|
33
|
+
#: Human-readable display name.
|
|
34
|
+
name: str
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass(frozen=True)
|
|
38
|
+
class Order:
|
|
39
|
+
"""The order behind the license and when it lapses."""
|
|
40
|
+
|
|
41
|
+
id: str
|
|
42
|
+
#: Expiry as a timezone-aware UTC :class:`~datetime.datetime`.
|
|
43
|
+
expires_at: datetime
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass(frozen=True)
|
|
47
|
+
class License:
|
|
48
|
+
"""A successfully-verified license."""
|
|
49
|
+
|
|
50
|
+
organization: Organization
|
|
51
|
+
project: Project
|
|
52
|
+
order: Order
|
|
53
|
+
#: Issuer-attached metadata: ``seats``, ``tier``, ``features``, …
|
|
54
|
+
metadata: Mapping[str, Any] = field(default_factory=dict)
|
|
55
|
+
|
|
56
|
+
def seats(self) -> Optional[int]:
|
|
57
|
+
"""``metadata.seats`` as an integer, if present."""
|
|
58
|
+
s = self.metadata.get("seats")
|
|
59
|
+
# bool is a subclass of int — exclude it.
|
|
60
|
+
if isinstance(s, int) and not isinstance(s, bool):
|
|
61
|
+
return s
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
def tier(self) -> Optional[str]:
|
|
65
|
+
"""``metadata.tier`` as a string, if present."""
|
|
66
|
+
t = self.metadata.get("tier")
|
|
67
|
+
return t if isinstance(t, str) else None
|
|
68
|
+
|
|
69
|
+
def features(self) -> list[str]:
|
|
70
|
+
"""``metadata.features`` as a list of strings (empty if absent)."""
|
|
71
|
+
f = self.metadata.get("features")
|
|
72
|
+
if isinstance(f, list):
|
|
73
|
+
return [x for x in f if isinstance(x, str)]
|
|
74
|
+
return []
|
|
75
|
+
|
|
76
|
+
def has_feature(self, feature: str) -> bool:
|
|
77
|
+
"""Whether ``metadata.features`` contains ``feature``."""
|
|
78
|
+
return feature in self.features()
|
|
79
|
+
|
|
80
|
+
def days_remaining(self, now: datetime) -> int:
|
|
81
|
+
"""Whole days from ``now`` until expiry (negative once expired)."""
|
|
82
|
+
delta = self.order.expires_at - now
|
|
83
|
+
secs = delta.total_seconds()
|
|
84
|
+
# Truncate toward zero, matching the Rust/TS implementations.
|
|
85
|
+
return int(secs / _DAY_SECONDS)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
# ---- Status: the outcome of the non-raising `check` call ----
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@dataclass(frozen=True)
|
|
92
|
+
class Valid:
|
|
93
|
+
"""A live, fully-valid license."""
|
|
94
|
+
|
|
95
|
+
license: License
|
|
96
|
+
kind: str = "valid"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@dataclass(frozen=True)
|
|
100
|
+
class Grace:
|
|
101
|
+
"""A lapsed license still honored within the grace window (SPEC §7)."""
|
|
102
|
+
|
|
103
|
+
license: License
|
|
104
|
+
expired_at: datetime
|
|
105
|
+
grace_until: datetime
|
|
106
|
+
kind: str = "grace"
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@dataclass(frozen=True)
|
|
110
|
+
class Unlicensed:
|
|
111
|
+
"""No acceptable license was found; :attr:`error` says why."""
|
|
112
|
+
|
|
113
|
+
error: SupsoError
|
|
114
|
+
kind: str = "unlicensed"
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
#: The outcome of a non-raising :meth:`Supso.check`.
|
|
118
|
+
Status = Union[Valid, Grace, Unlicensed]
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def is_licensed(status: Status) -> bool:
|
|
122
|
+
"""``True`` for ``valid`` or ``grace``."""
|
|
123
|
+
return status.kind in ("valid", "grace")
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def license_of(status: Status) -> Optional[License]:
|
|
127
|
+
"""The verified license for ``valid``/``grace``, else ``None``."""
|
|
128
|
+
return None if isinstance(status, Unlicensed) else status.license
|
supso/verify.py
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"""Token verification: the hybrid signature + payload pipeline (SPEC §4–§5).
|
|
2
|
+
|
|
3
|
+
A token is three URL-safe-base64 segments joined by ``.``::
|
|
4
|
+
|
|
5
|
+
base64url(payload_json) . base64url(ed25519_sig) . base64url(mldsa44_sig)
|
|
6
|
+
|
|
7
|
+
Both signatures cover the *encoded* payload bytes (the first segment as ASCII),
|
|
8
|
+
so the verifier never canonicalizes JSON. Acceptance requires **both**
|
|
9
|
+
signatures to verify — "hybrid" is AND, not OR.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import base64
|
|
15
|
+
import binascii
|
|
16
|
+
import json
|
|
17
|
+
import re
|
|
18
|
+
from datetime import datetime, timezone
|
|
19
|
+
from typing import Any, NamedTuple, Optional
|
|
20
|
+
|
|
21
|
+
from cryptography.exceptions import InvalidSignature
|
|
22
|
+
from dilithium_py.ml_dsa import ML_DSA_44
|
|
23
|
+
|
|
24
|
+
from .errors import SupsoError
|
|
25
|
+
from .keys import IssuerKeys
|
|
26
|
+
from .license import License, Order, Organization, Project
|
|
27
|
+
|
|
28
|
+
SCHEMA_VERSION = 1
|
|
29
|
+
_ED25519_SIG_LEN = 64
|
|
30
|
+
_MLDSA44_SIG_LEN = 2420
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class Verified(NamedTuple):
|
|
34
|
+
"""A token that passed every check except, possibly, expiry."""
|
|
35
|
+
|
|
36
|
+
license: License
|
|
37
|
+
expired: bool
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def verify_token_internal(
|
|
41
|
+
token: str,
|
|
42
|
+
expected_project: Optional[str],
|
|
43
|
+
keys: IssuerKeys,
|
|
44
|
+
now: datetime,
|
|
45
|
+
) -> Verified:
|
|
46
|
+
"""Verify a token's signatures and payload against ``keys``.
|
|
47
|
+
|
|
48
|
+
When ``expected_project`` is not ``None``, the payload's project slug must
|
|
49
|
+
equal it. Expiry is reported via :attr:`Verified.expired` rather than raised,
|
|
50
|
+
so the certificate search can recover a lapsed license for the grace window.
|
|
51
|
+
"""
|
|
52
|
+
segments = token.split(".")
|
|
53
|
+
if len(segments) != 3:
|
|
54
|
+
raise SupsoError("malformed", "token must split into exactly three segments")
|
|
55
|
+
payload_b64, ed_sig_b64, pq_sig_b64 = segments
|
|
56
|
+
if not payload_b64 or not ed_sig_b64 or not pq_sig_b64:
|
|
57
|
+
raise SupsoError("malformed", "token has an empty segment")
|
|
58
|
+
|
|
59
|
+
signed_msg = payload_b64.encode("ascii")
|
|
60
|
+
|
|
61
|
+
# ---- Ed25519 ----
|
|
62
|
+
ed_sig = _decode_segment(ed_sig_b64)
|
|
63
|
+
if len(ed_sig) != _ED25519_SIG_LEN:
|
|
64
|
+
raise SupsoError("malformed", "Ed25519 signature is not 64 bytes")
|
|
65
|
+
if not any(_safe_verify_ed(pk, ed_sig, signed_msg) for pk in keys.ed25519):
|
|
66
|
+
raise SupsoError("bad_ed25519_signature", "Ed25519 signature is invalid")
|
|
67
|
+
|
|
68
|
+
# ---- ML-DSA-44 ----
|
|
69
|
+
pq_sig = _decode_segment(pq_sig_b64)
|
|
70
|
+
if len(pq_sig) != _MLDSA44_SIG_LEN:
|
|
71
|
+
raise SupsoError("malformed", "ML-DSA-44 signature is the wrong length")
|
|
72
|
+
if not any(_safe_verify_pq(pk, signed_msg, pq_sig) for pk in keys.mldsa44):
|
|
73
|
+
raise SupsoError("bad_mldsa_signature", "ML-DSA-44 signature is invalid")
|
|
74
|
+
|
|
75
|
+
# ---- payload ----
|
|
76
|
+
payload = _parse_payload(_decode_segment(payload_b64))
|
|
77
|
+
if payload["v"] != SCHEMA_VERSION:
|
|
78
|
+
raise SupsoError(
|
|
79
|
+
"unsupported_schema", f"license schema version {payload['v']} is not supported"
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
project = _read_project(payload)
|
|
83
|
+
if expected_project is not None and project.slug != expected_project:
|
|
84
|
+
found = project.slug or "<none>"
|
|
85
|
+
raise SupsoError(
|
|
86
|
+
"wrong_project",
|
|
87
|
+
f'license is not for project "{expected_project}" (found "{found}")',
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
expires_at = _parse_expiry(payload["order"]["expires_at"])
|
|
91
|
+
organization = Organization(
|
|
92
|
+
id=payload["organization"]["id"], name=payload["organization"]["name"]
|
|
93
|
+
)
|
|
94
|
+
order = Order(id=payload["order"]["id"], expires_at=expires_at)
|
|
95
|
+
license = License(
|
|
96
|
+
organization=organization,
|
|
97
|
+
project=project,
|
|
98
|
+
order=order,
|
|
99
|
+
metadata=payload["metadata"] or {},
|
|
100
|
+
)
|
|
101
|
+
return Verified(license=license, expired=expires_at <= now)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def verify_token_strict(
|
|
105
|
+
token: str, expected_project: str, keys: IssuerKeys, now: datetime
|
|
106
|
+
) -> License:
|
|
107
|
+
"""Verify a token, collapsing expiry to a raised ``expired`` error (no grace)."""
|
|
108
|
+
result = verify_token_internal(token, expected_project, keys, now)
|
|
109
|
+
if result.expired:
|
|
110
|
+
raise SupsoError(
|
|
111
|
+
"expired",
|
|
112
|
+
f"license expired at {_iso(result.license.order.expires_at)} (now: {_iso(now)})",
|
|
113
|
+
)
|
|
114
|
+
return result.license
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def inspect_token(token: str, keys: IssuerKeys, now: datetime) -> License:
|
|
118
|
+
"""Verify signatures, schema, and timestamp **without** binding to a project,
|
|
119
|
+
returning the license even if expired. For tooling that enumerates
|
|
120
|
+
certificates and reads the project from the payload. A forged token raises.
|
|
121
|
+
"""
|
|
122
|
+
return verify_token_internal(token, None, keys, now).license
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
# ---- payload parsing ----
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _parse_payload(raw_bytes: bytes) -> dict[str, Any]:
|
|
129
|
+
try:
|
|
130
|
+
obj = json.loads(raw_bytes.decode("utf-8"))
|
|
131
|
+
except (ValueError, UnicodeDecodeError):
|
|
132
|
+
raise SupsoError("invalid_json", "license payload is not valid JSON")
|
|
133
|
+
if not isinstance(obj, dict):
|
|
134
|
+
raise SupsoError("invalid_json", "license payload is not an object")
|
|
135
|
+
v = obj.get("v")
|
|
136
|
+
if not isinstance(v, int) or isinstance(v, bool):
|
|
137
|
+
raise SupsoError("invalid_json", "license payload is missing `v`")
|
|
138
|
+
organization = _require_object(obj.get("organization"), "organization")
|
|
139
|
+
order = _require_object(obj.get("order"), "order")
|
|
140
|
+
metadata = obj.get("metadata")
|
|
141
|
+
return {
|
|
142
|
+
"v": v,
|
|
143
|
+
"organization": {
|
|
144
|
+
"id": _require_string(organization.get("id"), "organization.id"),
|
|
145
|
+
"name": _require_string(organization.get("name"), "organization.name"),
|
|
146
|
+
},
|
|
147
|
+
"order": {
|
|
148
|
+
"id": _require_string(order.get("id"), "order.id"),
|
|
149
|
+
"expires_at": _require_string(order.get("expires_at"), "order.expires_at"),
|
|
150
|
+
},
|
|
151
|
+
"metadata": metadata if isinstance(metadata, dict) else None,
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _read_project(payload: dict[str, Any]) -> Project:
|
|
156
|
+
"""The product binding lives at ``metadata.project``; missing fields default to ``""``."""
|
|
157
|
+
metadata = payload.get("metadata")
|
|
158
|
+
proj = metadata.get("project") if isinstance(metadata, dict) else None
|
|
159
|
+
|
|
160
|
+
def field(key: str) -> str:
|
|
161
|
+
if isinstance(proj, dict):
|
|
162
|
+
v = proj.get(key)
|
|
163
|
+
if isinstance(v, str):
|
|
164
|
+
return v
|
|
165
|
+
return ""
|
|
166
|
+
|
|
167
|
+
return Project(id=field("id"), slug=field("slug"), name=field("name"))
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _require_object(value: Any, field: str) -> dict[str, Any]:
|
|
171
|
+
if not isinstance(value, dict):
|
|
172
|
+
raise SupsoError("invalid_json", f"license payload is missing `{field}`")
|
|
173
|
+
return value
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _require_string(value: Any, field: str) -> str:
|
|
177
|
+
if not isinstance(value, str):
|
|
178
|
+
raise SupsoError(
|
|
179
|
+
"invalid_json", f"license payload field `{field}` is missing or not a string"
|
|
180
|
+
)
|
|
181
|
+
return value
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
# ---- expiry parsing (SPEC §5) ----
|
|
185
|
+
|
|
186
|
+
_DATE_ONLY = re.compile(r"^\d{4}-\d{2}-\d{2}$")
|
|
187
|
+
_RFC3339 = re.compile(
|
|
188
|
+
r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$"
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def _parse_expiry(s: str) -> datetime:
|
|
193
|
+
"""Parse ``order.expires_at``. A full RFC 3339 timestamp is used verbatim; a
|
|
194
|
+
bare ``YYYY-MM-DD`` date expires at the **end** of that day (``23:59:59Z``).
|
|
195
|
+
"""
|
|
196
|
+
if _DATE_ONLY.match(s):
|
|
197
|
+
return _parse_iso(f"{s}T23:59:59Z", s)
|
|
198
|
+
if _RFC3339.match(s):
|
|
199
|
+
return _parse_iso(s, s)
|
|
200
|
+
raise SupsoError("bad_timestamp", f"`order.expires_at` is not a valid timestamp: {s}")
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def _parse_iso(value: str, original: str) -> datetime:
|
|
204
|
+
normalized = value[:-1] + "+00:00" if value.endswith("Z") else value
|
|
205
|
+
try:
|
|
206
|
+
dt = datetime.fromisoformat(normalized)
|
|
207
|
+
except ValueError:
|
|
208
|
+
raise SupsoError(
|
|
209
|
+
"bad_timestamp", f"`order.expires_at` is not a valid timestamp: {original}"
|
|
210
|
+
)
|
|
211
|
+
if dt.tzinfo is None:
|
|
212
|
+
dt = dt.replace(tzinfo=timezone.utc)
|
|
213
|
+
return dt.astimezone(timezone.utc)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _iso(dt: datetime) -> str:
|
|
217
|
+
return dt.astimezone(timezone.utc).isoformat().replace("+00:00", "Z")
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
# ---- base64 + signatures ----
|
|
221
|
+
|
|
222
|
+
_B64URL_RE = re.compile(r"^[A-Za-z0-9_-]+$")
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def _decode_segment(s: str) -> bytes:
|
|
226
|
+
"""Strict URL-safe base64 (no padding) decode; raises ``base64`` on bad input."""
|
|
227
|
+
if not _B64URL_RE.match(s):
|
|
228
|
+
raise SupsoError("base64", "segment is not valid url-safe base64")
|
|
229
|
+
if len(s) % 4 == 1:
|
|
230
|
+
raise SupsoError("base64", "invalid base64 length")
|
|
231
|
+
padded = s + "=" * (-len(s) % 4)
|
|
232
|
+
try:
|
|
233
|
+
return base64.urlsafe_b64decode(padded)
|
|
234
|
+
except (ValueError, binascii.Error):
|
|
235
|
+
raise SupsoError("base64", "segment is not valid url-safe base64")
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def _safe_verify_ed(pk, sig: bytes, msg: bytes) -> bool:
|
|
239
|
+
try:
|
|
240
|
+
pk.verify(sig, msg)
|
|
241
|
+
return True
|
|
242
|
+
except InvalidSignature:
|
|
243
|
+
return False
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def _safe_verify_pq(pk: bytes, msg: bytes, sig: bytes) -> bool:
|
|
247
|
+
try:
|
|
248
|
+
return bool(ML_DSA_44.verify(pk, msg, sig))
|
|
249
|
+
except Exception: # noqa: BLE001 - a malformed key/sig is just "does not verify"
|
|
250
|
+
return False
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
__all__ = [
|
|
254
|
+
"Verified",
|
|
255
|
+
"verify_token_internal",
|
|
256
|
+
"verify_token_strict",
|
|
257
|
+
"inspect_token",
|
|
258
|
+
"SCHEMA_VERSION",
|
|
259
|
+
]
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: supso-project
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Offline hybrid (Ed25519 + ML-DSA-44) software-license verification for project maintainers — Supported Source.
|
|
5
|
+
Project-URL: Homepage, https://supso.org
|
|
6
|
+
Project-URL: Repository, https://github.com/SupsoOrg/supso-project-python
|
|
7
|
+
Author: Supso
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE-APACHE
|
|
10
|
+
Keywords: ed25519,license,licensing,ml-dsa,supported-source,verification
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Security :: Cryptography
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Requires-Dist: cryptography>=42
|
|
19
|
+
Requires-Dist: dilithium-py>=1.1
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# supso (Python)
|
|
25
|
+
|
|
26
|
+
Supported Source license checks for your project, from [Supported Source](https://supso.org).
|
|
27
|
+
|
|
28
|
+
Use this library to enforce licensing, so you'll know who is using your project, and can
|
|
29
|
+
be sure they're paying for your paid licenses. It's just one call at startup to confirm
|
|
30
|
+
the code running your software holds a valid license. The check is 100% offline, so there's
|
|
31
|
+
no network, no license server to run, nothing phoning home.
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import supso
|
|
35
|
+
|
|
36
|
+
license = supso.require_license("acme-db") # raises if unlicensed
|
|
37
|
+
print(f"licensed to {license.organization.name}, {license.seats()} seats")
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
pip install supso-project
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The package imports as `supso`:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import supso
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
### Hard enforcement (raises when missing license)
|
|
55
|
+
|
|
56
|
+
This is what we suggest you do.
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
import supso
|
|
60
|
+
supso.require_license("acme-db")
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Soft enforcement (does not raise errors)
|
|
64
|
+
|
|
65
|
+
If you would like to handle it yourself, use `is_licensed` and then write your own logic.
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
import supso
|
|
69
|
+
|
|
70
|
+
status = supso.check_license("acme-db") # logs a notice on grace/failure
|
|
71
|
+
if supso.is_licensed(status):
|
|
72
|
+
... # valid or within grace — run normally
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`status` is one of `supso.Valid`, `supso.Grace`, or `supso.Unlicensed`
|
|
76
|
+
(distinguish via `status.kind` or `isinstance`).
|
|
77
|
+
|
|
78
|
+
## Where licenses are found
|
|
79
|
+
|
|
80
|
+
When you don't pass a token, the library looks for a `*.cert` file (each holding
|
|
81
|
+
one license) in this order:
|
|
82
|
+
|
|
83
|
+
1. an explicit path — the `certificate_path(...)` option or the
|
|
84
|
+
`SUPSO_LICENSE_PATH` environment variable (authoritative; no fallback);
|
|
85
|
+
2. `~/.supso/license_certificates/`;
|
|
86
|
+
3. `./.supso/license_certificates/`.
|
|
87
|
+
|
|
88
|
+
A current license always wins. If none is current but one lapsed recently, it is
|
|
89
|
+
honored as `Grace` (default window 21 days) so your app keeps running while you
|
|
90
|
+
prompt the user to renew.
|
|
91
|
+
|
|
92
|
+
## Errors
|
|
93
|
+
|
|
94
|
+
Every failure is a `supso.SupsoError` carrying a stable `code` so you can branch
|
|
95
|
+
on the reason: `malformed`, `base64`, `bad_ed25519_signature`,
|
|
96
|
+
`bad_mldsa_signature`, `invalid_json`, `unsupported_schema`, `bad_timestamp`,
|
|
97
|
+
`expired`, `wrong_project`, `requirement_not_met`, `no_certificate`,
|
|
98
|
+
`none_valid`, `bad_trusted_key`.
|
|
99
|
+
|
|
100
|
+
## Development
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
uv venv && source .venv/bin/activate
|
|
104
|
+
uv pip install -e ".[dev]"
|
|
105
|
+
pytest
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
Apache-2.0. See [`LICENSE-APACHE`](./LICENSE-APACHE).
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
supso/__init__.py,sha256=hVeXsSu5d9z8FasLz40Vx2EuGA-NAvF-XGpiNULJ5hs,11473
|
|
2
|
+
supso/certificate.py,sha256=ikVXzuhlTNEGyOiFeb_umarg9tBXVAmA7fw8dB49ufI,4773
|
|
3
|
+
supso/errors.py,sha256=Q11mNoxoRqTkdTk05hcD8qJFBSfqm1sobdz6WF9xfgw,1231
|
|
4
|
+
supso/keys.py,sha256=NGBZjMvzfe5b2zacOT4f2sESF43Mjb9bCbrH8mEBQBw,4994
|
|
5
|
+
supso/license.py,sha256=mbVEV-4KgzheZ4PJEW7-jSwvMF7gdUqlkCdSAmRRCZE,3494
|
|
6
|
+
supso/verify.py,sha256=F5NqI-EHO7oKo36-VUGCc3_9DtGdOO2CbrygHcptZTc,8857
|
|
7
|
+
supso_project-1.0.0.dist-info/METADATA,sha256=pShxOIVKmb6_2N4qZ1bz4UOsgwmwNbzf3Cho8FAXJoA,3310
|
|
8
|
+
supso_project-1.0.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
9
|
+
supso_project-1.0.0.dist-info/licenses/LICENSE-APACHE,sha256=cPAdFxSCLIUZOWiFTbholiTAUYq-o-31y_n6qNrXvOQ,11335
|
|
10
|
+
supso_project-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work, excluding
|
|
103
|
+
those notices that do not pertain to any part of the Derivative
|
|
104
|
+
Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and do
|
|
117
|
+
not modify the License. You may add Your own attribution notices
|
|
118
|
+
within Derivative Works that You distribute, alongside or as an
|
|
119
|
+
addendum to the NOTICE text from the Work, provided that such
|
|
120
|
+
additional attribution notices cannot be construed as modifying
|
|
121
|
+
the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Supso
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|