Skip to content
Open
Show file tree
Hide file tree
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
64 changes: 0 additions & 64 deletions Posh-SSH/Add-SshIdentity.ps1

This file was deleted.

Binary file modified Posh-SSH/Assembly/BouncyCastle.Cryptography.dll
Binary file not shown.
Binary file modified Posh-SSH/Assembly/Microsoft.Bcl.AsyncInterfaces.dll
Binary file not shown.
Binary file not shown.
Binary file modified Posh-SSH/Assembly/Renci.SshNet.dll
Binary file not shown.
24,533 changes: 0 additions & 24,533 deletions Posh-SSH/Assembly/Renci.SshNet.xml

This file was deleted.

Binary file not shown.
Binary file modified Posh-SSH/Assembly/System.Runtime.CompilerServices.Unsafe.dll
Binary file not shown.
Binary file modified Posh-SSH/Assembly/System.Threading.Tasks.Extensions.dll
Binary file not shown.
25 changes: 14 additions & 11 deletions Posh-SSH/Posh-SSH.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#RootModule = ''

# Version number of this module.
ModuleVersion = '3.2.7'
ModuleVersion = '4.0.0'

# ID used to uniquely identify this module
GUID = 'f5c99306-7b5a-4fca-a052-f79ad1e48fbf'
Expand Down Expand Up @@ -75,7 +75,6 @@ FunctionsToExport = @('Get-PoshSSHModVersion',
'Get-SFTPSession',
'Get-SSHPortForward',
'Get-SSHSession',
'Get-SSHTrustedHost',
'Invoke-SSHCommand',
'Invoke-SSHCommandStream',
'Invoke-SSHStreamExpectAction',
Expand All @@ -89,20 +88,19 @@ FunctionsToExport = @('Get-PoshSSHModVersion',
'New-SSHLocalPortForward',
'New-SSHRemotePortForward',
'New-SSHShellStream',
'New-SSHTrustedHost',
'Remove-SFTPItem',
'Remove-SFTPSession',
'Remove-SSHSession',
'Remove-SSHTrustedHost',
'Rename-SFTPFile',
'Set-SFTPContent',
'Set-SFTPLocation',
'Set-SFTPPathAttribute',
'Start-SSHPortForward',
'Stop-SSHPortForward',
'Test-SFTPPath',
'Convert-SSHRegistryToJsonKnownHost',
'Get-SSHRegistryKnownHost')
'Convert-SSHRegistryToJsonTrustedHost',
'Get-SSHRegistryTrustedHostStore'
)

# Cmdlets to export from this module
CmdletsToExport = @('Get-SCPItem',
Expand All @@ -111,10 +109,15 @@ CmdletsToExport = @('Get-SCPItem',
'New-SSHSession',
'Set-SCPItem',
'Set-SFTPItem',
'New-SSHMemoryKnownHost',
'Get-SSHJsonKnownHost',
'Get-SSHOpenSSHKnownHost',
'Get-SSHHostKey')
'New-SSHMemoryTrustedHostStore',
'Get-SSHJsonTrustedHostStore',
'Get-SSHOpenSSHTrustedHostStore',
'Get-SSHHostKey',
'New-SSHTrustedHost',
'Add-SSHTrustedHost',
'Get-SSHTrustedHost',
'Remove-SSHTrustedHost'
)

# Variables to export from this module
VariablesToExport = '*'
Expand All @@ -131,7 +134,7 @@ FileList = @('Posh-SSH.psm1','PoshSSH.dll','Assembly\Renci.SshNet.dll', 'Assembl
# Private data to pass to the module specified in RootModule/ModuleToProcess
PrivateData = @{
PSData = @{
#Prerelease = 'beta1'
Prerelease = 'beta1'
ProjectUri = 'https://github.com/darkoperator/Posh-SSH'
}
}
Expand Down
192 changes: 13 additions & 179 deletions Posh-SSH/Posh-SSH.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ if (!(Test-Path variable:Global:SFTPSessions ))
$global:SFTPSessions = New-Object System.Collections.ArrayList
}

