479 points · by antitamper · 10y ago · 301 comments
We live in an age where this should be unacceptable. Why aren't there financial security laws yet?
Furthermore, credit unions can't make risky bets that could put them under. The money you deposit goes out as loans to other people.
I avoid banks like the plague. Too shady for me, never again.
The operator on the line asked me a ton of questions starting from my user-id (but not password), date of birth, full name, father's name, place of birth, type of account and many others that I don't remember now. Only after I correctly answered all these questions, did he start acting on my instructions.
But if i tell them to not make it that easy, i cant manage my shit over the phone anymore :/
Where did you spend your honeymoon? What was the name of your first pet? What is the name of the street where you grew up?
For any given person, a LOT of people know the answer to these kind of questions.
Also, I hate it when people use date of birth to verify identity. Medical people love doing this. Um, just check the person's Facebook and see when everyone wishes them a happy birthday, then go access their medical records?
Tangential to the actual issue, but in that field it's to prevent patient mixups, not to defend against malicious attackers.
As you implicitly point out, however, it doesn't require any portion of the password ever to be visible to the call-centre employee; one can just supplement an individual hash by a collection of hashes of appropriate character subsets, and then (say) randomly pick among the available subsets.
I went to my boss and explained that we can't do that. It's inviting exploitation. He responded to me that we had to keep them in plain text, in the database so that we could send them to users who forgot. If they can't login, they won't order product.
I have heard similar stories from other IT professionals. It's amazing that these operations aren't getting pwn3d twice a week.
Seems that they don't have any other way to grant the technicians access to the server/my account, which is absolutely ridiculous.
bcrypt.genSalt(10, function(err, salt) {
if (err) return; //handle error
bcrypt.hash(clearPassword, salt, function(err, hash) {
if (err) return; //handle error
// Store hash in your password DB.
});
});edit: Looks like it depends on which version you use.
'npm install bcrypt'[1] gives a version which supports true async usage (via V8 async callbacks in native code)
'npm install bcrypt-nodejs'[2] gives a pure JS version which I linked to. Which is the top search result for 'nodejs bcrypt'
[0] - https://github.com/shaneGirish/bcrypt-nodejs/blob/master/bCr...
[1] - https://www.npmjs.com/package/bcrypt
There, the encryption is handled asynchronously, the event loop is yielded while the calculations take place in a C extension.
How does that look now?
Unfortunately a lot of people think that these functions are a simple way to "not have to deal with callbacks", which is not correct...
Is there any reason not to use the Sync functions if you're not writing a web server and don't particularly care for performance?
This may sound like "not a big deal", but even an operation that takes 1ms will cause noticeable lag at ~50 operations per second, and block everything approaching a thousand.
For emphasis: they block the entire event loop. Not a single request, not a single client, not a single operation or event. The entire application for every user everywhere.
"explain why you forgot your password"
I don't know why but that made me laugh.> Email addresses on Medium are case-sensitive.
Wow. Is there ever any possible benefit to this? (Serious question)
In practice, most email providers don't actually honor that, and so in practice it's a bad move. It is technically correct though.
I guess I never thought to look that up. Likely due to the common way being so pervasive.
> The local-part of a mailbox MUST BE treated as case sensitive. [0]
"the local-part MUST be interpreted and assigned semantics only by the host specified in the domain part of the address."
[1] at the bottom of this page: https://medium.com/the-story/signing-in-to-medium-by-email-a...
No it doesn't.
No issues with incognito mode.
- Private key is stored in a secure place. Offline for all i care; printed on a piece of paper; memorized and swallowed.
- When user creates the account - password is padded with salt, then a public key is used to encrypt it. The resulting encrypted form is stored, along with the salt.
- When user attempts to authenticate - the password that is provided is padded with the stored salt, encrypted with the public key and compared to the stored password.
Private key is never used when comparing passwords. Never available to the system doing authentication, etc.
The only purpose of using a reversible encryption - is to be able to switch to a different authentication provider completely transparently to the user.
I've implemented this functionality considering that we may need to switch over to active directory (or some other directory) in place of storing passwords in the database - but never used it, fearful that i would be committing some cardinal crime against proper security practices
Thoughts?
If you store it on the server alongside the encrypted password and salt, you're effectively using a bigger salt with a weird hashing algorithm that hasn't been vetted by any expert for the specific purpose of password storage.
If you store it on the client side, the user needs to supply the public key whenever he tries to authenticate. This has the effect of making the salt much bigger, but you don't need to use public keys to achieve the same effect. If you can trust the user to store a public key, you can trust him to store any large chunk of random bits.
So apart from the virtually useless fact that you might be able to decrypt the password with the private key (why would you even want to do that, instead of just resetting it?) your method seems to offer no real benefit compared to simply using larger salts with argon2/scrypt/bcrypt/whatever.
We are using RSA. The public key is on the server. We simply using RSA as a "hashing algo". Randomly generated salt is added to the password sent by the user to make the password (much) longer as well as strengthen it before the encryption takes place.
I have explained the reasons for storing the passwords (for the time being, hopefully temporarily) in other replies in this comment branch:
quote:
There's no argument from me regarding undesirability of keeping the passwords. But we also have a different concern - we don't want to be in the business of authentication at all - our goal is to have a third party service or appliance performing authentication and forwarding us already authenticated sessions with the user name as a header, for instance. Our desired end-state - is when we do not have any knowledge of or access to credentials used by the end-user.
To enable us to make this transition possible - for the time being we store the passwords, since as i explained in another reply, we must make this transition transparent to the users and we have legitimate users that login once a year (think credit report, just an example, not our business), so we can't intercept the credentials within a reasonable time period.
/quote
If you're switching to a non-password based system like OAuth, make users link their accounts after logging in with their password. If you are going to completely drop the password, then send each user an identifiable link where they can link their account.
Our system already went through a similar transition years ago - when we had to migrate away from NDS (Novell), since we abandoned that technology.
In NDS we did not have access to hashes. We ended up having to "MTM" the passwords in opur web app to intercept them before they are sent to NDS and after a successful login store them in the database. To transition our entire user base took a very long time (more than a year), since we had no way to compel the users to login and had to wait until they login on their own volition.
Ever since we've been reluctant to lose the ability to recover the passwords. Transition to Active Directory has been on our agenda for quite some time - and having the ability to decrypt the password for this purpose - we can make that happen in short order (AD hashes the passwords, so it will be a one-way operation of course).
But the question still stands - is asymmetric encryption strong and secure enough to take place of hashing, assuming the private key is secured? I have not been able to find any relevant sources to answer these questions.
It should be (though it's a big "assuming"). Being able to quickly move away from an older less secure hashing scheme rather than waiting for users to log in could be a security advantage too.
quote:
There's no argument from me regarding undesirability of keeping the passwords. But we also have a different concern - we don't want to be in the business of authentication at all - our goal is to have a third party service or appliance performing authentication and forwarding us already authenticated sessions with the user name as a header, for instance. Our desired end-state - is when we do not have any knowledge of or access to credentials used by the end-user.
To enable us to make this transition possible - for the time being we store the passwords, since as i explained in another reply, we must make this transition transparent to the users and we have legitimate users that login once a year (think credit report, just an example, not our business), so we can't intercept the credentials within a reasonable time period.
/quote
The approach i used applies salt. It can also pad the password to some standard length, if desired. Though it currently doesn't do that.
Slowness of the algo is perhaps a benefit in a way? In my testing it is still fast enough for our use (we are not facebook).
I would worry about trying to dual-purpose the encryption like this. If you feel like you must have a way to get the plaintext password back, which BTW you really really do NOT want that liability, but anyway, the safer choice would be to use a semantically secure encryption of the password, and then ALSO hash the password using the current best practices. Use the hash for now to authenticate users, keep the ciphertext if you must, but you'll probably regret it.
There's no argument from me regarding undesirability of keeping the passwords. But we also have a different concern - we don't want to be in the business of authentication at all - our goal is to have a third party service or appliance performing authentication and forwarding us already authenticated sessions with the user name as a header, for instance. Our desired end-state - is when we do not have any knowledge of or access to credentials used by the end-user.
To enable us to make this transition possible - for the time being we store the passwords, since as i explained in another reply, we must make this transition transparent to the users and we have legitimate users that login once a year (think credit report, just an example, not our business), so we can't intercept the credentials within a reasonable time period.
What i try to get out of the replies - is whether there's nothing immediately broken about using asymmetric encryption that endangers us aside from the understandable but not immediate concern about liability.
P.S: Earlier i mentioned "intercepting credentials" in our code - and wanted to highlight that the ease of doing that is precisely the reason why we really want to separate ourselves from handling credentials in any form.
How about this: User provides their public key when they signup. To authenticate, server produces a nonce and sends to the client, client signs the nonce with private key and sends the result, server verifies signature with public key.
What are your reasons to hold on to the password?
> ...
> The above construction may invite theoretical concerns about entropy reduction (i.e. 72 characters of raw binary without any NUL bytes comes out to about 573 bits of possible entropy, but a SHA-384 hash outputs are clearly limited to 384 bits).
Given BCrypt hashes are a mere 184 bits, I don't see how this is a meaningful concern even in principle. If you're brute-forcing search spaces this big you're no longer looking to recover a password, but find a collision.
This was added in response to a point that a couple people (or perhaps a convincing sockpuppeteer) raised and tried to use to decry the entire article. You're lucky to get 60 bits of information entropy in any given user's password, as is. The "theoretical weakening" here isn't a practical concern: "2^192 security" is still boring crypto.
https://blog.agilebits.com/2011/05/05/defending-against-crac...
In reality, PBKDF2 is fine. It's not the best thing you can use, in the same sense as AES is probably not the absolute best round-for-round, cycle-for-cycle cipher you can use, but it gets the job done.
The answer for "what password hash should I use" can accurately be summed as "put bcrypt, scrypt, Argon2, and PBKDF2 on a dartboard, and then throw a dart".
In 1PW's case, PBKDF2 is even more reasonable, because 1PW actually needed a KDF, and bcrypt is not an especially good KDF.
PBKDF2 is an improvement over PBKDF1 (and other naive iterated hash constructions), but attacks got better and better defenses are called for.
No, it really isn't.
You can create a worker system, or use a child process to solve this problem, but most of these articles never mention it
[1] https://github.com/ncb000gt/node.bcrypt.js#async-recommended
I wonder whether threading really saves you, given that there are only so many cores in a system and password hashing is CPU heavy. Naively it seems a DoS would involve sending as many parallel requests as there are cores, which is not a lot and can easily be done from a single machine.
Not serializing IO, but them stopping every worker just because one of them has some hard work to do is not a sane working model for web backends.
The one recommended in the article[0] actually includes a blowfish C++ binding, with both synchronous and asynchronous methods for comparing and hashing. That binding uses NAN[1] to queue AsyncWorkers. NAN uses libuv[2] behind the scenes to launch a thread[3].
0. https://www.npmjs.com/package/bcrypt
1. https://github.com/nodejs/nan
2. https://github.com/libuv/libuv
3. https://blog.scottfrees.com/building-an-asynchronous-c-addon...
Or you can do the bcrypt() inside your (PostgreSQL) database and add an extra layer of security by not directly exposing the hash (or even the whole password table) to the web server process (i.e. write a password check SQL function and allow only calling it, no direct table/column access).
I did exactly what you are suggesting on a project some time ago - deferred to the database to do the password hashing and comparison to the stored hash. Unfortunately, the server query logs contained the query parameters. So did some of the database logs when running at elevated log levels. We quickly decided that was unacceptable, and moved the hashing process into the web server.
Anybody here that knows if any of these is a valid replacement? https://nodejs.org/api/crypto.html
Unfortunately, the example used for the bcrypt node module is the async form of hashing. That library exports both sync and async forms of hash/compare.
New Samsung phones and Lenovo Laptops already support this on the fingerprint sencor but the true benefit is that you can have competition among local authenticators without the server having to change anything.
For legacy devices where you do not have any kind of local authenticator their could be local software that lets you enter passwords. Its already part of the standard that the server has a way to only allow some of the authenticators, based on certification. This would allow a bank to specifiy only devices manufactured by a specific company or that have passed some certification process.
Now some people of course say that fingerprint sensors are not very secure. That is true. It still increases security because the local authenticator will only sign the challenge if it is sent from the correct website/software (App Id) and in most cases the TLS Channel Id. UAF (and/or U2F) prevent far more common attacks at the cost of less security if an attacker actually steels your phone. You can combine UAF with U2F for additional security even if your phone/laptop is stolen.
This has been passed to the W3C and its hopped FIDO 2.0 will be an offical standard [2] [3].
Google, Github and Dropbox already support U2F. PayPal supports UAF (works on mobile). Both of these can also work with NFC and Bluetooth LE.
[1] https://fidoalliance.org/specifications/overview/
[2] https://fidoalliance.org/fido-alliance-announces-fido-authen...
[3] https://www.w3.org/Submission/2015/SUBM-fido-web-api-2015112...
These kinds of systems aren't technically very complex but there hasn't been a lot of traction for them outside of corporate environments. The result is that they tend to be hyper-expensive, unfortunately. Standards like FIDO and the Yubikey are good first steps at pushing this into the consumer space, although they don't offer on-device PIN validation yet.
The worst part for me would be loosing that thing, in the end i would need alternative login methods anyway to be sure i dont lock myself out.
Classic Authy on a Smartwatch would be the simplest method i could live with that comes to my mind.
I don't have a solution myself, but I hope there is one some day.
Is there something obvious I'm missing here?
hmac.compare_digest is a constant time compare, in that no matter if there is a match or not, it will take the same amount of time.
If the attacker knows which algorithm and work factor you're utilising and your system doesn't use randomly generated per user salts (or an unknown pepper) then theoretically an attacker could use a hash timing attack, combined with a rainbow table, to massively reduce the scope of a user's potential password.
For example, let's say your rainbow table has 20 million password-hash combinations and your hash length is 33 letters, for every letter I know I could drop literally millions of hashes I know it ISN'T. With just the first four letters I could drop it by almost 60% (although my maths here might be completely wrong, it is actually pretty complicated to determine). But there's no real limit on how many letters you could drop from the hash with a timing attack, you could turn someone's password into a 1 in 62 chance.
The TL;DR: Use a per user salt. But a timing immune comparison definitely is "defense in depth" in case there is a bug elsewhere that breaks salts.
Using == instead of hmac.compare_digest is unlikely to be a source of vulnerabilities in your application, but it's a good habit to get into whenever you touch cryptography.
See also: https://news.ycombinator.com/item?id=10345965 (pg. 33-36, 42-43 of the PDF)
Again consider timing leaks.
Many interesting questions:
How do secrets affect timings?
How can attacker see timings?
How can attacker choose inputs to influence how secrets affect timings?
Et cetera.
The boring-crypto alternative: crypto software is built from instructions
that have no data flow from inputs to timings.
Obviously constant time.So if the timing attack has told you that the first letter of the hashed version is 'A' then you find another password from the table that hashes to AAxxx, ABxxx, etc.
Obviously that depends on you being able to precompute all the passwords in a consistent way as the hash being used.
Along the same lines - could you use a timing attack to figure out a salt? I guess it's near impossible?
F("value") > "123455" which is close, but that does not let you get a 'better' guess.
PS: Assuming the Salt is hidden, and the Hash is secure.
I know this doesn't apply to banking, etc but 99% of the websites that "require" me to create an account and log in don't need to store primary credentials for me. Please pick a secure implementation of oAuth2 and let people store their credentials wherever the hell they want to.
I'm bored of getting hits from "Have I been pwned?"
> 99% of the websites that "require" me to create an account and log in don't need to store primary credentials for me
Why are you giving them valuable credentials? Give them a throw-away password (password managers are great for this).
A hybrid between the two (common OAuth-style endpoints and any OpenID endpoint) is the best solution for everybody.
That way users can be their own oAuth providers if they want.
It's hard to make a blanked recommendation like that, even for "only 99%" of websites. Neither you, nor the person building the website, has any insight into who the website's users trust.
Offer OAuth2 as an alternative to passwords: Great move.
Only offer OAuth2 and don't let people create an account: Questionable.
The "bindings for most programming languages" link goes to the libsodium documentation, but I'll add a link in more contexts.
There would appear to be three distinct Java bindings of libsodium.
https://docs.djangoproject.com/en/1.9/topics/auth/passwords/
Passwords should be scrypt'ed on client, and then, the server should generate a SHA256 hash of the scrypt'ed hash and store that in DB.
- Running CPU & memory heavy scrypt hashing on the client side will allow us to use bigger hashing work-loads.
- EDIT: Removing the MITM point, because as many said, that's the job of TLS anyway.
- External brute force attackers will have to take the burden of heavy hashing. No DOSing through scrypt.
- Storing SHA256 hash instead of scrypt hash on DB means even if DB is stolen, attackers can't use stolen scrypt hashes to authenticate any client.
I would love to get others' feedback on this. EDIT: Found the reference: https://news.ycombinator.com/item?id=9305504
Doesn't that scrypt hash then become the password, from the server-side application's perspective?
How are you storing the salt for the user if your server only knows about a SHA-256 hash.
> MITM attacks won't get access to unencrypted fields.
That's TLS's job. If you, for example, are building a web app and you're delivering Javascript to perform the scrypt calculation, a MitM can replace the code to exfiltrate the user's plaintext password. It doesn't make sense for the threat model.
Yes, the scrypt hash just becomes the password for the server. However, this password is going to be unique and almost impossible to guess. Salting this password on server side doesn't give us any additional benefits. The server can store the salt that the client used, though.
Yes, the MITM point was minor. Just another minor security benefit on top of TLS (which takes the majority of the burden of securing against it). So, maybe I shouldn't even mention this point.
I don't even your threat model.
Can you walk us through how you see this working?
Client takes 'crappypassword' as input, sends p = scrypt('crappypassword')
The server stores SHA256(p)?
EDIT: misread what you said. is this correct?
base64_encode(hash('sha384', $password, true))
In client side JavaScript. I've seen my own passwords scroll in front of my eyes when debugging servers and reading POST variables. It's a minor level of shoulder surf protection before it hits the proper hash on the server.Not sure how I feel about it.
How are the salts managed? This detail is important. SHA256(scrypt(password, constant_value_instead_of_salt)) is going to produce collisions in the stored hash.
Before you mention the salt - the salt is only useful if it if available. The client needs to know the salt in order to perform the calculation, therefore your attacker will also know the salt, so that doesn't count as entropy in the hash, either.
A MITM would let you hijack the JS that controls scrypt/SHA-256, so you're already at game over. You've got to deliver that to the user in some fashion (TLS!); this isn't a real win for your approach.
> External brute force attackers will have to take the burden of heavy hashing.
If the attacker is trying targeted access to a site the only thing that's relevant is the time they have to expend - the hash is opaque. If they have the hash from, say, a DB theft, they're already going to have to take that burden. Your approach doesn't seem to add anything.
> Storing SHA256 hash instead of scrypt hash on DB means even if DB is stolen, attackers can't use stolen scrypt hashes to authenticate any client.
I'm not sure what that means. If you steal my scrypt hash for example.net, how do you use that to authenticate me to example.net?
Your approach pushes out complexity to the clients and doesn't seem to win us anything.
algorith | fairly safe difficulty (all variables) | very safe difficulty without incurring too much performance cost.
pbkdf + sha1 | completely unsafe | completely unsafe
pbkdf + sha2 | 100000 | ...
pbkdf + sha256
bcrypt
scrypt
argon2
That's the problem with a chart like this. The gradation will go from "completely unsafe" salted hashes to "very much safe enough" with only marginal changes after that.
Another problem is that these functions are all parameterized, so the chart needs to capture the safety level at specific parameters.
algorith | a safe set of parameters | a VERY safe set of parameters but needs strong hardware
Maybe a 4th column of "unsafe if difficulty is below"
This could be something updated yearly or whatever to help people figure out what things they need to move towards. If they see that their currently used settings are below the unsafe line, they will know it's time to upgrade.
Example: I use PBKDF2-SHA1 at difficulty of 11k iterations. Is that number still within the "probably okay" list, or is that in the "I can hack any password on your list in 15 minutes"
[1] https://blog.afoolishmanifesto.com/posts/do-passwords-right/
1. Use the best option available, but
2. We provided example code in multiple languages for the
best one that's widely availableThere is an open issue in Coda Hale's bcrypt repo about this: https://github.com/codahale/bcrypt-ruby/pull/119
My stance on posting "best practice" articles is: you must follow all best practices in them.
<Edited for clarity>
Timing attacks depend on an attacker having control over the hash being compared (e.g. they have a HMAC in a cookie they're sending you, and they can adjust it character by character) - with randomised secret salts and server-side hashing, this isn't the case.
The SCrypt example is the one I'm more concerned with. The defaults there are 1MB of RAM and 64-bit salts, both of which could do with increasing. I have an open issue on this: https://github.com/pbhogan/scrypt/issues/25
As it is, the example would probably be better as this:
password = SCrypt::Password.create(usersPassword, salt_size: 32, max_mem: 16*1024*1024)
You'll be pleased to know SCrypt::Password#== is at least constant-time.Unfortunately, there's nothing I can do about that, unless someone can point me to an alternative that uses a constant-time comparison.
I've left a comment on the pull request so that, hopefully, it can be merged.
> (and likely others)
Which others?
I see your team is actively posting on the bcrypt-ruby issue #119 as we speak, so I guess I'd say wait for the PR to merge, or manually implement the approach they've outlined to secure compare: https://github.com/codahale/bcrypt-ruby/pull/119/files
It's worth spending the time to learn, implement, and integrate into the security best practices you should already be deploying.
Of course the core of it could be upgraded, but the idea is sound. Sounds like you could say the same thing about using a DES-based hash. "Don't Hash! It's weak!" is throwing the baby out with the bath water.
Most of this can be solved with SAML, but it requires all of these old enterprisey stacks to convert their auth systems to be SAML compatible.
In the long term though, I think SAML and OAuth will be more prevalent than using passwords everywhere.
Are there any OAuth providers established that simply provide email addresses? I feel there's definitely room for a company to setup an OAuth provider that doesn't do anything except provide identity, rather than relying on personal information harvester companies (FB, Google, etc). The hard part would be getting onto the approved OAuth providers list of all the sites that users want access to.
There's also the fact said systems seem to be a nice target for spammers. They're popular, so they're often attacked. And because they're often attacked, their anti spam defences don't usually last very long. So any spammer now has a nice way to get an account on near enough any site they like, while with a standalone system, they'd at least have to tailor their attacks to the site in question.
There's also the fact it silos much of the internet (or at least user information) within the systems of a few large providers, which gives a significant amount of control to said providers.
Yep, I do tailor the selection of oauth providers to my audience. E.g., an app for devs = google, github, and gitlab.
Don't. Unless it's 100% absolutely necessary.
If you must, continue reading on.
For many services, the most valuable data they contain happens to be the user credentials that the service uses to authenticate the identity of the user. If you assume that users share their credentials across multiple services, if your system is attacked, and you improperly stored their credentials, you've caused way more damage, than the data you were trying to secure.
For example, take your run of the mill online todo app. If an attacker got access to the all the todos, vs an attacker got access to the all the todos and all the user passwords (even if securely stored). What is more valuable to an attacker?
Generally: Being able to deploy malware through a site users trust so you can attack them directly, en masse.
But the password hashes are a good runner-up.
(Title is currently: "How to Safely Store a Password in 2016")
is that true?
Proprietary Analog Password Encryption Routines.