openssl動態庫編譯


通常Linux系統自帶OpenSSL,但是其so文件由於沒有debug信息,因此無法跟蹤內部函數,對於學習
不太方便,需要通過源碼重新安裝。
        我的Linux系統是CentOS7,自帶的OpenSSL的版本是1.0.1e。在網上下載了OpenSSL1.0.1f后,通過
如下方法安裝
[html]  view plain  copy
 
  1. ./config --prefix=/usr/local --openssldir=/usr/local/ssl    
  2. make && make install    
  3. ./config -d shared --prefix=/usr/local --openssldir=/usr/local/ssl    
  4. make clean    
  5. make && make install    

        先安裝靜態庫版本,再安裝動態庫版本。安裝目錄為/usr/local下。安裝動態庫時增加-d選項,因為
調試時使用動態庫,需要跟蹤代碼。
        這樣后面就可以寫調試代碼調試,如下面的例子:
 
          
#include <stdio.h>
#include <string.h>
#include <openssl/bio.h>
int main()
{
BIO *= NULL;
int len = 0;
char *out = NULL;
= BIO_new(BIO_s_mem());
 
if (NULL == b)
{
return 0;
}
 
len = BIO_write(b,"openssl",4);
len = BIO_printf(b,"%s","zcp");
len = BIO_ctrl_pending(b);
 
out = (char *)OPENSSL_malloc(len);
if (NULL == out)
{
return 0;
}
memset(out, 0, len);
 
len = BIO_read(b,out,len);
printf("out is : %s\n",out);
 
OPENSSL_free(out);
BIO_free(b);
return 0;
}
    在當前路徑下創建一個新的動態庫軟鏈接:
    ln -s /usr/local/lib64/libcrypto.so.1.0.0  libcrypto.so.10
   然后gcc編譯時指明使用這個libcrypto:
    gcc -g -DDEBUG -o openssl_mem_bio_test openssl_mem_bio_test.c -lcrypto -Wl,-rpath=.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM