digest鉴权

2023-05-16

“摘要”式认证( Digest authentication)是一个简单的认证机制,最初是为HTTP协议开发的,因而也常叫做HTTP摘要,在RFC2671中描述。其身份验证机制很简单,它采用杂凑式(hash)加密方法,以避免用明文传输用户的口令。
摘要认证就是要核实,参与通信的双方,都知道双方共享的一个秘密(即口令)。

当服务器想要查证用户的身份,它产生一个摘要盘问(digest challenge),并发送给用户。典型的摘要盘问如下:

Digest realm="iptel.org", qop="auth,auth-int",
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="", algorithm=MD5

这里包括了一组参数,也要发送给用户。用户使用这些参数,来产生正确的摘要回答,并发送给服务器。摘要盘问中的各个参数,其意义如下:

realm(领域):领域参数是强制的,在所有的盘问中都必须有。它是目的是鉴别SIP消息中的机密。在SIP实际应用中,它通常设置为SIP代理服务器所负责的域名。

在要求用户输入用户名和口令时,SIP用户代理则会显示这个参数的内容给用户,以便用户使用正确的用户名和口令(这个服务器的)。

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

客户端使用这个“现时”来产生摘要响应(digest response),这样服务器也会在一个摘要响应中收到“现时”的内容。服务器先要检查了“现时”的有效性后,才会检查摘要响应的其它部分。

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


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

在摘要响应中,用户会将这个数据字符串发送回给服务器。这使得服务器可以是无状态的。如果需要在盘问和响应之间维护一些状态,可以用这个参数传送状态给客户端,此后当摘要响应回来时,再读这个状态。

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

qop(保护的质量)。这个参数规定服务器支持哪种保护方案。客户端可以从列表中选择一个。值

“auth”表示只进行身份查验, “auth-int”表示进行查验外,还有一些完整性保护。需要看更详细的描述,请参阅RFC2617。

在收到了摘要盘问后,如果没有预先配置,用户代理软件通常会提示用户输入用户名和口令,产生一个摘要响应,并将这个响应发送给服务器。例如,摘要响应可能如下:

Digest username="jan", realm="iptel.org",
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", uri="sip:iptel.org",
qop=auth, nc=00000001, cnonce="0a4f113b",
response="6629fae49393a05397450978507c4ef1", opaque=""

摘要响应类似于摘要盘问。相同的参数,则与摘要盘问有相同的意义。这里只描述新的参数:

uri(统一资源指示符):这个参数包含了客户端想要访问的URI。
qop:客户端选择的保护方式。
nc:“现时”计数器,这是一个16进制的数值,即客户端发送出请求的数量(包括当前这个请求),这

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

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

response(响应):这是由用户代理软件计算出的一个字符串,以证明用户知道口令。

当服务器接收到摘要响应,也要重新计算响应中各参数的值,并利用客户端提供的参数值,和服务器上存储的口令,进行比对。如果计算结果与收到的客户响应值是相同的,则客户已证明它知道口令,因而客户的身份验证通过。


Digest access authentication



From Wikipedia, the free encyclopedia




Digest access authentication is one of the agreed-upon methods a web server can use to negotiate credentials with a user's web browser. It applies a hash function to a password before sending it over the network, which is safer than basic access authentication, which sends plaintext.


Technically, digest authentication is an application of MD5 cryptographic hashing with usage of nonce values to discourage cryptanalysis. It uses the HTTPprotocol.










Contents


   [hide] 


  • 1 Overview
  • 2 Impact of MD5 security on digest authentication
  • 3 HTTP digest authentication considerations

    • 3.1 Advantages
    • 3.2 Disadvantages
    • 3.3 Alternative authentication protocols


  • 4 Example with explanation
  • 5 SIP digest authentication
  • 6 Browser implementation
  • 7 See also
  • 8 References
  • 9 External links

Overview


Digest access authentication was originally specified by RFC 2069 (An Extension to HTTP: Digest Access Authentication). RFC 2069 specifies roughly a traditional digest authentication scheme with security maintained by a server-generated nonce value. The authentication response is formed as follows (where HA1, HA2, A1, A2 are names of string variables):


\mathrm{HA1} = \mathrm{MD5}\Big(\mathrm{A1}\Big) = \mathrm{MD5}\Big( \mathrm{username} : \mathrm{realm} : \mathrm{password} \Big)
\mathrm{HA2} = \mathrm{MD5}\Big(\mathrm{A2}\Big) = \mathrm{MD5}\Big( \mathrm{method} : \mathrm{digestURI} \Big)
\mathrm{response} = \mathrm{MD5}\Big( \mathrm{HA1} : \mathrm{nonce} : \mathrm{HA2} \Big)

RFC 2069 was later replaced by RFC 2617 (HTTP Authentication: Basic and Digest Access Authentication). RFC 2617 introduced a number of optional security enhancements to digest authentication; "quality of protection" (qop), nonce counter incremented by client, and a client-generated random nonce. These enhancements are designed to protect against, for example,chosen-plaintext attack cryptanalysis.


