DEV Community

Cover image for How to solve the Rust+TLS+Windows Nightmare
Michael
Michael

Posted on

How to solve the Rust+TLS+Windows Nightmare

Problem

Developing with rusttls or openssl can be a huge pain when working with packages such as actix or awc. These packages tend to throw SSL errors when making requests or using a proxy to pass to any https url.

Solution

Install Visual Studio

  • Install the Compoment for Windows Development and Linux Embedded Development for C++ tools.

Install Rust

Set the toolchain to stable-x86_64-pc-windows-msvc

  rustup toolchain install stable-x86_64-pc-windows-msvc
  rustup default stable-x86_64-pc-windows-msvc
Enter fullscreen mode Exit fullscreen mode

Install Msys2

In msys2 install:

  pacman -Syu openssl-devel pkg-config mingw-w64-x86_64-toolchain
Enter fullscreen mode Exit fullscreen mode

Setting up vcpkg

  1. Make a new folder: mkdir -p C:\tools
  2. Clone vcpkg: git clone https://github.com/microsoft/vcpkg
  3. Navigate to C:\tools\vcpkg
  4. Run the following install commands:
  ./bootstrap-vcpkg.bat
  ./vcpkg.exe install openssl-windows:x64-windows
  ./vcpkg.exe install openssl:x64-windows-static
  ./vcpkg.exe integrate install
Enter fullscreen mode Exit fullscreen mode

Setting up Openssl Root Cert

  1. Create the directory: mkdir -p C:\Program Files\OpenSSL-Win64\certs
  2. Download the cacert.pem
  3. Place it in the certs directory.

Finally update all our environments:

  1. Add to path:
    • C:\msys64\mingw64\bin
  2. Add the following environment variables:
    • VCPKG_ROOT=C:\tools\vcpkg
    • SSL_CERT_FILE=C:\Program Files\OpenSSL-Win64\certs\cacert.pem
    • RUSTFLAGS=-Ctarget-feature=+crt-static
    • OPENSSL_NO_VENDOR=1

Conclusion

Developing with Rust and Windows can be a relatively painless process but just rusttls or openssl can be a huge pain when working with packages such as actix or awc. There might be an easier way to accomplish this but these are the steps that I have found to be the most reliable and repeatable across multiple systems.

Sources

Thank you to these lovely peeps for getting me down the right path.

Top comments (1)

Collapse
 
bmbenson profile image
Bryan Benson

Thank you! Massive help!