OpenSSH 7.3p1构建:配置只能找到旧版本的OpenSSL库

5

我正在尝试在安装了旧版本OpenSSL的Linux机器上构建OpenSSH 7.3p1

首先,我已经成功编译并安装了OpenSSL 1.0.2h/opt/openssh-1.0.2h,而不是旧版本OpenSSL所在的/usr目录。

tar xzf openssl-1.0.2h.tar.gz
cd openssl-1.0.2h
./config --prefix=/opt/openssl-1.0.2h shared
make depend
make
make test
make install

然后我继续使用OpenSSH:

tar xzf openssh-7.3p1.tar.gz
cd openssh-7.3p1
./configure --prefix=/opt/openssh-7.3p1 --with-openssl=/opt/openssl-1.0.2h

但是configure脚本失败并显示以下错误信息:

checking OpenSSL header version... 0090802f (OpenSSL 0.9.8e-rhel5 01 Jul 2008)
checking OpenSSL library version... configure: error: OpenSSL >= 0.9.8f required (have "0090802f (OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008)")

如果我使用--with-ssl-dir=/opt/openssl-1.0.2h/ssl,将显示相同的消息。

工具findssl.sh(在子目录contrib中找到)可以正确查找所有OpenSSL版本。它内部的注释建议使用CFLAGS来指定所需的库 - 我引用:

# Now run findssl.sh. This should identify the headers and libraries
# present  and  their  versions.  You  should  be  able  to identify the
# libraries  and headers used and adjust your CFLAGS or remove incorrect
# versions.  The  output will show OpenSSL's internal version identifier
# and should look something like:

接着我尝试了一下

./configure CFLAGS="-I/opt/openssl-1.0.2h/include" --prefix=/opt/openssh-7.3p1  --with-openssl=/opt/openssl-1.0.2h

这似乎是有效的,因为它找到了新的OpenSSL头文件版本:

checking OpenSSL header version... 1000208f (OpenSSL 1.0.2h  3 May 2016)
checking OpenSSL library version... configure: error: OpenSSL >= 0.9.8f required (have "0090802f (OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008)")

下一步是提供其他选项来定位库文件。但是如果我添加 LDFLAGS='-L/opt/openssl-1.0.2h/lib'--with-ldflags='-L/opt/openssl-1.0.2h/lib',我会得到以下结果:
checking OpenSSL header version... not found
configure: error: OpenSSL version header not found.

总之,我不知道如何让“configure”使用新的OpenSSL库。
更新1:如果使用“--with-ldflags='-L/opt/openssl-1.0.2h/ssl'”而不是“···openssl-1.0.2h/lib”,则头文件版本检查可以正常工作(请参见上面几行),但库版本检查仍然失败。
更新2:我追踪了这个问题并发现它与共享库有关。从“config.log”文件中,我得到了源代码文件“conftest.c”和“confdef.h”,以及用于构建可运行“conftest”的选项。
#include "confdefs.h"
#include <stdio.h>
#include <string.h>
#include <openssl/opensslv.h>
#include <openssl/crypto.h>
#define DATA "conftest.ssllibver"

int
main ()
{

  FILE *fd;
  int rc;

  fd = fopen(DATA,"w");
  if (fd == NULL)
     exit(1);

  if ((rc = fprintf(fd, "%08lx (%s)\n", (unsigned long)SSLeay(),
                    SSLeay_version(SSLEAY_VERSION))) < 0)
     exit(1);

  exit(0);
}