\mathrm{HA1} = \mathrm{MD5}\Big(\mathrm{A1}\Big) = \mathrm{MD5}\Big( \mathrm{username} : \mathrm{realm} : \mathrm{password} \Big)

If the qop directive's value is "auth" or is unspecified, then HA2 is


\mathrm{HA2} = \mathrm{MD5}\Big(\mathrm{A2}\Big) = \mathrm{MD5}\Big( \mathrm{method} : \mathrm{digestURI} \Big)

If the qop directive's value is "auth-int", then HA2 is


\mathrm{HA2} = \mathrm{MD5}\Big(\mathrm{A2}\Big) = \mathrm{MD5}\Big( \mathrm{method} : \mathrm{digestURI} : \mathrm {MD5}(entityBody)\Big)

If the qop directive's value is "auth" or "auth-int", then compute the response as follows:


\mathrm{response} = \mathrm{MD5}\Big( \mathrm{HA1} : \mathrm{nonce} : \mathrm{nonceCount} : \mathrm{clientNonce} : \mathrm{qop} : \mathrm{HA2} \Big)

If the qop directive is unspecified, then compute the response as follows:


\mathrm{response} = \mathrm{MD5}\Big( \mathrm{HA1} : \mathrm{nonce} : \mathrm{HA2} \Big)

The above shows that when qop is not specified, the simpler RFC 2069 standard is followed.


[edit]Impact of MD5 security on digest authentication


The MD5 calculations used in HTTP digest authentication is intended to be "one way", meaning that it should be difficult to determine the original input when only the output is known. If the password itself is too simple, however, then it may be possible to test all possible inputs and find a matching output (a brute-force attack) – perhaps aided by a dictionary or suitable look-up list.


The HTTP scheme was designed by Phillip Hallam-Baker at CERN in 1993 and does not incorporate subsequent improvements in authentication systems, such as the development of keyed-hash message authentication code (HMAC). Although the cryptographic construction that is used is based on the MD5 hash function, collision attacks were in 2004 generally believed to not affect applications where the plaintext (i.e. password) is not known.[1][citation needed] However, claims in 2006 (Kim, Biryukov2, Preneel, Hong, "On the Security of HMAC and NMAC Based on HAVAL MD4 MD5 SHA-0 and SHA-1") cause some doubt over other MD5 applications as well. So far, however, MD5 collision attacks have not been shown to pose a threat to digest authentication, and the RFC 2617 allows servers to implement mechanisms to detect some collision and replay attacks.


[edit]HTTP digest authentication considerations


[edit]Advantages


HTTP digest authentication is designed to be more secure than traditional digest authentication schemes; e.g., "significantly stronger than (e.g.) CRAM-MD5 ..." (RFC2617).


Some of the security strengths of HTTP digest authentication are:



  • The password is not used directly in the digest, but rather HA1 = MD5(username:realm:password). This allows some implementations (e.g. JBoss DIGESTAuth) to store HA1 rather than thecleartext password.
  • Client nonce was introduced in RFC 2617, which allows the client to prevent Chosen-plaintext attacks (which otherwise makes e.g. rainbow tables a threat to digest authentication schemes).
  • Server nonce is allowed to contain timestamps. Therefore the server may inspect nonce attributes submitted by clients, to prevent replay attacks.
  • Server is also allowed to maintain a list of recently issued or used server nonce values to prevent reuse.

[edit]Disadvantages


Digest access authentication is intended as a security trade-off. It is intended to replace unencrypted HTTP basic access authentication. It is not, however, intended to replace strong authentication protocols, such as public-key or Kerberos authentication.


In terms of security, there are several drawbacks with digest access authentication:



  • Many of the security options in RFC 2617 are optional. If quality-of-protection (qop) is not specified by the server, the client will operate in a security-reduced legacy RFC 2069 mode.
  • Digest access authentication is vulnerable to a man-in-the-middle (MitM) attack. For example, a MitM attacker could tell clients to use basic access authentication or legacy RFC2069 digest access authentication mode. To extend this further, digest access authentication provides no mechanism for clients to verify the server's identity.
  • Some servers require passwords to be stored using reversible encryption. However, it is possible to instead store the digested value of the username, realm, and password.[2]
  • It prevents the use of a strong password hash (such as bcrypt) when storing passwords (since either the password, or the digested username, realm and password must be recoverable).

[edit]Alternative authentication protocols


Some strong authentication protocols for web-based applications include:



  • Public key authentication (usually implemented with HTTPS / SSL client certificates).
  • Kerberos or SPNEGO authentication, primarily employed by Microsoft IIS running configured for Integrated Windows Authentication (IWA).
  • Secure Remote Password protocol (preferably within the HTTPS / TLS layer).

Weak cleartext protocols are also often in use:



  • Basic access authentication scheme
  • HTTP+HTML form-based authentication

These weak cleartext protocols used together with HTTPS network encryption resolve many of the threats that digest access authentication is designed to prevent.


[edit]Example with explanation


The following example was originally given in RFC 2617 and is expanded here to show the full text expected for each request and response. Note that only the "auth" (authentication) quality of protection code is covered – at the time of writing, only the Opera and Konqueror web browsers are known to support "auth-int" (authentication with integrity protection). Although the specification mentions HTTP version 1.1, the scheme can be successfully added to a version 1.0 server, as shown here.


