Crypto.passwordHash() is not secure for hashing passwords.

Showing 1-25 of 25 messages
Crypto.passwordHash() is not secure for hashing passwords. Ron Gross 2/1/12 4:46 AM
Read this before proceeding.

tl;dr - all the standard hashes (MD5, SHA1, SHA256, SHA512, SHA-3, ...) are insecure for storing passwords (if you just do one hash pass), because they're just too fast.

The proposed solution is to use a function that is deliberately slow, like bcrypt (in industry use for 12 years).
Another alternative is to apply a primitive like SHA1 iteratively, feeding the output back to itself.
I'm not sure which approach is better. This post suggests bcrypt.

Play's Crypto.passwordHash, by default, does one pass of MD5.

I'll be switching to bcrypt, I suggest Play defaults change to something more secure as well.
Re: Crypto.passwordHash() is not secure for hashing passwords. Ron Gross 2/1/12 4:53 AM
Link to a jbcrypt, a java implementation of bcrypt.
Re: Crypto.passwordHash() is not secure for hashing passwords. Adam Brimo 2/1/12 4:57 AM
Thanks for bringing this up. I completely agree, using a different password encryption library was one of the first things we did when we started using Play. 

There is another good explanation of encrypting password on the Jasypt site: http://www.jasypt.org/howtoencryptuserpasswords.html
Re: Crypto.passwordHash() is not secure for hashing passwords. GrailsDeveloper 2/1/12 11:21 AM
You can use http://bazaar.launchpad.net/~opensource21/+junk/permsec/view/head:/psec/app/de/ppi/util/PasswordTools.java
too. It uses salts and you can define the algorithm and rounds
depending on how safe you want it. You can change the default method
because the method is stored in the hash.
How ever it would be great to see in play 2.0 a safe implementation!

Niels
Re: Crypto.passwordHash() is not secure for hashing passwords. David Galichet 2/1/12 11:36 PM
You can also salt your password with the username for example :
Codecs.sha1(username + password). This will prevent quite efficiently
against reverse dictionary or rainbow tables attacks.

David.

On 1 fév, 20:21, GrailsDeveloper <opensourc...@googlemail.com> wrote:
> You can usehttp://bazaar.launchpad.net/~opensource21/+junk/permsec/view/head:/ps...
Re: [play-framework] Re: Crypto.passwordHash() is not secure for hashing passwords. Ron Gross 2/2/12 12:02 AM

Yes, but won't prevent a brute force attack. A single standard hash is not secure even with salting.

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.

Re: [play-framework] Re: Crypto.passwordHash() is not secure for hashing passwords. Will Sargent 2/2/12 12:11 AM
What Ron said, in spades.  Even HMAC-SHA512 has the problem that digest algorithms are fast and storing the digest is easy.  PBKDF2 or bcrypt is really the way to go for storing passwords.  

It's worthwhile to checkout this white paper as well: web_20_crypto.pdf

Will.
Re: [play-framework] Re: Crypto.passwordHash() is not secure for hashing passwords. Havoc Pennington 2/2/12 8:38 AM
Also https://wiki.mozilla.org/WebAppSec/Secure_Coding_Guidelines has good stuff.

Here is some code that:

 - hashes each password with a secret from application.conf, you can
change this secret to invalidate all passwords, also to crack
passwords you need both this secret (from disk) and the salt (from
database)
 - the SHA512 hash is then bcrypt'd with a salt

It uses http://www.mindrot.org/projects/jBCrypt/ (afaik you just have
to cut-and-paste the BCrypt.java file, it doesn't seem to be
Maven-published)

Havoc


/**
 *  Copyright (C) 2011 Havoc Pennington
 *  Licensed under the Apache License, Version 2.0
  */

package security

import java.util.UUID
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
import org.apache.commons.codec.binary.Hex
import org.apache.commons.codec.digest.DigestUtils

import bcrypt.BCrypt;

object Algorithms {

