# MD5 authentication against Active Directory with ruby ldap

**URL:** <https://rubytalk.org/t/md5-authentication-against-active-directory-with-ruby-ldap/40106>\
**Category:** ruby-talk\
**Created:** [22 August 2007 04:02 UTC](https://rubytalk.org/t/md5-authentication-against-active-directory-with-ruby-ldap/40106 "2007-08-22T04:02:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Yang](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@James\_Yang](https://rubytalk.org/u/James_Yang)\
**Post date:** [22 August 2007 04:02 UTC](https://rubytalk.org/t/md5-authentication-against-active-directory-with-ruby-ldap/40106/1 "2007-08-22T04:02:30Z")

</div>

Here is the code:

> **···**
>
> ------------------------------------------
> 
> require 'ldap'  
> require 'base64'  
> require 'digest/md5'
> 
> &nbsp;&nbsp;pass = "{MD5}" + Base64.encode64(Digest::MD5.digest("secret") ).chomp  
> # pass='secret'  
> &nbsp;&nbsp;conn = LDAP::Conn.new( '[dc.domain.com](http://dc.domain.com)', 389 )  
> &nbsp;&nbsp;conn.set\_option( LDAP::LDAP\_OPT\_PROTOCOL\_VERSION, 3 )  
> &nbsp;&nbsp;conn.bind('admin@domain.com',pass)
> 
> ---------------------------------------------
> 
> The problem is it doesn't work with MD5 hashed password but it works  
> with the plain text password ('secret'). I really appreciate it if  
> somebody can help me out.
> 
> James  
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Francis\_Cianfrocca](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@Francis\_Cianfrocca](https://rubytalk.org/u/Francis_Cianfrocca)\
**Post date:** [22 August 2007 11:41 UTC](https://rubytalk.org/t/md5-authentication-against-active-directory-with-ruby-ldap/40106/2 "2007-08-22T11:41:29Z")

</div>

This makes sense. LDAP directories store password hashes instead of  
passwords to make it impossible for anyone who has access to the directory's  
datastore (like a programmer, a sysadmin, a backup admin, or a hacker) to  
get enough information to be able to bind.

If you could actually bind using a password hash, then the hashes stored in  
the directory itself would in effect be plaintext, which defeats the whole  
purpose.

> **···**
>
> On 8/22/07, James Yang \<macinux@gmail.com\> wrote:
> 
> > Here is the code:
> > 
> > ------------------------------------------
> > 
> > require 'ldap'  
> > require 'base64'  
> > require 'digest/md5'
> > 
> > &nbsp;&nbsp;pass = "{MD5}" + Base64.encode64(Digest::MD5.digest("secret") ).chomp  
> > # pass='secret'  
> > &nbsp;&nbsp;conn = LDAP::Conn.new( 'dc.domain.com', 389 )  
> > &nbsp;&nbsp;conn.set\_option( LDAP::LDAP\_OPT\_PROTOCOL\_VERSION, 3 )  
> > &nbsp;&nbsp;conn.bind('admin@domain.com',pass)
> > 
> > ---------------------------------------------
> > 
> > The problem is it doesn't work with MD5 hashed password but it works  
> > with the plain text password ('secret'). I really appreciate it if  
> > somebody can help me out.
> > 
> > James  
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![James\_Yang](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@James\_Yang](https://rubytalk.org/u/James_Yang)\
**Post date:** [22 August 2007 21:12 UTC](https://rubytalk.org/t/md5-authentication-against-active-directory-with-ruby-ldap/40106/3 "2007-08-22T21:12:08Z")

</div>

Thanks Francis, but I am still confused. what you mean we have to use  
password in plain text to bind with Active Directory? Because the  
password would be saved in a configuration file, which is vulnerable.  
I'd like to save the hashed password in the configuration to bind with  
AD. I just changed the group policy on AD to allow "store passwords  
using reversible encryption" But it still takes the plain text binding  
and gives the error to the MD5 hashed password.

Francis Cianfrocca wrote:

> **···**
>
> > On 8/22/07, James Yang \<macinux@gmail.com\> wrote:
> > 
> > > # pass='secret'  
> > > James  
> > > --  
> > > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
> > 
> > This makes sense. LDAP directories store password hashes instead of  
> > passwords to make it impossible for anyone who has access to the  
> > directory's  
> > datastore (like a programmer, a sysadmin, a backup admin, or a hacker)  
> > to  
> > get enough information to be able to bind.
> > 
> > If you could actually bind using a password hash, then the hashes stored  
> > in  
> > the directory itself would in effect be plaintext, which defeats the  
> > whole  
> > purpose.
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Francis\_Cianfrocca](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@Francis\_Cianfrocca](https://rubytalk.org/u/Francis_Cianfrocca)\
**Post date:** [23 August 2007 02:06 UTC](https://rubytalk.org/t/md5-authentication-against-active-directory-with-ruby-ldap/40106/4 "2007-08-23T02:06:56Z")

</div>

If you saved a password-hash in a configuration file, and it were possible  
to bind with the password-hash, then the hash is in effect plaintext. You're  
not adding any security by using a hash in that circumstance. This is a  
difficult problem. If you're trying to enable an automatic login without any  
kind of authentication transaction involving a challenge, then somewhere  
along the way you will have a sensitive resource that you have to protect as  
best you can.

> **···**
>
> On 8/22/07, James Yang \<macinux@gmail.com\> wrote:
> 
> > Thanks Francis, but I am still confused. what you mean we have to use  
> > password in plain text to bind with Active Directory? Because the  
> > password would be saved in a configuration file, which is vulnerable.  
> > I'd like to save the hashed password in the configuration to bind with  
> > AD. I just changed the group policy on AD to allow "store passwords  
> > using reversible encryption" But it still takes the plain text binding  
> > and gives the error to the MD5 hashed password.

---

<div class="post-metadata">

**Author:** ![James\_Yang](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@James\_Yang](https://rubytalk.org/u/James_Yang)\
**Post date:** [23 August 2007 03:17 UTC](https://rubytalk.org/t/md5-authentication-against-active-directory-with-ruby-ldap/40106/5 "2007-08-23T03:17:23Z")

</div>

It is still confusing to me. I wonder if it is true that a plaintext  
password would be transfered over the network in the case that we use  
the plaintext password to bind with AD. If this is correct, there is no  
security. I guess there should be an efficient way to work it out.

James

Francis Cianfrocca wrote:

> **···**
>
> > On 8/22/07, James Yang \<macinux@gmail.com\> wrote:
> > 
> > > Thanks Francis, but I am still confused. what you mean we have to use  
> > > password in plain text to bind with Active Directory? Because the  
> > > password would be saved in a configuration file, which is vulnerable.  
> > > I'd like to save the hashed password in the configuration to bind with  
> > > AD. I just changed the group policy on AD to allow "store passwords  
> > > using reversible encryption" But it still takes the plain text binding  
> > > and gives the error to the MD5 hashed password.
> > 
> > If you saved a password-hash in a configuration file, and it were  
> > possible  
> > to bind with the password-hash, then the hash is in effect plaintext.  
> > You're  
> > not adding any security by using a hash in that circumstance. This is a  
> > difficult problem. If you're trying to enable an automatic login without  
> > any  
> > kind of authentication transaction involving a challenge, then somewhere  
> > along the way you will have a sensitive resource that you have to  
> > protect as  
> > best you can.
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Francis\_Cianfrocca](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@Francis\_Cianfrocca](https://rubytalk.org/u/Francis_Cianfrocca)\
**Post date:** [23 August 2007 11:33 UTC](https://rubytalk.org/t/md5-authentication-against-active-directory-with-ruby-ldap/40106/6 "2007-08-23T11:33:04Z")

</div>

Yes, the plaintext psw is transferred over the network, whether the  
plaintext is some readable passphrase or an MD5 (or other) hash. Use  
encryption for the network connection.

> **···**
>
> On 8/22/07, James Yang \<macinux@gmail.com\> wrote:
> 
> > It is still confusing to me. I wonder if it is true that a plaintext  
> > password would be transfered over the network in the case that we use  
> > the plaintext password to bind with AD. If this is correct, there is no  
> > security. I guess there should be an efficient way to work it out.

---

<div class="post-metadata">

**Author:** ![James\_Yang](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@James\_Yang](https://rubytalk.org/u/James_Yang)\
**Post date:** [23 August 2007 13:41 UTC](https://rubytalk.org/t/md5-authentication-against-active-directory-with-ruby-ldap/40106/7 "2007-08-23T13:41:38Z")

</div>

Thanks. next question is how to encrypt the network connection with AD  
for binding process. Here is the result for ldapsearch.

> **···**
>
> -----------------------------------------------------------------------  
> ldapsearch -h AD -p 389 -x -b "" -s base -LLL supportedSASLMechanisms  
> dn:  
> supportedSASLMechanisms: GSSAPI  
> supportedSASLMechanisms: GSS-SPNEGO  
> supportedSASLMechanisms: EXTERNAL  
> supportedSASLMechanisms: DIGEST-MD5
> 
> Francis Cianfrocca wrote:
> 
> > On 8/22/07, James Yang \<macinux@gmail.com\> wrote:
> > 
> > > It is still confusing to me. I wonder if it is true that a plaintext  
> > > password would be transfered over the network in the case that we use  
> > > the plaintext password to bind with AD. If this is correct, there is no  
> > > security. I guess there should be an efficient way to work it out.
> > 
> > Yes, the plaintext psw is transferred over the network, whether the  
> > plaintext is some readable passphrase or an MD5 (or other) hash. Use  
> > encryption for the network connection.
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Francis\_Cianfrocca](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@Francis\_Cianfrocca](https://rubytalk.org/u/Francis_Cianfrocca)\
**Post date:** [23 August 2007 13:55 UTC](https://rubytalk.org/t/md5-authentication-against-active-directory-with-ruby-ldap/40106/8 "2007-08-23T13:55:07Z")

</div>

Ask your A/D admin what encryption options are available on that A/D.  
Sometimes there is no encryption because Windows domain logins use a  
derivative of Kerberos which Microsoft advertises to be secure.

If you use ldapsearch, the man pages will tell you how to dial encryption  
into the client. For Ruby clients, Net::LDAP definitely supports TLS  
encryption. I'm 99% sure that ruby/ldap does as well.

> **···**
>
> On 8/23/07, James Yang \<macinux@gmail.com\> wrote:
> 
> > Thanks. next question is how to encrypt the network connection with AD  
> > for binding process. Here is the result for ldapsearch.
