SSL_CTX_use_certificate_file求救!!!
本帖最后由 zy_china 于 2016-09-13 12:48 编辑一段简单的代码如下:
bool CAPNSClient::InitAPNSClient()
{
ReleaseConnection();
// 初始化 SSL 算法库函数,调用 SSL 系列函数之前必须调用此函数!
SSL_library_init();
// 加载 SSL 抽像库错误信息
SSL_load_error_strings();
// 加载 BIO 抽象库的错误信息
//ERR_load_BIO_strings();
// 加载所有加密和散列函数
OpenSSL_add_all_algorithms();
/* Create an SSL_METHOD structure 设置客户端使用的 SSL 协议算法*/
m_pMeth = TLS_client_method();
/* Create an SSL_CTX structure 创建 SSL 上下文*/
m_pCtx = SSL_CTX_new(m_pMeth);
if(NULL == m_pCtx)
{
ERRLOG("Could not get SSL Context");
return false;
}
/* Load the CA from the Path 加载可信任的 CA 证书(路径) */
if(0 == SSL_CTX_load_verify_locations(m_pCtx, NULL, CA_CERT_PATH))
{
/* Handle failed load here */
ERRLOG("Failed to set CA location:%s", ERR_error_string( ERR_get_error(), NULL ));
return false;
}
/* Load the client certificate into the SSL_CTX structure 加载客户端证书*/
if (0 == SSL_CTX_use_certificate_file(m_pCtx, RSA_CLIENT_CERT, SSL_FILETYPE_PEM))
{
ERRLOG("Cannot use Certificate File:%s", ERR_error_string( ERR_get_error(), NULL ));
return false;
}
/* Load the private-key corresponding to the client certificate 加载客户端私钥文件*/
if (0 == SSL_CTX_use_PrivateKey_file(m_pCtx, RSA_CLIENT_KEY, SSL_FILETYPE_PEM))
{
ERRLOG("Cannot use Private Key:%s", ERR_error_string( ERR_get_error(), NULL ));
return false;
}
/* Check if the client certificate and private-key matches 验证私钥是否与证书一致*/
if (0 == SSL_CTX_check_private_key(m_pCtx))
{
ERRLOG("Private key does not match the certificate public key");
return false;
}
return true;
}
SSL_CTX_use_certificate_file报错:error:140AB18F:SSL routines:SSL_CTX_use_certificate:ee key too small
关键是我在镜像环境运行完全正常,移到主环境就出现此问题。两个环境的证书保证是一模一样的。网上完全搜不到此错误的描述。
快疯了,谁来帮帮我!多谢!!!
今天早上收到OpenSSL官方回复,添加了一行代码:SSL_CTX_set_security_level(m_pCtx, 0);
但出现了新的问题,还是那个函数,报错变成了:
error:140BF10C:SSL routines:ssl_set_cert:x509 lib
这个原因有人知道吗?
但通过再次确认,有问题的机器和运行正常的机器的安全级别是一致的。可能问题不是出在这。
有可能是系统哪的设置出现问题。我用的操作系统是OpenSuse。
有没有哪位给点建议啊! 回复 2# zy_china
这种问题还是直接在 openssl 的用户邮件列表里面讨论的好 已经发到用户邮件列表里了,我是几头开花,看哪个能帮到我
页:
[1]