Unusual error creating a SSL context with SSL_CTX_new


openssl 多线程编程中会出现下面的问题:

error:140A90F1:SSL routines:SSL_CTX_new:unable to load ssl2 md5 routines

查找了如下资料:

http://comments.gmane.org/gmane.comp.lib.boost.asio.user/2099


Well I think I have figured out what the issue is, or at least narrowed
it down. I have been able to provide a work around for our needs but I
wanted to post this in case someone came across this same issue.

It appears to be an issue with some type of static member initialization
inside the openssl library. I have 2 libraries, both of them use the
openssl library, let's call them A and B. When the application starts up
both A & B are able to successfully create a security context. Later,
when library B tries to create another security context it fails. Both
library A and B are module plugins to our application so they both will
load but if one is not needed it is unloaded. So once I realized that, I
ran some experiments.

If just A is loaded then things work fine.
If just B is loaded then things work fine.
If A and B are loaded, then A is unloaded, B fails
If A and B are loaded, then B is unloaded, A fails
If A is loaded, then unloaded, then B is loaded, B works fine
If B is loaded, then unloaded, then A is loaded, A works fine

So, my belief is that when openssl is loaded it initializes some static
members. Once a library that uses openssl is unloaded openssl clears
some needed state that prevents anyone else from creating a security
context.

暂时的解决方法如下:

SSL_CTX *ctx = NULL;
	ctx = SSL_CTX_new(SSLv23_client_method()); 
	if(ctx == NULL){
		ERR_print_errors_fp(stdout);
		InitOpenSSL();
		ctx= SSL_CTX_new(SSLv23_client_method()); 
		if(ctx == NULL){
			ERR_print_errors_fp(stdout);
			return HT_ERROR_INIT_ENGINE;
		}
	}

参考资料:

http://www.ibm.com/developerworks/cn/linux/l-openssl.html

1、配置 OpenLDAP 使用 SSL/TLS 加密数据通信 

2、应用 openssl 工具进行 SSL 故障分析 

3、使用 OpenSSL API 进行安全编程 

4、使用 OpenSSL API 进行安全编程,第 3 部分: 提供安全服务 

5、使用 OpenSSL API 进行安全编程,第 2 部分: 安全握手


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值