Skip to content

Commit

Permalink
!deploy v2.36.1
Browse files Browse the repository at this point in the history
## 2.36.1 - 2020-03-02

* [Issue #263](#263)
    * Fixed `[SecureString]` decryption on Unix machines running PowerShell 7 (found additional bugs)
    * Migrated private `Encrypt` and `Decrypt` to `EncryptionHelpers.ps1` in the Private folder to allow a single place to update.
  • Loading branch information
scrthq authored Mar 2, 2020
2 parents daaae47 + cb711bc commit 030e47e
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 114 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* [PSGSuite - ChangeLog](#psgsuite---changelog)
* [2.36.1 - 2020-03-02](#2361---2020-03-02)
* [2.36.0 - 2020-02-28](#2360---2020-02-28)
* [2.35.1 - 2019-12-29](#2351---2019-12-29)
* [2.35.0 - 2019-12-29](#2350---2019-12-29)
Expand Down Expand Up @@ -107,6 +108,12 @@

# PSGSuite - ChangeLog

## 2.36.1 - 2020-03-02

* [Issue #263](https://github.com/scrthq/PSGSuite/issues/263)
* Fixed `[SecureString]` decryption on Unix machines running PowerShell 7 (found additional bugs)
* Migrated private `Encrypt` and `Decrypt` to `EncryptionHelpers.ps1` in the Private folder to allow a single place to update.

## 2.36.0 - 2020-02-28

* [PR #255](https://github.com/scrthq/PSGSuite/pull/255) - _Thanks, [@FISHMANPET](https://github.com/FISHMANPET)!_
Expand Down
26 changes: 26 additions & 0 deletions PSGSuite/Private/EncryptionHelpers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function Invoke-GSDecrypt {
param($String)
if ($String -is [System.Security.SecureString]) {
[System.Runtime.InteropServices.Marshal]::PtrToStringBSTR(
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR(
$String
)
)
}
elseif ($String -is [ScriptBlock]) {
$String.InvokeReturnAsIs()
}
else {
$String
}
}

Function Invoke-GSEncrypt {
param($string)
if ($string -is [System.String] -and -not [String]::IsNullOrEmpty($String)) {
ConvertTo-SecureString -String $string -AsPlainText -Force
}
else {
$string
}
}
129 changes: 57 additions & 72 deletions PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,77 +49,6 @@ function Get-PSGSuiteConfig {
[Switch]
$NoImport
)
Begin {
function Decrypt {
param($String)
if ($String -is [System.Security.SecureString]) {
[System.Runtime.InteropServices.Marshal]::PtrToStringBSTR(
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR(
$String
)
)
}
elseif ($String -is [ScriptBlock]) {
$String.InvokeReturnAsIs()
}
else {
$String
}
}
$outputProps = @(
@{l = 'ConfigName';e = {$choice}},
@{l = 'P12KeyPath';e = {Decrypt $_.P12KeyPath}},
'P12Key',
@{l = 'P12KeyPassword';e = {Decrypt $_.P12KeyPassword}},
@{l = 'P12KeyObject';e = {Decrypt $_.P12KeyObject}},
@{l = 'ClientSecretsPath';e = {Decrypt $_.ClientSecretsPath}},
@{l = 'ClientSecrets';e = {Decrypt $_.ClientSecrets}},
@{l = 'AppEmail';e = {
if ($_.AppEmail) {
Decrypt $_.ServiceAccountClientID
}
elseif ($_.ClientSecrets) {
(Decrypt $_.ClientSecrets | ConvertFrom-Json).client_email
}
}},
@{l = 'AdminEmail';e = {Decrypt $_.AdminEmail}},
@{l = 'CustomerID';e = {Decrypt $_.CustomerID}},
@{l = 'Domain';e = {Decrypt $_.Domain}},
@{l = 'Preference';e = {Decrypt $_.Preference}},
@{l = 'ServiceAccountClientID';e = {
if ($_.ServiceAccountClientID) {
Decrypt $_.ServiceAccountClientID
}
elseif ($_.ClientSecrets) {
(Decrypt $_.ClientSecrets | ConvertFrom-Json).client_id
}
}},
@{l = 'Chat';e = {
$dict = @{
Webhooks = @{}
Spaces = @{}
}
foreach ($key in $_.Chat.Webhooks.Keys) {
$dict['Webhooks'][$key] = (Decrypt $_.Chat.Webhooks[$key])
}
foreach ($key in $_.Chat.Spaces.Keys) {
$dict['Spaces'][$key] = (Decrypt $_.Chat.Spaces[$key])
}
$dict
}},
@{l = 'ConfigPath';e = {
if ($_.ConfigPath) {
$_.ConfigPath
}
elseif ($Path) {
(Resolve-Path $Path).Path
}
else {
$null
}
}}
)
}
Process {
$script:ConfigScope = $Scope
switch ($PSCmdlet.ParameterSetName) {
Expand Down Expand Up @@ -148,7 +77,63 @@ function Get-PSGSuiteConfig {
}
}
}
$decryptedConfig = $encConf | Select-Object -Property $outputProps
$decryptedConfig = $encConf | Select-Object -Property @{l = 'ConfigName';e = { $choice }},
@{l = 'P12KeyPath'; e = { Invoke-GSDecrypt $_.P12KeyPath } },
'P12Key',
@{l = 'P12KeyPassword'; e = { Invoke-GSDecrypt $_.P12KeyPassword } },
@{l = 'P12KeyObject'; e = { Invoke-GSDecrypt $_.P12KeyObject } },
@{l = 'ClientSecretsPath'; e = { Invoke-GSDecrypt $_.ClientSecretsPath } },
@{l = 'ClientSecrets'; e = { Invoke-GSDecrypt $_.ClientSecrets } },
@{l = 'AppEmail'; e = {
if ($_.AppEmail) {
Invoke-GSDecrypt $_.AppEmail
}
elseif ($_.ClientSecrets) {
(Invoke-GSDecrypt $_.ClientSecrets | ConvertFrom-Json).client_email
}
}
},
@{l = 'AdminEmail'; e = { Invoke-GSDecrypt $_.AdminEmail } },
@{l = 'CustomerID'; e = { Invoke-GSDecrypt $_.CustomerID } },
@{l = 'Domain'; e = { Invoke-GSDecrypt $_.Domain } },
@{l = 'Preference'; e = { Invoke-GSDecrypt $_.Preference } },
@{l = 'ServiceAccountClientID'; e = {
if ($_.ServiceAccountClientID) {
Invoke-GSDecrypt $_.ServiceAccountClientID
}
elseif ($_.ClientSecrets) {
(Invoke-GSDecrypt $_.ClientSecrets | ConvertFrom-Json).client_id
}
}
},
@{l = 'Chat'; e = {
$dict = @{
Webhooks = @{ }
Spaces = @{ }
}
foreach ($key in $_.Chat.Webhooks.Keys) {
$dict['Webhooks'][$key] = (Invoke-GSDecrypt $_.Chat.Webhooks[$key])
}
foreach ($key in $_.Chat.Spaces.Keys) {
$dict['Spaces'][$key] = (Invoke-GSDecrypt $_.Chat.Spaces[$key])
}
$dict
}
},
@{
l = 'ConfigPath'
e = {
if ($_.ConfigPath) {
$_.ConfigPath
}
elseif ($Path) {
(Resolve-Path $Path).Path
}
else {
$null
}
}
}
Write-Verbose "Retrieved configuration '$choice'"
if (!$NoImport) {
$script:PSGSuite = $decryptedConfig
Expand Down
20 changes: 8 additions & 12 deletions PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function Set-PSGSuiteConfig {
$NoImport
)
Begin {
Function Encrypt {
Function Invoke-GSEncrypt {
param($string)
if ($string -is [System.Security.SecureString]) {
$string
Expand All @@ -158,11 +158,7 @@ function Set-PSGSuiteConfig {
}
Process {
$script:ConfigScope = $Scope
$params = @{}
if ($PSBoundParameters.Keys -contains "Verbose") {
$params["Verbose"] = $PSBoundParameters["Verbose"]
}
$configHash = Import-SpecificConfiguration -CompanyName 'SCRT HQ' -Name 'PSGSuite' @params
$configHash = Import-SpecificConfiguration -CompanyName 'SCRT HQ' -Name 'PSGSuite'
if (!$ConfigName) {
$ConfigName = if ($configHash["DefaultConfig"]){
$configHash["DefaultConfig"]
Expand Down Expand Up @@ -195,7 +191,7 @@ function Set-PSGSuiteConfig {
}
P12KeyPath {
if (-not [System.String]::IsNullOrWhiteSpace($PSBoundParameters[$key].Trim())) {
$configHash["$ConfigName"][$key] = (Encrypt $PSBoundParameters[$key])
$configHash["$ConfigName"][$key] = (Invoke-GSEncrypt $PSBoundParameters[$key])
$configHash["$ConfigName"]['P12Key'] = ([System.IO.File]::ReadAllBytes($PSBoundParameters[$key]))
}
}
Expand All @@ -204,8 +200,8 @@ function Set-PSGSuiteConfig {
}
ClientSecretsPath {
if (-not [System.String]::IsNullOrWhiteSpace($PSBoundParameters[$key].Trim())) {
$configHash["$ConfigName"][$key] = (Encrypt $PSBoundParameters[$key])
$configHash["$ConfigName"]['ClientSecrets'] = (Encrypt $(Get-Content $PSBoundParameters[$key] -Raw))
$configHash["$ConfigName"][$key] = (Invoke-GSEncrypt $PSBoundParameters[$key])
$configHash["$ConfigName"]['ClientSecrets'] = (Invoke-GSEncrypt $(Get-Content $PSBoundParameters[$key] -Raw))
}
}
Webhook {
Expand All @@ -217,7 +213,7 @@ function Set-PSGSuiteConfig {
}
foreach ($cWebhook in $PSBoundParameters[$key]) {
foreach ($cWebhookKey in $cWebhook.Keys) {
$configHash["$ConfigName"]['Chat']['Webhooks'][$cWebhookKey] = (Encrypt $cWebhook[$cWebhookKey])
$configHash["$ConfigName"]['Chat']['Webhooks'][$cWebhookKey] = (Invoke-GSEncrypt $cWebhook[$cWebhookKey])
}
}
}
Expand All @@ -231,12 +227,12 @@ function Set-PSGSuiteConfig {
$configHash["$ConfigName"]['Chat']['Spaces'] = @{}
foreach ($cWebhook in $PSBoundParameters[$key]) {
foreach ($cWebhookKey in $cWebhook.Keys) {
$configHash["$ConfigName"]['Chat']['Spaces'][$cWebhookKey] = (Encrypt $cWebhook[$cWebhookKey])
$configHash["$ConfigName"]['Chat']['Spaces'][$cWebhookKey] = (Invoke-GSEncrypt $cWebhook[$cWebhookKey])
}
}
}
default {
$configHash["$ConfigName"][$key] = (Encrypt $PSBoundParameters[$key])
$configHash["$ConfigName"][$key] = (Invoke-GSEncrypt $PSBoundParameters[$key])
}
}
}
Expand Down
74 changes: 44 additions & 30 deletions PSGSuite/Public/Configuration/Switch-PSGSuiteConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,6 @@
}
}
else {
function Decrypt {
param($String)
if ($String -is [System.Security.SecureString]) {
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto(
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR(
$string))
}
elseif ($String -is [System.String]) {
$String
}
}
$fullConf = Import-SpecificConfiguration -CompanyName 'SCRT HQ' -Name 'PSGSuite' -Scope $Script:ConfigScope -Verbose:$false
$defaultConfigName = $fullConf['DefaultConfig']
$choice = switch ($PSCmdlet.ParameterSetName) {
Expand All @@ -86,25 +75,50 @@
}
if ($choice) {
$script:PSGSuite = [PSCustomObject]($fullConf[$choice]) |
Select-Object -Property @{l = 'ConfigName';e = {$choice}},
@{l = 'P12KeyPath';e = {Decrypt $_.P12KeyPath}},
P12Key,
@{l = 'ClientSecretsPath';e = {Decrypt $_.ClientSecretsPath}},
@{l = 'ClientSecrets';e = {Decrypt $_.ClientSecrets}},
@{l = 'AppEmail';e = {Decrypt $_.AppEmail}},
@{l = 'AdminEmail';e = {Decrypt $_.AdminEmail}},
@{l = 'CustomerID';e = {Decrypt $_.CustomerID}},
@{l = 'Domain';e = {Decrypt $_.Domain}},
@{l = 'Preference';e = {Decrypt $_.Preference}},
@{l = 'ServiceAccountClientID';e = {Decrypt $_.ServiceAccountClientID}},
@{l = 'Webhook';e = {
$dict = @{}
foreach ($key in $_.Webhook.Keys) {
$dict[$key] = (Decrypt $_.Webhook[$key])
}
$dict
}},
ConfigPath
Select-Object -Property @{l = 'ConfigName';e = { $choice }},
@{l = 'P12KeyPath'; e = { Invoke-GSDecrypt $_.P12KeyPath } },
'P12Key',
@{l = 'P12KeyPassword'; e = { Invoke-GSDecrypt $_.P12KeyPassword } },
@{l = 'P12KeyObject'; e = { Invoke-GSDecrypt $_.P12KeyObject } },
@{l = 'ClientSecretsPath'; e = { Invoke-GSDecrypt $_.ClientSecretsPath } },
@{l = 'ClientSecrets'; e = { Invoke-GSDecrypt $_.ClientSecrets } },
@{l = 'AppEmail'; e = {
if ($_.AppEmail) {
Invoke-GSDecrypt $_.AppEmail
}
elseif ($_.ClientSecrets) {
(Invoke-GSDecrypt $_.ClientSecrets | ConvertFrom-Json).client_email
}
}
},
@{l = 'AdminEmail'; e = { Invoke-GSDecrypt $_.AdminEmail } },
@{l = 'CustomerID'; e = { Invoke-GSDecrypt $_.CustomerID } },
@{l = 'Domain'; e = { Invoke-GSDecrypt $_.Domain } },
@{l = 'Preference'; e = { Invoke-GSDecrypt $_.Preference } },
@{l = 'ServiceAccountClientID'; e = {
if ($_.ServiceAccountClientID) {
Invoke-GSDecrypt $_.ServiceAccountClientID
}
elseif ($_.ClientSecrets) {
(Invoke-GSDecrypt $_.ClientSecrets | ConvertFrom-Json).client_id
}
}
},
@{l = 'Chat'; e = {
$dict = @{
Webhooks = @{ }
Spaces = @{ }
}
foreach ($key in $_.Chat.Webhooks.Keys) {
$dict['Webhooks'][$key] = (Invoke-GSDecrypt $_.Chat.Webhooks[$key])
}
foreach ($key in $_.Chat.Spaces.Keys) {
$dict['Spaces'][$key] = (Invoke-GSDecrypt $_.Chat.Spaces[$key])
}
$dict
}
},
ConfigPath
if ($SetToDefault) {
if ($defaultConfigName -ne $choice) {
Write-Verbose "Setting config name '$choice' for domain '$($script:PSGSuite.Domain)' as default"
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ All other functions are either intact or have an alias included to support backw

[Full CHANGELOG here](https://github.com/scrthq/PSGSuite/blob/master/CHANGELOG.md)

#### 2.36.1 - 2020-03-02

* [Issue #263](https://github.com/scrthq/PSGSuite/issues/263)
* Fixed `[SecureString]` decryption on Unix machines running PowerShell 7 (found additional bugs)
* Migrated private `Encrypt` and `Decrypt` to `EncryptionHelpers.ps1` in the Private folder to allow a single place to update.

#### 2.36.0 - 2020-02-28

* [PR #255](https://github.com/scrthq/PSGSuite/pull/255) - _Thanks, [@FISHMANPET](https://github.com/FISHMANPET)!_
Expand Down

0 comments on commit 030e47e

Please sign in to comment.