zaro

How to get LDAP certificate from active directory?

Published in Active Directory Certificate Management 7 mins read

You can obtain an LDAP (Lightweight Directory Access Protocol) certificate for Active Directory by ensuring your domain controllers are provisioned with a valid server authentication certificate, or by retrieving an existing one directly from a running secure LDAP (LDAPS) service.

Understanding LDAP and LDAPS Certificates

LDAP is used for querying and modifying directory services, such as Active Directory. For secure communication, LDAP uses SSL/TLS, becoming LDAPS (LDAP Secure). To enable LDAPS, Active Directory domain controllers require a server authentication certificate. This certificate encrypts the communication and authenticates the domain controller to clients, ensuring data integrity and confidentiality.

A valid LDAPS certificate must meet several criteria:

  • It must be in the domain controller's Personal certificate store for the local computer.
  • It must contain the Server Authentication Extended Key Usage (EKU) (OID 1.3.6.1.5.5.7.3.1).
  • The Subject Name (CN) or Subject Alternative Name (SAN) field must include the Fully Qualified Domain Name (FQDN) of the domain controller.
  • The certificate's private key must be present and accessible to the Active Directory Domain Services (AD DS) service account.
  • The issuing Certificate Authority (CA) must be trusted by the clients connecting to the domain controller.

Methods to Obtain and Configure an LDAPS Certificate

There are two primary ways to provision an Active Directory domain controller with an LDAPS certificate:

1. Automated Enrollment via an Enterprise Certificate Authority (Recommended)

This is the most common and recommended method for organizations using Active Directory with an integrated Microsoft Enterprise Certificate Authority (CA). Active Directory Domain Services automatically detects and utilizes a suitable server authentication certificate if one is present in the domain controller's Personal certificate store.

Steps:

  1. Deploy a Microsoft Enterprise CA: If you don't already have one, set up an Enterprise Certificate Authority within your Active Directory environment.
  2. Configure Certificate Templates:
    • Duplicate the existing "Kerberos Authentication" or "Domain Controller" certificate template. If these are not suitable, duplicate the "Computer" template.
    • Ensure the template's Extended Key Usage (EKU) includes "Server Authentication."
    • Verify that the template's Subject Name settings are configured to "Build from Active Directory information" and include DNS name.
    • On the Security tab of the template, grant Read, Enroll, and Autoenroll permissions to "Domain Controllers" or a specific group containing your domain controllers.
  3. Configure Group Policy for Autoenrollment:
    • Open Group Policy Management (gpmc.msc).
    • Edit the Default Domain Controllers Policy or create a new Group Policy Object (GPO) linked to the "Domain Controllers" Organizational Unit (OU).
    • Navigate to Computer Configuration > Policies > Windows Settings > Security Settings > Public Key Policies > Automatic Certificate Request Settings.
    • Right-click, select New > Automatic Certificate Request.
    • Follow the wizard, selecting the certificate template you configured.
  4. Update Group Policy: Force a Group Policy update on your domain controllers by running gpupdate /force from an elevated command prompt.
    • Domain controllers will automatically request and enroll the certificate, and LDAPS will become active within minutes without requiring a restart.

2. Manual Import of a Certificate

This method is typically used when you obtain an LDAPS certificate from a third-party (commercial) Certificate Authority or in specific scenarios where auto-enrollment is not feasible.

Steps:

  1. Obtain the Certificate: Request a Server Authentication certificate from your chosen CA. Ensure it includes the domain controller's FQDN in the Subject Alternative Name (SAN) and is provided in a format that includes the private key (e.g., a .PFX or .P12 file).
  2. Import the Certificate:
    • On the domain controller, open the Microsoft Management Console (MMC) by typing mmc in the Run dialog.
    • Go to File > Add/Remove Snap-in....
    • Add the Certificates snap-in and select Computer account, then Local computer.
    • Navigate to Certificates (Local Computer) > Personal > Certificates.
    • Right-click Certificates, select All Tasks > Import....
    • Follow the Certificate Import Wizard, pointing to your .PFX file and providing the password. Ensure you mark the private key as exportable if needed, or simply complete the import.
    • Once imported correctly, Active Directory should detect and use the certificate for LDAPS within seconds.

