4 ms·
Yes they are secret, which is why databases usually don't store them, they store a salted hash. The secret , the key in a sense, is in the users head, or passw
by michelpp 6y ago
Yes they are secret, which is why databases usually don't store them, they store a salted hash. The secret , the key in a sense, is in the users head, or password manager I guess these days. An attacker cannot get the password from a correctly hashed and encrypted password because that information is not in there.
This is different than storing a key in the database that can turn encrypted data into unencrypted data. This is what I meant by not storing secrets. Instead of storing keys, pgsodium use encourages storing key ids (of a given length in a context). These keys can be used to reveal plaintext, so they shouldn't be stored but only derived.
So the trick to avoiding storing keys is to store the key id and derive the key, being careful not to leak it in the logs. This can be done by passing it directly from pgsodium_derive() straight into a function that takes a key. I'm considering adding a "mirror" api that doesn't take bytea keys but instead only key ids and always derives. I'm still kicking that idea around.
But your point is good, I should be less cavalier with my definitions of secret and key. I'm working on improvement for the "encrypted column" section that will explain more of this, and show how pgsodium can work in hand with Row Level Security. Stay tuned.
- Varriount 6y agoAh, I should have added "salted" to my original description. What are your opinions of the `crypt` and `gen_salt` functions from the pgcrypto module[0]? https://www.postgresql.org/docs/current/pgcrypto.html#id-1.11.7.34.6 https://www.postgresql.org/docs/current/pgcrypto.html#id-1.1...
- michelpp 6y agoThey're just fine, they do the job. Note that in PostgreSQL 10 they updates the user password storage and challenge mechanism to SCRAM https://info.crunchydata.com/blog/how-to-upgrade-postgresql-passwords-to-scram https://info.crunchydata.com/blog/how-to-upgrade-postgresql-...