  // HMAC SHA-512 hash
  private def signature(message: String, key: String): String = {
    require(key.length > 0)

    val mac = Mac.getInstance("HmacSHA512");
    val signingKey = new SecretKeySpec(key.getBytes("utf-8"), "HmacSHA512");
    mac.init(signingKey);
    val messageBytes = message.getBytes("utf-8");
    val resultBytes = mac.doFinal(messageBytes);

    new String(Hex.encodeHex(resultBytes))
  }

  def hashPassword(password: String, serverWidePasswordSecret: String) = {
    if (password.length == 0)
      throw new IllegalArgumentException("Password may not be zero-length")

    // we add the server's secret key to the password,
    // the idea is to require stealing both the server
    // key and the database, which might raise the bar
    // a bit.
    val intermediate = signature(password, serverWidePasswordSecret)

    BCrypt.hashpw(intermediate, BCrypt.gensalt())
  }

  def checkPassword(password: String, passwordHash: String,
serverWidePasswordSecret: String) = {
    val intermediate = signature(password, serverWidePasswordSecret)
    BCrypt.checkpw(intermediate, passwordHash)
  }
}

Re: [play-framework] Re: Crypto.passwordHash() is not secure for hashing passwords. Ron Gross 2/2/12 9:43 AM
Good idea about using both SHA512 and Bcrypt!

jbcrypt is available from maven. Here is the deps.yml line:

    - org.mindrot -> jbcrypt 0.3m

My code seems simpler than what you wrote:

public String hashPassword(User user, String password) {
        switch (user.hashingAlgorithm) {
            case BCRYPT_SHA512: // our own enum
                return Crypto.passwordHash(org.mindrot.jbcrypt.BCrypt.hashpw(password, user.salt), Crypto.HashType.SHA512);

            default:
                throw new RuntimeException("Unsupported hash algorithm: " + user.hashingAlgorithm);
        }
    }

The user salt is initialized with:

user.salt = org.mindrot.jbcrypt.BCrypt.gensalt();




 }
}

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.




--

Re: [play-framework] Re: Crypto.passwordHash() is not secure for hashing passwords. Eishay 2/2/12 1:54 PM
Bcrypt is definitely the way to go for passwords making brute force much harder. Is the inherit value in adding more encryption algorithms to the mix or is it specifically SHA512? 
Re: [play-framework] Re: Crypto.passwordHash() is not secure for hashing passwords. Ron Gross 2/2/12 2:11 PM
I think there are two advantages to using both algorithms together:

1. It's easier to add the app-specific crypto seed. So, in order to crack it you need to get both the salts from the DB and the crypto seed from disk, just like Havoc said.

2. It feels a bit safer because even if there's a slight hidden bug in the bcrypt implementation (because this library is less wildly used), it's possible (although not guaranteed) that an extra SHA512 round (trusted, often used library) will make exploiting the bug harder.
Re: [play-framework] Re: Crypto.passwordHash() is not secure for hashing passwords. Havoc Pennington 2/2/12 3:17 PM
Yep. The rationale on the Mozilla guidelines page is:

 * "The nonce for the hmac value is designed to be stored on the file
system and not in the databases storing the password hashes. In the
event of a compromise of hash values due to SQL injection, the nonce
will still be an unknown value since it would not be compromised from
the file system. This significantly increases the complexity of brute
forcing the compromised hashes considering both bcrypt and a large
unknown nonce value"
 * "The hmac operation is simply used as a secondary defense in the
event there is a design weakness with bcrypt that could leak
information about the password or aid an attacker"

I guess they use 512 because why not use the maximally-strong SHA
flavor (this is the rare case where having an algorithm be slow is
desirable, so you can use the slowest-but-strongest SHA).

Imagine you're using a database-as-a-service provider or something
like that, and the db provider is hacked, but your app server is not -
the extra secret hashed in from application.conf could save you in
that case and make it impossible to search for "123password" and
"letmein" and all those other common crappy passwords. Without the
extra secret, people can still search for them... even though bcrypt
is slow and the salt requires recomputing the hash for every
user-password combo, some of the common passwords are common enough
they'd likely get one eventually.

