jcmturner/gokrb5
GitHub: jcmturner/gokrb5
纯 Go 实现的 Kerberos 身份认证库,提供完整的客户端和服务端功能,支持 SPNEGO HTTP 认证、多种加密类型与企业 AD 集成。
Stars: 781 | Forks: 286
# gokrb5
推荐使用最新版本:[](https://github.com/jcmturner/gokrb5/releases)
开发将集中在最新的主版本上。新功能将仅针对此版本。
| 版本 | 依赖管理 | Import 路径 | 用法 | Godoc | Go Report Card |
|----------|-----------------------|-------------|-------|-------|----------------|
| [](https://github.com/jcmturner/gokrb5/actions?query=workflow%3Av8) | Go modules | import "github.com/jcmturner/gokrb5/v8/{sub-package}" | [](https://github.com/jcmturner/gokrb5/blob/master/v8/USAGE.md) | [](https://pkg.go.dev/github.com/jcmturner/gokrb5/v8) | [](https://goreportcard.com/report/github.com/jcmturner/gokrb5/v8) |
| [](https://github.com/jcmturner/gokrb5/actions?query=workflow%3Av7) | gopkg.in | import "gopkg.in/jcmturner/gokrb5.v7/{sub-package}" | [](https://github.com/jcmturner/gokrb5/blob/master/USAGE.md) | [](https://pkg.go.dev/github.com/jcmturner/gokrb5@v7.5.0+incompatible) | [](https://goreportcard.com/report/gopkg.in/jcmturner/gokrb5.v7) |
## 功能
* **纯 Go 实现** - 不依赖任何外部库
* 没有平台特定的代码
* 服务端
* HTTP handler 包装器实现了 SPNEGO Kerberos 身份验证
* HTTP handler 包装器解码 Microsoft AD PAC 授权数据
* 客户端
* 能够向通过 SPNEGO Kerberos 身份验证的 Web 服务进行认证的客户端
* 能够修改客户端密码
* 通用
* 用于自定义集成的 Kerberos 库
* 解析 Keytab 文件
* 解析 krb5.conf 文件
* 解析客户端凭据缓存文件,例如 `/tmp/krb5cc_$(id -u $(whoami))`
#### 已实现的加密与校验和类型
| 实现 | 加密 ID | 校验和 ID | RFC |
|-------|-------------|------------|------|
| des3-cbc-sha1-kd | 16 | 12 | 3961 |
| aes128-cts-hmac-sha1-96 | 17 | 15 | 3962 |
| aes256-cts-hmac-sha1-96 | 18 | 16 | 3962 |
| aes128-cts-hmac-sha256-128 | 19 | 19 | 8009 |
| aes256-cts-hmac-sha384-192 | 20 | 20 | 8009 |
| rc4-hmac | 23 | -138 | 4757 |
以下内容已正常工作/通过测试:
* 已针对 MIT KDC(1.6.3 是经过测试的最旧版本)和 Microsoft Active Directory(Windows 2008 R2)进行测试
* 已针对支持 PA-FX-FAST 的 KDC 进行测试。
* 已针对使用 PA-ENC-TIMESTAMP 进行预认证的用户进行测试。
* Microsoft PAC 授权数据会被处理并暴露在 HTTP request context 中。如果将 Microsoft Active Directory 用作 KDC,则可用。
## 参考资料
* [RFC 3244 Microsoft Windows 2000 Kerberos 修改密码与设置密码协议](https://tools.ietf.org/html/rfc3244)
* [RFC 4120 Kerberos 网络认证服务 (V5)](https://tools.ietf.org/html/rfc4120)
* [RFC 3961 Kerberos 5 的加密和校验和规范](https://tools.ietf.org/html/rfc3961)
* [RFC 3962 Kerberos 5 的高级加密标准 (AES) 加密](https://tools.ietf.org/html/rfc3962)
* [RFC 4121 Kerberos 版本 5 GSS-API 机制](https://tools.ietf.org/html/rfc4121)
* [RFC 4178 简单且受保护的通用安全服务应用程序接口 (GSS-API) 协商机制](https://tools.ietf.org/html/rfc4178.html)
* [RFC 4559 Microsoft Windows 中基于 SPNEGO 的 Kerberos 和 NTLM HTTP 认证](https://tools.ietf.org/html/rfc4559.html)
* [RFC 4757 Microsoft Windows 使用的 RC4-HMAC Kerberos 加密类型](https://tools.ietf.org/html/rfc4757)
* [RFC 6806 Kerberos 主体名称规范化与跨领域引用](https://tools.ietf.org/html/rfc6806.html)
* [RFC 6113 Kerberos 预认证的通用框架](https://tools.ietf.org/html/rfc6113.html)
* [RFC 8009 Kerberos 5 的 HMAC-SHA2 AES 加密](https://tools.ietf.org/html/rfc8009)
* [IANA 分配的 Kerberos 号码](http://www.iana.org/assignments/kerberos-parameters/kerberos-parameters.xhtml)
* [使用 Negotiate 协议的基于 HTTP 的跨平台身份验证 - 第 1 部分](https://msdn.microsoft.com/en-us/library/ms995329.aspx)
* [使用 Negotiate 协议的基于 HTTP 的跨平台身份验证 - 第 2 部分](https://msdn.microsoft.com/en-us/library/ms995330.aspx)
* [Microsoft PAC 验证](https://blogs.msdn.microsoft.com/openspecification/2009/04/24/understanding-microsoft-kerberos-pac-validation/)
* [Microsoft Kerberos 协议扩展](https://msdn.microsoft.com/en-us/library/cc233855.aspx)
* [Windows 数据类型](https://msdn.microsoft.com/en-us/library/cc230273.aspx)
### 实用链接
* https://en.wikipedia.org/wiki/Ciphertext_stealing#CBC_ciphertext_stealing
## 致谢
* 来自 MIT Kerberos 和 Internet 信任联盟的 Greg Hudson 提供了有用的建议。
## 已知问题
| 问题 | 已规避? | 参考 |
|-------|-------------|------------|
| Go 标准库的 encoding/asn1 包无法反序列化为 asn1.RawValue 切片 | 是 | https://github.com/golang/go/issues/17321 |
| Go 标准库的 encoding/asn1 包无法序列化为 GeneralString | 是 - 使用 https://github.com/jcmturner/gofork/tree/master/encoding/asn1 | https://github.com/golang/go/issues/18832 |
| Go 标准库的 encoding/asn1 包无法序列化为字符串切片,并且无法将 stringtype 参数标签传递给成员 | 是 - 使用 https://github.com/jcmturner/gofork/tree/master/encoding/asn1 | https://github.com/golang/go/issues/18834 |
| Go 标准库的 encoding/asn1 包无法使用 application 标签进行序列化 | 是 | |
| Go 标准库的 x/crypto/pbkdf2.Key 函数使用 int 类型作为迭代计数限制,这意味着在 32 位系统上无法满足 https://tools.ietf.org/html/rfc3962 第 4 节中指定的 4294967296 计数 | 是 - 使用 https://github.com/jcmturner/gofork/tree/master/x/crypto/pbkdf2 | https://go-review.googlesource.com/c/crypto/+/85535 |
标签:EVTX分析, HTTP, Terraform 安全, 日志审计