【问题标题】:Upgrade openssl on Linode server but how to decide 'ENGINESDIR'在 Linode 服务器上升级 openssl 但如何决定“ENGINESDIR”
【发布时间】:2023-03-23 15:17:01
【问题描述】:

在 Linode 服务器上,它已经安装了 openssl,但版本是1.1.0。但是我想尝试一些像TLSv1_3这样的功能,所以我决定将它升级到最新版本。

我的旧 openssl 版本是这样的:

OpenSSL 1.1.0g  2 Nov 2017
built on: reproducible build, date unspecified
platform: debian-amd64
compiler: gcc -DDSO_DLFCN -DHAVE_DLFCN_H -DNDEBUG -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DRC4_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DPADLOCK_ASM -DPOLY1305_ASM -DOPENSSLDIR="\"/usr/lib/ssl\"" -DENGINESDIR="\"/usr/lib/x86_64-linux-gnu/engines-1.1\"" 
OPENSSLDIR: "/usr/lib/ssl"
ENGINESDIR: "/usr/lib/x86_64-linux-gnu/engines-1.1"

由于是“升级”,所以我尽量保留原汁原味。通过一些网站我做了这个./config 命令。

./config --prefix=/usr --openssldir=/usr/lib/ssl threads shared zlib-dynamic no-ssl no-tls1 no-tls1_1 -DDSO_DLFCN -DHAVE_DLFCN_H -DNDEBUG -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DRC4_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DPADLOCK_ASM -DPOLY1305_ASM -DENGINESDIR=/usr/lib/x86_64-linux-gnu/engines-1.1

很长,但重要的是最后一句话:-DENGINESDIR=/usr/lib/x86_64-linux-gnu/engines-1.1

当我使用make 命令时,问题发生了。以下是错误消息:

<command-line>:0:0: warning: "ENGINESDIR" redefined
<command-line>:0:0: note: this is the location of the previous definition
crypto/cversion.c: In function 'OpenSSL_version':
<command-line>:0:13: error: 'usr' undeclared (first use in this function)
crypto/cversion.c:38:33: note: in expansion of macro 'ENGINESDIR'
     return "ENGINESDIR: \"" ENGINESDIR "\"";
                             ^~~~~~~~~~
<command-line>:0:13: note: each undeclared identifier is reported only once for each function it appears in
crypto/cversion.c:38:33: note: in expansion of macro 'ENGINESDIR'
     return "ENGINESDIR: \"" ENGINESDIR "\"";
                             ^~~~~~~~~~
<command-line>:0:17: error: 'lib' undeclared (first use in this function); did you mean 'ldiv'?
crypto/cversion.c:38:33: note: in expansion of macro 'ENGINESDIR'
     return "ENGINESDIR: \"" ENGINESDIR "\"";
                             ^~~~~~~~~~
<command-line>:0:21: error: 'x86_64' undeclared (first use in this function); did you mean '__x86_64'?
crypto/cversion.c:38:33: note: in expansion of macro 'ENGINESDIR'
     return "ENGINESDIR: \"" ENGINESDIR "\"";
                             ^~~~~~~~~~
<command-line>:0:34: error: 'gnu' undeclared (first use in this function)
crypto/cversion.c:38:33: note: in expansion of macro 'ENGINESDIR'
     return "ENGINESDIR: \"" ENGINESDIR "\"";
                             ^~~~~~~~~~
<command-line>:0:38: error: 'engines' undeclared (first use in this function); did you mean 'engine_st'?
crypto/cversion.c:38:33: note: in expansion of macro 'ENGINESDIR'
     return "ENGINESDIR: \"" ENGINESDIR "\"";
                             ^~~~~~~~~~
crypto/cversion.c:38:44: error: expected ';' before string constant
     return "ENGINESDIR: \"" ENGINESDIR "\"";
                                        ^~~~

似乎将我的目录分成不同的部分...

就是这样,我的问题是我应该手动设置ENGINESDIR 吗?如果我丢弃-DENGINESDIR 参数ENGINES 也可以指向/usr/lib/x86_64-linux-gnu/engines-1.1?还是有更好的选择?我对openssl不熟悉,我只能从很多谷歌上写这样的命令。????

PS1:我的新openssl版本是1.1.1-pre9

