如何在Windows 10/11上从源代码安装OpenSSL?

huangapple go评论56阅读模式
英文:

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

问题

我目前正在使用Windows 11,但我认为在Windows 10上的步骤应该是相同的。

我已经到处搜索过,没有一个教程能够成功地展示在Windows上安装OpenSSL的方法。

这个网站上的所有答案都只是一些权宜之计,例如使用Git版本。我特别使用XAMPP中的OpenSSL,但那不是我想要的。

我想要能够从源代码中安装OpenSSL。此外,当前Git和XAMPP安装的是OpenSSL版本1.1.1,而我想要的是OpenSSL 3。

我已经尝试了所有的方法,但OpenSSL的说明缺乏信息。它们只是给出一些提示,然后是三个点(...),像这样(./Configure...)。

这是我正在尝试的地方:

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

以这个示例为例,我选择了MinGW方法(但如果您可以成功地通过其他方法安装它,那也可以,我也会这样做):

我在Windows上安装了MSYS32和Perl,但然后在MinGW部分卡住了,我已经在MSYS32上安装了MinGW - 我只安装了工具链中的所有包:

$ 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

但是,gcc命令仍然不起作用。我认为这与我没有将其添加到MSYS32的PATH有关,但是没有关于如何执行此操作的说明(而且即使在安装整个工具链之后,C:\msys64\mingw64\bin为空!)

此外,他们后来说:

除此之外,请遵循INSTALL.md中的Unix / Linux说明。

太棒了,所以我去查看INSTALL.md,但那里只有另一个提示:

$ ./Configure
$ make
$ make test

为什么在Windows上构建和安装OpenSSL如此复杂呢?我想要的是来自官方源代码的版本,而不是通过Git或XAMPP等变通方法,或者不知名的第三方方法。(他们为什么不提供.exe文件呢?)

希望这篇帖子将来能够作为任何想要在Windows上安装OpenSSL并附带完整说明的人的参考。

谢谢。

英文:

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

答案1

得分: 5

打开“命令提示符”作为“管理员”,然后输入“winget install openssl”,然后按“enter”。

英文:

Open Command Prompt as Administrator then typo winget install openssl then enter.

答案2

得分: 1

我终于成功了,在Windows 11上安装了OpenSSL 3.2.0-dev

以下是详细步骤,以便将来的任何人都可以完成:

最终,我使用了第一种方法,使用C++,可以在这里看到:https://github.com/openssl/openssl/blob/master/NOTES-WINDOWS.md#quick-start

以下是说明,我尽量做得尽可能详细,请告诉我是否需要更改或修复:

第一步:安装必要的软件

步骤1: 安装Perl - 安装Strawberry版本,更容易安装,它会安装所有必要的组件并自动添加到Windows的PATH变量中。

步骤2: 安装NASM,并将其添加到Windows系统(或您的用户)的PATH变量中。我最终只将它添加到了我的用户变量的PATH中:C:\Users\<username>\AppData\Local\bin\NASM

步骤3: 安装Visual Studio(我使用的是Visual Studio Community 2022),并安装Desktop development with c++。我最终选择了以下软件包(我确定不是所有都是必需的,但如果您知道,请告诉我需要哪些软件包,以便我更新图片,避免安装太多软件包):

如何在Windows 10/11上从源代码安装OpenSSL?

步骤4: 下载并安装Visual Studio的Build Tools(我假设在将来,此链接将会更改,因此请搜索适用于您的Visual Studio版本的Build Tools安装链接):https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022

步骤5: 安装构建工具后,启动Visual Studio安装程序。在安装程序中,您现在将看到Build Tools。单击Visual Studio Build Tools下的“Modify”:

如何在Windows 10/11上从源代码安装OpenSSL?

然后安装OpenSSL安装所需的软件包,这将安装nmake

如何在Windows 10/11上从源代码安装OpenSSL?

然后,构建和安装步骤:

步骤6: 克隆openssl存储库到您PC上的某个文件夹中(我将其克隆到了C:/,所以最终我有了C:/openssl/),然后通过运行以下命令修复行结束符:

> git clone git://git.openssl.org/openssl.git

> cd openssl
> git config core.autocrlf false
> git config core.eol lf
> git checkout .

更新: 如果您想要另一个版本,请在不检出的情况下克隆存储库,修复行结束符,然后检出您想要的版本。例如,如果您想要3.1.0稳定版(请注意-n标志表示不检出):

> 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

步骤7: 在Windows搜索中,搜索“VS 2022的Developer Command Prompt”(或您的版本),以管理员身份运行它:

如何在Windows 10/11上从源代码安装OpenSSL?

这将打开这个命令窗口:

如何在Windows 10/11上从源代码安装OpenSSL?

步骤8: 您需要为要安装的OpenSSL版本设置正确的环境,否则构建将失败。在我的情况下,我想要为64位系统安装OpenSSL,复制粘贴以下内容(包括引号,并根据您的Visual Studio安装路径更改路径):

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

然后会设置环境,如下所示:

如何在Windows 10/11上从源代码安装OpenSSL?

步骤9: 从同一个Developer Command Prompt中,进入您克隆了openssl源代码的文件夹,对我来说是C:/openssl,然后按照OpenSSL指南的步骤操作:

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

请注意,这些步骤需要时间,我大约花了20-30分钟完成这4个命令

步骤10: 就是这样!已安装完成!您可以在C:\openssl\apps中找到OpenSSL可执行文件(openssl.exe)。(如果需要,将其添加到Windows系统或用户的PATH变量中)

在我的情况下,当我运行openssl version时,我看到的是OpenSSL 3.2.0-dev (Library: OpenSSL 3.2.0-dev )

英文:

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\&lt;username&gt;\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):
如何在Windows 10/11上从源代码安装OpenSSL?

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:

如何在Windows 10/11上从源代码安装OpenSSL?

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

如何在Windows 10/11上从源代码安装OpenSSL?

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:

&gt; git clone git://git.openssl.org/openssl.git

&gt; cd openssl
&gt; git config core.autocrlf false
&gt; git config core.eol lf
&gt; 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):

&gt; git clone -n git://git.openssl.org/openssl.git

&gt; cd openssl
&gt; git config core.autocrlf false
&gt; git config core.eol lf
&gt; 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:

如何在Windows 10/11上从源代码安装OpenSSL?

Which will open this command window:

如何在Windows 10/11上从源代码安装OpenSSL?

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):

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

which will then set the environment, as seen here:

如何在Windows 10/11上从源代码安装OpenSSL?

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:

&gt; perl Configure VC-WIN64A
&gt; nmake
&gt; nmake test
&gt; 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 )

huangapple
  • 本文由 发表于 2023年5月25日 19:01:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76331564.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定