How to Retrieve an Existing LDAPS Certificate from Active Directory

If LDAPS is already configured on your Active Directory domain controllers, you can retrieve the public certificate directly from the server that is presenting it using tools like OpenSSL. This is useful for verifying the certificate, its expiry, or for importing it into client trust stores.

Using OpenSSL s_client

This method allows you to download the certificate chain currently being presented by an Active Directory server for LDAPS communication.

Steps:

  1. Install OpenSSL: Ensure you have OpenSSL installed on your local computer. It is often included with various development tools or can be downloaded from the official OpenSSL website.

  2. Open a Command Prompt or Terminal:

  3. Run the command: Execute the following command, replacing <ip_or_fqdn_of_your_active_directory_server> with the actual IP address or Fully Qualified Domain Name of your Active Directory domain controller:

    openssl s_client -showcerts -connect <ip_or_fqdn_of_your_active_directory_server>:636

    Example:

    openssl s_client -showcerts -connect adserver.yourdomain.com:636
  4. Copy the Certificate Output:

    • The command output will display the certificate chain. Look for sections that begin with -----BEGIN CERTIFICATE----- and end with -----END CERTIFICATE-----.
    • The first certificate block (usually denoted by 0 s: or similar) is typically the server's leaf certificate.
    • Copy the entire certificate portion, including both the BEGIN and END lines.
  5. Save to a Text File: Paste the copied content into a plain text file. Save the file with a .cer or .pem extension (e.g., ad_ldap_cert.cer). This file now contains the public LDAPS certificate.

This retrieved certificate can then be imported into client trust stores if your clients do not implicitly trust the CA that issued the certificate.

Verifying Your LDAPS Certificate Configuration

After obtaining and configuring your LDAPS certificate, it's crucial to verify that LDAPS is functioning correctly:

  • LDP.exe Tool: On any Windows machine, open ldp.exe. Go to Connection > Connect. Enter the FQDN of your domain controller, set the port to 636, and check the SSL box. If the connection is successful, LDAPS is working.
  • Event Viewer: Check the Directory Service event logs on the domain controller for event ID 1220 (Microsoft-Windows-ActiveDirectory_DomainService) which indicates successful LDAPS binding.
  • OpenSSL Command: The openssl s_client command described above will also confirm if a certificate is being presented and if the connection is successful over port 636.

Key Considerations for LDAPS Certificates

Method Description Use Case
Automated Enrollment Utilizes a Microsoft Enterprise Certificate Authority and Group Policy to automatically issue and renew "Domain Controller" or "Kerberos Authentication" certificates to all domain controllers in the domain. AD DS detects the certificate and enables LDAPS. Ideal for internal Active Directory environments with an integrated CA.
Manual Import Involves obtaining a Server Authentication certificate (e.g., as a .PFX file) from an internal or external CA and manually importing it into the domain controller's Local Computer Personal certificate store. Used when an Enterprise CA is not present, or for certificates from external CAs.
OpenSSL s_client A command-line utility used to connect to the LDAPS port (636) on a domain controller and retrieve the public certificate chain it is currently presenting. This allows you to verify the certificate details and save it to a file for client trust or analysis. Retrieving an already active LDAPS certificate for verification or client trust.

Best Practices:

  • Monitor Certificate Expiration: Implement a process to monitor certificate expiry dates to avoid service outages.
  • Use Subject Alternative Name (SAN): Modern applications and best practices prefer SANs over just the Subject Name (CN). Ensure your certificate includes the FQDNs of your domain controllers in the SAN.
  • Root CA Trust: Ensure that the root CA certificate of the issuing authority is trusted by all client machines that need to connect via LDAPS.