AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Umstellung LDAP auf SSL/TLS

Ein Thema von Blup · begonnen am 17. Mai 2024 · letzter Beitrag vom 21. Mai 2024
Antwort Antwort
Seite 1 von 2  1 2      
Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.441 Beiträge
 
Delphi 10.4 Sydney
 
#1

Umstellung LDAP auf SSL/TLS

  Alt 17. Mai 2024, 12:19
Ich versuche eine vorhandene Anwendung von LDAP zu LDAPS umzustellen.

Derzeitiges Problem: Fehlermeldung bei der Abfrage der Option LDAP_OPT_SSL.
Als Ergebnis bekomme ich einen Code der mit ldap_err2string als "Parameterfehler" zurück gibt.
Delphi-Quellcode:
FConn: Pointer;
FSSL: Pointer;
FVersion: Integer;

  TriggerProtocol(Self, 'Initialize an LDAP session using SSL');
  fConn := ldap_sslinit(PChar(fHost), fPort, 1);

  try
    FVersion := LDAP_VERSION3;
    TriggerProtocol(Self, Format('Setting Protocol version to %d', [FVersion]));
    LDAPCheck(ldap_set_option(fConn, LDAP_OPT_PROTOCOL_VERSION, @FVersion));

    TriggerProtocol(Self, 'Checking if SSL is enabled');
    FSSL := LDAP_OPT_OFF;
    LDAPCheck(ldap_get_option(fConn, LDAP_OPT_SSL, FSSL));
    TriggerProtocol(Self, IfThen(FSSL = LDAP_OPT_ON, 'SSL is enabled', 'SSL not enabled'));

    if FSSL <> LDAP_OPT_ON then
    begin
      TriggerProtocol(Self, 'SSL being enabled...');
      FSSL := LDAP_OPT_ON;
      LDAPCheck(ldap_set_option(fConn, LDAP_OPT_SSL, FSSL));
    end;
Das Protokoll:
Code:
Initialize an LDAP session using SSL
Setting Protocol version to 3
Checking if SSL is enabled
Parameterfehler
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
229 Beiträge
 
#2

AW: Umstellung LDAP auf SSL/TLS

  Alt 17. Mai 2024, 12:45
Delphi-Quellcode:
    //LDAPCheck(ldap_get_option(fConn, LDAP_OPT_SSL, FSSL));
    LDAPCheck(ldap_get_option(fConn, LDAP_OPT_SSL, @FSSL)); ??
Also notice that FSSL and FVersion should be NativeUInt.
  Mit Zitat antworten Zitat
Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.441 Beiträge
 
Delphi 10.4 Sydney
 
#3

AW: Umstellung LDAP auf SSL/TLS

  Alt 17. Mai 2024, 13:04
@FSSL

Das gibt "Lokaler Fehler".
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
229 Beiträge
 
#4

AW: Umstellung LDAP auf SSL/TLS

  Alt 17. Mai 2024, 15:30
@FSSL

Das gibt "Lokaler Fehler".
At least it is not a parameter error any more, i would suggest to follow Microsoft example and find the missing step leading to this.

https://learn.microsoft.com/en-us/pr...ession-options
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
229 Beiträge
 
#5

AW: Umstellung LDAP auf SSL/TLS

  Alt 17. Mai 2024, 15:31
sorry !

this one is more direct:
https://learn.microsoft.com/en-us/pr...ssion-over-ssl
  Mit Zitat antworten Zitat
Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.441 Beiträge
 
Delphi 10.4 Sydney
 
#6

AW: Umstellung LDAP auf SSL/TLS

  Alt 17. Mai 2024, 16:22
Das ist das Beispiel das ich versuche nachzuprogrammieren.

Code:
//  Verify that SSL is enabled on the connection.
    //  (returns LDAP_OPT_ON/_OFF).
    printf("Checking if SSL is enabled\n");
    returnCode = ldap_get_option(pLdapConnection,LDAP_OPT_SSL,(void*)&amp;lv);
    if (returnCode != LDAP_SUCCESS)
        goto FatalExit;
Und genau an der Stelle komme ich jetzt nicht weiter.
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
229 Beiträge
 
#7

AW: Umstellung LDAP auf SSL/TLS

  Alt 17. Mai 2024, 17:25
Well i hastily tried this
Code:
procedure TForm10.LDAPConnect;
var
  pConn: PLDAP;
  Version: NativeUInt;
  CurrVer: NativeUInt;
begin
  pConn := ldap_sslinit('DESKTOP-HOST1', LDAP_SSL_PORT, 1);
  if not Assigned(pConn) then
    Exit;

  try
    Version := LDAP_VERSION3;
    if ldap_set_option(pConn, LDAP_OPT_PROTOCOL_VERSION, @Version) <> LDAP_SUCCESS then
      Exit;
    if ldap_get_option(pConn, LDAP_OPT_SSL, @CurrVer) <> LDAP_SUCCESS then
      Exit;
    Memo1.Lines.Add('Current SSL status : ' + BoolToStr(CurrVer <> 0, true));

    if CurrVer = NativeUInt(LDAP_OPT_OFF) then
    begin
      CurrVer := NativeUInt(LDAP_OPT_ON);
      if ldap_set_option(pConn, LDAP_OPT_SSL, @CurrVer) <> LDAP_SUCCESS then
        Exit;
    end;

    // check again
    if ldap_get_option(pConn, LDAP_OPT_SSL, @CurrVer) <> LDAP_SUCCESS then
      Exit;
    Memo1.Lines.Add('Current SSL status : ' + BoolToStr(CurrVer <> 0, true));

    Memo1.Lines.Add('Success');
  finally
    ldap_unbind_s(pConn);
  end;
