Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encrypted password in database and browser digest auth

I wrote a small webserver which currently uses basic auth over ssl. So far everything works great. Now I want (need) to switch to digest auth. But I can't figure how out to make this work with passwords that are not stored as cleartext in the database? I only have the password digest (generated using bcrypt) of my users' passwords stored. Is http digest auth possible at all?

like image 444
gucki Avatar asked Aug 31 '13 19:08

gucki


People also ask

Is digest authentication encrypted?

Digest Authentication encrypts the credentials along with a server generated nonce that gurantees that the user is who he says he or she is. Then the server recreates the encrypted credentials and sees if they match up. This way, authorization is completed without sending across a password in the clear.

What is password digest authentication?

Digest authentication is another authentication type specified in HTTP 1.1. Unlike basic authentication, digest authentication does not require the password to be transmitted. Rather, the client takes the username and password and uses the MD5 hashing algorithm to create a hash, which is then sent to the SQL Server.

What is password encryption database?

Password encryption is essential to store user credentials stored in a database securely. Without password encryption, anyone accessing a user database on a company's servers (including hackers) could easily view any stored passwords.

Should passwords be hashed or encrypted?

Hashing and encryption both provide ways to keep sensitive data safe. However, in almost all circumstances, passwords should be hashed, NOT encrypted. Hashing is a one-way function (i.e., it is impossible to "decrypt" a hash and obtain the original plaintext value). Hashing is appropriate for password validation.


1 Answers

Was just looking into this just now. First, I read through RFC 2617 - HTTP Authentication: Basic and Digest Access Authentication to get some insight into the specification and see how it can be adapted for a REST API authentication.

Ran into the same question as you did—Does digest authentication mean the server needs to store the user's password in plaintext?

This Stack Overflow answer makes it clear: No. The server doesn't store the plaintext password—it should store the hash of (username|realm|password).

That would've been fine except for one thing—the canonical spec only supports using MD5 as the hash function.

Of course you could store both the bcrypt hash and the MD5 hash but doing so only undermines the security of the bcrypt hash effectively rendering it useless (since an attacker can shift his efforts into brute forcing the MD5 hash instead).


So, I took a step back and thought, why not disregard the spec and use bcrypt on both sides as the hash function (bcrypt(username|realm|password))?

Well, aside from being purposefully slow, bcrypt has a maximum password length which makes it unsuitable for use as a general digest algorithm.


Whew, by now my head was swimming but I still thought to give it another go. Some of the suggestions were to use TLS with SRP or authenticated encryption, specifically EAX, but I felt that maybe those were taking things just a step too far for a simple Web service.

To put it simply, if you're really bent on doing this you can work around bcrypt's character limitation by using a preliminary hash.


Long story short it seems that you can do:

bcrypt(sha256(username|realm|password))

And use that in place of H(A1) in a bastardized version of the spec.

The question now becomes—was all that added complexity really worth it? Did we get any added layer of security over Basic auth over HTTPS?

like image 97
Alistair A. Israel Avatar answered Sep 19 '22 13:09

Alistair A. Israel