How can I tell what algorithms my library supports?
Does anyone have an example perl_auth program I could reference that
supports more modern encrypted storage of passwords?
I have a small set of users and do not want to use PAM or system
auth. The crypt implementation used by ckpasswd -f, is, well, extremely
old.
Jesse Rehmer <jesse.rehmer@blueworldhosting.com> writes:
Does anyone have an example perl_auth program I could reference that
supports more modern encrypted storage of passwords?
I have a small set of users and do not want to use PAM or system
auth. The crypt implementation used by ckpasswd -f, is, well, extremely
old.
ckpasswd -f just uses crypt, so it will use as modern of a password
hashing algorithm as your libc or libcrypt supports. Generally this is configured by the prefix of the hashed password. For example, on Linux,
you can use hashes starting with $y$ to use yescrypt, which is about as modern as you could possibly want.
This is therefore entirely up to how you set the passwords in the file
that you're pointing to with ckpasswd -f, which is a bit outside what INN deals with. It's quite possible that htpasswd, for example, won't
generate one of the newer hash types.
Jesse Rehmer <jesse.rehmer@blueworldhosting.com> writes:
How can I tell what algorithms my library supports?
man 3 crypt should hopefully tell you what the available hash algorithms
are. You'll need something that writes the password file, though (or use passwd to set a password for a system user and then copy and paste the
hash from /etc/shadow, which I've done in a pinch).
https://man.freebsd.org/cgi/man.cgi?crypt(3) seems to imply nothing better than SHA-512 is supported, which is a bit surprising.
Jesse Rehmer <jesse.rehmer@blueworldhosting.com> writes:
How can I tell what algorithms my library supports?
man 3 crypt should hopefully tell you what the available hash algorithms
are. You'll need something that writes the password file, though (or use passwd to set a password for a system user and then copy and paste the
hash from /etc/shadow, which I've done in a pinch).
https://man.freebsd.org/cgi/man.cgi?crypt(3) seems to imply nothing better than SHA-512 is supported, which is a bit surprising.
Auth works if I use the following for MD5:
openssl passwd -1 -salt xyz somepassword
Or the following for SHA512:
openssl passwd -6 -salt xyz somepassword
How can I tell what algorithms my library supports?
man 3 crypt should hopefully tell you what the available hash algorithms
are.
https://man.freebsd.org/cgi/man.cgi?crypt(3) seems to imply nothing better >> than SHA-512 is supported, which is a bit surprising.
Auth works if I use the following for MD5:
openssl passwd -1 -salt xyz somepassword
Or the following for SHA512:
openssl passwd -6 -salt xyz somepassword
In case OpenSSL is not installed on your server, you can also use
the following Perl command which does the same job:
% perl -le "print crypt('pass', '\$5\$UIhtJSBOaC0Ap3Vk\$');"
$5$UIhtJSBOaC0Ap3Vk$nbKgmykshoQ2HmvA3s/nI.X4uhhNHBKTYhBS3pYLjJ6
As Perl makes use of crypt(3), you have access to all available
hashing schemes on your systems (like yescript, if supported). Make
sure to use a random salt.
% perl -le "print crypt('pass', '\$y\$j9T\$YourSalt\$');"
$y$j9T$YourSalt$X4tB48vKNDT6mK0vNOc7ppKPWvEsyMg5LwoQfO50r2A
Hi Jesse and Russ,
Thanks for this discussion, it was pretty interesting.
I'll remove the mention of htpasswd from the ckpasswd man page, and modernize the wording.
Here is what I came up with. I hope it will be of help for other people looking at how to generate passwords.
-f filename
Read passwords from the given file rather than using getpwnam(3).
Each line of the file should look something like:
username:$5$Hlb2yXPd$2nOO/QR9P1mnRFr/i6L9ybxbgSDXd4UlatKqbcY4eoB
joe:FCjOJnpOo50IE:Old weak hash algorithm used for Joe
Each line has at least two fields separated by a colon. The first
field contains the username; the second field contains a password
hashed with the crypt(3) function. Additional colons and data may
appear after the encrypted password; that data will be ignored by
ckpasswd. Lines starting with a number sign ("#") are ignored.
INN does not come with a utility to create the encrypted passwords,
but OpenSSL can do so and it's also a quick job with Perl (see the
one-line example script below).
A line in *filename* for the user "user" with the password "pass"
would be "user:" followed with the output of the following command
using SHA-256 as hashing scheme:
% openssl passwd -5 pass
$5$UIhtJSBOaC0Ap3Vk$nbKgmykshoQ2HmvA3s/nI.X4uhhNHBKTYhBS3pYLjJ6
See the openssl-passwd(1) man page for the list of hashing schemes
it can generate. You must take one that your system crypt(3)
function handles (type "man 3 crypt" or "man 5 crypt" to find the
supported hashing schemes).
In case OpenSSL is not installed on your server, you can also use
the following Perl command which does the same job:
% perl -le "print crypt('pass', '\$5\$UIhtJSBOaC0Ap3Vk\$');"
$5$UIhtJSBOaC0Ap3Vk$nbKgmykshoQ2HmvA3s/nI.X4uhhNHBKTYhBS3pYLjJ6
As Perl makes use of crypt(3), you have access to all available
hashing schemes on your systems (like yescript, if supported). Make
sure to use a random salt.
% perl -le "print crypt('pass', '\$y\$j9T\$YourSalt\$');"
$y$j9T$YourSalt$X4tB48vKNDT6mK0vNOc7ppKPWvEsyMg5LwoQfO50r2A
In case OpenSSL is not installed on your server, you can also use
the following Perl command which does the same job:
% perl -le "print crypt('pass', '\$5\$UIhtJSBOaC0Ap3Vk\$');"
$5$UIhtJSBOaC0Ap3Vk$nbKgmykshoQ2HmvA3s/nI.X4uhhNHBKTYhBS3pYLjJ6
As Perl makes use of crypt(3), you have access to all available
hashing schemes on your systems (like yescript, if supported). Make
sure to use a random salt.
% perl -le "print crypt('pass', '\$y\$j9T\$YourSalt\$');"
$y$j9T$YourSalt$X4tB48vKNDT6mK0vNOc7ppKPWvEsyMg5LwoQfO50r2A
Where I got tripped up was using "htpasswd -m", which according toThanks for having raised the possible problem. At least it permitted modernizing the documentation for ckpasswd.
its man page produces MD5 hashes so I assumed it would work, but the
output wasn't working with nnrpd, so I thought it had to be a deeper
issue with crypto> libraries/support.
Minor Perl syntax nit to avoid the backslashes:Yes, it's more readable this way, thanks!
% perl -le 'print crypt("pass", q{$5$YourSalt$})' > $5$YourSalt$V5hqwFg1nhKb5as6md9KTe5b2NyavsMS6dBYVKfp5W7
It may be worth mentioning that the opaque "j9T" string in theOK. I also did not find in CPAN a module dealing with yescript or more generally with crypt options.
yescrypt example is generated with crypt_gensalt(3), and what
parameters generated it. (I'm not sure if Perl has an easy interface
to that.)
For perl however, it is not really clear to beginners) what is the salt
which must be changed/RANDOM, and what are the fixed elements, especially as one example users random string, and another human-readable version. (and yescript example having extra unexplained paramtered 'j9T')
I'd suggest:
- changing actual salt in *both* perl examples to "YourRandomSalt"
- clarifiying in documentation that only "pass" (your password) and
"YourRandomSalt" (random string which should be different for EACH
user) parts of the commands should be changed, and all the rest be left
as-is.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 13:11:41 |
Calls: | 10,389 |
Calls today: | 4 |
Files: | 14,061 |
Messages: | 6,416,887 |
Posted today: | 1 |