New-Alias -Name 'Get-SSHJsonKnowHost' -Value 'Get-SSHJsonKnownHost' -Force

# SSH Functions
##############################################################################################

Expand Down Expand Up @@ -366,7 +364,7 @@ function Invoke-SSHCommand
}

$cmd = $Connection.session.CreateCommand($Command)
$cmd.CommandTimeout = [timespan]::FromMilliseconds(50) #New-TimeSpan -Seconds $TimeOut
$cmd.CommandTimeout = [timespan]::FromSeconds($TimeOut)

# start asynchronious execution of the command.
$Duration = [System.Diagnostics.Stopwatch]::StartNew()
Expand Down Expand Up @@ -1951,7 +1949,7 @@ function Set-SFTPPathAttribute
function Get-SFTPPathInformation
{
[CmdletBinding()]
[OutputType([Renci.SshNet.Sftp.SftpFileSytemInformation])]
[OutputType([Renci.SshNet.Sftp.SftpFileSystemInformation])]
Param
(
[Parameter(Mandatory=$true,
Expand Down Expand Up @@ -3142,191 +3140,27 @@ function Start-SSHPortForward
End{}
}

# .ExternalHelp Posh-SSH.psm1-Help.xml
function Get-SSHTrustedHost
{
[CmdletBinding(DefaultParameterSetName = "Local")]
[OutputType("SSH.Stores.KnownHostRecord")]
Param(
# Known Host Store
[Parameter(Mandatory = $true,
ParameterSetName = "Store",
ValueFromPipeline = $true,
Position = 1)]
[Alias('KnowHostStore')]
[SSH.Stores.IStore]
$KnownHostStore,

# Host name the key fingerprint is associated with.
[Parameter(Mandatory = $false,
Position = 0)
]
[String]
$HostName
)

Begin{
$Default = [IO.Path]::Combine($Home,".poshssh", "hosts.json")
}
Process
{
if ($PSCmdlet.ParameterSetName -eq "Local") {
$Store = Get-SSHJsonKnownHost
if (-not (Test-Path -PathType Leaf $Default)) {
Write-Warning -Message "No known host file found, $($Default)"
}
} elseif ($PSCmdlet.ParameterSetName -eq "Store") {
$Store = $KnownHostStore
}

if ($PSBoundParameters.Keys -contains "HostName") {
$k = $Store.GetKey($HostName)
if ($k) {
$k | Add-Member -Force -MemberType NoteProperty -Name "HostName" -Value $HostName -TypeName "SSH.Stores.KnownHostRecord" -PassThru
}
} else {
$Store.GetAllKeys()
}
}
End
{}
}


# .ExternalHelp Posh-SSH.psm1-Help.xml
function New-SSHTrustedHost
{
[CmdletBinding(DefaultParameterSetName = "Local")]
Param
(
# IP Address of FQDN of host to add to trusted list.
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
$HostName,

# SSH Server Fingerprint. (md5 of host public key)
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=1)]
$FingerPrint,

# This is the hostkey cipher name.
[ValidateSet(
"ssh-ed25519",
"ecdsa-sha2-nistp256",
"ecdsa-sha2-nistp384",
"ecdsa-sha2-nistp521",
"rsa-sha2-512",
"rsa-sha2-256",
"ssh-rsa",
"ssh-dss"
)]
[Parameter(
ValueFromPipelineByPropertyName=$true,
Position=2)]
[string]
[Alias('KeyCipherName')]
$HostKeyName = "",

# Known Host Store
[Parameter(Mandatory = $true,
ParameterSetName = "Store")]
[Alias('KnowHostStore')]
[SSH.Stores.IStore]
$KnownHostStore
)

Begin{
$Default = [IO.Path]::Combine($Home,".poshssh", "hosts.json")
}
Process
{
if ($PSCmdlet.ParameterSetName -eq "Local") {
$Store = Get-SSHJsonKnownHost
if (-not (Test-Path -PathType Leaf $Default)) {
Write-Warning -Message "No known host file found, $($Default)"
}
} elseif ($PSCmdlet.ParameterSetName -eq "Store") {
$Store = $KnownHostStore
}

$Store.SetKey($HostName, $HostKeyName, $FingerPrint)
}
End {}
}

# .ExternalHelp Posh-SSH.psm1-Help.xml
function Remove-SSHTrustedHost
{
[CmdletBinding(DefaultParameterSetName = "Local")]
Param(
# IP Address of FQDN of host to add to trusted list.
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string]
$HostName,

# Known Host Store
[Parameter(Mandatory = $true,
ParameterSetName = "Store")]
[Alias('KnowHostStore')]
[SSH.Stores.IStore]
$KnownHostStore
)

Begin{
$Default = [IO.Path]::Combine($Home,".poshssh", "hosts.json")
}
Process{
if ($PSCmdlet.ParameterSetName -eq "Local") {
$Store = Get-SSHJsonKnownHost
if (-not (Test-Path -PathType Leaf $Default)) {
Write-Warning -Message "No known host file found, $($Default)"
}
} elseif ($PSCmdlet.ParameterSetName -eq "Store") {
if ($KnownHostStore -isnot [SSH.Stores.OpenSSHStore]) {
$Store = $KnownHostStore
} else {
Write-Error -Message "SSH.Stores.OpenSSHStore are a Read Only store." -ErrorAction Stop
}
}

$Store.RemoveByHost($HostName)
}
End{}
}