【问题讨论】:

    标签: linux openssl


    【解决方案1】:

    openssl version -a 的输出在以copmpiler: 开头的行中提及

    -DENGINESDIR="\"/usr/lib/x86_64-linux-gnu/engines-1.1\""
    

    这和你的一样,但是用双引号括起来,内部的转义了。

    为了在您的config 脚本中实现这一点,您必须转义双引号和反斜杠,因为一旦您调用脚本,它们就会被展开。这应该在调用 config 时起到作用:

    -DENGINESDIR=\"\\\"/usr/lib/x86_64-linux-gnu/engines-1.1\\\"\"
    

    更新

    在 OP 在他自己的回答中发表评论后,我花了更多时间通过自己尝试不同的事情来研究这个问题。上面提出的方法确实消除了编译错误并允许构建完成。但是,这不是正确的解决方案。

    为了深入了解这一点,我使用以下命令设置Makefile

    $ ./config --prefix=/tmp/openssl -DENGINESDIR=\"\\\"/tmp/openssl-engines\\\"\"
    

    之后执行make install 时的结果输出包含许多这样的行:

    gcc  -I. -Icrypto/include -Iinclude -DDSO_DLFCN -DHAVE_DLFCN_H -DNDEBUG
        -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC
        -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5
        -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DRC4_ASM
        -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DGHASH_ASM
        -DECP_NISTZ256_ASM -DPADLOCK_ASM -DPOLY1305_ASM
        -DENGINESDIR="\"/tmp/openssl-engines\"" -DOPENSSLDIR="\"/tmp/openssl/ssl\""
        -DENGINESDIR="\"/tmp/openssl/lib/engines-1.1\"" -Wall -O3 -pthread -m64
        -DL_ENDIAN  -Wa,--noexecstack -fPIC -DOPENSSL_USE_NODELETE
        -MMD -MF crypto/bn/bn_div.d.tmp -MT crypto/bn/bn_div.o -c
        -o crypto/bn/bn_div.o crypto/bn/bn_div.c
    <command-line>:0:0: warning: "ENGINESDIR" redefined
    <command-line>:0:0: note: this is the location of the previous definiti
    

    请注意,-DENGINESDIR 出现了两次,因此发出了警告。最后一个会覆盖第一个,因此不会产生预期的结果。

    进一步的调查显示,就像他的回答中指出的 OP 一样,Makefile 有一个“硬编码”行ENGINESDIR=$(libdir)/engines-1.1,它不能被覆盖,并且阻止了这方面的定制。因此,将-DENGINES 值与Configure 一起使用是没有用的。

    无需过多介绍:要使ENGINESDIR 值可配置,必须修改文件Configurations/unix-Makefile.tmpl 以包含以下行,类似于openssldir 设置的行:

    ENGINESDIR={- use File::Spec::Functions;
                  our $enginesdir =
                      $config{enginesdir} ?
                          (file_name_is_absolute($config{enginesdir}) ?
                               $config{enginesdir}
                               : catdir($prefix, $config{enginesdir}))
                          : catdir($prefix, "engines");
                  $enginesdir -}
    

    并且需要在Configure 文件中添加几行来引入实际的--enginesdir 参数。

    执行此操作后,以下命令序列确实按预期工作:

    $ ./config --prefix=/tmp/openssl --enginesdir=/tmp/openssl-engines
    $ make && make install && make install_engines
    

    这远远超出了 OP 的要求,我在名为 OpenSSL 的黑洞中投入了几个小时,但无论如何它是有教育意义的。

    【讨论】:

    • 添加引号后,您发布的编译器错误没有消失吗? (顺便说一句,似乎推荐的方法是用另一对额外的双引号将该表达式括起来,尽管我认为这不会产生影响。我用它更新了答案。)
    • 我错过了按Enter 按钮然后发送我不完整的消息,我无法立即编辑我的 cmets,该死的 Stackoverflow...这是完整的一个:
    • 感谢您的建议,但它也无法通过。我试图用转义的双引号替换命令的结尾部分,并且该错误再次显示并且看起来相同。我找到了一个名为Makefile 的文件,该文件中有一个CONFIGURE_ARGS 属性。在此属性的最后一个短语中,有很多设置,例如:CONFIGURE_ARGS=("...lots of my other -D conf", "-DENGINESDIR=/usr/lib/x86_64-linux-gnu/engines-1.1")。实际上,当我不使用转义双引号时也是如此。所以也许这让问题再次出现。
    • 双引号相同,心碎的结果。 ?
    • 我再次更新,我没有意识到额外的config 步骤是问题的一部分。你也可以试试新的表达方式吗?
    【解决方案2】:

    通过在提到的文件中搜索了一些时间,我终于找到了答案。 当你急于解决一个问题但完全没有任何感觉,但如果你不经意地过了几天,然后随机回来思考和搜索,你会发现答案是多么接近......生活很奇怪。 关键文件是Makefile,在你喜欢.../openssl-OpenSSL_1_1_1-pre9/的目录下,你尝试使用make命令,有几段突然跳进我的眼里,立刻吸引了我:

    # Do not edit these manually. Use Configure with --prefix or --openssldir
    # to change this!  Short explanation in the top comment in Configure
    INSTALLTOP=/usr
    OPENSSLDIR=/usr/lib/ssl
    LIBDIR=lib
    # $(libdir) is chosen to be compatible with the GNU coding standards
    libdir=$(INSTALLTOP)/$(LIBDIR)
    ENGINESDIR=$(libdir)/engines-1.1
    

    ENGINESDIR的compose风格,和我的命令关联起来,很快我就明白了这些目录之间的关系关键。

    所以我修改了我的命令,删除了原来的 -DENGINESDIR 并添加了一些 make 命令看起来像:

    ./config --prefix=/usr --openssldir=/usr/lib/ssl --libdir=lib/x86_64-linux-gnu ...

    make 再次,奇迹发生了,通过了,没有任何错误,甚至警告。并且我尝试make test,也通过了,只是跳过了一些东西,但它是正常的。

    虽然我没有尝试make install 来验证ENGINES 是否指向我的旧目录。不过我觉得应该没问题。

    所以关键是不要手动设置ENGINES 目录,因为它由两个名为INSTALLTOPLIBDIR 的目录组成。在 INSTALL.md 文件中(文件位于 openssl github repo 中)只有提到的用户可以使用 --prefix 来更改前缀,但在这些文件中我发现还有其他未提到但样式相同的参数可以更改 LIBDIR 其中ENGINESDIR 依靠它。也许它很少使用,所以降价文件没有提到所有可能的参数。

    非常感谢Reinier Torenbeek,没有他我不会再重新考虑这个答案。也许这不是一个难题,但在我遇到答案之前,我实际上无法解决它。我采纳了他的建议作为答案。

    【讨论】:

    • 既然您接受了我的回答(谢谢),我想确保我应得的 :-) 请参阅我的回答中的更新,进一步分析问题(如果您仍然不厌倦现在...)
    猜你喜欢
    • 1970-01-01
    • 2014-10-06
    • 1970-01-01
    • 2012-02-29
    • 2016-07-17
    • 1970-01-01
    • 1970-01-01
    • 2012-05-12
    • 1970-01-01
    相关资源
    最近更新 更多