简体   繁体   English

如何在C / C ++跨平台上以编程方式创建ssh隧道?

[英]How to programmatically create ssh tunnel in C/C++ cross-platform?

I need to connect via TCP to a port that's behind a firewall, accessible through an SSH tunnel. 我需要通过TCP连接到防火墙后面的端口,可以通过SSH隧道访问。 I can achieve connection by opening a tunnel and hittting that port, but I want to build this tunneling in to my application. 我可以通过打开隧道并点击该端口来实现连接,但我想在我的应用程序中构建这个隧道。

Additionally, I want to be able to provide automatic login by use of having authorized keys on the server 此外,我希望能够通过在服务器上使用授权密钥来提供自动登录

This must work on the following platforms (in order of importance) 这必须适用于以下平台(按重要性顺序)

  • iOS (trickiest because I can't fork an ssh tunnel like I can on other platforms) iOS(最棘手的是因为我无法像其他平台那样分叉ssh隧道)
  • OS X OS X.
  • Linux Linux的
  • Windows 视窗

What's the easy way to do this? 这样做的简单方法是什么? I don't want to spend a great deal of effort obviously since this isn't the meat of my application. 我不想花费很多精力,因为这不是我应用程序的核心。 But I'll reuse it so I may care enough to "do things right" 但我会重复使用它,所以我可能会关心“做正确的事情”

But libssh2 is BSD-licensed and appears to have the functionality needed 但libssh2是BSD许可的,似乎具有所需的功能

Looks like: libssh2_channel_direct_tcpip_ex will be the call 看起来像: libssh2_channel_direct_tcpip_ex将是通话

Note that the LGPL'd libssh is a problem because on iOS apps you MUST statically link and CANNOT dynamically link to libraries. 请注意 ,LGPL的libssh是一个问题,因为在iOS应用程序上,您必须静态链接,并且不能动态链接到库。 Therefore, using an LGPL'd library means my source becomes open source. 因此,使用LGPL的库意味着我的源代码变为开源。

Libssh is a very good client implementation for SSH protocol. Libssh是SSH协议的一个非常好的客户端实现。 I have written a blog on this. 我写了一篇博客 There is also a sample application demonstrating the same. 还有一个示例应用程序展示了相同的示例。 We use the same technique in MONyog (MySQL monitor). 我们在MONyog (MySQL监视器)中使用相同的技术。

如果你想查看商业LIB,www.chilkatsoft.com/,它是适用于所有语言的genric C ++库,其中支持IOS的SSH隧道。

Does the LGPL differentiate between linking dynamically and statically? LGPL是否区分动态和静态链接? I don't think so. 我不这么认为。

The library code (ie embedding your own SSH implementation) looks most versatile to me. 库代码(即嵌入您自己的SSH实现)看起来对我来说是最通用的。 Except the fact that you might inherit security problems. 除了您可能继承安全问题。

On MacOSX/Linux/Unix, you can simply invoke 'ssh' and assume it exists (or make it as a precondition). 在MacOSX / Linux / Unix上,您可以简单地调用'ssh'并假设它存在(或将其作为前提条件)。 On Windows, you would rely on putty and friends. 在Windows上,你会依赖于腻子和朋友。 I don't think that's a good idea. 我认为这不是一个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM