码迷,mamicode.com
首页 > Web开发 > 详细

http 登录Digest认证相关知识

时间:2016-11-28 00:00:44      阅读:666      评论:0      收藏:0      [点我收藏+]

标签:html   asi   whether   symlink   identity   username   content   employee   信息   

Digest access authentication

https://en.wikipedia.org/wiki/Digest_access_authentication

Digest access authentication is one of the agreed-upon methods a web server can use to negotiate credentials, such as username or password, with a user‘s web browser. This can be used to confirm the identity of a user before sending sensitive information, such as online banking transaction history. It applies a hash function to the username and password before sending them over the network. In contrast, basic access authentication uses the easily reversible Base64 encoding instead of encryption, making it non-secure unless used in conjunction with SSL.

Technically, digest authentication is an application of MD5 cryptographic hashing with usage of nonce values to prevent replay attacks. It uses the HTTP protocol.

Authentication

https://en.wikipedia.org/wiki/Authentication

Authentication (from Greek: α?θεντικ?ς authentikos, "real, genuine", from α?θ?ντης authentes, "author") is the act of confirming the truth of an attribute of a single piece of data (a datum) claimed true by an entity. In contrast with identification which refers to the act of stating or otherwise indicating a claim purportedly attesting to a person or thing‘s identity, authentication is the process of actually confirming that identity. It might involve confirming the identity of a person by validating their identity documents, verifying the authenticity of a website with a digital certificate,[1] determining the age of an artifact by carbon dating, or ensuring that a product is what its packaging and labeling claim to be. In other words, authentication often involves verifying the validity of at least one form of identification.

认证就是确定身份的过程。

Identification (psychology)

https://en.wikipedia.org/wiki/Identification_%28psychology%29

Identification is a psychological process whereby the subject assimilates an aspect, property, or attribute of the other and is transformed, wholly or partially, by the model the other provides. It is by means of a series of identifications that the personality is constituted and specified. The roots of the concept can be found in Freud‘s writings. The three most prominent concepts of identification as described by Freud are: primary identification, narcissistic (secondary) identification and partial (secondary) identification.[1]

While "in the psychoanalytic literature there is agreement that the core meaning of identification is simple - to be like or to become like another", it has also been adjudged ‘"the most perplexing clinical/theoretical area" in psychoanalysis‘.[2]

Authorization

https://en.wikipedia.org/wiki/Authorization

Authorization‘ is the function of specifying access rights to resources related to information security and computer security in general and to access control in particular. More formally, "to authorize" is to define an access policy. For example, human resources staff is normally authorized to access employee records and this policy is usually formalized as access control rules in a computer system. During operation, the system uses the access control rules to decide whether access requests from (authenticated) consumers shall be approved (granted) or disapproved (rejected). Resources include individual files or an item‘s data, computer programs, computer devices and functionality provided by computer applications. Examples of consumers are computer users, computer Softwares and other Hardware on the computer.

授权是在认证之前, 将资源分配给不同的用户角色。

 

digest报文详解

http://blog.csdn.net/andrewpj/article/details/45727853

    • 服务器核实用户身份

      server收到client的HTTP request(INVITE),如果server需要客户端摘要认证,就需要生成一个摘要盘问(digest challenge),通过Response给client一个401 Unauthorized状态发送给用户。

      摘要盘问如 图二 中的WWW-Authenticate header所示:

      技术分享

      摘要盘问中的各个参数意义如下:

    • realm(领域):必须的,在所有的盘问中都必须有。它是目的是鉴别SIP消息中的机密。在实际应用中,它通常设置为server所负责的域名。

    • nonce (现时):必须的,这是由服务器规定的数据字符串,在服务器每次产生一个摘要盘问时,这个参数都是不一样的(与前面所产生的不会雷同)。nonce 通常是由一些数据通过md5杂凑运算构造的。这样的数据通常包括时间标识和服务器的机密短语。确保每个nonce 都有一个有限的生命期(也就是过了一些时间后会失效,并且以后再也不会使用),而且是独一无二的(即任何其它的服务器都不能产生一个相同的nonce )。

    • Stale:不必须,一个标志,用来指示客户端先前的请求因其nonce值过期而被拒绝。如果stale是TRUE(大小写敏感),客户端可能希望用新的加密回应重新进行请求,而不用麻烦用户提供新的用户名和口令。服务器端只有在收到的请求nonce值不合法,而该nonce对应的摘要(digest)是合法的情况下(即客户端知道正确的用户名/口令),才能将stale置成TRUE值。如果stale是FALSE或其它非TRUE值,或者其stale域不存在,说明用户名、口令非法,要求输入新的值。

    • opaque(不透明体):必须的,这是一个不透明的(不让外人知道其意义)数据字符串,在盘问中发送给用户。

    • algorithm(算法):不必须,这是用来计算杂凑的算法。当前只支持MD5算法。

    • qop(保护的质量):必须的,这个参数规定服务器支持哪种保护方案。客户端可以从列表中选择一个。值 “auth”表示只进行身份查验, “auth-int”表示进行查验外,还有一些完整性保护。需要看更详细的描述,请参阅RFC2617

      1. 客户端反馈用户身份

      client 生成 生成摘要响应(digest response),然后再次通过 http request (INVITE (Withink digest))发给 server。

      摘要响应如 图三 中的Authenticate header所示:

      技术分享

      摘要响应中的各个参数意义如下:

    • username: 不用再说明了
    • realm: 需要和 server 盘问的realm保持一致
    • nonce:客户端使用这个“现时”来产生摘要响应(digest response),需要和server 盘问中携带的nonce保持一致,这样服务器也会在一个摘要响应中收到“现时”的内容。服务器先要检查了“现时”的有效性后,才会检查摘要响应的其它部分。

      因而,nonce 在本质上是一种标识符,确保收到的摘要机密,是从某个特定的摘要盘问产生的。还限制了摘要盘问的生命期,防止未来的重播攻击。

    • qop:客户端选择的保护方式。

    • nc (现时计数器):这是一个16进制的数值,即客户端发送出请求的数量(包括当前这个请求),这些请求都使用了当前请求中这个“现时”值。例如,对一个给定的“现时”值,在响应的第一个请求中,客户端将发送“nc=00000001”。这个指示值的目的,是让服务器保持这个计数器的一个副本,以便检测重复的请求。如果这个相同的值看到了两次,则这个请求是重复的。

    • response:这是由用户代理软件计算出的一个字符串,以证明用户知道口令。比如可以通过 username、password、http method、uri、以及nonce、qop等使用MD5加密生成。

    • cnonce:这也是一个不透明的字符串值,由客户端提供,并且客户端和服务器都会使用,以避免用明文文本。这使得双方都可以查验对方的身份,并对消息的完整性提供一些保护。

    • uri:这个参数包含了客户端想要访问的URI。

      1. server 确认用户
        确认用户主要由两部分构成:
    • 检查nonce的有效性
    • 检查摘要响应中的其他信息, 比如server可以按照和客户端同样的算法生成一个response值,和client传递的response进行对比。

 

