WebDav over Powershell with 2 Factor auth

Advertisement

CSDBA
Guest

WebDav over Powershell with 2 Factor auth

Hello,

Perhaps someone could point me in the right direction. I'm trying to connect to a WebDav host using WinSCP & Powershell
Connecting to this WebDav host works 100% in the WinSCP client itself. i specify the location of the certificate, put the host address and remote directories in under advanced. when i then connect I am prompted for 2 passwords. First the certificate PW, then the user / pass for the webdav host itself.

I would now like to do this via powershell. I noticed that you can generate the session code from the client - see below
the generated code specified the webdav host username and the certificate password. The actual webdav host password is not specified.



# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"

# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Webdav
HostName = "cert.domainname.com"
PortNumber = 443
UserName = "hostusername"
Password = "certificatepassword"
WebdavSecure = $True
TlsClientCertificatePath = "C:\OpenSSL-Win64\certificate"
}

$session = New-Object WinSCP.Session

try
{
# Connect
$session.Open($sessionOptions)

# Your code
}
finally
{
$session.Dispose()
}

In the end when I try to connect i get the following error


Exception calling "Open" with "1" argument(s): "SSL handshake failed, client certificate was requested: SSL error: sslv3 alert handshake failure
Connection failed."
At line:20 char:5
+ $session.Open($sessionOptions)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SessionRemoteException


If it works with the client surely it can be done using the .net assembly and PS

thanks in advance for any help or suggestions

Reply with quote

Advertisement

You can post new topics in this forum