Search code examples
windowsopenssl

How to install OpenSSL from source on Windows 10/11?


I am currently using Windows 11 but I assume it's the same steps for Windows 10.

I've searched everywhere, and there is not a single tutorial that shows how to succesfully install OpenSSL on Windows.

All answers on this website are just workarounds, for example using the Git version. I specifically use OpenSSL from XAMPP, but that's not what I want.

I want to be able to install OpenSSL from source. Also, currently Git and XAMPP install OpenSSL version 1.1.1, and I want OpenSSL 3.

I've tried all methods, and the OpenSSL instructions lack information. They just say some hints and then three dots (...), like (./Configure...).

This is where I'm trying to follow:

https://github.com/openssl/openssl/blob/master/NOTES-WINDOWS.md#native-builds-using-mingw

For this example, I went for the MinGW method (But, if you can help installing it via one of the other methods successfully then it's alright as well and I will also do it):

I installed MSYS32 and Perl on Windows, but then I got stuck at the MinGW part, I already installed MinGW on MSYS32 - I just installed ALL of the packages in the toolchain:

$ pacman -S mingw-w64-ucrt-x86_64-toolchain
:: There are 19 members in group mingw-w64-ucrt-x86_64-toolchain:
:: Repository ucrt64
   1) mingw-w64-ucrt-x86_64-binutils  2) mingw-w64-ucrt-x86_64-crt-git
   3) mingw-w64-ucrt-x86_64-gcc  4) mingw-w64-ucrt-x86_64-gcc-ada
   5) mingw-w64-ucrt-x86_64-gcc-fortran  6) mingw-w64-ucrt-x86_64-gcc-libgfortran
   7) mingw-w64-ucrt-x86_64-gcc-libs  8) mingw-w64-ucrt-x86_64-gcc-objc
   9) mingw-w64-ucrt-x86_64-gdb  10) mingw-w64-ucrt-x86_64-gdb-multiarch
   11) mingw-w64-ucrt-x86_64-headers-git  12) mingw-w64-ucrt-x86_64-libgccjit
   13) mingw-w64-ucrt-x86_64-libmangle-git  14) mingw-w64-ucrt-x86_64-libwinpthread-git
   15) mingw-w64-ucrt-x86_64-make  16) mingw-w64-ucrt-x86_64-pkgconf
   17) mingw-w64-ucrt-x86_64-tools-git  18) mingw-w64-ucrt-x86_64-winpthreads-git
   19) mingw-w64-ucrt-x86_64-winstorecompat-git

But then, gcc command still doesn't work. I believe it has something to do with me not adding it to the PATH of MSYS32, but there is no instructions as to how to do that (also, even after installing the entire toolchain, C:\msys64\mingw64\bin is empty!)

Also, they later say:

Apart from that, follow the Unix / Linux instructions in INSTALL.md.

Awesome, so I go to the INSTALL.md, and all that's there, is just another hint:

$ ./Configure
$ make
$ make test

Why is it so complex to just build and install OpenSSL on Windows? And I want the official from source, and not workarounds like via Git or XAMPP, or unknown 3rd party. (Why don't they provide a .exe anyway?)

Hopefully this post will be able to be used as future reference for anyone that wants to install OpenSSL on Windows with full instructions

Thanks


Solution

  • I finally made it, I installed OpenSSL 3.2.0-dev on Windows 11.

    These are the detailed steps so that anyone in the future can do it:

    I ended up using the first method, with C++, as seen here: https://github.com/openssl/openssl/blob/master/NOTES-WINDOWS.md#quick-start

    Here are the instructions, I tried to make them as detailed as possible, let me know if it needs changes or fixes:

    First steps: Installing the necessary software:

    Step 1: Install Perl - Install the Strawberry version, much easier to install and it installs everything and also adds them automatically to the Windows PATH variables

    Step 2: Install NASM, and add it to the Windows system (or your user's) PATH variables. I ended up adding it only to my user's variables PATH: C:\Users\<username>\AppData\Local\bin\NASM

    Step 3: Install Visual Studio (I have Visual Studio Community 2022), and install the Desktop development with c++. I ended up choosing the following packages(I'm sure not all are necessary, but if you know, please let me know which ones are the ones I need so that I'll update the photo to avoid installing too many packages): enter image description here

    Step 4: Download and install the Build Tools for Visual Studio (I assume in the future this link will change so look for the Build Tools installation link for your Visual Studio version): https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022

    Step 5: After installing the build tools, launch the Visual Studio installer. In the installer, you will now see the Build Tools. Click on "Modify" under the Visual Studio Build Tools:

    enter image description here

    And then install the needed packages for the OpenSSL installation, it's what's going to install nmake:

    enter image description here

    Then, the build and installation steps:

    Step 6: Clone the openssl repository to some folder on your PC (I cloned it in C:/ so I ended up having C:/openssl/), and fix the line endings by running the following commands:

    > git clone git://git.openssl.org/openssl.git
    
    > cd openssl
    > git config core.autocrlf false
    > git config core.eol lf
    > git checkout .
    

    Update: If you want another version, clone the repository without checking out, fix the line-endings and then checkout to the version you want. For example if you want 3.1.0 stable (Note the -n flag for no-checkout):

    > git clone -n git://git.openssl.org/openssl.git
    
    > cd openssl
    > git config core.autocrlf false
    > git config core.eol lf
    > git checkout openssl-3.1.0
    

    Step 7: In Windows Search, search for "Developer Command Prompt for VS 2022" (Or any of your versions), and run it as administrator:

    enter image description here

    Which will open this command window:

    enter image description here

    Step 8: You need to set the right environment for the version of OpenSSL you want to install, otherwise build will fail. In my case, I wanted to install OpenSSL for 64-bit systems, copy-paste the following (including the quotes, and change the path according to your Visual Studio installation path):

    "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"

    which will then set the environment, as seen here:

    enter image description here

    Step 9: From the same Developer Command Prompt, cd into the folder you cloned the openssl source code, in my case it was C:/openssl, and then follow the steps from the OpenSSL guide:

    > perl Configure VC-WIN64A
    > nmake
    > nmake test
    > nmake install
    

    Note that these steps take time, it took me around 20-30 minutes to finish all these 4 commands

    Step 10: That's it! It's installed! You can find the OpenSSL executable (openssl.exe) at C:\openssl\apps. (And add it to Windows system or user's PATH variables if you want)

    In my case when I run openssl version I see OpenSSL 3.2.0-dev (Library: OpenSSL 3.2.0-dev )