簡體   English   中英

在OSX和Ubuntu上構建修補的64位OpenSSL

[英]Building patched 64 bit OpenSSL on OSX and Ubuntu

我正在嘗試設置OpenSSL的修補版本以使用DTLS,但遇到了很多麻煩。 我認為這是由於我缺乏對gcc和鏈接c庫的理解。 特別是,我一直在看到人們說要鏈接到lib /子文件夾,但是我找不到用於OpenSSL的文件夾。 我也是一個關於構建32位OpenSSL的問題 ,但是我試圖做64位。

OSX

獲取源代碼和補丁:

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

現在,我將嘗試編譯一個使用修補的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上,我通過將庫移到compile命令的末尾並添加標志-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的文檔對此進行了很好的解釋,並且是最終參考。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM