Files
dlp-io/README.md
T
Li.jiaqi44 2c5c36f9a3
publish-dlp-io / publish (push) Failing after 50s
feat: is_encrypted 改用物理/逻辑大小判定 (0.4.0)
- 判定改为 GetCompressedFileSizeW 物理大小 vs 白名单 helper 逻辑大小:加密文件
  多 1,024 字节尾块,物理大于逻辑即加密,相等即未加密;不读文件内容,也无需判断
  当前进程是否白名单,Python/pyd/EXE 三种环境同一套代码
- 内容比对降为权威回退:压缩/稀疏文件、无尾块主机、helper 不可用时不结论,回退
  certutil 比对;DLP_IO_DETECT=content 可强制走内容比对
- 新增 handle_stat 与 _compressed_size_api/_physical_size/_helper_size/
  _detect_mode/_size_verdict/_content_verdict
- 测试夹具 DLP加密文件.pptx 换成 DLP加密文件.xlsx,加密用例同步覆盖大小判定
- 新增 docs/DLP_DSOC_API_NOTES.md,更新环境调研与库使用文档
2026-11-19 15:28:58 +08:00

80 lines
4.1 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)` 加密判定**:比 `GetCompressedFileSizeW` 的物理大小与 helper
报告的白名单逻辑大小——加密文件多一个 1,024 字节尾块,物理大于逻辑即加密,相等即
未加密。逻辑大小始终取自白名单 helper,所以不需要判断当前进程是否白名单,
Python/pyd/EXE 三种环境同一套代码。压缩/稀疏文件、helper 不可用等不结论的情况
回退到 certutil 内容比对;`DLP_IO_DETECT=content` 可强制内容比对。
- **写入始终未加密**:按文件后缀探测直写是否落盘明文(写探针文件后用 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 会自动选择最匹配的 wheel:Windows 上 CPython 3.10–3.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 tag,Windows runner(Python 3.10–3.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 wheel,Cython 编译,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
```