配置Apache Digest认证

article/2025/11/8 15:57:16

Apache常见的用户认证可以分为下面三种:

  • 基于IP,子网的访问控制(ACL)
  • 基本用户验证(Basic Authentication)
  • 消息摘要式身份验证(Digest Authentication)

消息摘要式身份验证(Digest Authentication)

Digest Authentication在基本身份验证上面扩展了安全性。服务器为每一连接生成一个唯一的随机数,客户端对用这个随机数对密码进行MD5加密,然后发送到服务器,服务器端也用此随机数对密码加密,然后和客户端传送过来的加密数据进行比较。

1. 发送页面访问请求

Request URL:http://localhost/config/

Request method:GET

2. Web服务器要求用书输入用户凭据(服务器返回401响应头和’realm’域)

HTTP/1.1 401 Unauthorized
Date: Tue, 01 Jun 2021 07:17:51 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-XSS-Protection: 1;mode=block
WWW-Authenticate: Digest realm="Digest Encrypt", nonce="C9zdI6/DBQA=b6e73f0db8e3966873cc961fc22031b43e02aab6", algorithm=MD5, qop="auth"
Content-Length: 381
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1

3. 浏览器弹出登录窗口(包含’realm’), 要求用提供用户名/密码

4.输入用户名密码后的请求

Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Authorization: Digest username="Admin", realm="Digest Encrypt", nonce="C9zdI6/DBQA=b6e73f0db8e3966873cc961fc22031b43e02aab6", uri="/config/", algorithm=MD5, response="ae7dc868b37313788a24d2e6e0094154", qop=auth, nc=00000001, cnonce="001945ca0da1ba75"

5.服务器将用户输入加密后的凭据和服务器端加密后的的凭据进行比较,如果一致则返回所请求页面的响应

HTTP/1.1 200 OK
Date: Tue, 01 Jun 2021 08:26:28 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-XSS-Protection: 1;mode=block
Authentication-Info: rspauth="a04006ede76a798709c2ea1c5c7533bb", cnonce="777276a0e05dcab9", nc=00000002, qop=auth
Content-Length: 5089
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html;charset=UTF-8


配置Apache

1. 创建密码文件

htdiget [-c] passwordfile realm username

D:\Softwares\Apache24\bin> htdigest.exe -c \ "Digest Encrypt" Admin

Adding password for Admin in realm Digest Encrypt.

New password: ********
Re-type new password: ********

-c = create file

常规添加不要使用-c选项,,因为它会覆盖现有的文件。

文件内容格式:Admin:Digest Encrypt:ded139b4abeb56c14a30ff0a07e27010

2. 配置httpd.conf

# The 'AuthName' and the 'Realm' must be the same (BASIC validation can be different). 
# Otherwise correct user password still will not pass the authentication.
<Directory "${DocumentRoot}\config">
    Options Indexes FollowSymLinks
    AuthType Digest
    AuthName "Digest Encrypt"
    AuthUserFile "D:\digest.txt"
    require valid-user
    AllowOverride None
</Directory>

3. 认证模块配置

查看httpd.conf里面是否有 

LoadModule auth_digest_module modules/mod_auth_digest.so
#LoadModule auth_basic_module modules/mod_auth_basic.so    

首先确认要有mod_auth_digest.so,这个没有就要重新编译apache。 

其次确保把mod_auth_basic.so这行给注释掉。因为apache默认是用basic来认证的,如果不注释的话,即使配置好了digest认证,也不会成功。两种认证方法只能二选一。


WWW-Authenticate Response Header

If a server receives a request for an access-protected object, and an acceptable Authorization header is not sent, the server responds with a "401 Unauthorized" status code, and a WWW-Authenticate header as per the framework defined above, which for the digest scheme is utilized as follows.

