Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to turn on SecureSocketLayer with DirectoryServices.Protocols.LdapConnection

I am trying to fix a bug with SSL in a product and noticed that although the code sets SSL to be true, in the next line in the code SSL is still at false. I wrote a unit test for this and the unit test confirms my suspicions.

  [TestMethod]
  public void SecureSocketLayerSetToTrue( )
  {
     var ldapConnection = new LdapConnection( 
                                new LdapDirectoryIdentifier( "ldap.test.com", 636 ));
     ldapConnection.SessionOptions.SecureSocketLayer = true;
     Assert.IsTrue( ldapConnection.SessionOptions.SecureSocketLayer );
  }

The test fails. Is there something here that I am missing?

like image 347
Jared Avatar asked Nov 10 '08 14:11

Jared


1 Answers

It turns out that the way that the DirectoryServices.Protocols implements it's LDAP calls is by passing them through to a low-level LDAP API. This LDAP API is what is queried when a get is done on the property.

The low-level API is only updated when the methods are executed. You can think about this like it is building command-line arguments for an executable that hasn't been launched yet.

When a call like Bind() is made, then the executable is launched and the properties will report the correct value.

So, just because the property was saying that the value was false, it was using the true when necessary.

like image 66
Jared Avatar answered Oct 14 '22 22:10

Jared