Skip to content

ImportExchangeHybrid.ps1 hostname extraction bug #2568

@cjs59

Description

@cjs59

Describe the bug
When using Win-ACME to get a certificate from Sectigo, InstallExchangeHybrid.ps1 fails to extract the domain name from the certificate subject: "CN=hostname.domain, O=Organisation Name, S=State, C=CC". It

To Reproduce

  1. Run with command line .\wacs.exe --source "manual" --host "hostname.domain" --baseuri "https://acme.sectigo.com/v2/OV" --eab-key-identifier "keyid" --eab-key "key" --certificatestore "My" --acl-fullcontrol "Network Service,Administrators" --installation "iis,script" --installationsiteid 1 --script "C:\Program Files\Win-ACME\Scripts\ImportExchangeHybrid.ps1" --scriptparameters "'{CertThumbprint}' 'IIS,SMTP' 0 '{CacheFile}' '{CachePassword}' '{CertFriendlyName}'"
  2. See certificate created correctly
  3. See error while deploying the certificate:
 Script C:\Program Files\Win-ACME\Scripts\ImportExchangeHybrid.ps1 starting with parameters 'thumbprint' 'IIS,SMTP' 0 'C:\ProgramData\win-acme\acme.sectigo.comv2OV\Certificates\filename.pfx' '********' '[Manual] hostname.domain @ 2024/5/2 10:44:10'
 Script error: Cannot process argument transformation on parameter 'DomainName'. Cannot convert value
 Script error: "hostname.domain, O" to type
 Script error: "Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.SmtpDomain]". Error: "Failed to convert
 Script error: hostname.domain, O from System.String to Microsoft.Exchange.Data.SmtpDomain. Error: Error while
 Script error: converting string 'hostname.domain, O' to result type Microsoft.Exchange.Data.SmtpDomain:
 Script error: "hostname.domain, O" isn't a valid SMTP domain."
 Script error:     + CategoryInfo          : InvalidData: (:) [Get-ExchangeCertificate], ParameterBindin...mationException
 Script error:     + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-ExchangeCertificate
 Script error:     + PSComputerName        : hostname.domain
 Script finished

Expected behavior
The script runs without any errors if you change line 170 from:

Get-ExchangeCertificate -DomainName $Certificate.Subject.split("=")[1]

To:

Get-ExchangeCertificate -DomainName $Certificate.Subject.split(",")[0].split("=")[1]

This version works with Sectigo-style subjects with multiple components as well as LetsEncrypt-style subjects with just "CN=hostname.domain".

Platform:

  • OS: Windows Server 2016, English
  • Version: win-acme.v2.2.8.1635.x64.trimmed.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions