Issue 6826 - Apache htpasswd MD5 support [patch]
Summary: Apache htpasswd MD5 support [patch]
Status: VERIFIED FIXED
Alias: None
Product: OpenLDAP
Classification: Unclassified
Component: contrib (show other issues)
Version: 2.4.23
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: OpenLDAP project
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-04 21:51 UTC by djpohly@gmail.com
Modified: 2014-08-01 21:03 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description djpohly@gmail.com 2011-02-04 21:51:40 UTC
Full_Name: Devin J. Pohly
Version: 2.4.23
OS: Linux
URL: http://openldap.pastebin.com/t4jWaUfe
Submission from: (NULL) (75.102.64.250)


== Proposed enhancement ==
When migrating an Apache .htpasswd-based system to LDAP authentication, it would
be nice if the password hashes would migrate cleanly.  .htpasswd uses three hash
formats: {SHA}, {CRYPT}, and "apr1", an MD5-based variant not supported by
OpenLDAP.

If OpenLDAP had a hash which was equivalent to (i.e. could be freely converted
to and from) Apache's apr1, conversion would be easy.

== Solution ==
If you're willing to have OpenLDAP depend on APR-Util, it would be trivial to
use the apr_md5_encode and apr_password_validate functions to support this
hash.

If not, I created a patch [1] which implements the apr1 hash.  The algorithm is
the same as PHK MD5 with a different magic number.  I derived the code from the
PHK source which is freely usable under the Beer-ware license (see patch).  This
patch adds an {APR1} hash type to OpenLDAP when configured with --enable-apr1.

[1] http://openldap.pastebin.com/t4jWaUfe

(Note: patch is against release, but passwd.c has not changed significantly in
HEAD.)

== Discussion ==
The patch has held up to my (limited) testing, but it could probably be written
better.  It might be useful to put the algorithm into its own function or file,
since it's fairly complex and used in both the chk_apr1 and hash_apr1 functions.
 It might also be useful to specify the magic number to the functions; then we
would get PHK $1$ hashes for free.

Apache selects salts with 48 bits of randomness but treats them as 64-bit salts.
 The lines referring to apr64[] replicate this behavior for backward
compatibility (so {APR1} hashes generated by slappasswd can be converted to
.htpasswd).  If you're not concerned about being able to convert in the opposite
direction, that code can be removed, and OpenLDAP can then use any size salt.

== Tools ==
The hashes are stored in OpenLDAP's base64(hash + salt) format for consistency. 
I put together a couple pipe-able scripts for converting between Apache's $apr1$
and OpenLDAP {APR1} formats:
Apache to OpenLDAP: http://openldap.pastebin.com/0SSbzjhH
OpenLDAP to Apache: http://openldap.pastebin.com/rfLBRASr
Comment 1 Howard Chu 2011-02-04 23:58:11 UTC
New password hash mechanisms should simply be implemented as standalone 
modules for inclusion under contrib/slapd-modules. See 
contrib/slapd-modules/passwd for existing examples.

-- 
   -- Howard Chu
   CTO, Symas Corp.           http://www.symas.com
   Director, Highland Sun     http://highlandsun.com/hyc/
   Chief Architect, OpenLDAP  http://www.openldap.org/project/

Comment 2 djpohly@gmail.com 2011-02-06 08:19:19 UTC
Alright, I have created a file contrib/slapd-modules/passwd/apr1.c which 
implements this hash:

http://openldap.pastebin.com/r2GzfveB

I have tested it and confirmed that it works on several passwords 
converted from an htpasswd file using the atol.pl script above.

Comment 3 Howard Chu 2011-02-06 16:15:11 UTC
changed notes
changed state Open to Test
moved from Incoming to Contrib
Comment 4 Howard Chu 2011-02-07 00:15:45 UTC
djpohly@gmail.com wrote:
> Alright, I have created a file contrib/slapd-modules/passwd/apr1.c which
> implements this hash:
>
> http://openldap.pastebin.com/r2GzfveB
>
> I have tested it and confirmed that it works on several passwords
> converted from an htpasswd file using the atol.pl script above.

Thanks, added to HEAD with additional changes.

-- 
   -- Howard Chu
   CTO, Symas Corp.           http://www.symas.com
   Director, Highland Sun     http://highlandsun.com/hyc/
   Chief Architect, OpenLDAP  http://www.openldap.org/project/

Comment 5 Quanah Gibson-Mount 2011-11-04 19:05:36 UTC
changed notes
changed state Test to Release
Comment 6 Quanah Gibson-Mount 2011-11-28 18:33:22 UTC
changed notes
changed state Release to Closed
Comment 7 OpenLDAP project 2014-08-01 21:03:29 UTC
Added in HEAD
Added in RE24