Skip to content
This repository was archived by the owner on Sep 5, 2020. It is now read-only.

Add FIPS check #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions Module/BrocadeICX/Core/New-ICXSession.ps1
Original file line number Diff line number Diff line change
@@ -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
###############################################################################################################
Expand All @@ -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(
Expand All @@ -43,42 +42,41 @@ 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
)

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!"
}
}

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
}

Expand All @@ -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
}
Expand All @@ -105,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)
Expand All @@ -126,7 +124,7 @@ function New-ICXSession
}
}

End{
End {

}
}