Skip to content

Commit

Permalink
fix #37
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbarron committed Nov 9, 2021
1 parent 8d2b687 commit faee349
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions VenafiPS/Public/Import-TppCertificate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ If not provided and the CN is also missing, the name becomes the first Domain Na
Finally, if none of the above are found, the serial number is used.
.PARAMETER PrivateKey
The private key data. Requires a Password. For a PEM certificate, the private key is in either the RSA or PKCS#8 format. If the CertificateData field contains a PKCS#12 formatted certificate, this parameter is ignored because only one private key is allowed.
Private key data; requires a value for Password.
For a PEM certificate, the private key is in either the RSA or PKCS#8 format.
Do not provide for a PKCS#12 certificate as the private key is already included.
.PARAMETER Password
Password required when including a private key.
Password required if the certificate has a private key.
.PARAMETER Reconcile
Controls certificate and corresponding private key replacement.
Expand Down Expand Up @@ -67,7 +69,8 @@ function Import-TppCertificate {
[ValidateScript( {
if ( $_ | Test-TppDnPath ) {
$true
} else {
}
else {
throw "'$_' is not a valid Policy path"
}
})]
Expand All @@ -79,7 +82,8 @@ function Import-TppCertificate {
[ValidateScript( {
if ( $_ | Test-Path ) {
$true
} else {
}
else {
throw "'$_' is not a valid path"
}
})]
Expand All @@ -99,6 +103,8 @@ function Import-TppCertificate {
[Parameter(Mandatory, ParameterSetName = 'ByDataWithPrivateKey')]
[String] $PrivateKey,

[Parameter(ParameterSetName = 'ByFile')]
[Parameter(ParameterSetName = 'ByData')]
[Parameter(Mandatory, ParameterSetName = 'ByFileWithPrivateKey')]
[Parameter(Mandatory, ParameterSetName = 'ByDataWithPrivateKey')]
[SecureString] $Password,
Expand All @@ -117,16 +123,19 @@ function Import-TppCertificate {

$VenafiSession.Validate() | Out-Null

}

process {
if ( $PSBoundParameters.ContainsKey('CertificatePath') ) {
# get cert data from file
$CertificateData = Get-Content -Path $CertificatePath -Raw
}

$params = @{
VenafiSession = $VenafiSession
Method = 'Post'
UriLeaf = 'certificates/import'
Body = @{
Method = 'Post'
UriLeaf = 'certificates/import'
Body = @{
PolicyDN = $PolicyPath
CertificateData = $CertificateData
}
Expand All @@ -146,11 +155,20 @@ function Import-TppCertificate {
$params.Body.ObjectName = $Name
}


if ( $PSBoundParameters.ContainsKey('PrivateKey') ) {
}

if ( $PSBoundParameters.ContainsKey('PrivateKey') ) {
$params.Body.PrivateKeyData = $PrivateKey
$plainTextPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password))
$params.Body.Password = $plainTextPassword
}
else {
if ( [System.IO.Path]::GetExtension($CertificatePath) -ne '.p12' ) {

}
}

$response = Invoke-TppRestMethod @params
Write-Verbose ('Successfully imported certificate')
Expand All @@ -159,7 +177,4 @@ function Import-TppCertificate {
$response.CertificateDN | Get-TppObject
}
}

process {
}
}

0 comments on commit faee349

Please sign in to comment.