45 points · by todsacerdoti · 6y ago · 23 comments
“I included emoji in my password and now I can’t log on to Yosemite”
https://docs.microsoft.com/en-us/previous-versions/windows/d...
Also note:
"Use this function instead of ZeroMemory when you want to ensure that your data will be overwritten promptly, as some C++ compilers can optimize a call to ZeroMemory by removing it entirely."
Managing passwords is tricky.
Edit: answering: "I don't see the post talking about zeroing memory anywhere?": Exactly. But it uses "free".
free(wbuf);
It is freed without being zeroed. Without demonstrating freeing, and without having the "clean up" part it would not matter. With it, and the given context (writing about using APIs to handle passwords), it does matter, and you should care too. Even more so if you a) aren't aware of the possibility of the compiler optimizations b) haven't even thought about the possible "leaking" issues.I much prefer alphanumeric only passwords to passwords that are required to have weird symbols.
However UTF8 passwords is a recipe for disaster that I want no part of. Passwords should be random byte strings, not a random piece of human language. Now technically alphanumeric isn't quite the same as a random byte-string but it is the one subset of text for which you can be almost certain that it will always be represented by the same bytes (although I suspect someone will point out an exception).
Note that not only does Unicode have several different binary representations, but even a sequence of code points has 4 different canonicalizations, that I cannot guarantee will always remain the same.
You'll need to get things into the right encoding (as the article states, UTF-16 is alive and well in some places, and there are two forms of that), and you'll probably need to do unicode normalization for some languages, because not every system will do that the same. But, normalization rules change over time, so you'll need to include the normalization used with the password processing code and storage.
sh -c "read -s PASS && echo $PASS"
I'm pretty sure it supports UTF-8 (only because I never heard otherwise. It does require Git to be installed on Windows for sh.exe but that was a prerequisite for our CLI anyways.That's the wrong reason to pick int over size_t. Am I missing something?
(EDIT) Especially since he calls it this way in the sample:
int len = read_password(password, sizeof(password), "password: ");
Maybe it's because it only reads up to PASS_MAX bytes, although glibc does not suffer from this limitation...