HTTP Digest method / Digest access authentication 摘要访问认证

文章目录

    HTTP Digest method,即,Digest access authentication,中文名为”摘要访问认证”。

    digest 摘要/文摘的意思。

    实际上就是,不以明文发送密码的验证方式。例如,TR069 协议中,ACS 与 CPE 之间的通信都是基于 HTTP Digest method。

    HTTP Digest 的逻辑

    1. 客户端发起 GET 请求
    2. 服务器响应 401 Unauthorized 未认证,HTTP 头信息中的 WWW-Authenticate 指定认证算法,realm 指定安全域 (realm 领域的意思,一般指域名),同时返回随机字符串 nonce (一次性的,防止 replay-attacks)
    3. 客户端重新发起请求,Authorization 指定用户名和密码信息,即摘要信息。MD5(HA1:nonce:HA2),其中 HA1=MD5(username:realm:password), HA2=MD5(method:digestURI)。使用 MD5 hash 算法,而不是 base64,主要是因为 md5 不可逆。
    4. 服务器认证成功,响应 200,可选 Authentication-Info

    Digest Authentication 对比 Basic Authentication

    • Digest Authentication 不以明文发送密码
    • Basic Authentication 以明文的方式发送密码

    TeamsACS

    TeamsACS 中的 HTTP Digest 封装,在 ./common/cwmp/auth_client.go 文件中:

    TeamsACS (main) [1]> grep Digest -r .
    ./common/cwmp/auth_client.go:           var authorization map[string]string = DigestAuthParams(resp)
    ./common/cwmp/auth_client.go:           AuthHeader := fmt.Sprintf(`Digest username="%s", realm="%s", nonce="%s", uri="%s", cnonce="%s", nc=00000001, qop=%s, response="%s", opaque="%s", algorithm=MD5`,
    ./common/cwmp/auth_client.go: auth parameters or nil if the header is not a valid parsable Digest
    ./common/cwmp/auth_client.go:func DigestAuthParams(r *http.Response) map[string]string {
    ./common/cwmp/auth_client.go:   if len(s) != 2 || s[0] != "Digest" {
    

    关于作者 🌱

    我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊,或者关注我的个人公众号“大象工具”, 查看更多联系方式