高效的 VPN 内核实现-WireGuard
2020-06-23 22:21:39 阿炯

WireGuard是由Jason A. Donenfeld开发的开放源代码VPN程序及协议,基于Linux内核实现,利用Curve25519进行密钥交换,ChaCha20用于加密,Poly1305用于数据认证,BLAKE2用于散列函数运算,支持IPv4和IPv6的第3层。WireGuard旨在获得比IPsec和OpenVPN更好的性能。 采用C语言开发并在GPLv2协议下授权,支持多平台。


WireGuard® is an extremely simple yet fast and modern VPN that utilizes state-of-the-art cryptography. It aims to be faster, simpler, leaner, and more useful than IPsec, while avoiding the massive headache. It intends to be considerably more performant than OpenVPN. WireGuard is designed as a general purpose VPN for running on embedded interfaces and super computers alike, fit for many different circumstances. Initially released for the Linux kernel, it is now cross-platform (Windows, macOS, BSD, iOS, Android) and widely deployable. It is currently under heavy development, but already it might be regarded as the most secure, easiest to use, and simplest VPN solution in the industry.


WireGuard 是一个 VPN 内核实现,代码行数少,优先考虑性能,配置简单,试图在做到配置简单的同时提供高性能。WireGuard 基于 UDP,数据包在一端加密之后封装在 UDP 包内发送到远程端点,然后解密。WireGuard 已被多家大公司使用,并被整合到工具、发行版,移动手机和数据中心,进入内核主线对它而言更是一个重要的里程碑。

Linux 5.6 除了将 WireGuard 合并进来,还添加了对 Multi-Path TCP(多路径 TCP)协议的初始支持。对于版本小于 5.6 的 Linux 内核,需要额外安装合适的内核模块当使用默认的 linux 包时不需要:
wireguard-lts 用于 LTS linux-lts 内核。
wireguard-dkms 用于其他版本小于 5.6 的 DKMS 变体内核。

安装 WireGuard、生成公钥和私钥像使用 SSH 一样,设置防火墙规则并启动服务。它与 OpenVPN 设置指南进行比较:后者有太多要做的了,另一个好处是它有一个仅 4000 行代码的精简代码库。将它与另一个流行的开源VPN(OpenVPN)的 100,000 行代码相比。显然调试 WireGuard 更加容易。不要因其简单而小看它,WireGuard 支持所有最新的加密技术,例如 Noise 协议框架、Curve25519、ChaCha20、Poly1305、BLAKE2、SipHash24、HKDF 和安全受信任结构。

由于 WireGuard 运行在内核空间,因此可以高速提供安全的网络。


特性

简单易用|Simple & Easy-to-use
WireGuard aims to be as easy to configure and deploy as SSH. A VPN connection is made simply by exchanging very simple public keys – exactly like exchanging SSH keys – and all the rest is transparently handled by WireGuard. It is even capable of roaming between IP addresses, just like Mosh. There is no need to manage connections, be concerned about state, manage daemons, or worry about what's under the hood. WireGuard presents an extremely basic yet powerful interface.

多种密码安全|Cryptographically Sound
WireGuard uses state-of-the-art cryptography, like the Noise protocol framework, Curve25519, ChaCha20, Poly1305, BLAKE2, SipHash24, HKDF, and secure trusted constructions. It makes conservative and reasonable choices and has been reviewed by cryptographers.

最小攻击|Minimal Attack Surface
WireGuard has been designed with ease-of-implementation and simplicity in mind. It is meant to be easily implemented in very few lines of code, and easily auditable for security vulnerabilities. Compared to behemoths like *Swan/IPsec or OpenVPN/OpenSSL, in which auditing the gigantic codebases is an overwhelming task even for large teams of security experts, WireGuard is meant to be comprehensively reviewable by single individuals.

高性能|High Performance
A combination of extremely high-speed cryptographic primitives and the fact that WireGuard lives inside the Linux kernel means that secure networking can be very high-speed. It is suitable for both small embedded devices like smartphones and fully loaded backbone routers.

定义明确并考虑周全|Well Defined & Thoroughly Considered
WireGuard is the result of a lengthy and thoroughly considered academic process, resulting in the technical whitepaper, an academic research paper which clearly defines the protocol and the intense considerations that went into each decision.

里程碑

2020年1月,Linus Torvalds 开启了 Linux 5.6 的合并窗口,并合并了 Dave Miller 的 net-next 树,亦即意味着 WireGuard 正式进入 Linux 5.6 内核主线。

WireGuard 已被多家大公司使用,并被整合到工具、发行版,移动手机和数据中心,此前也已经进入了 Linux 5.6 内核主线。2020年6月进入 OpenBSD,又拿下一个阵营,也意味着未来 OpenBSD 将能原生支持 WireGuard VPN。


