Quantcast

[knop-project] knop_crypthash - using hashed password, salt, and cost

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[knop-project] knop_crypthash - using hashed password, salt, and cost

stevepiercy
I'm doing a code review in knop_user -> login and its
dependencies.  There's a code block that leaves me scratching my head.
https://github.com/knop-project/knop/blob/master/knop9/knoplibs/knop_user.lasso#L436-L442

     if(knop_crypthash(#_password,
         -hash = string(#db -> field(.'passwordfield')),
         -salt = knop_blowfish(-string = #db ->
field(.'saltfield'), -mode = 'D'),
         -cost = (.'costfield' -> size ? integer(#db ->
field(.'costfield')) | .'costsize'),
         -cipher = (.'encrypt_cipher')) == true) => {

         #validlogin = true
     }

...and the source for knop_crypthash:
https://github.com/knop-project/knop/blob/master/knop9/knoplibs/knop_utils.lasso#L482-L563

 From this I've tried to reverse engineer how passwords should
be stored (and other bits used for knop_user -> login), but I
have not been successful.  It looks like knop_blowfish is used
to encrypt the salt and store that in the database.  Then on
login, the value in the saltfield is decrypted with
knop_blowfish and passed into the -salt argument for knop_crypthash.

When I tried storing the password like that and try
authentication with the -cost parameter, knop_user -> login
always fails.  All other knop_user -> login methods that do not
use -cost work for me.

If anyone has this working (Rick Draper, Jolle Carlestam),
please share a code sample of how you create a user record with
its fields for username, password (hashed), saltfield,
costfield, and any other relevant bits.

Also include whether anything more elaborate than knop_user ->
login('u', 'p') is called.

Finally, is there a reason that knop_blowfish is used here?  In
Bil Corry's original post on the topic, he didn't mention using
blowfish.  Here's a gist I threw together to test it.

Bil's post
http://lasso.2283332.n4.nabble.com/encryption-tt3140901.html#a3140908

My gist.
https://gist.github.com/stevepiercy/acf9d559e596e57f7c3a

Thanks in advance.

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Steve Piercy              Website Builder              Soquel, CA
<[hidden email]>               <http://www.StevePiercy.com/>

--
You received this message because you are subscribed to the Google Groups "knop-project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/knop-project.
To view this discussion on the web visit https://groups.google.com/d/msgid/knop-project/r422Ps-1085i-BAC72554BB144FCE9390547897A03C19%40ip30.192-168-0.rfc1918.steadfastdns.net.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [knop-project] knop_crypthash - using hashed password, salt, and cost

Bil Corry-3
Looking at the code, blowfish is used for the salt, not the hash, which is fine.  The hash is RIPEMD160, which is also fine:


You'll want cost working, that's important in case your hashes are stolen.

I also noticed SHA1 is the default when a cipher isn't specified:


SHA1 is on the way out, it should be SHA2 (e.g. SHA-256, SHA-512, etc).


- Bil

On Thu, Jul 9, 2015 at 10:18 AM, Steve Piercy - Website Builder <[hidden email]> wrote:
I'm doing a code review in knop_user -> login and its dependencies.  There's a code block that leaves me scratching my head.
https://github.com/knop-project/knop/blob/master/knop9/knoplibs/knop_user.lasso#L436-L442

    if(knop_crypthash(#_password,
        -hash = string(#db -> field(.'passwordfield')),
        -salt = knop_blowfish(-string = #db -> field(.'saltfield'), -mode = 'D'),
        -cost = (.'costfield' -> size ? integer(#db -> field(.'costfield')) | .'costsize'),
        -cipher = (.'encrypt_cipher')) == true) => {

        #validlogin = true
    }

...and the source for knop_crypthash:
https://github.com/knop-project/knop/blob/master/knop9/knoplibs/knop_utils.lasso#L482-L563

From this I've tried to reverse engineer how passwords should be stored (and other bits used for knop_user -> login), but I have not been successful.  It looks like knop_blowfish is used to encrypt the salt and store that in the database.  Then on login, the value in the saltfield is decrypted with knop_blowfish and passed into the -salt argument for knop_crypthash.

When I tried storing the password like that and try authentication with the -cost parameter, knop_user -> login always fails.  All other knop_user -> login methods that do not use -cost work for me.

If anyone has this working (Rick Draper, Jolle Carlestam), please share a code sample of how you create a user record with its fields for username, password (hashed), saltfield, costfield, and any other relevant bits.

Also include whether anything more elaborate than knop_user -> login('u', 'p') is called.

Finally, is there a reason that knop_blowfish is used here?  In Bil Corry's original post on the topic, he didn't mention using blowfish.  Here's a gist I threw together to test it.

Bil's post
http://lasso.2283332.n4.nabble.com/encryption-tt3140901.html#a3140908

My gist.
https://gist.github.com/stevepiercy/acf9d559e596e57f7c3a

Thanks in advance.

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Steve Piercy              Website Builder              Soquel, CA
<[hidden email]>               <http://www.StevePiercy.com/>

--
You received this message because you are subscribed to the Google Groups "knop-project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/knop-project.
To view this discussion on the web visit https://groups.google.com/d/msgid/knop-project/r422Ps-1085i-BAC72554BB144FCE9390547897A03C19%40ip30.192-168-0.rfc1918.steadfastdns.net.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "knop-project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/knop-project.
To view this discussion on the web visit https://groups.google.com/d/msgid/knop-project/CACdphr5O2CtzcmDt0h2R4Ug4RntbD_Zu3jju4OqQL-KYCcR8mw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [knop-project] knop_crypthash - using hashed password, salt, and cost

Steve Piercy
I forgot to follow up, I worked it out with some helpful
guidance from Jolle.

I use RIPEMD160 when hashing.  Also I have some revisions for
Knop that I need to merge, one of which is using RIPEMD160 as
the default.

I assumed cost was working in your implementation in
lp_crypt_hash.  Is this not done correctly?
http://lasso.2283332.n4.nabble.com/encryption-tt3140901.html#a3140908

In my implementation, I specify a cost as a random integer
between 20 and 2000 (instead of the default 20), and store the
value in the database.  I got that idea from another post.
http://lasso.2283332.n4.nabble.com/Encrypted-data-tt3305756.html#a3308152

And other practices from this post.  Yes, I'm stalking you Bil.  :P
http://lasso.2283332.n4.nabble.com/Looking-for-input-Authentication-tt3131137.html#a3131138

I have been soaking up crypto stuff from those who have
implemented it in Python.
https://pypi.python.org/pypi/bcrypt/2.0.0
https://pypi.python.org/pypi/scrypt/

I have no idea where Lasso is in that regard.

--steve


On 7/11/15 at 9:38 AM, [hidden email] (Bil Corry) pronounced:

>Looking at the code, blowfish is used for the salt, not the hash, which is
>fine.  The hash is RIPEMD160, which is also fine:
>
>https://github.com/knop-project/knop/blob/master/knop9/knoplibs/knop_user.lasso#L133
>
>You'll want cost working, that's important in case your hashes are stolen.
>
>I also noticed SHA1 is the default when a cipher isn't specified:
>
>https://github.com/knop-project/knop/blob/master/knop9/knoplibs/knop_utils.lasso#L488
>
>SHA1 is on the way out, it should be SHA2 (e.g. SHA-256, SHA-512, etc).
>
>
>- Bil
>
>On Thu, Jul 9, 2015 at 10:18 AM, Steve Piercy - Website Builder <
>[hidden email]> wrote:
>
>>I'm doing a code review in knop_user -> login and its dependencies.
>>There's a code block that leaves me scratching my head.
>>
>>https://github.com/knop-project/knop/blob/master/knop9/knoplibs/knop_user.lasso#L436-L442
>>
>>if(knop_crypthash(#_password,
>>-hash = string(#db -> field(.'passwordfield')),
>>-salt = knop_blowfish(-string = #db -> field(.'saltfield'), -mode
>>= 'D'),
>>-cost = (.'costfield' -> size ? integer(#db ->
>>field(.'costfield')) | .'costsize'),
>>-cipher = (.'encrypt_cipher')) == true) => {
>>
>>#validlogin = true
>>}
>>
>>...and the source for knop_crypthash:
>>
>>https://github.com/knop-project/knop/blob/master/knop9/knoplibs/knop_utils.lasso#L482-L563
>>
>>From this I've tried to reverse engineer how passwords should be stored
>>(and other bits used for knop_user -> login), but I have not been
>>successful.  It looks like knop_blowfish is used to encrypt the salt and
>>store that in the database.  Then on login, the value in the saltfield is
>>decrypted with knop_blowfish and passed into the -salt argument for
>>knop_crypthash.
>>
>>When I tried storing the password like that and try authentication with
>>the -cost parameter, knop_user -> login always fails.  All other knop_user
>>-> login methods that do not use -cost work for me.
>>
>>If anyone has this working (Rick Draper, Jolle Carlestam), please share a
>>code sample of how you create a user record with its fields for username,
>>password (hashed), saltfield, costfield, and any other relevant bits.
>>
>>Also include whether anything more elaborate than knop_user -> login('u',
>>'p') is called.
>>
>>Finally, is there a reason that knop_blowfish is used here?  In Bil
>>Corry's original post on the topic, he didn't mention using blowfish.
>>Here's a gist I threw together to test it.
>>
>>Bil's post
>>http://lasso.2283332.n4.nabble.com/encryption-tt3140901.html#a3140908
>>
>>My gist.
>>https://gist.github.com/stevepiercy/acf9d559e596e57f7c3a
>>
>>Thanks in advance.
>>
>>--steve
>>
>>-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
>>Steve Piercy              Website Builder              Soquel, CA
>><[hidden email]>               <http://www.StevePiercy.com/>
>>
>>--
>>You received this message because you are subscribed to the Google Groups
>>"knop-project" group.
>>To unsubscribe from this group and stop receiving emails from it, send an
>>email to [hidden email].
>>To post to this group, send email to [hidden email].
>>Visit this group at http://groups.google.com/group/knop-project.
>>To view this discussion on the web visit
>>
>https://groups.google.com/d/msgid/knop-project/r422Ps-1085i-BAC72554BB144FCE9390547897A03C19%40ip30.
>192-168-0.rfc1918.steadfastdns.net
>>.
>>For more options, visit https://groups.google.com/d/optout.
>>
>

------------------------
Steve Piercy, Soquel, CA

--
You received this message because you are subscribed to the Google Groups "knop-project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/knop-project.
To view this discussion on the web visit https://groups.google.com/d/msgid/knop-project/r422Ps-1085i-207D2B2243A24218BD3B9A41C03DD88F%40stevepi-mbp.local.
For more options, visit https://groups.google.com/d/optout.
Loading...