如果服务器收到对受访问保护对象的请求,并且没有发送可接受的授权头,则服务器会以 "401未授权 "状态代码和WWW-Authenticate头作为回应。

      challenge        =  "Digest" digest-challengedigest-challenge  = 1#( realm | [ domain ] | nonce |[ opaque ] |[ stale ] | [ algorithm ] |[ qop-options ] | [auth-param] )domain            = "domain" "=" <"> URI ( 1*SP URI ) <">URI               = absoluteURI | abs_pathnonce             = "nonce" "=" nonce-valuenonce-value       = quoted-stringopaque            = "opaque" "=" quoted-stringstale             = "stale" "=" ( "true" | "false" )algorithm         = "algorithm" "=" ( "MD5" | "MD5-sess" |token )qop-options       = "qop" "=" <"> 1#qop-value <">qop-value         = "auth" | "auth-int" | token
scheme说明
   realm

显示给用户的一个字符串,以便他们知道使用哪一个用户名和密码。这个字符串至少应该包含的名称,还可能包括表示可能有权限的用户集合。

例:"registered_users@gotham.news.com"。

nonce

服务器每次作出401响应时生成的唯一数据字符串。

nonce对客户端来说是不透明的。

参考链接

1. The WWW-Authenticate Response Header
 

 

 


http://chatgpt.dhexx.cn/article/8YSOqFSp.shtml

相关文章

http Digest认证计算方法整理

摘要认证及实现HTTP digest authentication - 简书 HTTP Basic和Digest认证介绍与计算 - 诸子流 - 博客园 不要不知道上面说的URI是什么意思啊 图解HTTP 第 8 章 确认访问用户身份的认证 - 简书8.1 何为认证 为了弄清究竟是谁在访问服务器&#xff0c;就得让对方的客户端自报家…

业务维度digest日志的记录与监控方案

需求 ​   为了满足从业务整体的维度 实现监控和链路复原&#xff0c;我们希望对于一个业务接口&#xff0c;记录一行请求日志&#xff0c;并通过某个 Unique Id&#xff08;如UserId、OrderId&#xff09;将多行日志关联起来&#xff0c;最终产出一批和业务强相关的数据&am…

java发起Digest Auth请求

常规认证方式 上代码&#xff1a; 需要的Maven <dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.5</version></dependency><dependency><groupId>org.…

认证学习3 - Digest摘要认证讲解、代码实现、演示

文章目录 Digest摘要认证 - 密文讲解&#xff08;Digest摘要认证&#xff09;实现&#xff08;Digest认证&#xff09;代码&#xff08;Digest认证&#xff09;代码&#xff08;Digest认证-客户端&#xff09;演示&#xff08;Digest认证-postman&#xff09; 认证大全&#xf…

HTTP的认证方式之DIGEST 认证(摘要认证)

核心步骤&#xff1a; 步骤 1&#xff1a; 请求需认证的资源时&#xff0c;服务器会随着状态码 401Authorization Required&#xff0c;返回带WWW-Authenticate 首部字段的响应。该字段内包含质问响应方式认证所需的临时质询码&#xff08;随机数&#xff0c;nonce&#xff09;…

Digest Auth 摘要认证

Digest Auth 摘要认证 1.非常规方式 转载&#xff1a;https://blog.csdn.net/qq_25391785/article/details/86595529 public static void postMethod(String url, String query) {try {CredentialsProvider credsProvider new BasicCredentialsProvider();credsProvider.setC…

digest鉴权

“摘要”式认证&#xff08; Digest authentication&#xff09;是一个简单的认证机制&#xff0c;最初是为HTTP协议开发的&#xff0c;因而也常叫做HTTP摘要&#xff0c;在RFC2671中描述。其身份验证机制很简单&#xff0c;它采用杂凑式&#xff08;hash&#xff09;加密方法&…

消息摘要(Digest),数字签名(Signature),数字证书(Certificate)是什么?

1. 消息摘要&#xff08;Digest&#xff09; 1. 什么是消息摘要&#xff1f; 对一份数据&#xff0c;进行一个单向的 Hash 函数&#xff0c;生成一个固定长度的 Hash 值&#xff0c;这个值就是这份数据的摘要&#xff0c;也称为指纹。 2. 摘要算法 常见的摘要算法有 MD5、SHA…

HTTP通讯安全中的Digest摘要认证释义与实现