This typical transaction consists of the following steps.



  • The client asks for a page that requires authentication but does not provide a username and password. Typically this is because the user simply entered the address or followed a link to the page.
  • The server responds with the 401 "Unauthorized" response code, providing the authentication realm and a randomly-generated, single-use value called a nonce.
  • At this point, the browser will present the authentication realm (typically a description of the computer or system being accessed) to the user and prompt for a username and password. The user may decide to cancel at this point.
  • Once a username and password have been supplied, the client re-sends the same request but adds an authentication header that includes the response code.
  • In this example, the server accepts the authentication and the page is returned. If the username is invalid and/or the password is incorrect, the server might return the "401" response code and the client would prompt the user again.

Note: A client may already have the required username and password without needing to prompt the user, e.g. if they have previously been stored by a web browser.



Client request (no authentication)

GET /dir/index.html HTTP/1.0
Host: localhost

(followed by a new line, in the form of a carriage return followed by a line feed).[citation needed]


Server response

HTTP/1.0 401 Unauthorized
Server: HTTPd/0.9
Date: Sun, 10 Apr 2005 20:26:47 GMT
WWW-Authenticate: Digest realm="testrealm@host.com",
qop="auth,auth-int",
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
opaque="5ccc069c403ebaf9f0171e9517f40e41"
Content-Type: text/html
Content-Length: 311

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
" http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd ">
<HTML>
<HEAD>
<TITLE>Error</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
</HEAD>
<BODY><H1>401 Unauthorized.</H1></BODY>
</HTML>

Client request (username "Mufasa", password "Circle Of Life")

GET /dir/index.html HTTP/1.0
Host: localhost
Authorization: Digest username="Mufasa",
realm="testrealm@host.com",
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
uri="/dir/index.html",
qop=auth,
nc=00000001,
cnonce="0a4f113b",
response="6629fae49393a05397450978507c4ef1",
opaque="5ccc069c403ebaf9f0171e9517f40e41"

(followed by a blank line, as before).


Server response

HTTP/1.0 200 OK
Server: HTTPd/0.9
Date: Sun, 10 Apr 2005 20:27:03 GMT
Content-Type: text/html
Content-Length: 7984

(followed by a blank line and HTML text of the restricted page).




The "response" value is calculated in three steps, as follows. Where values are combined, they are delimited by colon symbols.



  1. The MD5 hash of the combined username, authentication realm and password is calculated. The result is referred to as HA1.
  2. The MD5 hash of the combined method and digest URI is calculated, e.g. of "GET" and "/dir/index.html". The result is referred to as HA2.
  3. The MD5 hash of the combined HA1 result, server nonce (nonce), request counter (nc), client nonce (cnonce), quality of protection code (qop) and HA2 result is calculated. The result is the "response" value provided by the client.

Since the server has the same information as the client, the response can be checked by performing the same calculation. In the example given above the result is formed as follows, whereMD5() represents a function used to calculate an MD5 hash, backslashes represent a continuation and the quotes shown are not used in the calculation.


Completing the example given in RFC 2617 gives the following results for each step.


HA1 = MD5( "Mufasa:testrealm@host.com:Circle Of Life" )
= 939e7578ed9e3c518a452acee763bce9

HA2 = MD5( "GET:/dir/index.html" )
= 39aff3a2bab6126f332b942af96d3366

Response = MD5( "939e7578ed9e3c518a452acee763bce9:\
dcd98b7102dd2f0e8b11d0f600bfb0c093:\
00000001:0a4f113b:auth:\
39aff3a2bab6126f332b942af96d3366" )
= 6629fae49393a05397450978507c4ef1

At this point the client may make another request, reusing the server nonce value (the server only issues a new nonce for each "401" response) but providing a new client nonce (cnonce). For subsequent requests, the hexadecimal request counter (nc) must be greater than the last value it used – otherwise an attacker could simply "replay" an old request with the same credentials. It is up to the server to ensure that the counter increases for each of the nonce values that it has issued, rejecting any bad requests appropriately. Obviously changing the method, URI and/or counter value will result in a different response value.


The server should remember nonce values that it has recently generated. It may also remember when each nonce value was issued, expiring them after a certain amount of time. If an expired value is used, the server should respond with the "401" status code and add stale=TRUE to the authentication header, indicating that the client should re-send with the new nonce provided, without prompting the user for another username and password.


The server does not need to keep any expired nonce values – it can simply assume that any unrecognised values have expired. It is also possible for the server to only allow each nonce value to be returned once, although this forces the client to repeat every request. Note that expiring a server nonce immediately will not work, as the client would never get a chance to use it.


[edit]SIP digest authentication


SIP uses basically the same digest authentication algorithm. It is specified by RFC 3261.


[edit]Browser implementation


