Skip to content

Add export_root_ca_certificate() methods for LDAPS#248

Open
shridhargadekar wants to merge 1 commit into
SSSD:masterfrom
shridhargadekar:add-export-certificate-methods
Open

Add export_root_ca_certificate() methods for LDAPS#248
shridhargadekar wants to merge 1 commit into
SSSD:masterfrom
shridhargadekar:add-export-certificate-methods

Conversation

@shridhargadekar
Copy link
Copy Markdown
Contributor

Add certificate export functionality to AD and Samba hosts to support LDAPS testing with proper certificate trust chains.

AD (Windows):

  • Export LDAPS certificate from LocalMachine\My store (not Root)
  • Filter by FQDN subject and Server Authentication EKU (1.3.6.1.5.5.7.3.1)
  • Certificate has both CA:TRUE and ServerAuth for trust chain validation

Samba (Linux):

  • Export CA certificate from /var/data/certs/ca.crt
  • Pre-configured LDAPS certificate in container setup

These methods enable tests to:

  1. Export certificates from providers
  2. Trust them on client systems using TLSUtils.trust_ca_certificate()
  3. Validate LDAPS connections (port 636) with proper TLS verification

Used by adcli LDAPS tests to verify --use-ldaps functionality.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds the export_root_ca_certificate method to both the Active Directory and Samba host classes to allow exporting LDAPS certificates in PEM format. The review feedback suggests updating the PowerShell script in the AD implementation to use the non-obsolete GetHostEntry method and to use a more robust regex-based approach for matching the certificate subject.

Comment thread sssd_test_framework/hosts/ad.py Outdated
"""
result = self.conn.run(
"""
$fqdn = [System.Net.Dns]::GetHostByName($env:COMPUTERNAME).HostName
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The [System.Net.Dns]::GetHostByName method is obsolete. It is recommended to use [System.Net.Dns]::GetHostEntry instead, which is the modern replacement in .NET for resolving host information.

Suggested change
$fqdn = [System.Net.Dns]::GetHostByName($env:COMPUTERNAME).HostName
$fqdn = [System.Net.Dns]::GetHostEntry($env:COMPUTERNAME).HostName

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack, fixed it.

Comment thread sssd_test_framework/hosts/ad.py Outdated

# Get the LDAPS certificate from My store (server certificate with ServerAuth EKU)
$cert = Get-ChildItem Cert:\\LocalMachine\\My | Where-Object {
$_.Subject -eq "CN=$fqdn" -and
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using an exact match for the Subject property (-eq "CN=$fqdn") is fragile. Certificate subjects often contain additional Relative Distinguished Names (RDNs) such as Organizational Units (OU) or Domain Components (DC). A more robust approach is to use a regular expression match to identify the Common Name (CN) component specifically.

Suggested change
$_.Subject -eq "CN=$fqdn" -and
$_.Subject -match "CN=$([regex]::Escape($fqdn))($|,)" -and

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack, fixed this one

Add certificate export functionality to AD and Samba hosts to support
LDAPS testing with proper certificate trust chains.

AD (Windows):
- Export LDAPS certificate from LocalMachine\My store (not Root)
- Filter by FQDN subject and Server Authentication EKU (1.3.6.1.5.5.7.3.1)
- Certificate has both CA:TRUE and ServerAuth for trust chain validation

Samba (Linux):
- Export CA certificate from /var/data/certs/ca.crt
- Pre-configured LDAPS certificate in container setup

These methods enable tests to:
1. Export certificates from providers
2. Trust them on client systems using TLSUtils.trust_ca_certificate()
3. Validate LDAPS connections (port 636) with proper TLS verification

Used by adcli LDAPS tests to verify --use-ldaps functionality.

Signed-off-by: shridhargadekar <shridhar.always@gmail.com>
@shridhargadekar shridhargadekar force-pushed the add-export-certificate-methods branch from 3c51b44 to 7d0e6e6 Compare May 21, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant