Publish version 1.0.x #45

Merged
OCram85 merged 31 commits from dev into master 2019-04-29 16:05:44 +02:00
4 changed files with 64 additions and 11 deletions
Showing only changes of commit a71bfd0aaf - Show all commits

View File

@ -89,7 +89,26 @@ function Get-CredentialStoreItem {
if (($CSMembers.MemberType -eq "NoteProperty") -and ($CSMembers.Name -contains $CredentialName)) {
try {
if ($null -eq $CS.PfxCertificate) {
$Cert = Get-CSCertificate -Thumbprint $CS.Thumbprint
if ($CS.Type -eq 'Private') {
$Cert = Get-CSCertificate -Thumbprint $CS.Thumbprint
}
elseif ($CS.Type -eq 'Shard') {
if (Test-CSCertificate -Thumbprint $CS.Thumbprint -StoreName My -StoreLocation LocalMachine) {
$Cert = Get-CSCertificate -Thumbprint $CS.Thumbprint -StoreName My -StoreLocation LocalMachine
}
elseif (Test-CSCertificate -Thumbprint $CS.Thumbprint -StoreName Root -StoreLocation LocalMachine) {
$Cert = Get-CSCertificate -Thumbprint $CS.Thumbprint -StoreName Root -StoreLocation LocalMachine
}
else {
$ErrorParams = @{
ErrorAction = 'Stop'
Exception = [System.Exception]::new(
('Could not find any certificate with thumbprint {0}' -f $CS.Thumbprint)
)
}
Write-Error @ErrorParams
}
}
}
else {
$Cert = Get-PfxCertificate -FilePath $CS.PfxCertificate -ErrorAction Stop

View File

@ -118,15 +118,25 @@ function New-CredentialStoreItem {
if ($Credential.UserName) {
try {
if ($null -eq $CSContent.PfxCertificate) {
$Cert = Get-CSCertificate -Thumbprint $CSContent.Thumbprint
if ($null -eq $Cert) {
$ErrorParams = @{
ErrorAction = 'Stop'
Exception = [System.Security.Cryptography.X509Certificates.FileNotFoundException]::new(
('Could not find the linked certificate with thumbprint {0}' -f $CSContent.Thumbprint)
)
if ($CSContent.Type -eq 'Private') {
$Cert = Get-CSCertificate -Thumbprint $CSContent.Thumbprint
}
elseif ($CSContent.Type -eq 'Shard') {
if (Test-CSCertificate -Thumbprint $CSContent.Thumbprint -StoreName My -StoreLocation LocalMachine) {
$Cert = Get-CSCertificate -Thumbprint $CSContent.Thumbprint -StoreName My -StoreLocation LocalMachine
}
elseif (Test-CSCertificate -Thumbprint $CSContent.Thumbprint -StoreName Root -StoreLocation LocalMachine) {
$Cert = Get-CSCertificate -Thumbprint $CSContent.Thumbprint -StoreName Root -StoreLocation LocalMachine
}
else {
$ErrorParams = @{
ErrorAction = 'Stop'
Exception = [System.Exception]::new(
('Could not find any certificate with thumbprint {0}' -f $CSContent.Thumbprint)
)
}
Write-Error @ErrorParams
}
Write-Error @ErrorParams
}
}
else {

View File

@ -104,7 +104,26 @@ function Set-CredentialStoreItem {
if ($Credential.UserName) {
try {
if ($null -eq $CSContent.PfxCertificate) {
$Cert = Get-CSCertificate -Thumbprint $CSContent.Thumbprint
if ($CSContent.Type -eq 'Private') {
$Cert = Get-CSCertificate -Thumbprint $CSContent.Thumbprint
}
elseif ($CSContent.Type -eq 'Shard') {
if (Test-CSCertificate -Thumbprint $CSContent.Thumbprint -StoreName My -StoreLocation LocalMachine) {
$Cert = Get-CSCertificate -Thumbprint $CSContent.Thumbprint -StoreName My -StoreLocation LocalMachine
}
elseif (Test-CSCertificate -Thumbprint $CSContent.Thumbprint -StoreName Root -StoreLocation LocalMachine) {
$Cert = Get-CSCertificate -Thumbprint $CSContent.Thumbprint -StoreName Root -StoreLocation LocalMachine
}
else {
$ErrorParams = @{
ErrorAction = 'Stop'
Exception = [System.Exception]::new(
('Could not find any certificate with thumbprint {0}' -f $CSContent.Thumbprint)
)
}
Write-Error @ErrorParams
}
}
}
else {
$Cert = Get-PfxCertificate -FilePath $CSContent.PfxCertificate -ErrorAction Stop

View File

@ -210,7 +210,12 @@ function New-CredentialStore {
}
else {
Write-Verbose 'Importing new PFX certificate file...'
Import-CSCertificate -Path $PfxParams.CertName -StoreName My -StoreLocation CurrentUser
if ($PSCmdlet.ParameterSetName -eq 'Private') {
Import-CSCertificate -Path $PfxParams.CertName -StoreName My -StoreLocation CurrentUser -ErrorAction Stop
}
elseif ($PSCmdlet.ParameterSetName -eq 'Shared') {
Import-CSCertificate -Path $PfxParams.CertName -StoreName My -StoreLocation LocalMachine -ErrorAction Stop
}
}
}