none
PowerShell to connect to an OpenLDAP server over SSL RRS feed

  • Question

  • Hi, scripting guys !

    I try to connect to an OpenLDAP server (Linux) using LDAPS (LDAP over SSL) from a Windows-Server 2012r2 using Powershell. It seems a simple thing, but I cannot make it work. I searched the Internet for clues, but the answers given are not working (most of the post are about connecting to an AD server with LDAPS). It would be just great if someone could help me out in here !

    My final goal is to connect using a user/password with LDAPS. But as a first step, I am trying to connect anonymously. Of course, I have tested with an LDAP browser that anonymous LDAPS connections are allowed on this server, just to be sure... Here is my code

    $ServerName = "xxx" $Port = 636 $dn = "$ServerName"+":"+"$Port"  $c = New-Object System.DirectoryServices.Protocols.LdapConnection $dn $c.SessionOptions.SecureSocketLayer = $True $c.SessionOptions.ProtocolVersion = 3 $c.AuthType = [System.DirectoryServices.Protocols.AuthType]::Anonymous 

    $c.Bind()

    It does not work. I have a message "LDAP server unavailable".

    If I use port 389 and set SecureSocketLayer to $False, the same code works (the server accepts both LDAP and LDAPS connection, for anonymous user).



    • Edited by Larhape Wednesday, August 14, 2019 4:52 PM
    Wednesday, August 14, 2019 4:51 PM

All replies

  • Does that same code work against a Windows domain controller?

    -- Bill Stewart [Bill_Stewart]

    Wednesday, August 14, 2019 6:25 PM
    Moderator
  • Either the port is wrong or unavailable. Try not using SSL.

    Check firewalls for the required port.  Be sure you have the correct protocols enabled in your system

    [Net.ServicePointManager]::SecurityProtocol


    \_(ツ)_/

    Wednesday, August 14, 2019 6:30 PM
  • Good question, I will try this, and send the results. Actually, I did not try because AD controllers can be accessed much more easily with cmdlet.
    12 minutes ago
  • It works without SSL, with the same server. But the thing is that authenticated connections are disallowed if SSL is not used. Only anonymous connections are allowed without SSL, that's why I need to connect with SSL. I don't think there is a firewall blocking anything on the way.
    9 minutes ago
  • Either the port is wrong or unavailable. Try not using SSL.

    Check firewalls for the required port.  Be sure you have the correct protocols enabled in your system

    [Net.ServicePointManager]::SecurityProtocol


    \_(ツ)_/

    Here is what I have with this command

    [Net.ServicePointManager]::SecurityProtocol
    Ssl3, Tls

    6 minutes ago