http://www.cnblogs.com/jcli/archive/2012/12/11/2812459.html

 

Digest的流程和上面一样,只是challenge和digest的生成算法不同

  1. 在浏览器请求:http://localhost:8080/index.html
  2. 服务器返回401(unauthentication)代码,并附带一个包含challenge的头,格式如下:WWW-Authenticate    Digest realm="Admin All", qop="auth", nonce="1354760194666:4465c7b1921b6d769fd359e5152c453f", opaque="EE9C283E89AFB63E7FF6E2C04C524807"
  3. 浏 览器用MD5编码后的信息添加到请求头中再次请求1中的资源,如果用户名是tomcat,密码是tomcat,则生成的头信息:Authorization    Digest username="tomcat", realm="Admin All", nonce="1354760194666:4465c7b1921b6d769fd359e5152c453f", uri="/web/index.html", response="8d30e6438636fe21c6045246dd034372", opaque="EE9C283E89AFB63E7FF6E2C04C524807", qop=auth, nc=00000001, cnonce="9201a828891792b9"
  4. 用3中计算的请求头信息再次请求1中的资源
  5. 服务器用3中相同的算法(base64)验证用户密码合法性
  6. 返回index.html的资源

 

 

linux安装apache httpd 配置digest

http://www.cnblogs.com/rainisic/archive/2012/05/23/Linux_Apache2_4_Install.html

Linux下安装Apache 2.4

 

http://blog.jobbole.com/41519/

Step 1: 创建密码文件

语法:

-c = create file

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

设置文件所有权和权限(root可以进行读写, Apache Group只可以读取)

user.txt格式: LengWa:Digest Encrypt:d95ea4412b0fb517b25c4c46f32e5a2b

Step2: 配置httpd.conf

现在基于Digest的验证环境就搭建好了.

注: 在Basic验证中. 我使用了.htaccess 而在Digest验证中我没有使用. 只是为了个人的需要. 你可以根据自己需要进行配置.

http://liwei521930.blog.163.com/blog/static/515217082010112462152253/

有一些so库依赖, 配置httpd.conf

 

digest认证需要依赖cookie识别客户端

http://itangqi.me/2016/04/07/the-notes-of-learning-illustrating-http-three/

基于表单认证需要依赖cookie在客户端识别用户, 入下图:

技术分享

 

 依赖cookie识别客户端是限制,  是否digest认证可以避免这种限制呢?

分析digest认证, 其中 nonce貌似可以用作session id, 如下图中的nonce。

技术分享

 

 原理上是可行的, 但是经过抓包分析, nonce值在未登录前, 每次访问URL,响应的nonce值都是变化的,如果将nonce作为session id, 则未登录时候, 设置攻击访问场景, 则会建立很多会话,导致后台的灰化很容易满了。

cookie sid作为会话ID:

1、 将鉴权和会话分离,职责分明。 鉴权方式 digest form basic, 仅仅负责鉴权。 会话还是由cookie sid管理。

2、 利用cookie识别用户, 不会产生上述描述, 会话被未访问报文攻击, 导致很快就满的情况。

 

第一次nonce:

技术分享

 

 

 第二次nonce:

技术分享

 

 

实验截图

 

技术分享

 

 

 第一次访问资源:

技术分享

 

 第二次访问资源, nonce一样, 但是授权信息 response不一样:

技术分享

 

http 登录Digest认证相关知识

标签:html   asi   whether   symlink   identity   username   content   employee   信息   

原文地址:http://www.cnblogs.com/lightsong/p/6107244.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!