Skip to content

Commit

Permalink
added Install-PACertificate (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbolger committed Jul 19, 2019
1 parent afaa829 commit 931708b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
1 change: 1 addition & 0 deletions Posh-ACME/Posh-ACME.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ FunctionsToExport = @(
'Get-PACertificate',
'Get-PAOrder',
'Get-PAServer',
'Install-PACertificate',
'New-PAAccount',
'New-PACertificate',
'New-PAOrder',
Expand Down
43 changes: 43 additions & 0 deletions Posh-ACME/Public/Install-PACertificate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function Install-PACertificate {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
[PSTypeName('PoshACME.PACertificate')]$PACertificate
)

Process {

if (-not $IsWindows -and 'Desktop' -ne $PSEdition) {
Write-Warning "Install-PACertificate currently only works on Windows OSes"
return
}

Write-Verbose "Importing $($PACertificate.Subject) certificate to Windows certificate store."
Import-PfxCertInternal $PACertificate.PfxFullChain -PfxPass $PACertificate.PfxPass
}


<#
.SYNOPSIS
Install a Posh-ACME certificate into the local computer's certificate store.
.DESCRIPTION
This can be used instead of the -Install parameter on New-PACertificate to import a certificate into the local computer's certificate store.
.EXAMPLE
Install-PACertificate
Install the certificate associated with the currently selected order.
.EXAMPLE
Get-PACertificate example.com | Install-PACertificate
Install the specified certificate.
.LINK
Project: https://github.com/rmbolger/Posh-ACME
.LINK
Get-PACertificate
#>
}
12 changes: 4 additions & 8 deletions Posh-ACME/Public/New-PACertificate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,15 @@ function New-PACertificate {

Write-Verbose "Successfully created certificate."

$cert = Get-PACertificate

# install to local computer store if asked
if ($order.Install) {
Write-Verbose "Importing certificate to Windows certificate store."
if ([string]::IsNullOrEmpty($PfxPass)) {
$secPass = New-Object Security.SecureString
} else {
$secPass = ConvertTo-SecureString $PfxPass -AsPlainText -Force
}
Import-PfxCertInternal (Join-Path $script:OrderFolder 'fullchain.pfx') -PfxPass $secPass
$cert | Install-PACertificate
}

# output cert details
Get-PACertificate
Write-Output $cert

} elseif ($order.CertExpires) {
Write-Verbose "This certificate order has already been completed. Use -Force to overwrite the current certificate."
Expand Down

0 comments on commit 931708b

Please sign in to comment.