<#
<#
.SYNOPSIS
Get KnownHosts from registry (readonly)
Get TrustedHosts from registry (readonly)
.DESCRIPTION
Get KnownHosts from registry (readonly)
Get TrustedHosts from registry (readonly)
It is windows-only compatibility cmdlet
.EXAMPLE
PS C:\> Get-SSHRegistryTrustedHostStore
#>
function Get-SSHRegistryKnownHost {
class SSHRegistryKeyStore: SSH.Stores.MemoryStore {
function Get-SSHRegistryTrustedHostStore {
class SSHRegistryKeyStore: SSH.Stores.MemoryTrustedHostStore {
[void] OnGetKeys() {
$p = Get-ItemProperty HKCU:\SOFTWARE\PoshSSH
$HostKeys = $this.HostKeys
$p | Get-Member -MemberType NoteProperty |
Where-Object { $_.Name -notin 'PSPath', 'PSParentPath', 'PSChildName', 'PSDrive', 'PSProvider' } |
ForEach-Object {
$name = $_.Name
$hostData = [SSH.Stores.KnownHostValue]@{ HostKeyName='ssh-rsa'; Fingerprint=$p.$name }
$HostKeys.AddOrUpdate($name, $hostData, { return $hostData } )
$this.SetKey($name, 'ssh-rsa', $p.$name, $true)
}
}
[bool]SetKey([string]$HostName, [string]$KeyType, [string]$Fingerprint) {
return $false
}
[bool]RemoveByHost([string] $HostName) {
return $false
}
[bool]RemoveByFingerprint([string] $Fingerprint) {
return $false
}
}

New-Object SSHRegistryKeyStore
Expand All @@ -3339,14 +3173,14 @@ function Get-SSHRegistryKnownHost {
Convert windows registry key storage to Json
It is windows-only compatibility cmdlet
#>
function Convert-SSHRegistryToJSonKnownHost {
$JsonStore = Get-SSHJsonKnownHost
function Convert-SSHRegistryToJSonTrustedHost {
$JsonStore = Get-SSHJsonTrustedHostStore
$p = Get-ItemProperty HKCU:\SOFTWARE\PoshSSH
$p | Get-Member -MemberType NoteProperty |
Where-Object { $_.Name -notin 'PSPath', 'PSParentPath', 'PSChildName', 'PSDrive', 'PSProvider' } |
ForEach-Object {
$name = $_.Name
Write-Host "Save ssh-rsa key for $name"
[void]$JsonStore.SetKey($name, 'ssh-rsa', $p.$name)
[void]$JsonStore.SetKey($name, 'ssh-rsa', $p.$name, $true)
}
}
Binary file modified Posh-SSH/PoshSSH.dll
Binary file not shown.
Loading