password hashing with courier + mysql

View: New views
6 Messages — Rating Filter:   Alert me  

password hashing with courier + mysql

by Joseph C. Lininger :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hello all,
This topic may have been discussed before, but I can't find a solution
via google or by searching through list archives. Perhaps one of you can
help me.

I'm using Courier MTA with mysql as the authentication back-end. As of
now, the passwords are hashed using the older DES based algorithm.
However, my crypt (3) implementation supports md5, as well as sha256 or
sha512 hashes. I'd like the passwords to be hashed using one of these
methods. In particular, if a user sets his password via sqwebmail I'd
like one of these newer hashing methods to be used. Is there a way to
make this happen? If not, can someone suggest alternatives such as
pointing me to where in the source code I'd need to look to modify this
behavior? Thank you in advance for your help.
- --
Those of you who think they know everything are very annoying to those
of us who actually do.
Joseph C. Lininger, <jbahm@...>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)

iQEcBAEBCAAGBQJKzZ5OAAoJEMh8jNraUiwqA4EH/2SFvZG5zvZMQVxWpH5EUH2p
TcUfOa2WNBcedoAHQzj6lcKTi1snfxWG35pBeHusRCrlzf0uCax69KzhOqRb+6eq
YWVGTnsZmwvZkxUXc10b407xPg9Fqq5NjRVWcf9O3x16HqfVxIdSzN8p1CWym7pA
iTGg/4whwG0s6gPgcCZEO1lA5TktDORy0ko+PXoAeRp6hiOO0P944URfcKC7bH+v
+fqsCSA8RPaCUnrLHyTi4WMmD5KWo43rJf8vG4LpE8v/7/HHIIST3xW5B6eRNyG9
7A2OBt35mjknTNqpo3aGacvjjDkx/Po5nNVbhepu1+1nIPzoqTr2n6BKj8LlQBM=
=YvQZ
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
courier-users mailing list
courier-users@...
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users

Re: password hashing with courier + mysql

by Sam Varshavchik :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Joseph C. Lininger writes:

> I'm using Courier MTA with mysql as the authentication back-end. As of
> now, the passwords are hashed using the older DES based algorithm.
> However, my crypt (3) implementation supports md5, as well as sha256 or
> sha512 hashes. I'd like the passwords to be hashed using one of these
> methods.

You'll need to manually set a password encoded using one of the supported
hash function. When changing a password, Courier will use the same hash
function as the existing password.



------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
courier-users mailing list
courier-users@...
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users

attachment0 (204 bytes) Download Attachment

Re: password hashing with courier + mysql

by Joseph C. Lininger :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Sam,

> You'll need to manually set a password encoded using one of the supported  hash function.
> When changing a password, Courier will use the same hash  function as the existing
> password.

I got it to work with the MD5 hashing method by manually setting a
password. However, if I try using the SHA512 hash, the one I'd really
prefer to use, it will authenticate fine with the password. However, if
I change it in sqwebmail, then it reverts to the DES based algorithm. I
get a hash string in the form {CRYPT}<DES hash>. Is this a Courier
thing, something with my setup, or a me thing?

To let you know what I did, I first used the encrypt function in mysql
to set the password on an account. I passed $6$ followed by 8 random
characters and the $ character as the salt argument to that function.
Then I checked the string in the table. Fine so far.

Then I set the password in sqwebmail and then checked it again in mysql.
Now is when the reverting back to DES based algorithm happened.

If I must use the MD5 based algorithm I will. But I'd really prefer
SHA256 or SHA512 if it can be done. Please advise?
- --
Those of you who think they know everything are very annoying to those
of us who actually do.
Joseph C. Lininger, <jbahm@...>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)

iQEcBAEBCAAGBQJKzdM3AAoJEMh8jNraUiwqIhQH/A9ipjdZQ5h40j5nBM49bM5t
4csLUw8+UntuNvIwpDbxEFbpiueaYaqpNeN+AanF1mTFBhSfpxdE+KWHo/wjuOHT
ztKVionemS8D8xyPJCY5UdI5E1VO3frPaXMy4+dTDg1aM4e/znzgpqpDWPwl8s9d
aNC18nqZwfjMUQ6TiQJQ13L4fV8Ryjs/3B0J14YOxADpHJDwIpIfsNC6wanmjqpI
9Sh2gD4lMegmoYWELzCrD7UeKmX+J0zqYPMyDzol9Rm4OJepQjy4MZ96wIZveMEs
p+ud8+CYJ/nAvva/lu0YecXkGhepwg1H/LL38HfRtg0AAsravshuUH3g1iqqEo0=
=DxzV
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
courier-users mailing list
courier-users@...
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users

Re: password hashing with courier + mysql

by Sam Varshavchik :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Joseph C. Lininger writes:

> I got it to work with the MD5 hashing method by manually setting a
> password. However, if I try using the SHA512 hash, the one I'd really
> prefer to use, it will authenticate fine with the password. However, if
> I change it in sqwebmail, then it reverts to the DES based algorithm. I
> get a hash string in the form {CRYPT}<DES hash>. Is this a Courier
> thing, something with my setup, or a me thing?
>
> To let you know what I did, I first used the encrypt function in mysql
> to set the password on an account. I passed $6$ followed by 8 random
> characters and the $ character as the salt argument to that function.
> Then I checked the string in the table. Fine so far.
Courier does not support this particular password encryption function. I'm
not sure're how you're even able to validate such a password. The only way
this might work is if you're using PAM to authenticate, with your PAM
library implementing support for this encryption method. However were this
to be the case, you should also be using PAM to set the password, via a
scripted expect session:
http://www.courier-mta.org/authlib/README_authlib.html#pwchange

