RFC 2617 - HTTP Authentication: Basic and Digest Access Authentication
HTTP认证:基本和摘要访问认证
发布日期: 1999年6月
状态: 互联网标准跟踪协议 (Standards Track)
作者: J. Franks, P. Hallam-Baker, J. Hostetler, S. Lawrence, P. Leach, A. Luotonen, L. Stewart
废止: RFC 2069
被废止: RFC 7235, RFC 7615, RFC 7616, RFC 7617
摘要 (Abstract)
HTTP/1.0包含了基本访问认证方案 (Basic Access Authentication Scheme) 的规范。该方案不被认为是安全的用户认证方法(除非与某些外部安全系统如SSL结合使用),因为用户名和密码以明文形式在网络上传输。
本文档还提供了HTTP认证框架 (Authentication Framework) 的规范、原始的基本认证方案以及基于加密哈希的方案,称为"摘要访问认证" (Digest Access Authentication)。因此,它也旨在作为RFC 2069的替代品。由于自发布以来发现的问题,RFC 2069指定的一些可选元素已从本规范中删除;为了兼容性添加了其他新元素,这些新元素已设为可选,但强烈推荐使用。
与基本认证类似,摘要访问认证验证通信双方都知道共享密钥(密码);与基本认证不同的是,这种验证可以在不以明文发送密码的情况下完成,这是基本认证最大的弱点。与大多数其他认证协议一样,最大的风险来源通常不在核心协议本身,而在其使用的策略和程序中。
本备忘录状态 (Status of this Memo)
本文档为互联网社区指定了一个互联网标准跟踪协议,并请求讨论和改进建议。有关本协议的标准化状态和状态,请参阅"互联网官方协议标准"(STD 1)的当前版本。本备忘录的分发不受限制。
目录 (Table of Contents)
- 1. Access Authentication (访问认证)
- 1.1 Reliance on the HTTP/1.1 Specification (依赖HTTP/1.1规范)
- 1.2 Access Authentication Framework (访问认证框架)
- 2. Basic Authentication Scheme (基本认证方案)
- 3. Digest Access Authentication Scheme (摘要访问认证方案)
- 3.1 Introduction (简介)
- 3.1.1 Purpose (目的)
- 3.1.2 Overall Operation (整体操作)
- 3.1.3 Representation of digest values (摘要值的表示)
- 3.1.4 Limitations (限制)
- 3.2 Specification of Digest Headers (摘要头部规范)
- 3.2.1 The WWW-Authenticate Response Header (WWW-Authenticate响应头)
- 3.2.2 The Authorization Request Header (Authorization请求头)
- 3.2.3 The Authentication-Info Header (Authentication-Info头)
- 3.3 Digest Operation (摘要操作)
- 3.4 Security Protocol Negotiation (安全协议协商)
- 3.5 Example (示例)
- 3.6 Proxy-Authentication and Proxy-Authorization (代理认证和代理授权)
- 3.1 Introduction (简介)
- 4. Security Considerations (安全考虑)
- 4.1 Authentication of Clients using Basic Authentication
- 4.2 Authentication of Clients using Digest Authentication
- 4.3 Limited Use Nonce Values
- 4.4 Comparison of Digest with Basic Authentication
- 4.5 Replay Attacks
- 4.6 Weakness Created by Multiple Authentication Schemes
- 4.7 Online dictionary attacks
- 4.8 Man in the Middle
- 4.9 Chosen plaintext attacks
- 4.10 Precomputed dictionary attacks
- 4.11 Batch brute force attacks
- 4.12 Spoofing by Counterfeit Servers
- 4.13 Storing passwords
- 4.14 Summary
- 5. Sample implementation (示例实现)
- 6. Acknowledgments (致谢)
- 7. References (参考文献)
- 8. Authors' Addresses (作者地址)
核心概念
两种认证方案
1. Basic Authentication (基本认证)
- 原理: 用户名和密码以Base64编码发送
- 格式:
Authorization: Basic base64(username:password) - 安全性: ⚠️ 明文传输,不安全(除非使用HTTPS)
- 使用场景: 简单应用、内部系统、配合HTTPS
2. Digest Authentication (摘要认证)
- 原理: 使用MD5哈希,密码不以明文传输
- 格式: 包含nonce、realm、qop等参数
- 安全性: ✅ 比Basic更安全,但仍建议使用HTTPS
- 使用场景: 需要更高安全性的HTTP认证
认证流程
客户端 服务器
| |
|-------- 1. 请求受保护资源 -------->|
| |
|<------ 2. 401 + WWW-Authenticate --|
| (挑战) |
| |
|-------- 3. Authorization 头 ------>|
| (凭据) |
| |
|<------ 4. 200 OK + 资源 -----------|
| |
HTTP状态码
- 401 Unauthorized: 需要认证
- 407 Proxy Authentication Required: 需要代理认证
关键HTTP头部
WWW-Authenticate: 服务器发送的挑战Authorization: 客户端发送的凭据Authentication-Info: 可选的认证信息Proxy-Authenticate: 代理服务器的挑战Proxy-Authorization: 发送给代理的凭据
示例
Basic Authentication 示例
服务器响应:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="WallyWorld"
客户端请求:
GET /private/index.html HTTP/1.1
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Digest Authentication 示例
服务器响应:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Digest
realm="[email protected]",
qop="auth,auth-int",
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
opaque="5ccc069c403ebaf9f0171e9517f40e41"
客户端请求:
GET /dir/index.html HTTP/1.1
Authorization: Digest username="Mufasa",
realm="[email protected]",
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
uri="/dir/index.html",
qop=auth,
nc=00000001,
cnonce="0a4f113b",
response="6629fae49393a05397450978507c4ef1",
opaque="5ccc069c403ebaf9f0171e9517f40e41"
相关资源 (Related Resources)
- 官方原文: RFC 2617 (TXT)
- 官方页面: RFC 2617 DataTracker
- 废止: RFC 2069
- 被废止:
- RFC 7235 (HTTP/1.1 Authentication)
- RFC 7615 (HTTP Authentication-Info)
- RFC 7616 (HTTP Digest Access Authentication)
- RFC 7617 (HTTP Basic Authentication)
安全警告 ⚠️
- Basic认证不安全: 必须配合HTTPS使用
- Digest认证也有局限: 虽然比Basic好,但仍建议使用HTTPS
- 现代替代方案: 考虑使用OAuth 2.0、JWT等现代认证机制
- 密码存储: 服务器应使用加盐哈希存储密码
重要提示: RFC 2617已被RFC 7235、7616、7617等文档废止。现代应用应参考这些更新的标准,或使用OAuth 2.0等现代认证框架。