certdiag 2.7.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
certdiag/__init__.py ADDED
@@ -0,0 +1,65 @@
1
+ r"""certdiag — Windows 代码签名与证书链诊断工具(只读)。
2
+
3
+ 两种用法:
4
+
5
+ # 1) 库
6
+ from certdiag import attribute
7
+ report = attribute(r"C:\Windows\System32\cmd.exe", offline=True)
8
+ report["diagnosis"]["category"] # catalog_only_trust
9
+ report["diagnosis"]["confidence"] # high
10
+
11
+ # 2) 命令行
12
+ python -m certdiag <文件或目录> [--json 报告.json] [--sarif 报告.sarif]
13
+ """
14
+ from __future__ import annotations
15
+
16
+ import sys
17
+ from pathlib import Path
18
+
19
+ from .errors import UnsupportedPlatformError
20
+
21
+ __version__ = "2.7.2"
22
+
23
+ __all__ = ["attribute", "__version__"]
24
+
25
+
26
+ def attribute(path, *, offline: bool = False, no_probe: bool = False,
27
+ timeout: float = 5.0, revoke: str = "cache",
28
+ allow_private: bool = False, strict: bool = False,
29
+ force_catalog: bool = False, force_timestamp: bool = False,
30
+ revoke_timeout: float = 5.0, trace: bool = False,
31
+ tsa_revoke: bool = False) -> dict:
32
+ """诊断单个文件,返回与 CLI ``--json`` 相同结构的报告字典。
33
+
34
+ 参数含义与命令行一致:
35
+
36
+ - ``offline``:不发起任何网络请求(吊销状态会标为未检查)
37
+ - ``no_probe``:不探测 CRL/OCSP 连通性
38
+ - ``revoke``:off / cache / auto / online
39
+ - ``allow_private``:允许探测内网地址(默认拒绝)
40
+ - ``strict``:证据不足时降级为 unknown
41
+
42
+ 注意:默认 ``revoke="cache"`` 与 CLI 一致,可能启动 PowerShell 读取
43
+ 系统缓存;完全不想碰网络/子进程时传 ``offline=True``。
44
+
45
+ 返回的 dict 里至少包含 ``file`` / ``signature`` / ``diagnosis`` 三个键。
46
+ """
47
+ if sys.platform != "win32":
48
+ raise UnsupportedPlatformError("certdiag 的采集层仅支持 Windows")
49
+
50
+ from .cli import diagnose_one
51
+
52
+ return diagnose_one(
53
+ Path(path),
54
+ offline=offline,
55
+ no_probe=no_probe,
56
+ timeout=timeout,
57
+ force_catalog=force_catalog,
58
+ force_timestamp=force_timestamp,
59
+ revoke_mode=revoke,
60
+ allow_private=allow_private,
61
+ strict=strict,
62
+ trace=trace,
63
+ revoke_timeout=revoke_timeout,
64
+ tsa_revoke=tsa_revoke,
65
+ )
certdiag/__main__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ raise SystemExit(main())