Most browsers have substantially implemented the spec, some barring certain features such as auth-int checking or the MD5-sess algorithm. If the server requires that these optional features be handled, clients may not be able to authenticate (though note mod_auth_digest for Apache does not fully implement RFC 2617 either).



  • Amaya
  • Gecko-based: (not including auth-int: [1])

    • Mozilla Application Suite
    • Mozilla Firefox
    • Netscape 7+


  • iCab 3.0.3+
  • KHTML- and WebKit-based: (not including auth-int [2])

    • iCab 4
    • Konqueror
    • Google Chrome
    • Safari


  • Tasman-based:

    • Internet Explorer for Mac


  • Trident-based:

    • Internet Explorer 7+ [3] (not including auth-int)


  • Presto-based:

    • Opera
    • Opera Mobile
    • Opera Mini
    • Nintendo DS Browser
    • Nokia 770 Browser
    • Sony Mylo 1's Browser
    • Wii Internet Channel Browser


Digest access authentication is one of the agreed-upon methods a web server can use to negotiate credentials with a user's web browser. It applies a hash function to a password before sending it over the network, which is safer than basic access authentication, which sends plaintext.


Technically, digest authentication is an application of MD5 cryptographic hashing with usage of nonce values to discourage cryptanalysis. It uses the HTTPprotocol.










Contents


   [hide] 


  • 1 Overview
  • 2 Impact of MD5 security on digest authentication
  • 3 HTTP digest authentication considerations

    • 3.1 Advantages
    • 3.2 Disadvantages
    • 3.3 Alternative authentication protocols


  • 4 Example with explanation
  • 5 SIP digest authentication
  • 6 Browser implementation
  • 7 See also
  • 8 References
  • 9 External links

Overview


Digest access authentication was originally specified by RFC 2069 (An Extension to HTTP: Digest Access Authentication). RFC 2069 specifies roughly a traditional digest authentication scheme with security maintained by a server-generated nonce value. The authentication response is formed as follows (where HA1, HA2, A1, A2 are names of string variables):


\mathrm{HA1} = \mathrm{MD5}\Big(\mathrm{A1}\Big) = \mathrm{MD5}\Big( \mathrm{username} : \mathrm{realm} : \mathrm{password} \Big)
\mathrm{HA2} = \mathrm{MD5}\Big(\mathrm{A2}\Big) = \mathrm{MD5}\Big( \mathrm{method} : \mathrm{digestURI} \Big)
\mathrm{response} = \mathrm{MD5}\Big( \mathrm{HA1} : \mathrm{nonce} : \mathrm{HA2} \Big)

RFC 2069 was later replaced by RFC 2617 (HTTP Authentication: Basic and Digest Access Authentication). RFC 2617 introduced a number of optional security enhancements to digest authentication; "quality of protection" (qop), nonce counter incremented by client, and a client-generated random nonce. These enhancements are designed to protect against, for example,chosen-plaintext attack cryptanalysis.


\mathrm{HA1} = \mathrm{MD5}\Big(\mathrm{A1}\Big) = \mathrm{MD5}\Big( \mathrm{username} : \mathrm{realm} : \mathrm{password} \Big)

If the qop directive's value is "auth" or is unspecified, then HA2 is


\mathrm{HA2} = \mathrm{MD5}\Big(\mathrm{A2}\Big) = \mathrm{MD5}\Big( \mathrm{method} : \mathrm{digestURI} \Big)

If the qop directive's value is "auth-int", then HA2 is


\mathrm{HA2} = \mathrm{MD5}\Big(\mathrm{A2}\Big) = \mathrm{MD5}\Big( \mathrm{method} : \mathrm{digestURI} : \mathrm {MD5}(entityBody)\Big)

If the qop directive's value is "auth" or "auth-int", then compute the response as follows:


\mathrm{response} = \mathrm{MD5}\Big( \mathrm{HA1} : \mathrm{nonce} : \mathrm{nonceCount} : \mathrm{clientNonce} : \mathrm{qop} : \mathrm{HA2} \Big)

If the qop directive is unspecified, then compute the response as follows:


\mathrm{response} = \mathrm{MD5}\Big( \mathrm{HA1} : \mathrm{nonce} : \mathrm{HA2} \Big)

The above shows that when qop is not specified, the simpler RFC 2069 standard is followed.


[edit]Impact of MD5 security on digest authentication


The MD5 calculations used in HTTP digest authentication is intended to be "one way", meaning that it should be difficult to determine the original input when only the output is known. If the password itself is too simple, however, then it may be possible to test all possible inputs and find a matching output (a brute-force attack) – perhaps aided by a dictionary or suitable look-up list.


The HTTP scheme was designed by Phillip Hallam-Baker at CERN in 1993 and does not incorporate subsequent improvements in authentication systems, such as the development of keyed-hash message authentication code (HMAC). Although the cryptographic construction that is used is based on the MD5 hash function, collision attacks were in 2004 generally believed to not affect applications where the plaintext (i.e. password) is not known.[1][citation needed] However, claims in 2006 (Kim, Biryukov2, Preneel, Hong, "On the Security of HMAC and NMAC Based on HAVAL MD4 MD5 SHA-0 and SHA-1") cause some doubt over other MD5 applications as well. So far, however, MD5 collision attacks have not been shown to pose a threat to digest authentication, and the RFC 2617 allows servers to implement mechanisms to detect some collision and replay attacks.


[edit]HTTP digest authentication considerations


