Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature ssl protocol from master #158

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Expand Up @@ -20,8 +20,6 @@ Note: this module is not in any way developed or supported by anyone officially

#### Desktop

* 4.0
* 5.0
* 5.1

#### Core
Expand Down
37 changes: 34 additions & 3 deletions src/Functions/Public/Connect-vRAServer.ps1
@@ -1,4 +1,4 @@
function Connect-vRAServer {
function Connect-vRAServer {
<#
.SYNOPSIS
Connect to a vRA Server
Expand All @@ -24,6 +24,12 @@
.PARAMETER IgnoreCertRequirements
Ignore requirements to use fully signed certificates

.PARAMETER SslProtocol
Alternative Ssl protocol to use from the default
Requires vRA 7.x and above
Windows PowerShell: Ssl3, Tls, Tls11, Tls12
PowerShell Core: Tls, Tls11, Tls12

.INPUTS
System.String
System.SecureString
Expand Down Expand Up @@ -65,8 +71,11 @@
[Management.Automation.PSCredential]$Credential,

[parameter(Mandatory=$false)]
[Switch]$IgnoreCertRequirements
[Switch]$IgnoreCertRequirements,

[parameter(Mandatory=$false)]
[ValidateSet('Ssl3', 'Tls', 'Tls11', 'Tls12')]
[String]$SslProtocol
)

# --- Default Signed Certificates to true
Expand Down Expand Up @@ -98,6 +107,22 @@

}

# --- Security Protocol
$SslProtocolResult = 'Default'

if ($PSBoundParameters.ContainsKey("SslProtocol") ){

if ($PSVersionTable.PSEdition -eq "Desktop" -or !$PSVersionTable.PSEdition) {

$CurrentProtocols = ([System.Net.ServicePointManager]::SecurityProtocol).toString() -split ', '
if (!($SslProtocol -in $CurrentProtocols)){

[System.Net.ServicePointManager]::SecurityProtocol += [System.Net.SecurityProtocolType]::$($SslProtocol)
}
}
$SslProtocolResult = $SslProtocol
}

# --- Convert Secure Credentials to a format for sending in the JSON payload
if ($PSBoundParameters.ContainsKey("Credential")){

Expand Down Expand Up @@ -139,6 +164,12 @@

}

if (($SslProtocolResult -ne 'Default') -and ($PSVersionTable.PSEdition -eq "Core")) {

$Params.Add("SslProtocol", $SslProtocol)

}

$Response = Invoke-RestMethod @Params

# --- Create Output Object
Expand All @@ -150,7 +181,7 @@
Username = $Username
APIVersion = $Null
SignedCertificates = $SignedCertificates

SslProtocol = $SslProtocolResult
}

# --- Update vRAConnection with tenant and api version
Expand Down
11 changes: 10 additions & 1 deletion src/Functions/Public/Disconnect-vRAServer.ps1
@@ -1,4 +1,4 @@
function Disconnect-vRAServer {
function Disconnect-vRAServer {
<#
.SYNOPSIS
Disconnect from a vRA server
Expand Down Expand Up @@ -29,6 +29,15 @@
# --- Remove the token from vRA and remove the global PowerShell variable
$URI = "/identity/api/tokens/$($Global:vRAConnection.Token)"
Invoke-vRARestMethod -Method DELETE -URI $URI -Verbose:$VerbosePreference

# --- Remove custom Security Protocol if it has been specified
if ($Global:vRAConnection.SslProtocol -ne 'Default'){

if ($PSVersionTable.PSEdition -eq "Desktop" -or !$PSVersionTable.PSEdition) {

[System.Net.ServicePointManager]::SecurityProtocol -= [System.Net.SecurityProtocolType]::$($Global:vRAConnection.SslProtocol)
}
}

}
catch [Exception]{
Expand Down
8 changes: 7 additions & 1 deletion src/Functions/Public/Invoke-vRARestMethod.ps1
@@ -1,4 +1,4 @@
function Invoke-vRARestMethod {
function Invoke-vRARestMethod {
<#
.SYNOPSIS
Wrapper for Invoke-RestMethod/Invoke-WebRequest with vRA specifics
Expand Down Expand Up @@ -133,6 +133,12 @@
$Params.Add("SkipCertificateCheck", $true);
}

# --- Support for PowerShell Core SSL protocol checking
if (($Global:vRAConnection.SslProtocol -ne 'Default') -and ($PSVersionTable.PSEdition -eq "Core")) {

$Params.Add("SslProtocol", $Global:vRAConnection.SslProtocol);
}

try {

# --- Use either Invoke-WebRequest or Invoke-RestMethod
Expand Down