Metadata-Version: 2.4
Name: xenterprise
Version: 0.1.1
Summary: Offline validation of Vauxoo RS256-JWT license tokens (base_license client, no Odoo).
Author-email: Vauxoo <info@vauxoo.com>
License-Expression: LicenseRef-OPL-1
Project-URL: Homepage, https://www.vauxoo.com
Project-URL: Source, https://git.vauxoo.com/vauxoo/xenterprise
Keywords: license,jwt,rs256,vauxoo,odoo
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyjwt<3,>=2.8
Requires-Dist: cryptography
Requires-Dist: requests
Provides-Extra: test
Requires-Dist: pytest>=7; extra == "test"
Requires-Dist: ruff; extra == "test"
Dynamic: license-file

# xenterprise

Offline validation of Vauxoo RS256-JWT license tokens — the pure-Python client
extracted from the Vauxoo `base_license` Odoo module.

A proprietary module gates itself by listing `xenterprise` in its
`external_dependencies.python` (so `pip` installs it on deploy) and calling
`xenterprise.validate(...)` with the vendor public key. The signing server
(`license_manager`, running at `https://enterprise.vauxoo.ai`) is unchanged:
this package only **validates** tokens offline with the vendor **public** key —
it never signs. Grace / expiry / revocation and anti-rollback semantics are
identical to `base_license`, so a `license_manager` token validates the same way
whether it is checked by the Odoo module or by this package.

## Install

```bash
pip install xenterprise
```

## Public API

```python
import xenterprise
from xenterprise import (
    validate, Verdict,
    LicenseError, LicenseInvalid, LicenseRevoked,
    obfuscate_token, deobfuscate_token, compute_hwid,
    DEFAULT_ISSUER, DEFAULT_SERVER_URL,
)
from xenterprise import client  # optional HTTP to the vendor

v = xenterprise.validate(
    token,                 # the RS256 JWT issued by license_manager
    pubkey_pem=vendor_pem, # vendor PUBLIC key (PEM)
    product_code="CR_EDI", # vendor catalog code
    now=None,              # datetime | None (naive is read as UTC); None = now
    last_seen=None,        # datetime | None, anti-rollback high-water mark
    issuer=DEFAULT_ISSUER, # "vauxoo-license"
    leeway=300,            # seconds of clock tolerance
    blocked=False,         # True if a vendor revoke/expired verdict is persisted
)

if v.ok:            # True iff v.state in {"valid", "grace"}
    ...             # deliver the gated value
else:
    raise SomeError(v.reason)
```

`validate` never raises for a license outcome and never does network I/O. It
returns a `Verdict`:

| field       | type                                               | notes                                   |
|-------------|----------------------------------------------------|-----------------------------------------|
| `.state`    | `valid` / `grace` / `expired` / `revoked` / `invalid` |                                      |
| `.ok`       | `bool`                                             | `True` iff `state in {valid, grace}`    |
| `.term_end` | `date \| None`                                     | product subscription end (`None` = perpetual) |
| `.mode`     | `production` / `sandbox` / `None`                  | `None` when the token did not decode    |
| `.claims`   | `dict`                                             | the decoded JWT claims (empty if undecodable) |
| `.reason`   | `str`                                              | human-readable explanation              |

### State semantics (identical to `base_license`)

- **valid** — signature, issuer, required claims and mode check out; the token
  is not past its `exp`; the product is granted and its `term_end` is in the
  future (or perpetual).
- **grace** — the token is past `exp` but still inside the `grace` window
  (`grace` days from the token). Keep working; refresh when the vendor is
  reachable.
- **expired** — the product subscription `term_end` is in the past.
- **revoked** — definitive. Produced from `blocked=True` (a persisted vendor
  `revoked`/`expired` verdict) or `Verdict.revoked(...)`. Checked first, before
  any decode.
- **invalid** — missing/malformed token, bad signature, wrong issuer, missing
  required claim, unknown mode, product not granted, clock rolled back, or the
  token is expired **past** its grace window.

### Binding (`aud` / `hwid`)

`validate` deliberately does **not** check the production `aud`/`hwid` binding,
because those identifiers are install-specific. The decoded `claims` are
returned so an integrator can enforce binding with the identifiers it owns
(e.g. compare `claims["aud"]` to the database uuid and `claims["hwid"]` to
`compute_hwid(secret)`).

### Optional HTTP client

```python
from xenterprise import client

body = client.activate(server_url, key, database_uuid=..., hwid=...)
body = client.refresh(server_url, key=..., database_uuid=...)
token = client.interpret_response(body)   # raises LicenseRevoked / LicenseInvalid

# Install telemetry (best-effort check-in: install + daily heartbeat).
body = client.register(server_url, database_uuid=..., products="CR_EDI")
```

The client returns the raw vendor body (`{"ok": ..., "token"/"error": ...}`)
with a short timeout; `interpret_response` maps `revoked`/`expired` to
`LicenseRevoked` (definitive) and any other error code to `LicenseInvalid`
(soft — the vendor being unreachable must leave you in grace, never read as a
revocation). Plain `http://` is refused unless `require_https=False`.

## Development

```bash
python -m venv .venv && . .venv/bin/activate
pip install -e ".[test]"
ruff check .
pytest
python -m build        # wheel + sdist in dist/
```

## License

Odoo Proprietary License v1.0 (OPL-1). See `LICENSE`.