全新改进的 WireGuard 登陆 FreeBSD

2021年3月中旬消息,在2020年年底,FreeBSD 引入了一个 WireGuard 内核模块。最初的 WireGuard 移植到 FreeBSD 是由防火墙公司 Netgate 赞助的,但代码质量很差,而且没有上游 WireGuard 开发者的参与。而如今,那个 FreeBSD 的 WireGuard 内核代码正准备被一个更好的实现所取代。

WireGuard 的主要开发者 Jason Donenfeld 在一封电子邮件中解释了这一情况:"前段时间,一家知名的防火墙厂商委托一位开发者为 FreeBSD 编写 WireGuard。他们没有费心去查看这个项目,之后所有的代码都被合并到了 FreeBSD 中"。最近,Donenfeld 与 FreeBSD 的上游开发者,以及曾参与 WireGuard 向 OpenBSD 移植的 Matt Dunwoodie 开始合作,就一个改进的实现进行合作,这个实现也将与用户空间的 WireGuard 上游工具兼容。

Donenfeld 继续补充道:"我们三个人从头到尾地对实现进行了彻底的重构,我们每个人都推动提交,并通过代码来确保正确性。结果就是此次全新的 Wireguard-Freebsd 项目。这是一次不可思议的努力。合作的节奏非常快,也非常激动人心。Matt 和 Kyle 是了不起的程序员,而且和他们一起工作也很有趣"。所以 FreeBSD 从现在开始有了全新的 WireGuard 内核实现。新的 WireGuard 的代码可维护性更强了,而且运行状态更好,与其他平台上的 WireGuard 相吻合。

不过,FreeBSD 13.0 已预定于3月底发布,由于时间上的原因,这个新的 WireGuard 模块似乎不会随 FreeBSD 13.0 一同在发布时启用。同样考虑到之前的 WireGuard 模块的问题,它很可能在 FreeBSD 13.0 中被禁用。这个新的 WireGuard 模块可能会在 FreeBSD 13.1 中大放异彩, 但感兴趣的开发者如果愿意的话,应该可以在 13.0 中反向移植它。


WireGuardNT:Windows 内核下的高性能 WireGuard 实现

WireGuard 作者 Jason Donenfeld 于2021年8月上旬宣布了 WireGuardNT 项目,这是面向 Windows 内核的 WireGuard 原生移植。和其他版本一样,WireGuardNT 的小写为 "wireguard-nt",它一开始只是 Linux 版本代码库的端口。经过初步移植工作取得成功后,NT 代码库迅速分化,以更好地适应原生 NTisms 和 NDIS(Windows 网络栈)API。最后的结果是为 NT 内核实现了一个深度集成且高性能的 WireGuard,它利用了 NT 内核和 NDIS 的全部功能。相关项目和源代码见此处

Jason 在公告中介绍了 WireGuard 的背景,WireGuard 在 Windows 下的早期实现是一个用 Go 开发的用户空间实现——wireguard-go,负责将数据包传入和传出 Wintun 接口。当时使用 wireguard-go 需要关联一个虚拟网络设备,Jason 不满意 OpenVPN 项目提供的虚拟网络接口 tap-windows,因此从头实现了自己的 Wintun。Wintun 相对于 tap-windows 而言是一大改进,OpenVPN 项目之后自己也实现了对 Wintun 的支持。但 wireguard-go 仍然需要持续地在内核空间和用户空间之间进行上下文切换。为了移除这一性能瓶颈,虚拟网卡和加密等整个堆栈都需要移到内核。

WireGuardNT 的出现显着减少了延迟并消除了 wireguard-go/Wintun 的上下文切换问题。测量显示,内核模式实现 WireGuardNT 比用户空间实现 wireguard-go 要快 10-25%。Jason 还称,当使用 WireGuardNT 时,wireguard-go/Wintun 对 WiFi 性能的影响已经消失,功耗和电池使用量也更低。


简易企业级VPN替代方案-NetBird

NetBird 是一个简单快速的企业级 VPN 替代方案,建立在原生 WireGuard® 之上,可以轻松为您的组织或家庭创建安全的私人网络。它几乎不需要任何配置工作,从而摆脱了开放端口、复杂的防火墙规则、VPN 网关等烦琐任务的困扰。

简要来说 NetBird 是一个配置简易的,基于 WireGuard 的 VPN。它与 Tailscale 很像,但是区别也比较明显。Tailscale 是在用户态实现了 WireGuard 协议,无法使用 WireGuard 原生的命令行工具来进行管理。而NetBird 直接使用了内核态的 WireGuard,可以使用命令行工具 wg 来查看和管理。

如果你是 WireGuard 原生党,强烈建议使用 NetBird。



最新版本:1.0


官方主页:https://www.wireguard.com