rs_license —— JWT HS256 授权校验库
基于 PyO3 + Rust 的高安全性 License 校验库。验签逻辑全部在 Rust 二进制内部完成,Python 仅做简单调用。
安全特性
- 密钥混淆存储:真实密钥 XOR 掩码后分片打散存储,运行时动态还原,源码中无明文密钥。
- 内存清零:密钥使用后立即
fill(0)清零,防止内存 dump 抓取。 - Linux 反调试:检测
/proc/self/status的 TracerPid,调试器附加时返回错误密钥使验签失效。 - 签发隔离:
generate_token仅 dev 模式编译,Release 包完全不含签发能力。 - 符号剥离:Release 编译剥离全部符号表、函数名、行号信息。
文件结构
├── Cargo.toml # Rust 依赖与编译配置
├── pyproject.toml # maturin 打包配置
├── src/
│ └── lib.rs # 核心代码(验签/签发/密钥混淆/反调试)
├── tools/
│ └── gen_key_array.py # 密钥分片生成工具
├── demo.py # 使用 Demo
└── README.md # 本文件
快速开始
1. 安装 maturin
pip install maturin
2. 开发调试编译(含 generate_token)
cd rs_license
maturin develop --features dev
3. Release 正式打包(不含 generate_token)
maturin build --release
# 产物:target/wheel/rs_license-1.0.0-*.whl
4. Python 使用
import sys
from rs_license import verify_token, LicenseCode
token = "eyJhbG..." # 我方签发的 Token
resp = verify_token(token)
if resp.code != LicenseCode.OK:
print(f"授权失败: {resp.message}")
sys.exit(1)
print(f"授权通过,客户: {resp.client_id}")
生成新密钥
cd tools
python3 gen_key_array.py
# 按提示输入/生成密钥,将输出的数组替换到 src/lib.rs 中
编译加固
# UPX 加壳
upx --best --ultra-brute target/release/librs_license.so
# 上传 PyPI
pip install twine
twine upload target/wheel/rs_license-1.0.0-*.whl
Metadata
Release files for rs-license 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| rs_license-1.0.0-cp312-cp312-win_amd64.whl | CPython 3.12 | CPython 3.12 | Windows x86-64 | Details for rs_license-1.0.0-cp312-cp312-win_amd64.whl |
| rs_license-1.0.0-cp312-cp312-manylinux_2_28_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.28+ x86-64 | Details for rs_license-1.0.0-cp312-cp312-manylinux_2_28_x86_64.whl |
| rs_license-1.0.0-cp312-cp312-manylinux_2_28_aarch64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.28+ ARM64 | Details for rs_license-1.0.0-cp312-cp312-manylinux_2_28_aarch64.whl |
| rs_license-1.0.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl | CPython 3.12 | CPython 3.12 | macOS 11.0+ ARM64, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64 | Details for rs_license-1.0.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl |
Total release size: 1.8 MB
Release files / rs_license-1.0.0-cp312-cp312-win_amd64.whl
| Download URL | rs_license-1.0.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 336.2 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
1037957423d765fe0ff5e6049495691dc4414a25bf719fad75ecc291f06ac2a9
|
|
BLAKE2b-256 checksum How to use checksums |
d6aaf37d6792b790ac09cd863c3aebe4eda37d9716f9bde29b2e908bbbf9508d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / rs_license-1.0.0-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | rs_license-1.0.0-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 378.9 kB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
cf143491d789d9ed1b8ffbfb7d9667d409da80872c08ab8b0d4306695c62e553
|
|
BLAKE2b-256 checksum How to use checksums |
2d0d7c064b6003b7ff17c484bfbeaff2879a5cd9eeecdb234124d362daa5e6df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / rs_license-1.0.0-cp312-cp312-manylinux_2_28_aarch64.whl
| Download URL | rs_license-1.0.0-cp312-cp312-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 321.8 kB |
| Tags | CPython 3.12 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
148b9db4e110023c54548d1c2c2173cbc9e2629e3dd70b2984a17d2c4278317e
|
|
BLAKE2b-256 checksum How to use checksums |
440a0da582334f020f51c3218040c66bd0c44f57f8bec68c1163ecbec16ba822
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / rs_license-1.0.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
| Download URL | rs_license-1.0.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl |
|---|---|
| Size | 765.4 kB |
| Tags | CPython 3.12 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a07ff13bbea6a109771adfd1380ae9a359ac881c3d4140ff577e90c7ceea3a11
|
|
BLAKE2b-256 checksum How to use checksums |
27008bedc362cbd583542e75d82cf6a69b921abcfc0eefcb45b5925219e1bcd7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for rs-license 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.