Skip to content
This repository was archived by the owner on May 20, 2024. It is now read-only.
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
2 changes: 1 addition & 1 deletion SftpSync/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
[assembly: AssemblyVersion("2.2")]
[assembly: Guid ("363be07e-f6fb-49c5-af78-85405bd9c3f3")]
[assembly: NeutralResourcesLanguage ("en")]
[assembly: AssemblyFileVersion("2.2")]
[assembly: AssemblyFileVersion("2.2.7")]

Binary file modified SftpSync/Renci.SshNet.dll
Binary file not shown.
3 changes: 3 additions & 0 deletions SftpSync/SftpSync.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
<PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
<PropertyGroup>
<ReferencePath>$(MSBuildProjectDirectory)\..\..\bins\KeePass\</ReferencePath>
</PropertyGroup>
</Project>
226 changes: 127 additions & 99 deletions SftpSync/SftpWebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,37 @@
using System.Diagnostics;
using System.Collections.Generic;
using Renci.SshNet.Common;
using Renci.SshNet.Pageant;
using System.Text;

namespace SftpSync
{
public class SftpWebRequest: WebRequest, IHasIocProperties
public class SftpWebRequest : WebRequest, IHasIocProperties
{
private readonly Uri m_uri;

private readonly Uri m_uri;
private List<byte> m_reqBody = new List<byte>();
private byte[] m_fingerprint;

public override Uri RequestUri {
get {
return m_uri;
}
}
public override Uri RequestUri
{
get
{
return m_uri;
}
}

private string m_strMethod = string.Empty;
private string m_strMethod = string.Empty;

public override string Method
{
get { return m_strMethod; }
set
{
if(value == null) throw new ArgumentNullException("value");
m_strMethod = value;
}
}
public override string Method
{
get { return m_strMethod; }
set
{
if (value == null) throw new ArgumentNullException("value");
m_strMethod = value;
}
}

private WebHeaderCollection m_whcHeaders = new WebHeaderCollection();

Expand All @@ -50,75 +53,75 @@ public override WebHeaderCollection Headers

private long m_lContentLength = 0;

public override long ContentLength
{
get { return m_lContentLength; }
set
{
if(value < 0) throw new ArgumentOutOfRangeException("value");
m_lContentLength = value;
}
}

private string m_strContentType = string.Empty;

public override string ContentType
{
get { return m_strContentType; }
set
{
if(value == null) throw new ArgumentNullException("value");
m_strContentType = value;
}
}

private ICredentials m_cred = null;
public override ICredentials Credentials
{
get { return m_cred; }
set { m_cred = value; }
}

private bool m_bPreAuth = true;

public override bool PreAuthenticate
{
get { return m_bPreAuth; }
set { m_bPreAuth = value; }
}

private IWebProxy m_prx = null;

public override IWebProxy Proxy
{
get { return m_prx; }
set { m_prx = value; }
}

private IocProperties m_props = new IocProperties();

public IocProperties IOConnectionProperties
{
get { return m_props; }
set
{
if(value == null) { Debug.Assert(false); return; }
m_props = value;
}
}

public SftpWebRequest(Uri uri)
{
if(uri == null) throw new ArgumentNullException("uri");
m_uri = uri;
}

public override Stream GetRequestStream()
{
public override long ContentLength
{
get { return m_lContentLength; }
set
{
if (value < 0) throw new ArgumentOutOfRangeException("value");
m_lContentLength = value;
}
}

private string m_strContentType = string.Empty;

public override string ContentType
{
get { return m_strContentType; }
set
{
if (value == null) throw new ArgumentNullException("value");
m_strContentType = value;
}
}

private ICredentials m_cred = null;
public override ICredentials Credentials
{
get { return m_cred; }
set { m_cred = value; }
}

private bool m_bPreAuth = true;

public override bool PreAuthenticate
{
get { return m_bPreAuth; }
set { m_bPreAuth = value; }
}

private IWebProxy m_prx = null;

public override IWebProxy Proxy
{
get { return m_prx; }
set { m_prx = value; }
}

private IocProperties m_props = new IocProperties();

public IocProperties IOConnectionProperties
{
get { return m_props; }
set
{
if (value == null) { Debug.Assert(false); return; }
m_props = value;
}
}

public SftpWebRequest(Uri uri)
{
if (uri == null) throw new ArgumentNullException("uri");
m_uri = uri;
}

public override Stream GetRequestStream()
{
m_reqBody.Clear();
return new CopyMemoryStream(m_reqBody);
}
}

public override WebResponse GetResponse()
{
NetworkCredential cred = (m_cred as NetworkCredential);
Expand All @@ -130,7 +133,7 @@ public override WebResponse GetResponse()
int l_port = m_uri.Port == -1 ? 22 : m_uri.Port;

Uri uriTo = null;

if (m_strMethod == KeePassLib.Serialization.IOConnection.WrmMoveFile) uriTo = new Uri(m_whcHeaders.Get(
IOConnection.WrhMoveFileTo));

Expand All @@ -139,18 +142,43 @@ public override WebResponse GetResponse()

ConnectionInfo n_con_info;

if (m_props.Get("SSHKey") != null)
if (File.Exists(m_props.Get("SSHKey")))
{
using (FileStream keyStream = new FileStream(m_props.Get("SSHKey"), FileMode.Open))
{
PrivateKeyFile v_keyauth;

if (strPassword == null)
v_keyauth = new PrivateKeyFile(keyStream);
else
v_keyauth = new PrivateKeyFile(keyStream, strPassword);

n_con_info = new PrivateKeyConnectionInfo(m_uri.Host, l_port, strUser, v_keyauth);
}

}
else if (!String.IsNullOrWhiteSpace(m_props.Get("SSHKey")))
{
string keyString = m_props.Get("SSHKey").Replace("\\n", "\n");
MemoryStream keyStream = new MemoryStream(Encoding.ASCII.GetBytes(keyString));
PrivateKeyFile v_keyauth;
using (MemoryStream keyStream = new MemoryStream(Encoding.ASCII.GetBytes(keyString)))
{
PrivateKeyFile v_keyauth;

if (strPassword == null)
v_keyauth = new PrivateKeyFile(keyStream);
else
v_keyauth = new PrivateKeyFile(keyStream, strPassword);

if (strPassword == null)
v_keyauth = new PrivateKeyFile(keyStream);
else
v_keyauth = new PrivateKeyFile(keyStream, strPassword);
n_con_info = new PrivateKeyConnectionInfo(m_uri.Host, l_port, strUser, v_keyauth);
}
}
else if (String.IsNullOrWhiteSpace(m_props.Get("SSHKey")) &&
String.IsNullOrWhiteSpace(strPassword))
{
// No password, no keyfile, try pageant
PageantProtocol agent = new PageantProtocol();
n_con_info = new AgentConnectionInfo(m_uri.Host, l_port, strUser, agent);

n_con_info = new PrivateKeyConnectionInfo(m_uri.Host, l_port, strUser, v_keyauth);
}
else
{
Expand All @@ -170,7 +198,7 @@ public override WebResponse GetResponse()
{
int.TryParse(m_props.Get("SSHTimeout"), out connectionTimeout);
}

m_Client.ConnectionInfo.Timeout = new TimeSpan(0, 0, 0, 0, connectionTimeout);

if (m_props.Get("HostKey") != null)
Expand All @@ -179,11 +207,11 @@ public override WebResponse GetResponse()
if (v_ssh_dss_parts.Length != 16) throw new Exception("Input incorrect host fingerprint. Check it. Must look like: 12:34:56:78:90:ab:cd:ef:12:34:56:78:90:ab:cd:ef");
List<byte> v_ssh_dss_parts_b = new List<byte>();
foreach (string str in v_ssh_dss_parts)
{
{
try
{
v_ssh_dss_parts_b.Add(byte.Parse(str, System.Globalization.NumberStyles.AllowHexSpecifier));
}
}
catch (Exception)
{
throw new Exception("Input incorrect host fingerprint. Check it. Must look like: 12:34:56:78:90:ab:cd:ef:12:34:56:78:90:ab:cd:ef");
Expand All @@ -194,7 +222,7 @@ public override WebResponse GetResponse()
m_Client.HostKeyReceived += M_Client_HostKeyReceived;

}

return new SftpWebResponse(m_Client, m_strMethod, m_uri, uriTo, reqStream);
}

Expand All @@ -211,7 +239,7 @@ private void SftpWebRequest_AuthenticationPrompt(object sender, Renci.SshNet.Com

private void M_Client_HostKeyReceived(object sender, Renci.SshNet.Common.HostKeyEventArgs e)
{
e.CanTrust = e.FingerPrint.SequenceEqual(m_fingerprint) ?true: false;
e.CanTrust = e.FingerPrint.SequenceEqual(m_fingerprint) ? true : false;
}
}
}
5 changes: 2 additions & 3 deletions make_plgx.cmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
@echo off
echo "%CD%\..\bins\KeePass\KeePass.exe" --plgx-create %cd%\SftpSync --plgx-prereq-kp:2.18 --plgx-prereq-net:4.0 --debug
call "%CD%\..\bins\KeePass\KeePass.exe" --plgx-create %cd%\SftpSync --plgx-prereq-kp:2.18 --plgx-prereq-net:4.0 --debug
@echo on
call "%CD%\..\bins\KeePass\KeePass.exe" --plgx-create %cd%\SftpSync --plgx-prereq-kp:2.18 --plgx-prereq-net:4.0