Removing the password from Session.Output
I would like to spit out the session output to the console when I get certain exceptions. However, I noticed that the password is displayed on the "winscp> open -hostkey..." line. Not good.
I am currently planning on scanning for that line and replacing the password. The escaping makes it a little difficult.
1) Is there another way (SessionOptions, ...) to obscure this password?
2) Am I ignoring some much more efficient mechanism?
Thanks!
David
I am currently planning on scanning for that line and replacing the password. The escaping makes it a little difficult.
1) Is there another way (SessionOptions, ...) to obscure this password?
2) Am I ignoring some much more efficient mechanism?
private static void DisplaySessionException(WinSCP.SessionOptions so, WinSCP.Session sess, Exception ex)
{
Console.WriteLine("Exception encountered: {0}", ex.Message);
foreach (string s in sess.Output)
{
Console.WriteLine("\t{0}", FilterPassword(so, s));
}
}
private static string FilterPassword(WinSCP.SessionOptions so, string s)
{
if (!s.Contains("winscp>"))
return s;
string encodedPassword = so.Password
.Replace("%", "%25")
.Replace(" ", "%20")
.Replace(" ", "%20")
.Replace("+", "%2B")
.Replace("/", "%2F")
.Replace("@", "%40")
// ...
;
return s.Replace(encodedPassword, new string('*', so.Password.Length));
}Thanks!
David