Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Create the Austin certificate via PowerShell

...

Log into a server joined to the Austin Active Directory as a user with permissions to request a certificate from the desired template

...

Open an administrative PowerShell prompt

...

In the same administrative PowerShell prompt, navigate to the location where the certificate request should be created: 

Code Block
#example
Set-Location C:\Working

In the same administrative PowerShell prompt, run the following command to set the subject, any optional subject alternate names, and template of the certificate:  

...

Table of Contents
typeflat

Define the certificate subject and subject alternative names

  1. Sign in to a computer then start an administrative PowerShell session 

  2. Modify then run the following commands to set the subject and template of the certificate as well as any optional DNS or IP Address subject alternate name values:  

    Code Block
    languagepowershell
    $Subject = "<subject for the certificate>"
    

...

  1. $SubjectAlternateNames = @("<certificate SAN #1>","<certificate SAN #2>",...)
    

...

  1. $CertificateIPAddresses = 

...

In the same administrative PowerShell session, run one of the following:

...

  1. @("<certificate IP address #1>","<certificate IP address #2>",...)

Create the certificate request

  1. Run the following commands to define the newline string

    Code Block

...

$cert_subject = ("CN=" + $cert_url")

In the same administrative PowerShell prompt, run the following to create the INF file then open the INF file to review the output:

...

  1. languagepowershell
    $NewLine = [System.Environment]::NewLine
  2. Run the following commands to create the temporary files: 

    Code Block
    languagepowershell
    $CertificateTemplateFile = New-TemporaryFile
    $CertificateRequestFile = New-TemporaryFile
  3. Run the following commands to define the certificate template:

    Code Block
    languagepowershell
    $CertificateTemplate = @'
    [Version]
    Signature=

...

  1. "

...

  1. $Windows 

...

  1. NT$"
      
    [NewRequest]
    Subject=

...

  1. "CN=%Subject%"
    Exportable=TRUE
    MachineKeySet=TRUE
    KeyLength=2048
    KeySpec=AT_KEYEXCHANGE
      
    [Extensions]
    2.5.29.17=

...

  1. "{text}

...

  1. "
    _continue_=

...

  1. "DNS=

...

  1. %Subject%&

...

  1. "
    

...

  1. '@
  2. Run the following commands to update the subject in the certificate template: 

    Code Block
    languagepowershell
    $CertificateTemplate = $CertificateTemplate.Replace('%Subject%', $Subject)
  3. Run the following commands to add any optional DNS subject alternate names to the

...

  1. certificate template

    Code Block
    languagepowershell
    ForEach (

...

  1. $SubjectAlternateName in 

...

  1. $SubjectAlternateNames) {

...

  1.  $CertificateTemplate = '{0}{1}_continue_=

...

  1. "DNS=

...

  1. {2}&

...

In the same administrative PowerShell prompt, run the following to create the request, submit the request to a certificate authority, then accept the response:

Code Block
$cert_file_req = ((Get-Location).Path + "\" + $cert_file  + ".req")
$cert_file_cer = ((Get-Location).Path + "\" + $cert_file  + ".cer")
certreq -new $cert_file_inf $cert_file_req
certreq -submit -attrib ("CertificateTemplate:" + $cert_template) $cert_file_req $cert_file_cer
certreq -accept $cert_file_cer

Export the Austin certificate via PowerShell

...

Log into a server joined to the Austin Active Directory as a user with permissions to request a certificate from the desired template

...

Open an administrative PowerShell prompt

...

In the same administrative PowerShell prompt, run the following command to set the filename and subject of the certificate:  

Code Block
$cert_url = <FQDN for the certificate>

In the same administrative PowerShell prompt, run one or more of the following to export the certificate: 

...

To export the public and private keys to a PFX file, run the following commands: 

Code Block
$cert_file = $cert_url.Split(".")[0] + "_" + (Get-Date -Format yyyyMMdd-HHmmss)
$cert_file_pfx = ((Get-Location).Path + "\" + $cert_file  + ".pfx")
$cert_cred = Get-Credential -Credential "Certificate"
$cert_obj = Get-ChildItem -Path "cert:\LocalMachine\My" | Where-Object {$_.Subject -match $cert_url} | Sort-Object NotBefore -Descending | Select-Object -First 1
$cert_obj | Export-PfxCertificate -FilePath $cert_file_pfx -Password $cert_cred.Password

To export the public key to a CRT and a PEM file, run the following commands: 

...

  1. "' -f $CertificateTemplate, $NewLine, $SubjectAlternateName }
  2. Run the following commands to add any optional IP Address subject alternate names to the certificate template: 

    Code Block
    languagepowershell
    ForEach ($CertificateIPAddress in $CertificateIPAddresses) { $CertificateTemplate = '{0}{1}_continue_="IPAddress={2}&"' -f $CertificateTemplate, $NewLine, $CertificateIPAddress }
  3. Run the following commands to trim the certificate template:

    Code Block
    languagepowershell
    $CertificateTemplate = $CertificateTemplate -replace '&"\s*$', '"'
  4. Run the following commands to write the certificate template file:

    Code Block
    languagepowershell
    $Content | Out-File -FilePath $CertificateTemplateFile -Force
  5. Run the following commands to review the certificate template file: 

    Code Block
    languagepowershell
    Get-Content -Path $CertificateTemplateFile
  6. Run the following commands to create the certificate request file:

    Code Block
    languagepowershell
    certreq -new -f $CertificateTemplateFile $CertificateRequestFile
  7. Run the following commands to review the certificate request file: 

    Code Block
    languagepowershell
    Get-Content -Path $CertificateRequestFile
  8. Run the following commands to retrieve the certificate request file name: 

    Code Block
    languagepowershell
    Get-Item -Path $CertificateRequestFile

Submit the certificate request to a certificate authority

References