[edit]Advantages


HTTP digest authentication is designed to be more secure than traditional digest authentication schemes; e.g., "significantly stronger than (e.g.) CRAM-MD5 ..." (RFC2617).


Some of the security strengths of HTTP digest authentication are:



  • The password is not used directly in the digest, but rather HA1 = MD5(username:realm:password). This allows some implementations (e.g. JBoss DIGESTAuth) to store HA1 rather than thecleartext password.
  • Client nonce was introduced in RFC 2617, which allows the client to prevent Chosen-plaintext attacks (which otherwise makes e.g. rainbow tables a threat to digest authentication schemes).
  • Server nonce is allowed to contain timestamps. Therefore the server may inspect nonce attributes submitted by clients, to prevent replay attacks.
  • Server is also allowed to maintain a list of recently issued or used server nonce values to prevent reuse.

[edit]Disadvantages


Digest access authentication is intended as a security trade-off. It is intended to replace unencrypted HTTP basic access authentication. It is not, however, intended to replace strong authentication protocols, such as public-key or Kerberos authentication.


In terms of security, there are several drawbacks with digest access authentication:



  • Many of the security options in RFC 2617 are optional. If quality-of-protection (qop) is not specified by the server, the client will operate in a security-reduced legacy RFC 2069 mode.
  • Digest access authentication is vulnerable to a man-in-the-middle (MitM) attack. For example, a MitM attacker could tell clients to use basic access authentication or legacy RFC2069 digest access authentication mode. To extend this further, digest access authentication provides no mechanism for clients to verify the server's identity.
  • Some servers require passwords to be stored using reversible encryption. However, it is possible to instead store the digested value of the username, realm, and password.[2]
  • It prevents the use of a strong password hash (such as bcrypt) when storing passwords (since either the password, or the digested username, realm and password must be recoverable).

[edit]Alternative authentication protocols


Some strong authentication protocols for web-based applications include:



  • Public key authentication (usually implemented with HTTPS / SSL client certificates).
  • Kerberos or SPNEGO authentication, primarily employed by Microsoft IIS running configured for Integrated Windows Authentication (IWA).
  • Secure Remote Password protocol (preferably within the HTTPS / TLS layer).

Weak cleartext protocols are also often in use:



  • Basic access authentication scheme
  • HTTP+HTML form-based authentication

These weak cleartext protocols used together with HTTPS network encryption resolve many of the threats that digest access authentication is designed to prevent.


[edit]Example with explanation


The following example was originally given in RFC 2617 and is expanded here to show the full text expected for each request and response. Note that only the "auth" (authentication) quality of protection code is covered – at the time of writing, only the Opera and Konqueror web browsers are known to support "auth-int" (authentication with integrity protection). Although the specification mentions HTTP version 1.1, the scheme can be successfully added to a version 1.0 server, as shown here.


This typical transaction consists of the following steps.



  • The client asks for a page that requires authentication but does not provide a username and password. Typically this is because the user simply entered the address or followed a link to the page.
  • The server responds with the 401 "Unauthorized" response code, providing the authentication realm and a randomly-generated, single-use value called a nonce.
  • At this point, the browser will present the authentication realm (typically a description of the computer or system being accessed) to the user and prompt for a username and password. The user may decide to cancel at this point.
  • Once a username and password have been supplied, the client re-sends the same request but adds an authentication header that includes the response code.
  • In this example, the server accepts the authentication and the page is returned. If the username is invalid and/or the password is incorrect, the server might return the "401" response code and the client would prompt the user again.

Note: A client may already have the required username and password without needing to prompt the user, e.g. if they have previously been stored by a web browser.



Client request (no authentication)

GET /dir/index.html HTTP/1.0
Host: localhost

(followed by a new line, in the form of a carriage return followed by a line feed).[citation needed]


Server response

HTTP/1.0 401 Unauthorized
Server: HTTPd/0.9
Date: Sun, 10 Apr 2005 20:26:47 GMT
WWW-Authenticate: Digest realm="testrealm@host.com",
qop="auth,auth-int",
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
opaque="5ccc069c403ebaf9f0171e9517f40e41"
Content-Type: text/html
Content-Length: 311

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
" http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd ">
<HTML>
<HEAD>
<TITLE>Error</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
</HEAD>
<BODY><H1>401 Unauthorized.</H1></BODY>
</HTML>

Client request (username "Mufasa", password "Circle Of Life")

GET /dir/index.html HTTP/1.0
Host: localhost
Authorization: Digest username="Mufasa",
realm="testrealm@host.com",
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
uri="/dir/index.html",
qop=auth,
nc=00000001,
cnonce="0a4f113b",
response="6629fae49393a05397450978507c4ef1",
opaque="5ccc069c403ebaf9f0171e9517f40e41"

(followed by a blank line, as before).


Server response

HTTP/1.0 200 OK
Server: HTTPd/0.9
Date: Sun, 10 Apr 2005 20:27:03 GMT
Content-Type: text/html
Content-Length: 7984

(followed by a blank line and HTML text of the restricted page).