Havoc

On Thu, Feb 2, 2012 at 5:11 PM, Ron Gross <ron....@gmail.com> wrote:
> I think there are two advantages to using both algorithms together:
>
> 1. It's easier to add the app-specific crypto seed. So, in order to crack it
> you need to get both the salts from the DB and the crypto seed from disk,
> just like Havoc said.
>
> 2. It feels a bit safer because even if there's a slight hidden bug in the
> bcrypt implementation (because this library is less wildly used), it's
> possible (although not guaranteed) that an extra SHA512 round (trusted,
> often used library) will make exploiting the bug harder.
>

This message has been hidden because it was flagged for abuse.
Re: [play-framework] Re: Crypto.passwordHash() is not secure for hashing passwords. Drew 2/2/12 9:42 PM
Just to chime in, I did a bit of a research on what's the best way to store passwords a couple of years ago. The thing with hash functions is that they are mostly built to just do that, create hashes quickly. So by definition, if you are using a hashing function that is fast, it's not going to be secure. So I moved to BCrypt a couple of years back.

The thing to note is that, even when using BCrypt, you need generate a brand new salt for each password. The salt can be anything random and the salt doesn't need to be protected. So you can store your password in a "salt : hash" format where the first part is the plaintext salt. The salt has no use to attackers, it's only used to ensure that the hashes are not predictable and the attacker cannot infer relationships between the hashes. It's pretty much the same idea as IVs (Initialization Vectors) [1] in encryption.

HTH,

Drew

[1] http://en.wikipedia.org/wiki/Initialization_vector

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>

This message has been hidden because it was flagged for abuse.
Re: [play-framework] Re: Crypto.passwordHash() is not secure for hashing passwords. Jean-Francois Im 2/3/12 8:01 AM
On Fri, Feb 3, 2012 at 00:42, Drew Kutcharian <dr...@venarc.com> wrote:
> The thing to note is that, even when using BCrypt, you need generate a brand new salt for each password. The salt can be anything random and the salt doesn't need to be protected. So you can store your password in a "salt : hash" format where the first part is the plaintext salt. The salt has no use to attackers, it's only used to ensure that the hashes are not predictable and the attacker cannot infer relationships between the hashes. It's pretty much the same idea as IVs (Initialization Vectors) [1] in encryption.

Are you sure that you need to actually store a salt value? I was under
the impression that BCrypt stored it implicitly and there is no
documentation of such a requirement in the jbcrypt documentation. From
a quick test:

$ scala -classpath lib/jbcrypt-0.3m.jar
Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) 64-Bit Server VM,
Java 1.6.0_29).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import org.mindrot.jbcrypt._
import org.mindrot.jbcrypt._

scala> BCrypt.hashpw("hello", BCrypt.gensalt())
res0: java.lang.String =
$2a$10$76eXtd9ab8sbZWLlGxCmfOVr2ENud6JFOTyp3L9sJokSZwROChIgy

scala> BCrypt.hashpw("hello", BCrypt.gensalt())
res1: java.lang.String =
$2a$10$F5g.8C3b.3sBBm.LCbCbw.N/2QvHNTwJDCX4aCgRNz0UL.lqv/CpO

scala> BCrypt.checkpw("hello", res0)
res2: Boolean = true

scala> BCrypt.checkpw("hello", res1)
res3: Boolean = true

scala> BCrypt.checkpw("hello!", res1)
res4: Boolean = false

Re: [play-framework] Crypto.passwordHash() is not secure for hashing passwords. Drew 2/3/12 10:01 AM
Yes, you're right about jBcrypt. It actually includes the salt and length of the salt in the encoded string that it returns using $ as delimiters. I was just trying to explain how salts are usually stored and they don't need to be encrypted.

-- Drew

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>

