gpt4 book ai didi

c++ - Openssl SSL_CTX_new(SSLv3_method()) 返回 NULL

转载 作者:IT王子 更新时间:2023-10-29 01:14:42 25 4
gpt4 key购买 nike

来自 cat/proc/version 的 Linux 版本

Linux version 3.6.11-4.fc16.i686 (mockbuild@bkernel02) (gcc version 4.6.3 20120306 (Red Hat 4.6.3-2) (GCC) )

来自 openssl version 命令:

OpenSSL 1.0.1g 7 Apr 2014

首先,我使用带有 cURL 的 REST API 执行 HTTP 请求,以从服务器(线程 1)获取一些配置。然后我创建一个 TLS channel 并通过该 channel (线程 2)登录到 XMPP 服务器。然后我尝试通过创建 TLS channel (Thread3) 登录到 SIP 服务器。但是 TLS channel 创建失败并出现此错误:

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

SSL_library_init();
SSL_load_error_strings();
SSL_CTX* sslContext = SSL_CTX_new(SSLv3_method());

此处 sslContext 为 NULL。我在网上看到了很多关于这个错误的错误报告和邮件,但没有任何解决方案。我不知道它是否与 cURL 有关,但在很多情况下,人们在使用 cURL 时都会遇到这个问题。

有关此错误的其他人的帖子,请参阅以下链接。

https://issues.apache.org/bugzilla/show_bug.cgi?id=56027

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

http://en.it-usenet.org/thread/17225/526/

http://curl.haxx.se/mail/curlphp-2009-01/0020.html

编辑:

评论第一条命令的输出:

# openssl version -a                                                           
OpenSSL 1.0.1g 7 Apr 2014
built on: Tue Aug 12 10:07:53 BDT 2014
platform: linux-generic32
options: bn(64,32) rc4(ptr,char) des(idx,cisc,16,long) blowfish(ptr)
compiler: /home/moshiur/Documents/Workspace/ph_SDKs/Untitled_Folder/ph
OPENSSLDIR: "/etc/ssl"


# ls /etc/ssl/
certs misc openssl.cnf private

最佳答案

Openssl SSL_CTX_new(SSLv3_method()) returns NULL

调用:

  • OpenSSL_add_ssl_algorithms
  • SSL_load_error_strings

参见 Library Initialization在 OpenSSL 维基上。来自维基:

If you fail to initialize the library, then you will experience unexplained errors like SSL_CTX_new returning NULL, and alert handshake failure with no shared ciphers.


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

听起来该库配置了 no-ssl2no-md5。这是 FIPS 配置吗?

配置定义在几个地方可用。首先,您可以检查(有时会显示定义):

$ /usr/local/ssl/macosx-x64/bin/openssl version -a
OpenSSL 1.0.1i 6 Aug 2014
built on: Wed Aug 6 18:45:03 EDT 2014
platform: darwin64-x86_64-cc
options: bn(64,64) rc4(ptr,char) des(idx,cisc,16,int) idea(int) blowfish(idx)
compiler: cc -fPIC -fno-common -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN
-DHAVE_DLFCN_H -arch x86_64 -O3 -DL_ENDIAN -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT
-DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM
-DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM
OPENSSLDIR: "/usr/local/ssl/macosx-x64"

其次,您可以使用 opensslconf.h 进行运行时检查。例如,您可以通过 OPENSSL_NO_SSL2 检查 no-ssl2 配置选项(这些定义始终显示):

$ cat /usr/local/ssl/macosx-x64/include/openssl/opensslconf.h | grep -A 1 -i SSL2
#ifndef OPENSSL_NO_SSL2
# define OPENSSL_NO_SSL2
#endif
--
# if defined(OPENSSL_NO_SSL2) && !defined(NO_SSL2)
# define NO_SSL2
# endif

您可以在代码中使用这些来保护功能。例如:

#ifndef OPENSSL_NO_SSL2
/* SSLv2 is available */
#endif

关于c++ - Openssl SSL_CTX_new(SSLv3_method()) 返回 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25282939/

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