The "response" value is calculated in three steps, as follows. Where values are combined, they are delimited by colon symbols.



  1. The MD5 hash of the combined username, authentication realm and password is calculated. The result is referred to as HA1.
  2. The MD5 hash of the combined method and digest URI is calculated, e.g. of "GET" and "/dir/index.html". The result is referred to as HA2.
  3. The MD5 hash of the combined HA1 result, server nonce (nonce), request counter (nc), client nonce (cnonce), quality of protection code (qop) and HA2 result is calculated. The result is the "response" value provided by the client.

Since the server has the same information as the client, the response can be checked by performing the same calculation. In the example given above the result is formed as follows, whereMD5() represents a function used to calculate an MD5 hash, backslashes represent a continuation and the quotes shown are not used in the calculation.


Completing the example given in RFC 2617 gives the following results for each step.


HA1 = MD5( "Mufasa:testrealm@host.com:Circle Of Life" )
= 939e7578ed9e3c518a452acee763bce9

HA2 = MD5( "GET:/dir/index.html" )
= 39aff3a2bab6126f332b942af96d3366

Response = MD5( "939e7578ed9e3c518a452acee763bce9:\
dcd98b7102dd2f0e8b11d0f600bfb0c093:\
00000001:0a4f113b:auth:\
39aff3a2bab6126f332b942af96d3366" )
= 6629fae49393a05397450978507c4ef1

At this point the client may make another request, reusing the server nonce value (the server only issues a new nonce for each "401" response) but providing a new client nonce (cnonce). For subsequent requests, the hexadecimal request counter (nc) must be greater than the last value it used – otherwise an attacker could simply "replay" an old request with the same credentials. It is up to the server to ensure that the counter increases for each of the nonce values that it has issued, rejecting any bad requests appropriately. Obviously changing the method, URI and/or counter value will result in a different response value.


The server should remember nonce values that it has recently generated. It may also remember when each nonce value was issued, expiring them after a certain amount of time. If an expired value is used, the server should respond with the "401" status code and add stale=TRUE to the authentication header, indicating that the client should re-send with the new nonce provided, without prompting the user for another username and password.


The server does not need to keep any expired nonce values – it can simply assume that any unrecognised values have expired. It is also possible for the server to only allow each nonce value to be returned once, although this forces the client to repeat every request. Note that expiring a server nonce immediately will not work, as the client would never get a chance to use it.


[edit]SIP digest authentication


SIP uses basically the same digest authentication algorithm. It is specified by RFC 3261.


[edit]Browser implementation


Most browsers have substantially implemented the spec, some barring certain features such as auth-int checking or the MD5-sess algorithm. If the server requires that these optional features be handled, clients may not be able to authenticate (though note mod_auth_digest for Apache does not fully implement RFC 2617 either).



  • Amaya
  • Gecko-based: (not including auth-int: [1])

    • Mozilla Application Suite
    • Mozilla Firefox
    • Netscape 7+


  • iCab 3.0.3+
  • KHTML- and WebKit-based: (not including auth-int [2])

    • iCab 4
    • Konqueror
    • Google Chrome
    • Safari


  • Tasman-based:

    • Internet Explorer for Mac


  • Trident-based:

    • Internet Explorer 7+ [3] (not including auth-int)


  • Presto-based:

    • Opera
    • Opera Mobile
    • Opera Mini
    • Nintendo DS Browser
    • Nokia 770 Browser
    • Sony Mylo 1's Browser
    • Wii Internet Channel Browser
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

