Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed $ca parameter #43

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 30 additions & 15 deletions DSCResources/MSFT_xCertReq/MSFT_xCertReq.psm1
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
#Requires -Version 4.0

$script:ResourceRootPath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent)

# Import the xCertificate Resource Module (to import the common modules)
Import-Module -Name (Join-Path -Path $script:ResourceRootPath -ChildPath 'xCertificate.psd1')

# Import Localization Strings
$localizedData = Get-LocalizedData `
-ResourceName 'MSFT_xCertReq' `
-ResourcePath (Split-Path -Parent $Script:MyInvocation.MyCommand.Path)
#region localizeddata
if (Test-Path "${PSScriptRoot}\${PSUICulture}")
{
Import-LocalizedData `
-BindingVariable LocalizedData `
-Filename MSFT_xCertReq.strings.psd1 `
-BaseDirectory "${PSScriptRoot}\${PSUICulture}"
}
else
{
#fallback to en-US
Import-LocalizedData `
-BindingVariable LocalizedData `
-Filename MSFT_xCertReq.strings.psd1 `
-BaseDirectory "${PSScriptRoot}\en-US"
}
#endregion

# Import the common certificate functions
Import-Module -Name ( Join-Path `
-Path (Split-Path -Path $PSScriptRoot -Parent) `
-ChildPath 'CertificateCommon\CertificateCommon.psm1' )

<#
.SYNOPSIS
Expand Down Expand Up @@ -310,7 +323,7 @@ function Set-TargetResource

# A unique identifier for temporary files that will be used when interacting with the command line utility
$guid = [system.guid]::NewGuid().guid
$workingPath = Join-Path -Path $env:Temp -ChildPath "xCertReq-$guid"
$workingPath = Join-Path -Path $ENV:Temp -ChildPath "xCertReq-$guid"
$infPath = [System.IO.Path]::ChangeExtension($workingPath,'.inf')
$reqPath = [System.IO.Path]::ChangeExtension($workingPath,'.req')
$cerPath = [System.IO.Path]::ChangeExtension($workingPath,'.cer')
Expand Down Expand Up @@ -375,7 +388,7 @@ RenewalCert = $Thumbprint
# SUBMIT: Submit a request to a Certification Authority.
# DSC runs in the context of LocalSystem, which uses the Computer account in Active Directory
# to authenticate to network resources
# The Credential paramter with PDT is used to impersonate a user making the request
# The Credential paramter with xPDT is used to impersonate a user making the request
if (Test-Path -Path $reqPath)
{
Write-Verbose -Message ( @(
Expand All @@ -385,13 +398,15 @@ RenewalCert = $Thumbprint

if ($Credential)
{
Import-Module -Name $PSScriptRoot\..\PDT\PDT.psm1 -Force

# Assemble the command and arguments to pass to the powershell process that
# will request the certificate
$certReqOutPath = [System.IO.Path]::ChangeExtension($workingPath,'.out')
$command = "$PSHOME\PowerShell.exe"
$arguments = "-Command ""& $env:SystemRoot\system32\certreq.exe" + `
" @('-submit','-q','-config',$ca,'$reqPath','$cerPath')" + `
" | Set-Content -Path '$certReqOutPath'"""
$arguments = "-Command ""& $ENV:SystemRoot\system32\certreq.exe" + `
" @('-submit','-q','-config','$ca','$reqPath','$cerPath')" + `
" | Set-Content -Path '$certReqOutPath'"""

# This may output a win32-process object, but it often does not because of
# a timing issue in PDT (the process has often completed before the
Expand All @@ -406,7 +421,7 @@ RenewalCert = $Thumbprint
$($LocalizedData.SubmittingRequestProcessCertificateMessage)
) -join '' )

$null = Wait-Win32ProcessEnd `
$null = Wait-Win32ProcessStop `
-Path $command `
-Arguments $arguments `
-Credential $Credential
Expand Down
Loading