end;
and it did gave me this result in the memo
Zitat:
Current SSL status : False
Current SSL status : False
Success
It did refuse to enable SSL, but this is on my PC and i have no LDAP infrastructure to test deeper, but the point is :
There is no Error at all !
  Mit Zitat antworten Zitat
rabatscher

Registriert seit: 13. Dez 2007
Ort: Bruck an der Mur
68 Beiträge
 
#8

AW: Umstellung LDAP auf SSL/TLS

  Alt 21. Mai 2024, 10:14
Vielleicht nicht die Antwort, die du gesucht hast aber:
https://sourceforge.net/projects/lda...3.zip/download

die Jungs dort haben einen richtig guten Job bezüglich LDAP/LDAPS gemacht. Eventuell durchforstest du
den Source dort um ein paar Anleihen zu machen.
  Mit Zitat antworten Zitat
Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.441 Beiträge
 
Delphi 10.4 Sydney
 
#9

AW: Umstellung LDAP auf SSL/TLS

  Alt 21. Mai 2024, 11:22
Die Abfrage von LDAP_OPT_SSL liefert LDAP_LOCAL_ERROR.
Ob die Variable als NativeUInt, CARDINAL oder Pointer deklariert ist, spielt keine Rolle, die sind bei mir alle 32Bit.

Ich vermute, TLS is bereits aktiviert und deshalb steht die Option SSL nicht zur Verfügung.
Das bedeutet für mich, die Anleitung von MS ist nicht mehr aktuell oder unvollständig.

Im Quelltext "LDAPAdmin" wird die Option LDAP_OPT_SSL nicht benutzt und LDAP_LOCAL_ERROR an einer Stelle ignoriert:
Delphi-Quellcode:
  if ldapSSL then
    ldappld := ldap_sslinit(PChar(ldapServer), ldapPort,1)
  else
    ldappld := ldap_init(PChar(ldapServer), ldapPort);
  if Assigned(pld) then
  try
    LdapCheck(ldap_set_option(pld,LDAP_OPT_PROTOCOL_VERSION,@ldapVersion));
    if ldapSSL or ldapTLS then
    begin
      res := ldap_set_option(pld, LDAP_OPT_SERVER_CERTIFICATE, @VerifyCert);
      if (res <> LDAP_SUCCESS) and (res <> LDAP_LOCAL_ERROR) then
        LdapCheck(res);
      CertServerName := PChar(ldapServer);
    end;
    CertUserAbort := false;
    if ldapTLS then
    begin
      res := ldap_start_tls_s(ldappld, nil, nil, nil, nil);
      if CertUserAbort then
        Abort;
      LdapCheck(res);
    end;
    case ldapAuthMethod of
Ich versuch diese Variante...
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
229 Beiträge
 
#10

AW: Umstellung LDAP auf SSL/TLS

  Alt 21. Mai 2024, 12:30
Hi again,

with this code which is the same as mine above with one addition the connect
Code:
procedure TForm10.LDAPConnect;
var
  pConn: PLDAP;
  Version: NativeUInt;
  CurrVer: NativeUInt;
  TimeOut: TLDAPTimeVal;
begin
  pConn := ldap_sslinit('127.0.0.1', LDAP_SSL_PORT, 1);
 // pConn := ldap_init('localhost', LDAP_PORT);
  if not Assigned(pConn) then
    Exit;

  try
    Version := LDAP_VERSION3;
    if ldap_set_option(pConn, LDAP_OPT_PROTOCOL_VERSION, @Version) <> LDAP_SUCCESS then
      Exit;
    if ldap_get_option(pConn, LDAP_OPT_SSL, @CurrVer) <> LDAP_SUCCESS then
      Exit;
    Memo1.Lines.Add('Current SSL status : ' + BoolToStr(CurrVer <> 0, true));

    if CurrVer = NativeUInt(LDAP_OPT_OFF) then
    begin
      CurrVer := NativeUInt(LDAP_OPT_ON);
      if ldap_set_option(pConn, LDAP_OPT_SSL, @CurrVer) <> LDAP_SUCCESS then
        Exit;
    end;

    // check again
    if ldap_get_option(pConn, LDAP_OPT_SSL, @CurrVer) <> LDAP_SUCCESS then
      Exit;
    Memo1.Lines.Add('Current SSL status : ' + BoolToStr(CurrVer <> 0, true));

    TimeOut.tv_sec := 5;
    TimeOut.tv_usec := 0;
    if ldap_connect(pConn, @TimeOut) <> LDAP_SUCCESS then
      begin
        Memo1.Lines.Add('ldap_connect failed');
        Exit;
      end;

    Memo1.Lines.Add('Connected');

    Memo1.Lines.Add('Success');
  finally
    ldap_unbind_s(pConn);
  end;
end;
Also i installed Active Directory LightWeight Directory Service from Windows Features
ads.png

Now the result also failed to connect still, because i didn't configure any certificate and not sure about what account i allowed as i clicked next ,next ....
But from Wireshark the connection is established with TLS v1.2 and a Client Hello is sent from the app to ADS server but the server abruptly closed the connection, this is a symptom when the server doesn't have a valid certificate, i don't want to go through issuing a certificate for many reasons but the biggest one is i don't have a valid domain or a have access to real AD server on Windows OS server to issue trusted one.
Wireshark :
2024-05-21-14_23_58-untitled.jpg

So i suggest to use wireshark to check if SSL/TLS is enabled instead of depending on LDAP_OPT_SSL, i doubt it might refer to client side certificate verification instead of what you think of the connection is TLS.

See, using ldap_sslinit is already indicating the secure connection, so LDAP_OPT_SSL might not be the indicator, but again i might be wrong here, or may be it is reserved when using ldap_init instead of ldap_sslinit, i don't know.
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:09 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz