gpt4 book ai didi

c - 在 OSX 和 Ubuntu 上构建打补丁的 64 位 OpenSSL

转载 作者:太空狗 更新时间:2023-10-29 12:34:58 26 4
gpt4 key购买 nike

我正在尝试设置 patched version的 OpenSSL 使用 DTLS,我遇到了很多麻烦。我假设这是由于我对 gcc 和链接 c 库缺乏了解。特别是,我一直看到人们说要链接到 lib/子文件夹,但我找不到用于 OpenSSL 的链接。我也是question on building 32 bit OpenSSL ,但我正在尝试做 64 位。

操作系统

获取源码和补丁:

wget ftp://ftp.openssl.org/source/openssl-1.0.1c.tar.gz # get latest stable OpenSSL
mv ~/Downloads/openssl-1.0.1c.tar.gz /usr/local/openssl-1.0.1c.tar.gz
cd /usr/local/openssl-1.0.1c.tar.gz
wget http://sctp.fh-muenster.de/dtls/dtls-bugs-1.0.1.patch # get the patch file

构建(64 位,OpenSSL 默认为 32 位):

export CFLAGS="-arch x86_64"
export LDFLAGS="-arch x86_64"
./Configure darwin64-x86_64-cc # 64 bit config command
make # .a files should be built, great

太好了,我在 OpenSSL 根目录中有一些库:

/usr/local/openssl-1.0.1c$ ll lib*
-rw-r--r-- 1 nflacco staff 3286136 Jan 4 12:43 libcrypto.a
-rw-r--r-- 1 nflacco staff 260 Jan 4 12:43 libcrypto.pc
-rw-r--r-- 1 nflacco staff 570200 Jan 4 12:43 libssl.a
-rw-r--r-- 1 nflacco staff 275 Jan 4 12:43 libssl.pc

现在我将尝试编译 a simple piece of code that uses the patched OpenSSL :

~$ gcc -L /usr/local/openssl-1.0.1c -lssl -lcrypto -I /usr/local/opt/openssl/include -o server server.c
ld: warning: _OPENSSL_ia32cap_P has different visibility (hidden) in /usr/local/openssl-1.0.1c/libcrypto.a(x86_64cpuid.o) and (default) in /usr/local/openssl-1.0.1c/libcrypto.a(cryptlib.o)
Undefined symbols for architecture x86_64:
"_BIO_dgram_get_peer", referenced from:
_generate_cookie_callback in ccfldIrE.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [server] Error 1

Ubuntu

建筑:

./config
make

正在检查库(忽略日期,Ubuntu 认为是圣诞节):

/usr/local/openssl-1.0.1c$ ll lib*
-rw-r--r-- 1 root root 3170340 Dec 25 17:45 libcrypto.a
-rw-r--r-- 1 root root 264 Dec 25 17:46 libcrypto.pc
-rw-r--r-- 1 root root 534092 Dec 25 17:45 libssl.a
-rw-r--r-- 1 root root 279 Dec 25 17:46 libssl.pc

然后,尝试编译:

gcc -L /usr/local/openssl-1.0.1c -lssl -lcrypto -I /usr/local/opt/openssl/include -o server server.c
/tmp/cc0DgDl1.o: In function `generate_cookie_callback':
server.c:(.text+0x8b): undefined reference to `RAND_bytes'
server.c:(.text+0xba): undefined reference to `SSL_get_rbio'
server.c:(.text+0xdc): undefined reference to `BIO_ctrl'
server.c:(.text+0x112): undefined reference to `CRYPTO_malloc'
/tmp/cc0DgDl1.o: In function `main':
server.c:(.text+0x163): undefined reference to `SSL_library_init'
server.c:(.text+0x168): undefined reference to `SSL_load_error_strings'
server.c:(.text+0x16d): undefined reference to `SSL_library_init'
/tmp/cc0DgDl1.o: In function `configure_server_ssl':
server.c:(.text+0x2f5): undefined reference to `SSL_CTX_set_cipher_list'
server.c:(.text+0x318): undefined reference to `SSL_CTX_ctrl'
server.c:(.text+0x333): undefined reference to `SSL_CTX_use_certificate_file'
server.c:(.text+0x35e): undefined reference to `SSL_CTX_use_PrivateKey_file'
server.c:(.text+0x379): undefined reference to `SSL_CTX_check_private_key'
server.c:(.text+0x3a4): undefined reference to `SSL_CTX_set_verify'
server.c:(.text+0x3c7): undefined reference to `SSL_CTX_ctrl'
server.c:(.text+0x3da): undefined reference to `SSL_CTX_set_cookie_generate_cb'
server.c:(.text+0x3ed): undefined reference to `SSL_CTX_set_cookie_verify_cb'
/tmp/cc0DgDl1.o: In function `start_server':
server.c:(.text+0x40b): undefined reference to `DTLSv1_server_method'
server.c:(.text+0x413): undefined reference to `SSL_CTX_new'
collect2: ld returned 1 exit status

更新:

在 Ubuntu 上,我通过将库移动到编译命令的末尾并添加标志 -ldl 来编译它,使其在没有警告的情况下进行编译:

gcc -L /usr/local/openssl-1.0.1c -I /usr/local/opt/openssl/include -o server server.c -lssl -lcrypto -ldl

在 OSX 上,此命令给出了与之前相同的错误,没有找到 _BIO_dgram_get_peer

最佳答案

您必须将库放在命令行的最后:

gcc -L /usr/local/openssl-1.0.1c -I /usr/local/opt/openssl/include -o server server.c -lssl -lcrypto
# ^^^^^^^^^^^^^^

这个网站上有很多重复的问题,解释了原因和方法。 ld 的文档对其进行了很好的解释,是最终的引用。

关于c - 在 OSX 和 Ubuntu 上构建打补丁的 64 位 OpenSSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14164953/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com