Files
dlp-io/README.md
T
p40000043244@byd.com 316f307034 ci: 3.8/3.9 仅提供纯 Python wheel, CI 矩阵回退 3.10-3.14
Windows runner 未安装 Python 3.8/3.9 (run 258 失败于 Python 3.8 is required)。
requires-python 维持 >=3.8: 3.8/3.9 用户安装 py3-none-any wheel, 功能一致;
pyd wheel 覆盖 runner 预装的 3.10-3.14。
2026-08-03 16:10:06 +08:00

78 lines
3.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# dlp-io
io-compatible file reads through an approved Python helper on Windows DLP hosts.
完整文档见 [docs/DLP_IO_LIBRARY.md](docs/DLP_IO_LIBRARY.md);DLP 环境实测特征与判定/写入逻辑推导见 [docs/DLP_ENVIRONMENT_NOTES.md](docs/DLP_ENVIRONMENT_NOTES.md)。
## DLP 程序化特征与实现逻辑
在透明加密 DLP 环境下实测到的关键事实(详见上面的特征文档):
- **文件属性不可区分**:加密/未加密文件的 attrib、ADS、大小完全一致,只有内容可判。
- **同尺寸流式加密**:密文无附加头尾、无静态 magic,且进程按身份分白名单——
`python.exe`/`cmd.exe`/`powershell.exe` 读加密文件得到明文(透明解密),
`certutil.exe` 等非白名单工具得到磁盘密文。
- **白名单读透明 ≠ 写加密**:写入是否被加密因机器策略而异,必须运行时探测。
对应的实现逻辑:
- **读取始终明文**:打包 EXE(非白名单)经 stdin 注入 helper 源码拉起白名单
`python.exe`,由它读明文、经认证 Named Pipe 回传(python 按身份白名单,
任何父进程拉起都有效)。
- **`is_encrypted(path)` 加密判定**:先比 certutil 原始哈希与当前进程视图哈希,
不等即加密;相等时存在歧义(未加密,或 EXE 读加密文件),再比 helper 视图与
本地视图的前 64 KiB 定案——Python/pyd/EXE 三种环境都正确。
- **写入始终未加密**:按文件后缀探测直写是否落盘明文(写探针文件后用 certutil
原始哈希校验);若直写会被加密,自动切换到 PowerShell stdin 管道中转写盘,
字节不落地任何临时文件;两通道均不可用则抛 `DlpWriteError`,绝不静默写密文。
可用 `DLP_IO_WRITE_CHANNEL=direct|powershell` 强制指定通道。
## 安装
从 Gitea PyPI registry 安装(匿名可下载,无需 token):
```powershell
py -m pip install --index-url https://gitea.docker.antior.cn/api/packages/antior/pypi/simple dlp-io
```
pip 会自动选择最匹配的 wheelWindows 上 CPython 3.103.14 安装对应的 pyd wheel(整个库由 Cython 编译为单个 `.pyd`),3.8/3.9 及其余环境安装纯 Python wheel(库要求 Python >= 3.8)。如需固定版本:
```powershell
py -m pip install --index-url https://gitea.docker.antior.cn/api/packages/antior/pypi/simple dlp-io==0.1.1
```
也可以从 [Releases](https://gitea.docker.antior.cn/antior/dlp-io/releases) 页面下载产物:wheel 用 `py -m pip install <文件>` 安装;`dlp_io.py` 或对应版本的裸 `.pyd` 为免安装单文件,直接放进项目目录(或加入 `PYTHONPATH`)即可 `import dlp_io`
## 开发
```bash
pip install -r requirements-dev.txt
pytest
```
## 构建发布
发布流程由 `.gitea/workflows/publish-dlp-io.yaml` 驱动:推送 `dlp-io-vX.Y.Z` 格式的 annotated tagWindows runnerPython 3.103.14)会自动完成测试、构建,并把产物上传到 Gitea Release
- `dlp_io-X.Y.Z-py3-none-any.whl`(纯 Python,跨平台)
- `dlp_io-X.Y.Z-cp310``cp314-win_amd64.whl`5 个 pyd wheelCython 编译,Windows 按解释器版本选用;3.8/3.9 使用纯 Python wheel
- `dlp_io-X.Y.Z.tar.gz`sdist
- `dlp_io.py` 和 5 个裸 `dlp_io.cp3XX-win_amd64.pyd`(免安装单文件,放进项目目录即可 import)
同一批 wheel/sdist 还会同步发布到 Gitea PyPI registry`https://gitea.docker.antior.cn/api/packages/antior/pypi/simple`),可直接 `pip install --index-url ... dlp-io`
安装方式见 [docs/DLP_IO_LIBRARY.md](docs/DLP_IO_LIBRARY.md)。
本地只构建纯 Python 版:
```bash
py -3.13 -m build
```
pyd wheel 由 CI 编译,不需要本地编译;runner 主机需预装 MSVC 生成工具(Visual Studio Build Tools 的 C++ 工作负载)。如需本地验证 pyd 构建,安装 `cython` 后执行:
```bash
set DLP_IO_PYD=1
py -3.13 -m build --wheel --no-isolation
```