Metadata-Version: 2.5
Name: fastapi-license
Version: 1.0.0
Summary: Enterprise hardware-bound license system for FastAPI applications with PyArmor obfuscation support.
Project-URL: Homepage, https://github.com/your-org/fastapi-license
Project-URL: Documentation, https://github.com/your-org/fastapi-license#readme
Project-URL: Repository, https://github.com/your-org/fastapi-license
Project-URL: Issues, https://github.com/your-org/fastapi-license/issues
Author-email: fastapi-license Developer <dev@fastapi-license.io>
License: Proprietary
Keywords: drm,fastapi,hardware-fingerprint,license,obfuscation,pyarmor
Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: FastAPI
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 :: Security
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: click>=8.1.0
Requires-Dist: cryptography>=42.0.0
Requires-Dist: fastapi>=0.111.0
Requires-Dist: psutil>=5.9.0
Requires-Dist: rich>=13.7.0
Requires-Dist: starlette>=0.37.0
Provides-Extra: dev
Requires-Dist: build>=1.2.0; extra == 'dev'
Requires-Dist: hatch>=1.9.0; extra == 'dev'
Requires-Dist: httpx>=0.27.0; extra == 'dev'
Requires-Dist: pyarmor>=8.5.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: ruff>=0.4.0; extra == 'dev'
Requires-Dist: twine>=5.1.0; extra == 'dev'
Description-Content-Type: text/markdown

# fastapi-license

> **Enterprise hardware-bound license system for FastAPI applications.**  
> Distribusi binary terobfuskasi via PyArmor v8+ BCC mode, dengan CLI berbasis Click + Rich dan integrasi FastAPI Lifespan & Middleware.

---

## Instalasi

```bash
pip install fastapi-license
```

---

## Alur Kerja

### 1. Client: Ambil Hardware Fingerprint (Server Klien)
```bash
fastapi-license probe --output fingerprint.json
```

### 2. Developer: Generate Lisensi
```bash
fastapi-license gen \
  --fingerprint fingerprint.json \
  --expiry 2027-12-31 \
  --features "analytics,pdf_export,billing" \
  --private-key private.pem \
  --output license.lic
```

### 3. Developer: Build & Obfuskasi Kode FastAPI
```bash
fastapi-license build --src ./my_app --dist ./dist_protected --bcc
```

### 4. Admin: Inspeksi Lisensi
```bash
fastapi-license inspect --license license.lic --public-key public.pem
```

---

## Integrasi FastAPI

```python
from contextlib import asynccontextmanager
from fastapi import FastAPI, Depends
from fastapi_license import LicenseManager, LicenseGuardMiddleware, require_feature

license_manager = LicenseManager(
    license_path="license.lic",
    public_key_path="public.pem"
)

@asynccontextmanager
async def lifespan(app: FastAPI):
    license_manager.verify_on_startup()
    yield

app = FastAPI(title="Protected API", lifespan=lifespan)
app.add_middleware(LicenseGuardMiddleware, manager=license_manager)

@app.get("/api/analytics", dependencies=[Depends(require_feature("analytics"))])
async def analytics():
    return {"data": "Analytics stream"}
```

---

## Generate Keypair

```python
from fastapi_license.core.crypto import CryptoEngine

engine = CryptoEngine()
private_pem, public_pem = engine.generate_keypair(algorithm="ed25519")

with open("private.pem", "wb") as f:
    f.write(private_pem)
with open("public.pem", "wb") as f:
    f.write(public_pem)
```

---

## Security Architecture

- **Hardware Binding**: CPU ID + Motherboard UUID + Root Disk Serial + Primary MAC → SHA-256
- **Cryptography**: Ed25519 (default) / RSA-4096 asymmetric signature
- **Obfuscation**: PyArmor v8+ BCC Mode → native C binary (`.so` / `.pyd`)
- **Fail-Closed**: Semua error lisensi menyebabkan `sys.exit(1)` sebelum server bind port
- **Clock Anti-Tamper**: Monotonic clock + heartbeat timestamp comparison

---

## Exception Hierarchy

| Exception | Trigger |
|---|---|
| `LicenseNotFoundError` | File `license.lic` tidak ditemukan |
| `TamperDetectedError` | Signature cryptographic tidak valid |
| `HardwareMismatchError` | Hardware ID server tidak cocok |
| `LicenseExpiredError` | Tanggal kedaluwarsa terlewat |
| `ClockTamperError` | Manipulasi waktu sistem terdeteksi |
