Digest access authentication is one of the agreed-upon methods a
web server
A web server is computer software and underlying Computer hardware, hardware that accepts requests via Hypertext Transfer Protocol, HTTP (the network protocol created to distribute web content) or its secure variant HTTPS. A user agent, co ...
can use to negotiate credentials, such as username or password, with a user's
web browser
A web browser, often shortened to browser, is an application for accessing websites. When a user requests a web page from a particular website, the browser retrieves its files from a web server and then displays the page on the user's scr ...
. 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
A hash function is any Function (mathematics), function that can be used to map data (computing), data of arbitrary size to fixed-size values, though there are some hash functions that support variable-length output. The values returned by a ...
to the username and
password
A password, sometimes called a passcode, is secret data, typically a string of characters, usually used to confirm a user's identity. Traditionally, passwords were expected to be memorized, but the large number of password-protected services t ...
before sending them over the network. In contrast,
basic access authentication uses the easily reversible
Base64 encoding instead of hashing, making it non-secure unless used in conjunction with
TLS.
Technically, digest authentication is an application of
cryptographic hashing with usage of
nonce values to prevent
replay attacks. It uses the
HTTP
HTTP (Hypertext Transfer Protocol) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, wher ...
protocol.
DIGEST-MD5 as a
SASL mechanism specified by is obsolete since July 2011.
Overview
Digest access authentication was originally specified by (''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 and HA2 are names of string variables):
:
HA1 = MD5(username:realm:password)
HA2 = MD5(method:digestURI)
response = MD5(HA1:nonce:HA2)
An MD5 hash is a 16-byte value. The HA1 and HA2 values used in the computation of the response are the hexadecimal representation (in lowercase) of the MD5 hashes respectively.
RFC 2069 was later replaced by (''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
Cryptanalysis (from the Greek ''kryptós'', "hidden", and ''analýein'', "to analyze") refers to the process of analyzing information systems in order to understand hidden aspects of the systems. Cryptanalysis is used to breach cryptographic se ...
.
If the algorithm directive's value is "MD5" or unspecified, then HA1 is
:
HA1 = MD5(username:realm:password)
If the algorithm directive's value is "MD5-sess", then HA1 is
:
HA1 = MD5(MD5(username:realm:password):nonce:cnonce)
If the qop directive's value is "auth" or is unspecified, then HA2 is
:
HA2 = MD5(method:digestURI)
If the qop directive's value is "auth-int", then HA2 is
:
HA2 = MD5(method:digestURI:MD5(entityBody))
If the qop directive's value is "auth" or "auth-int", then compute the response as follows:
:
response = MD5(HA1:nonce:nonceCount:cnonce:qop:HA2)
If the qop directive is unspecified, then compute the response as follows:
:
response = MD5(HA1:nonce:HA2)
The above shows that when qop is not specified, the simpler RFC 2069 standard is followed.
In September 2015, RFC 7616 replaced RFC 2617 by adding 4 new
algorithms
In mathematics and computer science, an algorithm () is a finite sequence of mathematically rigorous instructions, typically used to solve a class of specific problems or to perform a computation. Algorithms are used as specifications for per ...
: "SHA-256", "SHA-256-sess", "SHA-512-256" and "SHA-512-256-sess". The encoding is equivalent to "MD5" and "MD5-sess" algorithms, with
MD5 hashing function replaced with
SHA-256 and
SHA-512-256. However, , none of popular browsers, including Firefox and Chrome, support SHA-256 as the hash function. , Firefox 93 officially supports "SHA-256" and "SHA-256-sess" algorithms for digest authentication. However, support for "SHA-512-256", "SHA-512-256-sess" algorithms and username hashing is still lacking. , Chromium 117 (then Chrome and Edge) supports "SHA-256".
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
A dictionary is a listing of lexemes from the lexicon of one or more specific languages, often arranged Alphabetical order, alphabetically (or by Semitic root, consonantal root for Semitic languages or radical-and-stroke sorting, radical an ...
or
suitable look-up list, which for MD5 is readily available.
The HTTP scheme was designed by
Phillip Hallam-Baker at
CERN
The European Organization for Nuclear Research, known as CERN (; ; ), is an intergovernmental organization that operates the largest particle physics laboratory in the world. Established in 1954, it is based in Meyrin, western suburb of Gene ...
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
Cryptography, or cryptology (from "hidden, secret"; and ''graphein'', "to write", or '' -logia'', "study", respectively), is the practice and study of techniques for secure communication in the presence of adversarial behavior. More gen ...
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.
However, claims in 2006 cause some doubt over other MD5 applications as well.
HTTP digest authentication considerations
Advantages
HTTP digest authentication is designed to be more secure than traditional digest authentication schemes, for example "significantly stronger than (e.g.)
CRAM-MD5 ..." (RFC 2617).
Some of the security strengths of HTTP digest authentication are:
* The password is not sent clear to the server.
* The password is not used directly in the digest, but rather HA1 = MD5(username:realm:password). This allows some implementations (e.g.
JBoss) to store HA1 rather than the cleartext password (however, see disadvantages of this approach)
* Client nonce was introduced in RFC 2617, which allows the client to prevent
chosen-plaintext attacks, such as
rainbow tables that could otherwise threaten 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
* It prevents
Phishing because the plain password is never sent to any server, be it the correct server or not. (Public key systems rely on the user being able to verify that the URL is correct.)
Disadvantages
There are several drawbacks with digest access authentication:
* The website has no control over the user interface presented to the end user.
* 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
* A server can store HA1 = MD5(username:realm:password) instead of the password itself. However, if the stored HA1 is leaked, an attacker can generate valid responses and access documents in the realm just as easily as if they had access to the password itself. The table of HA1 values must therefore be protected as securely as a file containing plaintext passwords.
* Digest access authentication 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)
Also, since the
MD5 algorithm is not allowed in
FIPS, HTTP Digest authentication will not work with FIPS-certified
[The following is a list of FIPS approved algorithms: ] crypto modules.
Alternative authentication protocols
By far the most common approach is to use a
HTTP+HTML form-based authentication cleartext protocol, or more rarely
Basic access authentication. These weak cleartext protocols used together with
HTTPS
Hypertext Transfer Protocol Secure (HTTPS) is an extension of the Hypertext Transfer Protocol (HTTP). It uses encryption for secure communication over a computer network, and is widely used on the Internet. In HTTPS, the communication protoc ...
network encryption resolve many of the threats that digest access authentication is designed to prevent. However, this use of HTTPS relies upon the end user to accurately validate that they are accessing the correct URL each time to prevent sending their password to an untrusted server, which results in
phishing attacks.
Users often fail to do this, which is why phishing has become the most common form of security breach.
Some strong authentication protocols for web-based applications that are occasionally used include:
*
Public key authentication (usually implemented with a
HTTPS
Hypertext Transfer Protocol Secure (HTTPS) is an extension of the Hypertext Transfer Protocol (HTTP). It uses encryption for secure communication over a computer network, and is widely used on the Internet. In HTTPS, the communication protoc ...
/
SSL client certificate) using a client certificate.
*
Kerberos or
SPNEGO authentication, employed for example by
Microsoft IIS running configured for
Integrated Windows Authentication (IWA).
*
Secure Remote Password protocol (preferably within the
HTTPS
Hypertext Transfer Protocol Secure (HTTPS) is an extension of the Hypertext Transfer Protocol (HTTP). It uses encryption for secure communication over a computer network, and is widely used on the Internet. In HTTPS, the communication protoc ...
/
TLS layer). However, this is not implemented by any mainstream browsers.
*
JSON Web Token (JWT) is a
JSON
JSON (JavaScript Object Notation, pronounced or ) is an open standard file format and electronic data interchange, data interchange format that uses Human-readable medium and data, human-readable text to store and transmit data objects consi ...
-based standard RFC 7519 for creating
access tokens that assert some number of claims.
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 – , only the
Opera
Opera is a form of History of theatre#European theatre, Western theatre in which music is a fundamental component and dramatic roles are taken by Singing, singers. Such a "work" (the literal translation of the Italian word "opera") is typically ...
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.
[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.] 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.
----
; Client request (no authentication):
GET /dir/index.html HTTP/1.0
Host: localhost
(followed by a
new line
New or NEW may refer to:
Music
* New, singer of K-pop group The Boyz
* ''New'' (album), by Paul McCartney, 2013
** "New" (Paul McCartney song), 2013
* ''New'' (EP), by Regurgitator, 1995
* "New" (Daya song), 2017
* "New" (No Doubt song), 1 ...
, in the form of a
carriage return followed by a
line feed).
; Server response:
HTTP/1.0 401 Unauthorized
Server: HTTPd/0.9
Date: Sun, 10 Apr 2014 20:26:47 GMT
WWW-Authenticate: Digest realm="[email protected]",
qop="auth,auth-int",
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
opaque="5ccc069c403ebaf9f0171e9517f40e41"
Content-Type: text/html
Content-Length: 153
Error
401 Unauthorized.
; Client request (username "Mufasa", password "Circle Of Life"):
GET /dir/index.html HTTP/1.0
Host: localhost
Authorization: Digest username="Mufasa",
realm="[email protected]",
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 colons.
# The MD5 hash of the combined username, authentication realm and password is calculated. The result is referred to as HA1.
# 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.
# 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, where
MD5()
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:
[email protected]: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.
The .htdigest file
.htdigest is a
flat-file used to store usernames, realm and passwords for digest authentication of
Apache HTTP Server
The Apache HTTP Server ( ) is a free and open-source software, free and open-source cross-platform web server, released under the terms of Apache License, Apache License 2.0. It is developed and maintained by a community of developers under the ...
. The name of the file is given in the
.htaccess configuration, and can be anything, but ".htdigest" is the canonical name. The file name starts with a dot, because most
Unix-like
A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
operating systems consider any file that begins with dot to be hidden. This file is often maintained with the
shell
Shell may refer to:
Architecture and design
* Shell (structure), a thin structure
** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses
Science Biology
* Seashell, a hard outer layer of a marine ani ...
command "htdigest" which can add, and update users, and will properly encode the password for use.
The "htdigest" command is found in the apache2-utils package on
dpkg package management systems and the httpd-tools package on
RPM package management systems.
The syntax of the htdigest command:
htdigest
-c ''passwdfile realm username''
The format of the .htdigest file:
user1:Realm:5ea41921c65387d904834f8403185412
user2:Realm:734418f1e487083dc153890208b79379
SIP digest authentication
Session Initiation Protocol (SIP) uses basically the same digest authentication algorithm. It is specified by RFC 3261.
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
Geckos are small, mostly carnivorous lizards that have a wide distribution, found on every continent except Antarctica. Belonging to the infraorder Gekkota, geckos are found in warm climates. They range from .
Geckos are unique among lizards ...
-based: (not including auth-int)
**
Mozilla Application Suite
The Mozilla Application Suite (originally known as Mozilla, marketed as the Mozilla Suite) is a discontinued cross-platform integrated Internet suite. Its development was initiated by Netscape Communications Corporation, before their acquisition ...
**
Mozilla Firefox
**
Netscape 7+
*
iCab 3.0.3+
*
KHTML- and
WebKit
WebKit is a browser engine primarily used in Apple's Safari web browser, as well as all web browsers on iOS and iPadOS. WebKit is also used by the PlayStation consoles starting with the PS3, the Tizen mobile operating systems, the Amazon K ...
-based: (not including auth-int)
**
iCab 4
**
Konqueror
**
Google Chrome
Google Chrome is a web browser developed by Google. It was first released in 2008 for Microsoft Windows, built with free software components from Apple WebKit and Mozilla Firefox. Versions were later released for Linux, macOS, iOS, iPadOS, an ...
**
Safari
A safari (; originally ) is an overland journey to observe wildlife, wild animals, especially in East Africa. The so-called big five game, "Big Five" game animals of Africa – lion, African leopard, leopard, rhinoceros, African elephant, elep ...
*
Tasman-based:
**
Internet Explorer for Mac
*
Trident-based:
**
Internet Explorer 5+ (not including auth-int)
*
Presto-based:
**
Opera
Opera is a form of History of theatre#European theatre, Western theatre in which music is a fundamental component and dramatic roles are taken by Singing, singers. Such a "work" (the literal translation of the Italian word "opera") is typically ...
(Opera switched away from Presto in 2013)
**
Opera Mobile
**
Opera Mini
**
Nintendo DS Browser
**
Nokia 770 Browser
**
Sony Mylo 1's Browser
**
Wii Internet Channel Browser
Deprecations
Because of the disadvantages of Digest authentication compared to Basic authentication over HTTPS it has been deprecated by a lot of software e.g.:
* Bitbucket
* Symfony PHP framework
See also
*
AKA (security)
*
JSON Web Token (JWT)
*
Basic access authentication
*
HTTP+HTML form-based authentication
Notes
References
{{Cryptography hash
External links
RFC 7235RFC 6331RFC 2617(updated by RFC 7235)
RFC 2069(obsolete)
Cryptographic protocols
Hypertext Transfer Protocol
Request for Comments
Computer access control protocols
de:HTTP-Authentifizierung#Digest Access Authentication
fr:HTTP Authentification#Méthode Digest