From 307cfbd12f7d48bd5f626b071c7dfdbfe9a53bcb Mon Sep 17 00:00:00 2001 From: Taylor Paddock Date: Wed, 4 Oct 2017 23:14:28 -0400 Subject: [PATCH 1/2] Added FIPS check --- Module/BrocadeICX/Core/New-ICXSession.ps1 | 34 +++++++++++------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/Module/BrocadeICX/Core/New-ICXSession.ps1 b/Module/BrocadeICX/Core/New-ICXSession.ps1 index a0b7161..815ecea 100644 --- a/Module/BrocadeICX/Core/New-ICXSession.ps1 +++ b/Module/BrocadeICX/Core/New-ICXSession.ps1 @@ -24,8 +24,7 @@ https://github.com/BornToBeRoot/PowerShell_BrocadeICX/blob/master/Documentation/Function/New-ICXSession.README.md #> -function New-ICXSession -{ +function New-ICXSession { [CmdletBinding()] param( [Parameter( @@ -49,18 +48,20 @@ function New-ICXSession $Credential ) - Begin{ - + Begin { + # If FIPS is enabled, exit with error + if ((Get-ItemPropertyValue -Path HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy -Name Enabled) -eq 1) { + throw "FIPS is enabled. FIPS must be disabled to establish SSH connection." + } } - Process{ + Process { # If no credentials are submitted by parameter, prompt the user to enter them - if($Credential -eq $null) - { - try{ + if($Credential -eq $null) { + try { $Credential = Get-Credential $null } - catch{ + catch { throw "Entering credentials has been canceled by user. Can't establish SSH connection without credentials!" } } @@ -68,17 +69,14 @@ function New-ICXSession Write-Verbose -Message "Accept key is set to: $AcceptKey" # Create a new Brocade ICX session for each Switch - foreach($ComputerName2 in $ComputerName) - { + foreach($ComputerName2 in $ComputerName) { Write-Verbose -Message "Create new SSH session for ""$ComputerName2""." - try{ - if($AcceptKey) - { + try { + if($AcceptKey) { $Created_SSHSession = New-SSHSession -ComputerName $ComputerName2 -Credential $Credential -AcceptKey -ErrorAction Stop } - else - { + else { $Created_SSHSession = New-SSHSession -ComputerName $ComputerName2 -Credential $Credential -ErrorAction Stop } @@ -89,7 +87,7 @@ function New-ICXSession Write-Verbose -Message "Creating shell stream for ""$ComputerName2""..." $SSHStream = $SSHSession.Session.CreateShellStream("dumb", 0, 0, 0, 0, 1000) } - catch{ + catch { Write-Error -Message "$($_.Exception.Message)" -Category ConnectionError continue } @@ -126,7 +124,7 @@ function New-ICXSession } } - End{ + End { } } \ No newline at end of file From c6829372beae8b109df36d91113782c7810f777a Mon Sep 17 00:00:00 2001 From: Taylor Paddock Date: Wed, 4 Oct 2017 23:26:14 -0400 Subject: [PATCH 2/2] Formatting fixes --- Module/BrocadeICX/Core/New-ICXSession.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Module/BrocadeICX/Core/New-ICXSession.ps1 b/Module/BrocadeICX/Core/New-ICXSession.ps1 index 815ecea..f013fa2 100644 --- a/Module/BrocadeICX/Core/New-ICXSession.ps1 +++ b/Module/BrocadeICX/Core/New-ICXSession.ps1 @@ -1,7 +1,7 @@ ############################################################################################################### # Language : PowerShell 4.0 # Filename : New-ICXSession.ps1 -# Autor : BornToBeRoot (https://github.com/BornToBeRoot) +# Author : BornToBeRoot (https://github.com/BornToBeRoot) # Description : Create a new Brocade ICX sessions over SSH # Repository : https://github.com/BornToBeRoot/PowerShell_BrocadeICX ############################################################################################################### @@ -42,7 +42,7 @@ function New-ICXSession { [Parameter( Position=2, Mandatory=$false, - HelpMessage='Credentials to authenticate agains a Brocade ICX Switch (SSH connection)')] + HelpMessage='Credentials to authenticate against a Brocade ICX Switch (SSH connection)')] [System.Management.Automation.PSCredential] [System.Management.Automation.CredentialAttribute()] $Credential @@ -57,7 +57,7 @@ function New-ICXSession { Process { # If no credentials are submitted by parameter, prompt the user to enter them - if($Credential -eq $null) { + if ($Credential -eq $null) { try { $Credential = Get-Credential $null } @@ -69,11 +69,11 @@ function New-ICXSession { Write-Verbose -Message "Accept key is set to: $AcceptKey" # Create a new Brocade ICX session for each Switch - foreach($ComputerName2 in $ComputerName) { + foreach ($ComputerName2 in $ComputerName) { Write-Verbose -Message "Create new SSH session for ""$ComputerName2""." try { - if($AcceptKey) { + if ($AcceptKey) { $Created_SSHSession = New-SSHSession -ComputerName $ComputerName2 -Credential $Credential -AcceptKey -ErrorAction Stop } else { @@ -103,7 +103,7 @@ function New-ICXSession { Stream = $SSHStream } - # Set the default parameter set + # Set the default parameter set $ICXSession.PSObject.TypeNames.Insert(0,'BrocadeICX.ICXSession') $DefaultDisplaySet = 'SessionID', 'ComputerName', 'AccessMode' $DefaultDisplayPropertySet = New-Object System.Management.Automation.PSPropertySet('DefaultDisplayPropertySet',[string[]]$DefaultDisplaySet)