digest鉴权 的相关文章

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

    核心步骤 xff1a 步骤 1 xff1a 请求需认证的资源时 xff0c 服务器会随着状态码 401Authorization Required xff0c 返回带WWW Authenticate 首部字段的响应 该字段内包含质问响应方式
  • Http Digest 认证

    其认证的基本框架为挑战认证的结构 xff0c 如下图所示 xff1a xfeff xfeff 1 客户端希望取到服务器上的某个资源 xff0c 向服务器发送Get请求 2 服务器收到客户端的请求后 xff0c 发现这个资源需要认证信息 xf
  • Http auth认证的两种方式Basic方式和 Digest认证

    Http Basic Auth 方式 当访问一个Http Basic Auth 网站的时候需要提供用户名 xff0c 密码 xff0c 否则会返回401 without authoration Http Basic Authenticati
  • http-digest的认证

    摘要认证 digest authentication HTTP1 1提出的基本认证的替代方法 服务器端以nonce进行质询 xff0c 客户端以用户名 xff0c 密码 xff0c nonce xff0c HTTP方法 xff0c 请求的U
  • java httpClient Digest Auth 认证

    技术交流QQ群 933925017 java httpClient Digest Auth 认证 因为项目需要 请求海康摄像头 进行抓图以及云台控制等功能 海康有http协议 但是需要进行请求头认证 因为海康给的资料已经过时 所以找了很久
  • 摘要认证及实现HTTP digest authentication

    最近工作需要做了摘要认证 xff08 digest authentication xff09 xff0c 下面就工作中遇到的问题及过程做一个总结 第一次客户端请求 GET POST 服务器产生一个随机数nonce xff0c 服务器将这个随
  • php getdigest,http digest

    HTTP digest 摘要访问认证是一种协议规定的Web服务器用来同网页浏览器进行认证信息协商的方法 它在密码发出前 xff0c 先对其应用哈希函数 xff0c 这相对于HTTP基本认证发送明文而言 xff0c 更安全 从技术上讲 xff
  • HTTP认证之摘要认证——Digest(二)

    导航 HTTP认证之基本认证 Basic xff08 一 xff09 HTTP认证之基本认证 Basic xff08 二 xff09 HTTP认证之摘要认证 Digest xff08 一 xff09 HTTP认证之摘要认证 Digest x
  • http digest

    HTTP digest 摘要访问认证是一种协议规定的Web服务器用来同网页浏览器进行认证信息协商的方法 它在密码发出前 xff0c 先对其应用哈希函数 xff0c 这相对于HTTP基本认证发送明文而言 xff0c 更安全 从技术上讲 xff
  • C++ libcurl Digest Auth

    C 43 43 libcurl Digest Auth postman操作如下 xff1a 附认证原理如下 xff1a MD5 md5 span class token punctuation span string HA1 span cl
  • Digest Auth 摘要认证

    Digest Auth 摘要认证 1 非常规方式 转载 xff1a https blog csdn net qq 25391785 article details 86595529 public static void postMethod
  • HTTP Digest authentication

    Digest authentication xff09 是一个简单的认证机制 xff0c 最初是为 HTTP 协议开发的 xff0c 因而也常叫做 HTTP 摘要 xff0c 在 RFC2671 中描述 其身份验证机制很简单 xff0c 它
  • AUTH:basic认证和digest认证

    Http authentication BASIC In the context of an HTTP transaction basic access authentication is a method for a web browse
  • PHP HTTP Digest校验

    PHP作为客户端进行HTTP Digest校验 span class token comment 请求方法 span span class token variable username span span class token oper
  • Http Digest认证协议

    其认证的基本框架为挑战认证的结构 xff0c 如下图所示 xff1a xfeff xfeff 1 客户端希望取到服务器上的某个资源 xff0c 向服务器发送Get请求 2 服务器收到客户端的请求后 xff0c 发现这个资源需要认证信息 xf
  • Digest来验证

    Apache默认使用basic模块验证 xff0c 但它只是明文验证 Digest验证 xff0c 是用md5摘要值进行对比 httpRequest getAuthType 方法 xff0c 可以得到网页的验证方式request BASIC
  • 我可以序列化 ruby​​ Digest::SHA1 实例对象吗?

    大家好 我正在 ruby sinatra 中重新实现现有的自定义文件上传服务 并使用 redis 作为后备存储 客户 计算 SHA1 哈希并启动上传 上传最多 64K 块直至完成 服务器 将块附加到文件 计算完整文件的 SHA1 哈希值以验
  • 如何使用 Node.JS 进行请求 HTTP 摘要身份验证?

    我必须使用 Node JS 为 API 文档编写一些代码 但我在过去几天尝试了在网络上找到的所有解决方案 当然包括 Stack 但没有成功 我的 API 使用 HTTP Digest Auth 这就是问题所在 我能够连接 这不是什么大问题
  • 如何使用 X509 证书签署 xml,将摘要值和签名添加到 xml 模板

    我对 C 很陌生 尤其是使用 X509 签名 我有一个 xml 模板 必须在其中添加使用的证书 完成 并签署时间戳 TS 1 二进制安全令牌和正文 id 1 此外 我需要用这 3 个元素的摘要值写入 例如替换占位符 并添加签名值 但是 我不
  • Tomcat Digest 与 Manager WebApp

    我正在尝试为 tomcat 管理器应用程序设置摘要密码 我有