This would also use your system PAM library to actually update your
password, which presumably would implement your encryption function.

So, I can't give you any more pointers since you did not adequately
described your configuration. All I can tell you is that Courier recognizes
$1${salt}$password, an MD5-based salted hashing (not a straight MD5 hash,
btw); {MD5}password, a base64-encoded straight MD5 hash; {MD5RAW}password, a
hexadecimal-encoded straight MD5 hash, {SHA}password, {SHA256}password and
{SHA512}password, a base64-encoded straight SHAx hash, {SSHA}password, a
base64-encoded salted SSHA1 hash method, and the legacy DES-based passwords.




------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
courier-users mailing list
courier-users@...
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users

attachment0 (204 bytes) Download Attachment

Re: password hashing with courier + mysql

by Joseph C. Lininger :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Sam,

> Courier does not support this particular password encryption function.
I'm  not sure're
> how you're even able to validate such a password. The only way  this
might work is
> if you're using PAM to authenticate, with your PAM  library
implementing support
> for this encryption method. However were this  to be the case, you
should also be
> using PAM to set the password, via a  scripted expect session:

I am not using pam for authentication in Courier. I'm using authmysql.
Probably the reason authentication works was pure luck, the way Courier
makes the crypt (3) call. The SHA512 based password hashing in my
implementation is compatible to an extent with the MD5 based algorithm
in wider circulation. Depending on exactly how Courier reads the
password string and processes it through crypt (3) it could likely work
without you ever intending for it to have done. Having it carry over to
password changes, now, that requires some handling. I'd be willing to
make the modifications and submit a patch if you'd be willing to point
me to a starting point in the code. I could find it myself, but as the
author if you told me where to look you'd shave a lot of time off the
analysis and modification time. I'll probably go ahead and make the
modifications and at least make the capability available through a
private patch even if you aren't interested in having it in the mainline
Courier distribution because I and some people I work with have a use
for it. If you want to use it though, I'll do the work to add it and
give it to you in the form of a patch.
- --
Those of you who think they know everything are very annoying to those
of us who actually do.
Joseph C. Lininger, <jbahm@...>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)

iQEcBAEBCAAGBQJKz332AAoJEMh8jNraUiwqEVMH/3ksCWKRCMfwe21DhPHKxDr4
PfKK+9U7sEfP9XhxkWlEogc+iFQdkgWT6kgG6/9ja0TEpJBdBVs6PJCFqB1XV47e
75duohtboyfVNzpQtZFZrNo67DTT7A14kp/pIry8eiriKsVn54J06Y1YEQKvl4mp
scGGgCGkIUxQE5s2Zqg7eB9QBjz1VxI6KCaaUTtKVFy152HIo7VN82fUcB6ezmUe
K2Duqy5srT0n3cDl9kdhYJ5TlsQ9SlIZx5v4eWTJIKX+qRLvucqx1zDFxgKH6hPr
Qh4ekl4CdxoQI3/ogmZqbNq9CxWxIyIh8Uy2UyRFI6n1WAL7Sdlebhy20roB2QQ=
=NKMR
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
courier-users mailing list
courier-users@...
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users

Re: password hashing with courier + mysql

by Sam Varshavchik :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Joseph C. Lininger writes:

> I am not using pam for authentication in Courier. I'm using authmysql.
> Probably the reason authentication works was pure luck, the way Courier
> makes the crypt (3) call. The SHA512 based password hashing in my
> implementation is compatible to an extent with the MD5 based algorithm
> in wider circulation. Depending on exactly how Courier reads the
> password string and processes it through crypt (3) it could likely work
> without you ever intending for it to have done. Having it carry over to
> password changes, now, that requires some handling. I'd be willing to
> make the modifications and submit a patch if you'd be willing to point
> me to a starting point in the code. I could find it myself, but as the
> author if you told me where to look you'd shave a lot of time off the
> analysis and modification time. I'll probably go ahead and make the
> modifications and at least make the capability available through a
> private patch even if you aren't interested in having it in the mainline
> Courier distribution because I and some people I work with have a use
> for it. If you want to use it though, I'll do the work to add it and
> give it to you in the form of a patch.
The problem is that Courier does not use crypt() to validate "$1$" formatted
passwords. It essentially reimplements the entire algorithm that computes
this hash. Except for the original crypt passwords, all hash functions are
implemented natively in Courier. At the time of the original implementation,
crypt() only did the crypt method, the new salted md5 passwords were
implemented separately in glibc. From what you're telling me, it looks like
all the hash functions have now been folded into crypt(), and that's how you
pull this off.

Implementing the new hash function within the existing framework is going to
be a bear. Reimplementing the entire $6$ algorithm will be an adventure. But
if you want to give it a shot:

All the password stuff is in the courier-authlib package. Verifying an
existing password is done in authcheckpassword(), in checkpassword.c.
Changing an existing password is implemented in authcryptpasswd(), in
cryptpassword.c.

This code is fairly old, but it works. If you want to take a shot in
cleaning it up, go for it.




------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
courier-users mailing list
courier-users@...
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users

attachment0 (204 bytes) Download Attachment