Generate Private Keys on YubiKey and Use them on Windows

Up until I wrote this blog post, the tutorials and documentation I have come across regarding the use of Yubikey PIV certificates with Windows all involved having a complete set of private and public keys (generated outside of Yubikey) to be installed on Windows and imported into Yubikey for use. However, Yubikey also provides a more secure option: generating the private key on the Yubikey itself. The advantage of this method is that the private key never leaves the Yubikey, making it impossible for it to be leaked. But in such a case, we don't have a private key to import into Windows, and Windows is unaware of our corresponding digital certificate, so it won't consider our certificate as an available one for signing.

This article will explain how to generate a private key on the Yubikey and associate it with the certificate on Windows, to enable code signing on Windows. Although the purpose of this article is code signing, the association method described in the article also applies to other scenarios that require the use of private keys generated on the Yubikey.


在 YubiKey 上生成私钥并在 Windows 上使用

截止到我写这篇博客,我在网络上所看到的将 Yubikey PIV 证书与 Windows 一起使用的教程和文档都是已经有完整的私钥和公钥(在 Yubikey 外生成),将其安装在 Windows 和导入到 Yubikey 使用。但是,Yubikey 还提供了一种具有更高安全性的选项:在 Yubikey 上生成私钥,这种方法的好处是私钥不会离开 Yubikey,因此不可能被泄露。但是在这样的情况下,我们没有可以用于导入到 Windows 的私钥,Windows 并不知道我们具有相应数字证书的私钥,在签名时不会将我们的证书作为可用的证书。

本文将介绍如何在 Yubikey 上生成私钥,使 Windows 将证书与 Yubikey 上的私钥相关联,以便在 Windows 上进行代码签名。尽管本文的目的是进行代码签名,但是文中的关联方法也适用于其他需要使用在 Yubikey 上生成的私钥的场景。


Run Cloudflare WARP in Docker

Cloudflare WARP is a free VPN service provided by Cloudflare. As most service providers consider its exit IP as a reputable residential broadband IP, many people use it for accessing websites that have strict risk control policies, especially when their server’s IP address is not clean. However, when we use it on our own servers, we may encounter the following issues:

  • The official WARP client, in the default mode with WARP, blocks all inbound connections, which means that websites and services on servers cannot be accessed.
  • Although the official WARP client in Local Proxy mode does not have the problem of blocking inbound connections, the HTTPS/SOCKS5 proxy it provides cannot transmit UDP packets.
  • In order to prevent abuse, Cloudflare blocks third-party clients (such as wgcf) from accessing WARP services in some regions, and it is currently unknown whether this measure will be extended to other regions.

This article will run the official WARP client in Docker to solve the above problem.


在 Docker 中运行 Cloudflare WARP

Cloudflare WARP 是 Cloudflare 提供的免费 VPN 服务,由于多数服务商都将其出口 IP 视作信誉良好的家宽 IP,许多人将其用于 IP 地址较脏的服务器,以便访问风控较严格的网站。然而当我们将它在自己的服务器上使用时,会遇到以下的问题:

  • 官方 WARP 客户端在默认模式 with WARP 下会阻断所有入站连接,这意味着服务器上的网站和服务都无法被访问
  • 官方 WARP 客户端在 Local Proxy 模式下尽管没有阻断入站连接的问题,其提供的 HTTPS/SOCKS5 代理并不能传输 UDP 数据包
  • 为了防止滥用,Cloudflare 在部分地区阻止了第三方客户端 (wgcf 等) 访问 WARP 服务,暂不清楚它是否会扩大该措施的范围

本文将在 Docker 中运行官方 WARP 客户端,以解决上述问题。