zmap/zlint
GitHub: zmap/zlint
ZLint 是一个用 Go 编写的 X.509 证书 linter,用于检查证书是否符合 Web PKI 标准及各项 CA/Browser Forum 等基线要求。
Stars: 439 | Forks: 124
# ZLint
[](https://github.com/zmap/zlint/actions?query=workflow%3AGo)
[](https://github.com/zmap/zlint/actions?query=workflow%3Aintegration-test)
[](https://github.com/zmap/zlint/actions?query=workflow%3Agolangci-lint)
[](https://goreportcard.com/report/github.com/zmap/zlint)
ZLint 是一个用 Go 编写的 X.509 证书 linter,用于检查与标准(例如
[RFC 5280])以及其他相关 PKI 要求(例如
[CA/Browser Forum 基线要求][BR v1.4.8])的一致性。
它可以作为命令行工具使用,也可以作为库集成到 CA
软件中。
## 要求
ZLint 要求安装 [Go 1.16.x 或更高版本](https://golang.org/doc/install)。
命令行设置说明假设 `go` 命令包含在您的 `$PATH` 中。
## Lint 来源
历史上,ZLint 仅专注于 [RFC 5280] 和 [CA/Browser Forum 基线要求][BRs] 的
[v1.4.8 版本][BR v1.4.8]。有关原始 BR 覆盖范围的详细
列表,可以在[此电子表格中][Coverage Spreadsheet]找到。
最近,ZLint 进行了重构,使得基于
其他来源添加 lint 变得更加容易。虽然还不完整,但目前 ZLint 的 lint 来源包括:
* [CA/Browser Forum EV SSL 证书指南][CABF EV]
* [ETSI ESI]
* [Mozilla 的 PKI 策略][MozPolicy]
* [Apple 的 CT 策略][AppleCT]
* 各种 RFC(例如 [RFC 6818]、[RFC 4055]、[RFC 8399])
默认情况下,ZLint 将应用来自所有来源的适用 lint,但使用者也
可以通过包含/排除特定来源来自定义使用哪些 lint。
## 版本控制和发布
在可能的情况下,我们将在最终确定生产就绪的发布标签前一周,
尝试提供发布候选版本 (RC)。我们鼓励用户测试 RC
发布,以便及早提供反馈,从而在
正式发布之前修复 bug。
## 命令行使用
ZLint 可以通过简单的捆绑可执行文件
_ZLint_ 在命令行中使用,也可以通过
[ZCertificate](https://github.com/zmap/zcertificate) 使用,这是一个更加成熟的
命令行证书解析器,它链接到 ZLint。
ZLint CLI 使用示例:
```
go get github.com/zmap/zlint/v3/cmd/zlint
echo "Lint mycert.pem with all applicable lints"
zlint mycert.pem
echo "Lint mycert.pem with just the two named lints"
zlint -includeNames=e_mp_exponent_cannot_be_one,e_mp_modulus_must_be_divisible_by_8 mycert.pem
echo "List available lint sources"
zlint -list-lints-source
echo "Lint mycert.pem with all of the lints except for ETSI ESI sourced lints"
zlint -excludeSources=ETSI_ESI mycert.pem
echo "Receive a copy of the full (default) configuration for all configurable lints"
zlint -exampleConfig
echo "Lint mycert.pem using a custom configuration for any configurable lints"
zlint -config configFile.toml mycert.pem
echo "List available lint profiles. A profile is a pre-defined collection of lints."
zlint -list-profiles
```
有关所有可用的命令行选项,请参阅 `zlint -h`。
### Lint 证书吊销列表
在对证书吊销列表运行 lint 时,不需要特殊的标志。但是,相关的 CRL 必须是带有 `X509 CRL` PEM armor 的 PEM 编码 ASN.1。
以下是可解析的 CRL PEM 文件的示例。
```
-----BEGIN X509 CRL-----
MIIBnjCBhwIBATANBgkqhkiG9w0BAQsFADAYMRYwFAYDVQQDEw1BbWlyIHdhcyBI
ZXJlFw0yMzAzMTMwNTUyNTVaFw0yMzAzMTQwNTUyNTVaoDswOTArBgNVHSMEJDAi
gCAywvCJz28KsE/6Wf9E1nuiihBFWlUyq7X/RDgn5SllIDAKBgNVHRQEAwIBATAN
BgkqhkiG9w0BAQsFAAOCAQEAakioBhLs31svWHGmolDhUg6O1daN6zXSAz/avgzl
38aTKfRSNQ+vM7qgrvCoRojnamziJgXe1hz+/dc8H0/+WEBwVgp1rBzr8f25dSZC
lXBHT1cNI5RL+wU0pFMouUiwWqwUg8o9iGYkqvhuko4AQIcpAoBuf0OggjCuj48r
FX7UN7Kz4pc/4ufengKGkf7EeEQffY3zlS0DAtWv+exoQ6Dt+otDr0PbINJZg+46
TJ/+0w6RsLGoe4Sh/PYPfaCngMyezENUgJgR1+vF6hbVUweeOB+4nFRNxvHMup0G
GEA4yfzQtHWL8rizWUCyuqXEMPZLzyJT0rv5cLgoOvs+8Q==
-----END X509 CRL-----
```
## 库使用
ZLint 也可以作为库使用。使用所有适用的
lint 对证书进行检查,就像将 `zlint.LintCertificate` 与已解析的证书一起使用一样简单:
```
import (
"github.com/zmap/zcrypto/x509"
"github.com/zmap/zlint/v3"
)
var certDER []byte = ...
parsed, err := x509.ParseCertificate(certDER)
if err != nil {
// If x509.ParseCertificate fails, the certificate is too broken to lint.
// This should be treated as ZLint rejecting the certificate
log.Fatal("unable to parse certificate:", err)
}
zlintResultSet := zlint.LintCertificate(parsed)
```
要使用一部分 lint(例如,基于 lint 来源或
名称)对证书进行 lint,请过滤全局 lint registry,并将其与 `zlint.LintCertificateEx` 一起使用:
```
import (
"github.com/zmap/zcrypto/x509"
"github.com/zmap/zlint/v3"
"github.com/zmap/zlint/v3/lint"
)
var certDER []byte = ...
parsed, err := x509.ParseCertificate(certDER)
if err != nil {
// If x509.ParseCertificate fails, the certificate is too broken to lint.
// This should be treated as ZLint rejecting the certificate
log.Fatal("unable to parse certificate:", err)
}
registry, err := lint.GlobalRegistry().Filter(lint.FilterOptions{
ExcludeSources: []lint.LintSource{lint.EtsiEsi},
})
if err != nil {
log.Fatal("lint registry filter failed to apply:", err)
}
zlintResultSet := zlint.LintCertificateEx(parsed, registry)
```
要在存在特定配置文件的情况下对证书进行 lint,您必须先构建配置,然后在 `Registry` 接口中调用 `SetConfiguration`。
可以使用以下任意函数构建 `Configuration`:
* `lint.NewConfig(r io.Reader) (Configuration, error)`
* `lint.NewConfigFromFile(path string) (Configuration, error)`
* `lint.NewConfigFromString(config string) (Configuration, error)`
所有三个构造函数的输入内容必须是有效的 TOML 文档。
```
import (
"github.com/zmap/zcrypto/x509"
"github.com/zmap/zlint/v3"
)
var certDER []byte = ...
parsed, err := x509.ParseCertificate(certDER)
if err != nil {
// If x509.ParseCertificate fails, the certificate is too broken to lint.
// This should be treated as ZLint rejecting the certificate
log.Fatal("unable to parse certificate:", err)
}
configuration, err := lint.NewConfigFromString(`
[some_configurable_lint]
IsWebPki = true
NumIterations = 42
[some_configurable_lint.AnySubMapping]
something = "else"
anything = "at all"
`)
if err != nil {
log.Fatal("unable to parse configuration:", err)
}
lint.GlobalRegistry().SetConfigutration(configuration)
zlintResultSet := zlint.LintCertificate(parsed)
```
有关示例,请参阅 [`zlint` 命令][zlint cmd]的源代码。
## 扩展 ZLint
## Zlint 用户/集成
[Mozilla root program](https://wiki.allizom.org/CA/Required_or_Recommended_Practices#Pre-Issuance_Linting) **强烈建议**进行颁发前 linting。
以下是一些已知以某种方式与 ZLint 集成的项目/CA:
* [Actalis](https://www.actalis.it/en/home.aspx)
* [ANF AC](https://www.anf.es/)
* [Camerfirma](https://www.camerfirma.com/)
* [CFSSL](https://github.com/cloudflare/cfssl)
* [Deutsche Telekom Security GmbH](https://www.telesec.de/en)
* [Digicert](https://www.digicert.com/)
* [EJBCA](https://download.primekey.com/docs/EJBCA-Enterprise/6_11_1/adminguide.html#Post%20Processing%20Validators%20(Pre-Certificate%20or%20Certificate%20Validation))
* [Entrust](https://www.entrust.com/)
* [Globalsign](https://www.globalsign.com/en/)
* [GoDaddy](https://www.godaddy.com)
* [Google Trust Services](https://pki.goog/)
* [Government of Spain, FNMT](http://www.fnmt.es/)
* [Izenpe](https://www.izenpe.eus/)
* [Let's Encrypt](https://letsencrypt.org) 和 [Boulder](https://github.com/letsencrypt/boulder)
* [Microsec](https://www.microsec.com/)
* [Microsoft](https://www.microsoft.com)
* [Nexus Certificate Manager](https://doc.nexusgroup.com/display/PUB/Smart+ID+Certificate+Manager)
* [QuoVadis](https://www.quovadisglobal.com/)
* [Sectigo](https://sectigo.com/)、[crt.sh](https://crt.sh/) 和 [pkimetal](https://github.com/pkimetal/pkimetal)
* [Siemens](https://siemens.com/pki)
* [SSL.com](https://www.ssl.com/)
* [PKI Insights](https://www.codegic.com/pki-insights-health-monitoring-for-microsoft-ca/)
* [NETLOCK](https://www.netlock.hu/)
* [Disig](https://eidas.disig.sk/en/)
如果您了解
其他使用 zlint 的 CA/项目,请提交 pull request 来更新 README。
## 许可和版权
ZMap 版权所有 2024 Regents of the University of Michigan
根据 Apache License, Version 2.0(“License”)获得许可;除非遵守
License,否则您不得使用
此文件。您可以在 http://www.apache.org/licenses/LICENSE-2.0 获取
License 的副本。
除非适用法律要求或书面同意,否则根据
License 分发的软件按“原样”分发,不附带任何明示或
暗示的保证或条件。有关管辖 License 下的权限和
限制的具体语言,请参阅 LICENSE。
标签:EVTX分析, Go语言, Python安全, Web PKI, X.509证书, 代码检查工具, 密码学, 手动系统调用, 文档结构分析, 日志审计, 程序破解