无法在Windows 11中编译ssl_verify_fun。

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

Cannot compile ssl_verify_fun in Windows 11

问题

背景

我在Windows 11上有一个Phoenix应用程序。不幸的是,由于Windows上的依赖错误,我无法编译该应用程序。

我尝试的方法

首先,我尝试从官方网站(https://www.erlang.org/downloads)下载Erlang和Elixir 1.15.4 for OTP 26(https://elixir-lang.org/install.html#windows)。

不幸的是,当我运行 mix phx.server 时,出现了错误。

$ mix deps.compile ssl_verify_fun
==> ssl_verify_fun
Compiling 7 files (.erl)
src/ssl_verify_hostname.erl:16: can't find include lib "public_key/include/public_key.hrl"

因此,我进入了这个Elixir主题,在Ubuntu上发生了相同的问题:

https://elixirforum.com/t/ubuntu-20-04-compile-ssl-verify-fun-fails/32802

找到的解决方法是让用户在Ubuntu上安装一个特殊的Erlang包,erlang-dev。但是,由于我使用的是Windows,我不太可能选择这个选项。

所以我删除了Erlang和Elixir,然后使用scoop安装它们,希望那里提供的旧版本Elixir和Erlang可以免除这个问题。

使用scoop,我现在正在使用:

elixir 1.15.4   main   2023-07-27 10:27:04
erlang 25.3.2.4 main   2023-07-27 10:10:31

错误

然而,这仍然没有解决问题,因为我遇到了一连串的错误。

==> ssl_verify_fun
Compiling 7 files (.erl)
src/ssl_verify_fingerprint.erl:15:14: can't find include lib "public_key/include/public_key.hrl"
...

在这一点上,考虑到我的设置在Windows上,我不知道还有什么其他方法可以尝试。

问题

我该如何解决这个问题?

英文:

Background

I have a phoenix application in Windows 11. Unfortunately for me, I cannot compile the application because of a dependency error in Windows.

What I tried

First I tried the downloading Erlang from the official website (https://www.erlang.org/downloads), and Elixir
1.15.4 for OTP 26 (https://elixir-lang.org/install.html#windows)

Unfortunately for me, I was greeted with an error when running mix phx.server.

$ mix deps.compile ssl_verify_fun
==> ssl_verify_fun
Compiling 7 files (.erl)
src/ssl_verify_hostname.erl:16: can't find include lib "public_key/include/public_key.hrl"

So, this lead me into this Elixir thread where the same issue happens for Ubuntu:

https://elixirforum.com/t/ubuntu-20-04-compile-ssl-verify-fun-fails/32802

The solution found was for the user to install a special erlang package for Ubuntu, erlang-dev. However, since I am on Windows, I don't really have that option.

So I removed both Erlang and Elixir and installed them using scoop, hoping the older versions of both Elixir and Erlang available there would be free of this issue.

With scoop I am now using:

elixir 1.15.4   main   2023-07-27 10:27:04
erlang 25.3.2.4 main   2023-07-27 10:10:31

Error

However, this still does not fix the issue, as I am greeted with a barrage of errors:

==> ssl_verify_fun
Compiling 7 files (.erl)
src/ssl_verify_fingerprint.erl:15:14: can't find include lib "public_key/include/public_key.hrl"
%   15| -include_lib("public_key/include/public_key.hrl").
%     |              ^
src/ssl_verify_pk.erl:14:14: can't find include lib "public_key/include/public_key.hrl"
%   14| -include_lib("public_key/include/public_key.hrl").
%     |              ^
src/ssl_verify_fun_cert_helpers.erl:13:14: can't find include lib "public_key/include/public_key.hrl"
%   13| -include_lib("public_key/include/public_key.hrl").
%     |              ^
src/ssl_verify_fingerprint.erl:27:26: record 'OTPCertificate' undefined
%   27| -spec verify_fun(Cert :: #'OTPCertificate'{},
%     |                          ^
src/ssl_verify_pk.erl:26:26: record 'OTPCertificate' undefined
%   26| -spec verify_fun(Cert :: #'OTPCertificate'{},
%     |                          ^
src/ssl_verify_fun_cert_helpers.erl:23:34: undefined macro 'id-ce-subjectAltName'
%   23|   AltSubject = select_extension(?'id-ce-subjectAltName', Extensions),
%     |                                  ^
src/ssl_verify_fingerprint.erl:29:39: record 'Extension' undefined
%   29|                           {extension, #'Extension'{}}, InitialUserState :: term()) ->
%     |                                       ^
src/ssl_verify_pk.erl:28:39: record 'Extension' undefined
%   28|                           {extension, #'Extension'{}}, InitialUserState :: term()) ->
%     |                                       ^
src/ssl_verify_hostname.erl:16:14: can't find include lib "public_key/include/public_key.hrl"
%   16| -include_lib("public_key/include/public_key.hrl").
%     |              ^
src/ssl_verify_fun_cert_helpers.erl:9:2: function extract_dns_names/1 undefined
%    9| -export([extract_dns_names/1,
%     |  ^
src/ssl_verify_fingerprint.erl:52:39: record 'OTPCertificate' undefined
%   52| -spec verify_cert_fingerprint(Cert :: #'OTPCertificate'{}, Fingerprint :: fingerprint()) ->
%     |                                       ^
src/ssl_verify_pk.erl:51:30: record 'OTPCertificate' undefined
%   51| -spec verify_cert_pk(Cert :: #'OTPCertificate'{}, Pk :: pk()) ->
%     |                              ^
src/ssl_verify_hostname.erl:28:26: record 'OTPCertificate' undefined
%   28| -spec verify_fun(Cert :: #'OTPCertificate'{},
%     |                          ^
src/ssl_verify_fun_cert_helpers.erl:19:2: spec for undefined function extract_dns_names/1
%   19| -spec extract_dns_names(Cert :: #'OTPCertificate'{}) -> [] | [string()].
%     |  ^
src/ssl_verify_hostname.erl:30:39: record 'Extension' undefined
%   30|                           {extension, #'Extension'{}}, InitialUserState :: term()) ->
%     |                                       ^
src/ssl_verify_fun_cert_helpers.erl:19:33: record 'OTPCertificate' undefined
%   19| -spec extract_dns_names(Cert :: #'OTPCertificate'{}) -> [] | [string()].
%     |                                 ^
src/ssl_verify_hostname.erl:46:36: record 'OTPCertificate' undefined
%   46| -spec verify_cert_hostname(Cert :: #'OTPCertificate'{}, Hostname :: hostname()) ->
%     |                                    ^
src/ssl_verify_fun_cert_helpers.erl:32:26: record 'OTPCertificate' undefined
%   32| -spec extract_cn(Cert :: #'OTPCertificate'{}) -> {error, no_common_name} | {ok, string()} | {error, invalid}.
%     |                          ^
src/ssl_verify_hostname.erl:76:38: record 'OTPCertificate' undefined
%   76|                              Cert :: #'OTPCertificate'{},
%     |                                      ^
src/ssl_verify_fun_cert_helpers.erl:34:17: record 'OTPCertificate' undefined
%   34|   TBSCert = Cert#'OTPCertificate'.tbsCertificate,
%     |                 ^
src/ssl_verify_fun_cert_helpers.erl:35:32: record 'OTPTBSCertificate' undefined
%   35|   {rdnSequence, List} = TBSCert#'OTPTBSCertificate'.subject,
%     |                                ^
src/ssl_verify_fun_cert_helpers.erl:38:26: record 'OTPCertificate' undefined
%   38| -spec extract_pk(Cert :: #'OTPCertificate'{}) -> {error, no_common_name} | #'SubjectPublicKeyInfo'{}.
%     |                          ^
src/ssl_verify_fun_cert_helpers.erl:38:76: record 'SubjectPublicKeyInfo' undefined
%   38| -spec extract_pk(Cert :: #'OTPCertificate'{}) -> {error, no_common_name} | #'SubjectPublicKeyInfo'{}.
%     |                                                                            ^
src/ssl_verify_fun_cert_helpers.erl:40:17: record 'OTPCertificate' undefined
%   40|   TBSCert = Cert#'OTPCertificate'.tbsCertificate,
%     |                 ^
src/ssl_verify_fun_cert_helpers.erl:41:26: record 'OTPTBSCertificate' undefined
%   41|   PublicKeyInfo = TBSCert#'OTPTBSCertificate'.subjectPublicKeyInfo,
%     |                          ^
src/ssl_verify_fun_cert_helpers.erl:42:16: record 'OTPSubjectPublicKeyInfo' undefined
%   42|   PublicKeyInfo#'OTPSubjectPublicKeyInfo'.subjectPublicKey.
%     |                ^
src/ssl_verify_fun_cert_helpers.erl:48:24: record 'Extension' undefined
%   48| -spec extensions_list([#'Extension'{}] | asn1_NOVALUE) -> [] | [#'Extension'{}].
ean it with "mix deps.clean ssl_verify_fun"n, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile ssl_verify_fun --force", update it with "mix deps.update ssl_verify_fun" or cl%     |                        ^
src/ssl_verify_fun_cert_helpers.erl:48:65: record 'Extension' undefined
%   48| -spec extensions_list([#'Extension'{}] | asn1_NOVALUE) -> [] | [#'Extension'{}].
%     |                                                                 ^
src/ssl_verify_fun_cert_helpers.erl:55:39: record 'Extension' undefined
%   55| -spec select_extension(Id :: term(), [#'Extension'{}]) -> undefined | #'Extension'{}.
%     |                                       ^
src/ssl_verify_fun_cert_helpers.erl:55:71: record 'Extension' undefined
%   55| -spec select_extension(Id :: term(), [#'Extension'{}]) -> undefined | #'Extension'{}.
%     |                                                                       ^
src/ssl_verify_fun_cert_helpers.erl:57:28: record 'Extension' undefined
%   57|   Matching = [Extension || #'Extension'{extnID = ExtId} = Extension <- Extensions, ExtId =:= Id],
%     |                            ^
src/ssl_verify_fun_cert_helpers.erl:57:84: variable 'ExtId' is unbound
%   57|   Matching = [Extension || #'Extension'{extnID = ExtId} = Extension <- Extensions, ExtId =:= Id],
%     |                                                                                    ^
src/ssl_verify_fun_cert_helpers.erl:75:15: record 'AttributeTypeAndValue' undefined
%   75| extract_cn2([[#'AttributeTypeAndValue'{type={2, 5, 4, 3},
%     |               ^
src/ssl_verify_fun_cert_helpers.erl:77:39: variable 'CN' is unbound
%   77|   ssl_verify_fun_encodings:get_string(CN);
%     |                                       ^
src/ssl_verify_fun_cert_helpers.erl:49:1: Warning: function extensions_list/1 is unused
%   49| extensions_list(E) ->
%     | ^
src/ssl_verify_fun_cert_helpers.erl:56:1: Warning: function select_extension/2 is unused
%   56| select_extension(Id, Extensions) ->
%     | ^
src/ssl_verify_fun_cert_helpers.erl:64:1: Warning: function extract_dns_names_from_alt_names/2 is unused
%   64| extract_dns_names_from_alt_names([ExtValue | Rest], Acc) ->
%     | ^

At this point, given my setup is on Windows, I don't know what else to try.

Question

How can I fix this issue?

答案1

得分: 1

在进一步调查后,我发现了这个问题:

https://github.com/elixir-lang/elixir/issues/12653

这代表了我的问题。基本上,Elixir没有检查缺失文件的正确路径:

https://github.com/elixir-lang/elixir/issues/12681

现在,有一种可能的解决方法。通过强制你的应用程序使用相关依赖项(ssl_verify_fun)的更新版本,你可以将以下内容添加到你的 mix.exs 文件中:

{:ssl_verify_fun, "~> 1.1.7", manager: :rebar3, override: true}

但是,我不太喜欢这种方法。如果明天发生相同的事情,你就必须再次覆盖它。而且当覆盖开始相互冲突时,你真的会遇到问题。

在我的情况下,我通过查看 mix.lock 找到了使用旧版本 ssl_verify_fun 的应用程序。它是 hackney

然而,我没有去处理每个依赖项并尝试修复它,而是采取了更彻底的方法。我删除了我的 mix.lock 然后运行了 mix deps.update --all

这迫使一些旧的依赖项更新。之后,简单的 mix deps.get 解决了问题,mix phx.server 也可以正常工作。

你可以在Elixir论坛的这个帖子中找到更多信息:

https://elixirforum.com/t/cannot-compile-ssl-verify-fun-in-windows-11/57265/4

英文:

Answer

After some more digging I found out this issue:

https://github.com/elixir-lang/elixir/issues/12653

Which represents my problem. Basically Elixir does not check the correct paths for the missing file:

https://github.com/elixir-lang/elixir/issues/12681

Now, there is a possible workaround for this issue. By forcing your application to use a more updated version of the dependency in question (ssl_verify_fun), you can add this to your mix.exs file:

> {:ssl_verify_fun, "~> 1.1.7", manager: :rebar3, override: true}

However, I don’t really like this. If tomorrow the same thing happens, you have to overwrite again. And when overwrites start conflicting with each other, then you really have a problem.

In my case, I found which application was using the old version of ssl_verify_fun by looking at mix.lock. It was hackney.

However, instead of going through every dependency and trying to fix it, I took the more nuclear approach. I deleted my mix.lock and then run mix deps.update --all.

This forced some older dependencies to update. After that a simple mix deps.get fixed the issue and mix phx.server worked.

You can find more information in the Elixir Forum thread:

https://elixirforum.com/t/cannot-compile-ssl-verify-fun-in-windows-11/57265/4

答案2

得分: 0

抱歉,我只会返回翻译好的部分,不会回答问题。

"I wish people who are trying to compile C code would learn a bit more about the mechanics of compiling C code. Because off the top of my head I'd say that your LIB path doesn't include that public_key/include directory. But how you set the LIB path is a bit tricky all by itself because it sort of depends on which compiler/linker you're using.

Also, in your case, I cannot tell if you're trying under WSL or not. However, that said, take a look at this link: How To Build Erlang/OTP on Windows. I know you were asking about ssl_verify_fun but the idea is the same; you need to get the C code compiling and linking correctly and the stuff at the link covers that. Mainly what you want to make sure is that you've got your INCLUDE and LIB paths set correctly.

Frankly it's a fairly complex trick (given WSL and the need for the MS C++ compiler and all) so it's really pretty tough to give a specific answer to your question. Maybe try following the linked guide and see if you can't narrow down the issue.

英文:

I wish people who are trying to compile C code would learn a bit more about the mechanics of compiling C code. Because off the top of my head I'd say that your LIB path doesn't include that public_key/include directory. But how you set the LIB path is a bit tricky all by itself because it sort of depends on which compiler/linker you're using.

Also, in your case, I cannot tell if you're trying under WSL or not. However, that said, take a look at this link: How To Build Erlang/OTP on Windows. I know you were asking about ssl_verify_fun but the idea is the same; you need to get the C code compiling and linking correctly and the stuff at the link covers that. Mainly what you want to make sure is that you've got your INCLUDE and LIB paths set correctly.

Frankly it's a fairly complex trick (given WSL and the need for the MS C++ compiler and all) so it's really pretty tough to give a specific answer to your question. Maybe try following the linked guide and see if you can't narrow down the issue.

huangapple
  • 本文由 发表于 2023年7月27日 18:58:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76779059.html
匿名

发表评论

匿名网友

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

确定