gpt4 book ai didi

go - 如何在 Golang 上通过 IPC 为 OpenLDAP 客户端实现 SASL/EXTERNAL?

转载 作者:行者123 更新时间:2023-12-02 21:32:13 24 4
gpt4 key购买 nike

我目前正在尝试为用 Golang 编写的 OpenLDAP 客户端实现 SASL/EXTERNAL 身份验证。

换句话说,我想加载以下数据:

ldapsearch -Y EXTERNAL -H ldapi:// -s base -b 'olcDatabase={1}mdb,cn=config' olcSyncRepl

我正在使用https://github.com/go-ldap/ldap图书馆。不幸的是,该库仅支持简单的身份验证。我很高兴实现 SASL/EXTERNAL 但我无法识别该协议(protocol)是如何工作的?例如有https://ldap.com/ldapv3-wire-protocol-reference-bind/ CRAM-MD5 身份验证过程。

我想得到 SASL/EXTERNAL 的相同解释。

我成功连接到 unix 套接字 (ldapi://)。但我不明白需要以编程方式发送什么样的命令才能完成身份验证。

最佳答案

我找到了解决方案。

首先,您需要连接到unix套接字。通常,套接字位于 /var/run/slapd/ldapi 路径。

然后您需要进行两个更改的简单绑定(bind):

  1. 用户名应为空
  2. 需要指定您要使用 sasl 身份验证
pkt := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationBindRequest, nil, "Bind Request")
pkt.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, 3, "Version"))
pkt.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, "", "User Name"))

saslAuth := ber.Encode(ber.ClassContext, ber.TypeConstructed, 3, "", "authentication")
saslAuth.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, "EXTERNAL", "SASL Mech"))
saslAuth.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, "", "SASL Cred"))

pkt.AppendChild(saslAuth)

这是 PR https://github.com/go-ldap/ldap/pull/232 .

关于go - 如何在 Golang 上通过 IPC 为 OpenLDAP 客户端实现 SASL/EXTERNAL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58272670/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com