具有非基于文件的密钥的 SFTP

发布于 2024-10-05 22:36:28 字数 677 浏览 1 评论 0 原文

我计划使用带有公钥/私钥身份验证的 SFTP 编写一些软件,以将文件上传到服务器。我想知道人们如何建议管理密钥(尤其是私钥)。

我的目标平台是使用 C# 或 C++ 的 Windows。我查看了许多库:

C#
(免费/开放)
SharpSSH
Granados

(商业)
Rebex

C++
libcurl/OpenSSH

所有这些似乎都需要将私钥存储在文件系统上,这出于安全原因我宁愿避免。我也不想自己实施身份验证,尽管我承认这是一种选择。我的问题:

有没有办法直接从内存中提供这些库(或我可能忽略的任何库/API)键值,而不是从文件加载?

如果没有,管理这些关键文件的推荐方法是什么?除了密码加密和严格的访问控制之外,还应该采取其他措施来保护密钥文件吗?

I'm planning to write some software using SFTP with public/private key authentication to upload files to a server. I am wondering how people recommend managing the keys (especially the private key).

My target platform is Windows with C# or C++. I've looked at a number of libraries:

C#
(free/open)
SharpSSH
Granados

(commercial)
Rebex

C++
libcurl/OpenSSH

All of these appear to require the private key to be stored on the filesystem, which I would prefer to avoid for security reasons. I would also prefer not to implement the authentication myself although I recognize that as an option. My questions:

Is there a way to feed any of these libraries (or any library/API I may have overlooked) the key values directly from memory instead of loading from a file?

If not, what is the recommended way to manage these key files? Beyond password encryption and tight access control, are there other things one should do to protect the key file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

舟遥客 2024-10-12 22:36:28

所有这些似乎都需要
私钥存储在
文件系统,我更喜欢
出于安全原因避免。

我认为你应该拥抱文件系统。 NTFS(作为 Windows 开发人员,您几乎肯定会使用它)等现代文件系统具有强大的安全机制,这些机制可能比您(或我)可能设计的大多数替代机制都经过深思熟虑。 NTFS 有访问控制列表、加密等等——如果您不能相信您的文件系统能够保证数据安全,那么您为什么还要费心去关心网络流量呢?

我会注意到,有一些特定的情况可能会妨碍我上面所说的操作,但我没有看到原始帖子中提到的任何情况。

All of these appear to require the
private key to be stored on the
filesystem, which I would prefer to
avoid for security reasons.

I think you should embrace the filesystem. Modern ones such as NTFS (which as a Windows developer you are almost surely using) have robust security mechanisms which are probably better thought out than most any alternative mechanism you (or I) might devise. NTFS has access control lists, encryption, and so on--if you can't trust your filesystem to keep your data safe, why do you even bother caring about network traffic?

I'll note that there are some specific circumstances which could preclude doing what I've said above, but I don't see any of them mentioned in the original post.

鹤舞 2024-10-12 22:36:28

我从未使用过 Granados,但该库的 SSH2UserAuthKey 类 有一个 FromSECSHStyleStream 方法,可以从任意 Stream(可以是 MemoryStream,如果您想直接从内存加载密钥)。看起来这可以让你绕过文件系统进行密钥存储。

Rebex.Net 有一个 SshPrivateKey 类构造函数,可以从 字节加载[];这也应该让你避免文件系统。

虽然我没有检查其他库,但似乎所有库都会提供从 byte[]MemoryStream 加载密钥的方法unsigned char*,具有直接从文件加载的便捷方法。

不过,这些 API 并没有解决私钥实际存储方式的问题。您可以对其进行密码保护(这似乎是 SSH 私钥的一种相当常见的方法)或使用 ProtectedData 类,使用当前 Windows 用户的凭据对其进行加密。

I've never used Granados, but that library's SSH2UserAuthKey class has a FromSECSHStyleStream method that loads a user's authentication key from an arbitrary Stream (which could be a MemoryStream if you want to load the key directly from memory). It seems like this would let you bypass the filesystem for key storage.

Rebex.Net has a SshPrivateKey class constructor that can load from a byte[]; this should also let you avoid the filesystem.

While I haven't checked the other libraries, it seems likely that all of them would provide methods to load a key from a byte[], MemoryStream, or unsigned char*, with convenience methods that load directly from a file.

These APIs don't solve the problem of how the private key will actually be stored, though. You could password-protect it (this seems a fairly common approach with SSH private keys) or use the ProtectedData class to encrypt it with the current Windows user's credentials.

冷夜 2024-10-12 22:36:28

SecureBlackbox(我们的产品)的 SFTP 类 可让您从任何流或字节数组。此外,它们还允许您生成和转换各种格式的 SSH 密钥。

如果您有疑问,我们可以通过论坛服务台

SFTP classes of SecureBlackbox (our product) let you load the key from any stream or byte array. Moreover, they also let you generate and convert SSH keys in various formats.

If you have questions, we provide support to evaluating users via Forum and HelpDesk

原谅我要高飞 2024-10-12 22:36:28

以下代码显示了如何使用 Rebex SFTP 使用私钥进行身份验证。

代码取自以下 论坛帖子。有关详细信息,请查看 SFTP 教程

// create client and connect 
Sftp client = new Sftp();
client.Connect(hostname);

// instead of loading it from disk file load the private key from a byte array
//SshPrivateKey privateKey = new SshPrivateKey("key_rsa.pem", "password");

byte[] privateKeyData = YourMethodForObtainingPrivateKey();    
SshPrivateKey privateKey = new SshPrivateKey(privateKeyData, "password");

// authenticate 
client.Login(username, privateKey);

// ... 

Following code shows how to authenticate using a private key using Rebex SFTP.

Code is taken from following forum post. For more info check SFTP tutorial.

// create client and connect 
Sftp client = new Sftp();
client.Connect(hostname);

// instead of loading it from disk file load the private key from a byte array
//SshPrivateKey privateKey = new SshPrivateKey("key_rsa.pem", "password");

byte[] privateKeyData = YourMethodForObtainingPrivateKey();    
SshPrivateKey privateKey = new SshPrivateKey(privateKeyData, "password");

// authenticate 
client.Login(username, privateKey);

// ... 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文