随机推荐

  • Keil仿真调试Debug不能放断点_图解

    前提 xff1a 正常连接了调试器 43 开发板 xff0c 才能进入Debug模式 xff01 xff01 xff01 一 正常情况 当Keil进入Debug模式 xff0c 正常可以放置断点时的界面 xff0c 是下面这样的 xff1a
  • 无人机(2)_电机

    型号值 如2212 前两位 电机外径 后两位 转子高度KV值 电机空转 时 电压每提高1V 电机转速提高 800转 分钟无刷电机 电机分有刷和无刷 无人机都是无刷 电机 贵 力气大 耐用 电池节数 很重要 一节是4 2V电调大小 A越大越好
  • Linux下运用opencv的简单图像编程

    文章目录 Linux下运用opencv的简单图像编程一 编写一个打开图片进行特效显示的代码 一 用普通方式编译程序1 准备工作 xff1a 2 准备一张图片 xff0c 移到相同目录下3 编译程序4 运行程序 二 用make 43 make
  • 简单stm32程序编写以及调试

    简单stm32程序编写以及调试 一 环境配置 1 MDK的安装 MDK xff08 Microcontroller Development Kit xff09 是针对ARM处理器 xff0c 特别是Cortex M内核处理器的最佳开发工具
  • STM32以中断的方式点亮LED小灯(标准库)

    STM32以中断的方式点亮LED小灯 xff08 标准库 xff09 文章目录 STM32以中断的方式点亮LED小灯 xff08 标准库 xff09 一 认识中断1 中断优先级 xff1a 2 中断嵌套 xff1a 3 中断执行流程4 中断
  • STM32 I2C_OLED显示汉字及屏幕滚动

    STM32 I2C OLED显示汉字及屏幕滚动 文章目录 STM32 I2C OLED显示汉字及屏幕滚动一 I2C以及AHT20温湿度传感器介绍二 用0 96寸OLED屏幕显示数据1 OLED介绍2 样例测试 三 汉字编码原理编码排序A0A
  • # FPGA编程入门

    FPGA编程入门 文章目录 FPGA编程入门一 1位全加器1 原理图1 1原理图1 2 全加器 2 verilog实现1位全加器2 1 代码2 2 编译 xff0c 查看RTL2 3 仿真实现 二 烧录三 4位全加器1 原理图实现4位全加器
  • 基于NIOS-II软核与verilog语言的流水灯实现

    基于NIOS II软核与verilog语言的流水灯实现 文章目录 基于NIOS II软核与verilog语言的流水灯实现1 实验目的2 实验设备3 实验内容4 软核设计4 1 新建一个工程4 2 Qsys 系统设计4 3 进行逻辑连接4 3
  • 处理器的大小端及位序

    大端Big Endian xff1a 数据的高字节存储到低位地址中 小端little Endian xff1a 数据的低字节存储到低位地址中 举例说明 xff1a 32位16进制数据为 61 0x12345678 xff0c 大端存储 地址
  • # VGA协议实践

    VGA协议实践 文章目录 VGA协议实践1 VGA介绍2 ALTPLL3 字模与图像生成4 ROM5 代码5 1 vga驱动模块5 2 显示数据生成模块5 3 按键消抖模块5 4 顶层模块5 5 TCL绑定引脚代码 6 效果7 总结8 参考
  • 串口扩展芯片

    串口扩展芯片 WK2124 实现SPI桥接 扩展4个增强功能串口 xff08 UART xff09 功能 扩展的子通道具备以下功能特点 xff1a 每个子通道UART的波特率 字长 校验格式可以独立设置 xff0c 最高可以提供2Mbps的
  • 手把手教你学51单片机_第 一、二章

    MCU CPU Flash 8kByte EMMC 64G 程序存储空间 xff0c 容量大 xff0c 掉电数据不丢失 RAM 512Byte DDR 4G 代码运行时中间变量的存取区 xff0c 无限次读写 xff0c 且读写速度快 x
  • 九天揽月带你玩转Ardupilot 的EKF2纸老虎

    目录 目录 摘要 1 kalman基础知识储备 2 ardupilot代码EKF流程学习 3 下面重点 逐一分析各个函数 摘要 本文主要记录自己学习ardupilot的ekf2代码的过程 xff0c 相信很多人想移植或者学习ekf2 看到眼
  • 在C++中定义全局变量时避免重复定义

    问题 xff1a 如何在C 43 43 中定义全局变量时避免重复定义呢 今天遇到问题 xff0c 全局变量重定义错误 xff0c 印象中记得要加extern xff0c 但是怎么都不对 xff0c 找资料后得到了解决方案 xff0c 记之
  • Ubuntu16.04下的FireFox浏览器无法查看网页视频的原因及解决方法

    Ubuntu16 04自带的firefox浏览器 在搭建好其他环境后 xff0c 我通过firefox去廖雪峰老师的官网查看python的教程 xff0c 发现无法打开网页中的视频 此时 xff0c 我又通过firefox浏览器中进入了腾讯
  • 【嵌入式模块】MPU6050

    文章目录 0 前言1 MPU6050概述1 1 基本概述1 2 引脚和常用原理图 2 代码3 姿态解算3 1 欧拉角 amp 旋转矩阵3 2 DMP 3 校正 0 前言 作为惯性传感器中入门级别的器件 xff0c MPU6050凭借它出色的
  • 7-13 出栈序列的合法性(25 分)(解决此类题的重要规律)

    给定一个最大容量为 M 的堆栈 xff0c 将 N 个数字按 1 2 3 N 的顺序入栈 xff0c 允许按任何顺序出栈 xff0c 则哪些数字序列是不可能得到的 xff1f 例如给定 M 61 5 N 61 7 xff0c 则我们有可能得
  • STL-map的简单用法(以及如何使用sort将map进行排序)

    map是不可排序的 xff0c 可是凡事都不是绝对的 xff0c 现在我就告诉大家如何将map进行简单的排序以及其的简单用法 一 map的常用方式 xff1a mapname clear xff09 xff1a 清空map mapname
  • 初识c语言的条件判断和循环。

    刚开始接触c语言的循环 xff0c 也许你会烦躁 xff0c 但是你只需要静下心来再看一遍 xff0c 你就会有更多的收获 xff0c 加油 xff01 xff08 凡事开头难 xff0c 迈过第一关 xff0c 你就是最棒的 xff01
  • digest鉴权

    摘要 式认证 xff08 Digest authentication xff09 是一个简单的认证机制 xff0c 最初是为HTTP协议开发的 xff0c 因而也常叫做HTTP摘要 xff0c 在RFC2671中描述 其身份验证机制很简单