How to securely deploy PPK file in WPF C# app?

我的梦境 提交于 2019-12-23 03:45:17

问题


I have a C# app that connects to a SFTP server to transfer log files. The app achieves this by using WinSCP .NET assembly to connect to the server.

How do I securely store the .ppk private key file such that the user is not able to take this file to access the SFTP for themselves?

http://winscp.net/eng/docs/library#csharp

Based on the way the library reference the .ppk, it may not be possible to avoid storing the .ppk file on the local disk during run-time?

Thanks in advance.


回答1:


There's generally no way to hide any kind of credentials that (any) application possess from the end user. You can only make them hard to be found, but it's questionable whether it is even worth the effort.

What you can (and should do) is to make sure the credentials grants only as little access as necessary.

So in your case, make sure the account, you authenticate with the private key:

  • has only write access (no read access, nor even list)
  • and has a low disk quota
  • is regularly (or automatically) monitored for any unusual activity

Specifically regarding the private key for WinSCP .NET assembly:

Yes, it has to be stored on the disk (i.e. temporarily extracted to a temp folder). Though you can have the private key encrypted with a passphrase. And have the passphrase hard-coded in the application (obfuscated if your want).

See SessionOptions.SshPrivateKeyPassphrase.


See also WinSCP article on Protecting credentials used for automation.




回答2:


Since the WinSCP .NET assembly is calling the command-line scripting interface there is probably no way to do this. I'm one of the developers of edtFTPnet/PRO, which is a native .NET implementation of various file-transfer protocols, including SFTP. Our interface allows you to set the private key using a byte-array (see SecureFTPConnection.ClientPrivateKeyBytes). Our product is not free, but it should get you where you want to go.



来源:https://stackoverflow.com/questions/31531103/how-to-securely-deploy-ppk-file-in-wpf-c-sharp-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!