Re: [play-framework] Crypto.passwordHash() is not secure for hashing passwords. Rakesh Waghela 2/3/12 12:28 PM
http://www.jasypt.org/features.html  of  any use ?
Re: Crypto.passwordHash() is not secure for hashing passwords. Alex Hanschke 6/15/12 11:40 AM
Found a good discussion on password security here: http://throwingfire.com/storing-passwords-securely/
Re: Crypto.passwordHash() is not secure for hashing passwords. Bruno Vernay 6/19/12 8:21 AM
An somehow authoritative source would be:  https://www.owasp.org/index.php/Hashing_Java
But it seems a bit out-dated by its own: https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet

Finally there are good information here: http://en.wikipedia.org/wiki/Key_stretching

Specially about sCrypt. The idea is that an algo consuming a lot of memory would limit the use of GPU or other parallel hardware to perform brute force.  Of course, you have to be careful not to crash your own server.

Some data about compromise between security and performance here: http://ludopoitou.wordpress.com/2012/06/13/more-secure-passwords/
Re: [play-framework] Re: Crypto.passwordHash() is not secure for hashing passwords. Gijsbert Peijs 7/25/12 1:02 AM
Hi Ron,

The dependency works like a charm and also your code example is really helpful but there is one thing that breaks the example: The order of hashing. 

jBCrypt stores it's randomly generated salts in the password hash which is a really great idea because it allows BCrypt.checkpw to work without you providing the salt. But if you hash the BCrypt password with SHA512, there is no way to determine the salt again so BCrypt.checkpw won't work. By first applying the SHA512 hash, you can encrypt the hashed password with BCrypt with a random salt. Now all you have to do is SHA512-hash the plain text password the user provides and use BCrypt.checkpw to validate against the password stored in the database.

In code this looks something like:

    /*
     * hash passwords. First SHA512 using Play's internal Crypto and subsequently BCrypt (with random Salt).
     */
    public static String hashPassword(String password) {
        String salt = BCrypt.gensalt();
        return BCrypt.hashpw(Crypto.passwordHash(password, Crypto.HashType.SHA512), salt);
    }
    
    /*
     * encrypts the provided plain text password to SHA512 and then uses BCrypt to validate against the stored double encrypted password.
     */
    public static boolean matchPasswords(String providedPassword, String storedPassword) {
        String sha512Password = Crypto.passwordHash(providedPassword, Crypto.HashType.SHA512); // Only SHA512, no BCrypt
        return BCrypt.checkpw(sha512Password, storedPassword);
    }

Hope this is of any use.

Regards,

Gijs.




Op donderdag 2 februari 2012 18:43:01 UTC+1 schreef Ron Gross het volgende:
Re: [play-framework] Re: Crypto.passwordHash() is not secure for hashing passwords. sts2055 1/29/13 1:30 PM
New play webdev here.

I am trying to implement an encryption method for user data that is to be stored in a database (mysql). I'm following the examples listed in this discussion, however, the Crypto class in play 2.0.4 does not include the passwordHash method any longer. I found the old Crypto java source (https://github.com/playframework/play/blob/master/framework/src/play/libs/Crypto.java), however, since the method has been removed I am now wondering if something new has come up with regards to the Play Framework and should be used instead.

Does anybody know why the method has been removed?
Re: [play-framework] Re: Crypto.passwordHash() is not secure for hashing passwords. Lars Støttrup Nielsen 4/14/13 12:00 PM
Probably because it wasn't secure enough by todays standards.
Imagine a GPU cracker such as hashcat on a botnet of 10000 computers.
You suddenly have a frightening amount of computational power available. The SHA algorithms are fast, which is the main problem.
Re: Crypto.passwordHash() is not secure for hashing passwords. Torben 4/16/13 11:17 AM
I agree and we started using BCrypt/jBCrypt on passwords for many of the reasons discussed here. I highly recommend it :)
Re: Crypto.passwordHash() is not secure for hashing passwords. Ryan Tanner 4/16/13 10:03 PM
You could also consider the play2-auth library, it uses BCrypt in its default implementation.  

More topics »