Skip to content

Commit

Permalink
Merge pull request #155 from lipkau/fix/#143-SupportTLS1.2
Browse files Browse the repository at this point in the history
Add support for TLS1.2
  • Loading branch information
lipkau authored Dec 5, 2018
2 parents ea6a1c7 + 7cd833b commit 5c7a064
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ConfluencePS/Private/Set-TlsLevel.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function Set-TlsLevel {
[CmdletBinding( SupportsShouldProcess = $false )]
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseShouldProcessForStateChangingFunctions', '')]
param (
[Parameter(Mandatory, ParameterSetName = 'Set')]
[Switch]$Tls12,

[Parameter(Mandatory, ParameterSetName = 'Revert')]
[Switch]$Revert
)

begin {
switch ($PSCmdlet.ParameterSetName) {
"Set" {
$Script:OriginalTlsSettings = [Net.ServicePointManager]::SecurityProtocol

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
}
"Revert" {
if ($Script:OriginalTlsSettings) {
[Net.ServicePointManager]::SecurityProtocol = $Script:OriginalTlsSettings
}
}
}
}
}
4 changes: 4 additions & 0 deletions ConfluencePS/Public/Invoke-Method.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ function Invoke-Method {
BEGIN {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started"

Set-TlsLevel -Tls12

# pass input to local variable
# this allows to use the PSBoundParameters for recursion
$_headers = @{ # Set any default headers
Expand Down Expand Up @@ -253,6 +255,8 @@ function Invoke-Method {
}

END {
Set-TlsLevel -Revert

Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function ended"
}
}

0 comments on commit 5c7a064

Please sign in to comment.