摘要 出于安全考虑&#xff0c;HTTP规范定义了几种认证方式以对访问者身份进行鉴权&#xff0c;最常见的认证方式之一是Digest认证 Digest认证简介 HTTP通讯采用人类可阅读的文本格式进行数据通讯&#xff0c;其内容非常容易被解读。出于安全考虑&#xff0c;HTTP规范定义了几…

http协议之digest(摘要)认证,详细讲解并附Java SpringBoot源码

目录 1.digest认证是什么&#xff1f; 2.digest认证过程 3.digest认证参数详解 4.基于SpringBoot实现digest认证 5.digest认证演示 6.digest认证完整项目 7.参考博客 1.digest认证是什么&#xff1f; HTTP通讯采用人类可阅读的文本格式进行数据通讯&#xff0c;其内容非…

【WinRAR】WinRAR 6.01 官方最新简体中文版

WinRAR 6.01 官方简体中文商业版下载地址&#xff08;需要注册&#xff09;&#xff1a; 64位&#xff1a; https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20210414/wrr/winrar-x64-601sc.exe https://www.win-rar.com/fileadmin/winrar-versions/sc/sc20210414/…

WinRAR命令行

基本使用 实践 将文件夹压缩到zip包 输入&#xff1a;文件夹如下&#xff0c;文件夹为class。 输出&#xff1a;classes.zip 指令如下&#xff1a; rar a classes.zip .\classes或者 WinRAR a classes.zip .\classes结果如下&#xff1a; PS C:\Users\liyd\Desktop\kuai…

WinRAR安装教程

文章目录 WinRAR安装教程无广告1. 下载2. 安装3. 注册4. 去广告 WinRAR安装教程无广告 1. 下载 国内官网&#xff1a;https://www.winrar.com.cn/ 2. 安装 双击&#xff0c;使用默认路径&#xff1a; 点击“安装”。 点击“确定”。 点击“完成”。 3. 注册 链接&#x…

WinRAR注册+去广告教程

1、注册 在WinRAR安装目录创建rarreg.key文件&#xff0c; 拷贝如下内容并保存&#xff1a; RAR registration data Federal Agency for Education 1000000 PC usage license UIDb621cca9a84bc5deffbf 6412612250ffbf533df6db2dfe8ccc3aae5362c06d54762105357d 5e3b1489e751c…

WinRAR4.20注册文件rarreg.key

2019独角兽企业重金招聘Python工程师标准>>> 在WinRAR的安装目录下&#xff0c;新建rarreg.key文件&#xff08;注意不要创建成rarreg.key.txt文件了^_^&#xff09;&#xff0c;内容为如下&#xff1a; RAR registration data Team EAT Single PC usage license UI…

Android按钮样式

//创建一个新的XML文件&#xff0c;可命名为styles<style name"button1"><item name"android:layout_height">wrap_content</item><item name"android:textColor">#FFFFFF</item><item name"android:text…

漂亮的Button按钮样式

开发中各种样式的Button,其实这些样式所有的View都可以共用的,可能对于你改变的只有颜色 所有的都是用代码实现 边框样式,给你的View加上边框 <Buttonandroid:layout_width="0dip"android:layout_height="match_parent"android:layout_margin=&q…

「HTML+CSS」--自定义按钮样式【001】

前言 Hello&#xff01;小伙伴&#xff01; 首先非常感谢您阅读海轰的文章&#xff0c;倘若文中有错误的地方&#xff0c;欢迎您指出&#xff5e; 哈哈 自我介绍一下 昵称&#xff1a;海轰 标签&#xff1a;程序猿一只&#xff5c;C选手&#xff5c;学生 简介&#xff1a;因C语…

HTML_炫酷的按钮样式

html部分 <a href"#"><span></span><span></span><span></span><span></span>Neon button</a><a href"#"><span></span><span></span><span></span…

html改变按钮样式

今天有人问我怎么改样式&#xff0c;需求是三个按钮&#xff0c;一次点一个&#xff0c;要求被点击的按钮和没被点的按钮是两种不同的样式&#xff0c;如图所示。 最初三个按钮都没选如图一&#xff0c;然后点击“已读”按钮&#xff0c;“已读”按钮样式改变。再点击“全部”按…