该程序将OpenSSL版本以文本形式存储在文件conftest.ssllibver中。出于调试目的,我将fprint(fd,转换为print(以将数据打印到终端上。
用于构建conftest程序的命令行为:
# gcc -o conftest -I/opt/openssl-1.0.2h/include -Wall \
-Wpointer-arith -Wsign-compare -Wformat-security -Wno-pointer-sign \
-fno-strict-aliasing -D_FORTIFY_SOURCE=2 -ftrapv -fno-builtin-memset \
-fstack-protector-all -std=gnu99 -fPIE -Wl,-z,relro -Wl,-z,now \ 
-Wl,-z,noexecstack -fstack-protector-all -pie conftest.c \
-lcrypto -lrt -ldl -lutil -lz

# ldd conftest |grep libcrypto
       libcrypto.so.6 => /lib64/libcrypto.so.6 (0x00002b5fc6c3e000)

使用旧版OpenSSL库。

当将-L/opt/openssl-1.0.2h/lib添加为参数时,conftest无法运行,因为动态加载器 (ld.so) 找不到 libcrypto.so.1.0.0

# ./conftest
./conftest: error while loading shared libraries: libcrypto.so.1.0.0: cannot open shared object file: No such file or directory
# ldd conftest | grep libcrypto
        libcrypto.so.1.0.0 => not found

但是,当我将LD_LIBRARY_PATH环境变量指向/opt/openssl-1.0.2h/lib时,动态加载器会找到库文件libcrypto.so.1.0.0,因此可执行文件conftest正常工作 -- 它使用新的OpenSSL库:

# export LD_LIBRARY_PATH=/opt/openssl-1.0.2h/lib
# ./conftest
1000208f (OpenSSL 1.0.2h  3 May 2016)
# ldd conftest
        libcrypto.so.1.0.0 => /opt/openssl-1.0.2h/lib/libcrypto.so.1.0.0 (0x00002b450bf97000)

另请参考在Super User上的为OS X构建OpenSSH?。其中包含了我使用的步骤。我已经使用了适用于OS X和Linux的通用步骤。 - jww
3个回答

3

导出LD_LIBRARY_PATH环境变量,该变量必须包含新的OpenSSL库文件所在的目录,然后运行configure脚本:

# export LD_LIBRARY_PATH=/opt/openssl-1.0.2h/lib
# ./configure CFLAGS="-I/opt/openssl-1.0.2h/include" \
--prefix=/opt/openssh-7.3p1 \
--with-ldflags="-L/opt/openssl-1.0.2h/lib"

这两个命令也可以合并为一个:

# LD_LIBRARY_PATH=/opt/openssl-1.0.2h/lib ./configure \
CFLAGS="-I/opt/openssl-1.0.2h/include" \
--prefix=/opt/openssh-7.3p1 \
--with-ldflags="-L/opt/openssl-1.0.2h/lib"

这是结果:
OpenSSH has been configured with the following options:
                     User binaries: /opt/openssh-7.3p1/bin
                   System binaries: /opt/openssh-7.3p1/sbin
               Configuration files: /opt/openssh-7.3p1/etc
                   Askpass program: /opt/openssh-7.3p1/libexec/ssh-askpass
                      Manual pages: /opt/openssh-7.3p1/share/man/manX
                          PID file: /var/run
  Privilege separation chroot path: /var/empty
            sshd default user PATH: /usr/bin:/bin:/usr/sbin:/sbin:/opt/openssh-7.3p1/bin
                    Manpage format: doc
                       PAM support: no
                   OSF SIA support: no
                 KerberosV support: no
                   SELinux support: no
                 Smartcard support: 
                     S/KEY support: no
              MD5 password support: no
                   libedit support: no
  Solaris process contract support: no
           Solaris project support: no
         Solaris privilege support: no
       IP address in $DISPLAY hack: no
           Translate v4 in v6 hack: yes
                  BSD Auth support: no
              Random number source: OpenSSL internal ONLY
             Privsep sandbox style: rlimit

              Host: x86_64-unknown-linux-gnu
          Compiler: gcc
    Compiler flags: -I/opt/openssl-1.0.2h/include -Wall -Wpointer-arith -Wsign-compare \
                    -Wformat-security -Wno-pointer-sign -fno-strict-aliasing \
                    -D_FORTIFY_SOURCE=2 -ftrapv -fno-builtin-memset -fstack-protector-all \
                    -std=gnu99 -fPIE 
Preprocessor flags: 
      Linker flags:  -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -fstack-protector-all \
                     -L/opt/openssl-1.0.2h/lib -pie
         Libraries: -lcrypto -lrt -ldl -lutil -lz  -lcrypt -lresolv

在接下来的 makemake install 步骤中,强烈建议使用 LD_LIBRARY_PATH。否则,make install 将失败,因为它会运行 ssh-keygen 命令以生成新的主机密钥,但它找不到新的 OpenSSH 库文件:

mkdir /opt/openssh-7.3p1/etc
./ssh-keygen: error while loading shared libraries: libcrypto.so.1.0.0: cannot open shared object file: No such file or directory
make: *** [host-key] Error 127

0
也许你应该在openssh的配置脚本中使用--with-ssl-dir选项:
$ ./configure --help | grep with-ssl-dir
  --with-ssl-dir=PATH     Specify path to OpenSSL installation

--with-openssl选项只是一个布尔标志,用于启用或禁用openssl依赖项。


是的,你说得对-- --with-openssl 只是一个布尔标志。但 --with-ssl-dir 选项并不能消除 OpenSSL 库版本检查错误。 - Jdamian
我最初使用了 --with-openssl,因为我最近编译并构建 bind 时使用了该标志,并且在那种情况下,它不仅仅是一个布尔标志:--with-openssl=PATH Build with OpenSSL yes|no|path. - Jdamian
如果 --with-ssl-dir 无法工作,您可以尝试在 OpenSSL 邮件列表中进行提问。 - redneb

0

除了这个解决方案@Jdamain提供的之外,我还需要重新编译openssl,并将--prefix--openssldir设置为相同的目录。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接